diff --git a/android/x86/include/freetype/config/ftconfig.h b/android/x86/include/freetype/config/ftconfig.h new file mode 100644 index 00000000..cb9e0a41 --- /dev/null +++ b/android/x86/include/freetype/config/ftconfig.h @@ -0,0 +1,504 @@ +/* ftconfig.h. Generated from ftconfig.in by configure. */ +/***************************************************************************/ +/* */ +/* ftconfig.in */ +/* */ +/* UNIX-specific configuration file (specification only). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This header file contains a number of macro definitions that are used */ + /* by the rest of the engine. Most of the macros here are automatically */ + /* determined at compile time, and you should not need to change it to */ + /* port FreeType, except to compile the library with a non-ANSI */ + /* compiler. */ + /* */ + /* Note however that if some specific modifications are needed, we */ + /* advise you to place a modified copy in your build directory. */ + /* */ + /* The build directory is usually `builds/', and contains */ + /* system-specific files that are always included first when building */ + /* the library. */ + /* */ + /*************************************************************************/ + + +#ifndef FTCONFIG_H_ +#define FTCONFIG_H_ + +#include +#include FT_CONFIG_OPTIONS_H +#include FT_CONFIG_STANDARD_LIBRARY_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* PLATFORM-SPECIFIC CONFIGURATION MACROS */ + /* */ + /* These macros can be toggled to suit a specific system. The current */ + /* ones are defaults used to compile FreeType in an ANSI C environment */ + /* (16bit compilers are also supported). Copy this file to your own */ + /* `builds/' directory, and edit it to port the engine. */ + /* */ + /*************************************************************************/ + + +#define HAVE_UNISTD_H 1 +#define HAVE_FCNTL_H 1 +#define HAVE_STDINT_H 1 + + + /* There are systems (like the Texas Instruments 'C54x) where a `char' */ + /* has 16 bits. ANSI C says that sizeof(char) is always 1. Since an */ + /* `int' has 16 bits also for this system, sizeof(int) gives 1 which */ + /* is probably unexpected. */ + /* */ + /* `CHAR_BIT' (defined in limits.h) gives the number of bits in a */ + /* `char' type. */ + +#ifndef FT_CHAR_BIT +#define FT_CHAR_BIT CHAR_BIT +#endif + + +/* #undef FT_USE_AUTOCONF_SIZEOF_TYPES */ +#ifdef FT_USE_AUTOCONF_SIZEOF_TYPES + +#define SIZEOF_INT 4 +#define SIZEOF_LONG 4 +#define FT_SIZEOF_INT SIZEOF_INT +#define FT_SIZEOF_LONG SIZEOF_LONG + +#else /* !FT_USE_AUTOCONF_SIZEOF_TYPES */ + + /* Following cpp computation of the bit length of int and long */ + /* is copied from default include/freetype/config/ftconfig.h. */ + /* If any improvement is required for this file, it should be */ + /* applied to the original header file for the builders that */ + /* do not use configure script. */ + + /* The size of an `int' type. */ +#if FT_UINT_MAX == 0xFFFFUL +#define FT_SIZEOF_INT (16 / FT_CHAR_BIT) +#elif FT_UINT_MAX == 0xFFFFFFFFUL +#define FT_SIZEOF_INT (32 / FT_CHAR_BIT) +#elif FT_UINT_MAX > 0xFFFFFFFFUL && FT_UINT_MAX == 0xFFFFFFFFFFFFFFFFUL +#define FT_SIZEOF_INT (64 / FT_CHAR_BIT) +#else +#error "Unsupported size of `int' type!" +#endif + + /* The size of a `long' type. A five-byte `long' (as used e.g. on the */ + /* DM642) is recognized but avoided. */ +#if FT_ULONG_MAX == 0xFFFFFFFFUL +#define FT_SIZEOF_LONG (32 / FT_CHAR_BIT) +#elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFUL +#define FT_SIZEOF_LONG (32 / FT_CHAR_BIT) +#elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFFFFFFFUL +#define FT_SIZEOF_LONG (64 / FT_CHAR_BIT) +#else +#error "Unsupported size of `long' type!" +#endif + +#endif /* !FT_USE_AUTOCONF_SIZEOF_TYPES */ + + + /* FT_UNUSED is a macro used to indicate that a given parameter is not */ + /* used -- this is only used to get rid of unpleasant compiler warnings */ +#ifndef FT_UNUSED +#define FT_UNUSED( arg ) ( (arg) = (arg) ) +#endif + + + /*************************************************************************/ + /* */ + /* AUTOMATIC CONFIGURATION MACROS */ + /* */ + /* These macros are computed from the ones defined above. Don't touch */ + /* their definition, unless you know precisely what you are doing. No */ + /* porter should need to mess with them. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Mac support */ + /* */ + /* This is the only necessary change, so it is defined here instead */ + /* providing a new configuration file. */ + /* */ +#if defined( __APPLE__ ) || ( defined( __MWERKS__ ) && defined( macintosh ) ) + /* no Carbon frameworks for 64bit 10.4.x */ + /* AvailabilityMacros.h is available since Mac OS X 10.2, */ + /* so guess the system version by maximum errno before inclusion */ +#include +#ifdef ECANCELED /* defined since 10.2 */ +#include "AvailabilityMacros.h" +#endif +#if defined( __LP64__ ) && \ + ( MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 ) +#undef FT_MACINTOSH +#endif + +#elif defined( __SC__ ) || defined( __MRC__ ) + /* Classic MacOS compilers */ +#include "ConditionalMacros.h" +#if TARGET_OS_MAC +#define FT_MACINTOSH 1 +#endif + +#endif + + + /* Fix compiler warning with sgi compiler */ +#if defined( __sgi ) && !defined( __GNUC__ ) +#if defined( _COMPILER_VERSION ) && ( _COMPILER_VERSION >= 730 ) +#pragma set woff 3505 +#endif +#endif + + + /*************************************************************************/ + /* */ + /*
*/ + /* basic_types */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* */ + /* FT_Int16 */ + /* */ + /* */ + /* A typedef for a 16bit signed integer type. */ + /* */ + typedef signed short FT_Int16; + + + /*************************************************************************/ + /* */ + /* */ + /* FT_UInt16 */ + /* */ + /* */ + /* A typedef for a 16bit unsigned integer type. */ + /* */ + typedef unsigned short FT_UInt16; + + /* */ + + + /* this #if 0 ... #endif clause is for documentation purposes */ +#if 0 + + /*************************************************************************/ + /* */ + /* */ + /* FT_Int32 */ + /* */ + /* */ + /* A typedef for a 32bit signed integer type. The size depends on */ + /* the configuration. */ + /* */ + typedef signed XXX FT_Int32; + + + /*************************************************************************/ + /* */ + /* */ + /* FT_UInt32 */ + /* */ + /* A typedef for a 32bit unsigned integer type. The size depends on */ + /* the configuration. */ + /* */ + typedef unsigned XXX FT_UInt32; + + + /*************************************************************************/ + /* */ + /* */ + /* FT_Int64 */ + /* */ + /* A typedef for a 64bit signed integer type. The size depends on */ + /* the configuration. Only defined if there is real 64bit support; */ + /* otherwise, it gets emulated with a structure (if necessary). */ + /* */ + typedef signed XXX FT_Int64; + + + /*************************************************************************/ + /* */ + /* */ + /* FT_UInt64 */ + /* */ + /* A typedef for a 64bit unsigned integer type. The size depends on */ + /* the configuration. Only defined if there is real 64bit support; */ + /* otherwise, it gets emulated with a structure (if necessary). */ + /* */ + typedef unsigned XXX FT_UInt64; + + /* */ + +#endif + +#if FT_SIZEOF_INT == 4 + + typedef signed int FT_Int32; + typedef unsigned int FT_UInt32; + +#elif FT_SIZEOF_LONG == 4 + + typedef signed long FT_Int32; + typedef unsigned long FT_UInt32; + +#else +#error "no 32bit type found -- please check your configuration files" +#endif + + + /* look up an integer type that is at least 32 bits */ +#if FT_SIZEOF_INT >= 4 + + typedef int FT_Fast; + typedef unsigned int FT_UFast; + +#elif FT_SIZEOF_LONG >= 4 + + typedef long FT_Fast; + typedef unsigned long FT_UFast; + +#endif + + + /* determine whether we have a 64-bit int type for platforms without */ + /* Autoconf */ +#if FT_SIZEOF_LONG == 8 + + /* FT_LONG64 must be defined if a 64-bit type is available */ +#define FT_LONG64 +#define FT_INT64 long +#define FT_UINT64 unsigned long + + /*************************************************************************/ + /* */ + /* A 64-bit data type may create compilation problems if you compile */ + /* in strict ANSI mode. To avoid them, we disable other 64-bit data */ + /* types if __STDC__ is defined. You can however ignore this rule */ + /* by defining the FT_CONFIG_OPTION_FORCE_INT64 configuration macro. */ + /* */ +#elif !defined( __STDC__ ) || defined( FT_CONFIG_OPTION_FORCE_INT64 ) + +#if defined( __STDC_VERSION__ ) && __STDC_VERSION__ >= 199901L + +#define FT_LONG64 +#define FT_INT64 long long int +#define FT_UINT64 unsigned long long int + +#elif defined( _MSC_VER ) && _MSC_VER >= 900 /* Visual C++ (and Intel C++) */ + + /* this compiler provides the __int64 type */ +#define FT_LONG64 +#define FT_INT64 __int64 +#define FT_UINT64 unsigned __int64 + +#elif defined( __BORLANDC__ ) /* Borland C++ */ + + /* XXXX: We should probably check the value of __BORLANDC__ in order */ + /* to test the compiler version. */ + + /* this compiler provides the __int64 type */ +#define FT_LONG64 +#define FT_INT64 __int64 +#define FT_UINT64 unsigned __int64 + +#elif defined( __WATCOMC__ ) /* Watcom C++ */ + + /* Watcom doesn't provide 64-bit data types */ + +#elif defined( __MWERKS__ ) /* Metrowerks CodeWarrior */ + +#define FT_LONG64 +#define FT_INT64 long long int +#define FT_UINT64 unsigned long long int + +#elif defined( __GNUC__ ) + + /* GCC provides the `long long' type */ +#define FT_LONG64 +#define FT_INT64 long long int +#define FT_UINT64 unsigned long long int + +#endif /* __STDC_VERSION__ >= 199901L */ + +#endif /* FT_SIZEOF_LONG == 8 */ + +#ifdef FT_LONG64 + typedef FT_INT64 FT_Int64; + typedef FT_UINT64 FT_UInt64; +#endif + + + /*************************************************************************/ + /* */ + /* miscellaneous */ + /* */ + /*************************************************************************/ + + +#define FT_BEGIN_STMNT do { +#define FT_END_STMNT } while ( 0 ) +#define FT_DUMMY_STMNT FT_BEGIN_STMNT FT_END_STMNT + + + /* typeof condition taken from gnulib's `intprops.h' header file */ +#if ( __GNUC__ >= 2 || \ + defined( __IBM__TYPEOF__ ) || \ + ( __SUNPRO_C >= 0x5110 && !__STDC__ ) ) +#define FT_TYPEOF( type ) (__typeof__ (type)) +#else +#define FT_TYPEOF( type ) /* empty */ +#endif + + +#ifdef FT_MAKE_OPTION_SINGLE_OBJECT + +#define FT_LOCAL( x ) static x +#define FT_LOCAL_DEF( x ) static x + +#else + +#ifdef __cplusplus +#define FT_LOCAL( x ) extern "C" x +#define FT_LOCAL_DEF( x ) extern "C" x +#else +#define FT_LOCAL( x ) extern x +#define FT_LOCAL_DEF( x ) x +#endif + +#endif /* FT_MAKE_OPTION_SINGLE_OBJECT */ + +#define FT_LOCAL_ARRAY( x ) extern const x +#define FT_LOCAL_ARRAY_DEF( x ) const x + + +#ifndef FT_BASE + +#ifdef __cplusplus +#define FT_BASE( x ) extern "C" x +#else +#define FT_BASE( x ) extern x +#endif + +#endif /* !FT_BASE */ + + +#ifndef FT_BASE_DEF + +#ifdef __cplusplus +#define FT_BASE_DEF( x ) x +#else +#define FT_BASE_DEF( x ) x +#endif + +#endif /* !FT_BASE_DEF */ + + +#ifndef FT_EXPORT + +#ifdef __cplusplus +#define FT_EXPORT( x ) extern "C" x +#else +#define FT_EXPORT( x ) extern x +#endif + +#endif /* !FT_EXPORT */ + + +#ifndef FT_EXPORT_DEF + +#ifdef __cplusplus +#define FT_EXPORT_DEF( x ) extern "C" x +#else +#define FT_EXPORT_DEF( x ) extern x +#endif + +#endif /* !FT_EXPORT_DEF */ + + +#ifndef FT_EXPORT_VAR + +#ifdef __cplusplus +#define FT_EXPORT_VAR( x ) extern "C" x +#else +#define FT_EXPORT_VAR( x ) extern x +#endif + +#endif /* !FT_EXPORT_VAR */ + + /* The following macros are needed to compile the library with a */ + /* C++ compiler and with 16bit compilers. */ + /* */ + + /* This is special. Within C++, you must specify `extern "C"' for */ + /* functions which are used via function pointers, and you also */ + /* must do that for structures which contain function pointers to */ + /* assure C linkage -- it's not possible to have (local) anonymous */ + /* functions which are accessed by (global) function pointers. */ + /* */ + /* */ + /* FT_CALLBACK_DEF is used to _define_ a callback function. */ + /* */ + /* FT_CALLBACK_TABLE is used to _declare_ a constant variable that */ + /* contains pointers to callback functions. */ + /* */ + /* FT_CALLBACK_TABLE_DEF is used to _define_ a constant variable */ + /* that contains pointers to callback functions. */ + /* */ + /* */ + /* Some 16bit compilers have to redefine these macros to insert */ + /* the infamous `_cdecl' or `__fastcall' declarations. */ + /* */ +#ifndef FT_CALLBACK_DEF +#ifdef __cplusplus +#define FT_CALLBACK_DEF( x ) extern "C" x +#else +#define FT_CALLBACK_DEF( x ) static x +#endif +#endif /* FT_CALLBACK_DEF */ + +#ifndef FT_CALLBACK_TABLE +#ifdef __cplusplus +#define FT_CALLBACK_TABLE extern "C" +#define FT_CALLBACK_TABLE_DEF extern "C" +#else +#define FT_CALLBACK_TABLE extern +#define FT_CALLBACK_TABLE_DEF /* nothing */ +#endif +#endif /* FT_CALLBACK_TABLE */ + + +FT_END_HEADER + + +#endif /* FTCONFIG_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/config/ftheader.h b/android/x86/include/freetype/config/ftheader.h new file mode 100644 index 00000000..68e14834 --- /dev/null +++ b/android/x86/include/freetype/config/ftheader.h @@ -0,0 +1,833 @@ +/***************************************************************************/ +/* */ +/* ftheader.h */ +/* */ +/* Build macros of the FreeType 2 library. */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +#ifndef FTHEADER_H_ +#define FTHEADER_H_ + + + /*@***********************************************************************/ + /* */ + /* */ + /* FT_BEGIN_HEADER */ + /* */ + /* */ + /* This macro is used in association with @FT_END_HEADER in header */ + /* files to ensure that the declarations within are properly */ + /* encapsulated in an `extern "C" { .. }' block when included from a */ + /* C++ compiler. */ + /* */ +#ifdef __cplusplus +#define FT_BEGIN_HEADER extern "C" { +#else +#define FT_BEGIN_HEADER /* nothing */ +#endif + + + /*@***********************************************************************/ + /* */ + /* */ + /* FT_END_HEADER */ + /* */ + /* */ + /* This macro is used in association with @FT_BEGIN_HEADER in header */ + /* files to ensure that the declarations within are properly */ + /* encapsulated in an `extern "C" { .. }' block when included from a */ + /* C++ compiler. */ + /* */ +#ifdef __cplusplus +#define FT_END_HEADER } +#else +#define FT_END_HEADER /* nothing */ +#endif + + + /*************************************************************************/ + /* */ + /* Aliases for the FreeType 2 public and configuration files. */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /*
*/ + /* header_file_macros */ + /* */ + /* */ + /* Header File Macros */ + /* */ + /* <Abstract> */ + /* Macro definitions used to #include specific header files. */ + /* */ + /* <Description> */ + /* The following macros are defined to the name of specific */ + /* FreeType~2 header files. They can be used directly in #include */ + /* statements as in: */ + /* */ + /* { */ + /* #include FT_FREETYPE_H */ + /* #include FT_MULTIPLE_MASTERS_H */ + /* #include FT_GLYPH_H */ + /* } */ + /* */ + /* There are several reasons why we are now using macros to name */ + /* public header files. The first one is that such macros are not */ + /* limited to the infamous 8.3~naming rule required by DOS (and */ + /* `FT_MULTIPLE_MASTERS_H' is a lot more meaningful than `ftmm.h'). */ + /* */ + /* The second reason is that it allows for more flexibility in the */ + /* way FreeType~2 is installed on a given system. */ + /* */ + /*************************************************************************/ + + + /* configuration files */ + + /************************************************************************* + * + * @macro: + * FT_CONFIG_CONFIG_H + * + * @description: + * A macro used in #include statements to name the file containing + * FreeType~2 configuration data. + * + */ +#ifndef FT_CONFIG_CONFIG_H +#define FT_CONFIG_CONFIG_H <freetype/config/ftconfig.h> +#endif + + + /************************************************************************* + * + * @macro: + * FT_CONFIG_STANDARD_LIBRARY_H + * + * @description: + * A macro used in #include statements to name the file containing + * FreeType~2 interface to the standard C library functions. + * + */ +#ifndef FT_CONFIG_STANDARD_LIBRARY_H +#define FT_CONFIG_STANDARD_LIBRARY_H <freetype/config/ftstdlib.h> +#endif + + + /************************************************************************* + * + * @macro: + * FT_CONFIG_OPTIONS_H + * + * @description: + * A macro used in #include statements to name the file containing + * FreeType~2 project-specific configuration options. + * + */ +#ifndef FT_CONFIG_OPTIONS_H +#define FT_CONFIG_OPTIONS_H <freetype/config/ftoption.h> +#endif + + + /************************************************************************* + * + * @macro: + * FT_CONFIG_MODULES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * list of FreeType~2 modules that are statically linked to new library + * instances in @FT_Init_FreeType. + * + */ +#ifndef FT_CONFIG_MODULES_H +#define FT_CONFIG_MODULES_H <freetype/config/ftmodule.h> +#endif + + /* */ + + /* public headers */ + + /************************************************************************* + * + * @macro: + * FT_FREETYPE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * base FreeType~2 API. + * + */ +#define FT_FREETYPE_H <freetype/freetype.h> + + + /************************************************************************* + * + * @macro: + * FT_ERRORS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * list of FreeType~2 error codes (and messages). + * + * It is included by @FT_FREETYPE_H. + * + */ +#define FT_ERRORS_H <freetype/fterrors.h> + + + /************************************************************************* + * + * @macro: + * FT_MODULE_ERRORS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * list of FreeType~2 module error offsets (and messages). + * + */ +#define FT_MODULE_ERRORS_H <freetype/ftmoderr.h> + + + /************************************************************************* + * + * @macro: + * FT_SYSTEM_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 interface to low-level operations (i.e., memory management + * and stream i/o). + * + * It is included by @FT_FREETYPE_H. + * + */ +#define FT_SYSTEM_H <freetype/ftsystem.h> + + + /************************************************************************* + * + * @macro: + * FT_IMAGE_H + * + * @description: + * A macro used in #include statements to name the file containing type + * definitions related to glyph images (i.e., bitmaps, outlines, + * scan-converter parameters). + * + * It is included by @FT_FREETYPE_H. + * + */ +#define FT_IMAGE_H <freetype/ftimage.h> + + + /************************************************************************* + * + * @macro: + * FT_TYPES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * basic data types defined by FreeType~2. + * + * It is included by @FT_FREETYPE_H. + * + */ +#define FT_TYPES_H <freetype/fttypes.h> + + + /************************************************************************* + * + * @macro: + * FT_LIST_H + * + * @description: + * A macro used in #include statements to name the file containing the + * list management API of FreeType~2. + * + * (Most applications will never need to include this file.) + * + */ +#define FT_LIST_H <freetype/ftlist.h> + + + /************************************************************************* + * + * @macro: + * FT_OUTLINE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * scalable outline management API of FreeType~2. + * + */ +#define FT_OUTLINE_H <freetype/ftoutln.h> + + + /************************************************************************* + * + * @macro: + * FT_SIZES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API which manages multiple @FT_Size objects per face. + * + */ +#define FT_SIZES_H <freetype/ftsizes.h> + + + /************************************************************************* + * + * @macro: + * FT_MODULE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * module management API of FreeType~2. + * + */ +#define FT_MODULE_H <freetype/ftmodapi.h> + + + /************************************************************************* + * + * @macro: + * FT_RENDER_H + * + * @description: + * A macro used in #include statements to name the file containing the + * renderer module management API of FreeType~2. + * + */ +#define FT_RENDER_H <freetype/ftrender.h> + + + /************************************************************************* + * + * @macro: + * FT_AUTOHINTER_H + * + * @description: + * A macro used in #include statements to name the file containing + * structures and macros related to the auto-hinting module. + * + */ +#define FT_AUTOHINTER_H <freetype/ftautoh.h> + + + /************************************************************************* + * + * @macro: + * FT_CFF_DRIVER_H + * + * @description: + * A macro used in #include statements to name the file containing + * structures and macros related to the CFF driver module. + * + */ +#define FT_CFF_DRIVER_H <freetype/ftcffdrv.h> + + + /************************************************************************* + * + * @macro: + * FT_TRUETYPE_DRIVER_H + * + * @description: + * A macro used in #include statements to name the file containing + * structures and macros related to the TrueType driver module. + * + */ +#define FT_TRUETYPE_DRIVER_H <freetype/ftttdrv.h> + + + /************************************************************************* + * + * @macro: + * FT_TYPE1_TABLES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * types and API specific to the Type~1 format. + * + */ +#define FT_TYPE1_TABLES_H <freetype/t1tables.h> + + + /************************************************************************* + * + * @macro: + * FT_TRUETYPE_IDS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * enumeration values which identify name strings, languages, encodings, + * etc. This file really contains a _large_ set of constant macro + * definitions, taken from the TrueType and OpenType specifications. + * + */ +#define FT_TRUETYPE_IDS_H <freetype/ttnameid.h> + + + /************************************************************************* + * + * @macro: + * FT_TRUETYPE_TABLES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * types and API specific to the TrueType (as well as OpenType) format. + * + */ +#define FT_TRUETYPE_TABLES_H <freetype/tttables.h> + + + /************************************************************************* + * + * @macro: + * FT_TRUETYPE_TAGS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of TrueType four-byte `tags' which identify blocks in + * SFNT-based font formats (i.e., TrueType and OpenType). + * + */ +#define FT_TRUETYPE_TAGS_H <freetype/tttags.h> + + + /************************************************************************* + * + * @macro: + * FT_BDF_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which accesses BDF-specific strings from a + * face. + * + */ +#define FT_BDF_H <freetype/ftbdf.h> + + + /************************************************************************* + * + * @macro: + * FT_CID_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which access CID font information from a + * face. + * + */ +#define FT_CID_H <freetype/ftcid.h> + + + /************************************************************************* + * + * @macro: + * FT_GZIP_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which supports gzip-compressed files. + * + */ +#define FT_GZIP_H <freetype/ftgzip.h> + + + /************************************************************************* + * + * @macro: + * FT_LZW_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which supports LZW-compressed files. + * + */ +#define FT_LZW_H <freetype/ftlzw.h> + + + /************************************************************************* + * + * @macro: + * FT_BZIP2_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which supports bzip2-compressed files. + * + */ +#define FT_BZIP2_H <freetype/ftbzip2.h> + + + /************************************************************************* + * + * @macro: + * FT_WINFONTS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which supports Windows FNT files. + * + */ +#define FT_WINFONTS_H <freetype/ftwinfnt.h> + + + /************************************************************************* + * + * @macro: + * FT_GLYPH_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API of the optional glyph management component. + * + */ +#define FT_GLYPH_H <freetype/ftglyph.h> + + + /************************************************************************* + * + * @macro: + * FT_BITMAP_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API of the optional bitmap conversion component. + * + */ +#define FT_BITMAP_H <freetype/ftbitmap.h> + + + /************************************************************************* + * + * @macro: + * FT_BBOX_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API of the optional exact bounding box computation routines. + * + */ +#define FT_BBOX_H <freetype/ftbbox.h> + + + /************************************************************************* + * + * @macro: + * FT_CACHE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API of the optional FreeType~2 cache sub-system. + * + */ +#define FT_CACHE_H <freetype/ftcache.h> + + + /************************************************************************* + * + * @macro: + * FT_CACHE_IMAGE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * `glyph image' API of the FreeType~2 cache sub-system. + * + * It is used to define a cache for @FT_Glyph elements. You can also + * use the API defined in @FT_CACHE_SMALL_BITMAPS_H if you only need to + * store small glyph bitmaps, as it will use less memory. + * + * This macro is deprecated. Simply include @FT_CACHE_H to have all + * glyph image-related cache declarations. + * + */ +#define FT_CACHE_IMAGE_H FT_CACHE_H + + + /************************************************************************* + * + * @macro: + * FT_CACHE_SMALL_BITMAPS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * `small bitmaps' API of the FreeType~2 cache sub-system. + * + * It is used to define a cache for small glyph bitmaps in a relatively + * memory-efficient way. You can also use the API defined in + * @FT_CACHE_IMAGE_H if you want to cache arbitrary glyph images, + * including scalable outlines. + * + * This macro is deprecated. Simply include @FT_CACHE_H to have all + * small bitmaps-related cache declarations. + * + */ +#define FT_CACHE_SMALL_BITMAPS_H FT_CACHE_H + + + /************************************************************************* + * + * @macro: + * FT_CACHE_CHARMAP_H + * + * @description: + * A macro used in #include statements to name the file containing the + * `charmap' API of the FreeType~2 cache sub-system. + * + * This macro is deprecated. Simply include @FT_CACHE_H to have all + * charmap-based cache declarations. + * + */ +#define FT_CACHE_CHARMAP_H FT_CACHE_H + + + /************************************************************************* + * + * @macro: + * FT_MAC_H + * + * @description: + * A macro used in #include statements to name the file containing the + * Macintosh-specific FreeType~2 API. The latter is used to access + * fonts embedded in resource forks. + * + * This header file must be explicitly included by client applications + * compiled on the Mac (note that the base API still works though). + * + */ +#define FT_MAC_H <freetype/ftmac.h> + + + /************************************************************************* + * + * @macro: + * FT_MULTIPLE_MASTERS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * optional multiple-masters management API of FreeType~2. + * + */ +#define FT_MULTIPLE_MASTERS_H <freetype/ftmm.h> + + + /************************************************************************* + * + * @macro: + * FT_SFNT_NAMES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * optional FreeType~2 API which accesses embedded `name' strings in + * SFNT-based font formats (i.e., TrueType and OpenType). + * + */ +#define FT_SFNT_NAMES_H <freetype/ftsnames.h> + + + /************************************************************************* + * + * @macro: + * FT_OPENTYPE_VALIDATE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * optional FreeType~2 API which validates OpenType tables (BASE, GDEF, + * GPOS, GSUB, JSTF). + * + */ +#define FT_OPENTYPE_VALIDATE_H <freetype/ftotval.h> + + + /************************************************************************* + * + * @macro: + * FT_GX_VALIDATE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * optional FreeType~2 API which validates TrueTypeGX/AAT tables (feat, + * mort, morx, bsln, just, kern, opbd, trak, prop). + * + */ +#define FT_GX_VALIDATE_H <freetype/ftgxval.h> + + + /************************************************************************* + * + * @macro: + * FT_PFR_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which accesses PFR-specific data. + * + */ +#define FT_PFR_H <freetype/ftpfr.h> + + + /************************************************************************* + * + * @macro: + * FT_STROKER_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which provides functions to stroke outline paths. + */ +#define FT_STROKER_H <freetype/ftstroke.h> + + + /************************************************************************* + * + * @macro: + * FT_SYNTHESIS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which performs artificial obliquing and emboldening. + */ +#define FT_SYNTHESIS_H <freetype/ftsynth.h> + + + /************************************************************************* + * + * @macro: + * FT_FONT_FORMATS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which provides functions specific to font formats. + */ +#define FT_FONT_FORMATS_H <freetype/ftfntfmt.h> + + /* deprecated */ +#define FT_XFREE86_H FT_FONT_FORMATS_H + + + /************************************************************************* + * + * @macro: + * FT_TRIGONOMETRY_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which performs trigonometric computations (e.g., + * cosines and arc tangents). + */ +#define FT_TRIGONOMETRY_H <freetype/fttrigon.h> + + + /************************************************************************* + * + * @macro: + * FT_LCD_FILTER_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which performs color filtering for subpixel rendering. + */ +#define FT_LCD_FILTER_H <freetype/ftlcdfil.h> + + + /************************************************************************* + * + * @macro: + * FT_UNPATENTED_HINTING_H + * + * @description: + * Deprecated. + */ +#define FT_UNPATENTED_HINTING_H <freetype/ttunpat.h> + + + /************************************************************************* + * + * @macro: + * FT_INCREMENTAL_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which performs incremental glyph loading. + */ +#define FT_INCREMENTAL_H <freetype/ftincrem.h> + + + /************************************************************************* + * + * @macro: + * FT_GASP_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which returns entries from the TrueType GASP table. + */ +#define FT_GASP_H <freetype/ftgasp.h> + + + /************************************************************************* + * + * @macro: + * FT_ADVANCES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which returns individual and ranged glyph advances. + */ +#define FT_ADVANCES_H <freetype/ftadvanc.h> + + + /* */ + +#define FT_ERROR_DEFINITIONS_H <freetype/fterrdef.h> + + + /* The internals of the cache sub-system are no longer exposed. We */ + /* default to FT_CACHE_H at the moment just in case, but we know of */ + /* no rogue client that uses them. */ + /* */ +#define FT_CACHE_MANAGER_H <freetype/ftcache.h> +#define FT_CACHE_INTERNAL_MRU_H <freetype/ftcache.h> +#define FT_CACHE_INTERNAL_MANAGER_H <freetype/ftcache.h> +#define FT_CACHE_INTERNAL_CACHE_H <freetype/ftcache.h> +#define FT_CACHE_INTERNAL_GLYPH_H <freetype/ftcache.h> +#define FT_CACHE_INTERNAL_IMAGE_H <freetype/ftcache.h> +#define FT_CACHE_INTERNAL_SBITS_H <freetype/ftcache.h> + + +#define FT_INCREMENTAL_H <freetype/ftincrem.h> + +#define FT_TRUETYPE_UNPATENTED_H <freetype/ttunpat.h> + + + /* + * Include internal headers definitions from <internal/...> + * only when building the library. + */ +#ifdef FT2_BUILD_LIBRARY +#define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h> +#include FT_INTERNAL_INTERNAL_H +#endif /* FT2_BUILD_LIBRARY */ + + +#endif /* FTHEADER_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/config/ftmodule.h b/android/x86/include/freetype/config/ftmodule.h new file mode 100644 index 00000000..b7299779 --- /dev/null +++ b/android/x86/include/freetype/config/ftmodule.h @@ -0,0 +1,20 @@ +/* This is a generated file. */ +FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, pfr_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, t42_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, winfnt_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class ) +FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) +FT_USE_MODULE( FT_Module_Class, autofit_module_class ) +FT_USE_MODULE( FT_Module_Class, pshinter_module_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class ) +FT_USE_MODULE( FT_Module_Class, psaux_module_class ) +FT_USE_MODULE( FT_Module_Class, psnames_module_class ) +/* EOF */ diff --git a/android/x86/include/freetype/config/ftoption.h b/android/x86/include/freetype/config/ftoption.h new file mode 100644 index 00000000..a8097feb --- /dev/null +++ b/android/x86/include/freetype/config/ftoption.h @@ -0,0 +1,851 @@ +/***************************************************************************/ +/* */ +/* ftoption.h */ +/* */ +/* User-selectable configuration macros (specification only). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTOPTION_H_ +#define FTOPTION_H_ + + +#include <ft2build.h> + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* USER-SELECTABLE CONFIGURATION MACROS */ + /* */ + /* This file contains the default configuration macro definitions for */ + /* a standard build of the FreeType library. There are three ways to */ + /* use this file to build project-specific versions of the library: */ + /* */ + /* - You can modify this file by hand, but this is not recommended in */ + /* cases where you would like to build several versions of the */ + /* library from a single source directory. */ + /* */ + /* - You can put a copy of this file in your build directory, more */ + /* precisely in `$BUILD/freetype/config/ftoption.h', where `$BUILD' */ + /* is the name of a directory that is included _before_ the FreeType */ + /* include path during compilation. */ + /* */ + /* The default FreeType Makefiles and Jamfiles use the build */ + /* directory `builds/<system>' by default, but you can easily change */ + /* that for your own projects. */ + /* */ + /* - Copy the file <ft2build.h> to `$BUILD/ft2build.h' and modify it */ + /* slightly to pre-define the macro FT_CONFIG_OPTIONS_H used to */ + /* locate this file during the build. For example, */ + /* */ + /* #define FT_CONFIG_OPTIONS_H <myftoptions.h> */ + /* #include <freetype/config/ftheader.h> */ + /* */ + /* will use `$BUILD/myftoptions.h' instead of this file for macro */ + /* definitions. */ + /* */ + /* Note also that you can similarly pre-define the macro */ + /* FT_CONFIG_MODULES_H used to locate the file listing of the modules */ + /* that are statically linked to the library at compile time. By */ + /* default, this file is <freetype/config/ftmodule.h>. */ + /* */ + /* We highly recommend using the third method whenever possible. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** G E N E R A L F R E E T Y P E 2 C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Uncomment the line below if you want to activate sub-pixel rendering */ + /* (a.k.a. LCD rendering, or ClearType) in this build of the library. */ + /* */ + /* Note that this feature is covered by several Microsoft patents */ + /* and should not be activated in any default build of the library. */ + /* */ + /* This macro has no impact on the FreeType API, only on its */ + /* _implementation_. For example, using FT_RENDER_MODE_LCD when calling */ + /* FT_Render_Glyph still generates a bitmap that is 3 times wider than */ + /* the original size in case this macro isn't defined; however, each */ + /* triplet of subpixels has R=G=B. */ + /* */ + /* This is done to allow FreeType clients to run unmodified, forcing */ + /* them to display normal gray-level anti-aliased glyphs. */ + /* */ +/* #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ + + + /*************************************************************************/ + /* */ + /* Many compilers provide a non-ANSI 64-bit data type that can be used */ + /* by FreeType to speed up some computations. However, this will create */ + /* some problems when compiling the library in strict ANSI mode. */ + /* */ + /* For this reason, the use of 64-bit integers is normally disabled when */ + /* the __STDC__ macro is defined. You can however disable this by */ + /* defining the macro FT_CONFIG_OPTION_FORCE_INT64 here. */ + /* */ + /* For most compilers, this will only create compilation warnings when */ + /* building the library. */ + /* */ + /* ObNote: The compiler-specific 64-bit integers are detected in the */ + /* file `ftconfig.h' either statically or through the */ + /* `configure' script on supported platforms. */ + /* */ +#undef FT_CONFIG_OPTION_FORCE_INT64 + + + /*************************************************************************/ + /* */ + /* If this macro is defined, do not try to use an assembler version of */ + /* performance-critical functions (e.g. FT_MulFix). You should only do */ + /* that to verify that the assembler function works properly, or to */ + /* execute benchmark tests of the various implementations. */ +/* #define FT_CONFIG_OPTION_NO_ASSEMBLER */ + + + /*************************************************************************/ + /* */ + /* If this macro is defined, try to use an inlined assembler version of */ + /* the `FT_MulFix' function, which is a `hotspot' when loading and */ + /* hinting glyphs, and which should be executed as fast as possible. */ + /* */ + /* Note that if your compiler or CPU is not supported, this will default */ + /* to the standard and portable implementation found in `ftcalc.c'. */ + /* */ +#define FT_CONFIG_OPTION_INLINE_MULFIX + + + /*************************************************************************/ + /* */ + /* LZW-compressed file support. */ + /* */ + /* FreeType now handles font files that have been compressed with the */ + /* `compress' program. This is mostly used to parse many of the PCF */ + /* files that come with various X11 distributions. The implementation */ + /* uses NetBSD's `zopen' to partially uncompress the file on the fly */ + /* (see src/lzw/ftgzip.c). */ + /* */ + /* Define this macro if you want to enable this `feature'. */ + /* */ +#define FT_CONFIG_OPTION_USE_LZW + + + /*************************************************************************/ + /* */ + /* Gzip-compressed file support. */ + /* */ + /* FreeType now handles font files that have been compressed with the */ + /* `gzip' program. This is mostly used to parse many of the PCF files */ + /* that come with XFree86. The implementation uses `zlib' to */ + /* partially uncompress the file on the fly (see src/gzip/ftgzip.c). */ + /* */ + /* Define this macro if you want to enable this `feature'. See also */ + /* the macro FT_CONFIG_OPTION_SYSTEM_ZLIB below. */ + /* */ +#define FT_CONFIG_OPTION_USE_ZLIB + + + /*************************************************************************/ + /* */ + /* ZLib library selection */ + /* */ + /* This macro is only used when FT_CONFIG_OPTION_USE_ZLIB is defined. */ + /* It allows FreeType's `ftgzip' component to link to the system's */ + /* installation of the ZLib library. This is useful on systems like */ + /* Unix or VMS where it generally is already available. */ + /* */ + /* If you let it undefined, the component will use its own copy */ + /* of the zlib sources instead. These have been modified to be */ + /* included directly within the component and *not* export external */ + /* function names. This allows you to link any program with FreeType */ + /* _and_ ZLib without linking conflicts. */ + /* */ + /* Do not #undef this macro here since the build system might define */ + /* it for certain configurations only. */ + /* */ +/* #define FT_CONFIG_OPTION_SYSTEM_ZLIB */ + + + /*************************************************************************/ + /* */ + /* Bzip2-compressed file support. */ + /* */ + /* FreeType now handles font files that have been compressed with the */ + /* `bzip2' program. This is mostly used to parse many of the PCF */ + /* files that come with XFree86. The implementation uses `libbz2' to */ + /* partially uncompress the file on the fly (see src/bzip2/ftbzip2.c). */ + /* Contrary to gzip, bzip2 currently is not included and need to use */ + /* the system available bzip2 implementation. */ + /* */ + /* Define this macro if you want to enable this `feature'. */ + /* */ +/* #define FT_CONFIG_OPTION_USE_BZIP2 */ + + + /*************************************************************************/ + /* */ + /* Define to disable the use of file stream functions and types, FILE, */ + /* fopen() etc. Enables the use of smaller system libraries on embedded */ + /* systems that have multiple system libraries, some with or without */ + /* file stream support, in the cases where file stream support is not */ + /* necessary such as memory loading of font files. */ + /* */ +/* #define FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT */ + + + /*************************************************************************/ + /* */ + /* PNG bitmap support. */ + /* */ + /* FreeType now handles loading color bitmap glyphs in the PNG format. */ + /* This requires help from the external libpng library. Uncompressed */ + /* color bitmaps do not need any external libraries and will be */ + /* supported regardless of this configuration. */ + /* */ + /* Define this macro if you want to enable this `feature'. */ + /* */ +/* #define FT_CONFIG_OPTION_USE_PNG */ + + + /*************************************************************************/ + /* */ + /* HarfBuzz support. */ + /* */ + /* FreeType uses the HarfBuzz library to improve auto-hinting of */ + /* OpenType fonts. If available, many glyphs not directly addressable */ + /* by a font's character map will be hinted also. */ + /* */ + /* Define this macro if you want to enable this `feature'. */ + /* */ +/* #define FT_CONFIG_OPTION_USE_HARFBUZZ */ + + + /*************************************************************************/ + /* */ + /* DLL export compilation */ + /* */ + /* When compiling FreeType as a DLL, some systems/compilers need a */ + /* special keyword in front OR after the return type of function */ + /* declarations. */ + /* */ + /* Two macros are used within the FreeType source code to define */ + /* exported library functions: FT_EXPORT and FT_EXPORT_DEF. */ + /* */ + /* FT_EXPORT( return_type ) */ + /* */ + /* is used in a function declaration, as in */ + /* */ + /* FT_EXPORT( FT_Error ) */ + /* FT_Init_FreeType( FT_Library* alibrary ); */ + /* */ + /* */ + /* FT_EXPORT_DEF( return_type ) */ + /* */ + /* is used in a function definition, as in */ + /* */ + /* FT_EXPORT_DEF( FT_Error ) */ + /* FT_Init_FreeType( FT_Library* alibrary ) */ + /* { */ + /* ... some code ... */ + /* return FT_Err_Ok; */ + /* } */ + /* */ + /* You can provide your own implementation of FT_EXPORT and */ + /* FT_EXPORT_DEF here if you want. If you leave them undefined, they */ + /* will be later automatically defined as `extern return_type' to */ + /* allow normal compilation. */ + /* */ + /* Do not #undef these macros here since the build system might define */ + /* them for certain configurations only. */ + /* */ +/* #define FT_EXPORT(x) extern x */ +/* #define FT_EXPORT_DEF(x) x */ + + + /*************************************************************************/ + /* */ + /* Glyph Postscript Names handling */ + /* */ + /* By default, FreeType 2 is compiled with the `psnames' module. This */ + /* module is in charge of converting a glyph name string into a */ + /* Unicode value, or return a Macintosh standard glyph name for the */ + /* use with the TrueType `post' table. */ + /* */ + /* Undefine this macro if you do not want `psnames' compiled in your */ + /* build of FreeType. This has the following effects: */ + /* */ + /* - The TrueType driver will provide its own set of glyph names, */ + /* if you build it to support postscript names in the TrueType */ + /* `post' table. */ + /* */ + /* - The Type 1 driver will not be able to synthesize a Unicode */ + /* charmap out of the glyphs found in the fonts. */ + /* */ + /* You would normally undefine this configuration macro when building */ + /* a version of FreeType that doesn't contain a Type 1 or CFF driver. */ + /* */ +#define FT_CONFIG_OPTION_POSTSCRIPT_NAMES + + + /*************************************************************************/ + /* */ + /* Postscript Names to Unicode Values support */ + /* */ + /* By default, FreeType 2 is built with the `PSNames' module compiled */ + /* in. Among other things, the module is used to convert a glyph name */ + /* into a Unicode value. This is especially useful in order to */ + /* synthesize on the fly a Unicode charmap from the CFF/Type 1 driver */ + /* through a big table named the `Adobe Glyph List' (AGL). */ + /* */ + /* Undefine this macro if you do not want the Adobe Glyph List */ + /* compiled in your `PSNames' module. The Type 1 driver will not be */ + /* able to synthesize a Unicode charmap out of the glyphs found in the */ + /* fonts. */ + /* */ +#define FT_CONFIG_OPTION_ADOBE_GLYPH_LIST + + + /*************************************************************************/ + /* */ + /* Support for Mac fonts */ + /* */ + /* Define this macro if you want support for outline fonts in Mac */ + /* format (mac dfont, mac resource, macbinary containing a mac */ + /* resource) on non-Mac platforms. */ + /* */ + /* Note that the `FOND' resource isn't checked. */ + /* */ +#define FT_CONFIG_OPTION_MAC_FONTS + + + /*************************************************************************/ + /* */ + /* Guessing methods to access embedded resource forks */ + /* */ + /* Enable extra Mac fonts support on non-Mac platforms (e.g. */ + /* GNU/Linux). */ + /* */ + /* Resource forks which include fonts data are stored sometimes in */ + /* locations which users or developers don't expected. In some cases, */ + /* resource forks start with some offset from the head of a file. In */ + /* other cases, the actual resource fork is stored in file different */ + /* from what the user specifies. If this option is activated, */ + /* FreeType tries to guess whether such offsets or different file */ + /* names must be used. */ + /* */ + /* Note that normal, direct access of resource forks is controlled via */ + /* the FT_CONFIG_OPTION_MAC_FONTS option. */ + /* */ +#ifdef FT_CONFIG_OPTION_MAC_FONTS +#define FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK +#endif + + + /*************************************************************************/ + /* */ + /* Allow the use of FT_Incremental_Interface to load typefaces that */ + /* contain no glyph data, but supply it via a callback function. */ + /* This is required by clients supporting document formats which */ + /* supply font data incrementally as the document is parsed, such */ + /* as the Ghostscript interpreter for the PostScript language. */ + /* */ +#define FT_CONFIG_OPTION_INCREMENTAL + + + /*************************************************************************/ + /* */ + /* The size in bytes of the render pool used by the scan-line converter */ + /* to do all of its work. */ + /* */ +#define FT_RENDER_POOL_SIZE 16384L + + + /*************************************************************************/ + /* */ + /* FT_MAX_MODULES */ + /* */ + /* The maximum number of modules that can be registered in a single */ + /* FreeType library object. 32 is the default. */ + /* */ +#define FT_MAX_MODULES 32 + + + /*************************************************************************/ + /* */ + /* Debug level */ + /* */ + /* FreeType can be compiled in debug or trace mode. In debug mode, */ + /* errors are reported through the `ftdebug' component. In trace */ + /* mode, additional messages are sent to the standard output during */ + /* execution. */ + /* */ + /* Define FT_DEBUG_LEVEL_ERROR to build the library in debug mode. */ + /* Define FT_DEBUG_LEVEL_TRACE to build it in trace mode. */ + /* */ + /* Don't define any of these macros to compile in `release' mode! */ + /* */ + /* Do not #undef these macros here since the build system might define */ + /* them for certain configurations only. */ + /* */ +/* #define FT_DEBUG_LEVEL_ERROR */ +/* #define FT_DEBUG_LEVEL_TRACE */ + + + /*************************************************************************/ + /* */ + /* Autofitter debugging */ + /* */ + /* If FT_DEBUG_AUTOFIT is defined, FreeType provides some means to */ + /* control the autofitter behaviour for debugging purposes with global */ + /* boolean variables (consequently, you should *never* enable this */ + /* while compiling in `release' mode): */ + /* */ + /* _af_debug_disable_horz_hints */ + /* _af_debug_disable_vert_hints */ + /* _af_debug_disable_blue_hints */ + /* */ + /* Additionally, the following functions provide dumps of various */ + /* internal autofit structures to stdout (using `printf'): */ + /* */ + /* af_glyph_hints_dump_points */ + /* af_glyph_hints_dump_segments */ + /* af_glyph_hints_dump_edges */ + /* af_glyph_hints_get_num_segments */ + /* af_glyph_hints_get_segment_offset */ + /* */ + /* As an argument, they use another global variable: */ + /* */ + /* _af_debug_hints */ + /* */ + /* Please have a look at the `ftgrid' demo program to see how those */ + /* variables and macros should be used. */ + /* */ + /* Do not #undef these macros here since the build system might define */ + /* them for certain configurations only. */ + /* */ +/* #define FT_DEBUG_AUTOFIT */ + + + /*************************************************************************/ + /* */ + /* Memory Debugging */ + /* */ + /* FreeType now comes with an integrated memory debugger that is */ + /* capable of detecting simple errors like memory leaks or double */ + /* deletes. To compile it within your build of the library, you */ + /* should define FT_DEBUG_MEMORY here. */ + /* */ + /* Note that the memory debugger is only activated at runtime when */ + /* when the _environment_ variable `FT2_DEBUG_MEMORY' is defined also! */ + /* */ + /* Do not #undef this macro here since the build system might define */ + /* it for certain configurations only. */ + /* */ +/* #define FT_DEBUG_MEMORY */ + + + /*************************************************************************/ + /* */ + /* Module errors */ + /* */ + /* If this macro is set (which is _not_ the default), the higher byte */ + /* of an error code gives the module in which the error has occurred, */ + /* while the lower byte is the real error code. */ + /* */ + /* Setting this macro makes sense for debugging purposes only, since */ + /* it would break source compatibility of certain programs that use */ + /* FreeType 2. */ + /* */ + /* More details can be found in the files ftmoderr.h and fterrors.h. */ + /* */ +#undef FT_CONFIG_OPTION_USE_MODULE_ERRORS + + + /*************************************************************************/ + /* */ + /* Position Independent Code */ + /* */ + /* If this macro is set (which is _not_ the default), FreeType2 will */ + /* avoid creating constants that require address fixups. Instead the */ + /* constants will be moved into a struct and additional intialization */ + /* code will be used. */ + /* */ + /* Setting this macro is needed for systems that prohibit address */ + /* fixups, such as BREW. */ + /* */ +/* #define FT_CONFIG_OPTION_PIC */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** S F N T D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_EMBEDDED_BITMAPS if you want to support */ + /* embedded bitmaps in all formats using the SFNT module (namely */ + /* TrueType & OpenType). */ + /* */ +#define TT_CONFIG_OPTION_EMBEDDED_BITMAPS + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_POSTSCRIPT_NAMES if you want to be able to */ + /* load and enumerate the glyph Postscript names in a TrueType or */ + /* OpenType file. */ + /* */ + /* Note that when you do not compile the `PSNames' module by undefining */ + /* the above FT_CONFIG_OPTION_POSTSCRIPT_NAMES, the `sfnt' module will */ + /* contain additional code used to read the PS Names table from a font. */ + /* */ + /* (By default, the module uses `PSNames' to extract glyph names.) */ + /* */ +#define TT_CONFIG_OPTION_POSTSCRIPT_NAMES + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_SFNT_NAMES if your applications need to */ + /* access the internal name table in a SFNT-based format like TrueType */ + /* or OpenType. The name table contains various strings used to */ + /* describe the font, like family name, copyright, version, etc. It */ + /* does not contain any glyph name though. */ + /* */ + /* Accessing SFNT names is done through the functions declared in */ + /* `ftsnames.h'. */ + /* */ +#define TT_CONFIG_OPTION_SFNT_NAMES + + + /*************************************************************************/ + /* */ + /* TrueType CMap support */ + /* */ + /* Here you can fine-tune which TrueType CMap table format shall be */ + /* supported. */ +#define TT_CONFIG_CMAP_FORMAT_0 +#define TT_CONFIG_CMAP_FORMAT_2 +#define TT_CONFIG_CMAP_FORMAT_4 +#define TT_CONFIG_CMAP_FORMAT_6 +#define TT_CONFIG_CMAP_FORMAT_8 +#define TT_CONFIG_CMAP_FORMAT_10 +#define TT_CONFIG_CMAP_FORMAT_12 +#define TT_CONFIG_CMAP_FORMAT_13 +#define TT_CONFIG_CMAP_FORMAT_14 + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** T R U E T Y P E D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_BYTECODE_INTERPRETER if you want to compile */ + /* a bytecode interpreter in the TrueType driver. */ + /* */ + /* By undefining this, you will only compile the code necessary to load */ + /* TrueType glyphs without hinting. */ + /* */ + /* Do not #undef this macro here, since the build system might */ + /* define it for certain configurations only. */ + /* */ +#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_SUBPIXEL_HINTING if you want to compile */ + /* EXPERIMENTAL subpixel hinting support into the TrueType driver. This */ + /* replaces the native TrueType hinting mechanism when anything but */ + /* FT_RENDER_MODE_MONO is requested. */ + /* */ + /* Enabling this causes the TrueType driver to ignore instructions under */ + /* certain conditions. This is done in accordance with the guide here, */ + /* with some minor differences: */ + /* */ + /* http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx */ + /* */ + /* By undefining this, you only compile the code necessary to hint */ + /* TrueType glyphs with native TT hinting. */ + /* */ + /* This option requires TT_CONFIG_OPTION_BYTECODE_INTERPRETER to be */ + /* defined. */ + /* */ +/* #define TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED to compile the */ + /* TrueType glyph loader to use Apple's definition of how to handle */ + /* component offsets in composite glyphs. */ + /* */ + /* Apple and MS disagree on the default behavior of component offsets */ + /* in composites. Apple says that they should be scaled by the scaling */ + /* factors in the transformation matrix (roughly, it's more complex) */ + /* while MS says they should not. OpenType defines two bits in the */ + /* composite flags array which can be used to disambiguate, but old */ + /* fonts will not have them. */ + /* */ + /* http://www.microsoft.com/typography/otspec/glyf.htm */ + /* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html */ + /* */ +#undef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_GX_VAR_SUPPORT if you want to include */ + /* support for Apple's distortable font technology (fvar, gvar, cvar, */ + /* and avar tables). This has many similarities to Type 1 Multiple */ + /* Masters support. */ + /* */ +#define TT_CONFIG_OPTION_GX_VAR_SUPPORT + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_BDF if you want to include support for */ + /* an embedded `BDF ' table within SFNT-based bitmap formats. */ + /* */ +#define TT_CONFIG_OPTION_BDF + + + /*************************************************************************/ + /* */ + /* Option TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES controls the maximum */ + /* number of bytecode instructions executed for a single run of the */ + /* bytecode interpreter, needed to prevent infinite loops. You don't */ + /* want to change this except for very special situations (e.g., making */ + /* a library fuzzer spend less time to handle broken fonts). */ + /* */ + /* It is not expected that this value is ever modified by a configuring */ + /* script; instead, it gets surrounded with #ifndef ... #endif so that */ + /* the value can be set as a preprocessor option on the compiler's */ + /* command line. */ + /* */ +#ifndef TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES +#define TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES 1000000L +#endif + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** T Y P E 1 D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* T1_MAX_DICT_DEPTH is the maximum depth of nest dictionaries and */ + /* arrays in the Type 1 stream (see t1load.c). A minimum of 4 is */ + /* required. */ + /* */ +#define T1_MAX_DICT_DEPTH 5 + + + /*************************************************************************/ + /* */ + /* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */ + /* calls during glyph loading. */ + /* */ +#define T1_MAX_SUBRS_CALLS 16 + + + /*************************************************************************/ + /* */ + /* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */ + /* minimum of 16 is required. */ + /* */ + /* The Chinese font MingTiEG-Medium (CNS 11643 character set) needs 256. */ + /* */ +#define T1_MAX_CHARSTRINGS_OPERANDS 256 + + + /*************************************************************************/ + /* */ + /* Define this configuration macro if you want to prevent the */ + /* compilation of `t1afm', which is in charge of reading Type 1 AFM */ + /* files into an existing face. Note that if set, the T1 driver will be */ + /* unable to produce kerning distances. */ + /* */ +#undef T1_CONFIG_OPTION_NO_AFM + + + /*************************************************************************/ + /* */ + /* Define this configuration macro if you want to prevent the */ + /* compilation of the Multiple Masters font support in the Type 1 */ + /* driver. */ + /* */ +#undef T1_CONFIG_OPTION_NO_MM_SUPPORT + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** C F F D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Using CFF_CONFIG_OPTION_DARKENING_PARAMETER_{X,Y}{1,2,3,4} it is */ + /* possible to set up the default values of the four control points that */ + /* define the stem darkening behaviour of the (new) CFF engine. For */ + /* more details please read the documentation of the */ + /* `darkening-parameters' property of the cff driver module (file */ + /* `ftcffdrv.h'), which allows the control at run-time. */ + /* */ + /* Do *not* undefine these macros! */ + /* */ +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 500 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 400 + +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 1000 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 275 + +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 1667 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 275 + +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 2333 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 0 + + + /*************************************************************************/ + /* */ + /* CFF_CONFIG_OPTION_OLD_ENGINE controls whether the pre-Adobe CFF */ + /* engine gets compiled into FreeType. If defined, it is possible to */ + /* switch between the two engines using the `hinting-engine' property of */ + /* the cff driver module. */ + /* */ +/* #define CFF_CONFIG_OPTION_OLD_ENGINE */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** A U T O F I T M O D U L E C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Compile autofit module with CJK (Chinese, Japanese, Korean) script */ + /* support. */ + /* */ +#define AF_CONFIG_OPTION_CJK + + /*************************************************************************/ + /* */ + /* Compile autofit module with Indic script support. */ + /* */ +#define AF_CONFIG_OPTION_INDIC + + /*************************************************************************/ + /* */ + /* Compile autofit module with warp hinting. The idea of the warping */ + /* code is to slightly scale and shift a glyph within a single dimension */ + /* so that as much of its segments are aligned (more or less) on the */ + /* grid. To find out the optimal scaling and shifting value, various */ + /* parameter combinations are tried and scored. */ + /* */ + /* This experimental option is active only if the rendering mode is */ + /* FT_RENDER_MODE_LIGHT; you can switch warping on and off with the */ + /* `warping' property of the auto-hinter (see file `ftautoh.h' for more */ + /* information; by default it is switched off). */ + /* */ +#define AF_CONFIG_OPTION_USE_WARPER + + /* */ + + + /* + * This macro is obsolete. Support has been removed in FreeType + * version 2.5. + */ +/* #define FT_CONFIG_OPTION_OLD_INTERNALS */ + + + /* + * This macro is defined if native TrueType hinting is requested by the + * definitions above. + */ +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER +#define TT_USE_BYTECODE_INTERPRETER +#endif + + + /* + * Check CFF darkening parameters. The checks are the same as in function + * `cff_property_set' in file `cffdrivr.c'. + */ +#if CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 < 0 || \ + \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 < 0 || \ + \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 > \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 > \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 > \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 || \ + \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 > 500 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 > 500 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 > 500 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 > 500 +#error "Invalid CFF darkening parameters!" +#endif + +FT_END_HEADER + + +#endif /* FTOPTION_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/config/ftstdlib.h b/android/x86/include/freetype/config/ftstdlib.h new file mode 100644 index 00000000..9daea56f --- /dev/null +++ b/android/x86/include/freetype/config/ftstdlib.h @@ -0,0 +1,173 @@ +/***************************************************************************/ +/* */ +/* ftstdlib.h */ +/* */ +/* ANSI-specific library and header configuration file (specification */ +/* only). */ +/* */ +/* Copyright 2002-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This file is used to group all #includes to the ANSI C library that */ + /* FreeType normally requires. It also defines macros to rename the */ + /* standard functions within the FreeType source code. */ + /* */ + /* Load a file which defines FTSTDLIB_H_ before this one to override it. */ + /* */ + /*************************************************************************/ + + +#ifndef FTSTDLIB_H_ +#define FTSTDLIB_H_ + + +#include <stddef.h> + +#define ft_ptrdiff_t ptrdiff_t + + + /**********************************************************************/ + /* */ + /* integer limits */ + /* */ + /* UINT_MAX and ULONG_MAX are used to automatically compute the size */ + /* of `int' and `long' in bytes at compile-time. So far, this works */ + /* for all platforms the library has been tested on. */ + /* */ + /* Note that on the extremely rare platforms that do not provide */ + /* integer types that are _exactly_ 16 and 32 bits wide (e.g. some */ + /* old Crays where `int' is 36 bits), we do not make any guarantee */ + /* about the correct behaviour of FT2 with all fonts. */ + /* */ + /* In these case, `ftconfig.h' will refuse to compile anyway with a */ + /* message like `couldn't find 32-bit type' or something similar. */ + /* */ + /**********************************************************************/ + + +#include <limits.h> + +#define FT_CHAR_BIT CHAR_BIT +#define FT_USHORT_MAX USHRT_MAX +#define FT_INT_MAX INT_MAX +#define FT_INT_MIN INT_MIN +#define FT_UINT_MAX UINT_MAX +#define FT_LONG_MAX LONG_MAX +#define FT_ULONG_MAX ULONG_MAX + + + /**********************************************************************/ + /* */ + /* character and string processing */ + /* */ + /**********************************************************************/ + + +#include <string.h> + +#define ft_memchr memchr +#define ft_memcmp memcmp +#define ft_memcpy memcpy +#define ft_memmove memmove +#define ft_memset memset +#define ft_strcat strcat +#define ft_strcmp strcmp +#define ft_strcpy strcpy +#define ft_strlen strlen +#define ft_strncmp strncmp +#define ft_strncpy strncpy +#define ft_strrchr strrchr +#define ft_strstr strstr + + + /**********************************************************************/ + /* */ + /* file handling */ + /* */ + /**********************************************************************/ + + +#include <stdio.h> + +#define FT_FILE FILE +#define ft_fclose fclose +#define ft_fopen fopen +#define ft_fread fread +#define ft_fseek fseek +#define ft_ftell ftell +#define ft_sprintf sprintf + + + /**********************************************************************/ + /* */ + /* sorting */ + /* */ + /**********************************************************************/ + + +#include <stdlib.h> + +#define ft_qsort qsort + + + /**********************************************************************/ + /* */ + /* memory allocation */ + /* */ + /**********************************************************************/ + + +#define ft_scalloc calloc +#define ft_sfree free +#define ft_smalloc malloc +#define ft_srealloc realloc + + + /**********************************************************************/ + /* */ + /* miscellaneous */ + /* */ + /**********************************************************************/ + + +#define ft_atol atol + + + /**********************************************************************/ + /* */ + /* execution control */ + /* */ + /**********************************************************************/ + + +#include <setjmp.h> + +#define ft_jmp_buf jmp_buf /* note: this cannot be a typedef since */ + /* jmp_buf is defined as a macro */ + /* on certain platforms */ + +#define ft_longjmp longjmp +#define ft_setjmp( b ) setjmp( *(ft_jmp_buf*) &(b) ) /* same thing here */ + + + /* the following is only used for debugging purposes, i.e., if */ + /* FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined */ + +#include <stdarg.h> + + +#endif /* FTSTDLIB_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/freetype.h b/android/x86/include/freetype/freetype.h new file mode 100644 index 00000000..4666d489 --- /dev/null +++ b/android/x86/include/freetype/freetype.h @@ -0,0 +1,4272 @@ +/***************************************************************************/ +/* */ +/* freetype.h */ +/* */ +/* FreeType high-level API and common types (specification only). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FREETYPE_H_ +#define FREETYPE_H_ + + +#ifndef FT_FREETYPE_H +#error "`ft2build.h' hasn't been included yet!" +#error "Please always use macros to include FreeType header files." +#error "Example:" +#error " #include <ft2build.h>" +#error " #include FT_FREETYPE_H" +#endif + + +#include <ft2build.h> +#include FT_CONFIG_CONFIG_H +#include FT_TYPES_H +#include FT_ERRORS_H + + +FT_BEGIN_HEADER + + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* header_inclusion */ + /* */ + /* <Title> */ + /* FreeType's header inclusion scheme */ + /* */ + /* <Abstract> */ + /* How client applications should include FreeType header files. */ + /* */ + /* <Description> */ + /* To be as flexible as possible (and for historical reasons), */ + /* FreeType uses a very special inclusion scheme to load header */ + /* files, for example */ + /* */ + /* { */ + /* #include <ft2build.h> */ + /* */ + /* #include FT_FREETYPE_H */ + /* #include FT_OUTLINE_H */ + /* } */ + /* */ + /* A compiler and its preprocessor only needs an include path to find */ + /* the file `ft2build.h'; the exact locations and names of the other */ + /* FreeType header files are hidden by preprocessor macro names, */ + /* loaded by `ft2build.h'. The API documentation always gives the */ + /* header macro name needed for a particular function. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* user_allocation */ + /* */ + /* <Title> */ + /* User allocation */ + /* */ + /* <Abstract> */ + /* How client applications should allocate FreeType data structures. */ + /* */ + /* <Description> */ + /* FreeType assumes that structures allocated by the user and passed */ + /* as arguments are zeroed out except for the actual data. In other */ + /* words, it is recommended to use `calloc' (or variants of it) */ + /* instead of `malloc' for allocation. */ + /* */ + /*************************************************************************/ + + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* B A S I C T Y P E S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* base_interface */ + /* */ + /* <Title> */ + /* Base Interface */ + /* */ + /* <Abstract> */ + /* The FreeType~2 base font interface. */ + /* */ + /* <Description> */ + /* This section describes the most important public high-level API */ + /* functions of FreeType~2. */ + /* */ + /* <Order> */ + /* FT_Library */ + /* FT_Face */ + /* FT_Size */ + /* FT_GlyphSlot */ + /* FT_CharMap */ + /* FT_Encoding */ + /* FT_ENC_TAG */ + /* */ + /* FT_FaceRec */ + /* */ + /* FT_FACE_FLAG_SCALABLE */ + /* FT_FACE_FLAG_FIXED_SIZES */ + /* FT_FACE_FLAG_FIXED_WIDTH */ + /* FT_FACE_FLAG_HORIZONTAL */ + /* FT_FACE_FLAG_VERTICAL */ + /* FT_FACE_FLAG_COLOR */ + /* FT_FACE_FLAG_SFNT */ + /* FT_FACE_FLAG_CID_KEYED */ + /* FT_FACE_FLAG_TRICKY */ + /* FT_FACE_FLAG_KERNING */ + /* FT_FACE_FLAG_MULTIPLE_MASTERS */ + /* FT_FACE_FLAG_GLYPH_NAMES */ + /* FT_FACE_FLAG_EXTERNAL_STREAM */ + /* FT_FACE_FLAG_HINTER */ + /* */ + /* FT_HAS_HORIZONTAL */ + /* FT_HAS_VERTICAL */ + /* FT_HAS_KERNING */ + /* FT_HAS_FIXED_SIZES */ + /* FT_HAS_GLYPH_NAMES */ + /* FT_HAS_MULTIPLE_MASTERS */ + /* FT_HAS_COLOR */ + /* */ + /* FT_IS_SFNT */ + /* FT_IS_SCALABLE */ + /* FT_IS_FIXED_WIDTH */ + /* FT_IS_CID_KEYED */ + /* FT_IS_TRICKY */ + /* */ + /* FT_STYLE_FLAG_BOLD */ + /* FT_STYLE_FLAG_ITALIC */ + /* */ + /* FT_SizeRec */ + /* FT_Size_Metrics */ + /* */ + /* FT_GlyphSlotRec */ + /* FT_Glyph_Metrics */ + /* FT_SubGlyph */ + /* */ + /* FT_Bitmap_Size */ + /* */ + /* FT_Init_FreeType */ + /* FT_Done_FreeType */ + /* */ + /* FT_New_Face */ + /* FT_Done_Face */ + /* FT_Reference_Face */ + /* FT_New_Memory_Face */ + /* FT_Open_Face */ + /* FT_Open_Args */ + /* FT_Parameter */ + /* FT_Attach_File */ + /* FT_Attach_Stream */ + /* */ + /* FT_Set_Char_Size */ + /* FT_Set_Pixel_Sizes */ + /* FT_Request_Size */ + /* FT_Select_Size */ + /* FT_Size_Request_Type */ + /* FT_Size_RequestRec */ + /* FT_Size_Request */ + /* FT_Set_Transform */ + /* FT_Load_Glyph */ + /* FT_Get_Char_Index */ + /* FT_Get_First_Char */ + /* FT_Get_Next_Char */ + /* FT_Get_Name_Index */ + /* FT_Load_Char */ + /* */ + /* FT_OPEN_MEMORY */ + /* FT_OPEN_STREAM */ + /* FT_OPEN_PATHNAME */ + /* FT_OPEN_DRIVER */ + /* FT_OPEN_PARAMS */ + /* */ + /* FT_LOAD_DEFAULT */ + /* FT_LOAD_RENDER */ + /* FT_LOAD_MONOCHROME */ + /* FT_LOAD_LINEAR_DESIGN */ + /* FT_LOAD_NO_SCALE */ + /* FT_LOAD_NO_HINTING */ + /* FT_LOAD_NO_BITMAP */ + /* FT_LOAD_NO_AUTOHINT */ + /* FT_LOAD_COLOR */ + /* */ + /* FT_LOAD_VERTICAL_LAYOUT */ + /* FT_LOAD_IGNORE_TRANSFORM */ + /* FT_LOAD_FORCE_AUTOHINT */ + /* FT_LOAD_NO_RECURSE */ + /* FT_LOAD_PEDANTIC */ + /* */ + /* FT_LOAD_TARGET_NORMAL */ + /* FT_LOAD_TARGET_LIGHT */ + /* FT_LOAD_TARGET_MONO */ + /* FT_LOAD_TARGET_LCD */ + /* FT_LOAD_TARGET_LCD_V */ + /* */ + /* FT_LOAD_TARGET_MODE */ + /* */ + /* FT_Render_Glyph */ + /* FT_Render_Mode */ + /* FT_Get_Kerning */ + /* FT_Kerning_Mode */ + /* FT_Get_Track_Kerning */ + /* FT_Get_Glyph_Name */ + /* FT_Get_Postscript_Name */ + /* */ + /* FT_CharMapRec */ + /* FT_Select_Charmap */ + /* FT_Set_Charmap */ + /* FT_Get_Charmap_Index */ + /* */ + /* FT_Get_FSType_Flags */ + /* FT_Get_SubGlyph_Info */ + /* */ + /* FT_Face_Internal */ + /* FT_Size_Internal */ + /* FT_Slot_Internal */ + /* */ + /* FT_FACE_FLAG_XXX */ + /* FT_STYLE_FLAG_XXX */ + /* FT_OPEN_XXX */ + /* FT_LOAD_XXX */ + /* FT_LOAD_TARGET_XXX */ + /* FT_SUBGLYPH_FLAG_XXX */ + /* FT_FSTYPE_XXX */ + /* */ + /* FT_HAS_FAST_GLYPHS */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Glyph_Metrics */ + /* */ + /* <Description> */ + /* A structure used to model the metrics of a single glyph. The */ + /* values are expressed in 26.6 fractional pixel format; if the flag */ + /* @FT_LOAD_NO_SCALE has been used while loading the glyph, values */ + /* are expressed in font units instead. */ + /* */ + /* <Fields> */ + /* width :: */ + /* The glyph's width. */ + /* */ + /* height :: */ + /* The glyph's height. */ + /* */ + /* horiBearingX :: */ + /* Left side bearing for horizontal layout. */ + /* */ + /* horiBearingY :: */ + /* Top side bearing for horizontal layout. */ + /* */ + /* horiAdvance :: */ + /* Advance width for horizontal layout. */ + /* */ + /* vertBearingX :: */ + /* Left side bearing for vertical layout. */ + /* */ + /* vertBearingY :: */ + /* Top side bearing for vertical layout. Larger positive values */ + /* mean further below the vertical glyph origin. */ + /* */ + /* vertAdvance :: */ + /* Advance height for vertical layout. Positive values mean the */ + /* glyph has a positive advance downward. */ + /* */ + /* <Note> */ + /* If not disabled with @FT_LOAD_NO_HINTING, the values represent */ + /* dimensions of the hinted glyph (in case hinting is applicable). */ + /* */ + /* Stroking a glyph with an outside border does not increase */ + /* `horiAdvance' or `vertAdvance'; you have to manually adjust these */ + /* values to account for the added width and height. */ + /* */ + typedef struct FT_Glyph_Metrics_ + { + FT_Pos width; + FT_Pos height; + + FT_Pos horiBearingX; + FT_Pos horiBearingY; + FT_Pos horiAdvance; + + FT_Pos vertBearingX; + FT_Pos vertBearingY; + FT_Pos vertAdvance; + + } FT_Glyph_Metrics; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Bitmap_Size */ + /* */ + /* <Description> */ + /* This structure models the metrics of a bitmap strike (i.e., a set */ + /* of glyphs for a given point size and resolution) in a bitmap font. */ + /* It is used for the `available_sizes' field of @FT_Face. */ + /* */ + /* <Fields> */ + /* height :: The vertical distance, in pixels, between two */ + /* consecutive baselines. It is always positive. */ + /* */ + /* width :: The average width, in pixels, of all glyphs in the */ + /* strike. */ + /* */ + /* size :: The nominal size of the strike in 26.6 fractional */ + /* points. This field is not very useful. */ + /* */ + /* x_ppem :: The horizontal ppem (nominal width) in 26.6 fractional */ + /* pixels. */ + /* */ + /* y_ppem :: The vertical ppem (nominal height) in 26.6 fractional */ + /* pixels. */ + /* */ + /* <Note> */ + /* Windows FNT: */ + /* The nominal size given in a FNT font is not reliable. Thus when */ + /* the driver finds it incorrect, it sets `size' to some calculated */ + /* values and sets `x_ppem' and `y_ppem' to the pixel width and */ + /* height given in the font, respectively. */ + /* */ + /* TrueType embedded bitmaps: */ + /* `size', `width', and `height' values are not contained in the */ + /* bitmap strike itself. They are computed from the global font */ + /* parameters. */ + /* */ + typedef struct FT_Bitmap_Size_ + { + FT_Short height; + FT_Short width; + + FT_Pos size; + + FT_Pos x_ppem; + FT_Pos y_ppem; + + } FT_Bitmap_Size; + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* O B J E C T C L A S S E S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Library */ + /* */ + /* <Description> */ + /* A handle to a FreeType library instance. Each `library' is */ + /* completely independent from the others; it is the `root' of a set */ + /* of objects like fonts, faces, sizes, etc. */ + /* */ + /* It also embeds a memory manager (see @FT_Memory), as well as a */ + /* scan-line converter object (see @FT_Raster). */ + /* */ + /* In multi-threaded applications it is easiest to use one */ + /* `FT_Library' object per thread. In case this is too cumbersome, */ + /* a single `FT_Library' object across threads is possible also */ + /* (since FreeType version 2.5.6), as long as a mutex lock is used */ + /* around @FT_New_Face and @FT_Done_Face. */ + /* */ + /* <Note> */ + /* Library objects are normally created by @FT_Init_FreeType, and */ + /* destroyed with @FT_Done_FreeType. If you need reference-counting */ + /* (cf. @FT_Reference_Library), use @FT_New_Library and */ + /* @FT_Done_Library. */ + /* */ + typedef struct FT_LibraryRec_ *FT_Library; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* module_management */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Module */ + /* */ + /* <Description> */ + /* A handle to a given FreeType module object. Each module can be a */ + /* font driver, a renderer, or anything else that provides services */ + /* to the formers. */ + /* */ + typedef struct FT_ModuleRec_* FT_Module; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Driver */ + /* */ + /* <Description> */ + /* A handle to a given FreeType font driver object. Each font driver */ + /* is a special module capable of creating faces from font files. */ + /* */ + typedef struct FT_DriverRec_* FT_Driver; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Renderer */ + /* */ + /* <Description> */ + /* A handle to a given FreeType renderer. A renderer is a special */ + /* module in charge of converting a glyph image to a bitmap, when */ + /* necessary. Each renderer supports a given glyph image format, and */ + /* one or more target surface depths. */ + /* */ + typedef struct FT_RendererRec_* FT_Renderer; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* base_interface */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Face */ + /* */ + /* <Description> */ + /* A handle to a given typographic face object. A face object models */ + /* a given typeface, in a given style. */ + /* */ + /* <Note> */ + /* Each face object also owns a single @FT_GlyphSlot object, as well */ + /* as one or more @FT_Size objects. */ + /* */ + /* Use @FT_New_Face or @FT_Open_Face to create a new face object from */ + /* a given filepathname or a custom input stream. */ + /* */ + /* Use @FT_Done_Face to destroy it (along with its slot and sizes). */ + /* */ + /* An `FT_Face' object can only be safely used from one thread at a */ + /* time. Similarly, creation and destruction of `FT_Face' with the */ + /* same @FT_Library object can only be done from one thread at a */ + /* time. On the other hand, functions like @FT_Load_Glyph and its */ + /* siblings are thread-safe and do not need the lock to be held as */ + /* long as the same `FT_Face' object is not used from multiple */ + /* threads at the same time. */ + /* */ + /* <Also> */ + /* See @FT_FaceRec for the publicly accessible fields of a given face */ + /* object. */ + /* */ + typedef struct FT_FaceRec_* FT_Face; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Size */ + /* */ + /* <Description> */ + /* A handle to an object used to model a face scaled to a given */ + /* character size. */ + /* */ + /* <Note> */ + /* Each @FT_Face has an _active_ @FT_Size object that is used by */ + /* functions like @FT_Load_Glyph to determine the scaling */ + /* transformation that in turn is used to load and hint glyphs and */ + /* metrics. */ + /* */ + /* You can use @FT_Set_Char_Size, @FT_Set_Pixel_Sizes, */ + /* @FT_Request_Size or even @FT_Select_Size to change the content */ + /* (i.e., the scaling values) of the active @FT_Size. */ + /* */ + /* You can use @FT_New_Size to create additional size objects for a */ + /* given @FT_Face, but they won't be used by other functions until */ + /* you activate it through @FT_Activate_Size. Only one size can be */ + /* activated at any given time per face. */ + /* */ + /* <Also> */ + /* See @FT_SizeRec for the publicly accessible fields of a given size */ + /* object. */ + /* */ + typedef struct FT_SizeRec_* FT_Size; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_GlyphSlot */ + /* */ + /* <Description> */ + /* A handle to a given `glyph slot'. A slot is a container where it */ + /* is possible to load any of the glyphs contained in its parent */ + /* face. */ + /* */ + /* In other words, each time you call @FT_Load_Glyph or */ + /* @FT_Load_Char, the slot's content is erased by the new glyph data, */ + /* i.e., the glyph's metrics, its image (bitmap or outline), and */ + /* other control information. */ + /* */ + /* <Also> */ + /* See @FT_GlyphSlotRec for the publicly accessible glyph fields. */ + /* */ + typedef struct FT_GlyphSlotRec_* FT_GlyphSlot; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_CharMap */ + /* */ + /* <Description> */ + /* A handle to a given character map. A charmap is used to translate */ + /* character codes in a given encoding into glyph indexes for its */ + /* parent's face. Some font formats may provide several charmaps per */ + /* font. */ + /* */ + /* Each face object owns zero or more charmaps, but only one of them */ + /* can be `active' and used by @FT_Get_Char_Index or @FT_Load_Char. */ + /* */ + /* The list of available charmaps in a face is available through the */ + /* `face->num_charmaps' and `face->charmaps' fields of @FT_FaceRec. */ + /* */ + /* The currently active charmap is available as `face->charmap'. */ + /* You should call @FT_Set_Charmap to change it. */ + /* */ + /* <Note> */ + /* When a new face is created (either through @FT_New_Face or */ + /* @FT_Open_Face), the library looks for a Unicode charmap within */ + /* the list and automatically activates it. */ + /* */ + /* <Also> */ + /* See @FT_CharMapRec for the publicly accessible fields of a given */ + /* character map. */ + /* */ + typedef struct FT_CharMapRec_* FT_CharMap; + + + /*************************************************************************/ + /* */ + /* <Macro> */ + /* FT_ENC_TAG */ + /* */ + /* <Description> */ + /* This macro converts four-letter tags into an unsigned long. It is */ + /* used to define `encoding' identifiers (see @FT_Encoding). */ + /* */ + /* <Note> */ + /* Since many 16-bit compilers don't like 32-bit enumerations, you */ + /* should redefine this macro in case of problems to something like */ + /* this: */ + /* */ + /* { */ + /* #define FT_ENC_TAG( value, a, b, c, d ) value */ + /* } */ + /* */ + /* to get a simple enumeration without assigning special numbers. */ + /* */ + +#ifndef FT_ENC_TAG +#define FT_ENC_TAG( value, a, b, c, d ) \ + value = ( ( (FT_UInt32)(a) << 24 ) | \ + ( (FT_UInt32)(b) << 16 ) | \ + ( (FT_UInt32)(c) << 8 ) | \ + (FT_UInt32)(d) ) + +#endif /* FT_ENC_TAG */ + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Encoding */ + /* */ + /* <Description> */ + /* An enumeration used to specify character sets supported by */ + /* charmaps. Used in the @FT_Select_Charmap API function. */ + /* */ + /* <Note> */ + /* Despite the name, this enumeration lists specific character */ + /* repertories (i.e., charsets), and not text encoding methods (e.g., */ + /* UTF-8, UTF-16, etc.). */ + /* */ + /* Other encodings might be defined in the future. */ + /* */ + /* <Values> */ + /* FT_ENCODING_NONE :: */ + /* The encoding value~0 is reserved. */ + /* */ + /* FT_ENCODING_UNICODE :: */ + /* Corresponds to the Unicode character set. This value covers */ + /* all versions of the Unicode repertoire, including ASCII and */ + /* Latin-1. Most fonts include a Unicode charmap, but not all */ + /* of them. */ + /* */ + /* For example, if you want to access Unicode value U+1F028 (and */ + /* the font contains it), use value 0x1F028 as the input value for */ + /* @FT_Get_Char_Index. */ + /* */ + /* FT_ENCODING_MS_SYMBOL :: */ + /* Corresponds to the Microsoft Symbol encoding, used to encode */ + /* mathematical symbols and wingdings. For more information, see */ + /* `http://www.microsoft.com/typography/otspec/recom.htm', */ + /* `http://www.kostis.net/charsets/symbol.htm', and */ + /* `http://www.kostis.net/charsets/wingding.htm'. */ + /* */ + /* This encoding uses character codes from the PUA (Private Unicode */ + /* Area) in the range U+F020-U+F0FF. */ + /* */ + /* FT_ENCODING_SJIS :: */ + /* Corresponds to Japanese SJIS encoding. More info at */ + /* at `http://en.wikipedia.org/wiki/Shift_JIS'. */ + /* See note on multi-byte encodings below. */ + /* */ + /* FT_ENCODING_GB2312 :: */ + /* Corresponds to an encoding system for Simplified Chinese as used */ + /* used in mainland China. */ + /* */ + /* FT_ENCODING_BIG5 :: */ + /* Corresponds to an encoding system for Traditional Chinese as */ + /* used in Taiwan and Hong Kong. */ + /* */ + /* FT_ENCODING_WANSUNG :: */ + /* Corresponds to the Korean encoding system known as Wansung. */ + /* For more information see */ + /* `https://msdn.microsoft.com/en-US/goglobal/cc305154'. */ + /* */ + /* FT_ENCODING_JOHAB :: */ + /* The Korean standard character set (KS~C 5601-1992), which */ + /* corresponds to MS Windows code page 1361. This character set */ + /* includes all possible Hangeul character combinations. */ + /* */ + /* FT_ENCODING_ADOBE_LATIN_1 :: */ + /* Corresponds to a Latin-1 encoding as defined in a Type~1 */ + /* PostScript font. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_ADOBE_STANDARD :: */ + /* Corresponds to the Adobe Standard encoding, as found in Type~1, */ + /* CFF, and OpenType/CFF fonts. It is limited to 256 character */ + /* codes. */ + /* */ + /* FT_ENCODING_ADOBE_EXPERT :: */ + /* Corresponds to the Adobe Expert encoding, as found in Type~1, */ + /* CFF, and OpenType/CFF fonts. It is limited to 256 character */ + /* codes. */ + /* */ + /* FT_ENCODING_ADOBE_CUSTOM :: */ + /* Corresponds to a custom encoding, as found in Type~1, CFF, and */ + /* OpenType/CFF fonts. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_APPLE_ROMAN :: */ + /* Corresponds to the 8-bit Apple roman encoding. Many TrueType */ + /* and OpenType fonts contain a charmap for this encoding, since */ + /* older versions of Mac OS are able to use it. */ + /* */ + /* FT_ENCODING_OLD_LATIN_2 :: */ + /* This value is deprecated and was never used nor reported by */ + /* FreeType. Don't use or test for it. */ + /* */ + /* FT_ENCODING_MS_SJIS :: */ + /* Same as FT_ENCODING_SJIS. Deprecated. */ + /* */ + /* FT_ENCODING_MS_GB2312 :: */ + /* Same as FT_ENCODING_GB2312. Deprecated. */ + /* */ + /* FT_ENCODING_MS_BIG5 :: */ + /* Same as FT_ENCODING_BIG5. Deprecated. */ + /* */ + /* FT_ENCODING_MS_WANSUNG :: */ + /* Same as FT_ENCODING_WANSUNG. Deprecated. */ + /* */ + /* FT_ENCODING_MS_JOHAB :: */ + /* Same as FT_ENCODING_JOHAB. Deprecated. */ + /* */ + /* <Note> */ + /* By default, FreeType automatically synthesizes a Unicode charmap */ + /* for PostScript fonts, using their glyph names dictionaries. */ + /* However, it also reports the encodings defined explicitly in the */ + /* font file, for the cases when they are needed, with the Adobe */ + /* values as well. */ + /* */ + /* FT_ENCODING_NONE is set by the BDF and PCF drivers if the charmap */ + /* is neither Unicode nor ISO-8859-1 (otherwise it is set to */ + /* FT_ENCODING_UNICODE). Use @FT_Get_BDF_Charset_ID to find out */ + /* which encoding is really present. If, for example, the */ + /* `cs_registry' field is `KOI8' and the `cs_encoding' field is `R', */ + /* the font is encoded in KOI8-R. */ + /* */ + /* FT_ENCODING_NONE is always set (with a single exception) by the */ + /* winfonts driver. Use @FT_Get_WinFNT_Header and examine the */ + /* `charset' field of the @FT_WinFNT_HeaderRec structure to find out */ + /* which encoding is really present. For example, */ + /* @FT_WinFNT_ID_CP1251 (204) means Windows code page 1251 (for */ + /* Russian). */ + /* */ + /* FT_ENCODING_NONE is set if `platform_id' is @TT_PLATFORM_MACINTOSH */ + /* and `encoding_id' is not @TT_MAC_ID_ROMAN (otherwise it is set to */ + /* FT_ENCODING_APPLE_ROMAN). */ + /* */ + /* If `platform_id' is @TT_PLATFORM_MACINTOSH, use the function */ + /* @FT_Get_CMap_Language_ID to query the Mac language ID that may */ + /* be needed to be able to distinguish Apple encoding variants. See */ + /* */ + /* http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt */ + /* */ + /* to get an idea how to do that. Basically, if the language ID */ + /* is~0, don't use it, otherwise subtract 1 from the language ID. */ + /* Then examine `encoding_id'. If, for example, `encoding_id' is */ + /* @TT_MAC_ID_ROMAN and the language ID (minus~1) is */ + /* `TT_MAC_LANGID_GREEK', it is the Greek encoding, not Roman. */ + /* @TT_MAC_ID_ARABIC with `TT_MAC_LANGID_FARSI' means the Farsi */ + /* variant the Arabic encoding. */ + /* */ + typedef enum FT_Encoding_ + { + FT_ENC_TAG( FT_ENCODING_NONE, 0, 0, 0, 0 ), + + FT_ENC_TAG( FT_ENCODING_MS_SYMBOL, 's', 'y', 'm', 'b' ), + FT_ENC_TAG( FT_ENCODING_UNICODE, 'u', 'n', 'i', 'c' ), + + FT_ENC_TAG( FT_ENCODING_SJIS, 's', 'j', 'i', 's' ), + FT_ENC_TAG( FT_ENCODING_GB2312, 'g', 'b', ' ', ' ' ), + FT_ENC_TAG( FT_ENCODING_BIG5, 'b', 'i', 'g', '5' ), + FT_ENC_TAG( FT_ENCODING_WANSUNG, 'w', 'a', 'n', 's' ), + FT_ENC_TAG( FT_ENCODING_JOHAB, 'j', 'o', 'h', 'a' ), + + /* for backwards compatibility */ + FT_ENCODING_MS_SJIS = FT_ENCODING_SJIS, + FT_ENCODING_MS_GB2312 = FT_ENCODING_GB2312, + FT_ENCODING_MS_BIG5 = FT_ENCODING_BIG5, + FT_ENCODING_MS_WANSUNG = FT_ENCODING_WANSUNG, + FT_ENCODING_MS_JOHAB = FT_ENCODING_JOHAB, + + FT_ENC_TAG( FT_ENCODING_ADOBE_STANDARD, 'A', 'D', 'O', 'B' ), + FT_ENC_TAG( FT_ENCODING_ADOBE_EXPERT, 'A', 'D', 'B', 'E' ), + FT_ENC_TAG( FT_ENCODING_ADOBE_CUSTOM, 'A', 'D', 'B', 'C' ), + FT_ENC_TAG( FT_ENCODING_ADOBE_LATIN_1, 'l', 'a', 't', '1' ), + + FT_ENC_TAG( FT_ENCODING_OLD_LATIN_2, 'l', 'a', 't', '2' ), + + FT_ENC_TAG( FT_ENCODING_APPLE_ROMAN, 'a', 'r', 'm', 'n' ) + + } FT_Encoding; + + + /* these constants are deprecated; use the corresponding `FT_Encoding' */ + /* values instead */ +#define ft_encoding_none FT_ENCODING_NONE +#define ft_encoding_unicode FT_ENCODING_UNICODE +#define ft_encoding_symbol FT_ENCODING_MS_SYMBOL +#define ft_encoding_latin_1 FT_ENCODING_ADOBE_LATIN_1 +#define ft_encoding_latin_2 FT_ENCODING_OLD_LATIN_2 +#define ft_encoding_sjis FT_ENCODING_SJIS +#define ft_encoding_gb2312 FT_ENCODING_GB2312 +#define ft_encoding_big5 FT_ENCODING_BIG5 +#define ft_encoding_wansung FT_ENCODING_WANSUNG +#define ft_encoding_johab FT_ENCODING_JOHAB + +#define ft_encoding_adobe_standard FT_ENCODING_ADOBE_STANDARD +#define ft_encoding_adobe_expert FT_ENCODING_ADOBE_EXPERT +#define ft_encoding_adobe_custom FT_ENCODING_ADOBE_CUSTOM +#define ft_encoding_apple_roman FT_ENCODING_APPLE_ROMAN + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_CharMapRec */ + /* */ + /* <Description> */ + /* The base charmap structure. */ + /* */ + /* <Fields> */ + /* face :: A handle to the parent face object. */ + /* */ + /* encoding :: An @FT_Encoding tag identifying the charmap. Use */ + /* this with @FT_Select_Charmap. */ + /* */ + /* platform_id :: An ID number describing the platform for the */ + /* following encoding ID. This comes directly from */ + /* the TrueType specification and should be emulated */ + /* for other formats. */ + /* */ + /* encoding_id :: A platform specific encoding number. This also */ + /* comes from the TrueType specification and should be */ + /* emulated similarly. */ + /* */ + typedef struct FT_CharMapRec_ + { + FT_Face face; + FT_Encoding encoding; + FT_UShort platform_id; + FT_UShort encoding_id; + + } FT_CharMapRec; + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* B A S E O B J E C T C L A S S E S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Face_Internal */ + /* */ + /* <Description> */ + /* An opaque handle to an `FT_Face_InternalRec' structure, used to */ + /* model private data of a given @FT_Face object. */ + /* */ + /* This structure might change between releases of FreeType~2 and is */ + /* not generally available to client applications. */ + /* */ + typedef struct FT_Face_InternalRec_* FT_Face_Internal; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_FaceRec */ + /* */ + /* <Description> */ + /* FreeType root face class structure. A face object models a */ + /* typeface in a font file. */ + /* */ + /* <Fields> */ + /* num_faces :: The number of faces in the font file. Some */ + /* font formats can have multiple faces in */ + /* a font file. */ + /* */ + /* face_index :: This field holds two different values. */ + /* Bits 0-15 are the index of the face in the */ + /* font file (starting with value~0). They */ + /* are set to~0 if there is only one face in */ + /* the font file. */ + /* */ + /* Bits 16-30 are relevant to GX variation */ + /* fonts only, holding the named instance */ + /* index for the current face index (starting */ + /* with value~1; value~0 indicates font access */ + /* without GX variation data). For non-GX */ + /* fonts, bits 16-30 are ignored. If we have */ + /* the third named instance of face~4, say, */ + /* `face_index' is set to 0x00030004. */ + /* */ + /* Bit 31 is always zero (this is, */ + /* `face_index' is always a positive value). */ + /* */ + /* face_flags :: A set of bit flags that give important */ + /* information about the face; see */ + /* @FT_FACE_FLAG_XXX for the details. */ + /* */ + /* style_flags :: The lower 16~bits contain a set of bit */ + /* flags indicating the style of the face; see */ + /* @FT_STYLE_FLAG_XXX for the details. Bits */ + /* 16-30 hold the number of named instances */ + /* available for the current face if we have a */ + /* GX variation (sub)font. Bit 31 is always */ + /* zero (this is, `style_flags' is always a */ + /* positive value). */ + /* */ + /* num_glyphs :: The number of glyphs in the face. If the */ + /* face is scalable and has sbits (see */ + /* `num_fixed_sizes'), it is set to the number */ + /* of outline glyphs. */ + /* */ + /* For CID-keyed fonts, this value gives the */ + /* highest CID used in the font. */ + /* */ + /* family_name :: The face's family name. This is an ASCII */ + /* string, usually in English, that describes */ + /* the typeface's family (like `Times New */ + /* Roman', `Bodoni', `Garamond', etc). This */ + /* is a least common denominator used to list */ + /* fonts. Some formats (TrueType & OpenType) */ + /* provide localized and Unicode versions of */ + /* this string. Applications should use the */ + /* format specific interface to access them. */ + /* Can be NULL (e.g., in fonts embedded in a */ + /* PDF file). */ + /* */ + /* In case the font doesn't provide a specific */ + /* family name entry, FreeType tries to */ + /* synthesize one, deriving it from other name */ + /* entries. */ + /* */ + /* style_name :: The face's style name. This is an ASCII */ + /* string, usually in English, that describes */ + /* the typeface's style (like `Italic', */ + /* `Bold', `Condensed', etc). Not all font */ + /* formats provide a style name, so this field */ + /* is optional, and can be set to NULL. As */ + /* for `family_name', some formats provide */ + /* localized and Unicode versions of this */ + /* string. Applications should use the format */ + /* specific interface to access them. */ + /* */ + /* num_fixed_sizes :: The number of bitmap strikes in the face. */ + /* Even if the face is scalable, there might */ + /* still be bitmap strikes, which are called */ + /* `sbits' in that case. */ + /* */ + /* available_sizes :: An array of @FT_Bitmap_Size for all bitmap */ + /* strikes in the face. It is set to NULL if */ + /* there is no bitmap strike. */ + /* */ + /* num_charmaps :: The number of charmaps in the face. */ + /* */ + /* charmaps :: An array of the charmaps of the face. */ + /* */ + /* generic :: A field reserved for client uses. See the */ + /* @FT_Generic type description. */ + /* */ + /* bbox :: The font bounding box. Coordinates are */ + /* expressed in font units (see */ + /* `units_per_EM'). The box is large enough */ + /* to contain any glyph from the font. Thus, */ + /* `bbox.yMax' can be seen as the `maximum */ + /* ascender', and `bbox.yMin' as the `minimum */ + /* descender'. Only relevant for scalable */ + /* formats. */ + /* */ + /* Note that the bounding box might be off by */ + /* (at least) one pixel for hinted fonts. See */ + /* @FT_Size_Metrics for further discussion. */ + /* */ + /* units_per_EM :: The number of font units per EM square for */ + /* this face. This is typically 2048 for */ + /* TrueType fonts, and 1000 for Type~1 fonts. */ + /* Only relevant for scalable formats. */ + /* */ + /* ascender :: The typographic ascender of the face, */ + /* expressed in font units. For font formats */ + /* not having this information, it is set to */ + /* `bbox.yMax'. Only relevant for scalable */ + /* formats. */ + /* */ + /* descender :: The typographic descender of the face, */ + /* expressed in font units. For font formats */ + /* not having this information, it is set to */ + /* `bbox.yMin'. Note that this field is */ + /* usually negative. Only relevant for */ + /* scalable formats. */ + /* */ + /* height :: This value is the vertical distance */ + /* between two consecutive baselines, */ + /* expressed in font units. It is always */ + /* positive. Only relevant for scalable */ + /* formats. */ + /* */ + /* If you want the global glyph height, use */ + /* `ascender - descender'. */ + /* */ + /* max_advance_width :: The maximum advance width, in font units, */ + /* for all glyphs in this face. This can be */ + /* used to make word wrapping computations */ + /* faster. Only relevant for scalable */ + /* formats. */ + /* */ + /* max_advance_height :: The maximum advance height, in font units, */ + /* for all glyphs in this face. This is only */ + /* relevant for vertical layouts, and is set */ + /* to `height' for fonts that do not provide */ + /* vertical metrics. Only relevant for */ + /* scalable formats. */ + /* */ + /* underline_position :: The position, in font units, of the */ + /* underline line for this face. It is the */ + /* center of the underlining stem. Only */ + /* relevant for scalable formats. */ + /* */ + /* underline_thickness :: The thickness, in font units, of the */ + /* underline for this face. Only relevant for */ + /* scalable formats. */ + /* */ + /* glyph :: The face's associated glyph slot(s). */ + /* */ + /* size :: The current active size for this face. */ + /* */ + /* charmap :: The current active charmap for this face. */ + /* */ + /* <Note> */ + /* Fields may be changed after a call to @FT_Attach_File or */ + /* @FT_Attach_Stream. */ + /* */ + typedef struct FT_FaceRec_ + { + FT_Long num_faces; + FT_Long face_index; + + FT_Long face_flags; + FT_Long style_flags; + + FT_Long num_glyphs; + + FT_String* family_name; + FT_String* style_name; + + FT_Int num_fixed_sizes; + FT_Bitmap_Size* available_sizes; + + FT_Int num_charmaps; + FT_CharMap* charmaps; + + FT_Generic generic; + + /*# The following member variables (down to `underline_thickness') */ + /*# are only relevant to scalable outlines; cf. @FT_Bitmap_Size */ + /*# for bitmap fonts. */ + FT_BBox bbox; + + FT_UShort units_per_EM; + FT_Short ascender; + FT_Short descender; + FT_Short height; + + FT_Short max_advance_width; + FT_Short max_advance_height; + + FT_Short underline_position; + FT_Short underline_thickness; + + FT_GlyphSlot glyph; + FT_Size size; + FT_CharMap charmap; + + /*@private begin */ + + FT_Driver driver; + FT_Memory memory; + FT_Stream stream; + + FT_ListRec sizes_list; + + FT_Generic autohint; /* face-specific auto-hinter data */ + void* extensions; /* unused */ + + FT_Face_Internal internal; + + /*@private end */ + + } FT_FaceRec; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_FACE_FLAG_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags used in the `face_flags' field of the */ + /* @FT_FaceRec structure. They inform client applications of */ + /* properties of the corresponding face. */ + /* */ + /* <Values> */ + /* FT_FACE_FLAG_SCALABLE :: */ + /* Indicates that the face contains outline glyphs. This doesn't */ + /* prevent bitmap strikes, i.e., a face can have both this and */ + /* and @FT_FACE_FLAG_FIXED_SIZES set. */ + /* */ + /* FT_FACE_FLAG_FIXED_SIZES :: */ + /* Indicates that the face contains bitmap strikes. See also the */ + /* `num_fixed_sizes' and `available_sizes' fields of @FT_FaceRec. */ + /* */ + /* FT_FACE_FLAG_FIXED_WIDTH :: */ + /* Indicates that the face contains fixed-width characters (like */ + /* Courier, Lucido, MonoType, etc.). */ + /* */ + /* FT_FACE_FLAG_SFNT :: */ + /* Indicates that the face uses the `sfnt' storage scheme. For */ + /* now, this means TrueType and OpenType. */ + /* */ + /* FT_FACE_FLAG_HORIZONTAL :: */ + /* Indicates that the face contains horizontal glyph metrics. This */ + /* should be set for all common formats. */ + /* */ + /* FT_FACE_FLAG_VERTICAL :: */ + /* Indicates that the face contains vertical glyph metrics. This */ + /* is only available in some formats, not all of them. */ + /* */ + /* FT_FACE_FLAG_KERNING :: */ + /* Indicates that the face contains kerning information. If set, */ + /* the kerning distance can be retrieved through the function */ + /* @FT_Get_Kerning. Otherwise the function always return the */ + /* vector (0,0). Note that FreeType doesn't handle kerning data */ + /* from the `GPOS' table (as present in some OpenType fonts). */ + /* */ + /* FT_FACE_FLAG_FAST_GLYPHS :: */ + /* THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT. */ + /* */ + /* FT_FACE_FLAG_MULTIPLE_MASTERS :: */ + /* Indicates that the font contains multiple masters and is capable */ + /* of interpolating between them. See the multiple-masters */ + /* specific API for details. */ + /* */ + /* FT_FACE_FLAG_GLYPH_NAMES :: */ + /* Indicates that the font contains glyph names that can be */ + /* retrieved through @FT_Get_Glyph_Name. Note that some TrueType */ + /* fonts contain broken glyph name tables. Use the function */ + /* @FT_Has_PS_Glyph_Names when needed. */ + /* */ + /* FT_FACE_FLAG_EXTERNAL_STREAM :: */ + /* Used internally by FreeType to indicate that a face's stream was */ + /* provided by the client application and should not be destroyed */ + /* when @FT_Done_Face is called. Don't read or test this flag. */ + /* */ + /* FT_FACE_FLAG_HINTER :: */ + /* Set if the font driver has a hinting machine of its own. For */ + /* example, with TrueType fonts, it makes sense to use data from */ + /* the SFNT `gasp' table only if the native TrueType hinting engine */ + /* (with the bytecode interpreter) is available and active. */ + /* */ + /* FT_FACE_FLAG_CID_KEYED :: */ + /* Set if the font is CID-keyed. In that case, the font is not */ + /* accessed by glyph indices but by CID values. For subsetted */ + /* CID-keyed fonts this has the consequence that not all index */ + /* values are a valid argument to FT_Load_Glyph. Only the CID */ + /* values for which corresponding glyphs in the subsetted font */ + /* exist make FT_Load_Glyph return successfully; in all other cases */ + /* you get an `FT_Err_Invalid_Argument' error. */ + /* */ + /* Note that CID-keyed fonts that are in an SFNT wrapper don't */ + /* have this flag set since the glyphs are accessed in the normal */ + /* way (using contiguous indices); the `CID-ness' isn't visible to */ + /* the application. */ + /* */ + /* FT_FACE_FLAG_TRICKY :: */ + /* Set if the font is `tricky', this is, it always needs the */ + /* font format's native hinting engine to get a reasonable result. */ + /* A typical example is the Chinese font `mingli.ttf' that uses */ + /* TrueType bytecode instructions to move and scale all of its */ + /* subglyphs. */ + /* */ + /* It is not possible to auto-hint such fonts using */ + /* @FT_LOAD_FORCE_AUTOHINT; it will also ignore */ + /* @FT_LOAD_NO_HINTING. You have to set both @FT_LOAD_NO_HINTING */ + /* and @FT_LOAD_NO_AUTOHINT to really disable hinting; however, you */ + /* probably never want this except for demonstration purposes. */ + /* */ + /* Currently, there are about a dozen TrueType fonts in the list of */ + /* tricky fonts; they are hard-coded in file `ttobjs.c'. */ + /* */ + /* FT_FACE_FLAG_COLOR :: */ + /* Set if the font has color glyph tables. To access color glyphs */ + /* use @FT_LOAD_COLOR. */ + /* */ +#define FT_FACE_FLAG_SCALABLE ( 1L << 0 ) +#define FT_FACE_FLAG_FIXED_SIZES ( 1L << 1 ) +#define FT_FACE_FLAG_FIXED_WIDTH ( 1L << 2 ) +#define FT_FACE_FLAG_SFNT ( 1L << 3 ) +#define FT_FACE_FLAG_HORIZONTAL ( 1L << 4 ) +#define FT_FACE_FLAG_VERTICAL ( 1L << 5 ) +#define FT_FACE_FLAG_KERNING ( 1L << 6 ) +#define FT_FACE_FLAG_FAST_GLYPHS ( 1L << 7 ) +#define FT_FACE_FLAG_MULTIPLE_MASTERS ( 1L << 8 ) +#define FT_FACE_FLAG_GLYPH_NAMES ( 1L << 9 ) +#define FT_FACE_FLAG_EXTERNAL_STREAM ( 1L << 10 ) +#define FT_FACE_FLAG_HINTER ( 1L << 11 ) +#define FT_FACE_FLAG_CID_KEYED ( 1L << 12 ) +#define FT_FACE_FLAG_TRICKY ( 1L << 13 ) +#define FT_FACE_FLAG_COLOR ( 1L << 14 ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_HORIZONTAL( face ) + * + * @description: + * A macro that returns true whenever a face object contains + * horizontal metrics (this is true for all font formats though). + * + * @also: + * @FT_HAS_VERTICAL can be used to check for vertical metrics. + * + */ +#define FT_HAS_HORIZONTAL( face ) \ + ( face->face_flags & FT_FACE_FLAG_HORIZONTAL ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_VERTICAL( face ) + * + * @description: + * A macro that returns true whenever a face object contains real + * vertical metrics (and not only synthesized ones). + * + */ +#define FT_HAS_VERTICAL( face ) \ + ( face->face_flags & FT_FACE_FLAG_VERTICAL ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_KERNING( face ) + * + * @description: + * A macro that returns true whenever a face object contains kerning + * data that can be accessed with @FT_Get_Kerning. + * + */ +#define FT_HAS_KERNING( face ) \ + ( face->face_flags & FT_FACE_FLAG_KERNING ) + + + /************************************************************************* + * + * @macro: + * FT_IS_SCALABLE( face ) + * + * @description: + * A macro that returns true whenever a face object contains a scalable + * font face (true for TrueType, Type~1, Type~42, CID, OpenType/CFF, + * and PFR font formats. + * + */ +#define FT_IS_SCALABLE( face ) \ + ( face->face_flags & FT_FACE_FLAG_SCALABLE ) + + + /************************************************************************* + * + * @macro: + * FT_IS_SFNT( face ) + * + * @description: + * A macro that returns true whenever a face object contains a font + * whose format is based on the SFNT storage scheme. This usually + * means: TrueType fonts, OpenType fonts, as well as SFNT-based embedded + * bitmap fonts. + * + * If this macro is true, all functions defined in @FT_SFNT_NAMES_H and + * @FT_TRUETYPE_TABLES_H are available. + * + */ +#define FT_IS_SFNT( face ) \ + ( face->face_flags & FT_FACE_FLAG_SFNT ) + + + /************************************************************************* + * + * @macro: + * FT_IS_FIXED_WIDTH( face ) + * + * @description: + * A macro that returns true whenever a face object contains a font face + * that contains fixed-width (or `monospace', `fixed-pitch', etc.) + * glyphs. + * + */ +#define FT_IS_FIXED_WIDTH( face ) \ + ( face->face_flags & FT_FACE_FLAG_FIXED_WIDTH ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_FIXED_SIZES( face ) + * + * @description: + * A macro that returns true whenever a face object contains some + * embedded bitmaps. See the `available_sizes' field of the + * @FT_FaceRec structure. + * + */ +#define FT_HAS_FIXED_SIZES( face ) \ + ( face->face_flags & FT_FACE_FLAG_FIXED_SIZES ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_FAST_GLYPHS( face ) + * + * @description: + * Deprecated. + * + */ +#define FT_HAS_FAST_GLYPHS( face ) 0 + + + /************************************************************************* + * + * @macro: + * FT_HAS_GLYPH_NAMES( face ) + * + * @description: + * A macro that returns true whenever a face object contains some glyph + * names that can be accessed through @FT_Get_Glyph_Name. + * + */ +#define FT_HAS_GLYPH_NAMES( face ) \ + ( face->face_flags & FT_FACE_FLAG_GLYPH_NAMES ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_MULTIPLE_MASTERS( face ) + * + * @description: + * A macro that returns true whenever a face object contains some + * multiple masters. The functions provided by @FT_MULTIPLE_MASTERS_H + * are then available to choose the exact design you want. + * + */ +#define FT_HAS_MULTIPLE_MASTERS( face ) \ + ( face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS ) + + + /************************************************************************* + * + * @macro: + * FT_IS_CID_KEYED( face ) + * + * @description: + * A macro that returns true whenever a face object contains a CID-keyed + * font. See the discussion of @FT_FACE_FLAG_CID_KEYED for more + * details. + * + * If this macro is true, all functions defined in @FT_CID_H are + * available. + * + */ +#define FT_IS_CID_KEYED( face ) \ + ( face->face_flags & FT_FACE_FLAG_CID_KEYED ) + + + /************************************************************************* + * + * @macro: + * FT_IS_TRICKY( face ) + * + * @description: + * A macro that returns true whenever a face represents a `tricky' font. + * See the discussion of @FT_FACE_FLAG_TRICKY for more details. + * + */ +#define FT_IS_TRICKY( face ) \ + ( face->face_flags & FT_FACE_FLAG_TRICKY ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_COLOR( face ) + * + * @description: + * A macro that returns true whenever a face object contains + * tables for color glyphs. + * + */ +#define FT_HAS_COLOR( face ) \ + ( face->face_flags & FT_FACE_FLAG_COLOR ) + + + /*************************************************************************/ + /* */ + /* <Const> */ + /* FT_STYLE_FLAG_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags used to indicate the style of a given face. */ + /* These are used in the `style_flags' field of @FT_FaceRec. */ + /* */ + /* <Values> */ + /* FT_STYLE_FLAG_ITALIC :: */ + /* Indicates that a given face style is italic or oblique. */ + /* */ + /* FT_STYLE_FLAG_BOLD :: */ + /* Indicates that a given face is bold. */ + /* */ + /* <Note> */ + /* The style information as provided by FreeType is very basic. More */ + /* details are beyond the scope and should be done on a higher level */ + /* (for example, by analyzing various fields of the `OS/2' table in */ + /* SFNT based fonts). */ + /* */ +#define FT_STYLE_FLAG_ITALIC ( 1 << 0 ) +#define FT_STYLE_FLAG_BOLD ( 1 << 1 ) + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Size_Internal */ + /* */ + /* <Description> */ + /* An opaque handle to an `FT_Size_InternalRec' structure, used to */ + /* model private data of a given @FT_Size object. */ + /* */ + typedef struct FT_Size_InternalRec_* FT_Size_Internal; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Size_Metrics */ + /* */ + /* <Description> */ + /* The size metrics structure gives the metrics of a size object. */ + /* */ + /* <Fields> */ + /* x_ppem :: The width of the scaled EM square in pixels, hence */ + /* the term `ppem' (pixels per EM). It is also */ + /* referred to as `nominal width'. */ + /* */ + /* y_ppem :: The height of the scaled EM square in pixels, */ + /* hence the term `ppem' (pixels per EM). It is also */ + /* referred to as `nominal height'. */ + /* */ + /* x_scale :: A 16.16 fractional scaling value used to convert */ + /* horizontal metrics from font units to 26.6 */ + /* fractional pixels. Only relevant for scalable */ + /* font formats. */ + /* */ + /* y_scale :: A 16.16 fractional scaling value used to convert */ + /* vertical metrics from font units to 26.6 */ + /* fractional pixels. Only relevant for scalable */ + /* font formats. */ + /* */ + /* ascender :: The ascender in 26.6 fractional pixels. See */ + /* @FT_FaceRec for the details. */ + /* */ + /* descender :: The descender in 26.6 fractional pixels. See */ + /* @FT_FaceRec for the details. */ + /* */ + /* height :: The height in 26.6 fractional pixels. See */ + /* @FT_FaceRec for the details. */ + /* */ + /* max_advance :: The maximum advance width in 26.6 fractional */ + /* pixels. See @FT_FaceRec for the details. */ + /* */ + /* <Note> */ + /* The scaling values, if relevant, are determined first during a */ + /* size changing operation. The remaining fields are then set by the */ + /* driver. For scalable formats, they are usually set to scaled */ + /* values of the corresponding fields in @FT_FaceRec. */ + /* */ + /* Note that due to glyph hinting, these values might not be exact */ + /* for certain fonts. Thus they must be treated as unreliable */ + /* with an error margin of at least one pixel! */ + /* */ + /* Indeed, the only way to get the exact metrics is to render _all_ */ + /* glyphs. As this would be a definite performance hit, it is up to */ + /* client applications to perform such computations. */ + /* */ + /* The FT_Size_Metrics structure is valid for bitmap fonts also. */ + /* */ + typedef struct FT_Size_Metrics_ + { + FT_UShort x_ppem; /* horizontal pixels per EM */ + FT_UShort y_ppem; /* vertical pixels per EM */ + + FT_Fixed x_scale; /* scaling values used to convert font */ + FT_Fixed y_scale; /* units to 26.6 fractional pixels */ + + FT_Pos ascender; /* ascender in 26.6 frac. pixels */ + FT_Pos descender; /* descender in 26.6 frac. pixels */ + FT_Pos height; /* text height in 26.6 frac. pixels */ + FT_Pos max_advance; /* max horizontal advance, in 26.6 pixels */ + + } FT_Size_Metrics; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_SizeRec */ + /* */ + /* <Description> */ + /* FreeType root size class structure. A size object models a face */ + /* object at a given size. */ + /* */ + /* <Fields> */ + /* face :: Handle to the parent face object. */ + /* */ + /* generic :: A typeless pointer, unused by the FreeType library or */ + /* any of its drivers. It can be used by client */ + /* applications to link their own data to each size */ + /* object. */ + /* */ + /* metrics :: Metrics for this size object. This field is read-only. */ + /* */ + typedef struct FT_SizeRec_ + { + FT_Face face; /* parent face object */ + FT_Generic generic; /* generic pointer for client uses */ + FT_Size_Metrics metrics; /* size metrics */ + FT_Size_Internal internal; + + } FT_SizeRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_SubGlyph */ + /* */ + /* <Description> */ + /* The subglyph structure is an internal object used to describe */ + /* subglyphs (for example, in the case of composites). */ + /* */ + /* <Note> */ + /* The subglyph implementation is not part of the high-level API, */ + /* hence the forward structure declaration. */ + /* */ + /* You can however retrieve subglyph information with */ + /* @FT_Get_SubGlyph_Info. */ + /* */ + typedef struct FT_SubGlyphRec_* FT_SubGlyph; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Slot_Internal */ + /* */ + /* <Description> */ + /* An opaque handle to an `FT_Slot_InternalRec' structure, used to */ + /* model private data of a given @FT_GlyphSlot object. */ + /* */ + typedef struct FT_Slot_InternalRec_* FT_Slot_Internal; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_GlyphSlotRec */ + /* */ + /* <Description> */ + /* FreeType root glyph slot class structure. A glyph slot is a */ + /* container where individual glyphs can be loaded, be they in */ + /* outline or bitmap format. */ + /* */ + /* <Fields> */ + /* library :: A handle to the FreeType library instance */ + /* this slot belongs to. */ + /* */ + /* face :: A handle to the parent face object. */ + /* */ + /* next :: In some cases (like some font tools), several */ + /* glyph slots per face object can be a good */ + /* thing. As this is rare, the glyph slots are */ + /* listed through a direct, single-linked list */ + /* using its `next' field. */ + /* */ + /* generic :: A typeless pointer unused by the FreeType */ + /* library or any of its drivers. It can be */ + /* used by client applications to link their own */ + /* data to each glyph slot object. */ + /* */ + /* metrics :: The metrics of the last loaded glyph in the */ + /* slot. The returned values depend on the last */ + /* load flags (see the @FT_Load_Glyph API */ + /* function) and can be expressed either in 26.6 */ + /* fractional pixels or font units. */ + /* */ + /* Note that even when the glyph image is */ + /* transformed, the metrics are not. */ + /* */ + /* linearHoriAdvance :: The advance width of the unhinted glyph. */ + /* Its value is expressed in 16.16 fractional */ + /* pixels, unless @FT_LOAD_LINEAR_DESIGN is set */ + /* when loading the glyph. This field can be */ + /* important to perform correct WYSIWYG layout. */ + /* Only relevant for outline glyphs. */ + /* */ + /* linearVertAdvance :: The advance height of the unhinted glyph. */ + /* Its value is expressed in 16.16 fractional */ + /* pixels, unless @FT_LOAD_LINEAR_DESIGN is set */ + /* when loading the glyph. This field can be */ + /* important to perform correct WYSIWYG layout. */ + /* Only relevant for outline glyphs. */ + /* */ + /* advance :: This shorthand is, depending on */ + /* @FT_LOAD_IGNORE_TRANSFORM, the transformed */ + /* (hinted) advance width for the glyph, in 26.6 */ + /* fractional pixel format. As specified with */ + /* @FT_LOAD_VERTICAL_LAYOUT, it uses either the */ + /* `horiAdvance' or the `vertAdvance' value of */ + /* `metrics' field. */ + /* */ + /* format :: This field indicates the format of the image */ + /* contained in the glyph slot. Typically */ + /* @FT_GLYPH_FORMAT_BITMAP, */ + /* @FT_GLYPH_FORMAT_OUTLINE, or */ + /* @FT_GLYPH_FORMAT_COMPOSITE, but others are */ + /* possible. */ + /* */ + /* bitmap :: This field is used as a bitmap descriptor */ + /* when the slot format is */ + /* @FT_GLYPH_FORMAT_BITMAP. Note that the */ + /* address and content of the bitmap buffer can */ + /* change between calls of @FT_Load_Glyph and a */ + /* few other functions. */ + /* */ + /* bitmap_left :: The bitmap's left bearing expressed in */ + /* integer pixels. Only valid if the format is */ + /* @FT_GLYPH_FORMAT_BITMAP, this is, if the */ + /* glyph slot contains a bitmap. */ + /* */ + /* bitmap_top :: The bitmap's top bearing expressed in integer */ + /* pixels. Remember that this is the distance */ + /* from the baseline to the top-most glyph */ + /* scanline, upwards y~coordinates being */ + /* *positive*. */ + /* */ + /* outline :: The outline descriptor for the current glyph */ + /* image if its format is */ + /* @FT_GLYPH_FORMAT_OUTLINE. Once a glyph is */ + /* loaded, `outline' can be transformed, */ + /* distorted, embolded, etc. However, it must */ + /* not be freed. */ + /* */ + /* num_subglyphs :: The number of subglyphs in a composite glyph. */ + /* This field is only valid for the composite */ + /* glyph format that should normally only be */ + /* loaded with the @FT_LOAD_NO_RECURSE flag. */ + /* */ + /* subglyphs :: An array of subglyph descriptors for */ + /* composite glyphs. There are `num_subglyphs' */ + /* elements in there. Currently internal to */ + /* FreeType. */ + /* */ + /* control_data :: Certain font drivers can also return the */ + /* control data for a given glyph image (e.g. */ + /* TrueType bytecode, Type~1 charstrings, etc.). */ + /* This field is a pointer to such data. */ + /* */ + /* control_len :: This is the length in bytes of the control */ + /* data. */ + /* */ + /* other :: Really wicked formats can use this pointer to */ + /* present their own glyph image to client */ + /* applications. Note that the application */ + /* needs to know about the image format. */ + /* */ + /* lsb_delta :: The difference between hinted and unhinted */ + /* left side bearing while auto-hinting is */ + /* active. Zero otherwise. */ + /* */ + /* rsb_delta :: The difference between hinted and unhinted */ + /* right side bearing while auto-hinting is */ + /* active. Zero otherwise. */ + /* */ + /* <Note> */ + /* If @FT_Load_Glyph is called with default flags (see */ + /* @FT_LOAD_DEFAULT) the glyph image is loaded in the glyph slot in */ + /* its native format (e.g., an outline glyph for TrueType and Type~1 */ + /* formats). */ + /* */ + /* This image can later be converted into a bitmap by calling */ + /* @FT_Render_Glyph. This function finds the current renderer for */ + /* the native image's format, then invokes it. */ + /* */ + /* The renderer is in charge of transforming the native image through */ + /* the slot's face transformation fields, then converting it into a */ + /* bitmap that is returned in `slot->bitmap'. */ + /* */ + /* Note that `slot->bitmap_left' and `slot->bitmap_top' are also used */ + /* to specify the position of the bitmap relative to the current pen */ + /* position (e.g., coordinates (0,0) on the baseline). Of course, */ + /* `slot->format' is also changed to @FT_GLYPH_FORMAT_BITMAP. */ + /* */ + /* <Note> */ + /* Here is a small pseudo code fragment that shows how to use */ + /* `lsb_delta' and `rsb_delta': */ + /* */ + /* { */ + /* FT_Pos origin_x = 0; */ + /* FT_Pos prev_rsb_delta = 0; */ + /* */ + /* */ + /* for all glyphs do */ + /* <compute kern between current and previous glyph and add it to */ + /* `origin_x'> */ + /* */ + /* <load glyph with `FT_Load_Glyph'> */ + /* */ + /* if ( prev_rsb_delta - face->glyph->lsb_delta >= 32 ) */ + /* origin_x -= 64; */ + /* else if ( prev_rsb_delta - face->glyph->lsb_delta < -32 ) */ + /* origin_x += 64; */ + /* */ + /* prev_rsb_delta = face->glyph->rsb_delta; */ + /* */ + /* <save glyph image, or render glyph, or ...> */ + /* */ + /* origin_x += face->glyph->advance.x; */ + /* endfor */ + /* } */ + /* */ + typedef struct FT_GlyphSlotRec_ + { + FT_Library library; + FT_Face face; + FT_GlyphSlot next; + FT_UInt reserved; /* retained for binary compatibility */ + FT_Generic generic; + + FT_Glyph_Metrics metrics; + FT_Fixed linearHoriAdvance; + FT_Fixed linearVertAdvance; + FT_Vector advance; + + FT_Glyph_Format format; + + FT_Bitmap bitmap; + FT_Int bitmap_left; + FT_Int bitmap_top; + + FT_Outline outline; + + FT_UInt num_subglyphs; + FT_SubGlyph subglyphs; + + void* control_data; + long control_len; + + FT_Pos lsb_delta; + FT_Pos rsb_delta; + + void* other; + + FT_Slot_Internal internal; + + } FT_GlyphSlotRec; + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* F U N C T I O N S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Init_FreeType */ + /* */ + /* <Description> */ + /* Initialize a new FreeType library object. The set of modules */ + /* that are registered by this function is determined at build time. */ + /* */ + /* <Output> */ + /* alibrary :: A handle to a new library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* In case you want to provide your own memory allocating routines, */ + /* use @FT_New_Library instead, followed by a call to */ + /* @FT_Add_Default_Modules (or a series of calls to @FT_Add_Module). */ + /* */ + /* See the documentation of @FT_Library and @FT_Face for */ + /* multi-threading issues. */ + /* */ + /* If you need reference-counting (cf. @FT_Reference_Library), use */ + /* @FT_New_Library and @FT_Done_Library. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Init_FreeType( FT_Library *alibrary ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_FreeType */ + /* */ + /* <Description> */ + /* Destroy a given FreeType library object and all of its children, */ + /* including resources, drivers, faces, sizes, etc. */ + /* */ + /* <Input> */ + /* library :: A handle to the target library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_FreeType( FT_Library library ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_OPEN_XXX */ + /* */ + /* <Description> */ + /* A list of bit field constants used within the `flags' field of the */ + /* @FT_Open_Args structure. */ + /* */ + /* <Values> */ + /* FT_OPEN_MEMORY :: This is a memory-based stream. */ + /* */ + /* FT_OPEN_STREAM :: Copy the stream from the `stream' field. */ + /* */ + /* FT_OPEN_PATHNAME :: Create a new input stream from a C~path */ + /* name. */ + /* */ + /* FT_OPEN_DRIVER :: Use the `driver' field. */ + /* */ + /* FT_OPEN_PARAMS :: Use the `num_params' and `params' fields. */ + /* */ + /* <Note> */ + /* The `FT_OPEN_MEMORY', `FT_OPEN_STREAM', and `FT_OPEN_PATHNAME' */ + /* flags are mutually exclusive. */ + /* */ +#define FT_OPEN_MEMORY 0x1 +#define FT_OPEN_STREAM 0x2 +#define FT_OPEN_PATHNAME 0x4 +#define FT_OPEN_DRIVER 0x8 +#define FT_OPEN_PARAMS 0x10 + + + /* these constants are deprecated; use the corresponding `FT_OPEN_XXX' */ + /* values instead */ +#define ft_open_memory FT_OPEN_MEMORY +#define ft_open_stream FT_OPEN_STREAM +#define ft_open_pathname FT_OPEN_PATHNAME +#define ft_open_driver FT_OPEN_DRIVER +#define ft_open_params FT_OPEN_PARAMS + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Parameter */ + /* */ + /* <Description> */ + /* A simple structure used to pass more or less generic parameters to */ + /* @FT_Open_Face. */ + /* */ + /* <Fields> */ + /* tag :: A four-byte identification tag. */ + /* */ + /* data :: A pointer to the parameter data. */ + /* */ + /* <Note> */ + /* The ID and function of parameters are driver-specific. See the */ + /* various FT_PARAM_TAG_XXX flags for more information. */ + /* */ + typedef struct FT_Parameter_ + { + FT_ULong tag; + FT_Pointer data; + + } FT_Parameter; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Open_Args */ + /* */ + /* <Description> */ + /* A structure used to indicate how to open a new font file or */ + /* stream. A pointer to such a structure can be used as a parameter */ + /* for the functions @FT_Open_Face and @FT_Attach_Stream. */ + /* */ + /* <Fields> */ + /* flags :: A set of bit flags indicating how to use the */ + /* structure. */ + /* */ + /* memory_base :: The first byte of the file in memory. */ + /* */ + /* memory_size :: The size in bytes of the file in memory. */ + /* */ + /* pathname :: A pointer to an 8-bit file pathname. */ + /* */ + /* stream :: A handle to a source stream object. */ + /* */ + /* driver :: This field is exclusively used by @FT_Open_Face; */ + /* it simply specifies the font driver to use to open */ + /* the face. If set to~0, FreeType tries to load the */ + /* face with each one of the drivers in its list. */ + /* */ + /* num_params :: The number of extra parameters. */ + /* */ + /* params :: Extra parameters passed to the font driver when */ + /* opening a new face. */ + /* */ + /* <Note> */ + /* The stream type is determined by the contents of `flags' that */ + /* are tested in the following order by @FT_Open_Face: */ + /* */ + /* If the @FT_OPEN_MEMORY bit is set, assume that this is a */ + /* memory file of `memory_size' bytes, located at `memory_address'. */ + /* The data are are not copied, and the client is responsible for */ + /* releasing and destroying them _after_ the corresponding call to */ + /* @FT_Done_Face. */ + /* */ + /* Otherwise, if the @FT_OPEN_STREAM bit is set, assume that a */ + /* custom input stream `stream' is used. */ + /* */ + /* Otherwise, if the @FT_OPEN_PATHNAME bit is set, assume that this */ + /* is a normal file and use `pathname' to open it. */ + /* */ + /* If the @FT_OPEN_DRIVER bit is set, @FT_Open_Face only tries to */ + /* open the file with the driver whose handler is in `driver'. */ + /* */ + /* If the @FT_OPEN_PARAMS bit is set, the parameters given by */ + /* `num_params' and `params' is used. They are ignored otherwise. */ + /* */ + /* Ideally, both the `pathname' and `params' fields should be tagged */ + /* as `const'; this is missing for API backwards compatibility. In */ + /* other words, applications should treat them as read-only. */ + /* */ + typedef struct FT_Open_Args_ + { + FT_UInt flags; + const FT_Byte* memory_base; + FT_Long memory_size; + FT_String* pathname; + FT_Stream stream; + FT_Module driver; + FT_Int num_params; + FT_Parameter* params; + + } FT_Open_Args; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Face */ + /* */ + /* <Description> */ + /* This function calls @FT_Open_Face to open a font by its pathname. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* pathname :: A path to the font file. */ + /* */ + /* face_index :: See @FT_Open_Face for a detailed description of this */ + /* parameter. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Use @FT_Done_Face to destroy the created @FT_Face object (along */ + /* with its slot and sizes). */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Face( FT_Library library, + const char* filepathname, + FT_Long face_index, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Memory_Face */ + /* */ + /* <Description> */ + /* This function calls @FT_Open_Face to open a font that has been */ + /* loaded into memory. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* file_base :: A pointer to the beginning of the font data. */ + /* */ + /* file_size :: The size of the memory chunk used by the font data. */ + /* */ + /* face_index :: See @FT_Open_Face for a detailed description of this */ + /* parameter. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You must not deallocate the memory before calling @FT_Done_Face. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Memory_Face( FT_Library library, + const FT_Byte* file_base, + FT_Long file_size, + FT_Long face_index, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Open_Face */ + /* */ + /* <Description> */ + /* Create a face object from a given resource described by */ + /* @FT_Open_Args. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* args :: A pointer to an `FT_Open_Args' structure that must */ + /* be filled by the caller. */ + /* */ + /* face_index :: This field holds two different values. Bits 0-15 */ + /* are the index of the face in the font file (starting */ + /* with value~0). Set it to~0 if there is only one */ + /* face in the font file. */ + /* */ + /* Bits 16-30 are relevant to GX variation fonts only, */ + /* specifying the named instance index for the current */ + /* face index (starting with value~1; value~0 makes */ + /* FreeType ignore named instances). For non-GX fonts, */ + /* bits 16-30 are ignored. Assuming that you want to */ + /* access the third named instance in face~4, */ + /* `face_index' should be set to 0x00030004. If you */ + /* want to access face~4 without GX variation handling, */ + /* simply set `face_index' to value~4. */ + /* */ + /* FT_Open_Face and its siblings can be used to quickly */ + /* check whether the font format of a given font */ + /* resource is supported by FreeType. In general, if */ + /* the `face_index' argument is negative, the */ + /* function's return value is~0 if the font format is */ + /* recognized, or non-zero otherwise. The function */ + /* allocates a more or less empty face handle in */ + /* `*aface' (if `aface' isn't NULL); the only two */ + /* useful fields in this special case are */ + /* `face->num_faces' and `face->style_flags'. For any */ + /* negative value of `face_index', `face->num_faces' */ + /* gives the number of faces within the font file. For */ + /* the negative value `-(N+1)' (with `N' a 16-bit */ + /* value), bits 16-30 in `face->style_flags' give the */ + /* number of named instances in face `N' if we have a */ + /* GX variation font (or zero otherwise). After */ + /* examination, the returned @FT_Face structure should */ + /* be deallocated with a call to @FT_Done_Face. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Unlike FreeType 1.x, this function automatically creates a glyph */ + /* slot for the face object that can be accessed directly through */ + /* `face->glyph'. */ + /* */ + /* Each new face object created with this function also owns a */ + /* default @FT_Size object, accessible as `face->size'. */ + /* */ + /* One @FT_Library instance can have multiple face objects, this is, */ + /* @FT_Open_Face and its siblings can be called multiple times using */ + /* the same `library' argument. */ + /* */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Face. */ + /* */ + /* To loop over all faces, use code similar to the following snippet */ + /* (omitting the error handling). */ + /* */ + /* { */ + /* ... */ + /* FT_Face face; */ + /* FT_Long i, num_faces; */ + /* */ + /* */ + /* error = FT_Open_Face( library, args, -1, &face ); */ + /* if ( error ) { ... } */ + /* */ + /* num_faces = face->num_faces; */ + /* FT_Done_Face( face ); */ + /* */ + /* for ( i = 0; i < num_faces; i++ ) */ + /* { */ + /* ... */ + /* error = FT_Open_Face( library, args, i, &face ); */ + /* ... */ + /* FT_Done_Face( face ); */ + /* ... */ + /* } */ + /* } */ + /* */ + /* To loop over all valid values for `face_index', use something */ + /* similar to the following snippet, again without error handling. */ + /* The code accesses all faces immediately (thus only a single call */ + /* of `FT_Open_Face' within the do-loop), with and without named */ + /* instances. */ + /* */ + /* { */ + /* ... */ + /* FT_Face face; */ + /* */ + /* FT_Long num_faces = 0; */ + /* FT_Long num_instances = 0; */ + /* */ + /* FT_Long face_idx = 0; */ + /* FT_Long instance_idx = 0; */ + /* */ + /* */ + /* do */ + /* { */ + /* FT_Long id = ( instance_idx << 16 ) + face_idx; */ + /* */ + /* */ + /* error = FT_Open_Face( library, args, id, &face ); */ + /* if ( error ) { ... } */ + /* */ + /* num_faces = face->num_faces; */ + /* num_instances = face->style_flags >> 16; */ + /* */ + /* ... */ + /* */ + /* FT_Done_Face( face ); */ + /* */ + /* if ( instance_idx < num_instances ) */ + /* instance_idx++; */ + /* else */ + /* { */ + /* face_idx++; */ + /* instance_idx = 0; */ + /* } */ + /* */ + /* } while ( face_idx < num_faces ) */ + /* } */ + /* */ + FT_EXPORT( FT_Error ) + FT_Open_Face( FT_Library library, + const FT_Open_Args* args, + FT_Long face_index, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Attach_File */ + /* */ + /* <Description> */ + /* This function calls @FT_Attach_Stream to attach a file. */ + /* */ + /* <InOut> */ + /* face :: The target face object. */ + /* */ + /* <Input> */ + /* filepathname :: The pathname. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Attach_File( FT_Face face, + const char* filepathname ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Attach_Stream */ + /* */ + /* <Description> */ + /* `Attach' data to a face object. Normally, this is used to read */ + /* additional information for the face object. For example, you can */ + /* attach an AFM file that comes with a Type~1 font to get the */ + /* kerning values and other metrics. */ + /* */ + /* <InOut> */ + /* face :: The target face object. */ + /* */ + /* <Input> */ + /* parameters :: A pointer to @FT_Open_Args that must be filled by */ + /* the caller. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The meaning of the `attach' (i.e., what really happens when the */ + /* new file is read) is not fixed by FreeType itself. It really */ + /* depends on the font format (and thus the font driver). */ + /* */ + /* Client applications are expected to know what they are doing */ + /* when invoking this function. Most drivers simply do not implement */ + /* file attachments. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Attach_Stream( FT_Face face, + FT_Open_Args* parameters ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Reference_Face */ + /* */ + /* <Description> */ + /* A counter gets initialized to~1 at the time an @FT_Face structure */ + /* is created. This function increments the counter. @FT_Done_Face */ + /* then only destroys a face if the counter is~1, otherwise it simply */ + /* decrements the counter. */ + /* */ + /* This function helps in managing life-cycles of structures that */ + /* reference @FT_Face objects. */ + /* */ + /* <Input> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Since> */ + /* 2.4.2 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Reference_Face( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_Face */ + /* */ + /* <Description> */ + /* Discard a given face object, as well as all of its child slots and */ + /* sizes. */ + /* */ + /* <Input> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Face. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_Face( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Select_Size */ + /* */ + /* <Description> */ + /* Select a bitmap strike. */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Input> */ + /* strike_index :: The index of the bitmap strike in the */ + /* `available_sizes' field of @FT_FaceRec structure. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Select_Size( FT_Face face, + FT_Int strike_index ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Size_Request_Type */ + /* */ + /* <Description> */ + /* An enumeration type that lists the supported size request types. */ + /* */ + /* <Values> */ + /* FT_SIZE_REQUEST_TYPE_NOMINAL :: */ + /* The nominal size. The `units_per_EM' field of @FT_FaceRec is */ + /* used to determine both scaling values. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_REAL_DIM :: */ + /* The real dimension. The sum of the the `ascender' and (minus */ + /* of) the `descender' fields of @FT_FaceRec are used to determine */ + /* both scaling values. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_BBOX :: */ + /* The font bounding box. The width and height of the `bbox' field */ + /* of @FT_FaceRec are used to determine the horizontal and vertical */ + /* scaling value, respectively. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_CELL :: */ + /* The `max_advance_width' field of @FT_FaceRec is used to */ + /* determine the horizontal scaling value; the vertical scaling */ + /* value is determined the same way as */ + /* @FT_SIZE_REQUEST_TYPE_REAL_DIM does. Finally, both scaling */ + /* values are set to the smaller one. This type is useful if you */ + /* want to specify the font size for, say, a window of a given */ + /* dimension and 80x24 cells. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_SCALES :: */ + /* Specify the scaling values directly. */ + /* */ + /* <Note> */ + /* The above descriptions only apply to scalable formats. For bitmap */ + /* formats, the behaviour is up to the driver. */ + /* */ + /* See the note section of @FT_Size_Metrics if you wonder how size */ + /* requesting relates to scaling values. */ + /* */ + typedef enum FT_Size_Request_Type_ + { + FT_SIZE_REQUEST_TYPE_NOMINAL, + FT_SIZE_REQUEST_TYPE_REAL_DIM, + FT_SIZE_REQUEST_TYPE_BBOX, + FT_SIZE_REQUEST_TYPE_CELL, + FT_SIZE_REQUEST_TYPE_SCALES, + + FT_SIZE_REQUEST_TYPE_MAX + + } FT_Size_Request_Type; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Size_RequestRec */ + /* */ + /* <Description> */ + /* A structure used to model a size request. */ + /* */ + /* <Fields> */ + /* type :: See @FT_Size_Request_Type. */ + /* */ + /* width :: The desired width. */ + /* */ + /* height :: The desired height. */ + /* */ + /* horiResolution :: The horizontal resolution. If set to zero, */ + /* `width' is treated as a 26.6 fractional pixel */ + /* value. */ + /* */ + /* vertResolution :: The vertical resolution. If set to zero, */ + /* `height' is treated as a 26.6 fractional pixel */ + /* value. */ + /* */ + /* <Note> */ + /* If `width' is zero, then the horizontal scaling value is set equal */ + /* to the vertical scaling value, and vice versa. */ + /* */ + typedef struct FT_Size_RequestRec_ + { + FT_Size_Request_Type type; + FT_Long width; + FT_Long height; + FT_UInt horiResolution; + FT_UInt vertResolution; + + } FT_Size_RequestRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Size_Request */ + /* */ + /* <Description> */ + /* A handle to a size request structure. */ + /* */ + typedef struct FT_Size_RequestRec_ *FT_Size_Request; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Request_Size */ + /* */ + /* <Description> */ + /* Resize the scale of the active @FT_Size object in a face. */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Input> */ + /* req :: A pointer to a @FT_Size_RequestRec. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Although drivers may select the bitmap strike matching the */ + /* request, you should not rely on this if you intend to select a */ + /* particular bitmap strike. Use @FT_Select_Size instead in that */ + /* case. */ + /* */ + /* The relation between the requested size and the resulting glyph */ + /* size is dependent entirely on how the size is defined in the */ + /* source face. The font designer chooses the final size of each */ + /* glyph relative to this size. For more information refer to */ + /* `http://www.freetype.org/freetype2/docs/glyphs/glyphs-2.html' */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Request_Size( FT_Face face, + FT_Size_Request req ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Char_Size */ + /* */ + /* <Description> */ + /* This function calls @FT_Request_Size to request the nominal size */ + /* (in points). */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Input> */ + /* char_width :: The nominal width, in 26.6 fractional points. */ + /* */ + /* char_height :: The nominal height, in 26.6 fractional points. */ + /* */ + /* horz_resolution :: The horizontal resolution in dpi. */ + /* */ + /* vert_resolution :: The vertical resolution in dpi. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* If either the character width or height is zero, it is set equal */ + /* to the other value. */ + /* */ + /* If either the horizontal or vertical resolution is zero, it is set */ + /* equal to the other value. */ + /* */ + /* A character width or height smaller than 1pt is set to 1pt; if */ + /* both resolution values are zero, they are set to 72dpi. */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Char_Size( FT_Face face, + FT_F26Dot6 char_width, + FT_F26Dot6 char_height, + FT_UInt horz_resolution, + FT_UInt vert_resolution ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Pixel_Sizes */ + /* */ + /* <Description> */ + /* This function calls @FT_Request_Size to request the nominal size */ + /* (in pixels). */ + /* */ + /* <InOut> */ + /* face :: A handle to the target face object. */ + /* */ + /* <Input> */ + /* pixel_width :: The nominal width, in pixels. */ + /* */ + /* pixel_height :: The nominal height, in pixels. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You should not rely on the resulting glyphs matching, or being */ + /* constrained, to this pixel size. Refer to @FT_Request_Size to */ + /* understand how requested sizes relate to actual sizes. */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Pixel_Sizes( FT_Face face, + FT_UInt pixel_width, + FT_UInt pixel_height ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Load_Glyph */ + /* */ + /* <Description> */ + /* A function used to load a single glyph into the glyph slot of a */ + /* face object. */ + /* */ + /* <InOut> */ + /* face :: A handle to the target face object where the glyph */ + /* is loaded. */ + /* */ + /* <Input> */ + /* glyph_index :: The index of the glyph in the font file. For */ + /* CID-keyed fonts (either in PS or in CFF format) */ + /* this argument specifies the CID value. */ + /* */ + /* load_flags :: A flag indicating what to load for this glyph. The */ + /* @FT_LOAD_XXX constants can be used to control the */ + /* glyph loading process (e.g., whether the outline */ + /* should be scaled, whether to load bitmaps or not, */ + /* whether to hint the outline, etc). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The loaded glyph may be transformed. See @FT_Set_Transform for */ + /* the details. */ + /* */ + /* For subsetted CID-keyed fonts, `FT_Err_Invalid_Argument' is */ + /* returned for invalid CID values (this is, for CID values that */ + /* don't have a corresponding glyph in the font). See the discussion */ + /* of the @FT_FACE_FLAG_CID_KEYED flag for more details. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Load_Glyph( FT_Face face, + FT_UInt glyph_index, + FT_Int32 load_flags ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Load_Char */ + /* */ + /* <Description> */ + /* A function used to load a single glyph into the glyph slot of a */ + /* face object, according to its character code. */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object where the glyph */ + /* is loaded. */ + /* */ + /* <Input> */ + /* char_code :: The glyph's character code, according to the */ + /* current charmap used in the face. */ + /* */ + /* load_flags :: A flag indicating what to load for this glyph. The */ + /* @FT_LOAD_XXX constants can be used to control the */ + /* glyph loading process (e.g., whether the outline */ + /* should be scaled, whether to load bitmaps or not, */ + /* whether to hint the outline, etc). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function simply calls @FT_Get_Char_Index and @FT_Load_Glyph. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Load_Char( FT_Face face, + FT_ULong char_code, + FT_Int32 load_flags ); + + + /************************************************************************* + * + * @enum: + * FT_LOAD_XXX + * + * @description: + * A list of bit field constants used with @FT_Load_Glyph to indicate + * what kind of operations to perform during glyph loading. + * + * @values: + * FT_LOAD_DEFAULT :: + * Corresponding to~0, this value is used as the default glyph load + * operation. In this case, the following happens: + * + * 1. FreeType looks for a bitmap for the glyph corresponding to the + * face's current size. If one is found, the function returns. + * The bitmap data can be accessed from the glyph slot (see note + * below). + * + * 2. If no embedded bitmap is searched or found, FreeType looks for a + * scalable outline. If one is found, it is loaded from the font + * file, scaled to device pixels, then `hinted' to the pixel grid + * in order to optimize it. The outline data can be accessed from + * the glyph slot (see note below). + * + * Note that by default, the glyph loader doesn't render outlines into + * bitmaps. The following flags are used to modify this default + * behaviour to more specific and useful cases. + * + * FT_LOAD_NO_SCALE :: + * Don't scale the loaded outline glyph but keep it in font units. + * + * This flag implies @FT_LOAD_NO_HINTING and @FT_LOAD_NO_BITMAP, and + * unsets @FT_LOAD_RENDER. + * + * If the font is `tricky' (see @FT_FACE_FLAG_TRICKY for more), using + * FT_LOAD_NO_SCALE usually yields meaningless outlines because the + * subglyphs must be scaled and positioned with hinting instructions. + * This can be solved by loading the font without FT_LOAD_NO_SCALE and + * setting the character size to `font->units_per_EM'. + * + * FT_LOAD_NO_HINTING :: + * Disable hinting. This generally generates `blurrier' bitmap glyphs + * when the glyph are rendered in any of the anti-aliased modes. See + * also the note below. + * + * This flag is implied by @FT_LOAD_NO_SCALE. + * + * FT_LOAD_RENDER :: + * Call @FT_Render_Glyph after the glyph is loaded. By default, the + * glyph is rendered in @FT_RENDER_MODE_NORMAL mode. This can be + * overridden by @FT_LOAD_TARGET_XXX or @FT_LOAD_MONOCHROME. + * + * This flag is unset by @FT_LOAD_NO_SCALE. + * + * FT_LOAD_NO_BITMAP :: + * Ignore bitmap strikes when loading. Bitmap-only fonts ignore this + * flag. + * + * @FT_LOAD_NO_SCALE always sets this flag. + * + * FT_LOAD_VERTICAL_LAYOUT :: + * Load the glyph for vertical text layout. In particular, the + * `advance' value in the @FT_GlyphSlotRec structure is set to the + * `vertAdvance' value of the `metrics' field. + * + * In case @FT_HAS_VERTICAL doesn't return true, you shouldn't use + * this flag currently. Reason is that in this case vertical metrics + * get synthesized, and those values are not always consistent across + * various font formats. + * + * FT_LOAD_FORCE_AUTOHINT :: + * Indicates that the auto-hinter is preferred over the font's native + * hinter. See also the note below. + * + * FT_LOAD_PEDANTIC :: + * Indicates that the font driver should perform pedantic verifications + * during glyph loading. This is mostly used to detect broken glyphs + * in fonts. By default, FreeType tries to handle broken fonts also. + * + * In particular, errors from the TrueType bytecode engine are not + * passed to the application if this flag is not set; this might + * result in partially hinted or distorted glyphs in case a glyph's + * bytecode is buggy. + * + * FT_LOAD_NO_RECURSE :: + * Indicate that the font driver should not load composite glyphs + * recursively. Instead, it should set the `num_subglyph' and + * `subglyphs' values of the glyph slot accordingly, and set + * `glyph->format' to @FT_GLYPH_FORMAT_COMPOSITE. The description of + * subglyphs can then be accessed with @FT_Get_SubGlyph_Info. + * + * This flag implies @FT_LOAD_NO_SCALE and @FT_LOAD_IGNORE_TRANSFORM. + * + * FT_LOAD_IGNORE_TRANSFORM :: + * Indicates that the transform matrix set by @FT_Set_Transform should + * be ignored. + * + * FT_LOAD_MONOCHROME :: + * This flag is used with @FT_LOAD_RENDER to indicate that you want to + * render an outline glyph to a 1-bit monochrome bitmap glyph, with + * 8~pixels packed into each byte of the bitmap data. + * + * Note that this has no effect on the hinting algorithm used. You + * should rather use @FT_LOAD_TARGET_MONO so that the + * monochrome-optimized hinting algorithm is used. + * + * FT_LOAD_LINEAR_DESIGN :: + * Indicates that the `linearHoriAdvance' and `linearVertAdvance' + * fields of @FT_GlyphSlotRec should be kept in font units. See + * @FT_GlyphSlotRec for details. + * + * FT_LOAD_NO_AUTOHINT :: + * Disable auto-hinter. See also the note below. + * + * FT_LOAD_COLOR :: + * This flag is used to request loading of color embedded-bitmap + * images. The resulting color bitmaps, if available, will have the + * @FT_PIXEL_MODE_BGRA format. When the flag is not used and color + * bitmaps are found, they will be converted to 256-level gray + * bitmaps transparently. Those bitmaps will be in the + * @FT_PIXEL_MODE_GRAY format. + * + * FT_LOAD_COMPUTE_METRICS :: + * This flag sets computing glyph metrics without the use of bundled + * metrics tables (for example, the `hdmx' table in TrueType fonts). + * Well-behaving fonts have optimized bundled metrics and these should + * be used. This flag is mainly used by font validating or font + * editing applications, which need to ignore, verify, or edit those + * tables. + * + * Currently, this flag is only implemented for TrueType fonts. + * + * FT_LOAD_CROP_BITMAP :: + * Ignored. Deprecated. + * + * FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH :: + * Ignored. Deprecated. + * + * @note: + * By default, hinting is enabled and the font's native hinter (see + * @FT_FACE_FLAG_HINTER) is preferred over the auto-hinter. You can + * disable hinting by setting @FT_LOAD_NO_HINTING or change the + * precedence by setting @FT_LOAD_FORCE_AUTOHINT. You can also set + * @FT_LOAD_NO_AUTOHINT in case you don't want the auto-hinter to be + * used at all. + * + * See the description of @FT_FACE_FLAG_TRICKY for a special exception + * (affecting only a handful of Asian fonts). + * + * Besides deciding which hinter to use, you can also decide which + * hinting algorithm to use. See @FT_LOAD_TARGET_XXX for details. + * + * Note that the auto-hinter needs a valid Unicode cmap (either a native + * one or synthesized by FreeType) for producing correct results. If a + * font provides an incorrect mapping (for example, assigning the + * character code U+005A, LATIN CAPITAL LETTER Z, to a glyph depicting a + * mathematical integral sign), the auto-hinter might produce useless + * results. + * + */ +#define FT_LOAD_DEFAULT 0x0 +#define FT_LOAD_NO_SCALE ( 1L << 0 ) +#define FT_LOAD_NO_HINTING ( 1L << 1 ) +#define FT_LOAD_RENDER ( 1L << 2 ) +#define FT_LOAD_NO_BITMAP ( 1L << 3 ) +#define FT_LOAD_VERTICAL_LAYOUT ( 1L << 4 ) +#define FT_LOAD_FORCE_AUTOHINT ( 1L << 5 ) +#define FT_LOAD_CROP_BITMAP ( 1L << 6 ) +#define FT_LOAD_PEDANTIC ( 1L << 7 ) +#define FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ( 1L << 9 ) +#define FT_LOAD_NO_RECURSE ( 1L << 10 ) +#define FT_LOAD_IGNORE_TRANSFORM ( 1L << 11 ) +#define FT_LOAD_MONOCHROME ( 1L << 12 ) +#define FT_LOAD_LINEAR_DESIGN ( 1L << 13 ) +#define FT_LOAD_NO_AUTOHINT ( 1L << 15 ) + /* Bits 16..19 are used by `FT_LOAD_TARGET_' */ +#define FT_LOAD_COLOR ( 1L << 20 ) +#define FT_LOAD_COMPUTE_METRICS ( 1L << 21 ) + + /* */ + + /* used internally only by certain font drivers! */ +#define FT_LOAD_ADVANCE_ONLY ( 1L << 8 ) +#define FT_LOAD_SBITS_ONLY ( 1L << 14 ) + + + /************************************************************************** + * + * @enum: + * FT_LOAD_TARGET_XXX + * + * @description: + * A list of values that are used to select a specific hinting algorithm + * to use by the hinter. You should OR one of these values to your + * `load_flags' when calling @FT_Load_Glyph. + * + * Note that font's native hinters may ignore the hinting algorithm you + * have specified (e.g., the TrueType bytecode interpreter). You can set + * @FT_LOAD_FORCE_AUTOHINT to ensure that the auto-hinter is used. + * + * @values: + * FT_LOAD_TARGET_NORMAL :: + * This corresponds to the default hinting algorithm, optimized for + * standard gray-level rendering. For monochrome output, use + * @FT_LOAD_TARGET_MONO instead. + * + * FT_LOAD_TARGET_LIGHT :: + * A lighter hinting algorithm for gray-level modes. Many generated + * glyphs are fuzzier but better resemble their original shape. This + * is achieved by snapping glyphs to the pixel grid only vertically + * (Y-axis), as is done by Microsoft's ClearType and Adobe's + * proprietary font renderer. This preserves inter-glyph spacing in + * horizontal text. The snapping is done either by the native font + * driver if the driver itself and the font support it or by the + * auto-hinter. + * + * FT_LOAD_TARGET_MONO :: + * Strong hinting algorithm that should only be used for monochrome + * output. The result is probably unpleasant if the glyph is rendered + * in non-monochrome modes. + * + * FT_LOAD_TARGET_LCD :: + * A variant of @FT_LOAD_TARGET_NORMAL optimized for horizontally + * decimated LCD displays. + * + * FT_LOAD_TARGET_LCD_V :: + * A variant of @FT_LOAD_TARGET_NORMAL optimized for vertically + * decimated LCD displays. + * + * @note: + * You should use only _one_ of the FT_LOAD_TARGET_XXX values in your + * `load_flags'. They can't be ORed. + * + * If @FT_LOAD_RENDER is also set, the glyph is rendered in the + * corresponding mode (i.e., the mode that matches the used algorithm + * best). An exeption is FT_LOAD_TARGET_MONO since it implies + * @FT_LOAD_MONOCHROME. + * + * You can use a hinting algorithm that doesn't correspond to the same + * rendering mode. As an example, it is possible to use the `light' + * hinting algorithm and have the results rendered in horizontal LCD + * pixel mode, with code like + * + * { + * FT_Load_Glyph( face, glyph_index, + * load_flags | FT_LOAD_TARGET_LIGHT ); + * + * FT_Render_Glyph( face->glyph, FT_RENDER_MODE_LCD ); + * } + * + */ +#define FT_LOAD_TARGET_( x ) ( (FT_Int32)( (x) & 15 ) << 16 ) + +#define FT_LOAD_TARGET_NORMAL FT_LOAD_TARGET_( FT_RENDER_MODE_NORMAL ) +#define FT_LOAD_TARGET_LIGHT FT_LOAD_TARGET_( FT_RENDER_MODE_LIGHT ) +#define FT_LOAD_TARGET_MONO FT_LOAD_TARGET_( FT_RENDER_MODE_MONO ) +#define FT_LOAD_TARGET_LCD FT_LOAD_TARGET_( FT_RENDER_MODE_LCD ) +#define FT_LOAD_TARGET_LCD_V FT_LOAD_TARGET_( FT_RENDER_MODE_LCD_V ) + + + /************************************************************************** + * + * @macro: + * FT_LOAD_TARGET_MODE + * + * @description: + * Return the @FT_Render_Mode corresponding to a given + * @FT_LOAD_TARGET_XXX value. + * + */ +#define FT_LOAD_TARGET_MODE( x ) ( (FT_Render_Mode)( ( (x) >> 16 ) & 15 ) ) + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Transform */ + /* */ + /* <Description> */ + /* A function used to set the transformation that is applied to glyph */ + /* images when they are loaded into a glyph slot through */ + /* @FT_Load_Glyph. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to the transformation's 2x2 matrix. Use~0 for */ + /* the identity matrix. */ + /* delta :: A pointer to the translation vector. Use~0 for the null */ + /* vector. */ + /* */ + /* <Note> */ + /* The transformation is only applied to scalable image formats after */ + /* the glyph has been loaded. It means that hinting is unaltered by */ + /* the transformation and is performed on the character size given in */ + /* the last call to @FT_Set_Char_Size or @FT_Set_Pixel_Sizes. */ + /* */ + /* Note that this also transforms the `face.glyph.advance' field, but */ + /* *not* the values in `face.glyph.metrics'. */ + /* */ + FT_EXPORT( void ) + FT_Set_Transform( FT_Face face, + FT_Matrix* matrix, + FT_Vector* delta ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Render_Mode */ + /* */ + /* <Description> */ + /* An enumeration type that lists the render modes supported by */ + /* FreeType~2. Each mode corresponds to a specific type of scanline */ + /* conversion performed on the outline. */ + /* */ + /* For bitmap fonts and embedded bitmaps the `bitmap->pixel_mode' */ + /* field in the @FT_GlyphSlotRec structure gives the format of the */ + /* returned bitmap. */ + /* */ + /* All modes except @FT_RENDER_MODE_MONO use 256 levels of opacity, */ + /* indicating pixel coverage. Use linear alpha blending and gamma */ + /* correction to correctly render non-monochrome glyph bitmaps onto a */ + /* surface; see @FT_Render_Glyph. */ + /* */ + /* <Values> */ + /* FT_RENDER_MODE_NORMAL :: */ + /* This is the default render mode; it corresponds to 8-bit */ + /* anti-aliased bitmaps. */ + /* */ + /* FT_RENDER_MODE_LIGHT :: */ + /* This is equivalent to @FT_RENDER_MODE_NORMAL. It is only */ + /* defined as a separate value because render modes are also used */ + /* indirectly to define hinting algorithm selectors. See */ + /* @FT_LOAD_TARGET_XXX for details. */ + /* */ + /* FT_RENDER_MODE_MONO :: */ + /* This mode corresponds to 1-bit bitmaps (with 2~levels of */ + /* opacity). */ + /* */ + /* FT_RENDER_MODE_LCD :: */ + /* This mode corresponds to horizontal RGB and BGR sub-pixel */ + /* displays like LCD screens. It produces 8-bit bitmaps that are */ + /* 3~times the width of the original glyph outline in pixels, and */ + /* which use the @FT_PIXEL_MODE_LCD mode. */ + /* */ + /* FT_RENDER_MODE_LCD_V :: */ + /* This mode corresponds to vertical RGB and BGR sub-pixel displays */ + /* (like PDA screens, rotated LCD displays, etc.). It produces */ + /* 8-bit bitmaps that are 3~times the height of the original */ + /* glyph outline in pixels and use the @FT_PIXEL_MODE_LCD_V mode. */ + /* */ + /* <Note> */ + /* The LCD-optimized glyph bitmaps produced by FT_Render_Glyph can be */ + /* filtered to reduce color-fringes by using @FT_Library_SetLcdFilter */ + /* (not active in the default builds). It is up to the caller to */ + /* either call @FT_Library_SetLcdFilter (if available) or do the */ + /* filtering itself. */ + /* */ + /* The selected render mode only affects vector glyphs of a font. */ + /* Embedded bitmaps often have a different pixel mode like */ + /* @FT_PIXEL_MODE_MONO. You can use @FT_Bitmap_Convert to transform */ + /* them into 8-bit pixmaps. */ + /* */ + typedef enum FT_Render_Mode_ + { + FT_RENDER_MODE_NORMAL = 0, + FT_RENDER_MODE_LIGHT, + FT_RENDER_MODE_MONO, + FT_RENDER_MODE_LCD, + FT_RENDER_MODE_LCD_V, + + FT_RENDER_MODE_MAX + + } FT_Render_Mode; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Render_Mode' values instead */ +#define ft_render_mode_normal FT_RENDER_MODE_NORMAL +#define ft_render_mode_mono FT_RENDER_MODE_MONO + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Render_Glyph */ + /* */ + /* <Description> */ + /* Convert a given glyph image to a bitmap. It does so by inspecting */ + /* the glyph image format, finding the relevant renderer, and */ + /* invoking it. */ + /* */ + /* <InOut> */ + /* slot :: A handle to the glyph slot containing the image to */ + /* convert. */ + /* */ + /* <Input> */ + /* render_mode :: This is the render mode used to render the glyph */ + /* image into a bitmap. See @FT_Render_Mode for a */ + /* list of possible values. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* To get meaningful results, font scaling values must be set with */ + /* functions like @FT_Set_Char_Size before calling FT_Render_Glyph. */ + /* */ + /* When FreeType outputs a bitmap of a glyph, it really outputs an */ + /* alpha coverage map. If a pixel is completely covered by a */ + /* filled-in outline, the bitmap contains 0xFF at that pixel, meaning */ + /* that 0xFF/0xFF fraction of that pixel is covered, meaning the */ + /* pixel is 100% black (or 0% bright). If a pixel is only 50% */ + /* covered (value 0x80), the pixel is made 50% black (50% bright or a */ + /* middle shade of grey). 0% covered means 0% black (100% bright or */ + /* white). */ + /* */ + /* On high-DPI screens like on smartphones and tablets, the pixels */ + /* are so small that their chance of being completely covered and */ + /* therefore completely black are fairly good. On the low-DPI */ + /* screens, however, the situation is different. The pixels are too */ + /* large for most of the details of a glyph and shades of gray are */ + /* the norm rather than the exception. */ + /* */ + /* This is relevant because all our screens have a second problem: */ + /* they are not linear. 1~+~1 is not~2. Twice the value does not */ + /* result in twice the brightness. When a pixel is only 50% covered, */ + /* the coverage map says 50% black, and this translates to a pixel */ + /* value of 128 when you use 8~bits per channel (0-255). However, */ + /* this does not translate to 50% brightness for that pixel on our */ + /* sRGB and gamma~2.2 screens. Due to their non-linearity, they */ + /* dwell longer in the darks and only a pixel value of about 186 */ + /* results in 50% brightness – 128 ends up too dark on both bright */ + /* and dark backgrounds. The net result is that dark text looks */ + /* burnt-out, pixely and blotchy on bright background, bright text */ + /* too frail on dark backgrounds, and colored text on colored */ + /* background (for example, red on green) seems to have dark halos or */ + /* `dirt' around it. The situation is especially ugly for diagonal */ + /* stems like in `w' glyph shapes where the quality of FreeType's */ + /* anti-aliasing depends on the correct display of grays. On */ + /* high-DPI screens where smaller, fully black pixels reign supreme, */ + /* this doesn't matter, but on our low-DPI screens with all the gray */ + /* shades, it does. 0% and 100% brightness are the same things in */ + /* linear and non-linear space, just all the shades in-between */ + /* aren't. */ + /* */ + /* The blending function for placing text over a background is */ + /* */ + /* { */ + /* dst = alpha * src + (1 - alpha) * dst , */ + /* } */ + /* */ + /* which is known as the OVER operator. */ + /* */ + /* To correctly composite an antialiased pixel of a glyph onto a */ + /* surface, */ + /* */ + /* 1. take the foreground and background colors (e.g., in sRGB space) */ + /* and apply gamma to get them in a linear space, */ + /* */ + /* 2. use OVER to blend the two linear colors using the glyph pixel */ + /* as the alpha value (remember, the glyph bitmap is an alpha */ + /* coverage bitmap), and */ + /* */ + /* 3. apply inverse gamma to the blended pixel and write it back to */ + /* the image. */ + /* */ + /* Internal testing at Adobe found that a target inverse gamma of~1.8 */ + /* for step~3 gives good results across a wide range of displays with */ + /* an sRGB gamma curve or a similar one. */ + /* */ + /* This process can cost performance. There is an approximation that */ + /* does not need to know about the background color; see */ + /* https://bel.fi/alankila/lcd/ and */ + /* https://bel.fi/alankila/lcd/alpcor.html for details. */ + /* */ + /* *ATTENTION*: Linear blending is even more important when dealing */ + /* with subpixel-rendered glyphs to prevent color-fringing! A */ + /* subpixel-rendered glyph must first be filtered with a filter that */ + /* gives equal weight to the three color primaries and does not */ + /* exceed a sum of 0x100, see section @lcd_filtering. Then the */ + /* only difference to gray linear blending is that subpixel-rendered */ + /* linear blending is done 3~times per pixel: red foreground subpixel */ + /* to red background subpixel and so on for green and blue. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Render_Glyph( FT_GlyphSlot slot, + FT_Render_Mode render_mode ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Kerning_Mode */ + /* */ + /* <Description> */ + /* An enumeration used to specify which kerning values to return in */ + /* @FT_Get_Kerning. */ + /* */ + /* <Values> */ + /* FT_KERNING_DEFAULT :: Return grid-fitted kerning distances in */ + /* pixels (value is~0). Whether they are */ + /* scaled depends on @FT_LOAD_NO_SCALE. */ + /* */ + /* FT_KERNING_UNFITTED :: Return un-grid-fitted kerning distances in */ + /* 26.6 fractional pixels. Whether they are */ + /* scaled depends on @FT_LOAD_NO_SCALE. */ + /* */ + /* FT_KERNING_UNSCALED :: Return the kerning vector in original font */ + /* units. */ + /* */ + /* <Note> */ + /* FT_KERNING_DEFAULT returns full pixel values; it also makes */ + /* FreeType heuristically scale down kerning distances at small ppem */ + /* values so that they don't become too big. */ + /* */ + typedef enum FT_Kerning_Mode_ + { + FT_KERNING_DEFAULT = 0, + FT_KERNING_UNFITTED, + FT_KERNING_UNSCALED + + } FT_Kerning_Mode; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Kerning_Mode' values instead */ +#define ft_kerning_default FT_KERNING_DEFAULT +#define ft_kerning_unfitted FT_KERNING_UNFITTED +#define ft_kerning_unscaled FT_KERNING_UNSCALED + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Kerning */ + /* */ + /* <Description> */ + /* Return the kerning vector between two glyphs of a same face. */ + /* */ + /* <Input> */ + /* face :: A handle to a source face object. */ + /* */ + /* left_glyph :: The index of the left glyph in the kern pair. */ + /* */ + /* right_glyph :: The index of the right glyph in the kern pair. */ + /* */ + /* kern_mode :: See @FT_Kerning_Mode for more information. */ + /* Determines the scale and dimension of the returned */ + /* kerning vector. */ + /* */ + /* <Output> */ + /* akerning :: The kerning vector. This is either in font units, */ + /* fractional pixels (26.6 format), or pixels for */ + /* scalable formats, and in pixels for fixed-sizes */ + /* formats. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Only horizontal layouts (left-to-right & right-to-left) are */ + /* supported by this method. Other layouts, or more sophisticated */ + /* kernings, are out of the scope of this API function -- they can be */ + /* implemented through format-specific interfaces. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Kerning( FT_Face face, + FT_UInt left_glyph, + FT_UInt right_glyph, + FT_UInt kern_mode, + FT_Vector *akerning ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Track_Kerning */ + /* */ + /* <Description> */ + /* Return the track kerning for a given face object at a given size. */ + /* */ + /* <Input> */ + /* face :: A handle to a source face object. */ + /* */ + /* point_size :: The point size in 16.16 fractional points. */ + /* */ + /* degree :: The degree of tightness. Increasingly negative */ + /* values represent tighter track kerning, while */ + /* increasingly positive values represent looser track */ + /* kerning. Value zero means no track kerning. */ + /* */ + /* <Output> */ + /* akerning :: The kerning in 16.16 fractional points, to be */ + /* uniformly applied between all glyphs. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Currently, only the Type~1 font driver supports track kerning, */ + /* using data from AFM files (if attached with @FT_Attach_File or */ + /* @FT_Attach_Stream). */ + /* */ + /* Only very few AFM files come with track kerning data; please refer */ + /* to the Adobe's AFM specification for more details. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Track_Kerning( FT_Face face, + FT_Fixed point_size, + FT_Int degree, + FT_Fixed* akerning ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Glyph_Name */ + /* */ + /* <Description> */ + /* Retrieve the ASCII name of a given glyph in a face. This only */ + /* works for those faces where @FT_HAS_GLYPH_NAMES(face) returns~1. */ + /* */ + /* <Input> */ + /* face :: A handle to a source face object. */ + /* */ + /* glyph_index :: The glyph index. */ + /* */ + /* buffer_max :: The maximum number of bytes available in the */ + /* buffer. */ + /* */ + /* <Output> */ + /* buffer :: A pointer to a target buffer where the name is */ + /* copied to. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* An error is returned if the face doesn't provide glyph names or if */ + /* the glyph index is invalid. In all cases of failure, the first */ + /* byte of `buffer' is set to~0 to indicate an empty name. */ + /* */ + /* The glyph name is truncated to fit within the buffer if it is too */ + /* long. The returned string is always zero-terminated. */ + /* */ + /* Be aware that FreeType reorders glyph indices internally so that */ + /* glyph index~0 always corresponds to the `missing glyph' (called */ + /* `.notdef'). */ + /* */ + /* This function always returns an error if the config macro */ + /* `FT_CONFIG_OPTION_NO_GLYPH_NAMES' is not defined in `ftoptions.h'. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Glyph_Name( FT_Face face, + FT_UInt glyph_index, + FT_Pointer buffer, + FT_UInt buffer_max ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Postscript_Name */ + /* */ + /* <Description> */ + /* Retrieve the ASCII PostScript name of a given face, if available. */ + /* This only works with PostScript and TrueType fonts. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Return> */ + /* A pointer to the face's PostScript name. NULL if unavailable. */ + /* */ + /* <Note> */ + /* The returned pointer is owned by the face and is destroyed with */ + /* it. */ + /* */ + FT_EXPORT( const char* ) + FT_Get_Postscript_Name( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Select_Charmap */ + /* */ + /* <Description> */ + /* Select a given charmap by its encoding tag (as listed in */ + /* `freetype.h'). */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Input> */ + /* encoding :: A handle to the selected encoding. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function returns an error if no charmap in the face */ + /* corresponds to the encoding queried here. */ + /* */ + /* Because many fonts contain more than a single cmap for Unicode */ + /* encoding, this function has some special code to select the one */ + /* that covers Unicode best (`best' in the sense that a UCS-4 cmap is */ + /* preferred to a UCS-2 cmap). It is thus preferable to */ + /* @FT_Set_Charmap in this case. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Select_Charmap( FT_Face face, + FT_Encoding encoding ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Charmap */ + /* */ + /* <Description> */ + /* Select a given charmap for character code to glyph index mapping. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Input> */ + /* charmap :: A handle to the selected charmap. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function returns an error if the charmap is not part of */ + /* the face (i.e., if it is not listed in the `face->charmaps' */ + /* table). */ + /* */ + /* It also fails if a type~14 charmap is selected. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Charmap( FT_Face face, + FT_CharMap charmap ); + + + /************************************************************************* + * + * @function: + * FT_Get_Charmap_Index + * + * @description: + * Retrieve index of a given charmap. + * + * @input: + * charmap :: + * A handle to a charmap. + * + * @return: + * The index into the array of character maps within the face to which + * `charmap' belongs. If an error occurs, -1 is returned. + * + */ + FT_EXPORT( FT_Int ) + FT_Get_Charmap_Index( FT_CharMap charmap ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Char_Index */ + /* */ + /* <Description> */ + /* Return the glyph index of a given character code. This function */ + /* uses a charmap object to do the mapping. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* charcode :: The character code. */ + /* */ + /* <Return> */ + /* The glyph index. 0~means `undefined character code'. */ + /* */ + /* <Note> */ + /* If you use FreeType to manipulate the contents of font files */ + /* directly, be aware that the glyph index returned by this function */ + /* doesn't always correspond to the internal indices used within the */ + /* file. This is done to ensure that value~0 always corresponds to */ + /* the `missing glyph'. If the first glyph is not named `.notdef', */ + /* then for Type~1 and Type~42 fonts, `.notdef' will be moved into */ + /* the glyph ID~0 position, and whatever was there will be moved to */ + /* the position `.notdef' had. For Type~1 fonts, if there is no */ + /* `.notdef' glyph at all, then one will be created at index~0 and */ + /* whatever was there will be moved to the last index -- Type~42 */ + /* fonts are considered invalid under this condition. */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Get_Char_Index( FT_Face face, + FT_ULong charcode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_First_Char */ + /* */ + /* <Description> */ + /* This function is used to return the first character code in the */ + /* current charmap of a given face. It also returns the */ + /* corresponding glyph index. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Output> */ + /* agindex :: Glyph index of first character code. 0~if charmap is */ + /* empty. */ + /* */ + /* <Return> */ + /* The charmap's first character code. */ + /* */ + /* <Note> */ + /* You should use this function with @FT_Get_Next_Char to be able to */ + /* parse all character codes available in a given charmap. The code */ + /* should look like this: */ + /* */ + /* { */ + /* FT_ULong charcode; */ + /* FT_UInt gindex; */ + /* */ + /* */ + /* charcode = FT_Get_First_Char( face, &gindex ); */ + /* while ( gindex != 0 ) */ + /* { */ + /* ... do something with (charcode,gindex) pair ... */ + /* */ + /* charcode = FT_Get_Next_Char( face, charcode, &gindex ); */ + /* } */ + /* } */ + /* */ + /* Be aware that character codes can have values up to 0xFFFFFFFF; */ + /* this might happen for non-Unicode or malformed cmaps. However, */ + /* even with regular Unicode encoding, so-called `last resort fonts' */ + /* (using SFNT cmap format 13, see function @FT_Get_CMap_Format) */ + /* normally have entries for all Unicode characters up to 0x1FFFFF, */ + /* which can cause *a lot* of iterations. */ + /* */ + /* Note that `*agindex' is set to~0 if the charmap is empty. The */ + /* result itself can be~0 in two cases: if the charmap is empty or */ + /* if the value~0 is the first valid character code. */ + /* */ + FT_EXPORT( FT_ULong ) + FT_Get_First_Char( FT_Face face, + FT_UInt *agindex ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Next_Char */ + /* */ + /* <Description> */ + /* This function is used to return the next character code in the */ + /* current charmap of a given face following the value `char_code', */ + /* as well as the corresponding glyph index. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* char_code :: The starting character code. */ + /* */ + /* <Output> */ + /* agindex :: Glyph index of next character code. 0~if charmap */ + /* is empty. */ + /* */ + /* <Return> */ + /* The charmap's next character code. */ + /* */ + /* <Note> */ + /* You should use this function with @FT_Get_First_Char to walk */ + /* over all character codes available in a given charmap. See the */ + /* note for this function for a simple code example. */ + /* */ + /* Note that `*agindex' is set to~0 when there are no more codes in */ + /* the charmap. */ + /* */ + FT_EXPORT( FT_ULong ) + FT_Get_Next_Char( FT_Face face, + FT_ULong char_code, + FT_UInt *agindex ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Name_Index */ + /* */ + /* <Description> */ + /* Return the glyph index of a given glyph name. This function uses */ + /* driver specific objects to do the translation. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* glyph_name :: The glyph name. */ + /* */ + /* <Return> */ + /* The glyph index. 0~means `undefined character code'. */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Get_Name_Index( FT_Face face, + FT_String* glyph_name ); + + + /************************************************************************* + * + * @macro: + * FT_SUBGLYPH_FLAG_XXX + * + * @description: + * A list of constants used to describe subglyphs. Please refer to the + * TrueType specification for the meaning of the various flags. + * + * @values: + * FT_SUBGLYPH_FLAG_ARGS_ARE_WORDS :: + * FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES :: + * FT_SUBGLYPH_FLAG_ROUND_XY_TO_GRID :: + * FT_SUBGLYPH_FLAG_SCALE :: + * FT_SUBGLYPH_FLAG_XY_SCALE :: + * FT_SUBGLYPH_FLAG_2X2 :: + * FT_SUBGLYPH_FLAG_USE_MY_METRICS :: + * + */ +#define FT_SUBGLYPH_FLAG_ARGS_ARE_WORDS 1 +#define FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES 2 +#define FT_SUBGLYPH_FLAG_ROUND_XY_TO_GRID 4 +#define FT_SUBGLYPH_FLAG_SCALE 8 +#define FT_SUBGLYPH_FLAG_XY_SCALE 0x40 +#define FT_SUBGLYPH_FLAG_2X2 0x80 +#define FT_SUBGLYPH_FLAG_USE_MY_METRICS 0x200 + + + /************************************************************************* + * + * @func: + * FT_Get_SubGlyph_Info + * + * @description: + * Retrieve a description of a given subglyph. Only use it if + * `glyph->format' is @FT_GLYPH_FORMAT_COMPOSITE; an error is + * returned otherwise. + * + * @input: + * glyph :: + * The source glyph slot. + * + * sub_index :: + * The index of the subglyph. Must be less than + * `glyph->num_subglyphs'. + * + * @output: + * p_index :: + * The glyph index of the subglyph. + * + * p_flags :: + * The subglyph flags, see @FT_SUBGLYPH_FLAG_XXX. + * + * p_arg1 :: + * The subglyph's first argument (if any). + * + * p_arg2 :: + * The subglyph's second argument (if any). + * + * p_transform :: + * The subglyph transformation (if any). + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The values of `*p_arg1', `*p_arg2', and `*p_transform' must be + * interpreted depending on the flags returned in `*p_flags'. See the + * TrueType specification for details. + * + */ + FT_EXPORT( FT_Error ) + FT_Get_SubGlyph_Info( FT_GlyphSlot glyph, + FT_UInt sub_index, + FT_Int *p_index, + FT_UInt *p_flags, + FT_Int *p_arg1, + FT_Int *p_arg2, + FT_Matrix *p_transform ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_FSTYPE_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags used in the `fsType' field of the OS/2 table */ + /* in a TrueType or OpenType font and the `FSType' entry in a */ + /* PostScript font. These bit flags are returned by */ + /* @FT_Get_FSType_Flags; they inform client applications of embedding */ + /* and subsetting restrictions associated with a font. */ + /* */ + /* See */ + /* http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/FontPolicies.pdf */ + /* for more details. */ + /* */ + /* <Values> */ + /* FT_FSTYPE_INSTALLABLE_EMBEDDING :: */ + /* Fonts with no fsType bit set may be embedded and permanently */ + /* installed on the remote system by an application. */ + /* */ + /* FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING :: */ + /* Fonts that have only this bit set must not be modified, embedded */ + /* or exchanged in any manner without first obtaining permission of */ + /* the font software copyright owner. */ + /* */ + /* FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING :: */ + /* If this bit is set, the font may be embedded and temporarily */ + /* loaded on the remote system. Documents containing Preview & */ + /* Print fonts must be opened `read-only'; no edits can be applied */ + /* to the document. */ + /* */ + /* FT_FSTYPE_EDITABLE_EMBEDDING :: */ + /* If this bit is set, the font may be embedded but must only be */ + /* installed temporarily on other systems. In contrast to Preview */ + /* & Print fonts, documents containing editable fonts may be opened */ + /* for reading, editing is permitted, and changes may be saved. */ + /* */ + /* FT_FSTYPE_NO_SUBSETTING :: */ + /* If this bit is set, the font may not be subsetted prior to */ + /* embedding. */ + /* */ + /* FT_FSTYPE_BITMAP_EMBEDDING_ONLY :: */ + /* If this bit is set, only bitmaps contained in the font may be */ + /* embedded; no outline data may be embedded. If there are no */ + /* bitmaps available in the font, then the font is unembeddable. */ + /* */ + /* <Note> */ + /* The flags are ORed together, thus more than a single value can be */ + /* returned. */ + /* */ + /* While the fsType flags can indicate that a font may be embedded, a */ + /* license with the font vendor may be separately required to use the */ + /* font in this way. */ + /* */ +#define FT_FSTYPE_INSTALLABLE_EMBEDDING 0x0000 +#define FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING 0x0002 +#define FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING 0x0004 +#define FT_FSTYPE_EDITABLE_EMBEDDING 0x0008 +#define FT_FSTYPE_NO_SUBSETTING 0x0100 +#define FT_FSTYPE_BITMAP_EMBEDDING_ONLY 0x0200 + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_FSType_Flags */ + /* */ + /* <Description> */ + /* Return the fsType flags for a font. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Return> */ + /* The fsType flags, @FT_FSTYPE_XXX. */ + /* */ + /* <Note> */ + /* Use this function rather than directly reading the `fs_type' field */ + /* in the @PS_FontInfoRec structure, which is only guaranteed to */ + /* return the correct results for Type~1 fonts. */ + /* */ + /* <Since> */ + /* 2.3.8 */ + /* */ + FT_EXPORT( FT_UShort ) + FT_Get_FSType_Flags( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* glyph_variants */ + /* */ + /* <Title> */ + /* Glyph Variants */ + /* */ + /* <Abstract> */ + /* The FreeType~2 interface to Unicode Ideographic Variation */ + /* Sequences (IVS), using the SFNT cmap format~14. */ + /* */ + /* <Description> */ + /* Many CJK characters have variant forms. They are a sort of grey */ + /* area somewhere between being totally irrelevant and semantically */ + /* distinct; for this reason, the Unicode consortium decided to */ + /* introduce Ideographic Variation Sequences (IVS), consisting of a */ + /* Unicode base character and one of 240 variant selectors */ + /* (U+E0100-U+E01EF), instead of further extending the already huge */ + /* code range for CJK characters. */ + /* */ + /* An IVS is registered and unique; for further details please refer */ + /* to Unicode Technical Standard #37, the Ideographic Variation */ + /* Database: */ + /* */ + /* http://www.unicode.org/reports/tr37/ */ + /* */ + /* To date (November 2014), the character with the most variants is */ + /* U+9089, having 32 such IVS. */ + /* */ + /* Adobe and MS decided to support IVS with a new cmap subtable */ + /* (format~14). It is an odd subtable because it is not a mapping of */ + /* input code points to glyphs, but contains lists of all variants */ + /* supported by the font. */ + /* */ + /* A variant may be either `default' or `non-default'. A default */ + /* variant is the one you will get for that code point if you look it */ + /* up in the standard Unicode cmap. A non-default variant is a */ + /* different glyph. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetCharVariantIndex */ + /* */ + /* <Description> */ + /* Return the glyph index of a given character code as modified by */ + /* the variation selector. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* charcode :: */ + /* The character code point in Unicode. */ + /* */ + /* variantSelector :: */ + /* The Unicode code point of the variation selector. */ + /* */ + /* <Return> */ + /* The glyph index. 0~means either `undefined character code', or */ + /* `undefined selector code', or `no variation selector cmap */ + /* subtable', or `current CharMap is not Unicode'. */ + /* */ + /* <Note> */ + /* If you use FreeType to manipulate the contents of font files */ + /* directly, be aware that the glyph index returned by this function */ + /* doesn't always correspond to the internal indices used within */ + /* the file. This is done to ensure that value~0 always corresponds */ + /* to the `missing glyph'. */ + /* */ + /* This function is only meaningful if */ + /* a) the font has a variation selector cmap sub table, */ + /* and */ + /* b) the current charmap has a Unicode encoding. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Face_GetCharVariantIndex( FT_Face face, + FT_ULong charcode, + FT_ULong variantSelector ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetCharVariantIsDefault */ + /* */ + /* <Description> */ + /* Check whether this variant of this Unicode character is the one to */ + /* be found in the `cmap'. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* charcode :: */ + /* The character codepoint in Unicode. */ + /* */ + /* variantSelector :: */ + /* The Unicode codepoint of the variation selector. */ + /* */ + /* <Return> */ + /* 1~if found in the standard (Unicode) cmap, 0~if found in the */ + /* variation selector cmap, or -1 if it is not a variant. */ + /* */ + /* <Note> */ + /* This function is only meaningful if the font has a variation */ + /* selector cmap subtable. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_Int ) + FT_Face_GetCharVariantIsDefault( FT_Face face, + FT_ULong charcode, + FT_ULong variantSelector ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetVariantSelectors */ + /* */ + /* <Description> */ + /* Return a zero-terminated list of Unicode variant selectors found */ + /* in the font. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* <Return> */ + /* A pointer to an array of selector code points, or NULL if there is */ + /* no valid variant selector cmap subtable. */ + /* */ + /* <Note> */ + /* The last item in the array is~0; the array is owned by the */ + /* @FT_Face object but can be overwritten or released on the next */ + /* call to a FreeType function. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt32* ) + FT_Face_GetVariantSelectors( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetVariantsOfChar */ + /* */ + /* <Description> */ + /* Return a zero-terminated list of Unicode variant selectors found */ + /* for the specified character code. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* charcode :: */ + /* The character codepoint in Unicode. */ + /* */ + /* <Return> */ + /* A pointer to an array of variant selector code points that are */ + /* active for the given character, or NULL if the corresponding list */ + /* is empty. */ + /* */ + /* <Note> */ + /* The last item in the array is~0; the array is owned by the */ + /* @FT_Face object but can be overwritten or released on the next */ + /* call to a FreeType function. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt32* ) + FT_Face_GetVariantsOfChar( FT_Face face, + FT_ULong charcode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetCharsOfVariant */ + /* */ + /* <Description> */ + /* Return a zero-terminated list of Unicode character codes found for */ + /* the specified variant selector. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* variantSelector :: */ + /* The variant selector code point in Unicode. */ + /* */ + /* <Return> */ + /* A list of all the code points that are specified by this selector */ + /* (both default and non-default codes are returned) or NULL if there */ + /* is no valid cmap or the variant selector is invalid. */ + /* */ + /* <Note> */ + /* The last item in the array is~0; the array is owned by the */ + /* @FT_Face object but can be overwritten or released on the next */ + /* call to a FreeType function. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt32* ) + FT_Face_GetCharsOfVariant( FT_Face face, + FT_ULong variantSelector ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* computations */ + /* */ + /* <Title> */ + /* Computations */ + /* */ + /* <Abstract> */ + /* Crunching fixed numbers and vectors. */ + /* */ + /* <Description> */ + /* This section contains various functions used to perform */ + /* computations on 16.16 fixed-float numbers or 2d vectors. */ + /* */ + /* <Order> */ + /* FT_MulDiv */ + /* FT_MulFix */ + /* FT_DivFix */ + /* FT_RoundFix */ + /* FT_CeilFix */ + /* FT_FloorFix */ + /* FT_Vector_Transform */ + /* FT_Matrix_Multiply */ + /* FT_Matrix_Invert */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_MulDiv */ + /* */ + /* <Description> */ + /* A very simple function used to perform the computation `(a*b)/c' */ + /* with maximum accuracy (it uses a 64-bit intermediate integer */ + /* whenever necessary). */ + /* */ + /* This function isn't necessarily as fast as some processor specific */ + /* operations, but is at least completely portable. */ + /* */ + /* <Input> */ + /* a :: The first multiplier. */ + /* b :: The second multiplier. */ + /* c :: The divisor. */ + /* */ + /* <Return> */ + /* The result of `(a*b)/c'. This function never traps when trying to */ + /* divide by zero; it simply returns `MaxInt' or `MinInt' depending */ + /* on the signs of `a' and `b'. */ + /* */ + FT_EXPORT( FT_Long ) + FT_MulDiv( FT_Long a, + FT_Long b, + FT_Long c ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_MulFix */ + /* */ + /* <Description> */ + /* A very simple function used to perform the computation */ + /* `(a*b)/0x10000' with maximum accuracy. Most of the time this is */ + /* used to multiply a given value by a 16.16 fixed-point factor. */ + /* */ + /* <Input> */ + /* a :: The first multiplier. */ + /* b :: The second multiplier. Use a 16.16 factor here whenever */ + /* possible (see note below). */ + /* */ + /* <Return> */ + /* The result of `(a*b)/0x10000'. */ + /* */ + /* <Note> */ + /* This function has been optimized for the case where the absolute */ + /* value of `a' is less than 2048, and `b' is a 16.16 scaling factor. */ + /* As this happens mainly when scaling from notional units to */ + /* fractional pixels in FreeType, it resulted in noticeable speed */ + /* improvements between versions 2.x and 1.x. */ + /* */ + /* As a conclusion, always try to place a 16.16 factor as the */ + /* _second_ argument of this function; this can make a great */ + /* difference. */ + /* */ + FT_EXPORT( FT_Long ) + FT_MulFix( FT_Long a, + FT_Long b ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_DivFix */ + /* */ + /* <Description> */ + /* A very simple function used to perform the computation */ + /* `(a*0x10000)/b' with maximum accuracy. Most of the time, this is */ + /* used to divide a given value by a 16.16 fixed-point factor. */ + /* */ + /* <Input> */ + /* a :: The numerator. */ + /* b :: The denominator. Use a 16.16 factor here. */ + /* */ + /* <Return> */ + /* The result of `(a*0x10000)/b'. */ + /* */ + FT_EXPORT( FT_Long ) + FT_DivFix( FT_Long a, + FT_Long b ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_RoundFix */ + /* */ + /* <Description> */ + /* A very simple function used to round a 16.16 fixed number. */ + /* */ + /* <Input> */ + /* a :: The number to be rounded. */ + /* */ + /* <Return> */ + /* `a' rounded to nearest 16.16 fixed integer, halfway cases away */ + /* from zero. */ + /* */ + FT_EXPORT( FT_Fixed ) + FT_RoundFix( FT_Fixed a ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_CeilFix */ + /* */ + /* <Description> */ + /* A very simple function used to compute the ceiling function of a */ + /* 16.16 fixed number. */ + /* */ + /* <Input> */ + /* a :: The number for which the ceiling function is to be computed. */ + /* */ + /* <Return> */ + /* `a' rounded towards plus infinity. */ + /* */ + FT_EXPORT( FT_Fixed ) + FT_CeilFix( FT_Fixed a ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_FloorFix */ + /* */ + /* <Description> */ + /* A very simple function used to compute the floor function of a */ + /* 16.16 fixed number. */ + /* */ + /* <Input> */ + /* a :: The number for which the floor function is to be computed. */ + /* */ + /* <Return> */ + /* `a' rounded towards minus infinity. */ + /* */ + FT_EXPORT( FT_Fixed ) + FT_FloorFix( FT_Fixed a ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Vector_Transform */ + /* */ + /* <Description> */ + /* Transform a single vector through a 2x2 matrix. */ + /* */ + /* <InOut> */ + /* vector :: The target vector to transform. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to the source 2x2 matrix. */ + /* */ + /* <Note> */ + /* The result is undefined if either `vector' or `matrix' is invalid. */ + /* */ + FT_EXPORT( void ) + FT_Vector_Transform( FT_Vector* vec, + const FT_Matrix* matrix ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* version */ + /* */ + /* <Title> */ + /* FreeType Version */ + /* */ + /* <Abstract> */ + /* Functions and macros related to FreeType versions. */ + /* */ + /* <Description> */ + /* Note that those functions and macros are of limited use because */ + /* even a new release of FreeType with only documentation changes */ + /* increases the version number. */ + /* */ + /* <Order> */ + /* FT_Library_Version */ + /* */ + /* FREETYPE_MAJOR */ + /* FREETYPE_MINOR */ + /* FREETYPE_PATCH */ + /* */ + /* FT_Face_CheckTrueTypePatents */ + /* FT_Face_SetUnpatentedHinting */ + /* */ + /* FREETYPE_XXX */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @enum: + * FREETYPE_XXX + * + * @description: + * These three macros identify the FreeType source code version. + * Use @FT_Library_Version to access them at runtime. + * + * @values: + * FREETYPE_MAJOR :: The major version number. + * FREETYPE_MINOR :: The minor version number. + * FREETYPE_PATCH :: The patch level. + * + * @note: + * The version number of FreeType if built as a dynamic link library + * with the `libtool' package is _not_ controlled by these three + * macros. + * + */ +#define FREETYPE_MAJOR 2 +#define FREETYPE_MINOR 6 +#define FREETYPE_PATCH 3 + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Library_Version */ + /* */ + /* <Description> */ + /* Return the version of the FreeType library being used. This is */ + /* useful when dynamically linking to the library, since one cannot */ + /* use the macros @FREETYPE_MAJOR, @FREETYPE_MINOR, and */ + /* @FREETYPE_PATCH. */ + /* */ + /* <Input> */ + /* library :: A source library handle. */ + /* */ + /* <Output> */ + /* amajor :: The major version number. */ + /* */ + /* aminor :: The minor version number. */ + /* */ + /* apatch :: The patch version number. */ + /* */ + /* <Note> */ + /* The reason why this function takes a `library' argument is because */ + /* certain programs implement library initialization in a custom way */ + /* that doesn't use @FT_Init_FreeType. */ + /* */ + /* In such cases, the library version might not be available before */ + /* the library object has been created. */ + /* */ + FT_EXPORT( void ) + FT_Library_Version( FT_Library library, + FT_Int *amajor, + FT_Int *aminor, + FT_Int *apatch ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_CheckTrueTypePatents */ + /* */ + /* <Description> */ + /* Deprecated, does nothing. */ + /* */ + /* <Input> */ + /* face :: A face handle. */ + /* */ + /* <Return> */ + /* Always returns false. */ + /* */ + /* <Note> */ + /* Since May 2010, TrueType hinting is no longer patented. */ + /* */ + /* <Since> */ + /* 2.3.5 */ + /* */ + FT_EXPORT( FT_Bool ) + FT_Face_CheckTrueTypePatents( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_SetUnpatentedHinting */ + /* */ + /* <Description> */ + /* Deprecated, does nothing. */ + /* */ + /* <Input> */ + /* face :: A face handle. */ + /* */ + /* value :: New boolean setting. */ + /* */ + /* <Return> */ + /* Always returns false. */ + /* */ + /* <Note> */ + /* Since May 2010, TrueType hinting is no longer patented. */ + /* */ + /* <Since> */ + /* 2.3.5 */ + /* */ + FT_EXPORT( FT_Bool ) + FT_Face_SetUnpatentedHinting( FT_Face face, + FT_Bool value ); + + /* */ + + +FT_END_HEADER + +#endif /* FREETYPE_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ft2build.h b/android/x86/include/freetype/ft2build.h new file mode 100644 index 00000000..b22bb27a --- /dev/null +++ b/android/x86/include/freetype/ft2build.h @@ -0,0 +1,42 @@ +/***************************************************************************/ +/* */ +/* ft2build.h */ +/* */ +/* FreeType 2 build and setup macros. */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This is the `entry point' for FreeType header file inclusions. It is */ + /* the only header file which should be included directly; all other */ + /* FreeType header files should be accessed with macro names (after */ + /* including `ft2build.h'). */ + /* */ + /* A typical example is */ + /* */ + /* #include <ft2build.h> */ + /* #include FT_FREETYPE_H */ + /* */ + /*************************************************************************/ + + +#ifndef FT2BUILD_H_ +#define FT2BUILD_H_ + +#include "config/ftheader.h" + +#endif /* FT2BUILD_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftadvanc.h b/android/x86/include/freetype/ftadvanc.h new file mode 100644 index 00000000..023dd84b --- /dev/null +++ b/android/x86/include/freetype/ftadvanc.h @@ -0,0 +1,187 @@ +/***************************************************************************/ +/* */ +/* ftadvanc.h */ +/* */ +/* Quick computation of advance widths (specification only). */ +/* */ +/* Copyright 2008-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTADVANC_H_ +#define FTADVANC_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /************************************************************************** + * + * @section: + * quick_advance + * + * @title: + * Quick retrieval of advance values + * + * @abstract: + * Retrieve horizontal and vertical advance values without processing + * glyph outlines, if possible. + * + * @description: + * This section contains functions to quickly extract advance values + * without handling glyph outlines, if possible. + * + * @order: + * FT_Get_Advance + * FT_Get_Advances + * + */ + + + /*************************************************************************/ + /* */ + /* <Const> */ + /* FT_ADVANCE_FLAG_FAST_ONLY */ + /* */ + /* <Description> */ + /* A bit-flag to be OR-ed with the `flags' parameter of the */ + /* @FT_Get_Advance and @FT_Get_Advances functions. */ + /* */ + /* If set, it indicates that you want these functions to fail if the */ + /* corresponding hinting mode or font driver doesn't allow for very */ + /* quick advance computation. */ + /* */ + /* Typically, glyphs that are either unscaled, unhinted, bitmapped, */ + /* or light-hinted can have their advance width computed very */ + /* quickly. */ + /* */ + /* Normal and bytecode hinted modes that require loading, scaling, */ + /* and hinting of the glyph outline, are extremely slow by */ + /* comparison. */ + /* */ +#define FT_ADVANCE_FLAG_FAST_ONLY 0x20000000L + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Advance */ + /* */ + /* <Description> */ + /* Retrieve the advance value of a given glyph outline in an */ + /* @FT_Face. */ + /* */ + /* <Input> */ + /* face :: The source @FT_Face handle. */ + /* */ + /* gindex :: The glyph index. */ + /* */ + /* load_flags :: A set of bit flags similar to those used when */ + /* calling @FT_Load_Glyph, used to determine what kind */ + /* of advances you need. */ + /* <Output> */ + /* padvance :: The advance value. If scaling is performed (based on */ + /* the value of `load_flags'), the advance value is in */ + /* 16.16 format. Otherwise, it is in font units. */ + /* */ + /* If @FT_LOAD_VERTICAL_LAYOUT is set, this is the */ + /* vertical advance corresponding to a vertical layout. */ + /* Otherwise, it is the horizontal advance in a */ + /* horizontal layout. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + /* <Note> */ + /* This function may fail if you use @FT_ADVANCE_FLAG_FAST_ONLY and */ + /* if the corresponding font backend doesn't have a quick way to */ + /* retrieve the advances. */ + /* */ + /* A scaled advance is returned in 16.16 format but isn't transformed */ + /* by the affine transformation specified by @FT_Set_Transform. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Advance( FT_Face face, + FT_UInt gindex, + FT_Int32 load_flags, + FT_Fixed *padvance ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Advances */ + /* */ + /* <Description> */ + /* Retrieve the advance values of several glyph outlines in an */ + /* @FT_Face. */ + /* */ + /* <Input> */ + /* face :: The source @FT_Face handle. */ + /* */ + /* start :: The first glyph index. */ + /* */ + /* count :: The number of advance values you want to retrieve. */ + /* */ + /* load_flags :: A set of bit flags similar to those used when */ + /* calling @FT_Load_Glyph. */ + /* */ + /* <Output> */ + /* padvance :: The advance values. This array, to be provided by the */ + /* caller, must contain at least `count' elements. */ + /* */ + /* If scaling is performed (based on the value of */ + /* `load_flags'), the advance values are in 16.16 format. */ + /* Otherwise, they are in font units. */ + /* */ + /* If @FT_LOAD_VERTICAL_LAYOUT is set, these are the */ + /* vertical advances corresponding to a vertical layout. */ + /* Otherwise, they are the horizontal advances in a */ + /* horizontal layout. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + /* <Note> */ + /* This function may fail if you use @FT_ADVANCE_FLAG_FAST_ONLY and */ + /* if the corresponding font backend doesn't have a quick way to */ + /* retrieve the advances. */ + /* */ + /* Scaled advances are returned in 16.16 format but aren't */ + /* transformed by the affine transformation specified by */ + /* @FT_Set_Transform. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Advances( FT_Face face, + FT_UInt start, + FT_UInt count, + FT_Int32 load_flags, + FT_Fixed *padvances ); + + /* */ + + +FT_END_HEADER + +#endif /* FTADVANC_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftautoh.h b/android/x86/include/freetype/ftautoh.h new file mode 100644 index 00000000..8052dd23 --- /dev/null +++ b/android/x86/include/freetype/ftautoh.h @@ -0,0 +1,503 @@ +/***************************************************************************/ +/* */ +/* ftautoh.h */ +/* */ +/* FreeType API for controlling the auto-hinter (specification only). */ +/* */ +/* Copyright 2012-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTAUTOH_H_ +#define FTAUTOH_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /************************************************************************** + * + * @section: + * auto_hinter + * + * @title: + * The auto-hinter + * + * @abstract: + * Controlling the auto-hinting module. + * + * @description: + * While FreeType's auto-hinter doesn't expose API functions by itself, + * it is possible to control its behaviour with @FT_Property_Set and + * @FT_Property_Get. The following lists the available properties + * together with the necessary macros and structures. + * + * Note that the auto-hinter's module name is `autofitter' for + * historical reasons. + * + */ + + + /************************************************************************** + * + * @property: + * glyph-to-script-map + * + * @description: + * *Experimental* *only* + * + * The auto-hinter provides various script modules to hint glyphs. + * Examples of supported scripts are Latin or CJK. Before a glyph is + * auto-hinted, the Unicode character map of the font gets examined, and + * the script is then determined based on Unicode character ranges, see + * below. + * + * OpenType fonts, however, often provide much more glyphs than + * character codes (small caps, superscripts, ligatures, swashes, etc.), + * to be controlled by so-called `features'. Handling OpenType features + * can be quite complicated and thus needs a separate library on top of + * FreeType. + * + * The mapping between glyph indices and scripts (in the auto-hinter + * sense, see the @FT_AUTOHINTER_SCRIPT_XXX values) is stored as an + * array with `num_glyphs' elements, as found in the font's @FT_Face + * structure. The `glyph-to-script-map' property returns a pointer to + * this array, which can be modified as needed. Note that the + * modification should happen before the first glyph gets processed by + * the auto-hinter so that the global analysis of the font shapes + * actually uses the modified mapping. + * + * The following example code demonstrates how to access it (omitting + * the error handling). + * + * { + * FT_Library library; + * FT_Face face; + * FT_Prop_GlyphToScriptMap prop; + * + * + * FT_Init_FreeType( &library ); + * FT_New_Face( library, "foo.ttf", 0, &face ); + * + * prop.face = face; + * + * FT_Property_Get( library, "autofitter", + * "glyph-to-script-map", &prop ); + * + * // adjust `prop.map' as needed right here + * + * FT_Load_Glyph( face, ..., FT_LOAD_FORCE_AUTOHINT ); + * } + * + */ + + + /************************************************************************** + * + * @enum: + * FT_AUTOHINTER_SCRIPT_XXX + * + * @description: + * *Experimental* *only* + * + * A list of constants used for the @glyph-to-script-map property to + * specify the script submodule the auto-hinter should use for hinting a + * particular glyph. + * + * @values: + * FT_AUTOHINTER_SCRIPT_NONE :: + * Don't auto-hint this glyph. + * + * FT_AUTOHINTER_SCRIPT_LATIN :: + * Apply the latin auto-hinter. For the auto-hinter, `latin' is a + * very broad term, including Cyrillic and Greek also since characters + * from those scripts share the same design constraints. + * + * By default, characters from the following Unicode ranges are + * assigned to this submodule. + * + * { + * U+0020 - U+007F // Basic Latin (no control characters) + * U+00A0 - U+00FF // Latin-1 Supplement (no control characters) + * U+0100 - U+017F // Latin Extended-A + * U+0180 - U+024F // Latin Extended-B + * U+0250 - U+02AF // IPA Extensions + * U+02B0 - U+02FF // Spacing Modifier Letters + * U+0300 - U+036F // Combining Diacritical Marks + * U+0370 - U+03FF // Greek and Coptic + * U+0400 - U+04FF // Cyrillic + * U+0500 - U+052F // Cyrillic Supplement + * U+1D00 - U+1D7F // Phonetic Extensions + * U+1D80 - U+1DBF // Phonetic Extensions Supplement + * U+1DC0 - U+1DFF // Combining Diacritical Marks Supplement + * U+1E00 - U+1EFF // Latin Extended Additional + * U+1F00 - U+1FFF // Greek Extended + * U+2000 - U+206F // General Punctuation + * U+2070 - U+209F // Superscripts and Subscripts + * U+20A0 - U+20CF // Currency Symbols + * U+2150 - U+218F // Number Forms + * U+2460 - U+24FF // Enclosed Alphanumerics + * U+2C60 - U+2C7F // Latin Extended-C + * U+2DE0 - U+2DFF // Cyrillic Extended-A + * U+2E00 - U+2E7F // Supplemental Punctuation + * U+A640 - U+A69F // Cyrillic Extended-B + * U+A720 - U+A7FF // Latin Extended-D + * U+FB00 - U+FB06 // Alphab. Present. Forms (Latin Ligatures) + * U+1D400 - U+1D7FF // Mathematical Alphanumeric Symbols + * U+1F100 - U+1F1FF // Enclosed Alphanumeric Supplement + * } + * + * FT_AUTOHINTER_SCRIPT_CJK :: + * Apply the CJK auto-hinter, covering Chinese, Japanese, Korean, old + * Vietnamese, and some other scripts. + * + * By default, characters from the following Unicode ranges are + * assigned to this submodule. + * + * { + * U+1100 - U+11FF // Hangul Jamo + * U+2E80 - U+2EFF // CJK Radicals Supplement + * U+2F00 - U+2FDF // Kangxi Radicals + * U+2FF0 - U+2FFF // Ideographic Description Characters + * U+3000 - U+303F // CJK Symbols and Punctuation + * U+3040 - U+309F // Hiragana + * U+30A0 - U+30FF // Katakana + * U+3100 - U+312F // Bopomofo + * U+3130 - U+318F // Hangul Compatibility Jamo + * U+3190 - U+319F // Kanbun + * U+31A0 - U+31BF // Bopomofo Extended + * U+31C0 - U+31EF // CJK Strokes + * U+31F0 - U+31FF // Katakana Phonetic Extensions + * U+3200 - U+32FF // Enclosed CJK Letters and Months + * U+3300 - U+33FF // CJK Compatibility + * U+3400 - U+4DBF // CJK Unified Ideographs Extension A + * U+4DC0 - U+4DFF // Yijing Hexagram Symbols + * U+4E00 - U+9FFF // CJK Unified Ideographs + * U+A960 - U+A97F // Hangul Jamo Extended-A + * U+AC00 - U+D7AF // Hangul Syllables + * U+D7B0 - U+D7FF // Hangul Jamo Extended-B + * U+F900 - U+FAFF // CJK Compatibility Ideographs + * U+FE10 - U+FE1F // Vertical forms + * U+FE30 - U+FE4F // CJK Compatibility Forms + * U+FF00 - U+FFEF // Halfwidth and Fullwidth Forms + * U+1B000 - U+1B0FF // Kana Supplement + * U+1D300 - U+1D35F // Tai Xuan Hing Symbols + * U+1F200 - U+1F2FF // Enclosed Ideographic Supplement + * U+20000 - U+2A6DF // CJK Unified Ideographs Extension B + * U+2A700 - U+2B73F // CJK Unified Ideographs Extension C + * U+2B740 - U+2B81F // CJK Unified Ideographs Extension D + * U+2F800 - U+2FA1F // CJK Compatibility Ideographs Supplement + * } + * + * FT_AUTOHINTER_SCRIPT_INDIC :: + * Apply the indic auto-hinter, covering all major scripts from the + * Indian sub-continent and some other related scripts like Thai, Lao, + * or Tibetan. + * + * By default, characters from the following Unicode ranges are + * assigned to this submodule. + * + * { + * U+0900 - U+0DFF // Indic Range + * U+0F00 - U+0FFF // Tibetan + * U+1900 - U+194F // Limbu + * U+1B80 - U+1BBF // Sundanese + * U+1C80 - U+1CDF // Meetei Mayak + * U+A800 - U+A82F // Syloti Nagri + * U+11800 - U+118DF // Sharada + * } + * + * Note that currently Indic support is rudimentary only, missing blue + * zone support. + * + */ +#define FT_AUTOHINTER_SCRIPT_NONE 0 +#define FT_AUTOHINTER_SCRIPT_LATIN 1 +#define FT_AUTOHINTER_SCRIPT_CJK 2 +#define FT_AUTOHINTER_SCRIPT_INDIC 3 + + + /************************************************************************** + * + * @struct: + * FT_Prop_GlyphToScriptMap + * + * @description: + * *Experimental* *only* + * + * The data exchange structure for the @glyph-to-script-map property. + * + */ + typedef struct FT_Prop_GlyphToScriptMap_ + { + FT_Face face; + FT_UShort* map; + + } FT_Prop_GlyphToScriptMap; + + + /************************************************************************** + * + * @property: + * fallback-script + * + * @description: + * *Experimental* *only* + * + * If no auto-hinter script module can be assigned to a glyph, a + * fallback script gets assigned to it (see also the + * @glyph-to-script-map property). By default, this is + * @FT_AUTOHINTER_SCRIPT_CJK. Using the `fallback-script' property, + * this fallback value can be changed. + * + * { + * FT_Library library; + * FT_UInt fallback_script = FT_AUTOHINTER_SCRIPT_NONE; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "autofitter", + * "fallback-script", &fallback_script ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * It's important to use the right timing for changing this value: The + * creation of the glyph-to-script map that eventually uses the + * fallback script value gets triggered either by setting or reading a + * face-specific property like @glyph-to-script-map, or by auto-hinting + * any glyph from that face. In particular, if you have already created + * an @FT_Face structure but not loaded any glyph (using the + * auto-hinter), a change of the fallback script will affect this face. + * + */ + + + /************************************************************************** + * + * @property: + * default-script + * + * @description: + * *Experimental* *only* + * + * If FreeType gets compiled with FT_CONFIG_OPTION_USE_HARFBUZZ to make + * the HarfBuzz library access OpenType features for getting better + * glyph coverages, this property sets the (auto-fitter) script to be + * used for the default (OpenType) script data of a font's GSUB table. + * Features for the default script are intended for all scripts not + * explicitly handled in GSUB; an example is a `dlig' feature, + * containing the combination of the characters `T', `E', and `L' to + * form a `TEL' ligature. + * + * By default, this is @FT_AUTOHINTER_SCRIPT_LATIN. Using the + * `default-script' property, this default value can be changed. + * + * { + * FT_Library library; + * FT_UInt default_script = FT_AUTOHINTER_SCRIPT_NONE; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "autofitter", + * "default-script", &default_script ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * It's important to use the right timing for changing this value: The + * creation of the glyph-to-script map that eventually uses the + * default script value gets triggered either by setting or reading a + * face-specific property like @glyph-to-script-map, or by auto-hinting + * any glyph from that face. In particular, if you have already created + * an @FT_Face structure but not loaded any glyph (using the + * auto-hinter), a change of the default script will affect this face. + * + */ + + + /************************************************************************** + * + * @property: + * increase-x-height + * + * @description: + * For ppem values in the range 6~<= ppem <= `increase-x-height', round + * up the font's x~height much more often than normally. If the value + * is set to~0, which is the default, this feature is switched off. Use + * this property to improve the legibility of small font sizes if + * necessary. + * + * { + * FT_Library library; + * FT_Face face; + * FT_Prop_IncreaseXHeight prop; + * + * + * FT_Init_FreeType( &library ); + * FT_New_Face( library, "foo.ttf", 0, &face ); + * FT_Set_Char_Size( face, 10 * 64, 0, 72, 0 ); + * + * prop.face = face; + * prop.limit = 14; + * + * FT_Property_Set( library, "autofitter", + * "increase-x-height", &prop ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * Set this value right after calling @FT_Set_Char_Size, but before + * loading any glyph (using the auto-hinter). + * + */ + + + /************************************************************************** + * + * @struct: + * FT_Prop_IncreaseXHeight + * + * @description: + * The data exchange structure for the @increase-x-height property. + * + */ + typedef struct FT_Prop_IncreaseXHeight_ + { + FT_Face face; + FT_UInt limit; + + } FT_Prop_IncreaseXHeight; + + + /************************************************************************** + * + * @property: + * warping + * + * @description: + * *Experimental* *only* + * + * If FreeType gets compiled with option AF_CONFIG_OPTION_USE_WARPER to + * activate the warp hinting code in the auto-hinter, this property + * switches warping on and off. + * + * Warping only works in `light' auto-hinting mode. The idea of the + * code is to slightly scale and shift a glyph along the non-hinted + * dimension (which is usually the horizontal axis) so that as much of + * its segments are aligned (more or less) to the grid. To find out a + * glyph's optimal scaling and shifting value, various parameter + * combinations are tried and scored. + * + * By default, warping is off. The example below shows how to switch on + * warping (omitting the error handling). + * + * { + * FT_Library library; + * FT_Bool warping = 1; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "autofitter", + * "warping", &warping ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * The warping code can also change advance widths. Have a look at the + * `lsb_delta' and `rsb_delta' fields in the @FT_GlyphSlotRec structure + * for details on improving inter-glyph distances while rendering. + * + * Since warping is a global property of the auto-hinter it is best to + * change its value before rendering any face. Otherwise, you should + * reload all faces that get auto-hinted in `light' hinting mode. + * + */ + + + /************************************************************************** + * + * @property: + * no-stem-darkening[autofit] + * + * @description: + * *Experimental* *only,* *requires* *linear* *alpha* *blending* *and* + * *gamma* *correction* + * + * Stem darkening emboldens glyphs at smaller sizes to make them more + * readable on common low-DPI screens when using linear alpha blending + * and gamma correction, see @FT_Render_Glyph. When not using linear + * alpha blending and gamma correction, glyphs will appear heavy and + * fuzzy! + * + * Gamma correction essentially lightens fonts since shades of grey are + * shifted to higher pixel values (=~higher brightness) to match the + * original intention to the reality of our screens. The side-effect is + * that glyphs `thin out'. Mac OS~X and Adobe's proprietary font + * rendering library implement a counter-measure: stem darkening at + * smaller sizes where shades of gray dominate. By emboldening a glyph + * slightly in relation to its pixel size, individual pixels get higher + * coverage of filled-in outlines and are therefore `blacker'. This + * counteracts the `thinning out' of glyphs, making text remain readable + * at smaller sizes. All glyphs that pass through the auto-hinter will + * be emboldened unless this property is set to TRUE. + * + * See the description of the CFF driver for algorithmic details. Total + * consistency with the CFF driver is currently not achieved because the + * emboldening method differs and glyphs must be scaled down on the + * Y-axis to keep outline points inside their precomputed blue zones. + * The smaller the size (especially 9ppem and down), the higher the loss + * of emboldening versus the CFF driver. + * + */ + + + /************************************************************************** + * + * @property: + * darkening-parameters[autofit] + * + * @description: + * *Experimental* *only* + * + * See the description of the CFF driver for details. This + * implementation appropriates the + * CFF_CONFIG_OPTION_DARKENING_PARAMETER_* #defines for consistency. + * Note the differences described in @no-stem-darkening[autofit]. + * + */ + + + /* */ + + +FT_END_HEADER + +#endif /* FTAUTOH_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftbbox.h b/android/x86/include/freetype/ftbbox.h new file mode 100644 index 00000000..2a4d2144 --- /dev/null +++ b/android/x86/include/freetype/ftbbox.h @@ -0,0 +1,101 @@ +/***************************************************************************/ +/* */ +/* ftbbox.h */ +/* */ +/* FreeType exact bbox computation (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This component has a _single_ role: to compute exact outline bounding */ + /* boxes. */ + /* */ + /* It is separated from the rest of the engine for various technical */ + /* reasons. It may well be integrated in `ftoutln' later. */ + /* */ + /*************************************************************************/ + + +#ifndef FTBBOX_H_ +#define FTBBOX_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* outline_processing */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Get_BBox */ + /* */ + /* <Description> */ + /* Compute the exact bounding box of an outline. This is slower */ + /* than computing the control box. However, it uses an advanced */ + /* algorithm that returns _very_ quickly when the two boxes */ + /* coincide. Otherwise, the outline Bézier arcs are traversed to */ + /* extract their extrema. */ + /* */ + /* <Input> */ + /* outline :: A pointer to the source outline. */ + /* */ + /* <Output> */ + /* abbox :: The outline's exact bounding box. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* If the font is tricky and the glyph has been loaded with */ + /* @FT_LOAD_NO_SCALE, the resulting BBox is meaningless. To get */ + /* reasonable values for the BBox it is necessary to load the glyph */ + /* at a large ppem value (so that the hinting instructions can */ + /* properly shift and scale the subglyphs), then extracting the BBox, */ + /* which can be eventually converted back to font units. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Get_BBox( FT_Outline* outline, + FT_BBox *abbox ); + + /* */ + + +FT_END_HEADER + +#endif /* FTBBOX_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/android/x86/include/freetype/ftbdf.h b/android/x86/include/freetype/ftbdf.h new file mode 100644 index 00000000..016dba08 --- /dev/null +++ b/android/x86/include/freetype/ftbdf.h @@ -0,0 +1,210 @@ +/***************************************************************************/ +/* */ +/* ftbdf.h */ +/* */ +/* FreeType API for accessing BDF-specific strings (specification). */ +/* */ +/* Copyright 2002-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTBDF_H_ +#define FTBDF_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* bdf_fonts */ + /* */ + /* <Title> */ + /* BDF and PCF Files */ + /* */ + /* <Abstract> */ + /* BDF and PCF specific API. */ + /* */ + /* <Description> */ + /* This section contains the declaration of functions specific to BDF */ + /* and PCF fonts. */ + /* */ + /*************************************************************************/ + + + /********************************************************************** + * + * @enum: + * BDF_PropertyType + * + * @description: + * A list of BDF property types. + * + * @values: + * BDF_PROPERTY_TYPE_NONE :: + * Value~0 is used to indicate a missing property. + * + * BDF_PROPERTY_TYPE_ATOM :: + * Property is a string atom. + * + * BDF_PROPERTY_TYPE_INTEGER :: + * Property is a 32-bit signed integer. + * + * BDF_PROPERTY_TYPE_CARDINAL :: + * Property is a 32-bit unsigned integer. + */ + typedef enum BDF_PropertyType_ + { + BDF_PROPERTY_TYPE_NONE = 0, + BDF_PROPERTY_TYPE_ATOM = 1, + BDF_PROPERTY_TYPE_INTEGER = 2, + BDF_PROPERTY_TYPE_CARDINAL = 3 + + } BDF_PropertyType; + + + /********************************************************************** + * + * @type: + * BDF_Property + * + * @description: + * A handle to a @BDF_PropertyRec structure to model a given + * BDF/PCF property. + */ + typedef struct BDF_PropertyRec_* BDF_Property; + + + /********************************************************************** + * + * @struct: + * BDF_PropertyRec + * + * @description: + * This structure models a given BDF/PCF property. + * + * @fields: + * type :: + * The property type. + * + * u.atom :: + * The atom string, if type is @BDF_PROPERTY_TYPE_ATOM. May be + * NULL, indicating an empty string. + * + * u.integer :: + * A signed integer, if type is @BDF_PROPERTY_TYPE_INTEGER. + * + * u.cardinal :: + * An unsigned integer, if type is @BDF_PROPERTY_TYPE_CARDINAL. + */ + typedef struct BDF_PropertyRec_ + { + BDF_PropertyType type; + union { + const char* atom; + FT_Int32 integer; + FT_UInt32 cardinal; + + } u; + + } BDF_PropertyRec; + + + /********************************************************************** + * + * @function: + * FT_Get_BDF_Charset_ID + * + * @description: + * Retrieve a BDF font character set identity, according to + * the BDF specification. + * + * @input: + * face :: + * A handle to the input face. + * + * @output: + * acharset_encoding :: + * Charset encoding, as a C~string, owned by the face. + * + * acharset_registry :: + * Charset registry, as a C~string, owned by the face. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with BDF faces, returning an error otherwise. + */ + FT_EXPORT( FT_Error ) + FT_Get_BDF_Charset_ID( FT_Face face, + const char* *acharset_encoding, + const char* *acharset_registry ); + + + /********************************************************************** + * + * @function: + * FT_Get_BDF_Property + * + * @description: + * Retrieve a BDF property from a BDF or PCF font file. + * + * @input: + * face :: A handle to the input face. + * + * name :: The property name. + * + * @output: + * aproperty :: The property. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function works with BDF _and_ PCF fonts. It returns an error + * otherwise. It also returns an error if the property is not in the + * font. + * + * A `property' is a either key-value pair within the STARTPROPERTIES + * ... ENDPROPERTIES block of a BDF font or a key-value pair from the + * `info->props' array within a `FontRec' structure of a PCF font. + * + * Integer properties are always stored as `signed' within PCF fonts; + * consequently, @BDF_PROPERTY_TYPE_CARDINAL is a possible return value + * for BDF fonts only. + * + * In case of error, `aproperty->type' is always set to + * @BDF_PROPERTY_TYPE_NONE. + */ + FT_EXPORT( FT_Error ) + FT_Get_BDF_Property( FT_Face face, + const char* prop_name, + BDF_PropertyRec *aproperty ); + + /* */ + +FT_END_HEADER + +#endif /* FTBDF_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftbitmap.h b/android/x86/include/freetype/ftbitmap.h new file mode 100644 index 00000000..0eac7b9d --- /dev/null +++ b/android/x86/include/freetype/ftbitmap.h @@ -0,0 +1,240 @@ +/***************************************************************************/ +/* */ +/* ftbitmap.h */ +/* */ +/* FreeType utility functions for bitmaps (specification). */ +/* */ +/* Copyright 2004-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTBITMAP_H_ +#define FTBITMAP_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* bitmap_handling */ + /* */ + /* <Title> */ + /* Bitmap Handling */ + /* */ + /* <Abstract> */ + /* Handling FT_Bitmap objects. */ + /* */ + /* <Description> */ + /* This section contains functions for handling @FT_Bitmap objects. */ + /* Note that none of the functions changes the bitmap's `flow' (as */ + /* indicated by the sign of the `pitch' field in `FT_Bitmap'). */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Init */ + /* */ + /* <Description> */ + /* Initialize a pointer to an @FT_Bitmap structure. */ + /* */ + /* <InOut> */ + /* abitmap :: A pointer to the bitmap structure. */ + /* */ + /* <Note> */ + /* A deprecated name for the same function is `FT_Bitmap_New'. */ + /* */ + FT_EXPORT( void ) + FT_Bitmap_Init( FT_Bitmap *abitmap ); + + + /* deprecated */ + FT_EXPORT( void ) + FT_Bitmap_New( FT_Bitmap *abitmap ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Copy */ + /* */ + /* <Description> */ + /* Copy a bitmap into another one. */ + /* */ + /* <Input> */ + /* library :: A handle to a library object. */ + /* */ + /* source :: A handle to the source bitmap. */ + /* */ + /* <Output> */ + /* target :: A handle to the target bitmap. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Bitmap_Copy( FT_Library library, + const FT_Bitmap *source, + FT_Bitmap *target); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Embolden */ + /* */ + /* <Description> */ + /* Embolden a bitmap. The new bitmap will be about `xStrength' */ + /* pixels wider and `yStrength' pixels higher. The left and bottom */ + /* borders are kept unchanged. */ + /* */ + /* <Input> */ + /* library :: A handle to a library object. */ + /* */ + /* xStrength :: How strong the glyph is emboldened horizontally. */ + /* Expressed in 26.6 pixel format. */ + /* */ + /* yStrength :: How strong the glyph is emboldened vertically. */ + /* Expressed in 26.6 pixel format. */ + /* */ + /* <InOut> */ + /* bitmap :: A handle to the target bitmap. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The current implementation restricts `xStrength' to be less than */ + /* or equal to~8 if bitmap is of pixel_mode @FT_PIXEL_MODE_MONO. */ + /* */ + /* If you want to embolden the bitmap owned by a @FT_GlyphSlotRec, */ + /* you should call @FT_GlyphSlot_Own_Bitmap on the slot first. */ + /* */ + /* Bitmaps in @FT_PIXEL_MODE_GRAY2 and @FT_PIXEL_MODE_GRAY@ format */ + /* are converted to @FT_PIXEL_MODE_GRAY format (i.e., 8bpp). */ + /* */ + FT_EXPORT( FT_Error ) + FT_Bitmap_Embolden( FT_Library library, + FT_Bitmap* bitmap, + FT_Pos xStrength, + FT_Pos yStrength ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Convert */ + /* */ + /* <Description> */ + /* Convert a bitmap object with depth 1bpp, 2bpp, 4bpp, 8bpp or 32bpp */ + /* to a bitmap object with depth 8bpp, making the number of used */ + /* bytes line (a.k.a. the `pitch') a multiple of `alignment'. */ + /* */ + /* <Input> */ + /* library :: A handle to a library object. */ + /* */ + /* source :: The source bitmap. */ + /* */ + /* alignment :: The pitch of the bitmap is a multiple of this */ + /* parameter. Common values are 1, 2, or 4. */ + /* */ + /* <Output> */ + /* target :: The target bitmap. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* It is possible to call @FT_Bitmap_Convert multiple times without */ + /* calling @FT_Bitmap_Done (the memory is simply reallocated). */ + /* */ + /* Use @FT_Bitmap_Done to finally remove the bitmap object. */ + /* */ + /* The `library' argument is taken to have access to FreeType's */ + /* memory handling functions. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Bitmap_Convert( FT_Library library, + const FT_Bitmap *source, + FT_Bitmap *target, + FT_Int alignment ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_GlyphSlot_Own_Bitmap */ + /* */ + /* <Description> */ + /* Make sure that a glyph slot owns `slot->bitmap'. */ + /* */ + /* <Input> */ + /* slot :: The glyph slot. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function is to be used in combination with */ + /* @FT_Bitmap_Embolden. */ + /* */ + FT_EXPORT( FT_Error ) + FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Done */ + /* */ + /* <Description> */ + /* Destroy a bitmap object initialized with @FT_Bitmap_Init. */ + /* */ + /* <Input> */ + /* library :: A handle to a library object. */ + /* */ + /* bitmap :: The bitmap object to be freed. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The `library' argument is taken to have access to FreeType's */ + /* memory handling functions. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Bitmap_Done( FT_Library library, + FT_Bitmap *bitmap ); + + + /* */ + + +FT_END_HEADER + +#endif /* FTBITMAP_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftbzip2.h b/android/x86/include/freetype/ftbzip2.h new file mode 100644 index 00000000..b7f2eee8 --- /dev/null +++ b/android/x86/include/freetype/ftbzip2.h @@ -0,0 +1,102 @@ +/***************************************************************************/ +/* */ +/* ftbzip2.h */ +/* */ +/* Bzip2-compressed stream support. */ +/* */ +/* Copyright 2010-2016 by */ +/* Joel Klinghed. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTBZIP2_H_ +#define FTBZIP2_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* <Section> */ + /* bzip2 */ + /* */ + /* <Title> */ + /* BZIP2 Streams */ + /* */ + /* <Abstract> */ + /* Using bzip2-compressed font files. */ + /* */ + /* <Description> */ + /* This section contains the declaration of Bzip2-specific functions. */ + /* */ + /*************************************************************************/ + + + /************************************************************************ + * + * @function: + * FT_Stream_OpenBzip2 + * + * @description: + * Open a new stream to parse bzip2-compressed font files. This is + * mainly used to support the compressed `*.pcf.bz2' fonts that come + * with XFree86. + * + * @input: + * stream :: + * The target embedding stream. + * + * source :: + * The source stream. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source stream must be opened _before_ calling this function. + * + * Calling the internal function `FT_Stream_Close' on the new stream will + * *not* call `FT_Stream_Close' on the source stream. None of the stream + * objects will be released to the heap. + * + * The stream implementation is very basic and resets the decompression + * process each time seeking backwards is needed within the stream. + * + * In certain builds of the library, bzip2 compression recognition is + * automatically handled when calling @FT_New_Face or @FT_Open_Face. + * This means that if no font driver is capable of handling the raw + * compressed file, the library will try to open a bzip2 compressed stream + * from it and re-open the face with it. + * + * This function may return `FT_Err_Unimplemented_Feature' if your build + * of FreeType was not compiled with bzip2 support. + */ + FT_EXPORT( FT_Error ) + FT_Stream_OpenBzip2( FT_Stream stream, + FT_Stream source ); + + /* */ + + +FT_END_HEADER + +#endif /* FTBZIP2_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftcache.h b/android/x86/include/freetype/ftcache.h new file mode 100644 index 00000000..6c9f2c42 --- /dev/null +++ b/android/x86/include/freetype/ftcache.h @@ -0,0 +1,1057 @@ +/***************************************************************************/ +/* */ +/* ftcache.h */ +/* */ +/* FreeType Cache subsystem (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTCACHE_H_ +#define FTCACHE_H_ + + +#include <ft2build.h> +#include FT_GLYPH_H + + +FT_BEGIN_HEADER + + + /************************************************************************* + * + * <Section> + * cache_subsystem + * + * <Title> + * Cache Sub-System + * + * <Abstract> + * How to cache face, size, and glyph data with FreeType~2. + * + * <Description> + * This section describes the FreeType~2 cache sub-system, which is used + * to limit the number of concurrently opened @FT_Face and @FT_Size + * objects, as well as caching information like character maps and glyph + * images while limiting their maximum memory usage. + * + * Note that all types and functions begin with the `FTC_' prefix. + * + * The cache is highly portable and thus doesn't know anything about the + * fonts installed on your system, or how to access them. This implies + * the following scheme: + * + * First, available or installed font faces are uniquely identified by + * @FTC_FaceID values, provided to the cache by the client. Note that + * the cache only stores and compares these values, and doesn't try to + * interpret them in any way. + * + * Second, the cache calls, only when needed, a client-provided function + * to convert an @FTC_FaceID into a new @FT_Face object. The latter is + * then completely managed by the cache, including its termination + * through @FT_Done_Face. To monitor termination of face objects, the + * finalizer callback in the `generic' field of the @FT_Face object can + * be used, which might also be used to store the @FTC_FaceID of the + * face. + * + * Clients are free to map face IDs to anything else. The most simple + * usage is to associate them to a (pathname,face_index) pair that is + * used to call @FT_New_Face. However, more complex schemes are also + * possible. + * + * Note that for the cache to work correctly, the face ID values must be + * *persistent*, which means that the contents they point to should not + * change at runtime, or that their value should not become invalid. + * + * If this is unavoidable (e.g., when a font is uninstalled at runtime), + * you should call @FTC_Manager_RemoveFaceID as soon as possible, to let + * the cache get rid of any references to the old @FTC_FaceID it may + * keep internally. Failure to do so will lead to incorrect behaviour + * or even crashes. + * + * To use the cache, start with calling @FTC_Manager_New to create a new + * @FTC_Manager object, which models a single cache instance. You can + * then look up @FT_Face and @FT_Size objects with + * @FTC_Manager_LookupFace and @FTC_Manager_LookupSize, respectively. + * + * If you want to use the charmap caching, call @FTC_CMapCache_New, then + * later use @FTC_CMapCache_Lookup to perform the equivalent of + * @FT_Get_Char_Index, only much faster. + * + * If you want to use the @FT_Glyph caching, call @FTC_ImageCache, then + * later use @FTC_ImageCache_Lookup to retrieve the corresponding + * @FT_Glyph objects from the cache. + * + * If you need lots of small bitmaps, it is much more memory efficient + * to call @FTC_SBitCache_New followed by @FTC_SBitCache_Lookup. This + * returns @FTC_SBitRec structures, which are used to store small + * bitmaps directly. (A small bitmap is one whose metrics and + * dimensions all fit into 8-bit integers). + * + * We hope to also provide a kerning cache in the near future. + * + * + * <Order> + * FTC_Manager + * FTC_FaceID + * FTC_Face_Requester + * + * FTC_Manager_New + * FTC_Manager_Reset + * FTC_Manager_Done + * FTC_Manager_LookupFace + * FTC_Manager_LookupSize + * FTC_Manager_RemoveFaceID + * + * FTC_Node + * FTC_Node_Unref + * + * FTC_ImageCache + * FTC_ImageCache_New + * FTC_ImageCache_Lookup + * + * FTC_SBit + * FTC_SBitCache + * FTC_SBitCache_New + * FTC_SBitCache_Lookup + * + * FTC_CMapCache + * FTC_CMapCache_New + * FTC_CMapCache_Lookup + * + *************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** BASIC TYPE DEFINITIONS *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************* + * + * @type: FTC_FaceID + * + * @description: + * An opaque pointer type that is used to identity face objects. The + * contents of such objects is application-dependent. + * + * These pointers are typically used to point to a user-defined + * structure containing a font file path, and face index. + * + * @note: + * Never use NULL as a valid @FTC_FaceID. + * + * Face IDs are passed by the client to the cache manager that calls, + * when needed, the @FTC_Face_Requester to translate them into new + * @FT_Face objects. + * + * If the content of a given face ID changes at runtime, or if the value + * becomes invalid (e.g., when uninstalling a font), you should + * immediately call @FTC_Manager_RemoveFaceID before any other cache + * function. + * + * Failure to do so will result in incorrect behaviour or even + * memory leaks and crashes. + */ + typedef FT_Pointer FTC_FaceID; + + + /************************************************************************ + * + * @functype: + * FTC_Face_Requester + * + * @description: + * A callback function provided by client applications. It is used by + * the cache manager to translate a given @FTC_FaceID into a new valid + * @FT_Face object, on demand. + * + * <Input> + * face_id :: + * The face ID to resolve. + * + * library :: + * A handle to a FreeType library object. + * + * req_data :: + * Application-provided request data (see note below). + * + * <Output> + * aface :: + * A new @FT_Face handle. + * + * <Return> + * FreeType error code. 0~means success. + * + * <Note> + * The third parameter `req_data' is the same as the one passed by the + * client when @FTC_Manager_New is called. + * + * The face requester should not perform funny things on the returned + * face object, like creating a new @FT_Size for it, or setting a + * transformation through @FT_Set_Transform! + */ + typedef FT_Error + (*FTC_Face_Requester)( FTC_FaceID face_id, + FT_Library library, + FT_Pointer req_data, + FT_Face* aface ); + + /* */ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** CACHE MANAGER OBJECT *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_Manager */ + /* */ + /* <Description> */ + /* This object corresponds to one instance of the cache-subsystem. */ + /* It is used to cache one or more @FT_Face objects, along with */ + /* corresponding @FT_Size objects. */ + /* */ + /* The manager intentionally limits the total number of opened */ + /* @FT_Face and @FT_Size objects to control memory usage. See the */ + /* `max_faces' and `max_sizes' parameters of @FTC_Manager_New. */ + /* */ + /* The manager is also used to cache `nodes' of various types while */ + /* limiting their total memory usage. */ + /* */ + /* All limitations are enforced by keeping lists of managed objects */ + /* in most-recently-used order, and flushing old nodes to make room */ + /* for new ones. */ + /* */ + typedef struct FTC_ManagerRec_* FTC_Manager; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_Node */ + /* */ + /* <Description> */ + /* An opaque handle to a cache node object. Each cache node is */ + /* reference-counted. A node with a count of~0 might be flushed */ + /* out of a full cache whenever a lookup request is performed. */ + /* */ + /* If you look up nodes, you have the ability to `acquire' them, */ + /* i.e., to increment their reference count. This will prevent the */ + /* node from being flushed out of the cache until you explicitly */ + /* `release' it (see @FTC_Node_Unref). */ + /* */ + /* See also @FTC_SBitCache_Lookup and @FTC_ImageCache_Lookup. */ + /* */ + typedef struct FTC_NodeRec_* FTC_Node; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_New */ + /* */ + /* <Description> */ + /* Create a new cache manager. */ + /* */ + /* <Input> */ + /* library :: The parent FreeType library handle to use. */ + /* */ + /* max_faces :: Maximum number of opened @FT_Face objects managed by */ + /* this cache instance. Use~0 for defaults. */ + /* */ + /* max_sizes :: Maximum number of opened @FT_Size objects managed by */ + /* this cache instance. Use~0 for defaults. */ + /* */ + /* max_bytes :: Maximum number of bytes to use for cached data nodes. */ + /* Use~0 for defaults. Note that this value does not */ + /* account for managed @FT_Face and @FT_Size objects. */ + /* */ + /* requester :: An application-provided callback used to translate */ + /* face IDs into real @FT_Face objects. */ + /* */ + /* req_data :: A generic pointer that is passed to the requester */ + /* each time it is called (see @FTC_Face_Requester). */ + /* */ + /* <Output> */ + /* amanager :: A handle to a new manager object. 0~in case of */ + /* failure. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_Manager_New( FT_Library library, + FT_UInt max_faces, + FT_UInt max_sizes, + FT_ULong max_bytes, + FTC_Face_Requester requester, + FT_Pointer req_data, + FTC_Manager *amanager ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_Reset */ + /* */ + /* <Description> */ + /* Empty a given cache manager. This simply gets rid of all the */ + /* currently cached @FT_Face and @FT_Size objects within the manager. */ + /* */ + /* <InOut> */ + /* manager :: A handle to the manager. */ + /* */ + FT_EXPORT( void ) + FTC_Manager_Reset( FTC_Manager manager ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_Done */ + /* */ + /* <Description> */ + /* Destroy a given manager after emptying it. */ + /* */ + /* <Input> */ + /* manager :: A handle to the target cache manager object. */ + /* */ + FT_EXPORT( void ) + FTC_Manager_Done( FTC_Manager manager ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_LookupFace */ + /* */ + /* <Description> */ + /* Retrieve the @FT_Face object that corresponds to a given face ID */ + /* through a cache manager. */ + /* */ + /* <Input> */ + /* manager :: A handle to the cache manager. */ + /* */ + /* face_id :: The ID of the face object. */ + /* */ + /* <Output> */ + /* aface :: A handle to the face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The returned @FT_Face object is always owned by the manager. You */ + /* should never try to discard it yourself. */ + /* */ + /* The @FT_Face object doesn't necessarily have a current size object */ + /* (i.e., face->size can be~0). If you need a specific `font size', */ + /* use @FTC_Manager_LookupSize instead. */ + /* */ + /* Never change the face's transformation matrix (i.e., never call */ + /* the @FT_Set_Transform function) on a returned face! If you need */ + /* to transform glyphs, do it yourself after glyph loading. */ + /* */ + /* When you perform a lookup, out-of-memory errors are detected */ + /* _within_ the lookup and force incremental flushes of the cache */ + /* until enough memory is released for the lookup to succeed. */ + /* */ + /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */ + /* already been completely flushed, and still no memory was available */ + /* for the operation. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_Manager_LookupFace( FTC_Manager manager, + FTC_FaceID face_id, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FTC_ScalerRec */ + /* */ + /* <Description> */ + /* A structure used to describe a given character size in either */ + /* pixels or points to the cache manager. See */ + /* @FTC_Manager_LookupSize. */ + /* */ + /* <Fields> */ + /* face_id :: The source face ID. */ + /* */ + /* width :: The character width. */ + /* */ + /* height :: The character height. */ + /* */ + /* pixel :: A Boolean. If 1, the `width' and `height' fields are */ + /* interpreted as integer pixel character sizes. */ + /* Otherwise, they are expressed as 1/64th of points. */ + /* */ + /* x_res :: Only used when `pixel' is value~0 to indicate the */ + /* horizontal resolution in dpi. */ + /* */ + /* y_res :: Only used when `pixel' is value~0 to indicate the */ + /* vertical resolution in dpi. */ + /* */ + /* <Note> */ + /* This type is mainly used to retrieve @FT_Size objects through the */ + /* cache manager. */ + /* */ + typedef struct FTC_ScalerRec_ + { + FTC_FaceID face_id; + FT_UInt width; + FT_UInt height; + FT_Int pixel; + FT_UInt x_res; + FT_UInt y_res; + + } FTC_ScalerRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FTC_Scaler */ + /* */ + /* <Description> */ + /* A handle to an @FTC_ScalerRec structure. */ + /* */ + typedef struct FTC_ScalerRec_* FTC_Scaler; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_LookupSize */ + /* */ + /* <Description> */ + /* Retrieve the @FT_Size object that corresponds to a given */ + /* @FTC_ScalerRec pointer through a cache manager. */ + /* */ + /* <Input> */ + /* manager :: A handle to the cache manager. */ + /* */ + /* scaler :: A scaler handle. */ + /* */ + /* <Output> */ + /* asize :: A handle to the size object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The returned @FT_Size object is always owned by the manager. You */ + /* should never try to discard it by yourself. */ + /* */ + /* You can access the parent @FT_Face object simply as `size->face' */ + /* if you need it. Note that this object is also owned by the */ + /* manager. */ + /* */ + /* <Note> */ + /* When you perform a lookup, out-of-memory errors are detected */ + /* _within_ the lookup and force incremental flushes of the cache */ + /* until enough memory is released for the lookup to succeed. */ + /* */ + /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */ + /* already been completely flushed, and still no memory is available */ + /* for the operation. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_Manager_LookupSize( FTC_Manager manager, + FTC_Scaler scaler, + FT_Size *asize ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Node_Unref */ + /* */ + /* <Description> */ + /* Decrement a cache node's internal reference count. When the count */ + /* reaches 0, it is not destroyed but becomes eligible for subsequent */ + /* cache flushes. */ + /* */ + /* <Input> */ + /* node :: The cache node handle. */ + /* */ + /* manager :: The cache manager handle. */ + /* */ + FT_EXPORT( void ) + FTC_Node_Unref( FTC_Node node, + FTC_Manager manager ); + + + /************************************************************************* + * + * @function: + * FTC_Manager_RemoveFaceID + * + * @description: + * A special function used to indicate to the cache manager that + * a given @FTC_FaceID is no longer valid, either because its + * content changed, or because it was deallocated or uninstalled. + * + * @input: + * manager :: + * The cache manager handle. + * + * face_id :: + * The @FTC_FaceID to be removed. + * + * @note: + * This function flushes all nodes from the cache corresponding to this + * `face_id', with the exception of nodes with a non-null reference + * count. + * + * Such nodes are however modified internally so as to never appear + * in later lookups with the same `face_id' value, and to be immediately + * destroyed when released by all their users. + * + */ + FT_EXPORT( void ) + FTC_Manager_RemoveFaceID( FTC_Manager manager, + FTC_FaceID face_id ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* cache_subsystem */ + /* */ + /*************************************************************************/ + + /************************************************************************* + * + * @type: + * FTC_CMapCache + * + * @description: + * An opaque handle used to model a charmap cache. This cache is to + * hold character codes -> glyph indices mappings. + * + */ + typedef struct FTC_CMapCacheRec_* FTC_CMapCache; + + + /************************************************************************* + * + * @function: + * FTC_CMapCache_New + * + * @description: + * Create a new charmap cache. + * + * @input: + * manager :: + * A handle to the cache manager. + * + * @output: + * acache :: + * A new cache handle. NULL in case of error. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * Like all other caches, this one will be destroyed with the cache + * manager. + * + */ + FT_EXPORT( FT_Error ) + FTC_CMapCache_New( FTC_Manager manager, + FTC_CMapCache *acache ); + + + /************************************************************************ + * + * @function: + * FTC_CMapCache_Lookup + * + * @description: + * Translate a character code into a glyph index, using the charmap + * cache. + * + * @input: + * cache :: + * A charmap cache handle. + * + * face_id :: + * The source face ID. + * + * cmap_index :: + * The index of the charmap in the source face. Any negative value + * means to use the cache @FT_Face's default charmap. + * + * char_code :: + * The character code (in the corresponding charmap). + * + * @return: + * Glyph index. 0~means `no glyph'. + * + */ + FT_EXPORT( FT_UInt ) + FTC_CMapCache_Lookup( FTC_CMapCache cache, + FTC_FaceID face_id, + FT_Int cmap_index, + FT_UInt32 char_code ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* cache_subsystem */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** IMAGE CACHE OBJECT *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************* + * + * @struct: + * FTC_ImageTypeRec + * + * @description: + * A structure used to model the type of images in a glyph cache. + * + * @fields: + * face_id :: + * The face ID. + * + * width :: + * The width in pixels. + * + * height :: + * The height in pixels. + * + * flags :: + * The load flags, as in @FT_Load_Glyph. + * + */ + typedef struct FTC_ImageTypeRec_ + { + FTC_FaceID face_id; + FT_UInt width; + FT_UInt height; + FT_Int32 flags; + + } FTC_ImageTypeRec; + + + /************************************************************************* + * + * @type: + * FTC_ImageType + * + * @description: + * A handle to an @FTC_ImageTypeRec structure. + * + */ + typedef struct FTC_ImageTypeRec_* FTC_ImageType; + + + /* */ + + +#define FTC_IMAGE_TYPE_COMPARE( d1, d2 ) \ + ( (d1)->face_id == (d2)->face_id && \ + (d1)->width == (d2)->width && \ + (d1)->flags == (d2)->flags ) + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_ImageCache */ + /* */ + /* <Description> */ + /* A handle to a glyph image cache object. They are designed to */ + /* hold many distinct glyph images while not exceeding a certain */ + /* memory threshold. */ + /* */ + typedef struct FTC_ImageCacheRec_* FTC_ImageCache; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_ImageCache_New */ + /* */ + /* <Description> */ + /* Create a new glyph image cache. */ + /* */ + /* <Input> */ + /* manager :: The parent manager for the image cache. */ + /* */ + /* <Output> */ + /* acache :: A handle to the new glyph image cache object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_ImageCache_New( FTC_Manager manager, + FTC_ImageCache *acache ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_ImageCache_Lookup */ + /* */ + /* <Description> */ + /* Retrieve a given glyph image from a glyph image cache. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source glyph image cache. */ + /* */ + /* type :: A pointer to a glyph image type descriptor. */ + /* */ + /* gindex :: The glyph index to retrieve. */ + /* */ + /* <Output> */ + /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */ + /* failure. */ + /* */ + /* anode :: Used to return the address of of the corresponding cache */ + /* node after incrementing its reference count (see note */ + /* below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The returned glyph is owned and managed by the glyph image cache. */ + /* Never try to transform or discard it manually! You can however */ + /* create a copy with @FT_Glyph_Copy and modify the new one. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the glyph image, after increasing its reference */ + /* count. This ensures that the node (as well as the @FT_Glyph) will */ + /* always be kept in the cache until you call @FTC_Node_Unref to */ + /* `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the @FT_Glyph could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_ImageCache_Lookup( FTC_ImageCache cache, + FTC_ImageType type, + FT_UInt gindex, + FT_Glyph *aglyph, + FTC_Node *anode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_ImageCache_LookupScaler */ + /* */ + /* <Description> */ + /* A variant of @FTC_ImageCache_Lookup that uses an @FTC_ScalerRec */ + /* to specify the face ID and its size. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source glyph image cache. */ + /* */ + /* scaler :: A pointer to a scaler descriptor. */ + /* */ + /* load_flags :: The corresponding load flags. */ + /* */ + /* gindex :: The glyph index to retrieve. */ + /* */ + /* <Output> */ + /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */ + /* failure. */ + /* */ + /* anode :: Used to return the address of of the corresponding */ + /* cache node after incrementing its reference count */ + /* (see note below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The returned glyph is owned and managed by the glyph image cache. */ + /* Never try to transform or discard it manually! You can however */ + /* create a copy with @FT_Glyph_Copy and modify the new one. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the glyph image, after increasing its reference */ + /* count. This ensures that the node (as well as the @FT_Glyph) will */ + /* always be kept in the cache until you call @FTC_Node_Unref to */ + /* `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the @FT_Glyph could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + /* Calls to @FT_Set_Char_Size and friends have no effect on cached */ + /* glyphs; you should always use the FreeType cache API instead. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_ImageCache_LookupScaler( FTC_ImageCache cache, + FTC_Scaler scaler, + FT_ULong load_flags, + FT_UInt gindex, + FT_Glyph *aglyph, + FTC_Node *anode ); + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_SBit */ + /* */ + /* <Description> */ + /* A handle to a small bitmap descriptor. See the @FTC_SBitRec */ + /* structure for details. */ + /* */ + typedef struct FTC_SBitRec_* FTC_SBit; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FTC_SBitRec */ + /* */ + /* <Description> */ + /* A very compact structure used to describe a small glyph bitmap. */ + /* */ + /* <Fields> */ + /* width :: The bitmap width in pixels. */ + /* */ + /* height :: The bitmap height in pixels. */ + /* */ + /* left :: The horizontal distance from the pen position to the */ + /* left bitmap border (a.k.a. `left side bearing', or */ + /* `lsb'). */ + /* */ + /* top :: The vertical distance from the pen position (on the */ + /* baseline) to the upper bitmap border (a.k.a. `top */ + /* side bearing'). The distance is positive for upwards */ + /* y~coordinates. */ + /* */ + /* format :: The format of the glyph bitmap (monochrome or gray). */ + /* */ + /* max_grays :: Maximum gray level value (in the range 1 to~255). */ + /* */ + /* pitch :: The number of bytes per bitmap line. May be positive */ + /* or negative. */ + /* */ + /* xadvance :: The horizontal advance width in pixels. */ + /* */ + /* yadvance :: The vertical advance height in pixels. */ + /* */ + /* buffer :: A pointer to the bitmap pixels. */ + /* */ + typedef struct FTC_SBitRec_ + { + FT_Byte width; + FT_Byte height; + FT_Char left; + FT_Char top; + + FT_Byte format; + FT_Byte max_grays; + FT_Short pitch; + FT_Char xadvance; + FT_Char yadvance; + + FT_Byte* buffer; + + } FTC_SBitRec; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_SBitCache */ + /* */ + /* <Description> */ + /* A handle to a small bitmap cache. These are special cache objects */ + /* used to store small glyph bitmaps (and anti-aliased pixmaps) in a */ + /* much more efficient way than the traditional glyph image cache */ + /* implemented by @FTC_ImageCache. */ + /* */ + typedef struct FTC_SBitCacheRec_* FTC_SBitCache; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBitCache_New */ + /* */ + /* <Description> */ + /* Create a new cache to store small glyph bitmaps. */ + /* */ + /* <Input> */ + /* manager :: A handle to the source cache manager. */ + /* */ + /* <Output> */ + /* acache :: A handle to the new sbit cache. NULL in case of error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBitCache_New( FTC_Manager manager, + FTC_SBitCache *acache ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBitCache_Lookup */ + /* */ + /* <Description> */ + /* Look up a given small glyph bitmap in a given sbit cache and */ + /* `lock' it to prevent its flushing from the cache until needed. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source sbit cache. */ + /* */ + /* type :: A pointer to the glyph image type descriptor. */ + /* */ + /* gindex :: The glyph index. */ + /* */ + /* <Output> */ + /* sbit :: A handle to a small bitmap descriptor. */ + /* */ + /* anode :: Used to return the address of of the corresponding cache */ + /* node after incrementing its reference count (see note */ + /* below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The small bitmap descriptor and its bit buffer are owned by the */ + /* cache and should never be freed by the application. They might */ + /* as well disappear from memory on the next cache lookup, so don't */ + /* treat them as persistent data. */ + /* */ + /* The descriptor's `buffer' field is set to~0 to indicate a missing */ + /* glyph bitmap. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the bitmap, after increasing its reference count. */ + /* This ensures that the node (as well as the image) will always be */ + /* kept in the cache until you call @FTC_Node_Unref to `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the bitmap could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBitCache_Lookup( FTC_SBitCache cache, + FTC_ImageType type, + FT_UInt gindex, + FTC_SBit *sbit, + FTC_Node *anode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBitCache_LookupScaler */ + /* */ + /* <Description> */ + /* A variant of @FTC_SBitCache_Lookup that uses an @FTC_ScalerRec */ + /* to specify the face ID and its size. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source sbit cache. */ + /* */ + /* scaler :: A pointer to the scaler descriptor. */ + /* */ + /* load_flags :: The corresponding load flags. */ + /* */ + /* gindex :: The glyph index. */ + /* */ + /* <Output> */ + /* sbit :: A handle to a small bitmap descriptor. */ + /* */ + /* anode :: Used to return the address of of the corresponding */ + /* cache node after incrementing its reference count */ + /* (see note below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The small bitmap descriptor and its bit buffer are owned by the */ + /* cache and should never be freed by the application. They might */ + /* as well disappear from memory on the next cache lookup, so don't */ + /* treat them as persistent data. */ + /* */ + /* The descriptor's `buffer' field is set to~0 to indicate a missing */ + /* glyph bitmap. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the bitmap, after increasing its reference count. */ + /* This ensures that the node (as well as the image) will always be */ + /* kept in the cache until you call @FTC_Node_Unref to `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the bitmap could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBitCache_LookupScaler( FTC_SBitCache cache, + FTC_Scaler scaler, + FT_ULong load_flags, + FT_UInt gindex, + FTC_SBit *sbit, + FTC_Node *anode ); + + /* */ + + +FT_END_HEADER + +#endif /* FTCACHE_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftcffdrv.h b/android/x86/include/freetype/ftcffdrv.h new file mode 100644 index 00000000..9dea980a --- /dev/null +++ b/android/x86/include/freetype/ftcffdrv.h @@ -0,0 +1,262 @@ +/***************************************************************************/ +/* */ +/* ftcffdrv.h */ +/* */ +/* FreeType API for controlling the CFF driver (specification only). */ +/* */ +/* Copyright 2013-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTCFFDRV_H_ +#define FTCFFDRV_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /************************************************************************** + * + * @section: + * cff_driver + * + * @title: + * The CFF driver + * + * @abstract: + * Controlling the CFF driver module. + * + * @description: + * While FreeType's CFF driver doesn't expose API functions by itself, + * it is possible to control its behaviour with @FT_Property_Set and + * @FT_Property_Get. The list below gives the available properties + * together with the necessary macros and structures. + * + * The CFF driver's module name is `cff'. + * + * *Hinting* *and* *antialiasing* *principles* *of* *the* *new* *engine* + * + * The rasterizer is positioning horizontal features (e.g., ascender + * height & x-height, or crossbars) on the pixel grid and minimizing the + * amount of antialiasing applied to them, while placing vertical + * features (vertical stems) on the pixel grid without hinting, thus + * representing the stem position and weight accurately. Sometimes the + * vertical stems may be only partially black. In this context, + * `antialiasing' means that stems are not positioned exactly on pixel + * borders, causing a fuzzy appearance. + * + * There are two principles behind this approach. + * + * 1) No hinting in the horizontal direction: Unlike `superhinted' + * TrueType, which changes glyph widths to accommodate regular + * inter-glyph spacing, Adobe's approach is `faithful to the design' in + * representing both the glyph width and the inter-glyph spacing + * designed for the font. This makes the screen display as close as it + * can be to the result one would get with infinite resolution, while + * preserving what is considered the key characteristics of each glyph. + * Note that the distances between unhinted and grid-fitted positions at + * small sizes are comparable to kerning values and thus would be + * noticeable (and distracting) while reading if hinting were applied. + * + * One of the reasons to not hint horizontally is antialiasing for LCD + * screens: The pixel geometry of modern displays supplies three + * vertical sub-pixels as the eye moves horizontally across each visible + * pixel. On devices where we can be certain this characteristic is + * present a rasterizer can take advantage of the sub-pixels to add + * increments of weight. In Western writing systems this turns out to + * be the more critical direction anyway; the weights and spacing of + * vertical stems (see above) are central to Armenian, Cyrillic, Greek, + * and Latin type designs. Even when the rasterizer uses greyscale + * antialiasing instead of color (a necessary compromise when one + * doesn't know the screen characteristics), the unhinted vertical + * features preserve the design's weight and spacing much better than + * aliased type would. + * + * 2) Aligment in the vertical direction: Weights and spacing along the + * y~axis are less critical; what is much more important is the visual + * alignment of related features (like cap-height and x-height). The + * sense of alignment for these is enhanced by the sharpness of grid-fit + * edges, while the cruder vertical resolution (full pixels instead of + * 1/3 pixels) is less of a problem. + * + * On the technical side, horizontal alignment zones for ascender, + * x-height, and other important height values (traditionally called + * `blue zones') as defined in the font are positioned independently, + * each being rounded to the nearest pixel edge, taking care of + * overshoot suppression at small sizes, stem darkening, and scaling. + * + * Hstems (this is, hint values defined in the font to help align + * horizontal features) that fall within a blue zone are said to be + * `captured' and are aligned to that zone. Uncaptured stems are moved + * in one of four ways, top edge up or down, bottom edge up or down. + * Unless there are conflicting hstems, the smallest movement is taken + * to minimize distortion. + * + * @order: + * hinting-engine + * no-stem-darkening[cff] + * darkening-parameters[cff] + * + */ + + + /************************************************************************** + * + * @property: + * hinting-engine + * + * @description: + * Thanks to Adobe, which contributed a new hinting (and parsing) + * engine, an application can select between `freetype' and `adobe' if + * compiled with CFF_CONFIG_OPTION_OLD_ENGINE. If this configuration + * macro isn't defined, `hinting-engine' does nothing. + * + * The default engine is `freetype' if CFF_CONFIG_OPTION_OLD_ENGINE is + * defined, and `adobe' otherwise. + * + * The following example code demonstrates how to select Adobe's hinting + * engine (omitting the error handling). + * + * { + * FT_Library library; + * FT_UInt hinting_engine = FT_CFF_HINTING_ADOBE; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "cff", + * "hinting-engine", &hinting_engine ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + */ + + + /************************************************************************** + * + * @enum: + * FT_CFF_HINTING_XXX + * + * @description: + * A list of constants used for the @hinting-engine property to select + * the hinting engine for CFF fonts. + * + * @values: + * FT_CFF_HINTING_FREETYPE :: + * Use the old FreeType hinting engine. + * + * FT_CFF_HINTING_ADOBE :: + * Use the hinting engine contributed by Adobe. + * + */ +#define FT_CFF_HINTING_FREETYPE 0 +#define FT_CFF_HINTING_ADOBE 1 + + + /************************************************************************** + * + * @property: + * no-stem-darkening[cff] + * + * @description: + * By default, the Adobe CFF engine darkens stems at smaller sizes, + * regardless of hinting, to enhance contrast. This feature requires + * a rendering system with proper gamma correction. Setting this + * property, stem darkening gets switched off. + * + * Note that stem darkening is never applied if @FT_LOAD_NO_SCALE is set. + * + * { + * FT_Library library; + * FT_Bool no_stem_darkening = TRUE; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "cff", + * "no-stem-darkening", &no_stem_darkening ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + */ + + + /************************************************************************** + * + * @property: + * darkening-parameters[cff] + * + * @description: + * By default, the Adobe CFF engine darkens stems as follows (if the + * `no-stem-darkening' property isn't set): + * + * { + * stem width <= 0.5px: darkening amount = 0.4px + * stem width = 1px: darkening amount = 0.275px + * stem width = 1.667px: darkening amount = 0.275px + * stem width >= 2.333px: darkening amount = 0px + * } + * + * and piecewise linear in-between. At configuration time, these four + * control points can be set with the macro + * `CFF_CONFIG_OPTION_DARKENING_PARAMETERS'. At runtime, the control + * points can be changed using the `darkening-parameters' property, as + * the following example demonstrates. + * + * { + * FT_Library library; + * FT_Int darken_params[8] = { 500, 300, // x1, y1 + * 1000, 200, // x2, y2 + * 1500, 100, // x3, y3 + * 2000, 0 }; // x4, y4 + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "cff", + * "darkening-parameters", darken_params ); + * } + * + * The x~values give the stem width, and the y~values the darkening + * amount. The unit is 1000th of pixels. All coordinate values must be + * positive; the x~values must be monotonically increasing; the + * y~values must be monotonically decreasing and smaller than or + * equal to 500 (corresponding to half a pixel); the slope of each + * linear piece must be shallower than -1 (e.g., -.4). + * + * @note: + * This property can be used with @FT_Property_Get also. + * + */ + + /* */ + + +FT_END_HEADER + + +#endif /* FTCFFDRV_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftchapters.h b/android/x86/include/freetype/ftchapters.h new file mode 100644 index 00000000..ab438953 --- /dev/null +++ b/android/x86/include/freetype/ftchapters.h @@ -0,0 +1,135 @@ +/***************************************************************************/ +/* */ +/* This file defines the structure of the FreeType reference. */ +/* It is used by the python script that generates the HTML files. */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* general_remarks */ +/* */ +/* <Title> */ +/* General Remarks */ +/* */ +/* <Sections> */ +/* header_inclusion */ +/* user_allocation */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* core_api */ +/* */ +/* <Title> */ +/* Core API */ +/* */ +/* <Sections> */ +/* version */ +/* basic_types */ +/* base_interface */ +/* glyph_variants */ +/* glyph_management */ +/* mac_specific */ +/* sizes_management */ +/* header_file_macros */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* format_specific */ +/* */ +/* <Title> */ +/* Format-Specific API */ +/* */ +/* <Sections> */ +/* multiple_masters */ +/* truetype_tables */ +/* type1_tables */ +/* sfnt_names */ +/* bdf_fonts */ +/* cid_fonts */ +/* pfr_fonts */ +/* winfnt_fonts */ +/* font_formats */ +/* gasp_table */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* module_specific */ +/* */ +/* <Title> */ +/* Controlling FreeType Modules */ +/* */ +/* <Sections> */ +/* auto_hinter */ +/* cff_driver */ +/* tt_driver */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* cache_subsystem */ +/* */ +/* <Title> */ +/* Cache Sub-System */ +/* */ +/* <Sections> */ +/* cache_subsystem */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* support_api */ +/* */ +/* <Title> */ +/* Support API */ +/* */ +/* <Sections> */ +/* computations */ +/* list_processing */ +/* outline_processing */ +/* quick_advance */ +/* bitmap_handling */ +/* raster */ +/* glyph_stroker */ +/* system_interface */ +/* module_management */ +/* gzip */ +/* lzw */ +/* bzip2 */ +/* lcd_filtering */ +/* */ +/***************************************************************************/ + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* error_codes */ +/* */ +/* <Title> */ +/* Error Codes */ +/* */ +/* <Sections> */ +/* error_enumerations */ +/* error_code_values */ +/* */ +/***************************************************************************/ diff --git a/android/x86/include/freetype/ftcid.h b/android/x86/include/freetype/ftcid.h new file mode 100644 index 00000000..140f2f87 --- /dev/null +++ b/android/x86/include/freetype/ftcid.h @@ -0,0 +1,168 @@ +/***************************************************************************/ +/* */ +/* ftcid.h */ +/* */ +/* FreeType API for accessing CID font information (specification). */ +/* */ +/* Copyright 2007-2016 by */ +/* Dereg Clegg and Michael Toftdal. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTCID_H_ +#define FTCID_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* cid_fonts */ + /* */ + /* <Title> */ + /* CID Fonts */ + /* */ + /* <Abstract> */ + /* CID-keyed font specific API. */ + /* */ + /* <Description> */ + /* This section contains the declaration of CID-keyed font specific */ + /* functions. */ + /* */ + /*************************************************************************/ + + + /********************************************************************** + * + * @function: + * FT_Get_CID_Registry_Ordering_Supplement + * + * @description: + * Retrieve the Registry/Ordering/Supplement triple (also known as the + * "R/O/S") from a CID-keyed font. + * + * @input: + * face :: + * A handle to the input face. + * + * @output: + * registry :: + * The registry, as a C~string, owned by the face. + * + * ordering :: + * The ordering, as a C~string, owned by the face. + * + * supplement :: + * The supplement. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with CID faces, returning an error + * otherwise. + * + * @since: + * 2.3.6 + */ + FT_EXPORT( FT_Error ) + FT_Get_CID_Registry_Ordering_Supplement( FT_Face face, + const char* *registry, + const char* *ordering, + FT_Int *supplement); + + + /********************************************************************** + * + * @function: + * FT_Get_CID_Is_Internally_CID_Keyed + * + * @description: + * Retrieve the type of the input face, CID keyed or not. In + * constrast to the @FT_IS_CID_KEYED macro this function returns + * successfully also for CID-keyed fonts in an SNFT wrapper. + * + * @input: + * face :: + * A handle to the input face. + * + * @output: + * is_cid :: + * The type of the face as an @FT_Bool. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with CID faces and OpenType fonts, + * returning an error otherwise. + * + * @since: + * 2.3.9 + */ + FT_EXPORT( FT_Error ) + FT_Get_CID_Is_Internally_CID_Keyed( FT_Face face, + FT_Bool *is_cid ); + + + /********************************************************************** + * + * @function: + * FT_Get_CID_From_Glyph_Index + * + * @description: + * Retrieve the CID of the input glyph index. + * + * @input: + * face :: + * A handle to the input face. + * + * glyph_index :: + * The input glyph index. + * + * @output: + * cid :: + * The CID as an @FT_UInt. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with CID faces and OpenType fonts, + * returning an error otherwise. + * + * @since: + * 2.3.9 + */ + FT_EXPORT( FT_Error ) + FT_Get_CID_From_Glyph_Index( FT_Face face, + FT_UInt glyph_index, + FT_UInt *cid ); + + /* */ + + +FT_END_HEADER + +#endif /* FTCID_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/fterrdef.h b/android/x86/include/freetype/fterrdef.h new file mode 100644 index 00000000..3f53dd58 --- /dev/null +++ b/android/x86/include/freetype/fterrdef.h @@ -0,0 +1,276 @@ +/***************************************************************************/ +/* */ +/* fterrdef.h */ +/* */ +/* FreeType error codes (specification). */ +/* */ +/* Copyright 2002-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* error_code_values */ + /* */ + /* <Title> */ + /* Error Code Values */ + /* */ + /* <Abstract> */ + /* All possible error codes returned by FreeType functions. */ + /* */ + /* <Description> */ + /* The list below is taken verbatim from the file `fterrdef.h' */ + /* (loaded automatically by including `FT_FREETYPE_H'). The first */ + /* argument of the `FT_ERROR_DEF_' macro is the error label; by */ + /* default, the prefix `FT_Err_' gets added so that you get error */ + /* names like `FT_Err_Cannot_Open_Resource'. The second argument is */ + /* the error code, and the last argument an error string, which is not */ + /* used by FreeType. */ + /* */ + /* Within your application you should *only* use error names and */ + /* *never* its numeric values! The latter might (and actually do) */ + /* change in forthcoming FreeType versions. */ + /* */ + /* Macro `FT_NOERRORDEF_' defines `FT_Err_Ok', which is always zero. */ + /* See the `Error Enumerations' subsection how to automatically */ + /* generate a list of error strings. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Err_XXX */ + /* */ + /*************************************************************************/ + + /* generic errors */ + + FT_NOERRORDEF_( Ok, 0x00, + "no error" ) + + FT_ERRORDEF_( Cannot_Open_Resource, 0x01, + "cannot open resource" ) + FT_ERRORDEF_( Unknown_File_Format, 0x02, + "unknown file format" ) + FT_ERRORDEF_( Invalid_File_Format, 0x03, + "broken file" ) + FT_ERRORDEF_( Invalid_Version, 0x04, + "invalid FreeType version" ) + FT_ERRORDEF_( Lower_Module_Version, 0x05, + "module version is too low" ) + FT_ERRORDEF_( Invalid_Argument, 0x06, + "invalid argument" ) + FT_ERRORDEF_( Unimplemented_Feature, 0x07, + "unimplemented feature" ) + FT_ERRORDEF_( Invalid_Table, 0x08, + "broken table" ) + FT_ERRORDEF_( Invalid_Offset, 0x09, + "broken offset within table" ) + FT_ERRORDEF_( Array_Too_Large, 0x0A, + "array allocation size too large" ) + FT_ERRORDEF_( Missing_Module, 0x0B, + "missing module" ) + FT_ERRORDEF_( Missing_Property, 0x0C, + "missing property" ) + + /* glyph/character errors */ + + FT_ERRORDEF_( Invalid_Glyph_Index, 0x10, + "invalid glyph index" ) + FT_ERRORDEF_( Invalid_Character_Code, 0x11, + "invalid character code" ) + FT_ERRORDEF_( Invalid_Glyph_Format, 0x12, + "unsupported glyph image format" ) + FT_ERRORDEF_( Cannot_Render_Glyph, 0x13, + "cannot render this glyph format" ) + FT_ERRORDEF_( Invalid_Outline, 0x14, + "invalid outline" ) + FT_ERRORDEF_( Invalid_Composite, 0x15, + "invalid composite glyph" ) + FT_ERRORDEF_( Too_Many_Hints, 0x16, + "too many hints" ) + FT_ERRORDEF_( Invalid_Pixel_Size, 0x17, + "invalid pixel size" ) + + /* handle errors */ + + FT_ERRORDEF_( Invalid_Handle, 0x20, + "invalid object handle" ) + FT_ERRORDEF_( Invalid_Library_Handle, 0x21, + "invalid library handle" ) + FT_ERRORDEF_( Invalid_Driver_Handle, 0x22, + "invalid module handle" ) + FT_ERRORDEF_( Invalid_Face_Handle, 0x23, + "invalid face handle" ) + FT_ERRORDEF_( Invalid_Size_Handle, 0x24, + "invalid size handle" ) + FT_ERRORDEF_( Invalid_Slot_Handle, 0x25, + "invalid glyph slot handle" ) + FT_ERRORDEF_( Invalid_CharMap_Handle, 0x26, + "invalid charmap handle" ) + FT_ERRORDEF_( Invalid_Cache_Handle, 0x27, + "invalid cache manager handle" ) + FT_ERRORDEF_( Invalid_Stream_Handle, 0x28, + "invalid stream handle" ) + + /* driver errors */ + + FT_ERRORDEF_( Too_Many_Drivers, 0x30, + "too many modules" ) + FT_ERRORDEF_( Too_Many_Extensions, 0x31, + "too many extensions" ) + + /* memory errors */ + + FT_ERRORDEF_( Out_Of_Memory, 0x40, + "out of memory" ) + FT_ERRORDEF_( Unlisted_Object, 0x41, + "unlisted object" ) + + /* stream errors */ + + FT_ERRORDEF_( Cannot_Open_Stream, 0x51, + "cannot open stream" ) + FT_ERRORDEF_( Invalid_Stream_Seek, 0x52, + "invalid stream seek" ) + FT_ERRORDEF_( Invalid_Stream_Skip, 0x53, + "invalid stream skip" ) + FT_ERRORDEF_( Invalid_Stream_Read, 0x54, + "invalid stream read" ) + FT_ERRORDEF_( Invalid_Stream_Operation, 0x55, + "invalid stream operation" ) + FT_ERRORDEF_( Invalid_Frame_Operation, 0x56, + "invalid frame operation" ) + FT_ERRORDEF_( Nested_Frame_Access, 0x57, + "nested frame access" ) + FT_ERRORDEF_( Invalid_Frame_Read, 0x58, + "invalid frame read" ) + + /* raster errors */ + + FT_ERRORDEF_( Raster_Uninitialized, 0x60, + "raster uninitialized" ) + FT_ERRORDEF_( Raster_Corrupted, 0x61, + "raster corrupted" ) + FT_ERRORDEF_( Raster_Overflow, 0x62, + "raster overflow" ) + FT_ERRORDEF_( Raster_Negative_Height, 0x63, + "negative height while rastering" ) + + /* cache errors */ + + FT_ERRORDEF_( Too_Many_Caches, 0x70, + "too many registered caches" ) + + /* TrueType and SFNT errors */ + + FT_ERRORDEF_( Invalid_Opcode, 0x80, + "invalid opcode" ) + FT_ERRORDEF_( Too_Few_Arguments, 0x81, + "too few arguments" ) + FT_ERRORDEF_( Stack_Overflow, 0x82, + "stack overflow" ) + FT_ERRORDEF_( Code_Overflow, 0x83, + "code overflow" ) + FT_ERRORDEF_( Bad_Argument, 0x84, + "bad argument" ) + FT_ERRORDEF_( Divide_By_Zero, 0x85, + "division by zero" ) + FT_ERRORDEF_( Invalid_Reference, 0x86, + "invalid reference" ) + FT_ERRORDEF_( Debug_OpCode, 0x87, + "found debug opcode" ) + FT_ERRORDEF_( ENDF_In_Exec_Stream, 0x88, + "found ENDF opcode in execution stream" ) + FT_ERRORDEF_( Nested_DEFS, 0x89, + "nested DEFS" ) + FT_ERRORDEF_( Invalid_CodeRange, 0x8A, + "invalid code range" ) + FT_ERRORDEF_( Execution_Too_Long, 0x8B, + "execution context too long" ) + FT_ERRORDEF_( Too_Many_Function_Defs, 0x8C, + "too many function definitions" ) + FT_ERRORDEF_( Too_Many_Instruction_Defs, 0x8D, + "too many instruction definitions" ) + FT_ERRORDEF_( Table_Missing, 0x8E, + "SFNT font table missing" ) + FT_ERRORDEF_( Horiz_Header_Missing, 0x8F, + "horizontal header (hhea) table missing" ) + FT_ERRORDEF_( Locations_Missing, 0x90, + "locations (loca) table missing" ) + FT_ERRORDEF_( Name_Table_Missing, 0x91, + "name table missing" ) + FT_ERRORDEF_( CMap_Table_Missing, 0x92, + "character map (cmap) table missing" ) + FT_ERRORDEF_( Hmtx_Table_Missing, 0x93, + "horizontal metrics (hmtx) table missing" ) + FT_ERRORDEF_( Post_Table_Missing, 0x94, + "PostScript (post) table missing" ) + FT_ERRORDEF_( Invalid_Horiz_Metrics, 0x95, + "invalid horizontal metrics" ) + FT_ERRORDEF_( Invalid_CharMap_Format, 0x96, + "invalid character map (cmap) format" ) + FT_ERRORDEF_( Invalid_PPem, 0x97, + "invalid ppem value" ) + FT_ERRORDEF_( Invalid_Vert_Metrics, 0x98, + "invalid vertical metrics" ) + FT_ERRORDEF_( Could_Not_Find_Context, 0x99, + "could not find context" ) + FT_ERRORDEF_( Invalid_Post_Table_Format, 0x9A, + "invalid PostScript (post) table format" ) + FT_ERRORDEF_( Invalid_Post_Table, 0x9B, + "invalid PostScript (post) table" ) + + /* CFF, CID, and Type 1 errors */ + + FT_ERRORDEF_( Syntax_Error, 0xA0, + "opcode syntax error" ) + FT_ERRORDEF_( Stack_Underflow, 0xA1, + "argument stack underflow" ) + FT_ERRORDEF_( Ignore, 0xA2, + "ignore" ) + FT_ERRORDEF_( No_Unicode_Glyph_Name, 0xA3, + "no Unicode glyph name found" ) + FT_ERRORDEF_( Glyph_Too_Big, 0xA4, + "glyph too big for hinting" ) + + /* BDF errors */ + + FT_ERRORDEF_( Missing_Startfont_Field, 0xB0, + "`STARTFONT' field missing" ) + FT_ERRORDEF_( Missing_Font_Field, 0xB1, + "`FONT' field missing" ) + FT_ERRORDEF_( Missing_Size_Field, 0xB2, + "`SIZE' field missing" ) + FT_ERRORDEF_( Missing_Fontboundingbox_Field, 0xB3, + "`FONTBOUNDINGBOX' field missing" ) + FT_ERRORDEF_( Missing_Chars_Field, 0xB4, + "`CHARS' field missing" ) + FT_ERRORDEF_( Missing_Startchar_Field, 0xB5, + "`STARTCHAR' field missing" ) + FT_ERRORDEF_( Missing_Encoding_Field, 0xB6, + "`ENCODING' field missing" ) + FT_ERRORDEF_( Missing_Bbx_Field, 0xB7, + "`BBX' field missing" ) + FT_ERRORDEF_( Bbx_Too_Big, 0xB8, + "`BBX' too big" ) + FT_ERRORDEF_( Corrupted_Font_Header, 0xB9, + "Font header corrupted or missing fields" ) + FT_ERRORDEF_( Corrupted_Font_Glyphs, 0xBA, + "Font glyphs corrupted or missing fields" ) + + /* */ + + +/* END */ diff --git a/android/x86/include/freetype/fterrors.h b/android/x86/include/freetype/fterrors.h new file mode 100644 index 00000000..e15bfb00 --- /dev/null +++ b/android/x86/include/freetype/fterrors.h @@ -0,0 +1,226 @@ +/***************************************************************************/ +/* */ +/* fterrors.h */ +/* */ +/* FreeType error code handling (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* error_enumerations */ + /* */ + /* <Title> */ + /* Error Enumerations */ + /* */ + /* <Abstract> */ + /* How to handle errors and error strings. */ + /* */ + /* <Description> */ + /* The header file `fterrors.h' (which is automatically included by */ + /* `freetype.h' defines the handling of FreeType's enumeration */ + /* constants. It can also be used to generate error message strings */ + /* with a small macro trick explained below. */ + /* */ + /* *Error* *Formats* */ + /* */ + /* The configuration macro FT_CONFIG_OPTION_USE_MODULE_ERRORS can be */ + /* defined in `ftoption.h' in order to make the higher byte indicate */ + /* the module where the error has happened (this is not compatible */ + /* with standard builds of FreeType 2, however). See the file */ + /* `ftmoderr.h' for more details. */ + /* */ + /* *Error* *Message* *Strings* */ + /* */ + /* Error definitions are set up with special macros that allow client */ + /* applications to build a table of error message strings. The */ + /* strings are not included in a normal build of FreeType 2 to */ + /* save space (most client applications do not use them). */ + /* */ + /* To do so, you have to define the following macros before including */ + /* this file. */ + /* */ + /* { */ + /* FT_ERROR_START_LIST */ + /* } */ + /* */ + /* This macro is called before anything else to define the start of */ + /* the error list. It is followed by several FT_ERROR_DEF calls. */ + /* */ + /* { */ + /* FT_ERROR_DEF( e, v, s ) */ + /* } */ + /* */ + /* This macro is called to define one single error. `e' is the error */ + /* code identifier (e.g., `Invalid_Argument'), `v' is the error's */ + /* numerical value, and `s' is the corresponding error string. */ + /* */ + /* { */ + /* FT_ERROR_END_LIST */ + /* } */ + /* */ + /* This macro ends the list. */ + /* */ + /* Additionally, you have to undefine `FTERRORS_H_' before #including */ + /* this file. */ + /* */ + /* Here is a simple example. */ + /* */ + /* { */ + /* #undef FTERRORS_H_ */ + /* #define FT_ERRORDEF( e, v, s ) { e, s }, */ + /* #define FT_ERROR_START_LIST { */ + /* #define FT_ERROR_END_LIST { 0, NULL } }; */ + /* */ + /* const struct */ + /* { */ + /* int err_code; */ + /* const char* err_msg; */ + /* } ft_errors[] = */ + /* */ + /* #include FT_ERRORS_H */ + /* } */ + /* */ + /* Note that `FT_Err_Ok' is _not_ defined with `FT_ERRORDEF' but with */ + /* `FT_NOERRORDEF'; it is always zero. */ + /* */ + /*************************************************************************/ + + /* */ + + /* In previous FreeType versions we used `__FTERRORS_H__'. However, */ + /* using two successive underscores in a non-system symbol name */ + /* violates the C (and C++) standard, so it was changed to the */ + /* current form. In spite of this, we have to make */ + /* */ + /* #undefine __FTERRORS_H__ */ + /* */ + /* work for backwards compatibility. */ + /* */ +#if !( defined( FTERRORS_H_ ) && defined ( __FTERRORS_H__ ) ) +#define FTERRORS_H_ +#define __FTERRORS_H__ + + + /* include module base error codes */ +#include FT_MODULE_ERRORS_H + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** SETUP MACROS *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + + +#undef FT_NEED_EXTERN_C + + + /* FT_ERR_PREFIX is used as a prefix for error identifiers. */ + /* By default, we use `FT_Err_'. */ + /* */ +#ifndef FT_ERR_PREFIX +#define FT_ERR_PREFIX FT_Err_ +#endif + + + /* FT_ERR_BASE is used as the base for module-specific errors. */ + /* */ +#ifdef FT_CONFIG_OPTION_USE_MODULE_ERRORS + +#ifndef FT_ERR_BASE +#define FT_ERR_BASE FT_Mod_Err_Base +#endif + +#else + +#undef FT_ERR_BASE +#define FT_ERR_BASE 0 + +#endif /* FT_CONFIG_OPTION_USE_MODULE_ERRORS */ + + + /* If FT_ERRORDEF is not defined, we need to define a simple */ + /* enumeration type. */ + /* */ +#ifndef FT_ERRORDEF + +#define FT_ERRORDEF( e, v, s ) e = v, +#define FT_ERROR_START_LIST enum { +#define FT_ERROR_END_LIST FT_ERR_CAT( FT_ERR_PREFIX, Max ) }; + +#ifdef __cplusplus +#define FT_NEED_EXTERN_C + extern "C" { +#endif + +#endif /* !FT_ERRORDEF */ + + + /* this macro is used to define an error */ +#define FT_ERRORDEF_( e, v, s ) \ + FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v + FT_ERR_BASE, s ) + + /* this is only used for <module>_Err_Ok, which must be 0! */ +#define FT_NOERRORDEF_( e, v, s ) \ + FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v, s ) + + +#ifdef FT_ERROR_START_LIST + FT_ERROR_START_LIST +#endif + + + /* now include the error codes */ +#include FT_ERROR_DEFINITIONS_H + + +#ifdef FT_ERROR_END_LIST + FT_ERROR_END_LIST +#endif + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** SIMPLE CLEANUP *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + +#ifdef FT_NEED_EXTERN_C + } +#endif + +#undef FT_ERROR_START_LIST +#undef FT_ERROR_END_LIST + +#undef FT_ERRORDEF +#undef FT_ERRORDEF_ +#undef FT_NOERRORDEF_ + +#undef FT_NEED_EXTERN_C +#undef FT_ERR_BASE + + /* FT_ERR_PREFIX is needed internally */ +#ifndef FT2_BUILD_LIBRARY +#undef FT_ERR_PREFIX +#endif + +#endif /* !(FTERRORS_H_ && __FTERRORS_H__) */ + + +/* END */ diff --git a/android/x86/include/freetype/ftfntfmt.h b/android/x86/include/freetype/ftfntfmt.h new file mode 100644 index 00000000..bd423247 --- /dev/null +++ b/android/x86/include/freetype/ftfntfmt.h @@ -0,0 +1,95 @@ +/***************************************************************************/ +/* */ +/* ftfntfmt.h */ +/* */ +/* Support functions for font formats. */ +/* */ +/* Copyright 2002-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTFNTFMT_H_ +#define FTFNTFMT_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* font_formats */ + /* */ + /* <Title> */ + /* Font Formats */ + /* */ + /* <Abstract> */ + /* Getting the font format. */ + /* */ + /* <Description> */ + /* The single function in this section can be used to get the font */ + /* format. Note that this information is not needed normally; */ + /* however, there are special cases (like in PDF devices) where it is */ + /* important to differentiate, in spite of FreeType's uniform API. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Font_Format */ + /* */ + /* <Description> */ + /* Return a string describing the format of a given face. Possible */ + /* values are `TrueType', `Type~1', `BDF', `PCF', `Type~42', */ + /* `CID~Type~1', `CFF', `PFR', and `Windows~FNT'. */ + /* */ + /* The return value is suitable to be used as an X11 FONT_PROPERTY. */ + /* */ + /* <Input> */ + /* face :: */ + /* Input face handle. */ + /* */ + /* <Return> */ + /* Font format string. NULL in case of error. */ + /* */ + /* <Note> */ + /* A deprecated name for the same function is */ + /* `FT_Get_X11_Font_Format'. */ + /* */ + FT_EXPORT( const char* ) + FT_Get_Font_Format( FT_Face face ); + + + /* deprecated */ + FT_EXPORT( const char* ) + FT_Get_X11_Font_Format( FT_Face face ); + + + /* */ + + +FT_END_HEADER + +#endif /* FTFNTFMT_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftgasp.h b/android/x86/include/freetype/ftgasp.h new file mode 100644 index 00000000..3f5b3bc6 --- /dev/null +++ b/android/x86/include/freetype/ftgasp.h @@ -0,0 +1,129 @@ +/***************************************************************************/ +/* */ +/* ftgasp.h */ +/* */ +/* Access of TrueType's `gasp' table (specification). */ +/* */ +/* Copyright 2007-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTGASP_H_ +#define FTGASP_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + + /*************************************************************************** + * + * @section: + * gasp_table + * + * @title: + * Gasp Table + * + * @abstract: + * Retrieving TrueType `gasp' table entries. + * + * @description: + * The function @FT_Get_Gasp can be used to query a TrueType or OpenType + * font for specific entries in its `gasp' table, if any. This is + * mainly useful when implementing native TrueType hinting with the + * bytecode interpreter to duplicate the Windows text rendering results. + */ + + /************************************************************************* + * + * @enum: + * FT_GASP_XXX + * + * @description: + * A list of values and/or bit-flags returned by the @FT_Get_Gasp + * function. + * + * @values: + * FT_GASP_NO_TABLE :: + * This special value means that there is no GASP table in this face. + * It is up to the client to decide what to do. + * + * FT_GASP_DO_GRIDFIT :: + * Grid-fitting and hinting should be performed at the specified ppem. + * This *really* means TrueType bytecode interpretation. If this bit + * is not set, no hinting gets applied. + * + * FT_GASP_DO_GRAY :: + * Anti-aliased rendering should be performed at the specified ppem. + * If not set, do monochrome rendering. + * + * FT_GASP_SYMMETRIC_SMOOTHING :: + * If set, smoothing along multiple axes must be used with ClearType. + * + * FT_GASP_SYMMETRIC_GRIDFIT :: + * Grid-fitting must be used with ClearType's symmetric smoothing. + * + * @note: + * The bit-flags `FT_GASP_DO_GRIDFIT' and `FT_GASP_DO_GRAY' are to be + * used for standard font rasterization only. Independently of that, + * `FT_GASP_SYMMETRIC_SMOOTHING' and `FT_GASP_SYMMETRIC_GRIDFIT' are to + * be used if ClearType is enabled (and `FT_GASP_DO_GRIDFIT' and + * `FT_GASP_DO_GRAY' are consequently ignored). + * + * `ClearType' is Microsoft's implementation of LCD rendering, partly + * protected by patents. + * + * @since: + * 2.3.0 + */ +#define FT_GASP_NO_TABLE -1 +#define FT_GASP_DO_GRIDFIT 0x01 +#define FT_GASP_DO_GRAY 0x02 +#define FT_GASP_SYMMETRIC_SMOOTHING 0x08 +#define FT_GASP_SYMMETRIC_GRIDFIT 0x10 + + + /************************************************************************* + * + * @func: + * FT_Get_Gasp + * + * @description: + * Read the `gasp' table from a TrueType or OpenType font file and + * return the entry corresponding to a given character pixel size. + * + * @input: + * face :: The source face handle. + * ppem :: The vertical character pixel size. + * + * @return: + * Bit flags (see @FT_GASP_XXX), or @FT_GASP_NO_TABLE if there is no + * `gasp' table in the face. + * + * @since: + * 2.3.0 + */ + FT_EXPORT( FT_Int ) + FT_Get_Gasp( FT_Face face, + FT_UInt ppem ); + + /* */ + + +#endif /* FTGASP_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftglyph.h b/android/x86/include/freetype/ftglyph.h new file mode 100644 index 00000000..d9840a81 --- /dev/null +++ b/android/x86/include/freetype/ftglyph.h @@ -0,0 +1,605 @@ +/***************************************************************************/ +/* */ +/* ftglyph.h */ +/* */ +/* FreeType convenience functions to handle glyphs (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This file contains the definition of several convenience functions */ + /* that can be used by client applications to easily retrieve glyph */ + /* bitmaps and outlines from a given face. */ + /* */ + /* These functions should be optional if you are writing a font server */ + /* or text layout engine on top of FreeType. However, they are pretty */ + /* handy for many other simple uses of the library. */ + /* */ + /*************************************************************************/ + + +#ifndef FTGLYPH_H_ +#define FTGLYPH_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* glyph_management */ + /* */ + /* <Title> */ + /* Glyph Management */ + /* */ + /* <Abstract> */ + /* Generic interface to manage individual glyph data. */ + /* */ + /* <Description> */ + /* This section contains definitions used to manage glyph data */ + /* through generic FT_Glyph objects. Each of them can contain a */ + /* bitmap, a vector outline, or even images in other formats. */ + /* */ + /*************************************************************************/ + + + /* forward declaration to a private type */ + typedef struct FT_Glyph_Class_ FT_Glyph_Class; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Glyph */ + /* */ + /* <Description> */ + /* Handle to an object used to model generic glyph images. It is a */ + /* pointer to the @FT_GlyphRec structure and can contain a glyph */ + /* bitmap or pointer. */ + /* */ + /* <Note> */ + /* Glyph objects are not owned by the library. You must thus release */ + /* them manually (through @FT_Done_Glyph) _before_ calling */ + /* @FT_Done_FreeType. */ + /* */ + typedef struct FT_GlyphRec_* FT_Glyph; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_GlyphRec */ + /* */ + /* <Description> */ + /* The root glyph structure contains a given glyph image plus its */ + /* advance width in 16.16 fixed-point format. */ + /* */ + /* <Fields> */ + /* library :: A handle to the FreeType library object. */ + /* */ + /* clazz :: A pointer to the glyph's class. Private. */ + /* */ + /* format :: The format of the glyph's image. */ + /* */ + /* advance :: A 16.16 vector that gives the glyph's advance width. */ + /* */ + typedef struct FT_GlyphRec_ + { + FT_Library library; + const FT_Glyph_Class* clazz; + FT_Glyph_Format format; + FT_Vector advance; + + } FT_GlyphRec; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_BitmapGlyph */ + /* */ + /* <Description> */ + /* A handle to an object used to model a bitmap glyph image. This is */ + /* a sub-class of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec. */ + /* */ + typedef struct FT_BitmapGlyphRec_* FT_BitmapGlyph; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_BitmapGlyphRec */ + /* */ + /* <Description> */ + /* A structure used for bitmap glyph images. This really is a */ + /* `sub-class' of @FT_GlyphRec. */ + /* */ + /* <Fields> */ + /* root :: The root @FT_Glyph fields. */ + /* */ + /* left :: The left-side bearing, i.e., the horizontal distance */ + /* from the current pen position to the left border of the */ + /* glyph bitmap. */ + /* */ + /* top :: The top-side bearing, i.e., the vertical distance from */ + /* the current pen position to the top border of the glyph */ + /* bitmap. This distance is positive for upwards~y! */ + /* */ + /* bitmap :: A descriptor for the bitmap. */ + /* */ + /* <Note> */ + /* You can typecast an @FT_Glyph to @FT_BitmapGlyph if you have */ + /* `glyph->format == FT_GLYPH_FORMAT_BITMAP'. This lets you access */ + /* the bitmap's contents easily. */ + /* */ + /* The corresponding pixel buffer is always owned by @FT_BitmapGlyph */ + /* and is thus created and destroyed with it. */ + /* */ + typedef struct FT_BitmapGlyphRec_ + { + FT_GlyphRec root; + FT_Int left; + FT_Int top; + FT_Bitmap bitmap; + + } FT_BitmapGlyphRec; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_OutlineGlyph */ + /* */ + /* <Description> */ + /* A handle to an object used to model an outline glyph image. This */ + /* is a sub-class of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec. */ + /* */ + typedef struct FT_OutlineGlyphRec_* FT_OutlineGlyph; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_OutlineGlyphRec */ + /* */ + /* <Description> */ + /* A structure used for outline (vectorial) glyph images. This */ + /* really is a `sub-class' of @FT_GlyphRec. */ + /* */ + /* <Fields> */ + /* root :: The root @FT_Glyph fields. */ + /* */ + /* outline :: A descriptor for the outline. */ + /* */ + /* <Note> */ + /* You can typecast an @FT_Glyph to @FT_OutlineGlyph if you have */ + /* `glyph->format == FT_GLYPH_FORMAT_OUTLINE'. This lets you access */ + /* the outline's content easily. */ + /* */ + /* As the outline is extracted from a glyph slot, its coordinates are */ + /* expressed normally in 26.6 pixels, unless the flag */ + /* @FT_LOAD_NO_SCALE was used in @FT_Load_Glyph() or @FT_Load_Char(). */ + /* */ + /* The outline's tables are always owned by the object and are */ + /* destroyed with it. */ + /* */ + typedef struct FT_OutlineGlyphRec_ + { + FT_GlyphRec root; + FT_Outline outline; + + } FT_OutlineGlyphRec; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Glyph */ + /* */ + /* <Description> */ + /* A function used to extract a glyph image from a slot. Note that */ + /* the created @FT_Glyph object must be released with @FT_Done_Glyph. */ + /* */ + /* <Input> */ + /* slot :: A handle to the source glyph slot. */ + /* */ + /* <Output> */ + /* aglyph :: A handle to the glyph object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Glyph( FT_GlyphSlot slot, + FT_Glyph *aglyph ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Glyph_Copy */ + /* */ + /* <Description> */ + /* A function used to copy a glyph image. Note that the created */ + /* @FT_Glyph object must be released with @FT_Done_Glyph. */ + /* */ + /* <Input> */ + /* source :: A handle to the source glyph object. */ + /* */ + /* <Output> */ + /* target :: A handle to the target glyph object. 0~in case of */ + /* error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Glyph_Copy( FT_Glyph source, + FT_Glyph *target ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Glyph_Transform */ + /* */ + /* <Description> */ + /* Transform a glyph image if its format is scalable. */ + /* */ + /* <InOut> */ + /* glyph :: A handle to the target glyph object. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to a 2x2 matrix to apply. */ + /* */ + /* delta :: A pointer to a 2d vector to apply. Coordinates are */ + /* expressed in 1/64th of a pixel. */ + /* */ + /* <Return> */ + /* FreeType error code (if not 0, the glyph format is not scalable). */ + /* */ + /* <Note> */ + /* The 2x2 transformation matrix is also applied to the glyph's */ + /* advance vector. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Glyph_Transform( FT_Glyph glyph, + FT_Matrix* matrix, + FT_Vector* delta ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Glyph_BBox_Mode */ + /* */ + /* <Description> */ + /* The mode how the values of @FT_Glyph_Get_CBox are returned. */ + /* */ + /* <Values> */ + /* FT_GLYPH_BBOX_UNSCALED :: */ + /* Return unscaled font units. */ + /* */ + /* FT_GLYPH_BBOX_SUBPIXELS :: */ + /* Return unfitted 26.6 coordinates. */ + /* */ + /* FT_GLYPH_BBOX_GRIDFIT :: */ + /* Return grid-fitted 26.6 coordinates. */ + /* */ + /* FT_GLYPH_BBOX_TRUNCATE :: */ + /* Return coordinates in integer pixels. */ + /* */ + /* FT_GLYPH_BBOX_PIXELS :: */ + /* Return grid-fitted pixel coordinates. */ + /* */ + typedef enum FT_Glyph_BBox_Mode_ + { + FT_GLYPH_BBOX_UNSCALED = 0, + FT_GLYPH_BBOX_SUBPIXELS = 0, + FT_GLYPH_BBOX_GRIDFIT = 1, + FT_GLYPH_BBOX_TRUNCATE = 2, + FT_GLYPH_BBOX_PIXELS = 3 + + } FT_Glyph_BBox_Mode; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Glyph_BBox_Mode' values instead */ +#define ft_glyph_bbox_unscaled FT_GLYPH_BBOX_UNSCALED +#define ft_glyph_bbox_subpixels FT_GLYPH_BBOX_SUBPIXELS +#define ft_glyph_bbox_gridfit FT_GLYPH_BBOX_GRIDFIT +#define ft_glyph_bbox_truncate FT_GLYPH_BBOX_TRUNCATE +#define ft_glyph_bbox_pixels FT_GLYPH_BBOX_PIXELS + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Glyph_Get_CBox */ + /* */ + /* <Description> */ + /* Return a glyph's `control box'. The control box encloses all the */ + /* outline's points, including Bézier control points. Though it */ + /* coincides with the exact bounding box for most glyphs, it can be */ + /* slightly larger in some situations (like when rotating an outline */ + /* that contains Bézier outside arcs). */ + /* */ + /* Computing the control box is very fast, while getting the bounding */ + /* box can take much more time as it needs to walk over all segments */ + /* and arcs in the outline. To get the latter, you can use the */ + /* `ftbbox' component, which is dedicated to this single task. */ + /* */ + /* <Input> */ + /* glyph :: A handle to the source glyph object. */ + /* */ + /* mode :: The mode that indicates how to interpret the returned */ + /* bounding box values. */ + /* */ + /* <Output> */ + /* acbox :: The glyph coordinate bounding box. Coordinates are */ + /* expressed in 1/64th of pixels if it is grid-fitted. */ + /* */ + /* <Note> */ + /* Coordinates are relative to the glyph origin, using the y~upwards */ + /* convention. */ + /* */ + /* If the glyph has been loaded with @FT_LOAD_NO_SCALE, `bbox_mode' */ + /* must be set to @FT_GLYPH_BBOX_UNSCALED to get unscaled font */ + /* units in 26.6 pixel format. The value @FT_GLYPH_BBOX_SUBPIXELS */ + /* is another name for this constant. */ + /* */ + /* If the font is tricky and the glyph has been loaded with */ + /* @FT_LOAD_NO_SCALE, the resulting CBox is meaningless. To get */ + /* reasonable values for the CBox it is necessary to load the glyph */ + /* at a large ppem value (so that the hinting instructions can */ + /* properly shift and scale the subglyphs), then extracting the CBox, */ + /* which can be eventually converted back to font units. */ + /* */ + /* Note that the maximum coordinates are exclusive, which means that */ + /* one can compute the width and height of the glyph image (be it in */ + /* integer or 26.6 pixels) as: */ + /* */ + /* { */ + /* width = bbox.xMax - bbox.xMin; */ + /* height = bbox.yMax - bbox.yMin; */ + /* } */ + /* */ + /* Note also that for 26.6 coordinates, if `bbox_mode' is set to */ + /* @FT_GLYPH_BBOX_GRIDFIT, the coordinates will also be grid-fitted, */ + /* which corresponds to: */ + /* */ + /* { */ + /* bbox.xMin = FLOOR(bbox.xMin); */ + /* bbox.yMin = FLOOR(bbox.yMin); */ + /* bbox.xMax = CEILING(bbox.xMax); */ + /* bbox.yMax = CEILING(bbox.yMax); */ + /* } */ + /* */ + /* To get the bbox in pixel coordinates, set `bbox_mode' to */ + /* @FT_GLYPH_BBOX_TRUNCATE. */ + /* */ + /* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode' */ + /* to @FT_GLYPH_BBOX_PIXELS. */ + /* */ + FT_EXPORT( void ) + FT_Glyph_Get_CBox( FT_Glyph glyph, + FT_UInt bbox_mode, + FT_BBox *acbox ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Glyph_To_Bitmap */ + /* */ + /* <Description> */ + /* Convert a given glyph object to a bitmap glyph object. */ + /* */ + /* <InOut> */ + /* the_glyph :: A pointer to a handle to the target glyph. */ + /* */ + /* <Input> */ + /* render_mode :: An enumeration that describes how the data is */ + /* rendered. */ + /* */ + /* origin :: A pointer to a vector used to translate the glyph */ + /* image before rendering. Can be~0 (if no */ + /* translation). The origin is expressed in */ + /* 26.6 pixels. */ + /* */ + /* destroy :: A boolean that indicates that the original glyph */ + /* image should be destroyed by this function. It is */ + /* never destroyed in case of error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function does nothing if the glyph format isn't scalable. */ + /* */ + /* The glyph image is translated with the `origin' vector before */ + /* rendering. */ + /* */ + /* The first parameter is a pointer to an @FT_Glyph handle, that will */ + /* be _replaced_ by this function (with newly allocated data). */ + /* Typically, you would use (omitting error handling): */ + /* */ + /* */ + /* { */ + /* FT_Glyph glyph; */ + /* FT_BitmapGlyph glyph_bitmap; */ + /* */ + /* */ + /* // load glyph */ + /* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); */ + /* */ + /* // extract glyph image */ + /* error = FT_Get_Glyph( face->glyph, &glyph ); */ + /* */ + /* // convert to a bitmap (default render mode + destroying old) */ + /* if ( glyph->format != FT_GLYPH_FORMAT_BITMAP ) */ + /* { */ + /* error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, */ + /* 0, 1 ); */ + /* if ( error ) // `glyph' unchanged */ + /* ... */ + /* } */ + /* */ + /* // access bitmap content by typecasting */ + /* glyph_bitmap = (FT_BitmapGlyph)glyph; */ + /* */ + /* // do funny stuff with it, like blitting/drawing */ + /* ... */ + /* */ + /* // discard glyph image (bitmap or not) */ + /* FT_Done_Glyph( glyph ); */ + /* } */ + /* */ + /* */ + /* Here another example, again without error handling: */ + /* */ + /* */ + /* { */ + /* FT_Glyph glyphs[MAX_GLYPHS] */ + /* */ + /* */ + /* ... */ + /* */ + /* for ( idx = 0; i < MAX_GLYPHS; i++ ) */ + /* error = FT_Load_Glyph( face, idx, FT_LOAD_DEFAULT ) || */ + /* FT_Get_Glyph ( face->glyph, &glyph[idx] ); */ + /* */ + /* ... */ + /* */ + /* for ( idx = 0; i < MAX_GLYPHS; i++ ) */ + /* { */ + /* FT_Glyph bitmap = glyphs[idx]; */ + /* */ + /* */ + /* ... */ + /* */ + /* // after this call, `bitmap' no longer points into */ + /* // the `glyphs' array (and the old value isn't destroyed) */ + /* FT_Glyph_To_Bitmap( &bitmap, FT_RENDER_MODE_MONO, 0, 0 ); */ + /* */ + /* ... */ + /* */ + /* FT_Done_Glyph( bitmap ); */ + /* } */ + /* */ + /* ... */ + /* */ + /* for ( idx = 0; i < MAX_GLYPHS; i++ ) */ + /* FT_Done_Glyph( glyphs[idx] ); */ + /* } */ + /* */ + FT_EXPORT( FT_Error ) + FT_Glyph_To_Bitmap( FT_Glyph* the_glyph, + FT_Render_Mode render_mode, + FT_Vector* origin, + FT_Bool destroy ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_Glyph */ + /* */ + /* <Description> */ + /* Destroy a given glyph. */ + /* */ + /* <Input> */ + /* glyph :: A handle to the target glyph object. */ + /* */ + FT_EXPORT( void ) + FT_Done_Glyph( FT_Glyph glyph ); + + /* */ + + + /* other helpful functions */ + + /*************************************************************************/ + /* */ + /* <Section> */ + /* computations */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Matrix_Multiply */ + /* */ + /* <Description> */ + /* Perform the matrix operation `b = a*b'. */ + /* */ + /* <Input> */ + /* a :: A pointer to matrix `a'. */ + /* */ + /* <InOut> */ + /* b :: A pointer to matrix `b'. */ + /* */ + /* <Note> */ + /* The result is undefined if either `a' or `b' is zero. */ + /* */ + FT_EXPORT( void ) + FT_Matrix_Multiply( const FT_Matrix* a, + FT_Matrix* b ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Matrix_Invert */ + /* */ + /* <Description> */ + /* Invert a 2x2 matrix. Return an error if it can't be inverted. */ + /* */ + /* <InOut> */ + /* matrix :: A pointer to the target matrix. Remains untouched in */ + /* case of error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Matrix_Invert( FT_Matrix* matrix ); + + /* */ + + +FT_END_HEADER + +#endif /* FTGLYPH_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/android/x86/include/freetype/ftgxval.h b/android/x86/include/freetype/ftgxval.h new file mode 100644 index 00000000..a58e86a0 --- /dev/null +++ b/android/x86/include/freetype/ftgxval.h @@ -0,0 +1,357 @@ +/***************************************************************************/ +/* */ +/* ftgxval.h */ +/* */ +/* FreeType API for validating TrueTypeGX/AAT tables (specification). */ +/* */ +/* Copyright 2004-2016 by */ +/* Masatake YAMATO, Redhat K.K, */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/***************************************************************************/ +/* */ +/* gxvalid is derived from both gxlayout module and otvalid module. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ +/***************************************************************************/ + + +#ifndef FTGXVAL_H_ +#define FTGXVAL_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* gx_validation */ + /* */ + /* <Title> */ + /* TrueTypeGX/AAT Validation */ + /* */ + /* <Abstract> */ + /* An API to validate TrueTypeGX/AAT tables. */ + /* */ + /* <Description> */ + /* This section contains the declaration of functions to validate */ + /* some TrueTypeGX tables (feat, mort, morx, bsln, just, kern, opbd, */ + /* trak, prop, lcar). */ + /* */ + /* <Order> */ + /* FT_TrueTypeGX_Validate */ + /* FT_TrueTypeGX_Free */ + /* */ + /* FT_ClassicKern_Validate */ + /* FT_ClassicKern_Free */ + /* */ + /* FT_VALIDATE_GX_LENGTH */ + /* FT_VALIDATE_GXXXX */ + /* FT_VALIDATE_CKERNXXX */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* */ + /* Warning: Use FT_VALIDATE_XXX to validate a table. */ + /* Following definitions are for gxvalid developers. */ + /* */ + /* */ + /*************************************************************************/ + +#define FT_VALIDATE_feat_INDEX 0 +#define FT_VALIDATE_mort_INDEX 1 +#define FT_VALIDATE_morx_INDEX 2 +#define FT_VALIDATE_bsln_INDEX 3 +#define FT_VALIDATE_just_INDEX 4 +#define FT_VALIDATE_kern_INDEX 5 +#define FT_VALIDATE_opbd_INDEX 6 +#define FT_VALIDATE_trak_INDEX 7 +#define FT_VALIDATE_prop_INDEX 8 +#define FT_VALIDATE_lcar_INDEX 9 +#define FT_VALIDATE_GX_LAST_INDEX FT_VALIDATE_lcar_INDEX + + + /************************************************************************* + * + * @macro: + * FT_VALIDATE_GX_LENGTH + * + * @description: + * The number of tables checked in this module. Use it as a parameter + * for the `table-length' argument of function @FT_TrueTypeGX_Validate. + */ +#define FT_VALIDATE_GX_LENGTH (FT_VALIDATE_GX_LAST_INDEX + 1) + + /* */ + + /* Up to 0x1000 is used by otvalid. + Ox2xxx is reserved for feature OT extension. */ +#define FT_VALIDATE_GX_START 0x4000 +#define FT_VALIDATE_GX_BITFIELD( tag ) \ + ( FT_VALIDATE_GX_START << FT_VALIDATE_##tag##_INDEX ) + + + /********************************************************************** + * + * @enum: + * FT_VALIDATE_GXXXX + * + * @description: + * A list of bit-field constants used with @FT_TrueTypeGX_Validate to + * indicate which TrueTypeGX/AAT Type tables should be validated. + * + * @values: + * FT_VALIDATE_feat :: + * Validate `feat' table. + * + * FT_VALIDATE_mort :: + * Validate `mort' table. + * + * FT_VALIDATE_morx :: + * Validate `morx' table. + * + * FT_VALIDATE_bsln :: + * Validate `bsln' table. + * + * FT_VALIDATE_just :: + * Validate `just' table. + * + * FT_VALIDATE_kern :: + * Validate `kern' table. + * + * FT_VALIDATE_opbd :: + * Validate `opbd' table. + * + * FT_VALIDATE_trak :: + * Validate `trak' table. + * + * FT_VALIDATE_prop :: + * Validate `prop' table. + * + * FT_VALIDATE_lcar :: + * Validate `lcar' table. + * + * FT_VALIDATE_GX :: + * Validate all TrueTypeGX tables (feat, mort, morx, bsln, just, kern, + * opbd, trak, prop and lcar). + * + */ + +#define FT_VALIDATE_feat FT_VALIDATE_GX_BITFIELD( feat ) +#define FT_VALIDATE_mort FT_VALIDATE_GX_BITFIELD( mort ) +#define FT_VALIDATE_morx FT_VALIDATE_GX_BITFIELD( morx ) +#define FT_VALIDATE_bsln FT_VALIDATE_GX_BITFIELD( bsln ) +#define FT_VALIDATE_just FT_VALIDATE_GX_BITFIELD( just ) +#define FT_VALIDATE_kern FT_VALIDATE_GX_BITFIELD( kern ) +#define FT_VALIDATE_opbd FT_VALIDATE_GX_BITFIELD( opbd ) +#define FT_VALIDATE_trak FT_VALIDATE_GX_BITFIELD( trak ) +#define FT_VALIDATE_prop FT_VALIDATE_GX_BITFIELD( prop ) +#define FT_VALIDATE_lcar FT_VALIDATE_GX_BITFIELD( lcar ) + +#define FT_VALIDATE_GX ( FT_VALIDATE_feat | \ + FT_VALIDATE_mort | \ + FT_VALIDATE_morx | \ + FT_VALIDATE_bsln | \ + FT_VALIDATE_just | \ + FT_VALIDATE_kern | \ + FT_VALIDATE_opbd | \ + FT_VALIDATE_trak | \ + FT_VALIDATE_prop | \ + FT_VALIDATE_lcar ) + + + /********************************************************************** + * + * @function: + * FT_TrueTypeGX_Validate + * + * @description: + * Validate various TrueTypeGX tables to assure that all offsets and + * indices are valid. The idea is that a higher-level library that + * actually does the text layout can access those tables without + * error checking (which can be quite time consuming). + * + * @input: + * face :: + * A handle to the input face. + * + * validation_flags :: + * A bit field that specifies the tables to be validated. See + * @FT_VALIDATE_GXXXX for possible values. + * + * table_length :: + * The size of the `tables' array. Normally, @FT_VALIDATE_GX_LENGTH + * should be passed. + * + * @output: + * tables :: + * The array where all validated sfnt tables are stored. + * The array itself must be allocated by a client. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with TrueTypeGX fonts, returning an error + * otherwise. + * + * After use, the application should deallocate the buffers pointed to by + * each `tables' element, by calling @FT_TrueTypeGX_Free. A NULL value + * indicates that the table either doesn't exist in the font, the + * application hasn't asked for validation, or the validator doesn't have + * the ability to validate the sfnt table. + */ + FT_EXPORT( FT_Error ) + FT_TrueTypeGX_Validate( FT_Face face, + FT_UInt validation_flags, + FT_Bytes tables[FT_VALIDATE_GX_LENGTH], + FT_UInt table_length ); + + + /********************************************************************** + * + * @function: + * FT_TrueTypeGX_Free + * + * @description: + * Free the buffer allocated by TrueTypeGX validator. + * + * @input: + * face :: + * A handle to the input face. + * + * table :: + * The pointer to the buffer allocated by + * @FT_TrueTypeGX_Validate. + * + * @note: + * This function must be used to free the buffer allocated by + * @FT_TrueTypeGX_Validate only. + */ + FT_EXPORT( void ) + FT_TrueTypeGX_Free( FT_Face face, + FT_Bytes table ); + + + /********************************************************************** + * + * @enum: + * FT_VALIDATE_CKERNXXX + * + * @description: + * A list of bit-field constants used with @FT_ClassicKern_Validate + * to indicate the classic kern dialect or dialects. If the selected + * type doesn't fit, @FT_ClassicKern_Validate regards the table as + * invalid. + * + * @values: + * FT_VALIDATE_MS :: + * Handle the `kern' table as a classic Microsoft kern table. + * + * FT_VALIDATE_APPLE :: + * Handle the `kern' table as a classic Apple kern table. + * + * FT_VALIDATE_CKERN :: + * Handle the `kern' as either classic Apple or Microsoft kern table. + */ +#define FT_VALIDATE_MS ( FT_VALIDATE_GX_START << 0 ) +#define FT_VALIDATE_APPLE ( FT_VALIDATE_GX_START << 1 ) + +#define FT_VALIDATE_CKERN ( FT_VALIDATE_MS | FT_VALIDATE_APPLE ) + + + /********************************************************************** + * + * @function: + * FT_ClassicKern_Validate + * + * @description: + * Validate classic (16-bit format) kern table to assure that the offsets + * and indices are valid. The idea is that a higher-level library that + * actually does the text layout can access those tables without error + * checking (which can be quite time consuming). + * + * The `kern' table validator in @FT_TrueTypeGX_Validate deals with both + * the new 32-bit format and the classic 16-bit format, while + * FT_ClassicKern_Validate only supports the classic 16-bit format. + * + * @input: + * face :: + * A handle to the input face. + * + * validation_flags :: + * A bit field that specifies the dialect to be validated. See + * @FT_VALIDATE_CKERNXXX for possible values. + * + * @output: + * ckern_table :: + * A pointer to the kern table. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * After use, the application should deallocate the buffers pointed to by + * `ckern_table', by calling @FT_ClassicKern_Free. A NULL value + * indicates that the table doesn't exist in the font. + */ + FT_EXPORT( FT_Error ) + FT_ClassicKern_Validate( FT_Face face, + FT_UInt validation_flags, + FT_Bytes *ckern_table ); + + + /********************************************************************** + * + * @function: + * FT_ClassicKern_Free + * + * @description: + * Free the buffer allocated by classic Kern validator. + * + * @input: + * face :: + * A handle to the input face. + * + * table :: + * The pointer to the buffer that is allocated by + * @FT_ClassicKern_Validate. + * + * @note: + * This function must be used to free the buffer allocated by + * @FT_ClassicKern_Validate only. + */ + FT_EXPORT( void ) + FT_ClassicKern_Free( FT_Face face, + FT_Bytes table ); + + /* */ + + +FT_END_HEADER + +#endif /* FTGXVAL_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftgzip.h b/android/x86/include/freetype/ftgzip.h new file mode 100644 index 00000000..9e658b0d --- /dev/null +++ b/android/x86/include/freetype/ftgzip.h @@ -0,0 +1,148 @@ +/***************************************************************************/ +/* */ +/* ftgzip.h */ +/* */ +/* Gzip-compressed stream support. */ +/* */ +/* Copyright 2002-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTGZIP_H_ +#define FTGZIP_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* <Section> */ + /* gzip */ + /* */ + /* <Title> */ + /* GZIP Streams */ + /* */ + /* <Abstract> */ + /* Using gzip-compressed font files. */ + /* */ + /* <Description> */ + /* This section contains the declaration of Gzip-specific functions. */ + /* */ + /*************************************************************************/ + + + /************************************************************************ + * + * @function: + * FT_Stream_OpenGzip + * + * @description: + * Open a new stream to parse gzip-compressed font files. This is + * mainly used to support the compressed `*.pcf.gz' fonts that come + * with XFree86. + * + * @input: + * stream :: + * The target embedding stream. + * + * source :: + * The source stream. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source stream must be opened _before_ calling this function. + * + * Calling the internal function `FT_Stream_Close' on the new stream will + * *not* call `FT_Stream_Close' on the source stream. None of the stream + * objects will be released to the heap. + * + * The stream implementation is very basic and resets the decompression + * process each time seeking backwards is needed within the stream. + * + * In certain builds of the library, gzip compression recognition is + * automatically handled when calling @FT_New_Face or @FT_Open_Face. + * This means that if no font driver is capable of handling the raw + * compressed file, the library will try to open a gzipped stream from + * it and re-open the face with it. + * + * This function may return `FT_Err_Unimplemented_Feature' if your build + * of FreeType was not compiled with zlib support. + */ + FT_EXPORT( FT_Error ) + FT_Stream_OpenGzip( FT_Stream stream, + FT_Stream source ); + + + /************************************************************************ + * + * @function: + * FT_Gzip_Uncompress + * + * @description: + * Decompress a zipped input buffer into an output buffer. This function + * is modeled after zlib's `uncompress' function. + * + * @input: + * memory :: + * A FreeType memory handle. + * + * input :: + * The input buffer. + * + * input_len :: + * The length of the input buffer. + * + * @output: + * output:: + * The output buffer. + * + * @inout: + * output_len :: + * Before calling the function, this is the the total size of the + * output buffer, which must be large enough to hold the entire + * uncompressed data (so the size of the uncompressed data must be + * known in advance). After calling the function, `output_len' is the + * size of the used data in `output'. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function may return `FT_Err_Unimplemented_Feature' if your build + * of FreeType was not compiled with zlib support. + */ + FT_EXPORT( FT_Error ) + FT_Gzip_Uncompress( FT_Memory memory, + FT_Byte* output, + FT_ULong* output_len, + const FT_Byte* input, + FT_ULong input_len ); + + /* */ + + +FT_END_HEADER + +#endif /* FTGZIP_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftimage.h b/android/x86/include/freetype/ftimage.h new file mode 100644 index 00000000..1d557c93 --- /dev/null +++ b/android/x86/include/freetype/ftimage.h @@ -0,0 +1,1214 @@ +/***************************************************************************/ +/* */ +/* ftimage.h */ +/* */ +/* FreeType glyph image formats and default raster interface */ +/* (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + /*************************************************************************/ + /* */ + /* Note: A `raster' is simply a scan-line converter, used to render */ + /* FT_Outlines into FT_Bitmaps. */ + /* */ + /*************************************************************************/ + + +#ifndef FTIMAGE_H_ +#define FTIMAGE_H_ + + + /* STANDALONE_ is from ftgrays.c */ +#ifndef STANDALONE_ +#include <ft2build.h> +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* basic_types */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Pos */ + /* */ + /* <Description> */ + /* The type FT_Pos is used to store vectorial coordinates. Depending */ + /* on the context, these can represent distances in integer font */ + /* units, or 16.16, or 26.6 fixed-point pixel coordinates. */ + /* */ + typedef signed long FT_Pos; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Vector */ + /* */ + /* <Description> */ + /* A simple structure used to store a 2D vector; coordinates are of */ + /* the FT_Pos type. */ + /* */ + /* <Fields> */ + /* x :: The horizontal coordinate. */ + /* y :: The vertical coordinate. */ + /* */ + typedef struct FT_Vector_ + { + FT_Pos x; + FT_Pos y; + + } FT_Vector; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_BBox */ + /* */ + /* <Description> */ + /* A structure used to hold an outline's bounding box, i.e., the */ + /* coordinates of its extrema in the horizontal and vertical */ + /* directions. */ + /* */ + /* <Fields> */ + /* xMin :: The horizontal minimum (left-most). */ + /* */ + /* yMin :: The vertical minimum (bottom-most). */ + /* */ + /* xMax :: The horizontal maximum (right-most). */ + /* */ + /* yMax :: The vertical maximum (top-most). */ + /* */ + /* <Note> */ + /* The bounding box is specified with the coordinates of the lower */ + /* left and the upper right corner. In PostScript, those values are */ + /* often called (llx,lly) and (urx,ury), respectively. */ + /* */ + /* If `yMin' is negative, this value gives the glyph's descender. */ + /* Otherwise, the glyph doesn't descend below the baseline. */ + /* Similarly, if `ymax' is positive, this value gives the glyph's */ + /* ascender. */ + /* */ + /* `xMin' gives the horizontal distance from the glyph's origin to */ + /* the left edge of the glyph's bounding box. If `xMin' is negative, */ + /* the glyph extends to the left of the origin. */ + /* */ + typedef struct FT_BBox_ + { + FT_Pos xMin, yMin; + FT_Pos xMax, yMax; + + } FT_BBox; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Pixel_Mode */ + /* */ + /* <Description> */ + /* An enumeration type used to describe the format of pixels in a */ + /* given bitmap. Note that additional formats may be added in the */ + /* future. */ + /* */ + /* <Values> */ + /* FT_PIXEL_MODE_NONE :: */ + /* Value~0 is reserved. */ + /* */ + /* FT_PIXEL_MODE_MONO :: */ + /* A monochrome bitmap, using 1~bit per pixel. Note that pixels */ + /* are stored in most-significant order (MSB), which means that */ + /* the left-most pixel in a byte has value 128. */ + /* */ + /* FT_PIXEL_MODE_GRAY :: */ + /* An 8-bit bitmap, generally used to represent anti-aliased glyph */ + /* images. Each pixel is stored in one byte. Note that the number */ + /* of `gray' levels is stored in the `num_grays' field of the */ + /* @FT_Bitmap structure (it generally is 256). */ + /* */ + /* FT_PIXEL_MODE_GRAY2 :: */ + /* A 2-bit per pixel bitmap, used to represent embedded */ + /* anti-aliased bitmaps in font files according to the OpenType */ + /* specification. We haven't found a single font using this */ + /* format, however. */ + /* */ + /* FT_PIXEL_MODE_GRAY4 :: */ + /* A 4-bit per pixel bitmap, representing embedded anti-aliased */ + /* bitmaps in font files according to the OpenType specification. */ + /* We haven't found a single font using this format, however. */ + /* */ + /* FT_PIXEL_MODE_LCD :: */ + /* An 8-bit bitmap, representing RGB or BGR decimated glyph images */ + /* used for display on LCD displays; the bitmap is three times */ + /* wider than the original glyph image. See also */ + /* @FT_RENDER_MODE_LCD. */ + /* */ + /* FT_PIXEL_MODE_LCD_V :: */ + /* An 8-bit bitmap, representing RGB or BGR decimated glyph images */ + /* used for display on rotated LCD displays; the bitmap is three */ + /* times taller than the original glyph image. See also */ + /* @FT_RENDER_MODE_LCD_V. */ + /* */ + /* FT_PIXEL_MODE_BGRA :: */ + /* An image with four 8-bit channels per pixel, representing a */ + /* color image (such as emoticons) with alpha channel. For each */ + /* pixel, the format is BGRA, which means, the blue channel comes */ + /* first in memory. The color channels are pre-multiplied and in */ + /* the sRGB colorspace. For example, full red at half-translucent */ + /* opacity will be represented as `00,00,80,80', not `00,00,FF,80'. */ + /* See also @FT_LOAD_COLOR. */ + /* */ + typedef enum FT_Pixel_Mode_ + { + FT_PIXEL_MODE_NONE = 0, + FT_PIXEL_MODE_MONO, + FT_PIXEL_MODE_GRAY, + FT_PIXEL_MODE_GRAY2, + FT_PIXEL_MODE_GRAY4, + FT_PIXEL_MODE_LCD, + FT_PIXEL_MODE_LCD_V, + FT_PIXEL_MODE_BGRA, + + FT_PIXEL_MODE_MAX /* do not remove */ + + } FT_Pixel_Mode; + + + /* these constants are deprecated; use the corresponding `FT_Pixel_Mode' */ + /* values instead. */ +#define ft_pixel_mode_none FT_PIXEL_MODE_NONE +#define ft_pixel_mode_mono FT_PIXEL_MODE_MONO +#define ft_pixel_mode_grays FT_PIXEL_MODE_GRAY +#define ft_pixel_mode_pal2 FT_PIXEL_MODE_GRAY2 +#define ft_pixel_mode_pal4 FT_PIXEL_MODE_GRAY4 + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Bitmap */ + /* */ + /* <Description> */ + /* A structure used to describe a bitmap or pixmap to the raster. */ + /* Note that we now manage pixmaps of various depths through the */ + /* `pixel_mode' field. */ + /* */ + /* <Fields> */ + /* rows :: The number of bitmap rows. */ + /* */ + /* width :: The number of pixels in bitmap row. */ + /* */ + /* pitch :: The pitch's absolute value is the number of bytes */ + /* taken by one bitmap row, including padding. */ + /* However, the pitch is positive when the bitmap has */ + /* a `down' flow, and negative when it has an `up' */ + /* flow. In all cases, the pitch is an offset to add */ + /* to a bitmap pointer in order to go down one row. */ + /* */ + /* Note that `padding' means the alignment of a */ + /* bitmap to a byte border, and FreeType functions */ + /* normally align to the smallest possible integer */ + /* value. */ + /* */ + /* For the B/W rasterizer, `pitch' is always an even */ + /* number. */ + /* */ + /* To change the pitch of a bitmap (say, to make it a */ + /* multiple of 4), use @FT_Bitmap_Convert. */ + /* Alternatively, you might use callback functions to */ + /* directly render to the application's surface; see */ + /* the file `example2.cpp' in the tutorial for a */ + /* demonstration. */ + /* */ + /* buffer :: A typeless pointer to the bitmap buffer. This */ + /* value should be aligned on 32-bit boundaries in */ + /* most cases. */ + /* */ + /* num_grays :: This field is only used with */ + /* @FT_PIXEL_MODE_GRAY; it gives the number of gray */ + /* levels used in the bitmap. */ + /* */ + /* pixel_mode :: The pixel mode, i.e., how pixel bits are stored. */ + /* See @FT_Pixel_Mode for possible values. */ + /* */ + /* palette_mode :: This field is intended for paletted pixel modes; */ + /* it indicates how the palette is stored. Not */ + /* used currently. */ + /* */ + /* palette :: A typeless pointer to the bitmap palette; this */ + /* field is intended for paletted pixel modes. Not */ + /* used currently. */ + /* */ + typedef struct FT_Bitmap_ + { + unsigned int rows; + unsigned int width; + int pitch; + unsigned char* buffer; + unsigned short num_grays; + unsigned char pixel_mode; + unsigned char palette_mode; + void* palette; + + } FT_Bitmap; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* outline_processing */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Outline */ + /* */ + /* <Description> */ + /* This structure is used to describe an outline to the scan-line */ + /* converter. */ + /* */ + /* <Fields> */ + /* n_contours :: The number of contours in the outline. */ + /* */ + /* n_points :: The number of points in the outline. */ + /* */ + /* points :: A pointer to an array of `n_points' @FT_Vector */ + /* elements, giving the outline's point coordinates. */ + /* */ + /* tags :: A pointer to an array of `n_points' chars, giving */ + /* each outline point's type. */ + /* */ + /* If bit~0 is unset, the point is `off' the curve, */ + /* i.e., a Bézier control point, while it is `on' if */ + /* set. */ + /* */ + /* Bit~1 is meaningful for `off' points only. If set, */ + /* it indicates a third-order Bézier arc control point; */ + /* and a second-order control point if unset. */ + /* */ + /* If bit~2 is set, bits 5-7 contain the drop-out mode */ + /* (as defined in the OpenType specification; the value */ + /* is the same as the argument to the SCANMODE */ + /* instruction). */ + /* */ + /* Bits 3 and~4 are reserved for internal purposes. */ + /* */ + /* contours :: An array of `n_contours' shorts, giving the end */ + /* point of each contour within the outline. For */ + /* example, the first contour is defined by the points */ + /* `0' to `contours[0]', the second one is defined by */ + /* the points `contours[0]+1' to `contours[1]', etc. */ + /* */ + /* flags :: A set of bit flags used to characterize the outline */ + /* and give hints to the scan-converter and hinter on */ + /* how to convert/grid-fit it. See @FT_OUTLINE_XXX. */ + /* */ + /* <Note> */ + /* The B/W rasterizer only checks bit~2 in the `tags' array for the */ + /* first point of each contour. The drop-out mode as given with */ + /* @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and */ + /* @FT_OUTLINE_INCLUDE_STUBS in `flags' is then overridden. */ + /* */ + typedef struct FT_Outline_ + { + short n_contours; /* number of contours in glyph */ + short n_points; /* number of points in the glyph */ + + FT_Vector* points; /* the outline's points */ + char* tags; /* the points flags */ + short* contours; /* the contour end points */ + + int flags; /* outline masks */ + + } FT_Outline; + + /* */ + + /* Following limits must be consistent with */ + /* FT_Outline.{n_contours,n_points} */ +#define FT_OUTLINE_CONTOURS_MAX SHRT_MAX +#define FT_OUTLINE_POINTS_MAX SHRT_MAX + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_OUTLINE_XXX */ + /* */ + /* <Description> */ + /* A list of bit-field constants use for the flags in an outline's */ + /* `flags' field. */ + /* */ + /* <Values> */ + /* FT_OUTLINE_NONE :: */ + /* Value~0 is reserved. */ + /* */ + /* FT_OUTLINE_OWNER :: */ + /* If set, this flag indicates that the outline's field arrays */ + /* (i.e., `points', `flags', and `contours') are `owned' by the */ + /* outline object, and should thus be freed when it is destroyed. */ + /* */ + /* FT_OUTLINE_EVEN_ODD_FILL :: */ + /* By default, outlines are filled using the non-zero winding rule. */ + /* If set to 1, the outline will be filled using the even-odd fill */ + /* rule (only works with the smooth rasterizer). */ + /* */ + /* FT_OUTLINE_REVERSE_FILL :: */ + /* By default, outside contours of an outline are oriented in */ + /* clock-wise direction, as defined in the TrueType specification. */ + /* This flag is set if the outline uses the opposite direction */ + /* (typically for Type~1 fonts). This flag is ignored by the scan */ + /* converter. */ + /* */ + /* FT_OUTLINE_IGNORE_DROPOUTS :: */ + /* By default, the scan converter will try to detect drop-outs in */ + /* an outline and correct the glyph bitmap to ensure consistent */ + /* shape continuity. If set, this flag hints the scan-line */ + /* converter to ignore such cases. See below for more information. */ + /* */ + /* FT_OUTLINE_SMART_DROPOUTS :: */ + /* Select smart dropout control. If unset, use simple dropout */ + /* control. Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See */ + /* below for more information. */ + /* */ + /* FT_OUTLINE_INCLUDE_STUBS :: */ + /* If set, turn pixels on for `stubs', otherwise exclude them. */ + /* Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See below for */ + /* more information. */ + /* */ + /* FT_OUTLINE_HIGH_PRECISION :: */ + /* This flag indicates that the scan-line converter should try to */ + /* convert this outline to bitmaps with the highest possible */ + /* quality. It is typically set for small character sizes. Note */ + /* that this is only a hint that might be completely ignored by a */ + /* given scan-converter. */ + /* */ + /* FT_OUTLINE_SINGLE_PASS :: */ + /* This flag is set to force a given scan-converter to only use a */ + /* single pass over the outline to render a bitmap glyph image. */ + /* Normally, it is set for very large character sizes. It is only */ + /* a hint that might be completely ignored by a given */ + /* scan-converter. */ + /* */ + /* <Note> */ + /* The flags @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, */ + /* and @FT_OUTLINE_INCLUDE_STUBS are ignored by the smooth */ + /* rasterizer. */ + /* */ + /* There exists a second mechanism to pass the drop-out mode to the */ + /* B/W rasterizer; see the `tags' field in @FT_Outline. */ + /* */ + /* Please refer to the description of the `SCANTYPE' instruction in */ + /* the OpenType specification (in file `ttinst1.doc') how simple */ + /* drop-outs, smart drop-outs, and stubs are defined. */ + /* */ +#define FT_OUTLINE_NONE 0x0 +#define FT_OUTLINE_OWNER 0x1 +#define FT_OUTLINE_EVEN_ODD_FILL 0x2 +#define FT_OUTLINE_REVERSE_FILL 0x4 +#define FT_OUTLINE_IGNORE_DROPOUTS 0x8 +#define FT_OUTLINE_SMART_DROPOUTS 0x10 +#define FT_OUTLINE_INCLUDE_STUBS 0x20 + +#define FT_OUTLINE_HIGH_PRECISION 0x100 +#define FT_OUTLINE_SINGLE_PASS 0x200 + + + /* these constants are deprecated; use the corresponding */ + /* `FT_OUTLINE_XXX' values instead */ +#define ft_outline_none FT_OUTLINE_NONE +#define ft_outline_owner FT_OUTLINE_OWNER +#define ft_outline_even_odd_fill FT_OUTLINE_EVEN_ODD_FILL +#define ft_outline_reverse_fill FT_OUTLINE_REVERSE_FILL +#define ft_outline_ignore_dropouts FT_OUTLINE_IGNORE_DROPOUTS +#define ft_outline_high_precision FT_OUTLINE_HIGH_PRECISION +#define ft_outline_single_pass FT_OUTLINE_SINGLE_PASS + + /* */ + +#define FT_CURVE_TAG( flag ) ( flag & 3 ) + +#define FT_CURVE_TAG_ON 1 +#define FT_CURVE_TAG_CONIC 0 +#define FT_CURVE_TAG_CUBIC 2 + +#define FT_CURVE_TAG_HAS_SCANMODE 4 + +#define FT_CURVE_TAG_TOUCH_X 8 /* reserved for the TrueType hinter */ +#define FT_CURVE_TAG_TOUCH_Y 16 /* reserved for the TrueType hinter */ + +#define FT_CURVE_TAG_TOUCH_BOTH ( FT_CURVE_TAG_TOUCH_X | \ + FT_CURVE_TAG_TOUCH_Y ) + +#define FT_Curve_Tag_On FT_CURVE_TAG_ON +#define FT_Curve_Tag_Conic FT_CURVE_TAG_CONIC +#define FT_Curve_Tag_Cubic FT_CURVE_TAG_CUBIC +#define FT_Curve_Tag_Touch_X FT_CURVE_TAG_TOUCH_X +#define FT_Curve_Tag_Touch_Y FT_CURVE_TAG_TOUCH_Y + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Outline_MoveToFunc */ + /* */ + /* <Description> */ + /* A function pointer type used to describe the signature of a `move */ + /* to' function during outline walking/decomposition. */ + /* */ + /* A `move to' is emitted to start a new contour in an outline. */ + /* */ + /* <Input> */ + /* to :: A pointer to the target point of the `move to'. */ + /* */ + /* user :: A typeless pointer, which is passed from the caller of the */ + /* decomposition function. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + typedef int + (*FT_Outline_MoveToFunc)( const FT_Vector* to, + void* user ); + +#define FT_Outline_MoveTo_Func FT_Outline_MoveToFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Outline_LineToFunc */ + /* */ + /* <Description> */ + /* A function pointer type used to describe the signature of a `line */ + /* to' function during outline walking/decomposition. */ + /* */ + /* A `line to' is emitted to indicate a segment in the outline. */ + /* */ + /* <Input> */ + /* to :: A pointer to the target point of the `line to'. */ + /* */ + /* user :: A typeless pointer, which is passed from the caller of the */ + /* decomposition function. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + typedef int + (*FT_Outline_LineToFunc)( const FT_Vector* to, + void* user ); + +#define FT_Outline_LineTo_Func FT_Outline_LineToFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Outline_ConicToFunc */ + /* */ + /* <Description> */ + /* A function pointer type used to describe the signature of a `conic */ + /* to' function during outline walking or decomposition. */ + /* */ + /* A `conic to' is emitted to indicate a second-order Bézier arc in */ + /* the outline. */ + /* */ + /* <Input> */ + /* control :: An intermediate control point between the last position */ + /* and the new target in `to'. */ + /* */ + /* to :: A pointer to the target end point of the conic arc. */ + /* */ + /* user :: A typeless pointer, which is passed from the caller of */ + /* the decomposition function. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + typedef int + (*FT_Outline_ConicToFunc)( const FT_Vector* control, + const FT_Vector* to, + void* user ); + +#define FT_Outline_ConicTo_Func FT_Outline_ConicToFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Outline_CubicToFunc */ + /* */ + /* <Description> */ + /* A function pointer type used to describe the signature of a `cubic */ + /* to' function during outline walking or decomposition. */ + /* */ + /* A `cubic to' is emitted to indicate a third-order Bézier arc. */ + /* */ + /* <Input> */ + /* control1 :: A pointer to the first Bézier control point. */ + /* */ + /* control2 :: A pointer to the second Bézier control point. */ + /* */ + /* to :: A pointer to the target end point. */ + /* */ + /* user :: A typeless pointer, which is passed from the caller of */ + /* the decomposition function. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + typedef int + (*FT_Outline_CubicToFunc)( const FT_Vector* control1, + const FT_Vector* control2, + const FT_Vector* to, + void* user ); + +#define FT_Outline_CubicTo_Func FT_Outline_CubicToFunc + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Outline_Funcs */ + /* */ + /* <Description> */ + /* A structure to hold various function pointers used during outline */ + /* decomposition in order to emit segments, conic, and cubic Béziers. */ + /* */ + /* <Fields> */ + /* move_to :: The `move to' emitter. */ + /* */ + /* line_to :: The segment emitter. */ + /* */ + /* conic_to :: The second-order Bézier arc emitter. */ + /* */ + /* cubic_to :: The third-order Bézier arc emitter. */ + /* */ + /* shift :: The shift that is applied to coordinates before they */ + /* are sent to the emitter. */ + /* */ + /* delta :: The delta that is applied to coordinates before they */ + /* are sent to the emitter, but after the shift. */ + /* */ + /* <Note> */ + /* The point coordinates sent to the emitters are the transformed */ + /* version of the original coordinates (this is important for high */ + /* accuracy during scan-conversion). The transformation is simple: */ + /* */ + /* { */ + /* x' = (x << shift) - delta */ + /* y' = (x << shift) - delta */ + /* } */ + /* */ + /* Set the values of `shift' and `delta' to~0 to get the original */ + /* point coordinates. */ + /* */ + typedef struct FT_Outline_Funcs_ + { + FT_Outline_MoveToFunc move_to; + FT_Outline_LineToFunc line_to; + FT_Outline_ConicToFunc conic_to; + FT_Outline_CubicToFunc cubic_to; + + int shift; + FT_Pos delta; + + } FT_Outline_Funcs; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* basic_types */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Macro> */ + /* FT_IMAGE_TAG */ + /* */ + /* <Description> */ + /* This macro converts four-letter tags to an unsigned long type. */ + /* */ + /* <Note> */ + /* Since many 16-bit compilers don't like 32-bit enumerations, you */ + /* should redefine this macro in case of problems to something like */ + /* this: */ + /* */ + /* { */ + /* #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value */ + /* } */ + /* */ + /* to get a simple enumeration without assigning special numbers. */ + /* */ +#ifndef FT_IMAGE_TAG +#define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \ + value = ( ( (unsigned long)_x1 << 24 ) | \ + ( (unsigned long)_x2 << 16 ) | \ + ( (unsigned long)_x3 << 8 ) | \ + (unsigned long)_x4 ) +#endif /* FT_IMAGE_TAG */ + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Glyph_Format */ + /* */ + /* <Description> */ + /* An enumeration type used to describe the format of a given glyph */ + /* image. Note that this version of FreeType only supports two image */ + /* formats, even though future font drivers will be able to register */ + /* their own format. */ + /* */ + /* <Values> */ + /* FT_GLYPH_FORMAT_NONE :: */ + /* The value~0 is reserved. */ + /* */ + /* FT_GLYPH_FORMAT_COMPOSITE :: */ + /* The glyph image is a composite of several other images. This */ + /* format is _only_ used with @FT_LOAD_NO_RECURSE, and is used to */ + /* report compound glyphs (like accented characters). */ + /* */ + /* FT_GLYPH_FORMAT_BITMAP :: */ + /* The glyph image is a bitmap, and can be described as an */ + /* @FT_Bitmap. You generally need to access the `bitmap' field of */ + /* the @FT_GlyphSlotRec structure to read it. */ + /* */ + /* FT_GLYPH_FORMAT_OUTLINE :: */ + /* The glyph image is a vectorial outline made of line segments */ + /* and Bézier arcs; it can be described as an @FT_Outline; you */ + /* generally want to access the `outline' field of the */ + /* @FT_GlyphSlotRec structure to read it. */ + /* */ + /* FT_GLYPH_FORMAT_PLOTTER :: */ + /* The glyph image is a vectorial path with no inside and outside */ + /* contours. Some Type~1 fonts, like those in the Hershey family, */ + /* contain glyphs in this format. These are described as */ + /* @FT_Outline, but FreeType isn't currently capable of rendering */ + /* them correctly. */ + /* */ + typedef enum FT_Glyph_Format_ + { + FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE, 0, 0, 0, 0 ), + + FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE, 'c', 'o', 'm', 'p' ), + FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP, 'b', 'i', 't', 's' ), + FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE, 'o', 'u', 't', 'l' ), + FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER, 'p', 'l', 'o', 't' ) + + } FT_Glyph_Format; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Glyph_Format' values instead. */ +#define ft_glyph_format_none FT_GLYPH_FORMAT_NONE +#define ft_glyph_format_composite FT_GLYPH_FORMAT_COMPOSITE +#define ft_glyph_format_bitmap FT_GLYPH_FORMAT_BITMAP +#define ft_glyph_format_outline FT_GLYPH_FORMAT_OUTLINE +#define ft_glyph_format_plotter FT_GLYPH_FORMAT_PLOTTER + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** R A S T E R D E F I N I T I O N S *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* A raster is a scan converter, in charge of rendering an outline into */ + /* a a bitmap. This section contains the public API for rasters. */ + /* */ + /* Note that in FreeType 2, all rasters are now encapsulated within */ + /* specific modules called `renderers'. See `ftrender.h' for more */ + /* details on renderers. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* raster */ + /* */ + /* <Title> */ + /* Scanline Converter */ + /* */ + /* <Abstract> */ + /* How vectorial outlines are converted into bitmaps and pixmaps. */ + /* */ + /* <Description> */ + /* This section contains technical definitions. */ + /* */ + /* <Order> */ + /* FT_Raster */ + /* FT_Span */ + /* FT_SpanFunc */ + /* */ + /* FT_Raster_Params */ + /* FT_RASTER_FLAG_XXX */ + /* */ + /* FT_Raster_NewFunc */ + /* FT_Raster_DoneFunc */ + /* FT_Raster_ResetFunc */ + /* FT_Raster_SetModeFunc */ + /* FT_Raster_RenderFunc */ + /* FT_Raster_Funcs */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Raster */ + /* */ + /* <Description> */ + /* An opaque handle (pointer) to a raster object. Each object can be */ + /* used independently to convert an outline into a bitmap or pixmap. */ + /* */ + typedef struct FT_RasterRec_* FT_Raster; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Span */ + /* */ + /* <Description> */ + /* A structure used to model a single span of gray pixels when */ + /* rendering an anti-aliased bitmap. */ + /* */ + /* <Fields> */ + /* x :: The span's horizontal start position. */ + /* */ + /* len :: The span's length in pixels. */ + /* */ + /* coverage :: The span color/coverage, ranging from 0 (background) */ + /* to 255 (foreground). */ + /* */ + /* <Note> */ + /* This structure is used by the span drawing callback type named */ + /* @FT_SpanFunc that takes the y~coordinate of the span as a */ + /* parameter. */ + /* */ + /* The coverage value is always between 0 and 255. If you want less */ + /* gray values, the callback function has to reduce them. */ + /* */ + typedef struct FT_Span_ + { + short x; + unsigned short len; + unsigned char coverage; + + } FT_Span; + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_SpanFunc */ + /* */ + /* <Description> */ + /* A function used as a call-back by the anti-aliased renderer in */ + /* order to let client applications draw themselves the gray pixel */ + /* spans on each scan line. */ + /* */ + /* <Input> */ + /* y :: The scanline's y~coordinate. */ + /* */ + /* count :: The number of spans to draw on this scanline. */ + /* */ + /* spans :: A table of `count' spans to draw on the scanline. */ + /* */ + /* user :: User-supplied data that is passed to the callback. */ + /* */ + /* <Note> */ + /* This callback allows client applications to directly render the */ + /* gray spans of the anti-aliased bitmap to any kind of surfaces. */ + /* */ + /* This can be used to write anti-aliased outlines directly to a */ + /* given background bitmap, and even perform translucency. */ + /* */ + /* Note that the `count' field cannot be greater than a fixed value */ + /* defined by the `FT_MAX_GRAY_SPANS' configuration macro in */ + /* `ftoption.h'. By default, this value is set to~32, which means */ + /* that if there are more than 32~spans on a given scanline, the */ + /* callback is called several times with the same `y' parameter in */ + /* order to draw all callbacks. */ + /* */ + /* Otherwise, the callback is only called once per scan-line, and */ + /* only for those scanlines that do have `gray' pixels on them. */ + /* */ + typedef void + (*FT_SpanFunc)( int y, + int count, + const FT_Span* spans, + void* user ); + +#define FT_Raster_Span_Func FT_SpanFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_BitTest_Func */ + /* */ + /* <Description> */ + /* Deprecated, unimplemented. */ + /* */ + typedef int + (*FT_Raster_BitTest_Func)( int y, + int x, + void* user ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_BitSet_Func */ + /* */ + /* <Description> */ + /* Deprecated, unimplemented. */ + /* */ + typedef void + (*FT_Raster_BitSet_Func)( int y, + int x, + void* user ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_RASTER_FLAG_XXX */ + /* */ + /* <Description> */ + /* A list of bit flag constants as used in the `flags' field of a */ + /* @FT_Raster_Params structure. */ + /* */ + /* <Values> */ + /* FT_RASTER_FLAG_DEFAULT :: This value is 0. */ + /* */ + /* FT_RASTER_FLAG_AA :: This flag is set to indicate that an */ + /* anti-aliased glyph image should be */ + /* generated. Otherwise, it will be */ + /* monochrome (1-bit). */ + /* */ + /* FT_RASTER_FLAG_DIRECT :: This flag is set to indicate direct */ + /* rendering. In this mode, client */ + /* applications must provide their own span */ + /* callback. This lets them directly */ + /* draw or compose over an existing bitmap. */ + /* If this bit is not set, the target */ + /* pixmap's buffer _must_ be zeroed before */ + /* rendering. */ + /* */ + /* Direct rendering is only possible with */ + /* anti-aliased glyphs. */ + /* */ + /* FT_RASTER_FLAG_CLIP :: This flag is only used in direct */ + /* rendering mode. If set, the output will */ + /* be clipped to a box specified in the */ + /* `clip_box' field of the */ + /* @FT_Raster_Params structure. */ + /* */ + /* Note that by default, the glyph bitmap */ + /* is clipped to the target pixmap, except */ + /* in direct rendering mode where all spans */ + /* are generated if no clipping box is set. */ + /* */ +#define FT_RASTER_FLAG_DEFAULT 0x0 +#define FT_RASTER_FLAG_AA 0x1 +#define FT_RASTER_FLAG_DIRECT 0x2 +#define FT_RASTER_FLAG_CLIP 0x4 + + /* these constants are deprecated; use the corresponding */ + /* `FT_RASTER_FLAG_XXX' values instead */ +#define ft_raster_flag_default FT_RASTER_FLAG_DEFAULT +#define ft_raster_flag_aa FT_RASTER_FLAG_AA +#define ft_raster_flag_direct FT_RASTER_FLAG_DIRECT +#define ft_raster_flag_clip FT_RASTER_FLAG_CLIP + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Raster_Params */ + /* */ + /* <Description> */ + /* A structure to hold the arguments used by a raster's render */ + /* function. */ + /* */ + /* <Fields> */ + /* target :: The target bitmap. */ + /* */ + /* source :: A pointer to the source glyph image (e.g., an */ + /* @FT_Outline). */ + /* */ + /* flags :: The rendering flags. */ + /* */ + /* gray_spans :: The gray span drawing callback. */ + /* */ + /* black_spans :: Unused. */ + /* */ + /* bit_test :: Unused. */ + /* */ + /* bit_set :: Unused. */ + /* */ + /* user :: User-supplied data that is passed to each drawing */ + /* callback. */ + /* */ + /* clip_box :: An optional clipping box. It is only used in */ + /* direct rendering mode. Note that coordinates here */ + /* should be expressed in _integer_ pixels (and not in */ + /* 26.6 fixed-point units). */ + /* */ + /* <Note> */ + /* An anti-aliased glyph bitmap is drawn if the @FT_RASTER_FLAG_AA */ + /* bit flag is set in the `flags' field, otherwise a monochrome */ + /* bitmap is generated. */ + /* */ + /* If the @FT_RASTER_FLAG_DIRECT bit flag is set in `flags', the */ + /* raster will call the `gray_spans' callback to draw gray pixel */ + /* spans. This allows direct composition over a pre-existing bitmap */ + /* through user-provided callbacks to perform the span drawing and */ + /* composition. Not supported by the monochrome rasterizer. */ + /* */ + typedef struct FT_Raster_Params_ + { + const FT_Bitmap* target; + const void* source; + int flags; + FT_SpanFunc gray_spans; + FT_SpanFunc black_spans; /* unused */ + FT_Raster_BitTest_Func bit_test; /* unused */ + FT_Raster_BitSet_Func bit_set; /* unused */ + void* user; + FT_BBox clip_box; + + } FT_Raster_Params; + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_NewFunc */ + /* */ + /* <Description> */ + /* A function used to create a new raster object. */ + /* */ + /* <Input> */ + /* memory :: A handle to the memory allocator. */ + /* */ + /* <Output> */ + /* raster :: A handle to the new raster object. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + /* <Note> */ + /* The `memory' parameter is a typeless pointer in order to avoid */ + /* un-wanted dependencies on the rest of the FreeType code. In */ + /* practice, it is an @FT_Memory object, i.e., a handle to the */ + /* standard FreeType memory allocator. However, this field can be */ + /* completely ignored by a given raster implementation. */ + /* */ + typedef int + (*FT_Raster_NewFunc)( void* memory, + FT_Raster* raster ); + +#define FT_Raster_New_Func FT_Raster_NewFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_DoneFunc */ + /* */ + /* <Description> */ + /* A function used to destroy a given raster object. */ + /* */ + /* <Input> */ + /* raster :: A handle to the raster object. */ + /* */ + typedef void + (*FT_Raster_DoneFunc)( FT_Raster raster ); + +#define FT_Raster_Done_Func FT_Raster_DoneFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_ResetFunc */ + /* */ + /* <Description> */ + /* FreeType used to provide an area of memory called the `render */ + /* pool' available to all registered rasters. This was not thread */ + /* safe however and now FreeType never allocates this pool. NULL */ + /* is always passed in as pool_base. */ + /* */ + /* This function is called each time the render pool changes, or just */ + /* after a new raster object is created. */ + /* */ + /* <Input> */ + /* raster :: A handle to the new raster object. */ + /* */ + /* pool_base :: The address in memory of the render pool. */ + /* */ + /* pool_size :: The size in bytes of the render pool. */ + /* */ + /* <Note> */ + /* Rasters should ignore the render pool and rely on dynamic or stack */ + /* allocation if they want to (a handle to the memory allocator is */ + /* passed to the raster constructor). */ + /* */ + typedef void + (*FT_Raster_ResetFunc)( FT_Raster raster, + unsigned char* pool_base, + unsigned long pool_size ); + +#define FT_Raster_Reset_Func FT_Raster_ResetFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_SetModeFunc */ + /* */ + /* <Description> */ + /* This function is a generic facility to change modes or attributes */ + /* in a given raster. This can be used for debugging purposes, or */ + /* simply to allow implementation-specific `features' in a given */ + /* raster module. */ + /* */ + /* <Input> */ + /* raster :: A handle to the new raster object. */ + /* */ + /* mode :: A 4-byte tag used to name the mode or property. */ + /* */ + /* args :: A pointer to the new mode/property to use. */ + /* */ + typedef int + (*FT_Raster_SetModeFunc)( FT_Raster raster, + unsigned long mode, + void* args ); + +#define FT_Raster_Set_Mode_Func FT_Raster_SetModeFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_RenderFunc */ + /* */ + /* <Description> */ + /* Invoke a given raster to scan-convert a given glyph image into a */ + /* target bitmap. */ + /* */ + /* <Input> */ + /* raster :: A handle to the raster object. */ + /* */ + /* params :: A pointer to an @FT_Raster_Params structure used to */ + /* store the rendering parameters. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + /* <Note> */ + /* The exact format of the source image depends on the raster's glyph */ + /* format defined in its @FT_Raster_Funcs structure. It can be an */ + /* @FT_Outline or anything else in order to support a large array of */ + /* glyph formats. */ + /* */ + /* Note also that the render function can fail and return a */ + /* `FT_Err_Unimplemented_Feature' error code if the raster used does */ + /* not support direct composition. */ + /* */ + /* XXX: For now, the standard raster doesn't support direct */ + /* composition but this should change for the final release (see */ + /* the files `demos/src/ftgrays.c' and `demos/src/ftgrays2.c' */ + /* for examples of distinct implementations that support direct */ + /* composition). */ + /* */ + typedef int + (*FT_Raster_RenderFunc)( FT_Raster raster, + const FT_Raster_Params* params ); + +#define FT_Raster_Render_Func FT_Raster_RenderFunc + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Raster_Funcs */ + /* */ + /* <Description> */ + /* A structure used to describe a given raster class to the library. */ + /* */ + /* <Fields> */ + /* glyph_format :: The supported glyph format for this raster. */ + /* */ + /* raster_new :: The raster constructor. */ + /* */ + /* raster_reset :: Used to reset the render pool within the raster. */ + /* */ + /* raster_render :: A function to render a glyph into a given bitmap. */ + /* */ + /* raster_done :: The raster destructor. */ + /* */ + typedef struct FT_Raster_Funcs_ + { + FT_Glyph_Format glyph_format; + FT_Raster_NewFunc raster_new; + FT_Raster_ResetFunc raster_reset; + FT_Raster_SetModeFunc raster_set_mode; + FT_Raster_RenderFunc raster_render; + FT_Raster_DoneFunc raster_done; + + } FT_Raster_Funcs; + + /* */ + + +FT_END_HEADER + +#endif /* FTIMAGE_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/android/x86/include/freetype/ftincrem.h b/android/x86/include/freetype/ftincrem.h new file mode 100644 index 00000000..46b58b79 --- /dev/null +++ b/android/x86/include/freetype/ftincrem.h @@ -0,0 +1,354 @@ +/***************************************************************************/ +/* */ +/* ftincrem.h */ +/* */ +/* FreeType incremental loading (specification). */ +/* */ +/* Copyright 2002-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTINCREM_H_ +#define FTINCREM_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************** + * + * @section: + * incremental + * + * @title: + * Incremental Loading + * + * @abstract: + * Custom Glyph Loading. + * + * @description: + * This section contains various functions used to perform so-called + * `incremental' glyph loading. This is a mode where all glyphs loaded + * from a given @FT_Face are provided by the client application. + * + * Apart from that, all other tables are loaded normally from the font + * file. This mode is useful when FreeType is used within another + * engine, e.g., a PostScript Imaging Processor. + * + * To enable this mode, you must use @FT_Open_Face, passing an + * @FT_Parameter with the @FT_PARAM_TAG_INCREMENTAL tag and an + * @FT_Incremental_Interface value. See the comments for + * @FT_Incremental_InterfaceRec for an example. + * + */ + + + /*************************************************************************** + * + * @type: + * FT_Incremental + * + * @description: + * An opaque type describing a user-provided object used to implement + * `incremental' glyph loading within FreeType. This is used to support + * embedded fonts in certain environments (e.g., PostScript interpreters), + * where the glyph data isn't in the font file, or must be overridden by + * different values. + * + * @note: + * It is up to client applications to create and implement @FT_Incremental + * objects, as long as they provide implementations for the methods + * @FT_Incremental_GetGlyphDataFunc, @FT_Incremental_FreeGlyphDataFunc + * and @FT_Incremental_GetGlyphMetricsFunc. + * + * See the description of @FT_Incremental_InterfaceRec to understand how + * to use incremental objects with FreeType. + * + */ + typedef struct FT_IncrementalRec_* FT_Incremental; + + + /*************************************************************************** + * + * @struct: + * FT_Incremental_MetricsRec + * + * @description: + * A small structure used to contain the basic glyph metrics returned + * by the @FT_Incremental_GetGlyphMetricsFunc method. + * + * @fields: + * bearing_x :: + * Left bearing, in font units. + * + * bearing_y :: + * Top bearing, in font units. + * + * advance :: + * Horizontal component of glyph advance, in font units. + * + * advance_v :: + * Vertical component of glyph advance, in font units. + * + * @note: + * These correspond to horizontal or vertical metrics depending on the + * value of the `vertical' argument to the function + * @FT_Incremental_GetGlyphMetricsFunc. + * + */ + typedef struct FT_Incremental_MetricsRec_ + { + FT_Long bearing_x; + FT_Long bearing_y; + FT_Long advance; + FT_Long advance_v; /* since 2.3.12 */ + + } FT_Incremental_MetricsRec; + + + /*************************************************************************** + * + * @struct: + * FT_Incremental_Metrics + * + * @description: + * A handle to an @FT_Incremental_MetricsRec structure. + * + */ + typedef struct FT_Incremental_MetricsRec_* FT_Incremental_Metrics; + + + /*************************************************************************** + * + * @type: + * FT_Incremental_GetGlyphDataFunc + * + * @description: + * A function called by FreeType to access a given glyph's data bytes + * during @FT_Load_Glyph or @FT_Load_Char if incremental loading is + * enabled. + * + * Note that the format of the glyph's data bytes depends on the font + * file format. For TrueType, it must correspond to the raw bytes within + * the `glyf' table. For PostScript formats, it must correspond to the + * *unencrypted* charstring bytes, without any `lenIV' header. It is + * undefined for any other format. + * + * @input: + * incremental :: + * Handle to an opaque @FT_Incremental handle provided by the client + * application. + * + * glyph_index :: + * Index of relevant glyph. + * + * @output: + * adata :: + * A structure describing the returned glyph data bytes (which will be + * accessed as a read-only byte block). + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If this function returns successfully the method + * @FT_Incremental_FreeGlyphDataFunc will be called later to release + * the data bytes. + * + * Nested calls to @FT_Incremental_GetGlyphDataFunc can happen for + * compound glyphs. + * + */ + typedef FT_Error + (*FT_Incremental_GetGlyphDataFunc)( FT_Incremental incremental, + FT_UInt glyph_index, + FT_Data* adata ); + + + /*************************************************************************** + * + * @type: + * FT_Incremental_FreeGlyphDataFunc + * + * @description: + * A function used to release the glyph data bytes returned by a + * successful call to @FT_Incremental_GetGlyphDataFunc. + * + * @input: + * incremental :: + * A handle to an opaque @FT_Incremental handle provided by the client + * application. + * + * data :: + * A structure describing the glyph data bytes (which will be accessed + * as a read-only byte block). + * + */ + typedef void + (*FT_Incremental_FreeGlyphDataFunc)( FT_Incremental incremental, + FT_Data* data ); + + + /*************************************************************************** + * + * @type: + * FT_Incremental_GetGlyphMetricsFunc + * + * @description: + * A function used to retrieve the basic metrics of a given glyph index + * before accessing its data. This is necessary because, in certain + * formats like TrueType, the metrics are stored in a different place from + * the glyph images proper. + * + * @input: + * incremental :: + * A handle to an opaque @FT_Incremental handle provided by the client + * application. + * + * glyph_index :: + * Index of relevant glyph. + * + * vertical :: + * If true, return vertical metrics. + * + * ametrics :: + * This parameter is used for both input and output. + * The original glyph metrics, if any, in font units. If metrics are + * not available all the values must be set to zero. + * + * @output: + * ametrics :: + * The replacement glyph metrics in font units. + * + */ + typedef FT_Error + (*FT_Incremental_GetGlyphMetricsFunc) + ( FT_Incremental incremental, + FT_UInt glyph_index, + FT_Bool vertical, + FT_Incremental_MetricsRec *ametrics ); + + + /************************************************************************** + * + * @struct: + * FT_Incremental_FuncsRec + * + * @description: + * A table of functions for accessing fonts that load data + * incrementally. Used in @FT_Incremental_InterfaceRec. + * + * @fields: + * get_glyph_data :: + * The function to get glyph data. Must not be null. + * + * free_glyph_data :: + * The function to release glyph data. Must not be null. + * + * get_glyph_metrics :: + * The function to get glyph metrics. May be null if the font does + * not provide overriding glyph metrics. + * + */ + typedef struct FT_Incremental_FuncsRec_ + { + FT_Incremental_GetGlyphDataFunc get_glyph_data; + FT_Incremental_FreeGlyphDataFunc free_glyph_data; + FT_Incremental_GetGlyphMetricsFunc get_glyph_metrics; + + } FT_Incremental_FuncsRec; + + + /*************************************************************************** + * + * @struct: + * FT_Incremental_InterfaceRec + * + * @description: + * A structure to be used with @FT_Open_Face to indicate that the user + * wants to support incremental glyph loading. You should use it with + * @FT_PARAM_TAG_INCREMENTAL as in the following example: + * + * { + * FT_Incremental_InterfaceRec inc_int; + * FT_Parameter parameter; + * FT_Open_Args open_args; + * + * + * // set up incremental descriptor + * inc_int.funcs = my_funcs; + * inc_int.object = my_object; + * + * // set up optional parameter + * parameter.tag = FT_PARAM_TAG_INCREMENTAL; + * parameter.data = &inc_int; + * + * // set up FT_Open_Args structure + * open_args.flags = FT_OPEN_PATHNAME | FT_OPEN_PARAMS; + * open_args.pathname = my_font_pathname; + * open_args.num_params = 1; + * open_args.params = ¶meter; // we use one optional argument + * + * // open the font + * error = FT_Open_Face( library, &open_args, index, &face ); + * ... + * } + * + */ + typedef struct FT_Incremental_InterfaceRec_ + { + const FT_Incremental_FuncsRec* funcs; + FT_Incremental object; + + } FT_Incremental_InterfaceRec; + + + /*************************************************************************** + * + * @type: + * FT_Incremental_Interface + * + * @description: + * A pointer to an @FT_Incremental_InterfaceRec structure. + * + */ + typedef FT_Incremental_InterfaceRec* FT_Incremental_Interface; + + + /*************************************************************************** + * + * @constant: + * FT_PARAM_TAG_INCREMENTAL + * + * @description: + * A constant used as the tag of @FT_Parameter structures to indicate + * an incremental loading object to be used by FreeType. + * + */ +#define FT_PARAM_TAG_INCREMENTAL FT_MAKE_TAG( 'i', 'n', 'c', 'r' ) + + /* */ + + +FT_END_HEADER + +#endif /* FTINCREM_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftlcdfil.h b/android/x86/include/freetype/ftlcdfil.h new file mode 100644 index 00000000..e06a8957 --- /dev/null +++ b/android/x86/include/freetype/ftlcdfil.h @@ -0,0 +1,286 @@ +/***************************************************************************/ +/* */ +/* ftlcdfil.h */ +/* */ +/* FreeType API for color filtering of subpixel bitmap glyphs */ +/* (specification). */ +/* */ +/* Copyright 2006-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTLCDFIL_H_ +#define FTLCDFIL_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************** + * + * @section: + * lcd_filtering + * + * @title: + * LCD Filtering + * + * @abstract: + * Reduce color fringes of subpixel-rendered bitmaps. + * + * @description: + * Subpixel rendering exploits the color-striped structure of LCD + * pixels, increasing the available resolution in the direction of the + * stripe (usually horizontal RGB) by a factor of~3. Since these + * subpixels are color pixels, using them unfiltered creates severe + * color fringes. Use the @FT_Library_SetLcdFilter API to specify a + * low-pass filter, which is then applied to subpixel-rendered bitmaps + * generated through @FT_Render_Glyph. The filter sacrifices some of + * the higher resolution to reduce color fringes, making the glyph image + * slightly blurrier. Positional improvements will remain. + * + * Note that no filter is active by default, and that this function is + * *not* implemented in default builds of the library. You need to + * #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING in your `ftoption.h' file + * in order to activate it and explicitly call @FT_Library_SetLcdFilter + * to enable it. + * + * A filter should have two properties: + * + * 1) It should be normalized, meaning the sum of the 5~components + * should be 256 (0x100). It is possible to go above or under this + * target sum, however: going under means tossing out contrast, going + * over means invoking clamping and thereby non-linearities that + * increase contrast somewhat at the expense of greater distortion + * and color-fringing. Contrast is better enhanced through stem + * darkening. + * + * 2) It should be color-balanced, meaning a filter `{~a, b, c, b, a~}' + * where a~+ b~=~c. It distributes the computed coverage for one + * subpixel to all subpixels equally, sacrificing some won resolution + * but drastically reducing color-fringing. Positioning improvements + * remain! Note that color-fringing can only really be minimized + * when using a color-balanced filter and alpha-blending the glyph + * onto a surface in linear space; see @FT_Render_Glyph. + * + * Regarding the form, a filter can be a `boxy' filter or a `beveled' + * filter. Boxy filters are sharper but are less forgiving of non-ideal + * gamma curves of a screen (viewing angles!), beveled filters are + * fuzzier but more tolerant. + * + * Examples: + * + * - [0x10 0x40 0x70 0x40 0x10] is beveled and neither balanced nor + * normalized. + * + * - [0x1A 0x33 0x4D 0x33 0x1A] is beveled and balanced but not + * normalized. + * + * - [0x19 0x33 0x66 0x4c 0x19] is beveled and normalized but not + * balanced. + * + * - [0x00 0x4c 0x66 0x4c 0x00] is boxily beveled and normalized but not + * balanced. + * + * - [0x00 0x55 0x56 0x55 0x00] is boxy, normalized, and almost + * balanced. + * + * - [0x08 0x4D 0x56 0x4D 0x08] is beveled, normalized and, almost + * balanced. + * + * The filter affects glyph bitmaps rendered through @FT_Render_Glyph, + * @FT_Load_Glyph, and @FT_Load_Char. It does _not_ affect the output + * of @FT_Outline_Render and @FT_Outline_Get_Bitmap. + * + * If this feature is activated, the dimensions of LCD glyph bitmaps are + * either wider or taller than the dimensions of the corresponding + * outline with regard to the pixel grid. For example, for + * @FT_RENDER_MODE_LCD, the filter adds 3~subpixels to the left, and + * 3~subpixels to the right. The bitmap offset values are adjusted + * accordingly, so clients shouldn't need to modify their layout and + * glyph positioning code when enabling the filter. + * + * It is important to understand that linear alpha blending and gamma + * correction is critical for correctly rendering glyphs onto surfaces + * without artifacts and even more critical when subpixel rendering is + * involved. + * + * Each of the 3~alpha values (subpixels) is independently used to blend + * one color channel. That is, red alpha blends the red channel of the + * text color with the red channel of the background pixel. The + * distribution of density values by the color-balanced filter assumes + * alpha blending is done in linear space; only then color artifacts + * cancel out. + */ + + + /**************************************************************************** + * + * @enum: + * FT_LcdFilter + * + * @description: + * A list of values to identify various types of LCD filters. + * + * @values: + * FT_LCD_FILTER_NONE :: + * Do not perform filtering. When used with subpixel rendering, this + * results in sometimes severe color fringes. + * + * FT_LCD_FILTER_DEFAULT :: + * The default filter reduces color fringes considerably, at the cost + * of a slight blurriness in the output. + * + * It is a beveled, normalized, and color-balanced five-tap filter + * that is more forgiving to screens with non-ideal gamma curves and + * viewing angles. Note that while color-fringing is reduced, it can + * only be minimized by using linear alpha blending and gamma + * correction to render glyphs onto surfaces. The default filter + * weights are [0x08 0x4D 0x56 0x4D 0x08]. + * + * FT_LCD_FILTER_LIGHT :: + * The light filter is a variant that is sharper at the cost of + * slightly more color fringes than the default one. + * + * It is a boxy, normalized, and color-balanced three-tap filter that + * is less forgiving to screens with non-ideal gamma curves and + * viewing angles. This filter works best when the rendering system + * uses linear alpha blending and gamma correction to render glyphs + * onto surfaces. The light filter weights are + * [0x00 0x55 0x56 0x55 0x00]. + * + * FT_LCD_FILTER_LEGACY :: + * This filter corresponds to the original libXft color filter. It + * provides high contrast output but can exhibit really bad color + * fringes if glyphs are not extremely well hinted to the pixel grid. + * In other words, it only works well if the TrueType bytecode + * interpreter is enabled *and* high-quality hinted fonts are used. + * + * This filter is only provided for comparison purposes, and might be + * disabled or stay unsupported in the future. + * + * FT_LCD_FILTER_LEGACY1 :: + * For historical reasons, the FontConfig library returns a different + * enumeration value for legacy LCD filtering. To make code work that + * (incorrectly) forwards FontConfig's enumeration value to + * @FT_Library_SetLcdFilter without proper mapping, it is thus easiest + * to have another enumeration value, which is completely equal to + * `FT_LCD_FILTER_LEGACY'. + * + * @since: + * 2.3.0 (`FT_LCD_FILTER_LEGACY1' since 2.6.2) + */ + typedef enum FT_LcdFilter_ + { + FT_LCD_FILTER_NONE = 0, + FT_LCD_FILTER_DEFAULT = 1, + FT_LCD_FILTER_LIGHT = 2, + FT_LCD_FILTER_LEGACY1 = 3, + FT_LCD_FILTER_LEGACY = 16, + + FT_LCD_FILTER_MAX /* do not remove */ + + } FT_LcdFilter; + + + /************************************************************************** + * + * @func: + * FT_Library_SetLcdFilter + * + * @description: + * This function is used to apply color filtering to LCD decimated + * bitmaps, like the ones used when calling @FT_Render_Glyph with + * @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V. + * + * @input: + * library :: + * A handle to the target library instance. + * + * filter :: + * The filter type. + * + * You can use @FT_LCD_FILTER_NONE here to disable this feature, or + * @FT_LCD_FILTER_DEFAULT to use a default filter that should work + * well on most LCD screens. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This feature is always disabled by default. Clients must make an + * explicit call to this function with a `filter' value other than + * @FT_LCD_FILTER_NONE in order to enable it. + * + * Due to *PATENTS* covering subpixel rendering, this function doesn't + * do anything except returning `FT_Err_Unimplemented_Feature' if the + * configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not + * defined in your build of the library, which should correspond to all + * default builds of FreeType. + * + * @since: + * 2.3.0 + */ + FT_EXPORT( FT_Error ) + FT_Library_SetLcdFilter( FT_Library library, + FT_LcdFilter filter ); + + + /************************************************************************** + * + * @func: + * FT_Library_SetLcdFilterWeights + * + * @description: + * This function can be used to enable LCD filter with custom weights, + * instead of using presets in @FT_Library_SetLcdFilter. + * + * @input: + * library :: + * A handle to the target library instance. + * + * weights :: + * A pointer to an array; the function copies the first five bytes and + * uses them to specify the filter weights. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * Due to *PATENTS* covering subpixel rendering, this function doesn't + * do anything except returning `FT_Err_Unimplemented_Feature' if the + * configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not + * defined in your build of the library, which should correspond to all + * default builds of FreeType. + * + * @since: + * 2.4.0 + */ + FT_EXPORT( FT_Error ) + FT_Library_SetLcdFilterWeights( FT_Library library, + unsigned char *weights ); + + /* */ + + +FT_END_HEADER + +#endif /* FTLCDFIL_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftlist.h b/android/x86/include/freetype/ftlist.h new file mode 100644 index 00000000..82f437ac --- /dev/null +++ b/android/x86/include/freetype/ftlist.h @@ -0,0 +1,276 @@ +/***************************************************************************/ +/* */ +/* ftlist.h */ +/* */ +/* Generic list support for FreeType (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This file implements functions relative to list processing. Its */ + /* data structures are defined in `freetype.h'. */ + /* */ + /*************************************************************************/ + + +#ifndef FTLIST_H_ +#define FTLIST_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* list_processing */ + /* */ + /* <Title> */ + /* List Processing */ + /* */ + /* <Abstract> */ + /* Simple management of lists. */ + /* */ + /* <Description> */ + /* This section contains various definitions related to list */ + /* processing using doubly-linked nodes. */ + /* */ + /* <Order> */ + /* FT_List */ + /* FT_ListNode */ + /* FT_ListRec */ + /* FT_ListNodeRec */ + /* */ + /* FT_List_Add */ + /* FT_List_Insert */ + /* FT_List_Find */ + /* FT_List_Remove */ + /* FT_List_Up */ + /* FT_List_Iterate */ + /* FT_List_Iterator */ + /* FT_List_Finalize */ + /* FT_List_Destructor */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Find */ + /* */ + /* <Description> */ + /* Find the list node for a given listed object. */ + /* */ + /* <Input> */ + /* list :: A pointer to the parent list. */ + /* data :: The address of the listed object. */ + /* */ + /* <Return> */ + /* List node. NULL if it wasn't found. */ + /* */ + FT_EXPORT( FT_ListNode ) + FT_List_Find( FT_List list, + void* data ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Add */ + /* */ + /* <Description> */ + /* Append an element to the end of a list. */ + /* */ + /* <InOut> */ + /* list :: A pointer to the parent list. */ + /* node :: The node to append. */ + /* */ + FT_EXPORT( void ) + FT_List_Add( FT_List list, + FT_ListNode node ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Insert */ + /* */ + /* <Description> */ + /* Insert an element at the head of a list. */ + /* */ + /* <InOut> */ + /* list :: A pointer to parent list. */ + /* node :: The node to insert. */ + /* */ + FT_EXPORT( void ) + FT_List_Insert( FT_List list, + FT_ListNode node ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Remove */ + /* */ + /* <Description> */ + /* Remove a node from a list. This function doesn't check whether */ + /* the node is in the list! */ + /* */ + /* <Input> */ + /* node :: The node to remove. */ + /* */ + /* <InOut> */ + /* list :: A pointer to the parent list. */ + /* */ + FT_EXPORT( void ) + FT_List_Remove( FT_List list, + FT_ListNode node ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Up */ + /* */ + /* <Description> */ + /* Move a node to the head/top of a list. Used to maintain LRU */ + /* lists. */ + /* */ + /* <InOut> */ + /* list :: A pointer to the parent list. */ + /* node :: The node to move. */ + /* */ + FT_EXPORT( void ) + FT_List_Up( FT_List list, + FT_ListNode node ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_List_Iterator */ + /* */ + /* <Description> */ + /* An FT_List iterator function that is called during a list parse */ + /* by @FT_List_Iterate. */ + /* */ + /* <Input> */ + /* node :: The current iteration list node. */ + /* */ + /* user :: A typeless pointer passed to @FT_List_Iterate. */ + /* Can be used to point to the iteration's state. */ + /* */ + typedef FT_Error + (*FT_List_Iterator)( FT_ListNode node, + void* user ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Iterate */ + /* */ + /* <Description> */ + /* Parse a list and calls a given iterator function on each element. */ + /* Note that parsing is stopped as soon as one of the iterator calls */ + /* returns a non-zero value. */ + /* */ + /* <Input> */ + /* list :: A handle to the list. */ + /* iterator :: An iterator function, called on each node of the list. */ + /* user :: A user-supplied field that is passed as the second */ + /* argument to the iterator. */ + /* */ + /* <Return> */ + /* The result (a FreeType error code) of the last iterator call. */ + /* */ + FT_EXPORT( FT_Error ) + FT_List_Iterate( FT_List list, + FT_List_Iterator iterator, + void* user ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_List_Destructor */ + /* */ + /* <Description> */ + /* An @FT_List iterator function that is called during a list */ + /* finalization by @FT_List_Finalize to destroy all elements in a */ + /* given list. */ + /* */ + /* <Input> */ + /* system :: The current system object. */ + /* */ + /* data :: The current object to destroy. */ + /* */ + /* user :: A typeless pointer passed to @FT_List_Iterate. It can */ + /* be used to point to the iteration's state. */ + /* */ + typedef void + (*FT_List_Destructor)( FT_Memory memory, + void* data, + void* user ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Finalize */ + /* */ + /* <Description> */ + /* Destroy all elements in the list as well as the list itself. */ + /* */ + /* <Input> */ + /* list :: A handle to the list. */ + /* */ + /* destroy :: A list destructor that will be applied to each element */ + /* of the list. Set this to NULL if not needed. */ + /* */ + /* memory :: The current memory object that handles deallocation. */ + /* */ + /* user :: A user-supplied field that is passed as the last */ + /* argument to the destructor. */ + /* */ + /* <Note> */ + /* This function expects that all nodes added by @FT_List_Add or */ + /* @FT_List_Insert have been dynamically allocated. */ + /* */ + FT_EXPORT( void ) + FT_List_Finalize( FT_List list, + FT_List_Destructor destroy, + FT_Memory memory, + void* user ); + + /* */ + + +FT_END_HEADER + +#endif /* FTLIST_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftlzw.h b/android/x86/include/freetype/ftlzw.h new file mode 100644 index 00000000..582e2c14 --- /dev/null +++ b/android/x86/include/freetype/ftlzw.h @@ -0,0 +1,99 @@ +/***************************************************************************/ +/* */ +/* ftlzw.h */ +/* */ +/* LZW-compressed stream support. */ +/* */ +/* Copyright 2004-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTLZW_H_ +#define FTLZW_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* <Section> */ + /* lzw */ + /* */ + /* <Title> */ + /* LZW Streams */ + /* */ + /* <Abstract> */ + /* Using LZW-compressed font files. */ + /* */ + /* <Description> */ + /* This section contains the declaration of LZW-specific functions. */ + /* */ + /*************************************************************************/ + + /************************************************************************ + * + * @function: + * FT_Stream_OpenLZW + * + * @description: + * Open a new stream to parse LZW-compressed font files. This is + * mainly used to support the compressed `*.pcf.Z' fonts that come + * with XFree86. + * + * @input: + * stream :: The target embedding stream. + * + * source :: The source stream. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source stream must be opened _before_ calling this function. + * + * Calling the internal function `FT_Stream_Close' on the new stream will + * *not* call `FT_Stream_Close' on the source stream. None of the stream + * objects will be released to the heap. + * + * The stream implementation is very basic and resets the decompression + * process each time seeking backwards is needed within the stream + * + * In certain builds of the library, LZW compression recognition is + * automatically handled when calling @FT_New_Face or @FT_Open_Face. + * This means that if no font driver is capable of handling the raw + * compressed file, the library will try to open a LZW stream from it + * and re-open the face with it. + * + * This function may return `FT_Err_Unimplemented_Feature' if your build + * of FreeType was not compiled with LZW support. + */ + FT_EXPORT( FT_Error ) + FT_Stream_OpenLZW( FT_Stream stream, + FT_Stream source ); + + /* */ + + +FT_END_HEADER + +#endif /* FTLZW_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftmac.h b/android/x86/include/freetype/ftmac.h new file mode 100644 index 00000000..adb15cad --- /dev/null +++ b/android/x86/include/freetype/ftmac.h @@ -0,0 +1,274 @@ +/***************************************************************************/ +/* */ +/* ftmac.h */ +/* */ +/* Additional Mac-specific API. */ +/* */ +/* Copyright 1996-2016 by */ +/* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* NOTE: Include this file after FT_FREETYPE_H and after any */ +/* Mac-specific headers (because this header uses Mac types such as */ +/* Handle, FSSpec, FSRef, etc.) */ +/* */ +/***************************************************************************/ + + +#ifndef FTMAC_H_ +#define FTMAC_H_ + + +#include <ft2build.h> + + +FT_BEGIN_HEADER + + +/* gcc-3.4.1 and later can warn about functions tagged as deprecated */ +#ifndef FT_DEPRECATED_ATTRIBUTE +#if defined(__GNUC__) && \ + ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) +#define FT_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) +#else +#define FT_DEPRECATED_ATTRIBUTE +#endif +#endif + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* mac_specific */ + /* */ + /* <Title> */ + /* Mac Specific Interface */ + /* */ + /* <Abstract> */ + /* Only available on the Macintosh. */ + /* */ + /* <Description> */ + /* The following definitions are only available if FreeType is */ + /* compiled on a Macintosh. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Face_From_FOND */ + /* */ + /* <Description> */ + /* Create a new face object from a FOND resource. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* fond :: A FOND resource. */ + /* */ + /* face_index :: Only supported for the -1 `sanity check' special */ + /* case. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Notes> */ + /* This function can be used to create @FT_Face objects from fonts */ + /* that are installed in the system as follows. */ + /* */ + /* { */ + /* fond = GetResource( 'FOND', fontName ); */ + /* error = FT_New_Face_From_FOND( library, fond, 0, &face ); */ + /* } */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Face_From_FOND( FT_Library library, + Handle fond, + FT_Long face_index, + FT_Face *aface ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_GetFile_From_Mac_Name */ + /* */ + /* <Description> */ + /* Return an FSSpec for the disk file containing the named font. */ + /* */ + /* <Input> */ + /* fontName :: Mac OS name of the font (e.g., Times New Roman */ + /* Bold). */ + /* */ + /* <Output> */ + /* pathSpec :: FSSpec to the file. For passing to */ + /* @FT_New_Face_From_FSSpec. */ + /* */ + /* face_index :: Index of the face. For passing to */ + /* @FT_New_Face_From_FSSpec. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_GetFile_From_Mac_Name( const char* fontName, + FSSpec* pathSpec, + FT_Long* face_index ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_GetFile_From_Mac_ATS_Name */ + /* */ + /* <Description> */ + /* Return an FSSpec for the disk file containing the named font. */ + /* */ + /* <Input> */ + /* fontName :: Mac OS name of the font in ATS framework. */ + /* */ + /* <Output> */ + /* pathSpec :: FSSpec to the file. For passing to */ + /* @FT_New_Face_From_FSSpec. */ + /* */ + /* face_index :: Index of the face. For passing to */ + /* @FT_New_Face_From_FSSpec. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_GetFile_From_Mac_ATS_Name( const char* fontName, + FSSpec* pathSpec, + FT_Long* face_index ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_GetFilePath_From_Mac_ATS_Name */ + /* */ + /* <Description> */ + /* Return a pathname of the disk file and face index for given font */ + /* name that is handled by ATS framework. */ + /* */ + /* <Input> */ + /* fontName :: Mac OS name of the font in ATS framework. */ + /* */ + /* <Output> */ + /* path :: Buffer to store pathname of the file. For passing */ + /* to @FT_New_Face. The client must allocate this */ + /* buffer before calling this function. */ + /* */ + /* maxPathSize :: Lengths of the buffer `path' that client allocated. */ + /* */ + /* face_index :: Index of the face. For passing to @FT_New_Face. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, + UInt8* path, + UInt32 maxPathSize, + FT_Long* face_index ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Face_From_FSSpec */ + /* */ + /* <Description> */ + /* Create a new face object from a given resource and typeface index */ + /* using an FSSpec to the font file. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* spec :: FSSpec to the font file. */ + /* */ + /* face_index :: The index of the face within the resource. The */ + /* first face has index~0. */ + /* <Output> */ + /* aface :: A handle to a new face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* @FT_New_Face_From_FSSpec is identical to @FT_New_Face except */ + /* it accepts an FSSpec instead of a path. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Face_From_FSSpec( FT_Library library, + const FSSpec *spec, + FT_Long face_index, + FT_Face *aface ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Face_From_FSRef */ + /* */ + /* <Description> */ + /* Create a new face object from a given resource and typeface index */ + /* using an FSRef to the font file. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* spec :: FSRef to the font file. */ + /* */ + /* face_index :: The index of the face within the resource. The */ + /* first face has index~0. */ + /* <Output> */ + /* aface :: A handle to a new face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* @FT_New_Face_From_FSRef is identical to @FT_New_Face except */ + /* it accepts an FSRef instead of a path. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Face_From_FSRef( FT_Library library, + const FSRef *ref, + FT_Long face_index, + FT_Face *aface ) + FT_DEPRECATED_ATTRIBUTE; + + /* */ + + +FT_END_HEADER + + +#endif /* FTMAC_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftmm.h b/android/x86/include/freetype/ftmm.h new file mode 100644 index 00000000..6c05f0c3 --- /dev/null +++ b/android/x86/include/freetype/ftmm.h @@ -0,0 +1,384 @@ +/***************************************************************************/ +/* */ +/* ftmm.h */ +/* */ +/* FreeType Multiple Master font interface (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTMM_H_ +#define FTMM_H_ + + +#include <ft2build.h> +#include FT_TYPE1_TABLES_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* multiple_masters */ + /* */ + /* <Title> */ + /* Multiple Masters */ + /* */ + /* <Abstract> */ + /* How to manage Multiple Masters fonts. */ + /* */ + /* <Description> */ + /* The following types and functions are used to manage Multiple */ + /* Master fonts, i.e., the selection of specific design instances by */ + /* setting design axis coordinates. */ + /* */ + /* George Williams has extended this interface to make it work with */ + /* both Type~1 Multiple Masters fonts and GX distortable (var) */ + /* fonts. Some of these routines only work with MM fonts, others */ + /* will work with both types. They are similar enough that a */ + /* consistent interface makes sense. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_MM_Axis */ + /* */ + /* <Description> */ + /* A simple structure used to model a given axis in design space for */ + /* Multiple Masters fonts. */ + /* */ + /* This structure can't be used for GX var fonts. */ + /* */ + /* <Fields> */ + /* name :: The axis's name. */ + /* */ + /* minimum :: The axis's minimum design coordinate. */ + /* */ + /* maximum :: The axis's maximum design coordinate. */ + /* */ + typedef struct FT_MM_Axis_ + { + FT_String* name; + FT_Long minimum; + FT_Long maximum; + + } FT_MM_Axis; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Multi_Master */ + /* */ + /* <Description> */ + /* A structure used to model the axes and space of a Multiple Masters */ + /* font. */ + /* */ + /* This structure can't be used for GX var fonts. */ + /* */ + /* <Fields> */ + /* num_axis :: Number of axes. Cannot exceed~4. */ + /* */ + /* num_designs :: Number of designs; should be normally 2^num_axis */ + /* even though the Type~1 specification strangely */ + /* allows for intermediate designs to be present. */ + /* This number cannot exceed~16. */ + /* */ + /* axis :: A table of axis descriptors. */ + /* */ + typedef struct FT_Multi_Master_ + { + FT_UInt num_axis; + FT_UInt num_designs; + FT_MM_Axis axis[T1_MAX_MM_AXIS]; + + } FT_Multi_Master; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Var_Axis */ + /* */ + /* <Description> */ + /* A simple structure used to model a given axis in design space for */ + /* Multiple Masters and GX var fonts. */ + /* */ + /* <Fields> */ + /* name :: The axis's name. */ + /* Not always meaningful for GX. */ + /* */ + /* minimum :: The axis's minimum design coordinate. */ + /* */ + /* def :: The axis's default design coordinate. */ + /* FreeType computes meaningful default values for MM; it */ + /* is then an integer value, not in 16.16 format. */ + /* */ + /* maximum :: The axis's maximum design coordinate. */ + /* */ + /* tag :: The axis's tag (the GX equivalent to `name'). */ + /* FreeType provides default values for MM if possible. */ + /* */ + /* strid :: The entry in `name' table (another GX version of */ + /* `name'). */ + /* Not meaningful for MM. */ + /* */ + typedef struct FT_Var_Axis_ + { + FT_String* name; + + FT_Fixed minimum; + FT_Fixed def; + FT_Fixed maximum; + + FT_ULong tag; + FT_UInt strid; + + } FT_Var_Axis; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Var_Named_Style */ + /* */ + /* <Description> */ + /* A simple structure used to model a named style in a GX var font. */ + /* */ + /* This structure can't be used for MM fonts. */ + /* */ + /* <Fields> */ + /* coords :: The design coordinates for this style. */ + /* This is an array with one entry for each axis. */ + /* */ + /* strid :: The entry in `name' table identifying this style. */ + /* */ + typedef struct FT_Var_Named_Style_ + { + FT_Fixed* coords; + FT_UInt strid; + + } FT_Var_Named_Style; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_MM_Var */ + /* */ + /* <Description> */ + /* A structure used to model the axes and space of a Multiple Masters */ + /* or GX var distortable font. */ + /* */ + /* Some fields are specific to one format and not to the other. */ + /* */ + /* <Fields> */ + /* num_axis :: The number of axes. The maximum value is~4 for */ + /* MM; no limit in GX. */ + /* */ + /* num_designs :: The number of designs; should be normally */ + /* 2^num_axis for MM fonts. Not meaningful for GX */ + /* (where every glyph could have a different */ + /* number of designs). */ + /* */ + /* num_namedstyles :: The number of named styles; only meaningful for */ + /* GX that allows certain design coordinates to */ + /* have a string ID (in the `name' table) */ + /* associated with them. The font can tell the */ + /* user that, for example, Weight=1.5 is `Bold'. */ + /* */ + /* axis :: An axis descriptor table. */ + /* GX fonts contain slightly more data than MM. */ + /* Memory management of this pointer is done */ + /* internally by FreeType. */ + /* */ + /* namedstyle :: A named style table. */ + /* Only meaningful with GX. */ + /* Memory management of this pointer is done */ + /* internally by FreeType. */ + /* */ + typedef struct FT_MM_Var_ + { + FT_UInt num_axis; + FT_UInt num_designs; + FT_UInt num_namedstyles; + FT_Var_Axis* axis; + FT_Var_Named_Style* namedstyle; + + } FT_MM_Var; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Multi_Master */ + /* */ + /* <Description> */ + /* Retrieve the Multiple Master descriptor of a given font. */ + /* */ + /* This function can't be used with GX fonts. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* <Output> */ + /* amaster :: The Multiple Masters descriptor. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Multi_Master( FT_Face face, + FT_Multi_Master *amaster ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_MM_Var */ + /* */ + /* <Description> */ + /* Retrieve the Multiple Master/GX var descriptor of a given font. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* <Output> */ + /* amaster :: The Multiple Masters/GX var descriptor. */ + /* Allocates a data structure, which the user must */ + /* deallocate with `free' after use. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_MM_Var( FT_Face face, + FT_MM_Var* *amaster ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_MM_Design_Coordinates */ + /* */ + /* <Description> */ + /* For Multiple Masters fonts, choose an interpolated font design */ + /* through design coordinates. */ + /* */ + /* This function can't be used with GX fonts. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face. */ + /* */ + /* <Input> */ + /* num_coords :: The number of available design coordinates. If it */ + /* is larger than the number of axes, ignore the excess */ + /* values. If it is smaller than the number of axes, */ + /* use default values for the remaining axes. */ + /* */ + /* coords :: An array of design coordinates. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_MM_Design_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Long* coords ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Var_Design_Coordinates */ + /* */ + /* <Description> */ + /* For Multiple Master or GX Var fonts, choose an interpolated font */ + /* design through design coordinates. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face. */ + /* */ + /* <Input> */ + /* num_coords :: The number of available design coordinates. If it */ + /* is larger than the number of axes, ignore the excess */ + /* values. If it is smaller than the number of axes, */ + /* use default values for the remaining axes. */ + /* */ + /* coords :: An array of design coordinates. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Var_Design_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Fixed* coords ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_MM_Blend_Coordinates */ + /* */ + /* <Description> */ + /* For Multiple Masters and GX var fonts, choose an interpolated font */ + /* design through normalized blend coordinates. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face. */ + /* */ + /* <Input> */ + /* num_coords :: The number of available design coordinates. If it */ + /* is larger than the number of axes, ignore the excess */ + /* values. If it is smaller than the number of axes, */ + /* use default values for the remaining axes. */ + /* */ + /* coords :: The design coordinates array (each element must be */ + /* between 0 and 1.0). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_MM_Blend_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Fixed* coords ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Var_Blend_Coordinates */ + /* */ + /* <Description> */ + /* This is another name of @FT_Set_MM_Blend_Coordinates. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Var_Blend_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Fixed* coords ); + + /* */ + + +FT_END_HEADER + +#endif /* FTMM_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftmodapi.h b/android/x86/include/freetype/ftmodapi.h new file mode 100644 index 00000000..b4d2758e --- /dev/null +++ b/android/x86/include/freetype/ftmodapi.h @@ -0,0 +1,667 @@ +/***************************************************************************/ +/* */ +/* ftmodapi.h */ +/* */ +/* FreeType modules public interface (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTMODAPI_H_ +#define FTMODAPI_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* module_management */ + /* */ + /* <Title> */ + /* Module Management */ + /* */ + /* <Abstract> */ + /* How to add, upgrade, remove, and control modules from FreeType. */ + /* */ + /* <Description> */ + /* The definitions below are used to manage modules within FreeType. */ + /* Modules can be added, upgraded, and removed at runtime. */ + /* Additionally, some module properties can be controlled also. */ + /* */ + /* Here is a list of possible values of the `module_name' field in */ + /* the @FT_Module_Class structure. */ + /* */ + /* { */ + /* autofitter */ + /* bdf */ + /* cff */ + /* gxvalid */ + /* otvalid */ + /* pcf */ + /* pfr */ + /* psaux */ + /* pshinter */ + /* psnames */ + /* raster1 */ + /* sfnt */ + /* smooth, smooth-lcd, smooth-lcdv */ + /* truetype */ + /* type1 */ + /* type42 */ + /* t1cid */ + /* winfonts */ + /* } */ + /* */ + /* Note that the FreeType Cache sub-system is not a FreeType module. */ + /* */ + /* <Order> */ + /* FT_Module */ + /* FT_Module_Constructor */ + /* FT_Module_Destructor */ + /* FT_Module_Requester */ + /* FT_Module_Class */ + /* */ + /* FT_Add_Module */ + /* FT_Get_Module */ + /* FT_Remove_Module */ + /* FT_Add_Default_Modules */ + /* */ + /* FT_Property_Set */ + /* FT_Property_Get */ + /* */ + /* FT_New_Library */ + /* FT_Done_Library */ + /* FT_Reference_Library */ + /* */ + /* FT_Renderer */ + /* FT_Renderer_Class */ + /* */ + /* FT_Get_Renderer */ + /* FT_Set_Renderer */ + /* */ + /* FT_Set_Debug_Hook */ + /* */ + /*************************************************************************/ + + + /* module bit flags */ +#define FT_MODULE_FONT_DRIVER 1 /* this module is a font driver */ +#define FT_MODULE_RENDERER 2 /* this module is a renderer */ +#define FT_MODULE_HINTER 4 /* this module is a glyph hinter */ +#define FT_MODULE_STYLER 8 /* this module is a styler */ + +#define FT_MODULE_DRIVER_SCALABLE 0x100 /* the driver supports */ + /* scalable fonts */ +#define FT_MODULE_DRIVER_NO_OUTLINES 0x200 /* the driver does not */ + /* support vector outlines */ +#define FT_MODULE_DRIVER_HAS_HINTER 0x400 /* the driver provides its */ + /* own hinter */ +#define FT_MODULE_DRIVER_HINTS_LIGHTLY 0x800 /* the driver's hinter */ + /* produces LIGHT hints */ + + + /* deprecated values */ +#define ft_module_font_driver FT_MODULE_FONT_DRIVER +#define ft_module_renderer FT_MODULE_RENDERER +#define ft_module_hinter FT_MODULE_HINTER +#define ft_module_styler FT_MODULE_STYLER + +#define ft_module_driver_scalable FT_MODULE_DRIVER_SCALABLE +#define ft_module_driver_no_outlines FT_MODULE_DRIVER_NO_OUTLINES +#define ft_module_driver_has_hinter FT_MODULE_DRIVER_HAS_HINTER +#define ft_module_driver_hints_lightly FT_MODULE_DRIVER_HINTS_LIGHTLY + + + typedef FT_Pointer FT_Module_Interface; + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Module_Constructor */ + /* */ + /* <Description> */ + /* A function used to initialize (not create) a new module object. */ + /* */ + /* <Input> */ + /* module :: The module to initialize. */ + /* */ + typedef FT_Error + (*FT_Module_Constructor)( FT_Module module ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Module_Destructor */ + /* */ + /* <Description> */ + /* A function used to finalize (not destroy) a given module object. */ + /* */ + /* <Input> */ + /* module :: The module to finalize. */ + /* */ + typedef void + (*FT_Module_Destructor)( FT_Module module ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Module_Requester */ + /* */ + /* <Description> */ + /* A function used to query a given module for a specific interface. */ + /* */ + /* <Input> */ + /* module :: The module to be searched. */ + /* */ + /* name :: The name of the interface in the module. */ + /* */ + typedef FT_Module_Interface + (*FT_Module_Requester)( FT_Module module, + const char* name ); + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Module_Class */ + /* */ + /* <Description> */ + /* The module class descriptor. */ + /* */ + /* <Fields> */ + /* module_flags :: Bit flags describing the module. */ + /* */ + /* module_size :: The size of one module object/instance in */ + /* bytes. */ + /* */ + /* module_name :: The name of the module. */ + /* */ + /* module_version :: The version, as a 16.16 fixed number */ + /* (major.minor). */ + /* */ + /* module_requires :: The version of FreeType this module requires, */ + /* as a 16.16 fixed number (major.minor). Starts */ + /* at version 2.0, i.e., 0x20000. */ + /* */ + /* module_init :: The initializing function. */ + /* */ + /* module_done :: The finalizing function. */ + /* */ + /* get_interface :: The interface requesting function. */ + /* */ + typedef struct FT_Module_Class_ + { + FT_ULong module_flags; + FT_Long module_size; + const FT_String* module_name; + FT_Fixed module_version; + FT_Fixed module_requires; + + const void* module_interface; + + FT_Module_Constructor module_init; + FT_Module_Destructor module_done; + FT_Module_Requester get_interface; + + } FT_Module_Class; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Add_Module */ + /* */ + /* <Description> */ + /* Add a new module to a given library instance. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library object. */ + /* */ + /* <Input> */ + /* clazz :: A pointer to class descriptor for the module. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* An error will be returned if a module already exists by that name, */ + /* or if the module requires a version of FreeType that is too great. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Add_Module( FT_Library library, + const FT_Module_Class* clazz ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Module */ + /* */ + /* <Description> */ + /* Find a module by its name. */ + /* */ + /* <Input> */ + /* library :: A handle to the library object. */ + /* */ + /* module_name :: The module's name (as an ASCII string). */ + /* */ + /* <Return> */ + /* A module handle. 0~if none was found. */ + /* */ + /* <Note> */ + /* FreeType's internal modules aren't documented very well, and you */ + /* should look up the source code for details. */ + /* */ + FT_EXPORT( FT_Module ) + FT_Get_Module( FT_Library library, + const char* module_name ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Remove_Module */ + /* */ + /* <Description> */ + /* Remove a given module from a library instance. */ + /* */ + /* <InOut> */ + /* library :: A handle to a library object. */ + /* */ + /* <Input> */ + /* module :: A handle to a module object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The module object is destroyed by the function in case of success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Remove_Module( FT_Library library, + FT_Module module ); + + + /********************************************************************** + * + * @function: + * FT_Property_Set + * + * @description: + * Set a property for a given module. + * + * @input: + * library :: + * A handle to the library the module is part of. + * + * module_name :: + * The module name. + * + * property_name :: + * The property name. Properties are described in the `Synopsis' + * subsection of the module's documentation. + * + * Note that only a few modules have properties. + * + * value :: + * A generic pointer to a variable or structure that gives the new + * value of the property. The exact definition of `value' is + * dependent on the property; see the `Synopsis' subsection of the + * module's documentation. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If `module_name' isn't a valid module name, or `property_name' + * doesn't specify a valid property, or if `value' doesn't represent a + * valid value for the given property, an error is returned. + * + * The following example sets property `bar' (a simple integer) in + * module `foo' to value~1. + * + * { + * FT_UInt bar; + * + * + * bar = 1; + * FT_Property_Set( library, "foo", "bar", &bar ); + * } + * + * Note that the FreeType Cache sub-system doesn't recognize module + * property changes. To avoid glyph lookup confusion within the cache + * you should call @FTC_Manager_Reset to completely flush the cache if + * a module property gets changed after @FTC_Manager_New has been + * called. + * + * It is not possible to set properties of the FreeType Cache + * sub-system itself with FT_Property_Set; use @FTC_Property_Set + * instead. + * + * @since: + * 2.4.11 + * + */ + FT_EXPORT( FT_Error ) + FT_Property_Set( FT_Library library, + const FT_String* module_name, + const FT_String* property_name, + const void* value ); + + + /********************************************************************** + * + * @function: + * FT_Property_Get + * + * @description: + * Get a module's property value. + * + * @input: + * library :: + * A handle to the library the module is part of. + * + * module_name :: + * The module name. + * + * property_name :: + * The property name. Properties are described in the `Synopsis' + * subsection of the module's documentation. + * + * @inout: + * value :: + * A generic pointer to a variable or structure that gives the + * value of the property. The exact definition of `value' is + * dependent on the property; see the `Synopsis' subsection of the + * module's documentation. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If `module_name' isn't a valid module name, or `property_name' + * doesn't specify a valid property, or if `value' doesn't represent a + * valid value for the given property, an error is returned. + * + * The following example gets property `baz' (a range) in module `foo'. + * + * { + * typedef range_ + * { + * FT_Int32 min; + * FT_Int32 max; + * + * } range; + * + * range baz; + * + * + * FT_Property_Get( library, "foo", "baz", &baz ); + * } + * + * It is not possible to retrieve properties of the FreeType Cache + * sub-system with FT_Property_Get; use @FTC_Property_Get instead. + * + * @since: + * 2.4.11 + * + */ + FT_EXPORT( FT_Error ) + FT_Property_Get( FT_Library library, + const FT_String* module_name, + const FT_String* property_name, + void* value ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Reference_Library */ + /* */ + /* <Description> */ + /* A counter gets initialized to~1 at the time an @FT_Library */ + /* structure is created. This function increments the counter. */ + /* @FT_Done_Library then only destroys a library if the counter is~1, */ + /* otherwise it simply decrements the counter. */ + /* */ + /* This function helps in managing life-cycles of structures that */ + /* reference @FT_Library objects. */ + /* */ + /* <Input> */ + /* library :: A handle to a target library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Since> */ + /* 2.4.2 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Reference_Library( FT_Library library ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Library */ + /* */ + /* <Description> */ + /* This function is used to create a new FreeType library instance */ + /* from a given memory object. It is thus possible to use libraries */ + /* with distinct memory allocators within the same program. Note, */ + /* however, that the used @FT_Memory structure is expected to remain */ + /* valid for the life of the @FT_Library object. */ + /* */ + /* Normally, you would call this function (followed by a call to */ + /* @FT_Add_Default_Modules or a series of calls to @FT_Add_Module) */ + /* instead of @FT_Init_FreeType to initialize the FreeType library. */ + /* */ + /* Don't use @FT_Done_FreeType but @FT_Done_Library to destroy a */ + /* library instance. */ + /* */ + /* <Input> */ + /* memory :: A handle to the original memory object. */ + /* */ + /* <Output> */ + /* alibrary :: A pointer to handle of a new library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Library. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Library( FT_Memory memory, + FT_Library *alibrary ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_Library */ + /* */ + /* <Description> */ + /* Discard a given library object. This closes all drivers and */ + /* discards all resource objects. */ + /* */ + /* <Input> */ + /* library :: A handle to the target library. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Library. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_Library( FT_Library library ); + + /* */ + + typedef void + (*FT_DebugHook_Func)( void* arg ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Debug_Hook */ + /* */ + /* <Description> */ + /* Set a debug hook function for debugging the interpreter of a font */ + /* format. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library object. */ + /* */ + /* <Input> */ + /* hook_index :: The index of the debug hook. You should use the */ + /* values defined in `ftobjs.h', e.g., */ + /* `FT_DEBUG_HOOK_TRUETYPE'. */ + /* */ + /* debug_hook :: The function used to debug the interpreter. */ + /* */ + /* <Note> */ + /* Currently, four debug hook slots are available, but only two (for */ + /* the TrueType and the Type~1 interpreter) are defined. */ + /* */ + /* Since the internal headers of FreeType are no longer installed, */ + /* the symbol `FT_DEBUG_HOOK_TRUETYPE' isn't available publicly. */ + /* This is a bug and will be fixed in a forthcoming release. */ + /* */ + FT_EXPORT( void ) + FT_Set_Debug_Hook( FT_Library library, + FT_UInt hook_index, + FT_DebugHook_Func debug_hook ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Add_Default_Modules */ + /* */ + /* <Description> */ + /* Add the set of default drivers to a given library object. */ + /* This is only useful when you create a library object with */ + /* @FT_New_Library (usually to plug a custom memory manager). */ + /* */ + /* <InOut> */ + /* library :: A handle to a new library object. */ + /* */ + FT_EXPORT( void ) + FT_Add_Default_Modules( FT_Library library ); + + + + /************************************************************************** + * + * @section: + * truetype_engine + * + * @title: + * The TrueType Engine + * + * @abstract: + * TrueType bytecode support. + * + * @description: + * This section contains a function used to query the level of TrueType + * bytecode support compiled in this version of the library. + * + */ + + + /************************************************************************** + * + * @enum: + * FT_TrueTypeEngineType + * + * @description: + * A list of values describing which kind of TrueType bytecode + * engine is implemented in a given FT_Library instance. It is used + * by the @FT_Get_TrueType_Engine_Type function. + * + * @values: + * FT_TRUETYPE_ENGINE_TYPE_NONE :: + * The library doesn't implement any kind of bytecode interpreter. + * + * FT_TRUETYPE_ENGINE_TYPE_UNPATENTED :: + * Deprecated and removed. + * + * FT_TRUETYPE_ENGINE_TYPE_PATENTED :: + * The library implements a bytecode interpreter that covers + * the full instruction set of the TrueType virtual machine (this + * was governed by patents until May 2010, hence the name). + * + * @since: + * 2.2 + * + */ + typedef enum FT_TrueTypeEngineType_ + { + FT_TRUETYPE_ENGINE_TYPE_NONE = 0, + FT_TRUETYPE_ENGINE_TYPE_UNPATENTED, + FT_TRUETYPE_ENGINE_TYPE_PATENTED + + } FT_TrueTypeEngineType; + + + /************************************************************************** + * + * @func: + * FT_Get_TrueType_Engine_Type + * + * @description: + * Return an @FT_TrueTypeEngineType value to indicate which level of + * the TrueType virtual machine a given library instance supports. + * + * @input: + * library :: + * A library instance. + * + * @return: + * A value indicating which level is supported. + * + * @since: + * 2.2 + * + */ + FT_EXPORT( FT_TrueTypeEngineType ) + FT_Get_TrueType_Engine_Type( FT_Library library ); + + /* */ + + +FT_END_HEADER + +#endif /* FTMODAPI_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftmoderr.h b/android/x86/include/freetype/ftmoderr.h new file mode 100644 index 00000000..2a7671c8 --- /dev/null +++ b/android/x86/include/freetype/ftmoderr.h @@ -0,0 +1,194 @@ +/***************************************************************************/ +/* */ +/* ftmoderr.h */ +/* */ +/* FreeType module error offsets (specification). */ +/* */ +/* Copyright 2001-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This file is used to define the FreeType module error codes. */ + /* */ + /* If the macro FT_CONFIG_OPTION_USE_MODULE_ERRORS in `ftoption.h' is */ + /* set, the lower byte of an error value identifies the error code as */ + /* usual. In addition, the higher byte identifies the module. For */ + /* example, the error `FT_Err_Invalid_File_Format' has value 0x0003, the */ + /* error `TT_Err_Invalid_File_Format' has value 0x1303, the error */ + /* `T1_Err_Invalid_File_Format' has value 0x1403, etc. */ + /* */ + /* Note that `FT_Err_Ok', `TT_Err_Ok', etc. are always equal to zero, */ + /* including the high byte. */ + /* */ + /* If FT_CONFIG_OPTION_USE_MODULE_ERRORS isn't set, the higher byte of */ + /* an error value is set to zero. */ + /* */ + /* To hide the various `XXX_Err_' prefixes in the source code, FreeType */ + /* provides some macros in `fttypes.h'. */ + /* */ + /* FT_ERR( err ) */ + /* Add current error module prefix (as defined with the */ + /* `FT_ERR_PREFIX' macro) to `err'. For example, in the BDF module */ + /* the line */ + /* */ + /* error = FT_ERR( Invalid_Outline ); */ + /* */ + /* expands to */ + /* */ + /* error = BDF_Err_Invalid_Outline; */ + /* */ + /* For simplicity, you can always use `FT_Err_Ok' directly instead */ + /* of `FT_ERR( Ok )'. */ + /* */ + /* FT_ERR_EQ( errcode, err ) */ + /* FT_ERR_NEQ( errcode, err ) */ + /* Compare error code `errcode' with the error `err' for equality */ + /* and inequality, respectively. Example: */ + /* */ + /* if ( FT_ERR_EQ( error, Invalid_Outline ) ) */ + /* ... */ + /* */ + /* Using this macro you don't have to think about error prefixes. */ + /* Of course, if module errors are not active, the above example is */ + /* the same as */ + /* */ + /* if ( error == FT_Err_Invalid_Outline ) */ + /* ... */ + /* */ + /* FT_ERROR_BASE( errcode ) */ + /* FT_ERROR_MODULE( errcode ) */ + /* Get base error and module error code, respectively. */ + /* */ + /* */ + /* It can also be used to create a module error message table easily */ + /* with something like */ + /* */ + /* { */ + /* #undef FTMODERR_H_ */ + /* #define FT_MODERRDEF( e, v, s ) { FT_Mod_Err_ ## e, s }, */ + /* #define FT_MODERR_START_LIST { */ + /* #define FT_MODERR_END_LIST { 0, 0 } }; */ + /* */ + /* const struct */ + /* { */ + /* int mod_err_offset; */ + /* const char* mod_err_msg */ + /* } ft_mod_errors[] = */ + /* */ + /* #include FT_MODULE_ERRORS_H */ + /* } */ + /* */ + /*************************************************************************/ + + +#ifndef FTMODERR_H_ +#define FTMODERR_H_ + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** SETUP MACROS *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + + +#undef FT_NEED_EXTERN_C + +#ifndef FT_MODERRDEF + +#ifdef FT_CONFIG_OPTION_USE_MODULE_ERRORS +#define FT_MODERRDEF( e, v, s ) FT_Mod_Err_ ## e = v, +#else +#define FT_MODERRDEF( e, v, s ) FT_Mod_Err_ ## e = 0, +#endif + +#define FT_MODERR_START_LIST enum { +#define FT_MODERR_END_LIST FT_Mod_Err_Max }; + +#ifdef __cplusplus +#define FT_NEED_EXTERN_C + extern "C" { +#endif + +#endif /* !FT_MODERRDEF */ + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** LIST MODULE ERROR BASES *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + + +#ifdef FT_MODERR_START_LIST + FT_MODERR_START_LIST +#endif + + + FT_MODERRDEF( Base, 0x000, "base module" ) + FT_MODERRDEF( Autofit, 0x100, "autofitter module" ) + FT_MODERRDEF( BDF, 0x200, "BDF module" ) + FT_MODERRDEF( Bzip2, 0x300, "Bzip2 module" ) + FT_MODERRDEF( Cache, 0x400, "cache module" ) + FT_MODERRDEF( CFF, 0x500, "CFF module" ) + FT_MODERRDEF( CID, 0x600, "CID module" ) + FT_MODERRDEF( Gzip, 0x700, "Gzip module" ) + FT_MODERRDEF( LZW, 0x800, "LZW module" ) + FT_MODERRDEF( OTvalid, 0x900, "OpenType validation module" ) + FT_MODERRDEF( PCF, 0xA00, "PCF module" ) + FT_MODERRDEF( PFR, 0xB00, "PFR module" ) + FT_MODERRDEF( PSaux, 0xC00, "PS auxiliary module" ) + FT_MODERRDEF( PShinter, 0xD00, "PS hinter module" ) + FT_MODERRDEF( PSnames, 0xE00, "PS names module" ) + FT_MODERRDEF( Raster, 0xF00, "raster module" ) + FT_MODERRDEF( SFNT, 0x1000, "SFNT module" ) + FT_MODERRDEF( Smooth, 0x1100, "smooth raster module" ) + FT_MODERRDEF( TrueType, 0x1200, "TrueType module" ) + FT_MODERRDEF( Type1, 0x1300, "Type 1 module" ) + FT_MODERRDEF( Type42, 0x1400, "Type 42 module" ) + FT_MODERRDEF( Winfonts, 0x1500, "Windows FON/FNT module" ) + FT_MODERRDEF( GXvalid, 0x1600, "GX validation module" ) + + +#ifdef FT_MODERR_END_LIST + FT_MODERR_END_LIST +#endif + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** CLEANUP *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + + +#ifdef FT_NEED_EXTERN_C + } +#endif + +#undef FT_MODERR_START_LIST +#undef FT_MODERR_END_LIST +#undef FT_MODERRDEF +#undef FT_NEED_EXTERN_C + + +#endif /* FTMODERR_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftotval.h b/android/x86/include/freetype/ftotval.h new file mode 100644 index 00000000..c678ef34 --- /dev/null +++ b/android/x86/include/freetype/ftotval.h @@ -0,0 +1,204 @@ +/***************************************************************************/ +/* */ +/* ftotval.h */ +/* */ +/* FreeType API for validating OpenType tables (specification). */ +/* */ +/* Copyright 2004-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* */ +/* Warning: This module might be moved to a different library in the */ +/* future to avoid a tight dependency between FreeType and the */ +/* OpenType specification. */ +/* */ +/* */ +/***************************************************************************/ + + +#ifndef FTOTVAL_H_ +#define FTOTVAL_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* ot_validation */ + /* */ + /* <Title> */ + /* OpenType Validation */ + /* */ + /* <Abstract> */ + /* An API to validate OpenType tables. */ + /* */ + /* <Description> */ + /* This section contains the declaration of functions to validate */ + /* some OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF, MATH). */ + /* */ + /* <Order> */ + /* FT_OpenType_Validate */ + /* FT_OpenType_Free */ + /* */ + /* FT_VALIDATE_OTXXX */ + /* */ + /*************************************************************************/ + + + /********************************************************************** + * + * @enum: + * FT_VALIDATE_OTXXX + * + * @description: + * A list of bit-field constants used with @FT_OpenType_Validate to + * indicate which OpenType tables should be validated. + * + * @values: + * FT_VALIDATE_BASE :: + * Validate BASE table. + * + * FT_VALIDATE_GDEF :: + * Validate GDEF table. + * + * FT_VALIDATE_GPOS :: + * Validate GPOS table. + * + * FT_VALIDATE_GSUB :: + * Validate GSUB table. + * + * FT_VALIDATE_JSTF :: + * Validate JSTF table. + * + * FT_VALIDATE_MATH :: + * Validate MATH table. + * + * FT_VALIDATE_OT :: + * Validate all OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF, MATH). + * + */ +#define FT_VALIDATE_BASE 0x0100 +#define FT_VALIDATE_GDEF 0x0200 +#define FT_VALIDATE_GPOS 0x0400 +#define FT_VALIDATE_GSUB 0x0800 +#define FT_VALIDATE_JSTF 0x1000 +#define FT_VALIDATE_MATH 0x2000 + +#define FT_VALIDATE_OT FT_VALIDATE_BASE | \ + FT_VALIDATE_GDEF | \ + FT_VALIDATE_GPOS | \ + FT_VALIDATE_GSUB | \ + FT_VALIDATE_JSTF | \ + FT_VALIDATE_MATH + + /********************************************************************** + * + * @function: + * FT_OpenType_Validate + * + * @description: + * Validate various OpenType tables to assure that all offsets and + * indices are valid. The idea is that a higher-level library that + * actually does the text layout can access those tables without + * error checking (which can be quite time consuming). + * + * @input: + * face :: + * A handle to the input face. + * + * validation_flags :: + * A bit field that specifies the tables to be validated. See + * @FT_VALIDATE_OTXXX for possible values. + * + * @output: + * BASE_table :: + * A pointer to the BASE table. + * + * GDEF_table :: + * A pointer to the GDEF table. + * + * GPOS_table :: + * A pointer to the GPOS table. + * + * GSUB_table :: + * A pointer to the GSUB table. + * + * JSTF_table :: + * A pointer to the JSTF table. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with OpenType fonts, returning an error + * otherwise. + * + * After use, the application should deallocate the five tables with + * @FT_OpenType_Free. A NULL value indicates that the table either + * doesn't exist in the font, or the application hasn't asked for + * validation. + */ + FT_EXPORT( FT_Error ) + FT_OpenType_Validate( FT_Face face, + FT_UInt validation_flags, + FT_Bytes *BASE_table, + FT_Bytes *GDEF_table, + FT_Bytes *GPOS_table, + FT_Bytes *GSUB_table, + FT_Bytes *JSTF_table ); + + /********************************************************************** + * + * @function: + * FT_OpenType_Free + * + * @description: + * Free the buffer allocated by OpenType validator. + * + * @input: + * face :: + * A handle to the input face. + * + * table :: + * The pointer to the buffer that is allocated by + * @FT_OpenType_Validate. + * + * @note: + * This function must be used to free the buffer allocated by + * @FT_OpenType_Validate only. + */ + FT_EXPORT( void ) + FT_OpenType_Free( FT_Face face, + FT_Bytes table ); + + /* */ + + +FT_END_HEADER + +#endif /* FTOTVAL_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftoutln.h b/android/x86/include/freetype/ftoutln.h new file mode 100644 index 00000000..6a645120 --- /dev/null +++ b/android/x86/include/freetype/ftoutln.h @@ -0,0 +1,574 @@ +/***************************************************************************/ +/* */ +/* ftoutln.h */ +/* */ +/* Support for the FT_Outline type used to store glyph shapes of */ +/* most scalable font formats (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTOUTLN_H_ +#define FTOUTLN_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* outline_processing */ + /* */ + /* <Title> */ + /* Outline Processing */ + /* */ + /* <Abstract> */ + /* Functions to create, transform, and render vectorial glyph images. */ + /* */ + /* <Description> */ + /* This section contains routines used to create and destroy scalable */ + /* glyph images known as `outlines'. These can also be measured, */ + /* transformed, and converted into bitmaps and pixmaps. */ + /* */ + /* <Order> */ + /* FT_Outline */ + /* FT_Outline_New */ + /* FT_Outline_Done */ + /* FT_Outline_Copy */ + /* FT_Outline_Translate */ + /* FT_Outline_Transform */ + /* FT_Outline_Embolden */ + /* FT_Outline_EmboldenXY */ + /* FT_Outline_Reverse */ + /* FT_Outline_Check */ + /* */ + /* FT_Outline_Get_CBox */ + /* FT_Outline_Get_BBox */ + /* */ + /* FT_Outline_Get_Bitmap */ + /* FT_Outline_Render */ + /* FT_Outline_Decompose */ + /* FT_Outline_Funcs */ + /* FT_Outline_MoveToFunc */ + /* FT_Outline_LineToFunc */ + /* FT_Outline_ConicToFunc */ + /* FT_Outline_CubicToFunc */ + /* */ + /* FT_Orientation */ + /* FT_Outline_Get_Orientation */ + /* */ + /* FT_OUTLINE_XXX */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Decompose */ + /* */ + /* <Description> */ + /* Walk over an outline's structure to decompose it into individual */ + /* segments and Bézier arcs. This function also emits `move to' */ + /* operations to indicate the start of new contours in the outline. */ + /* */ + /* <Input> */ + /* outline :: A pointer to the source target. */ + /* */ + /* func_interface :: A table of `emitters', i.e., function pointers */ + /* called during decomposition to indicate path */ + /* operations. */ + /* */ + /* <InOut> */ + /* user :: A typeless pointer that is passed to each */ + /* emitter during the decomposition. It can be */ + /* used to store the state during the */ + /* decomposition. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* A contour that contains a single point only is represented by a */ + /* `move to' operation followed by `line to' to the same point. In */ + /* most cases, it is best to filter this out before using the */ + /* outline for stroking purposes (otherwise it would result in a */ + /* visible dot when round caps are used). */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Decompose( FT_Outline* outline, + const FT_Outline_Funcs* func_interface, + void* user ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_New */ + /* */ + /* <Description> */ + /* Create a new outline of a given size. */ + /* */ + /* <Input> */ + /* library :: A handle to the library object from where the */ + /* outline is allocated. Note however that the new */ + /* outline will *not* necessarily be *freed*, when */ + /* destroying the library, by @FT_Done_FreeType. */ + /* */ + /* numPoints :: The maximum number of points within the outline. */ + /* Must be smaller than or equal to 0xFFFF (65535). */ + /* */ + /* numContours :: The maximum number of contours within the outline. */ + /* This value must be in the range 0 to `numPoints'. */ + /* */ + /* <Output> */ + /* anoutline :: A handle to the new outline. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The reason why this function takes a `library' parameter is simply */ + /* to use the library's memory allocator. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_New( FT_Library library, + FT_UInt numPoints, + FT_Int numContours, + FT_Outline *anoutline ); + + + FT_EXPORT( FT_Error ) + FT_Outline_New_Internal( FT_Memory memory, + FT_UInt numPoints, + FT_Int numContours, + FT_Outline *anoutline ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Done */ + /* */ + /* <Description> */ + /* Destroy an outline created with @FT_Outline_New. */ + /* */ + /* <Input> */ + /* library :: A handle of the library object used to allocate the */ + /* outline. */ + /* */ + /* outline :: A pointer to the outline object to be discarded. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* If the outline's `owner' field is not set, only the outline */ + /* descriptor will be released. */ + /* */ + /* The reason why this function takes an `library' parameter is */ + /* simply to use ft_mem_free(). */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Done( FT_Library library, + FT_Outline* outline ); + + + FT_EXPORT( FT_Error ) + FT_Outline_Done_Internal( FT_Memory memory, + FT_Outline* outline ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Check */ + /* */ + /* <Description> */ + /* Check the contents of an outline descriptor. */ + /* */ + /* <Input> */ + /* outline :: A handle to a source outline. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Check( FT_Outline* outline ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Get_CBox */ + /* */ + /* <Description> */ + /* Return an outline's `control box'. The control box encloses all */ + /* the outline's points, including Bézier control points. Though it */ + /* coincides with the exact bounding box for most glyphs, it can be */ + /* slightly larger in some situations (like when rotating an outline */ + /* that contains Bézier outside arcs). */ + /* */ + /* Computing the control box is very fast, while getting the bounding */ + /* box can take much more time as it needs to walk over all segments */ + /* and arcs in the outline. To get the latter, you can use the */ + /* `ftbbox' component, which is dedicated to this single task. */ + /* */ + /* <Input> */ + /* outline :: A pointer to the source outline descriptor. */ + /* */ + /* <Output> */ + /* acbox :: The outline's control box. */ + /* */ + /* <Note> */ + /* See @FT_Glyph_Get_CBox for a discussion of tricky fonts. */ + /* */ + FT_EXPORT( void ) + FT_Outline_Get_CBox( const FT_Outline* outline, + FT_BBox *acbox ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Translate */ + /* */ + /* <Description> */ + /* Apply a simple translation to the points of an outline. */ + /* */ + /* <InOut> */ + /* outline :: A pointer to the target outline descriptor. */ + /* */ + /* <Input> */ + /* xOffset :: The horizontal offset. */ + /* */ + /* yOffset :: The vertical offset. */ + /* */ + FT_EXPORT( void ) + FT_Outline_Translate( const FT_Outline* outline, + FT_Pos xOffset, + FT_Pos yOffset ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Copy */ + /* */ + /* <Description> */ + /* Copy an outline into another one. Both objects must have the */ + /* same sizes (number of points & number of contours) when this */ + /* function is called. */ + /* */ + /* <Input> */ + /* source :: A handle to the source outline. */ + /* */ + /* <Output> */ + /* target :: A handle to the target outline. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Copy( const FT_Outline* source, + FT_Outline *target ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Transform */ + /* */ + /* <Description> */ + /* Apply a simple 2x2 matrix to all of an outline's points. Useful */ + /* for applying rotations, slanting, flipping, etc. */ + /* */ + /* <InOut> */ + /* outline :: A pointer to the target outline descriptor. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to the transformation matrix. */ + /* */ + /* <Note> */ + /* You can use @FT_Outline_Translate if you need to translate the */ + /* outline's points. */ + /* */ + FT_EXPORT( void ) + FT_Outline_Transform( const FT_Outline* outline, + const FT_Matrix* matrix ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Embolden */ + /* */ + /* <Description> */ + /* Embolden an outline. The new outline will be at most 4~times */ + /* `strength' pixels wider and higher. You may think of the left and */ + /* bottom borders as unchanged. */ + /* */ + /* Negative `strength' values to reduce the outline thickness are */ + /* possible also. */ + /* */ + /* <InOut> */ + /* outline :: A handle to the target outline. */ + /* */ + /* <Input> */ + /* strength :: How strong the glyph is emboldened. Expressed in */ + /* 26.6 pixel format. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The used algorithm to increase or decrease the thickness of the */ + /* glyph doesn't change the number of points; this means that certain */ + /* situations like acute angles or intersections are sometimes */ + /* handled incorrectly. */ + /* */ + /* If you need `better' metrics values you should call */ + /* @FT_Outline_Get_CBox or @FT_Outline_Get_BBox. */ + /* */ + /* Example call: */ + /* */ + /* { */ + /* FT_Load_Glyph( face, index, FT_LOAD_DEFAULT ); */ + /* if ( face->glyph->format == FT_GLYPH_FORMAT_OUTLINE ) */ + /* FT_Outline_Embolden( &face->glyph->outline, strength ); */ + /* } */ + /* */ + /* To get meaningful results, font scaling values must be set with */ + /* functions like @FT_Set_Char_Size before calling FT_Render_Glyph. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Embolden( FT_Outline* outline, + FT_Pos strength ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_EmboldenXY */ + /* */ + /* <Description> */ + /* Embolden an outline. The new outline will be `xstrength' pixels */ + /* wider and `ystrength' pixels higher. Otherwise, it is similar to */ + /* @FT_Outline_Embolden, which uses the same strength in both */ + /* directions. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_EmboldenXY( FT_Outline* outline, + FT_Pos xstrength, + FT_Pos ystrength ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Reverse */ + /* */ + /* <Description> */ + /* Reverse the drawing direction of an outline. This is used to */ + /* ensure consistent fill conventions for mirrored glyphs. */ + /* */ + /* <InOut> */ + /* outline :: A pointer to the target outline descriptor. */ + /* */ + /* <Note> */ + /* This function toggles the bit flag @FT_OUTLINE_REVERSE_FILL in */ + /* the outline's `flags' field. */ + /* */ + /* It shouldn't be used by a normal client application, unless it */ + /* knows what it is doing. */ + /* */ + FT_EXPORT( void ) + FT_Outline_Reverse( FT_Outline* outline ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Get_Bitmap */ + /* */ + /* <Description> */ + /* Render an outline within a bitmap. The outline's image is simply */ + /* OR-ed to the target bitmap. */ + /* */ + /* <Input> */ + /* library :: A handle to a FreeType library object. */ + /* */ + /* outline :: A pointer to the source outline descriptor. */ + /* */ + /* <InOut> */ + /* abitmap :: A pointer to the target bitmap descriptor. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function does NOT CREATE the bitmap, it only renders an */ + /* outline image within the one you pass to it! Consequently, the */ + /* various fields in `abitmap' should be set accordingly. */ + /* */ + /* It will use the raster corresponding to the default glyph format. */ + /* */ + /* The value of the `num_grays' field in `abitmap' is ignored. If */ + /* you select the gray-level rasterizer, and you want less than 256 */ + /* gray levels, you have to use @FT_Outline_Render directly. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Get_Bitmap( FT_Library library, + FT_Outline* outline, + const FT_Bitmap *abitmap ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Render */ + /* */ + /* <Description> */ + /* Render an outline within a bitmap using the current scan-convert. */ + /* This function uses an @FT_Raster_Params structure as an argument, */ + /* allowing advanced features like direct composition, translucency, */ + /* etc. */ + /* */ + /* <Input> */ + /* library :: A handle to a FreeType library object. */ + /* */ + /* outline :: A pointer to the source outline descriptor. */ + /* */ + /* <InOut> */ + /* params :: A pointer to an @FT_Raster_Params structure used to */ + /* describe the rendering operation. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You should know what you are doing and how @FT_Raster_Params works */ + /* to use this function. */ + /* */ + /* The field `params.source' will be set to `outline' before the scan */ + /* converter is called, which means that the value you give to it is */ + /* actually ignored. */ + /* */ + /* The gray-level rasterizer always uses 256 gray levels. If you */ + /* want less gray levels, you have to provide your own span callback. */ + /* See the @FT_RASTER_FLAG_DIRECT value of the `flags' field in the */ + /* @FT_Raster_Params structure for more details. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Render( FT_Library library, + FT_Outline* outline, + FT_Raster_Params* params ); + + + /************************************************************************** + * + * @enum: + * FT_Orientation + * + * @description: + * A list of values used to describe an outline's contour orientation. + * + * The TrueType and PostScript specifications use different conventions + * to determine whether outline contours should be filled or unfilled. + * + * @values: + * FT_ORIENTATION_TRUETYPE :: + * According to the TrueType specification, clockwise contours must + * be filled, and counter-clockwise ones must be unfilled. + * + * FT_ORIENTATION_POSTSCRIPT :: + * According to the PostScript specification, counter-clockwise contours + * must be filled, and clockwise ones must be unfilled. + * + * FT_ORIENTATION_FILL_RIGHT :: + * This is identical to @FT_ORIENTATION_TRUETYPE, but is used to + * remember that in TrueType, everything that is to the right of + * the drawing direction of a contour must be filled. + * + * FT_ORIENTATION_FILL_LEFT :: + * This is identical to @FT_ORIENTATION_POSTSCRIPT, but is used to + * remember that in PostScript, everything that is to the left of + * the drawing direction of a contour must be filled. + * + * FT_ORIENTATION_NONE :: + * The orientation cannot be determined. That is, different parts of + * the glyph have different orientation. + * + */ + typedef enum FT_Orientation_ + { + FT_ORIENTATION_TRUETYPE = 0, + FT_ORIENTATION_POSTSCRIPT = 1, + FT_ORIENTATION_FILL_RIGHT = FT_ORIENTATION_TRUETYPE, + FT_ORIENTATION_FILL_LEFT = FT_ORIENTATION_POSTSCRIPT, + FT_ORIENTATION_NONE + + } FT_Orientation; + + + /************************************************************************** + * + * @function: + * FT_Outline_Get_Orientation + * + * @description: + * This function analyzes a glyph outline and tries to compute its + * fill orientation (see @FT_Orientation). This is done by integrating + * the total area covered by the outline. The positive integral + * corresponds to the clockwise orientation and @FT_ORIENTATION_POSTSCRIPT + * is returned. The negative integral corresponds to the counter-clockwise + * orientation and @FT_ORIENTATION_TRUETYPE is returned. + * + * Note that this will return @FT_ORIENTATION_TRUETYPE for empty + * outlines. + * + * @input: + * outline :: + * A handle to the source outline. + * + * @return: + * The orientation. + * + */ + FT_EXPORT( FT_Orientation ) + FT_Outline_Get_Orientation( FT_Outline* outline ); + + /* */ + + +FT_END_HEADER + +#endif /* FTOUTLN_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/android/x86/include/freetype/ftpfr.h b/android/x86/include/freetype/ftpfr.h new file mode 100644 index 00000000..2e1bff2f --- /dev/null +++ b/android/x86/include/freetype/ftpfr.h @@ -0,0 +1,172 @@ +/***************************************************************************/ +/* */ +/* ftpfr.h */ +/* */ +/* FreeType API for accessing PFR-specific data (specification only). */ +/* */ +/* Copyright 2002-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTPFR_H_ +#define FTPFR_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* pfr_fonts */ + /* */ + /* <Title> */ + /* PFR Fonts */ + /* */ + /* <Abstract> */ + /* PFR/TrueDoc specific API. */ + /* */ + /* <Description> */ + /* This section contains the declaration of PFR-specific functions. */ + /* */ + /*************************************************************************/ + + + /********************************************************************** + * + * @function: + * FT_Get_PFR_Metrics + * + * @description: + * Return the outline and metrics resolutions of a given PFR face. + * + * @input: + * face :: Handle to the input face. It can be a non-PFR face. + * + * @output: + * aoutline_resolution :: + * Outline resolution. This is equivalent to `face->units_per_EM' + * for non-PFR fonts. Optional (parameter can be NULL). + * + * ametrics_resolution :: + * Metrics resolution. This is equivalent to `outline_resolution' + * for non-PFR fonts. Optional (parameter can be NULL). + * + * ametrics_x_scale :: + * A 16.16 fixed-point number used to scale distance expressed + * in metrics units to device sub-pixels. This is equivalent to + * `face->size->x_scale', but for metrics only. Optional (parameter + * can be NULL). + * + * ametrics_y_scale :: + * Same as `ametrics_x_scale' but for the vertical direction. + * optional (parameter can be NULL). + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If the input face is not a PFR, this function will return an error. + * However, in all cases, it will return valid values. + */ + FT_EXPORT( FT_Error ) + FT_Get_PFR_Metrics( FT_Face face, + FT_UInt *aoutline_resolution, + FT_UInt *ametrics_resolution, + FT_Fixed *ametrics_x_scale, + FT_Fixed *ametrics_y_scale ); + + + /********************************************************************** + * + * @function: + * FT_Get_PFR_Kerning + * + * @description: + * Return the kerning pair corresponding to two glyphs in a PFR face. + * The distance is expressed in metrics units, unlike the result of + * @FT_Get_Kerning. + * + * @input: + * face :: A handle to the input face. + * + * left :: Index of the left glyph. + * + * right :: Index of the right glyph. + * + * @output: + * avector :: A kerning vector. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function always return distances in original PFR metrics + * units. This is unlike @FT_Get_Kerning with the @FT_KERNING_UNSCALED + * mode, which always returns distances converted to outline units. + * + * You can use the value of the `x_scale' and `y_scale' parameters + * returned by @FT_Get_PFR_Metrics to scale these to device sub-pixels. + */ + FT_EXPORT( FT_Error ) + FT_Get_PFR_Kerning( FT_Face face, + FT_UInt left, + FT_UInt right, + FT_Vector *avector ); + + + /********************************************************************** + * + * @function: + * FT_Get_PFR_Advance + * + * @description: + * Return a given glyph advance, expressed in original metrics units, + * from a PFR font. + * + * @input: + * face :: A handle to the input face. + * + * gindex :: The glyph index. + * + * @output: + * aadvance :: The glyph advance in metrics units. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You can use the `x_scale' or `y_scale' results of @FT_Get_PFR_Metrics + * to convert the advance to device sub-pixels (i.e., 1/64th of pixels). + */ + FT_EXPORT( FT_Error ) + FT_Get_PFR_Advance( FT_Face face, + FT_UInt gindex, + FT_Pos *aadvance ); + + /* */ + + +FT_END_HEADER + +#endif /* FTPFR_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftrender.h b/android/x86/include/freetype/ftrender.h new file mode 100644 index 00000000..9f7ed9e9 --- /dev/null +++ b/android/x86/include/freetype/ftrender.h @@ -0,0 +1,232 @@ +/***************************************************************************/ +/* */ +/* ftrender.h */ +/* */ +/* FreeType renderer modules public interface (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTRENDER_H_ +#define FTRENDER_H_ + + +#include <ft2build.h> +#include FT_MODULE_H +#include FT_GLYPH_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* module_management */ + /* */ + /*************************************************************************/ + + + /* create a new glyph object */ + typedef FT_Error + (*FT_Glyph_InitFunc)( FT_Glyph glyph, + FT_GlyphSlot slot ); + + /* destroys a given glyph object */ + typedef void + (*FT_Glyph_DoneFunc)( FT_Glyph glyph ); + + typedef void + (*FT_Glyph_TransformFunc)( FT_Glyph glyph, + const FT_Matrix* matrix, + const FT_Vector* delta ); + + typedef void + (*FT_Glyph_GetBBoxFunc)( FT_Glyph glyph, + FT_BBox* abbox ); + + typedef FT_Error + (*FT_Glyph_CopyFunc)( FT_Glyph source, + FT_Glyph target ); + + typedef FT_Error + (*FT_Glyph_PrepareFunc)( FT_Glyph glyph, + FT_GlyphSlot slot ); + +/* deprecated */ +#define FT_Glyph_Init_Func FT_Glyph_InitFunc +#define FT_Glyph_Done_Func FT_Glyph_DoneFunc +#define FT_Glyph_Transform_Func FT_Glyph_TransformFunc +#define FT_Glyph_BBox_Func FT_Glyph_GetBBoxFunc +#define FT_Glyph_Copy_Func FT_Glyph_CopyFunc +#define FT_Glyph_Prepare_Func FT_Glyph_PrepareFunc + + + struct FT_Glyph_Class_ + { + FT_Long glyph_size; + FT_Glyph_Format glyph_format; + FT_Glyph_InitFunc glyph_init; + FT_Glyph_DoneFunc glyph_done; + FT_Glyph_CopyFunc glyph_copy; + FT_Glyph_TransformFunc glyph_transform; + FT_Glyph_GetBBoxFunc glyph_bbox; + FT_Glyph_PrepareFunc glyph_prepare; + }; + + + typedef FT_Error + (*FT_Renderer_RenderFunc)( FT_Renderer renderer, + FT_GlyphSlot slot, + FT_UInt mode, + const FT_Vector* origin ); + + typedef FT_Error + (*FT_Renderer_TransformFunc)( FT_Renderer renderer, + FT_GlyphSlot slot, + const FT_Matrix* matrix, + const FT_Vector* delta ); + + + typedef void + (*FT_Renderer_GetCBoxFunc)( FT_Renderer renderer, + FT_GlyphSlot slot, + FT_BBox* cbox ); + + + typedef FT_Error + (*FT_Renderer_SetModeFunc)( FT_Renderer renderer, + FT_ULong mode_tag, + FT_Pointer mode_ptr ); + +/* deprecated identifiers */ +#define FTRenderer_render FT_Renderer_RenderFunc +#define FTRenderer_transform FT_Renderer_TransformFunc +#define FTRenderer_getCBox FT_Renderer_GetCBoxFunc +#define FTRenderer_setMode FT_Renderer_SetModeFunc + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Renderer_Class */ + /* */ + /* <Description> */ + /* The renderer module class descriptor. */ + /* */ + /* <Fields> */ + /* root :: The root @FT_Module_Class fields. */ + /* */ + /* glyph_format :: The glyph image format this renderer handles. */ + /* */ + /* render_glyph :: A method used to render the image that is in a */ + /* given glyph slot into a bitmap. */ + /* */ + /* transform_glyph :: A method used to transform the image that is in */ + /* a given glyph slot. */ + /* */ + /* get_glyph_cbox :: A method used to access the glyph's cbox. */ + /* */ + /* set_mode :: A method used to pass additional parameters. */ + /* */ + /* raster_class :: For @FT_GLYPH_FORMAT_OUTLINE renderers only. */ + /* This is a pointer to its raster's class. */ + /* */ + typedef struct FT_Renderer_Class_ + { + FT_Module_Class root; + + FT_Glyph_Format glyph_format; + + FT_Renderer_RenderFunc render_glyph; + FT_Renderer_TransformFunc transform_glyph; + FT_Renderer_GetCBoxFunc get_glyph_cbox; + FT_Renderer_SetModeFunc set_mode; + + FT_Raster_Funcs* raster_class; + + } FT_Renderer_Class; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Renderer */ + /* */ + /* <Description> */ + /* Retrieve the current renderer for a given glyph format. */ + /* */ + /* <Input> */ + /* library :: A handle to the library object. */ + /* */ + /* format :: The glyph format. */ + /* */ + /* <Return> */ + /* A renderer handle. 0~if none found. */ + /* */ + /* <Note> */ + /* An error will be returned if a module already exists by that name, */ + /* or if the module requires a version of FreeType that is too great. */ + /* */ + /* To add a new renderer, simply use @FT_Add_Module. To retrieve a */ + /* renderer by its name, use @FT_Get_Module. */ + /* */ + FT_EXPORT( FT_Renderer ) + FT_Get_Renderer( FT_Library library, + FT_Glyph_Format format ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Renderer */ + /* */ + /* <Description> */ + /* Set the current renderer to use, and set additional mode. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library object. */ + /* */ + /* <Input> */ + /* renderer :: A handle to the renderer object. */ + /* */ + /* num_params :: The number of additional parameters. */ + /* */ + /* parameters :: Additional parameters. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* In case of success, the renderer will be used to convert glyph */ + /* images in the renderer's known format into bitmaps. */ + /* */ + /* This doesn't change the current renderer for other formats. */ + /* */ + /* Currently, no FreeType renderer module uses `parameters'; you */ + /* should thus always pass NULL as the value. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Renderer( FT_Library library, + FT_Renderer renderer, + FT_UInt num_params, + FT_Parameter* parameters ); + + /* */ + + +FT_END_HEADER + +#endif /* FTRENDER_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftsizes.h b/android/x86/include/freetype/ftsizes.h new file mode 100644 index 00000000..55e0d5cc --- /dev/null +++ b/android/x86/include/freetype/ftsizes.h @@ -0,0 +1,159 @@ +/***************************************************************************/ +/* */ +/* ftsizes.h */ +/* */ +/* FreeType size objects management (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Typical application would normally not need to use these functions. */ + /* However, they have been placed in a public API for the rare cases */ + /* where they are needed. */ + /* */ + /*************************************************************************/ + + +#ifndef FTSIZES_H_ +#define FTSIZES_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* sizes_management */ + /* */ + /* <Title> */ + /* Size Management */ + /* */ + /* <Abstract> */ + /* Managing multiple sizes per face. */ + /* */ + /* <Description> */ + /* When creating a new face object (e.g., with @FT_New_Face), an */ + /* @FT_Size object is automatically created and used to store all */ + /* pixel-size dependent information, available in the `face->size' */ + /* field. */ + /* */ + /* It is however possible to create more sizes for a given face, */ + /* mostly in order to manage several character pixel sizes of the */ + /* same font family and style. See @FT_New_Size and @FT_Done_Size. */ + /* */ + /* Note that @FT_Set_Pixel_Sizes and @FT_Set_Char_Size only */ + /* modify the contents of the current `active' size; you thus need */ + /* to use @FT_Activate_Size to change it. */ + /* */ + /* 99% of applications won't need the functions provided here, */ + /* especially if they use the caching sub-system, so be cautious */ + /* when using these. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Size */ + /* */ + /* <Description> */ + /* Create a new size object from a given face object. */ + /* */ + /* <Input> */ + /* face :: A handle to a parent face object. */ + /* */ + /* <Output> */ + /* asize :: A handle to a new size object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You need to call @FT_Activate_Size in order to select the new size */ + /* for upcoming calls to @FT_Set_Pixel_Sizes, @FT_Set_Char_Size, */ + /* @FT_Load_Glyph, @FT_Load_Char, etc. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Size( FT_Face face, + FT_Size* size ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_Size */ + /* */ + /* <Description> */ + /* Discard a given size object. Note that @FT_Done_Face */ + /* automatically discards all size objects allocated with */ + /* @FT_New_Size. */ + /* */ + /* <Input> */ + /* size :: A handle to a target size object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_Size( FT_Size size ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Activate_Size */ + /* */ + /* <Description> */ + /* Even though it is possible to create several size objects for a */ + /* given face (see @FT_New_Size for details), functions like */ + /* @FT_Load_Glyph or @FT_Load_Char only use the one that has been */ + /* activated last to determine the `current character pixel size'. */ + /* */ + /* This function can be used to `activate' a previously created size */ + /* object. */ + /* */ + /* <Input> */ + /* size :: A handle to a target size object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* If `face' is the size's parent face object, this function changes */ + /* the value of `face->size' to the input size handle. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Activate_Size( FT_Size size ); + + /* */ + + +FT_END_HEADER + +#endif /* FTSIZES_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftsnames.h b/android/x86/include/freetype/ftsnames.h new file mode 100644 index 00000000..a7b51c2c --- /dev/null +++ b/android/x86/include/freetype/ftsnames.h @@ -0,0 +1,200 @@ +/***************************************************************************/ +/* */ +/* ftsnames.h */ +/* */ +/* Simple interface to access SFNT name tables (which are used */ +/* to hold font names, copyright info, notices, etc.) (specification). */ +/* */ +/* This is _not_ used to retrieve glyph names! */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTSNAMES_H_ +#define FTSNAMES_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* sfnt_names */ + /* */ + /* <Title> */ + /* SFNT Names */ + /* */ + /* <Abstract> */ + /* Access the names embedded in TrueType and OpenType files. */ + /* */ + /* <Description> */ + /* The TrueType and OpenType specifications allow the inclusion of */ + /* a special `names table' in font files. This table contains */ + /* textual (and internationalized) information regarding the font, */ + /* like family name, copyright, version, etc. */ + /* */ + /* The definitions below are used to access them if available. */ + /* */ + /* Note that this has nothing to do with glyph names! */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_SfntName */ + /* */ + /* <Description> */ + /* A structure used to model an SFNT `name' table entry. */ + /* */ + /* <Fields> */ + /* platform_id :: The platform ID for `string'. */ + /* */ + /* encoding_id :: The encoding ID for `string'. */ + /* */ + /* language_id :: The language ID for `string'. */ + /* */ + /* name_id :: An identifier for `string'. */ + /* */ + /* string :: The `name' string. Note that its format differs */ + /* depending on the (platform,encoding) pair. It can */ + /* be a Pascal String, a UTF-16 one, etc. */ + /* */ + /* Generally speaking, the string is not */ + /* zero-terminated. Please refer to the TrueType */ + /* specification for details. */ + /* */ + /* string_len :: The length of `string' in bytes. */ + /* */ + /* <Note> */ + /* Possible values for `platform_id', `encoding_id', `language_id', */ + /* and `name_id' are given in the file `ttnameid.h'. For details */ + /* please refer to the TrueType or OpenType specification. */ + /* */ + /* See also @TT_PLATFORM_XXX, @TT_APPLE_ID_XXX, @TT_MAC_ID_XXX, */ + /* @TT_ISO_ID_XXX, and @TT_MS_ID_XXX. */ + /* */ + typedef struct FT_SfntName_ + { + FT_UShort platform_id; + FT_UShort encoding_id; + FT_UShort language_id; + FT_UShort name_id; + + FT_Byte* string; /* this string is *not* null-terminated! */ + FT_UInt string_len; /* in bytes */ + + } FT_SfntName; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Sfnt_Name_Count */ + /* */ + /* <Description> */ + /* Retrieve the number of name strings in the SFNT `name' table. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* <Return> */ + /* The number of strings in the `name' table. */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Get_Sfnt_Name_Count( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Sfnt_Name */ + /* */ + /* <Description> */ + /* Retrieve a string of the SFNT `name' table for a given index. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* idx :: The index of the `name' string. */ + /* */ + /* <Output> */ + /* aname :: The indexed @FT_SfntName structure. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The `string' array returned in the `aname' structure is not */ + /* null-terminated. The application should deallocate it if it is no */ + /* longer in use. */ + /* */ + /* Use @FT_Get_Sfnt_Name_Count to get the total number of available */ + /* `name' table entries, then do a loop until you get the right */ + /* platform, encoding, and name ID. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Sfnt_Name( FT_Face face, + FT_UInt idx, + FT_SfntName *aname ); + + + /*************************************************************************** + * + * @constant: + * FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY + * + * @description: + * A constant used as the tag of @FT_Parameter structures to make + * FT_Open_Face() ignore preferred family subfamily names in `name' + * table since OpenType version 1.4. For backwards compatibility with + * legacy systems that have a 4-face-per-family restriction. + * + */ +#define FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY FT_MAKE_TAG( 'i', 'g', 'p', 'f' ) + + + /*************************************************************************** + * + * @constant: + * FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY + * + * @description: + * A constant used as the tag of @FT_Parameter structures to make + * FT_Open_Face() ignore preferred subfamily names in `name' table since + * OpenType version 1.4. For backwards compatibility with legacy + * systems that have a 4-face-per-family restriction. + * + */ +#define FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY FT_MAKE_TAG( 'i', 'g', 'p', 's' ) + + /* */ + + +FT_END_HEADER + +#endif /* FTSNAMES_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftstroke.h b/android/x86/include/freetype/ftstroke.h new file mode 100644 index 00000000..b3b9922d --- /dev/null +++ b/android/x86/include/freetype/ftstroke.h @@ -0,0 +1,785 @@ +/***************************************************************************/ +/* */ +/* ftstroke.h */ +/* */ +/* FreeType path stroker (specification). */ +/* */ +/* Copyright 2002-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTSTROKE_H_ +#define FTSTROKE_H_ + +#include <ft2build.h> +#include FT_OUTLINE_H +#include FT_GLYPH_H + + +FT_BEGIN_HEADER + + + /************************************************************************ + * + * @section: + * glyph_stroker + * + * @title: + * Glyph Stroker + * + * @abstract: + * Generating bordered and stroked glyphs. + * + * @description: + * This component generates stroked outlines of a given vectorial + * glyph. It also allows you to retrieve the `outside' and/or the + * `inside' borders of the stroke. + * + * This can be useful to generate `bordered' glyph, i.e., glyphs + * displayed with a coloured (and anti-aliased) border around their + * shape. + * + * @order: + * FT_Stroker + * + * FT_Stroker_LineJoin + * FT_Stroker_LineCap + * FT_StrokerBorder + * + * FT_Outline_GetInsideBorder + * FT_Outline_GetOutsideBorder + * + * FT_Glyph_Stroke + * FT_Glyph_StrokeBorder + * + * FT_Stroker_New + * FT_Stroker_Set + * FT_Stroker_Rewind + * FT_Stroker_ParseOutline + * FT_Stroker_Done + * + * FT_Stroker_BeginSubPath + * FT_Stroker_EndSubPath + * + * FT_Stroker_LineTo + * FT_Stroker_ConicTo + * FT_Stroker_CubicTo + * + * FT_Stroker_GetBorderCounts + * FT_Stroker_ExportBorder + * FT_Stroker_GetCounts + * FT_Stroker_Export + * + */ + + + /************************************************************** + * + * @type: + * FT_Stroker + * + * @description: + * Opaque handle to a path stroker object. + */ + typedef struct FT_StrokerRec_* FT_Stroker; + + + /************************************************************** + * + * @enum: + * FT_Stroker_LineJoin + * + * @description: + * These values determine how two joining lines are rendered + * in a stroker. + * + * @values: + * FT_STROKER_LINEJOIN_ROUND :: + * Used to render rounded line joins. Circular arcs are used + * to join two lines smoothly. + * + * FT_STROKER_LINEJOIN_BEVEL :: + * Used to render beveled line joins. The outer corner of + * the joined lines is filled by enclosing the triangular + * region of the corner with a straight line between the + * outer corners of each stroke. + * + * FT_STROKER_LINEJOIN_MITER_FIXED :: + * Used to render mitered line joins, with fixed bevels if the + * miter limit is exceeded. The outer edges of the strokes + * for the two segments are extended until they meet at an + * angle. If the segments meet at too sharp an angle (such + * that the miter would extend from the intersection of the + * segments a distance greater than the product of the miter + * limit value and the border radius), then a bevel join (see + * above) is used instead. This prevents long spikes being + * created. FT_STROKER_LINEJOIN_MITER_FIXED generates a miter + * line join as used in PostScript and PDF. + * + * FT_STROKER_LINEJOIN_MITER_VARIABLE :: + * FT_STROKER_LINEJOIN_MITER :: + * Used to render mitered line joins, with variable bevels if + * the miter limit is exceeded. The intersection of the + * strokes is clipped at a line perpendicular to the bisector + * of the angle between the strokes, at the distance from the + * intersection of the segments equal to the product of the + * miter limit value and the border radius. This prevents + * long spikes being created. + * FT_STROKER_LINEJOIN_MITER_VARIABLE generates a mitered line + * join as used in XPS. FT_STROKER_LINEJOIN_MITER is an alias + * for FT_STROKER_LINEJOIN_MITER_VARIABLE, retained for + * backwards compatibility. + */ + typedef enum FT_Stroker_LineJoin_ + { + FT_STROKER_LINEJOIN_ROUND = 0, + FT_STROKER_LINEJOIN_BEVEL = 1, + FT_STROKER_LINEJOIN_MITER_VARIABLE = 2, + FT_STROKER_LINEJOIN_MITER = FT_STROKER_LINEJOIN_MITER_VARIABLE, + FT_STROKER_LINEJOIN_MITER_FIXED = 3 + + } FT_Stroker_LineJoin; + + + /************************************************************** + * + * @enum: + * FT_Stroker_LineCap + * + * @description: + * These values determine how the end of opened sub-paths are + * rendered in a stroke. + * + * @values: + * FT_STROKER_LINECAP_BUTT :: + * The end of lines is rendered as a full stop on the last + * point itself. + * + * FT_STROKER_LINECAP_ROUND :: + * The end of lines is rendered as a half-circle around the + * last point. + * + * FT_STROKER_LINECAP_SQUARE :: + * The end of lines is rendered as a square around the + * last point. + */ + typedef enum FT_Stroker_LineCap_ + { + FT_STROKER_LINECAP_BUTT = 0, + FT_STROKER_LINECAP_ROUND, + FT_STROKER_LINECAP_SQUARE + + } FT_Stroker_LineCap; + + + /************************************************************** + * + * @enum: + * FT_StrokerBorder + * + * @description: + * These values are used to select a given stroke border + * in @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder. + * + * @values: + * FT_STROKER_BORDER_LEFT :: + * Select the left border, relative to the drawing direction. + * + * FT_STROKER_BORDER_RIGHT :: + * Select the right border, relative to the drawing direction. + * + * @note: + * Applications are generally interested in the `inside' and `outside' + * borders. However, there is no direct mapping between these and the + * `left' and `right' ones, since this really depends on the glyph's + * drawing orientation, which varies between font formats. + * + * You can however use @FT_Outline_GetInsideBorder and + * @FT_Outline_GetOutsideBorder to get these. + */ + typedef enum FT_StrokerBorder_ + { + FT_STROKER_BORDER_LEFT = 0, + FT_STROKER_BORDER_RIGHT + + } FT_StrokerBorder; + + + /************************************************************** + * + * @function: + * FT_Outline_GetInsideBorder + * + * @description: + * Retrieve the @FT_StrokerBorder value corresponding to the + * `inside' borders of a given outline. + * + * @input: + * outline :: + * The source outline handle. + * + * @return: + * The border index. @FT_STROKER_BORDER_RIGHT for empty or invalid + * outlines. + */ + FT_EXPORT( FT_StrokerBorder ) + FT_Outline_GetInsideBorder( FT_Outline* outline ); + + + /************************************************************** + * + * @function: + * FT_Outline_GetOutsideBorder + * + * @description: + * Retrieve the @FT_StrokerBorder value corresponding to the + * `outside' borders of a given outline. + * + * @input: + * outline :: + * The source outline handle. + * + * @return: + * The border index. @FT_STROKER_BORDER_LEFT for empty or invalid + * outlines. + */ + FT_EXPORT( FT_StrokerBorder ) + FT_Outline_GetOutsideBorder( FT_Outline* outline ); + + + /************************************************************** + * + * @function: + * FT_Stroker_New + * + * @description: + * Create a new stroker object. + * + * @input: + * library :: + * FreeType library handle. + * + * @output: + * astroker :: + * A new stroker object handle. NULL in case of error. + * + * @return: + * FreeType error code. 0~means success. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_New( FT_Library library, + FT_Stroker *astroker ); + + + /************************************************************** + * + * @function: + * FT_Stroker_Set + * + * @description: + * Reset a stroker object's attributes. + * + * @input: + * stroker :: + * The target stroker handle. + * + * radius :: + * The border radius. + * + * line_cap :: + * The line cap style. + * + * line_join :: + * The line join style. + * + * miter_limit :: + * The miter limit for the FT_STROKER_LINEJOIN_MITER_FIXED and + * FT_STROKER_LINEJOIN_MITER_VARIABLE line join styles, + * expressed as 16.16 fixed-point value. + * + * @note: + * The radius is expressed in the same units as the outline + * coordinates. + * + * This function calls @FT_Stroker_Rewind automatically. + */ + FT_EXPORT( void ) + FT_Stroker_Set( FT_Stroker stroker, + FT_Fixed radius, + FT_Stroker_LineCap line_cap, + FT_Stroker_LineJoin line_join, + FT_Fixed miter_limit ); + + + /************************************************************** + * + * @function: + * FT_Stroker_Rewind + * + * @description: + * Reset a stroker object without changing its attributes. + * You should call this function before beginning a new + * series of calls to @FT_Stroker_BeginSubPath or + * @FT_Stroker_EndSubPath. + * + * @input: + * stroker :: + * The target stroker handle. + */ + FT_EXPORT( void ) + FT_Stroker_Rewind( FT_Stroker stroker ); + + + /************************************************************** + * + * @function: + * FT_Stroker_ParseOutline + * + * @description: + * A convenience function used to parse a whole outline with + * the stroker. The resulting outline(s) can be retrieved + * later by functions like @FT_Stroker_GetCounts and @FT_Stroker_Export. + * + * @input: + * stroker :: + * The target stroker handle. + * + * outline :: + * The source outline. + * + * opened :: + * A boolean. If~1, the outline is treated as an open path instead + * of a closed one. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If `opened' is~0 (the default), the outline is treated as a closed + * path, and the stroker generates two distinct `border' outlines. + * + * If `opened' is~1, the outline is processed as an open path, and the + * stroker generates a single `stroke' outline. + * + * This function calls @FT_Stroker_Rewind automatically. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_ParseOutline( FT_Stroker stroker, + FT_Outline* outline, + FT_Bool opened ); + + + /************************************************************** + * + * @function: + * FT_Stroker_BeginSubPath + * + * @description: + * Start a new sub-path in the stroker. + * + * @input: + * stroker :: + * The target stroker handle. + * + * to :: + * A pointer to the start vector. + * + * open :: + * A boolean. If~1, the sub-path is treated as an open one. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function is useful when you need to stroke a path that is + * not stored as an @FT_Outline object. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_BeginSubPath( FT_Stroker stroker, + FT_Vector* to, + FT_Bool open ); + + + /************************************************************** + * + * @function: + * FT_Stroker_EndSubPath + * + * @description: + * Close the current sub-path in the stroker. + * + * @input: + * stroker :: + * The target stroker handle. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You should call this function after @FT_Stroker_BeginSubPath. + * If the subpath was not `opened', this function `draws' a + * single line segment to the start position when needed. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_EndSubPath( FT_Stroker stroker ); + + + /************************************************************** + * + * @function: + * FT_Stroker_LineTo + * + * @description: + * `Draw' a single line segment in the stroker's current sub-path, + * from the last position. + * + * @input: + * stroker :: + * The target stroker handle. + * + * to :: + * A pointer to the destination point. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You should call this function between @FT_Stroker_BeginSubPath and + * @FT_Stroker_EndSubPath. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_LineTo( FT_Stroker stroker, + FT_Vector* to ); + + + /************************************************************** + * + * @function: + * FT_Stroker_ConicTo + * + * @description: + * `Draw' a single quadratic Bézier in the stroker's current sub-path, + * from the last position. + * + * @input: + * stroker :: + * The target stroker handle. + * + * control :: + * A pointer to a Bézier control point. + * + * to :: + * A pointer to the destination point. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You should call this function between @FT_Stroker_BeginSubPath and + * @FT_Stroker_EndSubPath. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_ConicTo( FT_Stroker stroker, + FT_Vector* control, + FT_Vector* to ); + + + /************************************************************** + * + * @function: + * FT_Stroker_CubicTo + * + * @description: + * `Draw' a single cubic Bézier in the stroker's current sub-path, + * from the last position. + * + * @input: + * stroker :: + * The target stroker handle. + * + * control1 :: + * A pointer to the first Bézier control point. + * + * control2 :: + * A pointer to second Bézier control point. + * + * to :: + * A pointer to the destination point. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You should call this function between @FT_Stroker_BeginSubPath and + * @FT_Stroker_EndSubPath. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_CubicTo( FT_Stroker stroker, + FT_Vector* control1, + FT_Vector* control2, + FT_Vector* to ); + + + /************************************************************** + * + * @function: + * FT_Stroker_GetBorderCounts + * + * @description: + * Call this function once you have finished parsing your paths + * with the stroker. It returns the number of points and + * contours necessary to export one of the `border' or `stroke' + * outlines generated by the stroker. + * + * @input: + * stroker :: + * The target stroker handle. + * + * border :: + * The border index. + * + * @output: + * anum_points :: + * The number of points. + * + * anum_contours :: + * The number of contours. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * When an outline, or a sub-path, is `closed', the stroker generates + * two independent `border' outlines, named `left' and `right'. + * + * When the outline, or a sub-path, is `opened', the stroker merges + * the `border' outlines with caps. The `left' border receives all + * points, while the `right' border becomes empty. + * + * Use the function @FT_Stroker_GetCounts instead if you want to + * retrieve the counts associated to both borders. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_GetBorderCounts( FT_Stroker stroker, + FT_StrokerBorder border, + FT_UInt *anum_points, + FT_UInt *anum_contours ); + + + /************************************************************** + * + * @function: + * FT_Stroker_ExportBorder + * + * @description: + * Call this function after @FT_Stroker_GetBorderCounts to + * export the corresponding border to your own @FT_Outline + * structure. + * + * Note that this function appends the border points and + * contours to your outline, but does not try to resize its + * arrays. + * + * @input: + * stroker :: + * The target stroker handle. + * + * border :: + * The border index. + * + * outline :: + * The target outline handle. + * + * @note: + * Always call this function after @FT_Stroker_GetBorderCounts to + * get sure that there is enough room in your @FT_Outline object to + * receive all new data. + * + * When an outline, or a sub-path, is `closed', the stroker generates + * two independent `border' outlines, named `left' and `right'. + * + * When the outline, or a sub-path, is `opened', the stroker merges + * the `border' outlines with caps. The `left' border receives all + * points, while the `right' border becomes empty. + * + * Use the function @FT_Stroker_Export instead if you want to + * retrieve all borders at once. + */ + FT_EXPORT( void ) + FT_Stroker_ExportBorder( FT_Stroker stroker, + FT_StrokerBorder border, + FT_Outline* outline ); + + + /************************************************************** + * + * @function: + * FT_Stroker_GetCounts + * + * @description: + * Call this function once you have finished parsing your paths + * with the stroker. It returns the number of points and + * contours necessary to export all points/borders from the stroked + * outline/path. + * + * @input: + * stroker :: + * The target stroker handle. + * + * @output: + * anum_points :: + * The number of points. + * + * anum_contours :: + * The number of contours. + * + * @return: + * FreeType error code. 0~means success. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_GetCounts( FT_Stroker stroker, + FT_UInt *anum_points, + FT_UInt *anum_contours ); + + + /************************************************************** + * + * @function: + * FT_Stroker_Export + * + * @description: + * Call this function after @FT_Stroker_GetBorderCounts to + * export all borders to your own @FT_Outline structure. + * + * Note that this function appends the border points and + * contours to your outline, but does not try to resize its + * arrays. + * + * @input: + * stroker :: + * The target stroker handle. + * + * outline :: + * The target outline handle. + */ + FT_EXPORT( void ) + FT_Stroker_Export( FT_Stroker stroker, + FT_Outline* outline ); + + + /************************************************************** + * + * @function: + * FT_Stroker_Done + * + * @description: + * Destroy a stroker object. + * + * @input: + * stroker :: + * A stroker handle. Can be NULL. + */ + FT_EXPORT( void ) + FT_Stroker_Done( FT_Stroker stroker ); + + + /************************************************************** + * + * @function: + * FT_Glyph_Stroke + * + * @description: + * Stroke a given outline glyph object with a given stroker. + * + * @inout: + * pglyph :: + * Source glyph handle on input, new glyph handle on output. + * + * @input: + * stroker :: + * A stroker handle. + * + * destroy :: + * A Boolean. If~1, the source glyph object is destroyed + * on success. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source glyph is untouched in case of error. + * + * Adding stroke may yield a significantly wider and taller glyph + * depending on how large of a radius was used to stroke the glyph. You + * may need to manually adjust horizontal and vertical advance amounts + * to account for this added size. + */ + FT_EXPORT( FT_Error ) + FT_Glyph_Stroke( FT_Glyph *pglyph, + FT_Stroker stroker, + FT_Bool destroy ); + + + /************************************************************** + * + * @function: + * FT_Glyph_StrokeBorder + * + * @description: + * Stroke a given outline glyph object with a given stroker, but + * only return either its inside or outside border. + * + * @inout: + * pglyph :: + * Source glyph handle on input, new glyph handle on output. + * + * @input: + * stroker :: + * A stroker handle. + * + * inside :: + * A Boolean. If~1, return the inside border, otherwise + * the outside border. + * + * destroy :: + * A Boolean. If~1, the source glyph object is destroyed + * on success. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source glyph is untouched in case of error. + * + * Adding stroke may yield a significantly wider and taller glyph + * depending on how large of a radius was used to stroke the glyph. You + * may need to manually adjust horizontal and vertical advance amounts + * to account for this added size. + */ + FT_EXPORT( FT_Error ) + FT_Glyph_StrokeBorder( FT_Glyph *pglyph, + FT_Stroker stroker, + FT_Bool inside, + FT_Bool destroy ); + + /* */ + +FT_END_HEADER + +#endif /* FTSTROKE_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/android/x86/include/freetype/ftsynth.h b/android/x86/include/freetype/ftsynth.h new file mode 100644 index 00000000..fdfcb691 --- /dev/null +++ b/android/x86/include/freetype/ftsynth.h @@ -0,0 +1,84 @@ +/***************************************************************************/ +/* */ +/* ftsynth.h */ +/* */ +/* FreeType synthesizing code for emboldening and slanting */ +/* (specification). */ +/* */ +/* Copyright 2000-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********* *********/ + /********* WARNING, THIS IS ALPHA CODE! THIS API *********/ + /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/ + /********* FREETYPE DEVELOPMENT TEAM *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /* Main reason for not lifting the functions in this module to a */ + /* `standard' API is that the used parameters for emboldening and */ + /* slanting are not configurable. Consider the functions as a */ + /* code resource that should be copied into the application and */ + /* adapted to the particular needs. */ + + +#ifndef FTSYNTH_H_ +#define FTSYNTH_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /* Embolden a glyph by a `reasonable' value (which is highly a matter of */ + /* taste). This function is actually a convenience function, providing */ + /* a wrapper for @FT_Outline_Embolden and @FT_Bitmap_Embolden. */ + /* */ + /* For emboldened outlines the height, width, and advance metrics are */ + /* increased by the strength of the emboldening -- this even affects */ + /* mono-width fonts! */ + /* */ + /* You can also call @FT_Outline_Get_CBox to get precise values. */ + FT_EXPORT( void ) + FT_GlyphSlot_Embolden( FT_GlyphSlot slot ); + + /* Slant an outline glyph to the right by about 12 degrees. */ + FT_EXPORT( void ) + FT_GlyphSlot_Oblique( FT_GlyphSlot slot ); + + /* */ + + +FT_END_HEADER + +#endif /* FTSYNTH_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftsystem.h b/android/x86/include/freetype/ftsystem.h new file mode 100644 index 00000000..908ae07f --- /dev/null +++ b/android/x86/include/freetype/ftsystem.h @@ -0,0 +1,355 @@ +/***************************************************************************/ +/* */ +/* ftsystem.h */ +/* */ +/* FreeType low-level system interface definition (specification). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTSYSTEM_H_ +#define FTSYSTEM_H_ + + +#include <ft2build.h> + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* system_interface */ + /* */ + /* <Title> */ + /* System Interface */ + /* */ + /* <Abstract> */ + /* How FreeType manages memory and i/o. */ + /* */ + /* <Description> */ + /* This section contains various definitions related to memory */ + /* management and i/o access. You need to understand this */ + /* information if you want to use a custom memory manager or you own */ + /* i/o streams. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* M E M O R Y M A N A G E M E N T */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @type: + * FT_Memory + * + * @description: + * A handle to a given memory manager object, defined with an + * @FT_MemoryRec structure. + * + */ + typedef struct FT_MemoryRec_* FT_Memory; + + + /************************************************************************* + * + * @functype: + * FT_Alloc_Func + * + * @description: + * A function used to allocate `size' bytes from `memory'. + * + * @input: + * memory :: + * A handle to the source memory manager. + * + * size :: + * The size in bytes to allocate. + * + * @return: + * Address of new memory block. 0~in case of failure. + * + */ + typedef void* + (*FT_Alloc_Func)( FT_Memory memory, + long size ); + + + /************************************************************************* + * + * @functype: + * FT_Free_Func + * + * @description: + * A function used to release a given block of memory. + * + * @input: + * memory :: + * A handle to the source memory manager. + * + * block :: + * The address of the target memory block. + * + */ + typedef void + (*FT_Free_Func)( FT_Memory memory, + void* block ); + + + /************************************************************************* + * + * @functype: + * FT_Realloc_Func + * + * @description: + * A function used to re-allocate a given block of memory. + * + * @input: + * memory :: + * A handle to the source memory manager. + * + * cur_size :: + * The block's current size in bytes. + * + * new_size :: + * The block's requested new size. + * + * block :: + * The block's current address. + * + * @return: + * New block address. 0~in case of memory shortage. + * + * @note: + * In case of error, the old block must still be available. + * + */ + typedef void* + (*FT_Realloc_Func)( FT_Memory memory, + long cur_size, + long new_size, + void* block ); + + + /************************************************************************* + * + * @struct: + * FT_MemoryRec + * + * @description: + * A structure used to describe a given memory manager to FreeType~2. + * + * @fields: + * user :: + * A generic typeless pointer for user data. + * + * alloc :: + * A pointer type to an allocation function. + * + * free :: + * A pointer type to an memory freeing function. + * + * realloc :: + * A pointer type to a reallocation function. + * + */ + struct FT_MemoryRec_ + { + void* user; + FT_Alloc_Func alloc; + FT_Free_Func free; + FT_Realloc_Func realloc; + }; + + + /*************************************************************************/ + /* */ + /* I / O M A N A G E M E N T */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @type: + * FT_Stream + * + * @description: + * A handle to an input stream. + * + * @also: + * See @FT_StreamRec for the publicly accessible fields of a given + * stream object. + * + */ + typedef struct FT_StreamRec_* FT_Stream; + + + /************************************************************************* + * + * @struct: + * FT_StreamDesc + * + * @description: + * A union type used to store either a long or a pointer. This is used + * to store a file descriptor or a `FILE*' in an input stream. + * + */ + typedef union FT_StreamDesc_ + { + long value; + void* pointer; + + } FT_StreamDesc; + + + /************************************************************************* + * + * @functype: + * FT_Stream_IoFunc + * + * @description: + * A function used to seek and read data from a given input stream. + * + * @input: + * stream :: + * A handle to the source stream. + * + * offset :: + * The offset of read in stream (always from start). + * + * buffer :: + * The address of the read buffer. + * + * count :: + * The number of bytes to read from the stream. + * + * @return: + * The number of bytes effectively read by the stream. + * + * @note: + * This function might be called to perform a seek or skip operation + * with a `count' of~0. A non-zero return value then indicates an + * error. + * + */ + typedef unsigned long + (*FT_Stream_IoFunc)( FT_Stream stream, + unsigned long offset, + unsigned char* buffer, + unsigned long count ); + + + /************************************************************************* + * + * @functype: + * FT_Stream_CloseFunc + * + * @description: + * A function used to close a given input stream. + * + * @input: + * stream :: + * A handle to the target stream. + * + */ + typedef void + (*FT_Stream_CloseFunc)( FT_Stream stream ); + + + /************************************************************************* + * + * @struct: + * FT_StreamRec + * + * @description: + * A structure used to describe an input stream. + * + * @input: + * base :: + * For memory-based streams, this is the address of the first stream + * byte in memory. This field should always be set to NULL for + * disk-based streams. + * + * size :: + * The stream size in bytes. + * + * In case of compressed streams where the size is unknown before + * actually doing the decompression, the value is set to 0x7FFFFFFF. + * (Note that this size value can occur for normal streams also; it is + * thus just a hint.) + * + * pos :: + * The current position within the stream. + * + * descriptor :: + * This field is a union that can hold an integer or a pointer. It is + * used by stream implementations to store file descriptors or `FILE*' + * pointers. + * + * pathname :: + * This field is completely ignored by FreeType. However, it is often + * useful during debugging to use it to store the stream's filename + * (where available). + * + * read :: + * The stream's input function. + * + * close :: + * The stream's close function. + * + * memory :: + * The memory manager to use to preload frames. This is set + * internally by FreeType and shouldn't be touched by stream + * implementations. + * + * cursor :: + * This field is set and used internally by FreeType when parsing + * frames. + * + * limit :: + * This field is set and used internally by FreeType when parsing + * frames. + * + */ + typedef struct FT_StreamRec_ + { + unsigned char* base; + unsigned long size; + unsigned long pos; + + FT_StreamDesc descriptor; + FT_StreamDesc pathname; + FT_Stream_IoFunc read; + FT_Stream_CloseFunc close; + + FT_Memory memory; + unsigned char* cursor; + unsigned char* limit; + + } FT_StreamRec; + + /* */ + + +FT_END_HEADER + +#endif /* FTSYSTEM_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/fttrigon.h b/android/x86/include/freetype/fttrigon.h new file mode 100644 index 00000000..f789b524 --- /dev/null +++ b/android/x86/include/freetype/fttrigon.h @@ -0,0 +1,350 @@ +/***************************************************************************/ +/* */ +/* fttrigon.h */ +/* */ +/* FreeType trigonometric functions (specification). */ +/* */ +/* Copyright 2001-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTTRIGON_H_ +#define FTTRIGON_H_ + +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* computations */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @type: + * FT_Angle + * + * @description: + * This type is used to model angle values in FreeType. Note that the + * angle is a 16.16 fixed-point value expressed in degrees. + * + */ + typedef FT_Fixed FT_Angle; + + + /************************************************************************* + * + * @macro: + * FT_ANGLE_PI + * + * @description: + * The angle pi expressed in @FT_Angle units. + * + */ +#define FT_ANGLE_PI ( 180L << 16 ) + + + /************************************************************************* + * + * @macro: + * FT_ANGLE_2PI + * + * @description: + * The angle 2*pi expressed in @FT_Angle units. + * + */ +#define FT_ANGLE_2PI ( FT_ANGLE_PI * 2 ) + + + /************************************************************************* + * + * @macro: + * FT_ANGLE_PI2 + * + * @description: + * The angle pi/2 expressed in @FT_Angle units. + * + */ +#define FT_ANGLE_PI2 ( FT_ANGLE_PI / 2 ) + + + /************************************************************************* + * + * @macro: + * FT_ANGLE_PI4 + * + * @description: + * The angle pi/4 expressed in @FT_Angle units. + * + */ +#define FT_ANGLE_PI4 ( FT_ANGLE_PI / 4 ) + + + /************************************************************************* + * + * @function: + * FT_Sin + * + * @description: + * Return the sinus of a given angle in fixed-point format. + * + * @input: + * angle :: + * The input angle. + * + * @return: + * The sinus value. + * + * @note: + * If you need both the sinus and cosinus for a given angle, use the + * function @FT_Vector_Unit. + * + */ + FT_EXPORT( FT_Fixed ) + FT_Sin( FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Cos + * + * @description: + * Return the cosinus of a given angle in fixed-point format. + * + * @input: + * angle :: + * The input angle. + * + * @return: + * The cosinus value. + * + * @note: + * If you need both the sinus and cosinus for a given angle, use the + * function @FT_Vector_Unit. + * + */ + FT_EXPORT( FT_Fixed ) + FT_Cos( FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Tan + * + * @description: + * Return the tangent of a given angle in fixed-point format. + * + * @input: + * angle :: + * The input angle. + * + * @return: + * The tangent value. + * + */ + FT_EXPORT( FT_Fixed ) + FT_Tan( FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Atan2 + * + * @description: + * Return the arc-tangent corresponding to a given vector (x,y) in + * the 2d plane. + * + * @input: + * x :: + * The horizontal vector coordinate. + * + * y :: + * The vertical vector coordinate. + * + * @return: + * The arc-tangent value (i.e. angle). + * + */ + FT_EXPORT( FT_Angle ) + FT_Atan2( FT_Fixed x, + FT_Fixed y ); + + + /************************************************************************* + * + * @function: + * FT_Angle_Diff + * + * @description: + * Return the difference between two angles. The result is always + * constrained to the ]-PI..PI] interval. + * + * @input: + * angle1 :: + * First angle. + * + * angle2 :: + * Second angle. + * + * @return: + * Constrained value of `value2-value1'. + * + */ + FT_EXPORT( FT_Angle ) + FT_Angle_Diff( FT_Angle angle1, + FT_Angle angle2 ); + + + /************************************************************************* + * + * @function: + * FT_Vector_Unit + * + * @description: + * Return the unit vector corresponding to a given angle. After the + * call, the value of `vec.x' will be `cos(angle)', and the value of + * `vec.y' will be `sin(angle)'. + * + * This function is useful to retrieve both the sinus and cosinus of a + * given angle quickly. + * + * @output: + * vec :: + * The address of target vector. + * + * @input: + * angle :: + * The input angle. + * + */ + FT_EXPORT( void ) + FT_Vector_Unit( FT_Vector* vec, + FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Vector_Rotate + * + * @description: + * Rotate a vector by a given angle. + * + * @inout: + * vec :: + * The address of target vector. + * + * @input: + * angle :: + * The input angle. + * + */ + FT_EXPORT( void ) + FT_Vector_Rotate( FT_Vector* vec, + FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Vector_Length + * + * @description: + * Return the length of a given vector. + * + * @input: + * vec :: + * The address of target vector. + * + * @return: + * The vector length, expressed in the same units that the original + * vector coordinates. + * + */ + FT_EXPORT( FT_Fixed ) + FT_Vector_Length( FT_Vector* vec ); + + + /************************************************************************* + * + * @function: + * FT_Vector_Polarize + * + * @description: + * Compute both the length and angle of a given vector. + * + * @input: + * vec :: + * The address of source vector. + * + * @output: + * length :: + * The vector length. + * + * angle :: + * The vector angle. + * + */ + FT_EXPORT( void ) + FT_Vector_Polarize( FT_Vector* vec, + FT_Fixed *length, + FT_Angle *angle ); + + + /************************************************************************* + * + * @function: + * FT_Vector_From_Polar + * + * @description: + * Compute vector coordinates from a length and angle. + * + * @output: + * vec :: + * The address of source vector. + * + * @input: + * length :: + * The vector length. + * + * angle :: + * The vector angle. + * + */ + FT_EXPORT( void ) + FT_Vector_From_Polar( FT_Vector* vec, + FT_Fixed length, + FT_Angle angle ); + + /* */ + + +FT_END_HEADER + +#endif /* FTTRIGON_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftttdrv.h b/android/x86/include/freetype/ftttdrv.h new file mode 100644 index 00000000..6c02e657 --- /dev/null +++ b/android/x86/include/freetype/ftttdrv.h @@ -0,0 +1,310 @@ +/***************************************************************************/ +/* */ +/* ftttdrv.h */ +/* */ +/* FreeType API for controlling the TrueType driver */ +/* (specification only). */ +/* */ +/* Copyright 2013-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTTTDRV_H_ +#define FTTTDRV_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /************************************************************************** + * + * @section: + * tt_driver + * + * @title: + * The TrueType driver + * + * @abstract: + * Controlling the TrueType driver module. + * + * @description: + * While FreeType's TrueType driver doesn't expose API functions by + * itself, it is possible to control its behaviour with @FT_Property_Set + * and @FT_Property_Get. The following lists the available properties + * together with the necessary macros and structures. + * + * The TrueType driver's module name is `truetype'. + * + * We start with a list of definitions, kindly provided by Greg + * Hitchcock. + * + * _Bi-Level_ _Rendering_ + * + * Monochromatic rendering, exclusively used in the early days of + * TrueType by both Apple and Microsoft. Microsoft's GDI interface + * supported hinting of the right-side bearing point, such that the + * advance width could be non-linear. Most often this was done to + * achieve some level of glyph symmetry. To enable reasonable + * performance (e.g., not having to run hinting on all glyphs just to + * get the widths) there was a bit in the head table indicating if the + * side bearing was hinted, and additional tables, `hdmx' and `LTSH', to + * cache hinting widths across multiple sizes and device aspect ratios. + * + * _Font_ _Smoothing_ + * + * Microsoft's GDI implementation of anti-aliasing. Not traditional + * anti-aliasing as the outlines were hinted before the sampling. The + * widths matched the bi-level rendering. + * + * _ClearType_ _Rendering_ + * + * Technique that uses physical subpixels to improve rendering on LCD + * (and other) displays. Because of the higher resolution, many methods + * of improving symmetry in glyphs through hinting the right-side + * bearing were no longer necessary. This lead to what GDI calls + * `natural widths' ClearType, see + * http://www.beatstamm.com/typography/RTRCh4.htm#Sec21. Since hinting + * has extra resolution, most non-linearity went away, but it is still + * possible for hints to change the advance widths in this mode. + * + * _ClearType_ _Compatible_ _Widths_ + * + * One of the earliest challenges with ClearType was allowing the + * implementation in GDI to be selected without requiring all UI and + * documents to reflow. To address this, a compatible method of + * rendering ClearType was added where the font hints are executed once + * to determine the width in bi-level rendering, and then re-run in + * ClearType, with the difference in widths being absorbed in the font + * hints for ClearType (mostly in the white space of hints); see + * http://www.beatstamm.com/typography/RTRCh4.htm#Sec20. Somewhat by + * definition, compatible width ClearType allows for non-linear widths, + * but only when the bi-level version has non-linear widths. + * + * _ClearType_ _Subpixel_ _Positioning_ + * + * One of the nice benefits of ClearType is the ability to more crisply + * display fractional widths; unfortunately, the GDI model of integer + * bitmaps did not support this. However, the WPF and Direct Write + * frameworks do support fractional widths. DWrite calls this `natural + * mode', not to be confused with GDI's `natural widths'. Subpixel + * positioning, in the current implementation of Direct Write, + * unfortunately does not support hinted advance widths, see + * http://www.beatstamm.com/typography/RTRCh4.htm#Sec22. Note that the + * TrueType interpreter fully allows the advance width to be adjusted in + * this mode, just the DWrite client will ignore those changes. + * + * _ClearType_ _Backwards_ _Compatibility_ + * + * This is a set of exceptions made in the TrueType interpreter to + * minimize hinting techniques that were problematic with the extra + * resolution of ClearType; see + * http://www.beatstamm.com/typography/RTRCh4.htm#Sec1 and + * http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx. + * This technique is not to be confused with ClearType compatible + * widths. ClearType backwards compatibility has no direct impact on + * changing advance widths, but there might be an indirect impact on + * disabling some deltas. This could be worked around in backwards + * compatibility mode. + * + * _Native_ _ClearType_ _Mode_ + * + * (Not to be confused with `natural widths'.) This mode removes all + * the exceptions in the TrueType interpreter when running with + * ClearType. Any issues on widths would still apply, though. + * + */ + + + /************************************************************************** + * + * @property: + * interpreter-version + * + * @description: + * Currently, two versions are available, representing the bytecode + * interpreter with and without subpixel hinting support, + * respectively. The default is subpixel support if + * TT_CONFIG_OPTION_SUBPIXEL_HINTING is defined, and no subpixel + * support otherwise (since it isn't available then). + * + * If subpixel hinting is on, many TrueType bytecode instructions behave + * differently compared to B/W or grayscale rendering (except if `native + * ClearType' is selected by the font). The main idea is to render at a + * much increased horizontal resolution, then sampling down the created + * output to subpixel precision. However, many older fonts are not + * suited to this and must be specially taken care of by applying + * (hardcoded) font-specific tweaks. + * + * Details on subpixel hinting and some of the necessary tweaks can be + * found in Greg Hitchcock's whitepaper at + * `http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx'. + * + * The following example code demonstrates how to activate subpixel + * hinting (omitting the error handling). + * + * { + * FT_Library library; + * FT_Face face; + * FT_UInt interpreter_version = TT_INTERPRETER_VERSION_38; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "truetype", + * "interpreter-version", + * &interpreter_version ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + */ + + + /************************************************************************** + * + * @enum: + * TT_INTERPRETER_VERSION_XXX + * + * @description: + * A list of constants used for the @interpreter-version property to + * select the hinting engine for Truetype fonts. + * + * The numeric value in the constant names represents the version + * number as returned by the `GETINFO' bytecode instruction. + * + * @values: + * TT_INTERPRETER_VERSION_35 :: + * Version~35 corresponds to MS rasterizer v.1.7 as used e.g. in + * Windows~98; only grayscale and B/W rasterizing is supported. + * + * TT_INTERPRETER_VERSION_38 :: + * Version~38 corresponds to MS rasterizer v.1.9; it is roughly + * equivalent to the hinting provided by DirectWrite ClearType (as + * can be found, for example, in the Internet Explorer~9 running on + * Windows~7). + * + * @note: + * This property controls the behaviour of the bytecode interpreter + * and thus how outlines get hinted. It does *not* control how glyph + * get rasterized! In particular, it does not control subpixel color + * filtering. + * + * If FreeType has not been compiled with configuration option + * FT_CONFIG_OPTION_SUBPIXEL_HINTING, selecting version~38 causes an + * `FT_Err_Unimplemented_Feature' error. + * + * Depending on the graphics framework, Microsoft uses different + * bytecode and rendering engines. As a consequence, the version + * numbers returned by a call to the `GETINFO' bytecode instruction are + * more convoluted than desired. + * + * Here are two tables that try to shed some light on the possible + * values for the MS rasterizer engine, together with the additional + * features introduced by it. + * + * { + * GETINFO framework version feature + * ------------------------------------------------------------------- + * 3 GDI (Win 3.1), v1.0 16-bit, first version + * TrueImage + * 33 GDI (Win NT 3.1), v1.5 32-bit + * HP Laserjet + * 34 GDI (Win 95) v1.6 font smoothing, + * new SCANTYPE opcode + * 35 GDI (Win 98/2000) v1.7 (UN)SCALED_COMPONENT_OFFSET + * bits in composite glyphs + * 36 MGDI (Win CE 2) v1.6+ classic ClearType + * 37 GDI (XP and later), v1.8 ClearType + * GDI+ old (before Vista) + * 38 GDI+ old (Vista, Win 7), v1.9 subpixel ClearType, + * WPF Y-direction ClearType, + * additional error checking + * 39 DWrite (before Win 8) v2.0 subpixel ClearType flags + * in GETINFO opcode, + * bug fixes + * 40 GDI+ (after Win 7), v2.1 Y-direction ClearType flag + * DWrite (Win 8) in GETINFO opcode, + * Gray ClearType + * } + * + * The `version' field gives a rough orientation only, since some + * applications provided certain features much earlier (as an example, + * Microsoft Reader used subpixel and Y-direction ClearType already in + * Windows 2000). Similarly, updates to a given framework might include + * improved hinting support. + * + * { + * version sampling rendering comment + * x y x y + * -------------------------------------------------------------- + * v1.0 normal normal B/W B/W bi-level + * v1.6 high high gray gray grayscale + * v1.8 high normal color-filter B/W (GDI) ClearType + * v1.9 high high color-filter gray Color ClearType + * v2.1 high normal gray B/W Gray ClearType + * v2.1 high high gray gray Gray ClearType + * } + * + * Color and Gray ClearType are the two available variants of + * `Y-direction ClearType', meaning grayscale rasterization along the + * Y-direction; the name used in the TrueType specification for this + * feature is `symmetric smoothing'. `Classic ClearType' is the + * original algorithm used before introducing a modified version in + * Win~XP. Another name for v1.6's grayscale rendering is `font + * smoothing', and `Color ClearType' is sometimes also called `DWrite + * ClearType'. To differentiate between today's Color ClearType and the + * earlier ClearType variant with B/W rendering along the vertical axis, + * the latter is sometimes called `GDI ClearType'. + * + * `Normal' and `high' sampling describe the (virtual) resolution to + * access the rasterized outline after the hinting process. `Normal' + * means 1 sample per grid line (i.e., B/W). In the current Microsoft + * implementation, `high' means an extra virtual resolution of 16x16 (or + * 16x1) grid lines per pixel for bytecode instructions like `MIRP'. + * After hinting, these 16 grid lines are mapped to 6x5 (or 6x1) grid + * lines for color filtering if Color ClearType is activated. + * + * Note that `Gray ClearType' is essentially the same as v1.6's + * grayscale rendering. However, the GETINFO instruction handles it + * differently: v1.6 returns bit~12 (hinting for grayscale), while v2.1 + * returns bits~13 (hinting for ClearType), 18 (symmetrical smoothing), + * and~19 (Gray ClearType). Also, this mode respects bits 2 and~3 for + * the version~1 gasp table exclusively (like Color ClearType), while + * v1.6 only respects the values of version~0 (bits 0 and~1). + * + * FreeType doesn't provide all capabilities of the most recent + * ClearType incarnation, thus we identify our subpixel support as + * version~38. + * + */ +#define TT_INTERPRETER_VERSION_35 35 +#define TT_INTERPRETER_VERSION_38 38 + + /* */ + + +FT_END_HEADER + + +#endif /* FTTTDRV_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/fttypes.h b/android/x86/include/freetype/fttypes.h new file mode 100644 index 00000000..2673e79c --- /dev/null +++ b/android/x86/include/freetype/fttypes.h @@ -0,0 +1,602 @@ +/***************************************************************************/ +/* */ +/* fttypes.h */ +/* */ +/* FreeType simple types definitions (specification only). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTTYPES_H_ +#define FTTYPES_H_ + + +#include <ft2build.h> +#include FT_CONFIG_CONFIG_H +#include FT_SYSTEM_H +#include FT_IMAGE_H + +#include <stddef.h> + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* basic_types */ + /* */ + /* <Title> */ + /* Basic Data Types */ + /* */ + /* <Abstract> */ + /* The basic data types defined by the library. */ + /* */ + /* <Description> */ + /* This section contains the basic data types defined by FreeType~2, */ + /* ranging from simple scalar types to bitmap descriptors. More */ + /* font-specific structures are defined in a different section. */ + /* */ + /* <Order> */ + /* FT_Byte */ + /* FT_Bytes */ + /* FT_Char */ + /* FT_Int */ + /* FT_UInt */ + /* FT_Int16 */ + /* FT_UInt16 */ + /* FT_Int32 */ + /* FT_UInt32 */ + /* FT_Int64 */ + /* FT_UInt64 */ + /* FT_Short */ + /* FT_UShort */ + /* FT_Long */ + /* FT_ULong */ + /* FT_Bool */ + /* FT_Offset */ + /* FT_PtrDist */ + /* FT_String */ + /* FT_Tag */ + /* FT_Error */ + /* FT_Fixed */ + /* FT_Pointer */ + /* FT_Pos */ + /* FT_Vector */ + /* FT_BBox */ + /* FT_Matrix */ + /* FT_FWord */ + /* FT_UFWord */ + /* FT_F2Dot14 */ + /* FT_UnitVector */ + /* FT_F26Dot6 */ + /* FT_Data */ + /* */ + /* FT_MAKE_TAG */ + /* */ + /* FT_Generic */ + /* FT_Generic_Finalizer */ + /* */ + /* FT_Bitmap */ + /* FT_Pixel_Mode */ + /* FT_Palette_Mode */ + /* FT_Glyph_Format */ + /* FT_IMAGE_TAG */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Bool */ + /* */ + /* <Description> */ + /* A typedef of unsigned char, used for simple booleans. As usual, */ + /* values 1 and~0 represent true and false, respectively. */ + /* */ + typedef unsigned char FT_Bool; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_FWord */ + /* */ + /* <Description> */ + /* A signed 16-bit integer used to store a distance in original font */ + /* units. */ + /* */ + typedef signed short FT_FWord; /* distance in FUnits */ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_UFWord */ + /* */ + /* <Description> */ + /* An unsigned 16-bit integer used to store a distance in original */ + /* font units. */ + /* */ + typedef unsigned short FT_UFWord; /* unsigned distance */ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Char */ + /* */ + /* <Description> */ + /* A simple typedef for the _signed_ char type. */ + /* */ + typedef signed char FT_Char; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Byte */ + /* */ + /* <Description> */ + /* A simple typedef for the _unsigned_ char type. */ + /* */ + typedef unsigned char FT_Byte; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Bytes */ + /* */ + /* <Description> */ + /* A typedef for constant memory areas. */ + /* */ + typedef const FT_Byte* FT_Bytes; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Tag */ + /* */ + /* <Description> */ + /* A typedef for 32-bit tags (as used in the SFNT format). */ + /* */ + typedef FT_UInt32 FT_Tag; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_String */ + /* */ + /* <Description> */ + /* A simple typedef for the char type, usually used for strings. */ + /* */ + typedef char FT_String; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Short */ + /* */ + /* <Description> */ + /* A typedef for signed short. */ + /* */ + typedef signed short FT_Short; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_UShort */ + /* */ + /* <Description> */ + /* A typedef for unsigned short. */ + /* */ + typedef unsigned short FT_UShort; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Int */ + /* */ + /* <Description> */ + /* A typedef for the int type. */ + /* */ + typedef signed int FT_Int; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_UInt */ + /* */ + /* <Description> */ + /* A typedef for the unsigned int type. */ + /* */ + typedef unsigned int FT_UInt; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Long */ + /* */ + /* <Description> */ + /* A typedef for signed long. */ + /* */ + typedef signed long FT_Long; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_ULong */ + /* */ + /* <Description> */ + /* A typedef for unsigned long. */ + /* */ + typedef unsigned long FT_ULong; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_F2Dot14 */ + /* */ + /* <Description> */ + /* A signed 2.14 fixed-point type used for unit vectors. */ + /* */ + typedef signed short FT_F2Dot14; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_F26Dot6 */ + /* */ + /* <Description> */ + /* A signed 26.6 fixed-point type used for vectorial pixel */ + /* coordinates. */ + /* */ + typedef signed long FT_F26Dot6; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Fixed */ + /* */ + /* <Description> */ + /* This type is used to store 16.16 fixed-point values, like scaling */ + /* values or matrix coefficients. */ + /* */ + typedef signed long FT_Fixed; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Error */ + /* */ + /* <Description> */ + /* The FreeType error code type. A value of~0 is always interpreted */ + /* as a successful operation. */ + /* */ + typedef int FT_Error; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Pointer */ + /* */ + /* <Description> */ + /* A simple typedef for a typeless pointer. */ + /* */ + typedef void* FT_Pointer; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Offset */ + /* */ + /* <Description> */ + /* This is equivalent to the ANSI~C `size_t' type, i.e., the largest */ + /* _unsigned_ integer type used to express a file size or position, */ + /* or a memory block size. */ + /* */ + typedef size_t FT_Offset; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_PtrDist */ + /* */ + /* <Description> */ + /* This is equivalent to the ANSI~C `ptrdiff_t' type, i.e., the */ + /* largest _signed_ integer type used to express the distance */ + /* between two pointers. */ + /* */ + typedef ft_ptrdiff_t FT_PtrDist; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_UnitVector */ + /* */ + /* <Description> */ + /* A simple structure used to store a 2D vector unit vector. Uses */ + /* FT_F2Dot14 types. */ + /* */ + /* <Fields> */ + /* x :: Horizontal coordinate. */ + /* */ + /* y :: Vertical coordinate. */ + /* */ + typedef struct FT_UnitVector_ + { + FT_F2Dot14 x; + FT_F2Dot14 y; + + } FT_UnitVector; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Matrix */ + /* */ + /* <Description> */ + /* A simple structure used to store a 2x2 matrix. Coefficients are */ + /* in 16.16 fixed-point format. The computation performed is: */ + /* */ + /* { */ + /* x' = x*xx + y*xy */ + /* y' = x*yx + y*yy */ + /* } */ + /* */ + /* <Fields> */ + /* xx :: Matrix coefficient. */ + /* */ + /* xy :: Matrix coefficient. */ + /* */ + /* yx :: Matrix coefficient. */ + /* */ + /* yy :: Matrix coefficient. */ + /* */ + typedef struct FT_Matrix_ + { + FT_Fixed xx, xy; + FT_Fixed yx, yy; + + } FT_Matrix; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Data */ + /* */ + /* <Description> */ + /* Read-only binary data represented as a pointer and a length. */ + /* */ + /* <Fields> */ + /* pointer :: The data. */ + /* */ + /* length :: The length of the data in bytes. */ + /* */ + typedef struct FT_Data_ + { + const FT_Byte* pointer; + FT_Int length; + + } FT_Data; + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Generic_Finalizer */ + /* */ + /* <Description> */ + /* Describe a function used to destroy the `client' data of any */ + /* FreeType object. See the description of the @FT_Generic type for */ + /* details of usage. */ + /* */ + /* <Input> */ + /* The address of the FreeType object that is under finalization. */ + /* Its client data is accessed through its `generic' field. */ + /* */ + typedef void (*FT_Generic_Finalizer)(void* object); + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Generic */ + /* */ + /* <Description> */ + /* Client applications often need to associate their own data to a */ + /* variety of FreeType core objects. For example, a text layout API */ + /* might want to associate a glyph cache to a given size object. */ + /* */ + /* Some FreeType object contains a `generic' field, of type */ + /* FT_Generic, which usage is left to client applications and font */ + /* servers. */ + /* */ + /* It can be used to store a pointer to client-specific data, as well */ + /* as the address of a `finalizer' function, which will be called by */ + /* FreeType when the object is destroyed (for example, the previous */ + /* client example would put the address of the glyph cache destructor */ + /* in the `finalizer' field). */ + /* */ + /* <Fields> */ + /* data :: A typeless pointer to any client-specified data. This */ + /* field is completely ignored by the FreeType library. */ + /* */ + /* finalizer :: A pointer to a `generic finalizer' function, which */ + /* will be called when the object is destroyed. If this */ + /* field is set to NULL, no code will be called. */ + /* */ + typedef struct FT_Generic_ + { + void* data; + FT_Generic_Finalizer finalizer; + + } FT_Generic; + + + /*************************************************************************/ + /* */ + /* <Macro> */ + /* FT_MAKE_TAG */ + /* */ + /* <Description> */ + /* This macro converts four-letter tags that are used to label */ + /* TrueType tables into an unsigned long, to be used within FreeType. */ + /* */ + /* <Note> */ + /* The produced values *must* be 32-bit integers. Don't redefine */ + /* this macro. */ + /* */ +#define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \ + (FT_Tag) \ + ( ( (FT_ULong)_x1 << 24 ) | \ + ( (FT_ULong)_x2 << 16 ) | \ + ( (FT_ULong)_x3 << 8 ) | \ + (FT_ULong)_x4 ) + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* L I S T M A N A G E M E N T */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* list_processing */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_ListNode */ + /* */ + /* <Description> */ + /* Many elements and objects in FreeType are listed through an */ + /* @FT_List record (see @FT_ListRec). As its name suggests, an */ + /* FT_ListNode is a handle to a single list element. */ + /* */ + typedef struct FT_ListNodeRec_* FT_ListNode; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_List */ + /* */ + /* <Description> */ + /* A handle to a list record (see @FT_ListRec). */ + /* */ + typedef struct FT_ListRec_* FT_List; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_ListNodeRec */ + /* */ + /* <Description> */ + /* A structure used to hold a single list element. */ + /* */ + /* <Fields> */ + /* prev :: The previous element in the list. NULL if first. */ + /* */ + /* next :: The next element in the list. NULL if last. */ + /* */ + /* data :: A typeless pointer to the listed object. */ + /* */ + typedef struct FT_ListNodeRec_ + { + FT_ListNode prev; + FT_ListNode next; + void* data; + + } FT_ListNodeRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_ListRec */ + /* */ + /* <Description> */ + /* A structure used to hold a simple doubly-linked list. These are */ + /* used in many parts of FreeType. */ + /* */ + /* <Fields> */ + /* head :: The head (first element) of doubly-linked list. */ + /* */ + /* tail :: The tail (last element) of doubly-linked list. */ + /* */ + typedef struct FT_ListRec_ + { + FT_ListNode head; + FT_ListNode tail; + + } FT_ListRec; + + /* */ + + +#define FT_IS_EMPTY( list ) ( (list).head == 0 ) +#define FT_BOOL( x ) ( (FT_Bool)( x ) ) + + /* concatenate C tokens */ +#define FT_ERR_XCAT( x, y ) x ## y +#define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y ) + + /* see `ftmoderr.h' for descriptions of the following macros */ + +#define FT_ERR( e ) FT_ERR_CAT( FT_ERR_PREFIX, e ) + +#define FT_ERROR_BASE( x ) ( (x) & 0xFF ) +#define FT_ERROR_MODULE( x ) ( (x) & 0xFF00U ) + +#define FT_ERR_EQ( x, e ) \ + ( FT_ERROR_BASE( x ) == FT_ERROR_BASE( FT_ERR( e ) ) ) +#define FT_ERR_NEQ( x, e ) \ + ( FT_ERROR_BASE( x ) != FT_ERROR_BASE( FT_ERR( e ) ) ) + + +FT_END_HEADER + +#endif /* FTTYPES_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ftwinfnt.h b/android/x86/include/freetype/ftwinfnt.h new file mode 100644 index 00000000..a1a715ba --- /dev/null +++ b/android/x86/include/freetype/ftwinfnt.h @@ -0,0 +1,275 @@ +/***************************************************************************/ +/* */ +/* ftwinfnt.h */ +/* */ +/* FreeType API for accessing Windows fnt-specific data. */ +/* */ +/* Copyright 2003-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTWINFNT_H_ +#define FTWINFNT_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* winfnt_fonts */ + /* */ + /* <Title> */ + /* Window FNT Files */ + /* */ + /* <Abstract> */ + /* Windows FNT specific API. */ + /* */ + /* <Description> */ + /* This section contains the declaration of Windows FNT specific */ + /* functions. */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @enum: + * FT_WinFNT_ID_XXX + * + * @description: + * A list of valid values for the `charset' byte in + * @FT_WinFNT_HeaderRec. Exact mapping tables for the various cpXXXX + * encodings (except for cp1361) can be found at + * ftp://ftp.unicode.org/Public in the MAPPINGS/VENDORS/MICSFT/WINDOWS + * subdirectory. cp1361 is roughly a superset of + * MAPPINGS/OBSOLETE/EASTASIA/KSC/JOHAB.TXT. + * + * @values: + * FT_WinFNT_ID_DEFAULT :: + * This is used for font enumeration and font creation as a + * `don't care' value. Valid font files don't contain this value. + * When querying for information about the character set of the font + * that is currently selected into a specified device context, this + * return value (of the related Windows API) simply denotes failure. + * + * FT_WinFNT_ID_SYMBOL :: + * There is no known mapping table available. + * + * FT_WinFNT_ID_MAC :: + * Mac Roman encoding. + * + * FT_WinFNT_ID_OEM :: + * From Michael Pöttgen <michael@poettgen.de>: + * + * The `Windows Font Mapping' article says that FT_WinFNT_ID_OEM + * is used for the charset of vector fonts, like `modern.fon', + * `roman.fon', and `script.fon' on Windows. + * + * The `CreateFont' documentation says: The FT_WinFNT_ID_OEM value + * specifies a character set that is operating-system dependent. + * + * The `IFIMETRICS' documentation from the `Windows Driver + * Development Kit' says: This font supports an OEM-specific + * character set. The OEM character set is system dependent. + * + * In general OEM, as opposed to ANSI (i.e., cp1252), denotes the + * second default codepage that most international versions of + * Windows have. It is one of the OEM codepages from + * + * https://msdn.microsoft.com/en-us/goglobal/bb964655, + * + * and is used for the `DOS boxes', to support legacy applications. + * A German Windows version for example usually uses ANSI codepage + * 1252 and OEM codepage 850. + * + * FT_WinFNT_ID_CP874 :: + * A superset of Thai TIS 620 and ISO 8859-11. + * + * FT_WinFNT_ID_CP932 :: + * A superset of Japanese Shift-JIS (with minor deviations). + * + * FT_WinFNT_ID_CP936 :: + * A superset of simplified Chinese GB 2312-1980 (with different + * ordering and minor deviations). + * + * FT_WinFNT_ID_CP949 :: + * A superset of Korean Hangul KS~C 5601-1987 (with different + * ordering and minor deviations). + * + * FT_WinFNT_ID_CP950 :: + * A superset of traditional Chinese Big~5 ETen (with different + * ordering and minor deviations). + * + * FT_WinFNT_ID_CP1250 :: + * A superset of East European ISO 8859-2 (with slightly different + * ordering). + * + * FT_WinFNT_ID_CP1251 :: + * A superset of Russian ISO 8859-5 (with different ordering). + * + * FT_WinFNT_ID_CP1252 :: + * ANSI encoding. A superset of ISO 8859-1. + * + * FT_WinFNT_ID_CP1253 :: + * A superset of Greek ISO 8859-7 (with minor modifications). + * + * FT_WinFNT_ID_CP1254 :: + * A superset of Turkish ISO 8859-9. + * + * FT_WinFNT_ID_CP1255 :: + * A superset of Hebrew ISO 8859-8 (with some modifications). + * + * FT_WinFNT_ID_CP1256 :: + * A superset of Arabic ISO 8859-6 (with different ordering). + * + * FT_WinFNT_ID_CP1257 :: + * A superset of Baltic ISO 8859-13 (with some deviations). + * + * FT_WinFNT_ID_CP1258 :: + * For Vietnamese. This encoding doesn't cover all necessary + * characters. + * + * FT_WinFNT_ID_CP1361 :: + * Korean (Johab). + */ + +#define FT_WinFNT_ID_CP1252 0 +#define FT_WinFNT_ID_DEFAULT 1 +#define FT_WinFNT_ID_SYMBOL 2 +#define FT_WinFNT_ID_MAC 77 +#define FT_WinFNT_ID_CP932 128 +#define FT_WinFNT_ID_CP949 129 +#define FT_WinFNT_ID_CP1361 130 +#define FT_WinFNT_ID_CP936 134 +#define FT_WinFNT_ID_CP950 136 +#define FT_WinFNT_ID_CP1253 161 +#define FT_WinFNT_ID_CP1254 162 +#define FT_WinFNT_ID_CP1258 163 +#define FT_WinFNT_ID_CP1255 177 +#define FT_WinFNT_ID_CP1256 178 +#define FT_WinFNT_ID_CP1257 186 +#define FT_WinFNT_ID_CP1251 204 +#define FT_WinFNT_ID_CP874 222 +#define FT_WinFNT_ID_CP1250 238 +#define FT_WinFNT_ID_OEM 255 + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_WinFNT_HeaderRec */ + /* */ + /* <Description> */ + /* Windows FNT Header info. */ + /* */ + typedef struct FT_WinFNT_HeaderRec_ + { + FT_UShort version; + FT_ULong file_size; + FT_Byte copyright[60]; + FT_UShort file_type; + FT_UShort nominal_point_size; + FT_UShort vertical_resolution; + FT_UShort horizontal_resolution; + FT_UShort ascent; + FT_UShort internal_leading; + FT_UShort external_leading; + FT_Byte italic; + FT_Byte underline; + FT_Byte strike_out; + FT_UShort weight; + FT_Byte charset; + FT_UShort pixel_width; + FT_UShort pixel_height; + FT_Byte pitch_and_family; + FT_UShort avg_width; + FT_UShort max_width; + FT_Byte first_char; + FT_Byte last_char; + FT_Byte default_char; + FT_Byte break_char; + FT_UShort bytes_per_row; + FT_ULong device_offset; + FT_ULong face_name_offset; + FT_ULong bits_pointer; + FT_ULong bits_offset; + FT_Byte reserved; + FT_ULong flags; + FT_UShort A_space; + FT_UShort B_space; + FT_UShort C_space; + FT_UShort color_table_offset; + FT_ULong reserved1[4]; + + } FT_WinFNT_HeaderRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_WinFNT_Header */ + /* */ + /* <Description> */ + /* A handle to an @FT_WinFNT_HeaderRec structure. */ + /* */ + typedef struct FT_WinFNT_HeaderRec_* FT_WinFNT_Header; + + + /********************************************************************** + * + * @function: + * FT_Get_WinFNT_Header + * + * @description: + * Retrieve a Windows FNT font info header. + * + * @input: + * face :: A handle to the input face. + * + * @output: + * aheader :: The WinFNT header. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with Windows FNT faces, returning an error + * otherwise. + */ + FT_EXPORT( FT_Error ) + FT_Get_WinFNT_Header( FT_Face face, + FT_WinFNT_HeaderRec *aheader ); + + /* */ + + +FT_END_HEADER + +#endif /* FTWINFNT_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/android/x86/include/freetype/t1tables.h b/android/x86/include/freetype/t1tables.h new file mode 100644 index 00000000..e272324b --- /dev/null +++ b/android/x86/include/freetype/t1tables.h @@ -0,0 +1,761 @@ +/***************************************************************************/ +/* */ +/* t1tables.h */ +/* */ +/* Basic Type 1/Type 2 tables definitions and interface (specification */ +/* only). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef T1TABLES_H_ +#define T1TABLES_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* type1_tables */ + /* */ + /* <Title> */ + /* Type 1 Tables */ + /* */ + /* <Abstract> */ + /* Type~1 (PostScript) specific font tables. */ + /* */ + /* <Description> */ + /* This section contains the definition of Type 1-specific tables, */ + /* including structures related to other PostScript font formats. */ + /* */ + /* <Order> */ + /* PS_FontInfoRec */ + /* PS_FontInfo */ + /* PS_PrivateRec */ + /* PS_Private */ + /* */ + /* CID_FaceDictRec */ + /* CID_FaceDict */ + /* CID_FaceInfoRec */ + /* CID_FaceInfo */ + /* */ + /* FT_Has_PS_Glyph_Names */ + /* FT_Get_PS_Font_Info */ + /* FT_Get_PS_Font_Private */ + /* FT_Get_PS_Font_Value */ + /* */ + /* T1_Blend_Flags */ + /* T1_EncodingType */ + /* PS_Dict_Keys */ + /* */ + /*************************************************************************/ + + + /* Note that we separate font data in PS_FontInfoRec and PS_PrivateRec */ + /* structures in order to support Multiple Master fonts. */ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* PS_FontInfoRec */ + /* */ + /* <Description> */ + /* A structure used to model a Type~1 or Type~2 FontInfo dictionary. */ + /* Note that for Multiple Master fonts, each instance has its own */ + /* FontInfo dictionary. */ + /* */ + typedef struct PS_FontInfoRec_ + { + FT_String* version; + FT_String* notice; + FT_String* full_name; + FT_String* family_name; + FT_String* weight; + FT_Long italic_angle; + FT_Bool is_fixed_pitch; + FT_Short underline_position; + FT_UShort underline_thickness; + + } PS_FontInfoRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* PS_FontInfo */ + /* */ + /* <Description> */ + /* A handle to a @PS_FontInfoRec structure. */ + /* */ + typedef struct PS_FontInfoRec_* PS_FontInfo; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* T1_FontInfo */ + /* */ + /* <Description> */ + /* This type is equivalent to @PS_FontInfoRec. It is deprecated but */ + /* kept to maintain source compatibility between various versions of */ + /* FreeType. */ + /* */ + typedef PS_FontInfoRec T1_FontInfo; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* PS_PrivateRec */ + /* */ + /* <Description> */ + /* A structure used to model a Type~1 or Type~2 private dictionary. */ + /* Note that for Multiple Master fonts, each instance has its own */ + /* Private dictionary. */ + /* */ + typedef struct PS_PrivateRec_ + { + FT_Int unique_id; + FT_Int lenIV; + + FT_Byte num_blue_values; + FT_Byte num_other_blues; + FT_Byte num_family_blues; + FT_Byte num_family_other_blues; + + FT_Short blue_values[14]; + FT_Short other_blues[10]; + + FT_Short family_blues [14]; + FT_Short family_other_blues[10]; + + FT_Fixed blue_scale; + FT_Int blue_shift; + FT_Int blue_fuzz; + + FT_UShort standard_width[1]; + FT_UShort standard_height[1]; + + FT_Byte num_snap_widths; + FT_Byte num_snap_heights; + FT_Bool force_bold; + FT_Bool round_stem_up; + + FT_Short snap_widths [13]; /* including std width */ + FT_Short snap_heights[13]; /* including std height */ + + FT_Fixed expansion_factor; + + FT_Long language_group; + FT_Long password; + + FT_Short min_feature[2]; + + } PS_PrivateRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* PS_Private */ + /* */ + /* <Description> */ + /* A handle to a @PS_PrivateRec structure. */ + /* */ + typedef struct PS_PrivateRec_* PS_Private; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* T1_Private */ + /* */ + /* <Description> */ + /* This type is equivalent to @PS_PrivateRec. It is deprecated but */ + /* kept to maintain source compatibility between various versions of */ + /* FreeType. */ + /* */ + typedef PS_PrivateRec T1_Private; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* T1_Blend_Flags */ + /* */ + /* <Description> */ + /* A set of flags used to indicate which fields are present in a */ + /* given blend dictionary (font info or private). Used to support */ + /* Multiple Masters fonts. */ + /* */ + /* <Values> */ + /* T1_BLEND_UNDERLINE_POSITION :: */ + /* T1_BLEND_UNDERLINE_THICKNESS :: */ + /* T1_BLEND_ITALIC_ANGLE :: */ + /* T1_BLEND_BLUE_VALUES :: */ + /* T1_BLEND_OTHER_BLUES :: */ + /* T1_BLEND_STANDARD_WIDTH :: */ + /* T1_BLEND_STANDARD_HEIGHT :: */ + /* T1_BLEND_STEM_SNAP_WIDTHS :: */ + /* T1_BLEND_STEM_SNAP_HEIGHTS :: */ + /* T1_BLEND_BLUE_SCALE :: */ + /* T1_BLEND_BLUE_SHIFT :: */ + /* T1_BLEND_FAMILY_BLUES :: */ + /* T1_BLEND_FAMILY_OTHER_BLUES :: */ + /* T1_BLEND_FORCE_BOLD :: */ + /* */ + typedef enum T1_Blend_Flags_ + { + /* required fields in a FontInfo blend dictionary */ + T1_BLEND_UNDERLINE_POSITION = 0, + T1_BLEND_UNDERLINE_THICKNESS, + T1_BLEND_ITALIC_ANGLE, + + /* required fields in a Private blend dictionary */ + T1_BLEND_BLUE_VALUES, + T1_BLEND_OTHER_BLUES, + T1_BLEND_STANDARD_WIDTH, + T1_BLEND_STANDARD_HEIGHT, + T1_BLEND_STEM_SNAP_WIDTHS, + T1_BLEND_STEM_SNAP_HEIGHTS, + T1_BLEND_BLUE_SCALE, + T1_BLEND_BLUE_SHIFT, + T1_BLEND_FAMILY_BLUES, + T1_BLEND_FAMILY_OTHER_BLUES, + T1_BLEND_FORCE_BOLD, + + T1_BLEND_MAX /* do not remove */ + + } T1_Blend_Flags; + + + /* these constants are deprecated; use the corresponding */ + /* `T1_Blend_Flags' values instead */ +#define t1_blend_underline_position T1_BLEND_UNDERLINE_POSITION +#define t1_blend_underline_thickness T1_BLEND_UNDERLINE_THICKNESS +#define t1_blend_italic_angle T1_BLEND_ITALIC_ANGLE +#define t1_blend_blue_values T1_BLEND_BLUE_VALUES +#define t1_blend_other_blues T1_BLEND_OTHER_BLUES +#define t1_blend_standard_widths T1_BLEND_STANDARD_WIDTH +#define t1_blend_standard_height T1_BLEND_STANDARD_HEIGHT +#define t1_blend_stem_snap_widths T1_BLEND_STEM_SNAP_WIDTHS +#define t1_blend_stem_snap_heights T1_BLEND_STEM_SNAP_HEIGHTS +#define t1_blend_blue_scale T1_BLEND_BLUE_SCALE +#define t1_blend_blue_shift T1_BLEND_BLUE_SHIFT +#define t1_blend_family_blues T1_BLEND_FAMILY_BLUES +#define t1_blend_family_other_blues T1_BLEND_FAMILY_OTHER_BLUES +#define t1_blend_force_bold T1_BLEND_FORCE_BOLD +#define t1_blend_max T1_BLEND_MAX + + /* */ + + + /* maximum number of Multiple Masters designs, as defined in the spec */ +#define T1_MAX_MM_DESIGNS 16 + + /* maximum number of Multiple Masters axes, as defined in the spec */ +#define T1_MAX_MM_AXIS 4 + + /* maximum number of elements in a design map */ +#define T1_MAX_MM_MAP_POINTS 20 + + + /* this structure is used to store the BlendDesignMap entry for an axis */ + typedef struct PS_DesignMap_ + { + FT_Byte num_points; + FT_Long* design_points; + FT_Fixed* blend_points; + + } PS_DesignMapRec, *PS_DesignMap; + + /* backwards-compatible definition */ + typedef PS_DesignMapRec T1_DesignMap; + + + typedef struct PS_BlendRec_ + { + FT_UInt num_designs; + FT_UInt num_axis; + + FT_String* axis_names[T1_MAX_MM_AXIS]; + FT_Fixed* design_pos[T1_MAX_MM_DESIGNS]; + PS_DesignMapRec design_map[T1_MAX_MM_AXIS]; + + FT_Fixed* weight_vector; + FT_Fixed* default_weight_vector; + + PS_FontInfo font_infos[T1_MAX_MM_DESIGNS + 1]; + PS_Private privates [T1_MAX_MM_DESIGNS + 1]; + + FT_ULong blend_bitflags; + + FT_BBox* bboxes [T1_MAX_MM_DESIGNS + 1]; + + /* since 2.3.0 */ + + /* undocumented, optional: the default design instance; */ + /* corresponds to default_weight_vector -- */ + /* num_default_design_vector == 0 means it is not present */ + /* in the font and associated metrics files */ + FT_UInt default_design_vector[T1_MAX_MM_DESIGNS]; + FT_UInt num_default_design_vector; + + } PS_BlendRec, *PS_Blend; + + + /* backwards-compatible definition */ + typedef PS_BlendRec T1_Blend; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FaceDictRec */ + /* */ + /* <Description> */ + /* A structure used to represent data in a CID top-level dictionary. */ + /* */ + typedef struct CID_FaceDictRec_ + { + PS_PrivateRec private_dict; + + FT_UInt len_buildchar; + FT_Fixed forcebold_threshold; + FT_Pos stroke_width; + FT_Fixed expansion_factor; + + FT_Byte paint_type; + FT_Byte font_type; + FT_Matrix font_matrix; + FT_Vector font_offset; + + FT_UInt num_subrs; + FT_ULong subrmap_offset; + FT_Int sd_bytes; + + } CID_FaceDictRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FaceDict */ + /* */ + /* <Description> */ + /* A handle to a @CID_FaceDictRec structure. */ + /* */ + typedef struct CID_FaceDictRec_* CID_FaceDict; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FontDict */ + /* */ + /* <Description> */ + /* This type is equivalent to @CID_FaceDictRec. It is deprecated but */ + /* kept to maintain source compatibility between various versions of */ + /* FreeType. */ + /* */ + typedef CID_FaceDictRec CID_FontDict; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FaceInfoRec */ + /* */ + /* <Description> */ + /* A structure used to represent CID Face information. */ + /* */ + typedef struct CID_FaceInfoRec_ + { + FT_String* cid_font_name; + FT_Fixed cid_version; + FT_Int cid_font_type; + + FT_String* registry; + FT_String* ordering; + FT_Int supplement; + + PS_FontInfoRec font_info; + FT_BBox font_bbox; + FT_ULong uid_base; + + FT_Int num_xuid; + FT_ULong xuid[16]; + + FT_ULong cidmap_offset; + FT_Int fd_bytes; + FT_Int gd_bytes; + FT_ULong cid_count; + + FT_Int num_dicts; + CID_FaceDict font_dicts; + + FT_ULong data_offset; + + } CID_FaceInfoRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FaceInfo */ + /* */ + /* <Description> */ + /* A handle to a @CID_FaceInfoRec structure. */ + /* */ + typedef struct CID_FaceInfoRec_* CID_FaceInfo; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_Info */ + /* */ + /* <Description> */ + /* This type is equivalent to @CID_FaceInfoRec. It is deprecated but */ + /* kept to maintain source compatibility between various versions of */ + /* FreeType. */ + /* */ + typedef CID_FaceInfoRec CID_Info; + + + /************************************************************************ + * + * @function: + * FT_Has_PS_Glyph_Names + * + * @description: + * Return true if a given face provides reliable PostScript glyph + * names. This is similar to using the @FT_HAS_GLYPH_NAMES macro, + * except that certain fonts (mostly TrueType) contain incorrect + * glyph name tables. + * + * When this function returns true, the caller is sure that the glyph + * names returned by @FT_Get_Glyph_Name are reliable. + * + * @input: + * face :: + * face handle + * + * @return: + * Boolean. True if glyph names are reliable. + * + */ + FT_EXPORT( FT_Int ) + FT_Has_PS_Glyph_Names( FT_Face face ); + + + /************************************************************************ + * + * @function: + * FT_Get_PS_Font_Info + * + * @description: + * Retrieve the @PS_FontInfoRec structure corresponding to a given + * PostScript font. + * + * @input: + * face :: + * PostScript face handle. + * + * @output: + * afont_info :: + * Output font info structure pointer. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * String pointers within the @PS_FontInfoRec structure are owned by + * the face and don't need to be freed by the caller. Missing entries + * in the font's FontInfo dictionary are represented by NULL pointers. + * + * If the font's format is not PostScript-based, this function will + * return the `FT_Err_Invalid_Argument' error code. + * + */ + FT_EXPORT( FT_Error ) + FT_Get_PS_Font_Info( FT_Face face, + PS_FontInfo afont_info ); + + + /************************************************************************ + * + * @function: + * FT_Get_PS_Font_Private + * + * @description: + * Retrieve the @PS_PrivateRec structure corresponding to a given + * PostScript font. + * + * @input: + * face :: + * PostScript face handle. + * + * @output: + * afont_private :: + * Output private dictionary structure pointer. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The string pointers within the @PS_PrivateRec structure are owned by + * the face and don't need to be freed by the caller. + * + * If the font's format is not PostScript-based, this function returns + * the `FT_Err_Invalid_Argument' error code. + * + */ + FT_EXPORT( FT_Error ) + FT_Get_PS_Font_Private( FT_Face face, + PS_Private afont_private ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* T1_EncodingType */ + /* */ + /* <Description> */ + /* An enumeration describing the `Encoding' entry in a Type 1 */ + /* dictionary. */ + /* */ + /* <Values> */ + /* T1_ENCODING_TYPE_NONE :: */ + /* T1_ENCODING_TYPE_ARRAY :: */ + /* T1_ENCODING_TYPE_STANDARD :: */ + /* T1_ENCODING_TYPE_ISOLATIN1 :: */ + /* T1_ENCODING_TYPE_EXPERT :: */ + /* */ + typedef enum T1_EncodingType_ + { + T1_ENCODING_TYPE_NONE = 0, + T1_ENCODING_TYPE_ARRAY, + T1_ENCODING_TYPE_STANDARD, + T1_ENCODING_TYPE_ISOLATIN1, + T1_ENCODING_TYPE_EXPERT + + } T1_EncodingType; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* PS_Dict_Keys */ + /* */ + /* <Description> */ + /* An enumeration used in calls to @FT_Get_PS_Font_Value to identify */ + /* the Type~1 dictionary entry to retrieve. */ + /* */ + /* <Values> */ + /* PS_DICT_FONT_TYPE :: */ + /* PS_DICT_FONT_MATRIX :: */ + /* PS_DICT_FONT_BBOX :: */ + /* PS_DICT_PAINT_TYPE :: */ + /* PS_DICT_FONT_NAME :: */ + /* PS_DICT_UNIQUE_ID :: */ + /* PS_DICT_NUM_CHAR_STRINGS :: */ + /* PS_DICT_CHAR_STRING_KEY :: */ + /* PS_DICT_CHAR_STRING :: */ + /* PS_DICT_ENCODING_TYPE :: */ + /* PS_DICT_ENCODING_ENTRY :: */ + /* PS_DICT_NUM_SUBRS :: */ + /* PS_DICT_SUBR :: */ + /* PS_DICT_STD_HW :: */ + /* PS_DICT_STD_VW :: */ + /* PS_DICT_NUM_BLUE_VALUES :: */ + /* PS_DICT_BLUE_VALUE :: */ + /* PS_DICT_BLUE_FUZZ :: */ + /* PS_DICT_NUM_OTHER_BLUES :: */ + /* PS_DICT_OTHER_BLUE :: */ + /* PS_DICT_NUM_FAMILY_BLUES :: */ + /* PS_DICT_FAMILY_BLUE :: */ + /* PS_DICT_NUM_FAMILY_OTHER_BLUES :: */ + /* PS_DICT_FAMILY_OTHER_BLUE :: */ + /* PS_DICT_BLUE_SCALE :: */ + /* PS_DICT_BLUE_SHIFT :: */ + /* PS_DICT_NUM_STEM_SNAP_H :: */ + /* PS_DICT_STEM_SNAP_H :: */ + /* PS_DICT_NUM_STEM_SNAP_V :: */ + /* PS_DICT_STEM_SNAP_V :: */ + /* PS_DICT_FORCE_BOLD :: */ + /* PS_DICT_RND_STEM_UP :: */ + /* PS_DICT_MIN_FEATURE :: */ + /* PS_DICT_LEN_IV :: */ + /* PS_DICT_PASSWORD :: */ + /* PS_DICT_LANGUAGE_GROUP :: */ + /* PS_DICT_VERSION :: */ + /* PS_DICT_NOTICE :: */ + /* PS_DICT_FULL_NAME :: */ + /* PS_DICT_FAMILY_NAME :: */ + /* PS_DICT_WEIGHT :: */ + /* PS_DICT_IS_FIXED_PITCH :: */ + /* PS_DICT_UNDERLINE_POSITION :: */ + /* PS_DICT_UNDERLINE_THICKNESS :: */ + /* PS_DICT_FS_TYPE :: */ + /* PS_DICT_ITALIC_ANGLE :: */ + /* */ + typedef enum PS_Dict_Keys_ + { + /* conventionally in the font dictionary */ + PS_DICT_FONT_TYPE, /* FT_Byte */ + PS_DICT_FONT_MATRIX, /* FT_Fixed */ + PS_DICT_FONT_BBOX, /* FT_Fixed */ + PS_DICT_PAINT_TYPE, /* FT_Byte */ + PS_DICT_FONT_NAME, /* FT_String* */ + PS_DICT_UNIQUE_ID, /* FT_Int */ + PS_DICT_NUM_CHAR_STRINGS, /* FT_Int */ + PS_DICT_CHAR_STRING_KEY, /* FT_String* */ + PS_DICT_CHAR_STRING, /* FT_String* */ + PS_DICT_ENCODING_TYPE, /* T1_EncodingType */ + PS_DICT_ENCODING_ENTRY, /* FT_String* */ + + /* conventionally in the font Private dictionary */ + PS_DICT_NUM_SUBRS, /* FT_Int */ + PS_DICT_SUBR, /* FT_String* */ + PS_DICT_STD_HW, /* FT_UShort */ + PS_DICT_STD_VW, /* FT_UShort */ + PS_DICT_NUM_BLUE_VALUES, /* FT_Byte */ + PS_DICT_BLUE_VALUE, /* FT_Short */ + PS_DICT_BLUE_FUZZ, /* FT_Int */ + PS_DICT_NUM_OTHER_BLUES, /* FT_Byte */ + PS_DICT_OTHER_BLUE, /* FT_Short */ + PS_DICT_NUM_FAMILY_BLUES, /* FT_Byte */ + PS_DICT_FAMILY_BLUE, /* FT_Short */ + PS_DICT_NUM_FAMILY_OTHER_BLUES, /* FT_Byte */ + PS_DICT_FAMILY_OTHER_BLUE, /* FT_Short */ + PS_DICT_BLUE_SCALE, /* FT_Fixed */ + PS_DICT_BLUE_SHIFT, /* FT_Int */ + PS_DICT_NUM_STEM_SNAP_H, /* FT_Byte */ + PS_DICT_STEM_SNAP_H, /* FT_Short */ + PS_DICT_NUM_STEM_SNAP_V, /* FT_Byte */ + PS_DICT_STEM_SNAP_V, /* FT_Short */ + PS_DICT_FORCE_BOLD, /* FT_Bool */ + PS_DICT_RND_STEM_UP, /* FT_Bool */ + PS_DICT_MIN_FEATURE, /* FT_Short */ + PS_DICT_LEN_IV, /* FT_Int */ + PS_DICT_PASSWORD, /* FT_Long */ + PS_DICT_LANGUAGE_GROUP, /* FT_Long */ + + /* conventionally in the font FontInfo dictionary */ + PS_DICT_VERSION, /* FT_String* */ + PS_DICT_NOTICE, /* FT_String* */ + PS_DICT_FULL_NAME, /* FT_String* */ + PS_DICT_FAMILY_NAME, /* FT_String* */ + PS_DICT_WEIGHT, /* FT_String* */ + PS_DICT_IS_FIXED_PITCH, /* FT_Bool */ + PS_DICT_UNDERLINE_POSITION, /* FT_Short */ + PS_DICT_UNDERLINE_THICKNESS, /* FT_UShort */ + PS_DICT_FS_TYPE, /* FT_UShort */ + PS_DICT_ITALIC_ANGLE, /* FT_Long */ + + PS_DICT_MAX = PS_DICT_ITALIC_ANGLE + + } PS_Dict_Keys; + + + /************************************************************************ + * + * @function: + * FT_Get_PS_Font_Value + * + * @description: + * Retrieve the value for the supplied key from a PostScript font. + * + * @input: + * face :: + * PostScript face handle. + * + * key :: + * An enumeration value representing the dictionary key to retrieve. + * + * idx :: + * For array values, this specifies the index to be returned. + * + * value :: + * A pointer to memory into which to write the value. + * + * valen_len :: + * The size, in bytes, of the memory supplied for the value. + * + * @output: + * value :: + * The value matching the above key, if it exists. + * + * @return: + * The amount of memory (in bytes) required to hold the requested + * value (if it exists, -1 otherwise). + * + * @note: + * The values returned are not pointers into the internal structures of + * the face, but are `fresh' copies, so that the memory containing them + * belongs to the calling application. This also enforces the + * `read-only' nature of these values, i.e., this function cannot be + * used to manipulate the face. + * + * `value' is a void pointer because the values returned can be of + * various types. + * + * If either `value' is NULL or `value_len' is too small, just the + * required memory size for the requested entry is returned. + * + * The `idx' parameter is used, not only to retrieve elements of, for + * example, the FontMatrix or FontBBox, but also to retrieve name keys + * from the CharStrings dictionary, and the charstrings themselves. It + * is ignored for atomic values. + * + * PS_DICT_BLUE_SCALE returns a value that is scaled up by 1000. To + * get the value as in the font stream, you need to divide by + * 65536000.0 (to remove the FT_Fixed scale, and the x1000 scale). + * + * IMPORTANT: Only key/value pairs read by the FreeType interpreter can + * be retrieved. So, for example, PostScript procedures such as NP, + * ND, and RD are not available. Arbitrary keys are, obviously, not be + * available either. + * + * If the font's format is not PostScript-based, this function returns + * the `FT_Err_Invalid_Argument' error code. + * + */ + FT_EXPORT( FT_Long ) + FT_Get_PS_Font_Value( FT_Face face, + PS_Dict_Keys key, + FT_UInt idx, + void *value, + FT_Long value_len ); + + /* */ + +FT_END_HEADER + +#endif /* T1TABLES_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ttnameid.h b/android/x86/include/freetype/ttnameid.h new file mode 100644 index 00000000..ce707f16 --- /dev/null +++ b/android/x86/include/freetype/ttnameid.h @@ -0,0 +1,1237 @@ +/***************************************************************************/ +/* */ +/* ttnameid.h */ +/* */ +/* TrueType name ID definitions (specification only). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTNAMEID_H_ +#define TTNAMEID_H_ + + +#include <ft2build.h> + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* truetype_tables */ + /* */ + + + /*************************************************************************/ + /* */ + /* Possible values for the `platform' identifier code in the name */ + /* records of the TTF `name' table. */ + /* */ + /*************************************************************************/ + + + /*********************************************************************** + * + * @enum: + * TT_PLATFORM_XXX + * + * @description: + * A list of valid values for the `platform_id' identifier code in + * @FT_CharMapRec and @FT_SfntName structures. + * + * @values: + * TT_PLATFORM_APPLE_UNICODE :: + * Used by Apple to indicate a Unicode character map and/or name entry. + * See @TT_APPLE_ID_XXX for corresponding `encoding_id' values. Note + * that name entries in this format are coded as big-endian UCS-2 + * character codes _only_. + * + * TT_PLATFORM_MACINTOSH :: + * Used by Apple to indicate a MacOS-specific charmap and/or name entry. + * See @TT_MAC_ID_XXX for corresponding `encoding_id' values. Note that + * most TrueType fonts contain an Apple roman charmap to be usable on + * MacOS systems (even if they contain a Microsoft charmap as well). + * + * TT_PLATFORM_ISO :: + * This value was used to specify ISO/IEC 10646 charmaps. It is however + * now deprecated. See @TT_ISO_ID_XXX for a list of corresponding + * `encoding_id' values. + * + * TT_PLATFORM_MICROSOFT :: + * Used by Microsoft to indicate Windows-specific charmaps. See + * @TT_MS_ID_XXX for a list of corresponding `encoding_id' values. + * Note that most fonts contain a Unicode charmap using + * (TT_PLATFORM_MICROSOFT, @TT_MS_ID_UNICODE_CS). + * + * TT_PLATFORM_CUSTOM :: + * Used to indicate application-specific charmaps. + * + * TT_PLATFORM_ADOBE :: + * This value isn't part of any font format specification, but is used + * by FreeType to report Adobe-specific charmaps in an @FT_CharMapRec + * structure. See @TT_ADOBE_ID_XXX. + */ + +#define TT_PLATFORM_APPLE_UNICODE 0 +#define TT_PLATFORM_MACINTOSH 1 +#define TT_PLATFORM_ISO 2 /* deprecated */ +#define TT_PLATFORM_MICROSOFT 3 +#define TT_PLATFORM_CUSTOM 4 +#define TT_PLATFORM_ADOBE 7 /* artificial */ + + + /*********************************************************************** + * + * @enum: + * TT_APPLE_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_APPLE_UNICODE charmaps and name entries. + * + * @values: + * TT_APPLE_ID_DEFAULT :: + * Unicode version 1.0. + * + * TT_APPLE_ID_UNICODE_1_1 :: + * Unicode 1.1; specifies Hangul characters starting at U+34xx. + * + * TT_APPLE_ID_ISO_10646 :: + * Deprecated (identical to preceding). + * + * TT_APPLE_ID_UNICODE_2_0 :: + * Unicode 2.0 and beyond (UTF-16 BMP only). + * + * TT_APPLE_ID_UNICODE_32 :: + * Unicode 3.1 and beyond, using UTF-32. + * + * TT_APPLE_ID_VARIANT_SELECTOR :: + * From Adobe, not Apple. Not a normal cmap. Specifies variations + * on a real cmap. + */ + +#define TT_APPLE_ID_DEFAULT 0 /* Unicode 1.0 */ +#define TT_APPLE_ID_UNICODE_1_1 1 /* specify Hangul at U+34xx */ +#define TT_APPLE_ID_ISO_10646 2 /* deprecated */ +#define TT_APPLE_ID_UNICODE_2_0 3 /* or later */ +#define TT_APPLE_ID_UNICODE_32 4 /* 2.0 or later, full repertoire */ +#define TT_APPLE_ID_VARIANT_SELECTOR 5 /* variation selector data */ + + + /*********************************************************************** + * + * @enum: + * TT_MAC_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_MACINTOSH charmaps and name entries. + * + * @values: + * TT_MAC_ID_ROMAN :: + * TT_MAC_ID_JAPANESE :: + * TT_MAC_ID_TRADITIONAL_CHINESE :: + * TT_MAC_ID_KOREAN :: + * TT_MAC_ID_ARABIC :: + * TT_MAC_ID_HEBREW :: + * TT_MAC_ID_GREEK :: + * TT_MAC_ID_RUSSIAN :: + * TT_MAC_ID_RSYMBOL :: + * TT_MAC_ID_DEVANAGARI :: + * TT_MAC_ID_GURMUKHI :: + * TT_MAC_ID_GUJARATI :: + * TT_MAC_ID_ORIYA :: + * TT_MAC_ID_BENGALI :: + * TT_MAC_ID_TAMIL :: + * TT_MAC_ID_TELUGU :: + * TT_MAC_ID_KANNADA :: + * TT_MAC_ID_MALAYALAM :: + * TT_MAC_ID_SINHALESE :: + * TT_MAC_ID_BURMESE :: + * TT_MAC_ID_KHMER :: + * TT_MAC_ID_THAI :: + * TT_MAC_ID_LAOTIAN :: + * TT_MAC_ID_GEORGIAN :: + * TT_MAC_ID_ARMENIAN :: + * TT_MAC_ID_MALDIVIAN :: + * TT_MAC_ID_SIMPLIFIED_CHINESE :: + * TT_MAC_ID_TIBETAN :: + * TT_MAC_ID_MONGOLIAN :: + * TT_MAC_ID_GEEZ :: + * TT_MAC_ID_SLAVIC :: + * TT_MAC_ID_VIETNAMESE :: + * TT_MAC_ID_SINDHI :: + * TT_MAC_ID_UNINTERP :: + */ + +#define TT_MAC_ID_ROMAN 0 +#define TT_MAC_ID_JAPANESE 1 +#define TT_MAC_ID_TRADITIONAL_CHINESE 2 +#define TT_MAC_ID_KOREAN 3 +#define TT_MAC_ID_ARABIC 4 +#define TT_MAC_ID_HEBREW 5 +#define TT_MAC_ID_GREEK 6 +#define TT_MAC_ID_RUSSIAN 7 +#define TT_MAC_ID_RSYMBOL 8 +#define TT_MAC_ID_DEVANAGARI 9 +#define TT_MAC_ID_GURMUKHI 10 +#define TT_MAC_ID_GUJARATI 11 +#define TT_MAC_ID_ORIYA 12 +#define TT_MAC_ID_BENGALI 13 +#define TT_MAC_ID_TAMIL 14 +#define TT_MAC_ID_TELUGU 15 +#define TT_MAC_ID_KANNADA 16 +#define TT_MAC_ID_MALAYALAM 17 +#define TT_MAC_ID_SINHALESE 18 +#define TT_MAC_ID_BURMESE 19 +#define TT_MAC_ID_KHMER 20 +#define TT_MAC_ID_THAI 21 +#define TT_MAC_ID_LAOTIAN 22 +#define TT_MAC_ID_GEORGIAN 23 +#define TT_MAC_ID_ARMENIAN 24 +#define TT_MAC_ID_MALDIVIAN 25 +#define TT_MAC_ID_SIMPLIFIED_CHINESE 25 +#define TT_MAC_ID_TIBETAN 26 +#define TT_MAC_ID_MONGOLIAN 27 +#define TT_MAC_ID_GEEZ 28 +#define TT_MAC_ID_SLAVIC 29 +#define TT_MAC_ID_VIETNAMESE 30 +#define TT_MAC_ID_SINDHI 31 +#define TT_MAC_ID_UNINTERP 32 + + + /*********************************************************************** + * + * @enum: + * TT_ISO_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_ISO charmaps and name entries. + * + * Their use is now deprecated. + * + * @values: + * TT_ISO_ID_7BIT_ASCII :: + * ASCII. + * TT_ISO_ID_10646 :: + * ISO/10646. + * TT_ISO_ID_8859_1 :: + * Also known as Latin-1. + */ + +#define TT_ISO_ID_7BIT_ASCII 0 +#define TT_ISO_ID_10646 1 +#define TT_ISO_ID_8859_1 2 + + + /*********************************************************************** + * + * @enum: + * TT_MS_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_MICROSOFT charmaps and name entries. + * + * @values: + * TT_MS_ID_SYMBOL_CS :: + * Corresponds to Microsoft symbol encoding. See + * @FT_ENCODING_MS_SYMBOL. + * + * TT_MS_ID_UNICODE_CS :: + * Corresponds to a Microsoft WGL4 charmap, matching Unicode. See + * @FT_ENCODING_UNICODE. + * + * TT_MS_ID_SJIS :: + * Corresponds to SJIS Japanese encoding. See @FT_ENCODING_SJIS. + * + * TT_MS_ID_GB2312 :: + * Corresponds to Simplified Chinese as used in Mainland China. See + * @FT_ENCODING_GB2312. + * + * TT_MS_ID_BIG_5 :: + * Corresponds to Traditional Chinese as used in Taiwan and Hong Kong. + * See @FT_ENCODING_BIG5. + * + * TT_MS_ID_WANSUNG :: + * Corresponds to Korean Wansung encoding. See @FT_ENCODING_WANSUNG. + * + * TT_MS_ID_JOHAB :: + * Corresponds to Johab encoding. See @FT_ENCODING_JOHAB. + * + * TT_MS_ID_UCS_4 :: + * Corresponds to UCS-4 or UTF-32 charmaps. This has been added to + * the OpenType specification version 1.4 (mid-2001.) + */ + +#define TT_MS_ID_SYMBOL_CS 0 +#define TT_MS_ID_UNICODE_CS 1 +#define TT_MS_ID_SJIS 2 +#define TT_MS_ID_GB2312 3 +#define TT_MS_ID_BIG_5 4 +#define TT_MS_ID_WANSUNG 5 +#define TT_MS_ID_JOHAB 6 +#define TT_MS_ID_UCS_4 10 + + + /*********************************************************************** + * + * @enum: + * TT_ADOBE_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_ADOBE charmaps. This is a FreeType-specific extension! + * + * @values: + * TT_ADOBE_ID_STANDARD :: + * Adobe standard encoding. + * TT_ADOBE_ID_EXPERT :: + * Adobe expert encoding. + * TT_ADOBE_ID_CUSTOM :: + * Adobe custom encoding. + * TT_ADOBE_ID_LATIN_1 :: + * Adobe Latin~1 encoding. + */ + +#define TT_ADOBE_ID_STANDARD 0 +#define TT_ADOBE_ID_EXPERT 1 +#define TT_ADOBE_ID_CUSTOM 2 +#define TT_ADOBE_ID_LATIN_1 3 + + + /*************************************************************************/ + /* */ + /* Possible values of the language identifier field in the name records */ + /* of the TTF `name' table if the `platform' identifier code is */ + /* TT_PLATFORM_MACINTOSH. These values are also used as return values */ + /* for function @FT_Get_CMap_Language_ID. */ + /* */ + /* The canonical source for the Apple assigned Language ID's is at */ + /* */ + /* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html */ + /* */ +#define TT_MAC_LANGID_ENGLISH 0 +#define TT_MAC_LANGID_FRENCH 1 +#define TT_MAC_LANGID_GERMAN 2 +#define TT_MAC_LANGID_ITALIAN 3 +#define TT_MAC_LANGID_DUTCH 4 +#define TT_MAC_LANGID_SWEDISH 5 +#define TT_MAC_LANGID_SPANISH 6 +#define TT_MAC_LANGID_DANISH 7 +#define TT_MAC_LANGID_PORTUGUESE 8 +#define TT_MAC_LANGID_NORWEGIAN 9 +#define TT_MAC_LANGID_HEBREW 10 +#define TT_MAC_LANGID_JAPANESE 11 +#define TT_MAC_LANGID_ARABIC 12 +#define TT_MAC_LANGID_FINNISH 13 +#define TT_MAC_LANGID_GREEK 14 +#define TT_MAC_LANGID_ICELANDIC 15 +#define TT_MAC_LANGID_MALTESE 16 +#define TT_MAC_LANGID_TURKISH 17 +#define TT_MAC_LANGID_CROATIAN 18 +#define TT_MAC_LANGID_CHINESE_TRADITIONAL 19 +#define TT_MAC_LANGID_URDU 20 +#define TT_MAC_LANGID_HINDI 21 +#define TT_MAC_LANGID_THAI 22 +#define TT_MAC_LANGID_KOREAN 23 +#define TT_MAC_LANGID_LITHUANIAN 24 +#define TT_MAC_LANGID_POLISH 25 +#define TT_MAC_LANGID_HUNGARIAN 26 +#define TT_MAC_LANGID_ESTONIAN 27 +#define TT_MAC_LANGID_LETTISH 28 +#define TT_MAC_LANGID_SAAMISK 29 +#define TT_MAC_LANGID_FAEROESE 30 +#define TT_MAC_LANGID_FARSI 31 +#define TT_MAC_LANGID_RUSSIAN 32 +#define TT_MAC_LANGID_CHINESE_SIMPLIFIED 33 +#define TT_MAC_LANGID_FLEMISH 34 +#define TT_MAC_LANGID_IRISH 35 +#define TT_MAC_LANGID_ALBANIAN 36 +#define TT_MAC_LANGID_ROMANIAN 37 +#define TT_MAC_LANGID_CZECH 38 +#define TT_MAC_LANGID_SLOVAK 39 +#define TT_MAC_LANGID_SLOVENIAN 40 +#define TT_MAC_LANGID_YIDDISH 41 +#define TT_MAC_LANGID_SERBIAN 42 +#define TT_MAC_LANGID_MACEDONIAN 43 +#define TT_MAC_LANGID_BULGARIAN 44 +#define TT_MAC_LANGID_UKRAINIAN 45 +#define TT_MAC_LANGID_BYELORUSSIAN 46 +#define TT_MAC_LANGID_UZBEK 47 +#define TT_MAC_LANGID_KAZAKH 48 +#define TT_MAC_LANGID_AZERBAIJANI 49 +#define TT_MAC_LANGID_AZERBAIJANI_CYRILLIC_SCRIPT 49 +#define TT_MAC_LANGID_AZERBAIJANI_ARABIC_SCRIPT 50 +#define TT_MAC_LANGID_ARMENIAN 51 +#define TT_MAC_LANGID_GEORGIAN 52 +#define TT_MAC_LANGID_MOLDAVIAN 53 +#define TT_MAC_LANGID_KIRGHIZ 54 +#define TT_MAC_LANGID_TAJIKI 55 +#define TT_MAC_LANGID_TURKMEN 56 +#define TT_MAC_LANGID_MONGOLIAN 57 +#define TT_MAC_LANGID_MONGOLIAN_MONGOLIAN_SCRIPT 57 +#define TT_MAC_LANGID_MONGOLIAN_CYRILLIC_SCRIPT 58 +#define TT_MAC_LANGID_PASHTO 59 +#define TT_MAC_LANGID_KURDISH 60 +#define TT_MAC_LANGID_KASHMIRI 61 +#define TT_MAC_LANGID_SINDHI 62 +#define TT_MAC_LANGID_TIBETAN 63 +#define TT_MAC_LANGID_NEPALI 64 +#define TT_MAC_LANGID_SANSKRIT 65 +#define TT_MAC_LANGID_MARATHI 66 +#define TT_MAC_LANGID_BENGALI 67 +#define TT_MAC_LANGID_ASSAMESE 68 +#define TT_MAC_LANGID_GUJARATI 69 +#define TT_MAC_LANGID_PUNJABI 70 +#define TT_MAC_LANGID_ORIYA 71 +#define TT_MAC_LANGID_MALAYALAM 72 +#define TT_MAC_LANGID_KANNADA 73 +#define TT_MAC_LANGID_TAMIL 74 +#define TT_MAC_LANGID_TELUGU 75 +#define TT_MAC_LANGID_SINHALESE 76 +#define TT_MAC_LANGID_BURMESE 77 +#define TT_MAC_LANGID_KHMER 78 +#define TT_MAC_LANGID_LAO 79 +#define TT_MAC_LANGID_VIETNAMESE 80 +#define TT_MAC_LANGID_INDONESIAN 81 +#define TT_MAC_LANGID_TAGALOG 82 +#define TT_MAC_LANGID_MALAY_ROMAN_SCRIPT 83 +#define TT_MAC_LANGID_MALAY_ARABIC_SCRIPT 84 +#define TT_MAC_LANGID_AMHARIC 85 +#define TT_MAC_LANGID_TIGRINYA 86 +#define TT_MAC_LANGID_GALLA 87 +#define TT_MAC_LANGID_SOMALI 88 +#define TT_MAC_LANGID_SWAHILI 89 +#define TT_MAC_LANGID_RUANDA 90 +#define TT_MAC_LANGID_RUNDI 91 +#define TT_MAC_LANGID_CHEWA 92 +#define TT_MAC_LANGID_MALAGASY 93 +#define TT_MAC_LANGID_ESPERANTO 94 +#define TT_MAC_LANGID_WELSH 128 +#define TT_MAC_LANGID_BASQUE 129 +#define TT_MAC_LANGID_CATALAN 130 +#define TT_MAC_LANGID_LATIN 131 +#define TT_MAC_LANGID_QUECHUA 132 +#define TT_MAC_LANGID_GUARANI 133 +#define TT_MAC_LANGID_AYMARA 134 +#define TT_MAC_LANGID_TATAR 135 +#define TT_MAC_LANGID_UIGHUR 136 +#define TT_MAC_LANGID_DZONGKHA 137 +#define TT_MAC_LANGID_JAVANESE 138 +#define TT_MAC_LANGID_SUNDANESE 139 + + +#if 0 /* these seem to be errors that have been dropped */ + +#define TT_MAC_LANGID_SCOTTISH_GAELIC 140 +#define TT_MAC_LANGID_IRISH_GAELIC 141 + +#endif + + + /* The following codes are new as of 2000-03-10 */ +#define TT_MAC_LANGID_GALICIAN 140 +#define TT_MAC_LANGID_AFRIKAANS 141 +#define TT_MAC_LANGID_BRETON 142 +#define TT_MAC_LANGID_INUKTITUT 143 +#define TT_MAC_LANGID_SCOTTISH_GAELIC 144 +#define TT_MAC_LANGID_MANX_GAELIC 145 +#define TT_MAC_LANGID_IRISH_GAELIC 146 +#define TT_MAC_LANGID_TONGAN 147 +#define TT_MAC_LANGID_GREEK_POLYTONIC 148 +#define TT_MAC_LANGID_GREELANDIC 149 +#define TT_MAC_LANGID_AZERBAIJANI_ROMAN_SCRIPT 150 + + + /*************************************************************************/ + /* */ + /* Possible values of the language identifier field in the name records */ + /* of the TTF `name' table if the `platform' identifier code is */ + /* TT_PLATFORM_MICROSOFT. */ + /* */ + /* The canonical source for the MS assigned LCIDs is */ + /* */ + /* http://www.microsoft.com/globaldev/reference/lcid-all.mspx */ + /* */ + +#define TT_MS_LANGID_ARABIC_GENERAL 0x0001 +#define TT_MS_LANGID_ARABIC_SAUDI_ARABIA 0x0401 +#define TT_MS_LANGID_ARABIC_IRAQ 0x0801 +#define TT_MS_LANGID_ARABIC_EGYPT 0x0C01 +#define TT_MS_LANGID_ARABIC_LIBYA 0x1001 +#define TT_MS_LANGID_ARABIC_ALGERIA 0x1401 +#define TT_MS_LANGID_ARABIC_MOROCCO 0x1801 +#define TT_MS_LANGID_ARABIC_TUNISIA 0x1C01 +#define TT_MS_LANGID_ARABIC_OMAN 0x2001 +#define TT_MS_LANGID_ARABIC_YEMEN 0x2401 +#define TT_MS_LANGID_ARABIC_SYRIA 0x2801 +#define TT_MS_LANGID_ARABIC_JORDAN 0x2C01 +#define TT_MS_LANGID_ARABIC_LEBANON 0x3001 +#define TT_MS_LANGID_ARABIC_KUWAIT 0x3401 +#define TT_MS_LANGID_ARABIC_UAE 0x3801 +#define TT_MS_LANGID_ARABIC_BAHRAIN 0x3C01 +#define TT_MS_LANGID_ARABIC_QATAR 0x4001 +#define TT_MS_LANGID_BULGARIAN_BULGARIA 0x0402 +#define TT_MS_LANGID_CATALAN_SPAIN 0x0403 +#define TT_MS_LANGID_CHINESE_GENERAL 0x0004 +#define TT_MS_LANGID_CHINESE_TAIWAN 0x0404 +#define TT_MS_LANGID_CHINESE_PRC 0x0804 +#define TT_MS_LANGID_CHINESE_HONG_KONG 0x0C04 +#define TT_MS_LANGID_CHINESE_SINGAPORE 0x1004 + +#if 1 /* this looks like the correct value */ +#define TT_MS_LANGID_CHINESE_MACAU 0x1404 +#else /* but beware, Microsoft may change its mind... + the most recent Word reference has the following: */ +#define TT_MS_LANGID_CHINESE_MACAU TT_MS_LANGID_CHINESE_HONG_KONG +#endif + +#if 0 /* used only with .NET `cultures'; commented out */ +#define TT_MS_LANGID_CHINESE_TRADITIONAL 0x7C04 +#endif + +#define TT_MS_LANGID_CZECH_CZECH_REPUBLIC 0x0405 +#define TT_MS_LANGID_DANISH_DENMARK 0x0406 +#define TT_MS_LANGID_GERMAN_GERMANY 0x0407 +#define TT_MS_LANGID_GERMAN_SWITZERLAND 0x0807 +#define TT_MS_LANGID_GERMAN_AUSTRIA 0x0C07 +#define TT_MS_LANGID_GERMAN_LUXEMBOURG 0x1007 +#define TT_MS_LANGID_GERMAN_LIECHTENSTEI 0x1407 +#define TT_MS_LANGID_GREEK_GREECE 0x0408 + + /* don't ask what this one means... It is commented out currently. */ +#if 0 +#define TT_MS_LANGID_GREEK_GREECE2 0x2008 +#endif + +#define TT_MS_LANGID_ENGLISH_GENERAL 0x0009 +#define TT_MS_LANGID_ENGLISH_UNITED_STATES 0x0409 +#define TT_MS_LANGID_ENGLISH_UNITED_KINGDOM 0x0809 +#define TT_MS_LANGID_ENGLISH_AUSTRALIA 0x0C09 +#define TT_MS_LANGID_ENGLISH_CANADA 0x1009 +#define TT_MS_LANGID_ENGLISH_NEW_ZEALAND 0x1409 +#define TT_MS_LANGID_ENGLISH_IRELAND 0x1809 +#define TT_MS_LANGID_ENGLISH_SOUTH_AFRICA 0x1C09 +#define TT_MS_LANGID_ENGLISH_JAMAICA 0x2009 +#define TT_MS_LANGID_ENGLISH_CARIBBEAN 0x2409 +#define TT_MS_LANGID_ENGLISH_BELIZE 0x2809 +#define TT_MS_LANGID_ENGLISH_TRINIDAD 0x2C09 +#define TT_MS_LANGID_ENGLISH_ZIMBABWE 0x3009 +#define TT_MS_LANGID_ENGLISH_PHILIPPINES 0x3409 +#define TT_MS_LANGID_ENGLISH_INDONESIA 0x3809 +#define TT_MS_LANGID_ENGLISH_HONG_KONG 0x3C09 +#define TT_MS_LANGID_ENGLISH_INDIA 0x4009 +#define TT_MS_LANGID_ENGLISH_MALAYSIA 0x4409 +#define TT_MS_LANGID_ENGLISH_SINGAPORE 0x4809 +#define TT_MS_LANGID_SPANISH_SPAIN_TRADITIONAL_SORT 0x040A +#define TT_MS_LANGID_SPANISH_MEXICO 0x080A +#define TT_MS_LANGID_SPANISH_SPAIN_INTERNATIONAL_SORT 0x0C0A +#define TT_MS_LANGID_SPANISH_GUATEMALA 0x100A +#define TT_MS_LANGID_SPANISH_COSTA_RICA 0x140A +#define TT_MS_LANGID_SPANISH_PANAMA 0x180A +#define TT_MS_LANGID_SPANISH_DOMINICAN_REPUBLIC 0x1C0A +#define TT_MS_LANGID_SPANISH_VENEZUELA 0x200A +#define TT_MS_LANGID_SPANISH_COLOMBIA 0x240A +#define TT_MS_LANGID_SPANISH_PERU 0x280A +#define TT_MS_LANGID_SPANISH_ARGENTINA 0x2C0A +#define TT_MS_LANGID_SPANISH_ECUADOR 0x300A +#define TT_MS_LANGID_SPANISH_CHILE 0x340A +#define TT_MS_LANGID_SPANISH_URUGUAY 0x380A +#define TT_MS_LANGID_SPANISH_PARAGUAY 0x3C0A +#define TT_MS_LANGID_SPANISH_BOLIVIA 0x400A +#define TT_MS_LANGID_SPANISH_EL_SALVADOR 0x440A +#define TT_MS_LANGID_SPANISH_HONDURAS 0x480A +#define TT_MS_LANGID_SPANISH_NICARAGUA 0x4C0A +#define TT_MS_LANGID_SPANISH_PUERTO_RICO 0x500A +#define TT_MS_LANGID_SPANISH_UNITED_STATES 0x540A + /* The following ID blatantly violate MS specs by using a */ + /* sublanguage > 0x1F. */ +#define TT_MS_LANGID_SPANISH_LATIN_AMERICA 0xE40AU +#define TT_MS_LANGID_FINNISH_FINLAND 0x040B +#define TT_MS_LANGID_FRENCH_FRANCE 0x040C +#define TT_MS_LANGID_FRENCH_BELGIUM 0x080C +#define TT_MS_LANGID_FRENCH_CANADA 0x0C0C +#define TT_MS_LANGID_FRENCH_SWITZERLAND 0x100C +#define TT_MS_LANGID_FRENCH_LUXEMBOURG 0x140C +#define TT_MS_LANGID_FRENCH_MONACO 0x180C +#define TT_MS_LANGID_FRENCH_WEST_INDIES 0x1C0C +#define TT_MS_LANGID_FRENCH_REUNION 0x200C +#define TT_MS_LANGID_FRENCH_CONGO 0x240C + /* which was formerly: */ +#define TT_MS_LANGID_FRENCH_ZAIRE TT_MS_LANGID_FRENCH_CONGO +#define TT_MS_LANGID_FRENCH_SENEGAL 0x280C +#define TT_MS_LANGID_FRENCH_CAMEROON 0x2C0C +#define TT_MS_LANGID_FRENCH_COTE_D_IVOIRE 0x300C +#define TT_MS_LANGID_FRENCH_MALI 0x340C +#define TT_MS_LANGID_FRENCH_MOROCCO 0x380C +#define TT_MS_LANGID_FRENCH_HAITI 0x3C0C + /* and another violation of the spec (see 0xE40AU) */ +#define TT_MS_LANGID_FRENCH_NORTH_AFRICA 0xE40CU +#define TT_MS_LANGID_HEBREW_ISRAEL 0x040D +#define TT_MS_LANGID_HUNGARIAN_HUNGARY 0x040E +#define TT_MS_LANGID_ICELANDIC_ICELAND 0x040F +#define TT_MS_LANGID_ITALIAN_ITALY 0x0410 +#define TT_MS_LANGID_ITALIAN_SWITZERLAND 0x0810 +#define TT_MS_LANGID_JAPANESE_JAPAN 0x0411 +#define TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA 0x0412 +#define TT_MS_LANGID_KOREAN_JOHAB_KOREA 0x0812 +#define TT_MS_LANGID_DUTCH_NETHERLANDS 0x0413 +#define TT_MS_LANGID_DUTCH_BELGIUM 0x0813 +#define TT_MS_LANGID_NORWEGIAN_NORWAY_BOKMAL 0x0414 +#define TT_MS_LANGID_NORWEGIAN_NORWAY_NYNORSK 0x0814 +#define TT_MS_LANGID_POLISH_POLAND 0x0415 +#define TT_MS_LANGID_PORTUGUESE_BRAZIL 0x0416 +#define TT_MS_LANGID_PORTUGUESE_PORTUGAL 0x0816 +#define TT_MS_LANGID_RHAETO_ROMANIC_SWITZERLAND 0x0417 +#define TT_MS_LANGID_ROMANIAN_ROMANIA 0x0418 +#define TT_MS_LANGID_MOLDAVIAN_MOLDAVIA 0x0818 +#define TT_MS_LANGID_RUSSIAN_RUSSIA 0x0419 +#define TT_MS_LANGID_RUSSIAN_MOLDAVIA 0x0819 +#define TT_MS_LANGID_CROATIAN_CROATIA 0x041A +#define TT_MS_LANGID_SERBIAN_SERBIA_LATIN 0x081A +#define TT_MS_LANGID_SERBIAN_SERBIA_CYRILLIC 0x0C1A + +#if 0 /* this used to be this value, but it looks like we were wrong */ +#define TT_MS_LANGID_BOSNIAN_BOSNIA_HERZEGOVINA 0x101A +#else /* current sources say */ +#define TT_MS_LANGID_CROATIAN_BOSNIA_HERZEGOVINA 0x101A +#define TT_MS_LANGID_BOSNIAN_BOSNIA_HERZEGOVINA 0x141A + /* and XPsp2 Platform SDK added (2004-07-26) */ + /* Names are shortened to be significant within 40 chars. */ +#define TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_LATIN 0x181A +#define TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_CYRILLIC 0x181A +#endif + +#define TT_MS_LANGID_SLOVAK_SLOVAKIA 0x041B +#define TT_MS_LANGID_ALBANIAN_ALBANIA 0x041C +#define TT_MS_LANGID_SWEDISH_SWEDEN 0x041D +#define TT_MS_LANGID_SWEDISH_FINLAND 0x081D +#define TT_MS_LANGID_THAI_THAILAND 0x041E +#define TT_MS_LANGID_TURKISH_TURKEY 0x041F +#define TT_MS_LANGID_URDU_PAKISTAN 0x0420 +#define TT_MS_LANGID_URDU_INDIA 0x0820 +#define TT_MS_LANGID_INDONESIAN_INDONESIA 0x0421 +#define TT_MS_LANGID_UKRAINIAN_UKRAINE 0x0422 +#define TT_MS_LANGID_BELARUSIAN_BELARUS 0x0423 +#define TT_MS_LANGID_SLOVENE_SLOVENIA 0x0424 +#define TT_MS_LANGID_ESTONIAN_ESTONIA 0x0425 +#define TT_MS_LANGID_LATVIAN_LATVIA 0x0426 +#define TT_MS_LANGID_LITHUANIAN_LITHUANIA 0x0427 +#define TT_MS_LANGID_CLASSIC_LITHUANIAN_LITHUANIA 0x0827 +#define TT_MS_LANGID_TAJIK_TAJIKISTAN 0x0428 +#define TT_MS_LANGID_FARSI_IRAN 0x0429 +#define TT_MS_LANGID_VIETNAMESE_VIET_NAM 0x042A +#define TT_MS_LANGID_ARMENIAN_ARMENIA 0x042B +#define TT_MS_LANGID_AZERI_AZERBAIJAN_LATIN 0x042C +#define TT_MS_LANGID_AZERI_AZERBAIJAN_CYRILLIC 0x082C +#define TT_MS_LANGID_BASQUE_SPAIN 0x042D +#define TT_MS_LANGID_SORBIAN_GERMANY 0x042E +#define TT_MS_LANGID_MACEDONIAN_MACEDONIA 0x042F +#define TT_MS_LANGID_SUTU_SOUTH_AFRICA 0x0430 +#define TT_MS_LANGID_TSONGA_SOUTH_AFRICA 0x0431 +#define TT_MS_LANGID_TSWANA_SOUTH_AFRICA 0x0432 +#define TT_MS_LANGID_VENDA_SOUTH_AFRICA 0x0433 +#define TT_MS_LANGID_XHOSA_SOUTH_AFRICA 0x0434 +#define TT_MS_LANGID_ZULU_SOUTH_AFRICA 0x0435 +#define TT_MS_LANGID_AFRIKAANS_SOUTH_AFRICA 0x0436 +#define TT_MS_LANGID_GEORGIAN_GEORGIA 0x0437 +#define TT_MS_LANGID_FAEROESE_FAEROE_ISLANDS 0x0438 +#define TT_MS_LANGID_HINDI_INDIA 0x0439 +#define TT_MS_LANGID_MALTESE_MALTA 0x043A + /* Added by XPsp2 Platform SDK (2004-07-26) */ +#define TT_MS_LANGID_SAMI_NORTHERN_NORWAY 0x043B +#define TT_MS_LANGID_SAMI_NORTHERN_SWEDEN 0x083B +#define TT_MS_LANGID_SAMI_NORTHERN_FINLAND 0x0C3B +#define TT_MS_LANGID_SAMI_LULE_NORWAY 0x103B +#define TT_MS_LANGID_SAMI_LULE_SWEDEN 0x143B +#define TT_MS_LANGID_SAMI_SOUTHERN_NORWAY 0x183B +#define TT_MS_LANGID_SAMI_SOUTHERN_SWEDEN 0x1C3B +#define TT_MS_LANGID_SAMI_SKOLT_FINLAND 0x203B +#define TT_MS_LANGID_SAMI_INARI_FINLAND 0x243B + /* ... and we also keep our old identifier... */ +#define TT_MS_LANGID_SAAMI_LAPONIA 0x043B + +#if 0 /* this seems to be a previous inversion */ +#define TT_MS_LANGID_IRISH_GAELIC_IRELAND 0x043C +#define TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM 0x083C +#else +#define TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM 0x083C +#define TT_MS_LANGID_IRISH_GAELIC_IRELAND 0x043C +#endif + +#define TT_MS_LANGID_YIDDISH_GERMANY 0x043D +#define TT_MS_LANGID_MALAY_MALAYSIA 0x043E +#define TT_MS_LANGID_MALAY_BRUNEI_DARUSSALAM 0x083E +#define TT_MS_LANGID_KAZAK_KAZAKSTAN 0x043F +#define TT_MS_LANGID_KIRGHIZ_KIRGHIZSTAN /* Cyrillic*/ 0x0440 + /* alias declared in Windows 2000 */ +#define TT_MS_LANGID_KIRGHIZ_KIRGHIZ_REPUBLIC \ + TT_MS_LANGID_KIRGHIZ_KIRGHIZSTAN + +#define TT_MS_LANGID_SWAHILI_KENYA 0x0441 +#define TT_MS_LANGID_TURKMEN_TURKMENISTAN 0x0442 +#define TT_MS_LANGID_UZBEK_UZBEKISTAN_LATIN 0x0443 +#define TT_MS_LANGID_UZBEK_UZBEKISTAN_CYRILLIC 0x0843 +#define TT_MS_LANGID_TATAR_TATARSTAN 0x0444 +#define TT_MS_LANGID_BENGALI_INDIA 0x0445 +#define TT_MS_LANGID_BENGALI_BANGLADESH 0x0845 +#define TT_MS_LANGID_PUNJABI_INDIA 0x0446 +#define TT_MS_LANGID_PUNJABI_ARABIC_PAKISTAN 0x0846 +#define TT_MS_LANGID_GUJARATI_INDIA 0x0447 +#define TT_MS_LANGID_ORIYA_INDIA 0x0448 +#define TT_MS_LANGID_TAMIL_INDIA 0x0449 +#define TT_MS_LANGID_TELUGU_INDIA 0x044A +#define TT_MS_LANGID_KANNADA_INDIA 0x044B +#define TT_MS_LANGID_MALAYALAM_INDIA 0x044C +#define TT_MS_LANGID_ASSAMESE_INDIA 0x044D +#define TT_MS_LANGID_MARATHI_INDIA 0x044E +#define TT_MS_LANGID_SANSKRIT_INDIA 0x044F +#define TT_MS_LANGID_MONGOLIAN_MONGOLIA /* Cyrillic */ 0x0450 +#define TT_MS_LANGID_MONGOLIAN_MONGOLIA_MONGOLIAN 0x0850 +#define TT_MS_LANGID_TIBETAN_CHINA 0x0451 + /* Don't use the next constant! It has */ + /* (1) the wrong spelling (Dzonghka) */ + /* (2) Microsoft doesn't officially define it -- */ + /* at least it is not in the List of Local */ + /* ID Values. */ + /* (3) Dzongkha is not the same language as */ + /* Tibetan, so merging it is wrong anyway. */ + /* */ + /* TT_MS_LANGID_TIBETAN_BHUTAN is correct, BTW. */ +#define TT_MS_LANGID_DZONGHKA_BHUTAN 0x0851 + +#if 0 + /* the following used to be defined */ +#define TT_MS_LANGID_TIBETAN_BHUTAN 0x0451 + /* ... but it was changed; */ +#else + /* So we will continue to #define it, but with the correct value */ +#define TT_MS_LANGID_TIBETAN_BHUTAN TT_MS_LANGID_DZONGHKA_BHUTAN +#endif + +#define TT_MS_LANGID_WELSH_WALES 0x0452 +#define TT_MS_LANGID_KHMER_CAMBODIA 0x0453 +#define TT_MS_LANGID_LAO_LAOS 0x0454 +#define TT_MS_LANGID_BURMESE_MYANMAR 0x0455 +#define TT_MS_LANGID_GALICIAN_SPAIN 0x0456 +#define TT_MS_LANGID_KONKANI_INDIA 0x0457 +#define TT_MS_LANGID_MANIPURI_INDIA /* Bengali */ 0x0458 +#define TT_MS_LANGID_SINDHI_INDIA /* Arabic */ 0x0459 +#define TT_MS_LANGID_SINDHI_PAKISTAN 0x0859 + /* Missing a LCID for Sindhi in Devanagari script */ +#define TT_MS_LANGID_SYRIAC_SYRIA 0x045A +#define TT_MS_LANGID_SINHALESE_SRI_LANKA 0x045B +#define TT_MS_LANGID_CHEROKEE_UNITED_STATES 0x045C +#define TT_MS_LANGID_INUKTITUT_CANADA 0x045D +#define TT_MS_LANGID_AMHARIC_ETHIOPIA 0x045E +#define TT_MS_LANGID_TAMAZIGHT_MOROCCO /* Arabic */ 0x045F +#define TT_MS_LANGID_TAMAZIGHT_MOROCCO_LATIN 0x085F + /* Missing a LCID for Tifinagh script */ +#define TT_MS_LANGID_KASHMIRI_PAKISTAN /* Arabic */ 0x0460 + /* Spelled this way by XPsp2 Platform SDK (2004-07-26) */ + /* script is yet unclear... might be Arabic, Nagari or Sharada */ +#define TT_MS_LANGID_KASHMIRI_SASIA 0x0860 + /* ... and aliased (by MS) for compatibility reasons. */ +#define TT_MS_LANGID_KASHMIRI_INDIA TT_MS_LANGID_KASHMIRI_SASIA +#define TT_MS_LANGID_NEPALI_NEPAL 0x0461 +#define TT_MS_LANGID_NEPALI_INDIA 0x0861 +#define TT_MS_LANGID_FRISIAN_NETHERLANDS 0x0462 +#define TT_MS_LANGID_PASHTO_AFGHANISTAN 0x0463 +#define TT_MS_LANGID_FILIPINO_PHILIPPINES 0x0464 +#define TT_MS_LANGID_DHIVEHI_MALDIVES 0x0465 + /* alias declared in Windows 2000 */ +#define TT_MS_LANGID_DIVEHI_MALDIVES TT_MS_LANGID_DHIVEHI_MALDIVES +#define TT_MS_LANGID_EDO_NIGERIA 0x0466 +#define TT_MS_LANGID_FULFULDE_NIGERIA 0x0467 +#define TT_MS_LANGID_HAUSA_NIGERIA 0x0468 +#define TT_MS_LANGID_IBIBIO_NIGERIA 0x0469 +#define TT_MS_LANGID_YORUBA_NIGERIA 0x046A +#define TT_MS_LANGID_QUECHUA_BOLIVIA 0x046B +#define TT_MS_LANGID_QUECHUA_ECUADOR 0x086B +#define TT_MS_LANGID_QUECHUA_PERU 0x0C6B +#define TT_MS_LANGID_SEPEDI_SOUTH_AFRICA 0x046C + /* Also spelled by XPsp2 Platform SDK (2004-07-26) */ +#define TT_MS_LANGID_SOTHO_SOUTHERN_SOUTH_AFRICA \ + TT_MS_LANGID_SEPEDI_SOUTH_AFRICA + /* language codes 0x046D, 0x046E and 0x046F are (still) unknown. */ +#define TT_MS_LANGID_IGBO_NIGERIA 0x0470 +#define TT_MS_LANGID_KANURI_NIGERIA 0x0471 +#define TT_MS_LANGID_OROMO_ETHIOPIA 0x0472 +#define TT_MS_LANGID_TIGRIGNA_ETHIOPIA 0x0473 +#define TT_MS_LANGID_TIGRIGNA_ERYTHREA 0x0873 + /* also spelled in the `Passport SDK' list as: */ +#define TT_MS_LANGID_TIGRIGNA_ERYTREA TT_MS_LANGID_TIGRIGNA_ERYTHREA +#define TT_MS_LANGID_GUARANI_PARAGUAY 0x0474 +#define TT_MS_LANGID_HAWAIIAN_UNITED_STATES 0x0475 +#define TT_MS_LANGID_LATIN 0x0476 +#define TT_MS_LANGID_SOMALI_SOMALIA 0x0477 + /* Note: Yi does not have a (proper) ISO 639-2 code, since it is mostly */ + /* not written (but OTOH the peculiar writing system is worth */ + /* studying). */ +#define TT_MS_LANGID_YI_CHINA 0x0478 +#define TT_MS_LANGID_PAPIAMENTU_NETHERLANDS_ANTILLES 0x0479 + /* language codes from 0x047A to 0x047F are (still) unknown. */ +#define TT_MS_LANGID_UIGHUR_CHINA 0x0480 +#define TT_MS_LANGID_MAORI_NEW_ZEALAND 0x0481 + +#if 0 /* not deemed useful for fonts */ +#define TT_MS_LANGID_HUMAN_INTERFACE_DEVICE 0x04FF +#endif + + + /*************************************************************************/ + /* */ + /* Possible values of the `name' identifier field in the name records of */ + /* the TTF `name' table. These values are platform independent. */ + /* */ +#define TT_NAME_ID_COPYRIGHT 0 +#define TT_NAME_ID_FONT_FAMILY 1 +#define TT_NAME_ID_FONT_SUBFAMILY 2 +#define TT_NAME_ID_UNIQUE_ID 3 +#define TT_NAME_ID_FULL_NAME 4 +#define TT_NAME_ID_VERSION_STRING 5 +#define TT_NAME_ID_PS_NAME 6 +#define TT_NAME_ID_TRADEMARK 7 + + /* the following values are from the OpenType spec */ +#define TT_NAME_ID_MANUFACTURER 8 +#define TT_NAME_ID_DESIGNER 9 +#define TT_NAME_ID_DESCRIPTION 10 +#define TT_NAME_ID_VENDOR_URL 11 +#define TT_NAME_ID_DESIGNER_URL 12 +#define TT_NAME_ID_LICENSE 13 +#define TT_NAME_ID_LICENSE_URL 14 + /* number 15 is reserved */ +#define TT_NAME_ID_PREFERRED_FAMILY 16 +#define TT_NAME_ID_PREFERRED_SUBFAMILY 17 +#define TT_NAME_ID_MAC_FULL_NAME 18 + + /* The following code is new as of 2000-01-21 */ +#define TT_NAME_ID_SAMPLE_TEXT 19 + + /* This is new in OpenType 1.3 */ +#define TT_NAME_ID_CID_FINDFONT_NAME 20 + + /* This is new in OpenType 1.5 */ +#define TT_NAME_ID_WWS_FAMILY 21 +#define TT_NAME_ID_WWS_SUBFAMILY 22 + + + /*************************************************************************/ + /* */ + /* Bit mask values for the Unicode Ranges from the TTF `OS2 ' table. */ + /* */ + /* Updated 08-Nov-2008. */ + /* */ + + /* Bit 0 Basic Latin */ +#define TT_UCR_BASIC_LATIN (1L << 0) /* U+0020-U+007E */ + /* Bit 1 C1 Controls and Latin-1 Supplement */ +#define TT_UCR_LATIN1_SUPPLEMENT (1L << 1) /* U+0080-U+00FF */ + /* Bit 2 Latin Extended-A */ +#define TT_UCR_LATIN_EXTENDED_A (1L << 2) /* U+0100-U+017F */ + /* Bit 3 Latin Extended-B */ +#define TT_UCR_LATIN_EXTENDED_B (1L << 3) /* U+0180-U+024F */ + /* Bit 4 IPA Extensions */ + /* Phonetic Extensions */ + /* Phonetic Extensions Supplement */ +#define TT_UCR_IPA_EXTENSIONS (1L << 4) /* U+0250-U+02AF */ + /* U+1D00-U+1D7F */ + /* U+1D80-U+1DBF */ + /* Bit 5 Spacing Modifier Letters */ + /* Modifier Tone Letters */ +#define TT_UCR_SPACING_MODIFIER (1L << 5) /* U+02B0-U+02FF */ + /* U+A700-U+A71F */ + /* Bit 6 Combining Diacritical Marks */ + /* Combining Diacritical Marks Supplement */ +#define TT_UCR_COMBINING_DIACRITICS (1L << 6) /* U+0300-U+036F */ + /* U+1DC0-U+1DFF */ + /* Bit 7 Greek and Coptic */ +#define TT_UCR_GREEK (1L << 7) /* U+0370-U+03FF */ + /* Bit 8 Coptic */ +#define TT_UCR_COPTIC (1L << 8) /* U+2C80-U+2CFF */ + /* Bit 9 Cyrillic */ + /* Cyrillic Supplement */ + /* Cyrillic Extended-A */ + /* Cyrillic Extended-B */ +#define TT_UCR_CYRILLIC (1L << 9) /* U+0400-U+04FF */ + /* U+0500-U+052F */ + /* U+2DE0-U+2DFF */ + /* U+A640-U+A69F */ + /* Bit 10 Armenian */ +#define TT_UCR_ARMENIAN (1L << 10) /* U+0530-U+058F */ + /* Bit 11 Hebrew */ +#define TT_UCR_HEBREW (1L << 11) /* U+0590-U+05FF */ + /* Bit 12 Vai */ +#define TT_UCR_VAI (1L << 12) /* U+A500-U+A63F */ + /* Bit 13 Arabic */ + /* Arabic Supplement */ +#define TT_UCR_ARABIC (1L << 13) /* U+0600-U+06FF */ + /* U+0750-U+077F */ + /* Bit 14 NKo */ +#define TT_UCR_NKO (1L << 14) /* U+07C0-U+07FF */ + /* Bit 15 Devanagari */ +#define TT_UCR_DEVANAGARI (1L << 15) /* U+0900-U+097F */ + /* Bit 16 Bengali */ +#define TT_UCR_BENGALI (1L << 16) /* U+0980-U+09FF */ + /* Bit 17 Gurmukhi */ +#define TT_UCR_GURMUKHI (1L << 17) /* U+0A00-U+0A7F */ + /* Bit 18 Gujarati */ +#define TT_UCR_GUJARATI (1L << 18) /* U+0A80-U+0AFF */ + /* Bit 19 Oriya */ +#define TT_UCR_ORIYA (1L << 19) /* U+0B00-U+0B7F */ + /* Bit 20 Tamil */ +#define TT_UCR_TAMIL (1L << 20) /* U+0B80-U+0BFF */ + /* Bit 21 Telugu */ +#define TT_UCR_TELUGU (1L << 21) /* U+0C00-U+0C7F */ + /* Bit 22 Kannada */ +#define TT_UCR_KANNADA (1L << 22) /* U+0C80-U+0CFF */ + /* Bit 23 Malayalam */ +#define TT_UCR_MALAYALAM (1L << 23) /* U+0D00-U+0D7F */ + /* Bit 24 Thai */ +#define TT_UCR_THAI (1L << 24) /* U+0E00-U+0E7F */ + /* Bit 25 Lao */ +#define TT_UCR_LAO (1L << 25) /* U+0E80-U+0EFF */ + /* Bit 26 Georgian */ + /* Georgian Supplement */ +#define TT_UCR_GEORGIAN (1L << 26) /* U+10A0-U+10FF */ + /* U+2D00-U+2D2F */ + /* Bit 27 Balinese */ +#define TT_UCR_BALINESE (1L << 27) /* U+1B00-U+1B7F */ + /* Bit 28 Hangul Jamo */ +#define TT_UCR_HANGUL_JAMO (1L << 28) /* U+1100-U+11FF */ + /* Bit 29 Latin Extended Additional */ + /* Latin Extended-C */ + /* Latin Extended-D */ +#define TT_UCR_LATIN_EXTENDED_ADDITIONAL (1L << 29) /* U+1E00-U+1EFF */ + /* U+2C60-U+2C7F */ + /* U+A720-U+A7FF */ + /* Bit 30 Greek Extended */ +#define TT_UCR_GREEK_EXTENDED (1L << 30) /* U+1F00-U+1FFF */ + /* Bit 31 General Punctuation */ + /* Supplemental Punctuation */ +#define TT_UCR_GENERAL_PUNCTUATION (1L << 31) /* U+2000-U+206F */ + /* U+2E00-U+2E7F */ + /* Bit 32 Superscripts And Subscripts */ +#define TT_UCR_SUPERSCRIPTS_SUBSCRIPTS (1L << 0) /* U+2070-U+209F */ + /* Bit 33 Currency Symbols */ +#define TT_UCR_CURRENCY_SYMBOLS (1L << 1) /* U+20A0-U+20CF */ + /* Bit 34 Combining Diacritical Marks For Symbols */ +#define TT_UCR_COMBINING_DIACRITICS_SYMB (1L << 2) /* U+20D0-U+20FF */ + /* Bit 35 Letterlike Symbols */ +#define TT_UCR_LETTERLIKE_SYMBOLS (1L << 3) /* U+2100-U+214F */ + /* Bit 36 Number Forms */ +#define TT_UCR_NUMBER_FORMS (1L << 4) /* U+2150-U+218F */ + /* Bit 37 Arrows */ + /* Supplemental Arrows-A */ + /* Supplemental Arrows-B */ + /* Miscellaneous Symbols and Arrows */ +#define TT_UCR_ARROWS (1L << 5) /* U+2190-U+21FF */ + /* U+27F0-U+27FF */ + /* U+2900-U+297F */ + /* U+2B00-U+2BFF */ + /* Bit 38 Mathematical Operators */ + /* Supplemental Mathematical Operators */ + /* Miscellaneous Mathematical Symbols-A */ + /* Miscellaneous Mathematical Symbols-B */ +#define TT_UCR_MATHEMATICAL_OPERATORS (1L << 6) /* U+2200-U+22FF */ + /* U+2A00-U+2AFF */ + /* U+27C0-U+27EF */ + /* U+2980-U+29FF */ + /* Bit 39 Miscellaneous Technical */ +#define TT_UCR_MISCELLANEOUS_TECHNICAL (1L << 7) /* U+2300-U+23FF */ + /* Bit 40 Control Pictures */ +#define TT_UCR_CONTROL_PICTURES (1L << 8) /* U+2400-U+243F */ + /* Bit 41 Optical Character Recognition */ +#define TT_UCR_OCR (1L << 9) /* U+2440-U+245F */ + /* Bit 42 Enclosed Alphanumerics */ +#define TT_UCR_ENCLOSED_ALPHANUMERICS (1L << 10) /* U+2460-U+24FF */ + /* Bit 43 Box Drawing */ +#define TT_UCR_BOX_DRAWING (1L << 11) /* U+2500-U+257F */ + /* Bit 44 Block Elements */ +#define TT_UCR_BLOCK_ELEMENTS (1L << 12) /* U+2580-U+259F */ + /* Bit 45 Geometric Shapes */ +#define TT_UCR_GEOMETRIC_SHAPES (1L << 13) /* U+25A0-U+25FF */ + /* Bit 46 Miscellaneous Symbols */ +#define TT_UCR_MISCELLANEOUS_SYMBOLS (1L << 14) /* U+2600-U+26FF */ + /* Bit 47 Dingbats */ +#define TT_UCR_DINGBATS (1L << 15) /* U+2700-U+27BF */ + /* Bit 48 CJK Symbols and Punctuation */ +#define TT_UCR_CJK_SYMBOLS (1L << 16) /* U+3000-U+303F */ + /* Bit 49 Hiragana */ +#define TT_UCR_HIRAGANA (1L << 17) /* U+3040-U+309F */ + /* Bit 50 Katakana */ + /* Katakana Phonetic Extensions */ +#define TT_UCR_KATAKANA (1L << 18) /* U+30A0-U+30FF */ + /* U+31F0-U+31FF */ + /* Bit 51 Bopomofo */ + /* Bopomofo Extended */ +#define TT_UCR_BOPOMOFO (1L << 19) /* U+3100-U+312F */ + /* U+31A0-U+31BF */ + /* Bit 52 Hangul Compatibility Jamo */ +#define TT_UCR_HANGUL_COMPATIBILITY_JAMO (1L << 20) /* U+3130-U+318F */ + /* Bit 53 Phags-Pa */ +#define TT_UCR_CJK_MISC (1L << 21) /* U+A840-U+A87F */ +#define TT_UCR_KANBUN TT_UCR_CJK_MISC /* deprecated */ +#define TT_UCR_PHAGSPA + /* Bit 54 Enclosed CJK Letters and Months */ +#define TT_UCR_ENCLOSED_CJK_LETTERS_MONTHS (1L << 22) /* U+3200-U+32FF */ + /* Bit 55 CJK Compatibility */ +#define TT_UCR_CJK_COMPATIBILITY (1L << 23) /* U+3300-U+33FF */ + /* Bit 56 Hangul Syllables */ +#define TT_UCR_HANGUL (1L << 24) /* U+AC00-U+D7A3 */ + /* Bit 57 High Surrogates */ + /* High Private Use Surrogates */ + /* Low Surrogates */ + /* */ + /* According to OpenType specs v.1.3+, */ + /* setting bit 57 implies that there is */ + /* at least one codepoint beyond the */ + /* Basic Multilingual Plane that is */ + /* supported by this font. So it really */ + /* means >= U+10000 */ +#define TT_UCR_SURROGATES (1L << 25) /* U+D800-U+DB7F */ + /* U+DB80-U+DBFF */ + /* U+DC00-U+DFFF */ +#define TT_UCR_NON_PLANE_0 TT_UCR_SURROGATES + /* Bit 58 Phoenician */ +#define TT_UCR_PHOENICIAN (1L << 26) /*U+10900-U+1091F*/ + /* Bit 59 CJK Unified Ideographs */ + /* CJK Radicals Supplement */ + /* Kangxi Radicals */ + /* Ideographic Description Characters */ + /* CJK Unified Ideographs Extension A */ + /* CJK Unified Ideographs Extension B */ + /* Kanbun */ +#define TT_UCR_CJK_UNIFIED_IDEOGRAPHS (1L << 27) /* U+4E00-U+9FFF */ + /* U+2E80-U+2EFF */ + /* U+2F00-U+2FDF */ + /* U+2FF0-U+2FFF */ + /* U+3400-U+4DB5 */ + /*U+20000-U+2A6DF*/ + /* U+3190-U+319F */ + /* Bit 60 Private Use */ +#define TT_UCR_PRIVATE_USE (1L << 28) /* U+E000-U+F8FF */ + /* Bit 61 CJK Strokes */ + /* CJK Compatibility Ideographs */ + /* CJK Compatibility Ideographs Supplement */ +#define TT_UCR_CJK_COMPATIBILITY_IDEOGRAPHS (1L << 29) /* U+31C0-U+31EF */ + /* U+F900-U+FAFF */ + /*U+2F800-U+2FA1F*/ + /* Bit 62 Alphabetic Presentation Forms */ +#define TT_UCR_ALPHABETIC_PRESENTATION_FORMS (1L << 30) /* U+FB00-U+FB4F */ + /* Bit 63 Arabic Presentation Forms-A */ +#define TT_UCR_ARABIC_PRESENTATIONS_A (1L << 31) /* U+FB50-U+FDFF */ + /* Bit 64 Combining Half Marks */ +#define TT_UCR_COMBINING_HALF_MARKS (1L << 0) /* U+FE20-U+FE2F */ + /* Bit 65 Vertical forms */ + /* CJK Compatibility Forms */ +#define TT_UCR_CJK_COMPATIBILITY_FORMS (1L << 1) /* U+FE10-U+FE1F */ + /* U+FE30-U+FE4F */ + /* Bit 66 Small Form Variants */ +#define TT_UCR_SMALL_FORM_VARIANTS (1L << 2) /* U+FE50-U+FE6F */ + /* Bit 67 Arabic Presentation Forms-B */ +#define TT_UCR_ARABIC_PRESENTATIONS_B (1L << 3) /* U+FE70-U+FEFE */ + /* Bit 68 Halfwidth and Fullwidth Forms */ +#define TT_UCR_HALFWIDTH_FULLWIDTH_FORMS (1L << 4) /* U+FF00-U+FFEF */ + /* Bit 69 Specials */ +#define TT_UCR_SPECIALS (1L << 5) /* U+FFF0-U+FFFD */ + /* Bit 70 Tibetan */ +#define TT_UCR_TIBETAN (1L << 6) /* U+0F00-U+0FFF */ + /* Bit 71 Syriac */ +#define TT_UCR_SYRIAC (1L << 7) /* U+0700-U+074F */ + /* Bit 72 Thaana */ +#define TT_UCR_THAANA (1L << 8) /* U+0780-U+07BF */ + /* Bit 73 Sinhala */ +#define TT_UCR_SINHALA (1L << 9) /* U+0D80-U+0DFF */ + /* Bit 74 Myanmar */ +#define TT_UCR_MYANMAR (1L << 10) /* U+1000-U+109F */ + /* Bit 75 Ethiopic */ + /* Ethiopic Supplement */ + /* Ethiopic Extended */ +#define TT_UCR_ETHIOPIC (1L << 11) /* U+1200-U+137F */ + /* U+1380-U+139F */ + /* U+2D80-U+2DDF */ + /* Bit 76 Cherokee */ +#define TT_UCR_CHEROKEE (1L << 12) /* U+13A0-U+13FF */ + /* Bit 77 Unified Canadian Aboriginal Syllabics */ +#define TT_UCR_CANADIAN_ABORIGINAL_SYLLABICS (1L << 13) /* U+1400-U+167F */ + /* Bit 78 Ogham */ +#define TT_UCR_OGHAM (1L << 14) /* U+1680-U+169F */ + /* Bit 79 Runic */ +#define TT_UCR_RUNIC (1L << 15) /* U+16A0-U+16FF */ + /* Bit 80 Khmer */ + /* Khmer Symbols */ +#define TT_UCR_KHMER (1L << 16) /* U+1780-U+17FF */ + /* U+19E0-U+19FF */ + /* Bit 81 Mongolian */ +#define TT_UCR_MONGOLIAN (1L << 17) /* U+1800-U+18AF */ + /* Bit 82 Braille Patterns */ +#define TT_UCR_BRAILLE (1L << 18) /* U+2800-U+28FF */ + /* Bit 83 Yi Syllables */ + /* Yi Radicals */ +#define TT_UCR_YI (1L << 19) /* U+A000-U+A48F */ + /* U+A490-U+A4CF */ + /* Bit 84 Tagalog */ + /* Hanunoo */ + /* Buhid */ + /* Tagbanwa */ +#define TT_UCR_PHILIPPINE (1L << 20) /* U+1700-U+171F */ + /* U+1720-U+173F */ + /* U+1740-U+175F */ + /* U+1760-U+177F */ + /* Bit 85 Old Italic */ +#define TT_UCR_OLD_ITALIC (1L << 21) /*U+10300-U+1032F*/ + /* Bit 86 Gothic */ +#define TT_UCR_GOTHIC (1L << 22) /*U+10330-U+1034F*/ + /* Bit 87 Deseret */ +#define TT_UCR_DESERET (1L << 23) /*U+10400-U+1044F*/ + /* Bit 88 Byzantine Musical Symbols */ + /* Musical Symbols */ + /* Ancient Greek Musical Notation */ +#define TT_UCR_MUSICAL_SYMBOLS (1L << 24) /*U+1D000-U+1D0FF*/ + /*U+1D100-U+1D1FF*/ + /*U+1D200-U+1D24F*/ + /* Bit 89 Mathematical Alphanumeric Symbols */ +#define TT_UCR_MATH_ALPHANUMERIC_SYMBOLS (1L << 25) /*U+1D400-U+1D7FF*/ + /* Bit 90 Private Use (plane 15) */ + /* Private Use (plane 16) */ +#define TT_UCR_PRIVATE_USE_SUPPLEMENTARY (1L << 26) /*U+F0000-U+FFFFD*/ + /*U+100000-U+10FFFD*/ + /* Bit 91 Variation Selectors */ + /* Variation Selectors Supplement */ +#define TT_UCR_VARIATION_SELECTORS (1L << 27) /* U+FE00-U+FE0F */ + /*U+E0100-U+E01EF*/ + /* Bit 92 Tags */ +#define TT_UCR_TAGS (1L << 28) /*U+E0000-U+E007F*/ + /* Bit 93 Limbu */ +#define TT_UCR_LIMBU (1L << 29) /* U+1900-U+194F */ + /* Bit 94 Tai Le */ +#define TT_UCR_TAI_LE (1L << 30) /* U+1950-U+197F */ + /* Bit 95 New Tai Lue */ +#define TT_UCR_NEW_TAI_LUE (1L << 31) /* U+1980-U+19DF */ + /* Bit 96 Buginese */ +#define TT_UCR_BUGINESE (1L << 0) /* U+1A00-U+1A1F */ + /* Bit 97 Glagolitic */ +#define TT_UCR_GLAGOLITIC (1L << 1) /* U+2C00-U+2C5F */ + /* Bit 98 Tifinagh */ +#define TT_UCR_TIFINAGH (1L << 2) /* U+2D30-U+2D7F */ + /* Bit 99 Yijing Hexagram Symbols */ +#define TT_UCR_YIJING (1L << 3) /* U+4DC0-U+4DFF */ + /* Bit 100 Syloti Nagri */ +#define TT_UCR_SYLOTI_NAGRI (1L << 4) /* U+A800-U+A82F */ + /* Bit 101 Linear B Syllabary */ + /* Linear B Ideograms */ + /* Aegean Numbers */ +#define TT_UCR_LINEAR_B (1L << 5) /*U+10000-U+1007F*/ + /*U+10080-U+100FF*/ + /*U+10100-U+1013F*/ + /* Bit 102 Ancient Greek Numbers */ +#define TT_UCR_ANCIENT_GREEK_NUMBERS (1L << 6) /*U+10140-U+1018F*/ + /* Bit 103 Ugaritic */ +#define TT_UCR_UGARITIC (1L << 7) /*U+10380-U+1039F*/ + /* Bit 104 Old Persian */ +#define TT_UCR_OLD_PERSIAN (1L << 8) /*U+103A0-U+103DF*/ + /* Bit 105 Shavian */ +#define TT_UCR_SHAVIAN (1L << 9) /*U+10450-U+1047F*/ + /* Bit 106 Osmanya */ +#define TT_UCR_OSMANYA (1L << 10) /*U+10480-U+104AF*/ + /* Bit 107 Cypriot Syllabary */ +#define TT_UCR_CYPRIOT_SYLLABARY (1L << 11) /*U+10800-U+1083F*/ + /* Bit 108 Kharoshthi */ +#define TT_UCR_KHAROSHTHI (1L << 12) /*U+10A00-U+10A5F*/ + /* Bit 109 Tai Xuan Jing Symbols */ +#define TT_UCR_TAI_XUAN_JING (1L << 13) /*U+1D300-U+1D35F*/ + /* Bit 110 Cuneiform */ + /* Cuneiform Numbers and Punctuation */ +#define TT_UCR_CUNEIFORM (1L << 14) /*U+12000-U+123FF*/ + /*U+12400-U+1247F*/ + /* Bit 111 Counting Rod Numerals */ +#define TT_UCR_COUNTING_ROD_NUMERALS (1L << 15) /*U+1D360-U+1D37F*/ + /* Bit 112 Sundanese */ +#define TT_UCR_SUNDANESE (1L << 16) /* U+1B80-U+1BBF */ + /* Bit 113 Lepcha */ +#define TT_UCR_LEPCHA (1L << 17) /* U+1C00-U+1C4F */ + /* Bit 114 Ol Chiki */ +#define TT_UCR_OL_CHIKI (1L << 18) /* U+1C50-U+1C7F */ + /* Bit 115 Saurashtra */ +#define TT_UCR_SAURASHTRA (1L << 19) /* U+A880-U+A8DF */ + /* Bit 116 Kayah Li */ +#define TT_UCR_KAYAH_LI (1L << 20) /* U+A900-U+A92F */ + /* Bit 117 Rejang */ +#define TT_UCR_REJANG (1L << 21) /* U+A930-U+A95F */ + /* Bit 118 Cham */ +#define TT_UCR_CHAM (1L << 22) /* U+AA00-U+AA5F */ + /* Bit 119 Ancient Symbols */ +#define TT_UCR_ANCIENT_SYMBOLS (1L << 23) /*U+10190-U+101CF*/ + /* Bit 120 Phaistos Disc */ +#define TT_UCR_PHAISTOS_DISC (1L << 24) /*U+101D0-U+101FF*/ + /* Bit 121 Carian */ + /* Lycian */ + /* Lydian */ +#define TT_UCR_OLD_ANATOLIAN (1L << 25) /*U+102A0-U+102DF*/ + /*U+10280-U+1029F*/ + /*U+10920-U+1093F*/ + /* Bit 122 Domino Tiles */ + /* Mahjong Tiles */ +#define TT_UCR_GAME_TILES (1L << 26) /*U+1F030-U+1F09F*/ + /*U+1F000-U+1F02F*/ + /* Bit 123-127 Reserved for process-internal usage */ + + + /*************************************************************************/ + /* */ + /* Some compilers have a very limited length of identifiers. */ + /* */ +#if defined( __TURBOC__ ) && __TURBOC__ < 0x0410 || defined( __PACIFIC__ ) +#define HAVE_LIMIT_ON_IDENTS +#endif + + +#ifndef HAVE_LIMIT_ON_IDENTS + + + /*************************************************************************/ + /* */ + /* Here some alias #defines in order to be clearer. */ + /* */ + /* These are not always #defined to stay within the 31~character limit, */ + /* which some compilers have. */ + /* */ + /* Credits go to Dave Hoo <dhoo@flash.net> for pointing out that modern */ + /* Borland compilers (read: from BC++ 3.1 on) can increase this limit. */ + /* If you get a warning with such a compiler, use the -i40 switch. */ + /* */ +#define TT_UCR_ARABIC_PRESENTATION_FORMS_A \ + TT_UCR_ARABIC_PRESENTATIONS_A +#define TT_UCR_ARABIC_PRESENTATION_FORMS_B \ + TT_UCR_ARABIC_PRESENTATIONS_B + +#define TT_UCR_COMBINING_DIACRITICAL_MARKS \ + TT_UCR_COMBINING_DIACRITICS +#define TT_UCR_COMBINING_DIACRITICAL_MARKS_SYMB \ + TT_UCR_COMBINING_DIACRITICS_SYMB + + +#endif /* !HAVE_LIMIT_ON_IDENTS */ + + +FT_END_HEADER + +#endif /* TTNAMEID_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/tttables.h b/android/x86/include/freetype/tttables.h new file mode 100644 index 00000000..dfe3bcb1 --- /dev/null +++ b/android/x86/include/freetype/tttables.h @@ -0,0 +1,829 @@ +/***************************************************************************/ +/* */ +/* tttables.h */ +/* */ +/* Basic SFNT/TrueType tables definitions and interface */ +/* (specification only). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTTABLES_H_ +#define TTTABLES_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* <Section> */ + /* truetype_tables */ + /* */ + /* <Title> */ + /* TrueType Tables */ + /* */ + /* <Abstract> */ + /* TrueType specific table types and functions. */ + /* */ + /* <Description> */ + /* This section contains the definition of TrueType-specific tables */ + /* as well as some routines used to access and process them. */ + /* */ + /* <Order> */ + /* TT_Header */ + /* TT_HoriHeader */ + /* TT_VertHeader */ + /* TT_OS2 */ + /* TT_Postscript */ + /* TT_PCLT */ + /* TT_MaxProfile */ + /* */ + /* FT_Sfnt_Tag */ + /* FT_Get_Sfnt_Table */ + /* FT_Load_Sfnt_Table */ + /* FT_Sfnt_Table_Info */ + /* */ + /* FT_Get_CMap_Language_ID */ + /* FT_Get_CMap_Format */ + /* */ + /* FT_PARAM_TAG_UNPATENTED_HINTING */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_Header */ + /* */ + /* <Description> */ + /* A structure used to model a TrueType font header table. All */ + /* fields follow the TrueType specification. */ + /* */ + typedef struct TT_Header_ + { + FT_Fixed Table_Version; + FT_Fixed Font_Revision; + + FT_Long CheckSum_Adjust; + FT_Long Magic_Number; + + FT_UShort Flags; + FT_UShort Units_Per_EM; + + FT_Long Created [2]; + FT_Long Modified[2]; + + FT_Short xMin; + FT_Short yMin; + FT_Short xMax; + FT_Short yMax; + + FT_UShort Mac_Style; + FT_UShort Lowest_Rec_PPEM; + + FT_Short Font_Direction; + FT_Short Index_To_Loc_Format; + FT_Short Glyph_Data_Format; + + } TT_Header; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_HoriHeader */ + /* */ + /* <Description> */ + /* A structure used to model a TrueType horizontal header, the `hhea' */ + /* table, as well as the corresponding horizontal metrics table, */ + /* i.e., the `hmtx' table. */ + /* */ + /* <Fields> */ + /* Version :: The table version. */ + /* */ + /* Ascender :: The font's ascender, i.e., the distance */ + /* from the baseline to the top-most of all */ + /* glyph points found in the font. */ + /* */ + /* This value is invalid in many fonts, as */ + /* it is usually set by the font designer, */ + /* and often reflects only a portion of the */ + /* glyphs found in the font (maybe ASCII). */ + /* */ + /* You should use the `sTypoAscender' field */ + /* of the OS/2 table instead if you want */ + /* the correct one. */ + /* */ + /* Descender :: The font's descender, i.e., the distance */ + /* from the baseline to the bottom-most of */ + /* all glyph points found in the font. It */ + /* is negative. */ + /* */ + /* This value is invalid in many fonts, as */ + /* it is usually set by the font designer, */ + /* and often reflects only a portion of the */ + /* glyphs found in the font (maybe ASCII). */ + /* */ + /* You should use the `sTypoDescender' */ + /* field of the OS/2 table instead if you */ + /* want the correct one. */ + /* */ + /* Line_Gap :: The font's line gap, i.e., the distance */ + /* to add to the ascender and descender to */ + /* get the BTB, i.e., the */ + /* baseline-to-baseline distance for the */ + /* font. */ + /* */ + /* advance_Width_Max :: This field is the maximum of all advance */ + /* widths found in the font. It can be */ + /* used to compute the maximum width of an */ + /* arbitrary string of text. */ + /* */ + /* min_Left_Side_Bearing :: The minimum left side bearing of all */ + /* glyphs within the font. */ + /* */ + /* min_Right_Side_Bearing :: The minimum right side bearing of all */ + /* glyphs within the font. */ + /* */ + /* xMax_Extent :: The maximum horizontal extent (i.e., the */ + /* `width' of a glyph's bounding box) for */ + /* all glyphs in the font. */ + /* */ + /* caret_Slope_Rise :: The rise coefficient of the cursor's */ + /* slope of the cursor (slope=rise/run). */ + /* */ + /* caret_Slope_Run :: The run coefficient of the cursor's */ + /* slope. */ + /* */ + /* Reserved :: 8~reserved bytes. */ + /* */ + /* metric_Data_Format :: Always~0. */ + /* */ + /* number_Of_HMetrics :: Number of HMetrics entries in the `hmtx' */ + /* table -- this value can be smaller than */ + /* the total number of glyphs in the font. */ + /* */ + /* long_metrics :: A pointer into the `hmtx' table. */ + /* */ + /* short_metrics :: A pointer into the `hmtx' table. */ + /* */ + /* <Note> */ + /* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */ + /* be identical except for the names of their fields, */ + /* which are different. */ + /* */ + /* This ensures that a single function in the `ttload' */ + /* module is able to read both the horizontal and vertical */ + /* headers. */ + /* */ + typedef struct TT_HoriHeader_ + { + FT_Fixed Version; + FT_Short Ascender; + FT_Short Descender; + FT_Short Line_Gap; + + FT_UShort advance_Width_Max; /* advance width maximum */ + + FT_Short min_Left_Side_Bearing; /* minimum left-sb */ + FT_Short min_Right_Side_Bearing; /* minimum right-sb */ + FT_Short xMax_Extent; /* xmax extents */ + FT_Short caret_Slope_Rise; + FT_Short caret_Slope_Run; + FT_Short caret_Offset; + + FT_Short Reserved[4]; + + FT_Short metric_Data_Format; + FT_UShort number_Of_HMetrics; + + /* The following fields are not defined by the TrueType specification */ + /* but they are used to connect the metrics header to the relevant */ + /* `HMTX' table. */ + + void* long_metrics; + void* short_metrics; + + } TT_HoriHeader; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_VertHeader */ + /* */ + /* <Description> */ + /* A structure used to model a TrueType vertical header, the `vhea' */ + /* table, as well as the corresponding vertical metrics table, i.e., */ + /* the `vmtx' table. */ + /* */ + /* <Fields> */ + /* Version :: The table version. */ + /* */ + /* Ascender :: The font's ascender, i.e., the distance */ + /* from the baseline to the top-most of */ + /* all glyph points found in the font. */ + /* */ + /* This value is invalid in many fonts, as */ + /* it is usually set by the font designer, */ + /* and often reflects only a portion of */ + /* the glyphs found in the font (maybe */ + /* ASCII). */ + /* */ + /* You should use the `sTypoAscender' */ + /* field of the OS/2 table instead if you */ + /* want the correct one. */ + /* */ + /* Descender :: The font's descender, i.e., the */ + /* distance from the baseline to the */ + /* bottom-most of all glyph points found */ + /* in the font. It is negative. */ + /* */ + /* This value is invalid in many fonts, as */ + /* it is usually set by the font designer, */ + /* and often reflects only a portion of */ + /* the glyphs found in the font (maybe */ + /* ASCII). */ + /* */ + /* You should use the `sTypoDescender' */ + /* field of the OS/2 table instead if you */ + /* want the correct one. */ + /* */ + /* Line_Gap :: The font's line gap, i.e., the distance */ + /* to add to the ascender and descender to */ + /* get the BTB, i.e., the */ + /* baseline-to-baseline distance for the */ + /* font. */ + /* */ + /* advance_Height_Max :: This field is the maximum of all */ + /* advance heights found in the font. It */ + /* can be used to compute the maximum */ + /* height of an arbitrary string of text. */ + /* */ + /* min_Top_Side_Bearing :: The minimum top side bearing of all */ + /* glyphs within the font. */ + /* */ + /* min_Bottom_Side_Bearing :: The minimum bottom side bearing of all */ + /* glyphs within the font. */ + /* */ + /* yMax_Extent :: The maximum vertical extent (i.e., the */ + /* `height' of a glyph's bounding box) for */ + /* all glyphs in the font. */ + /* */ + /* caret_Slope_Rise :: The rise coefficient of the cursor's */ + /* slope of the cursor (slope=rise/run). */ + /* */ + /* caret_Slope_Run :: The run coefficient of the cursor's */ + /* slope. */ + /* */ + /* caret_Offset :: The cursor's offset for slanted fonts. */ + /* This value is `reserved' in vmtx */ + /* version 1.0. */ + /* */ + /* Reserved :: 8~reserved bytes. */ + /* */ + /* metric_Data_Format :: Always~0. */ + /* */ + /* number_Of_HMetrics :: Number of VMetrics entries in the */ + /* `vmtx' table -- this value can be */ + /* smaller than the total number of glyphs */ + /* in the font. */ + /* */ + /* long_metrics :: A pointer into the `vmtx' table. */ + /* */ + /* short_metrics :: A pointer into the `vmtx' table. */ + /* */ + /* <Note> */ + /* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */ + /* be identical except for the names of their fields, */ + /* which are different. */ + /* */ + /* This ensures that a single function in the `ttload' */ + /* module is able to read both the horizontal and vertical */ + /* headers. */ + /* */ + typedef struct TT_VertHeader_ + { + FT_Fixed Version; + FT_Short Ascender; + FT_Short Descender; + FT_Short Line_Gap; + + FT_UShort advance_Height_Max; /* advance height maximum */ + + FT_Short min_Top_Side_Bearing; /* minimum left-sb or top-sb */ + FT_Short min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb */ + FT_Short yMax_Extent; /* xmax or ymax extents */ + FT_Short caret_Slope_Rise; + FT_Short caret_Slope_Run; + FT_Short caret_Offset; + + FT_Short Reserved[4]; + + FT_Short metric_Data_Format; + FT_UShort number_Of_VMetrics; + + /* The following fields are not defined by the TrueType specification */ + /* but they're used to connect the metrics header to the relevant */ + /* `HMTX' or `VMTX' table. */ + + void* long_metrics; + void* short_metrics; + + } TT_VertHeader; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_OS2 */ + /* */ + /* <Description> */ + /* A structure used to model a TrueType OS/2 table. All fields */ + /* comply to the OpenType specification. */ + /* */ + /* Note that we now support old Mac fonts that do not include an OS/2 */ + /* table. In this case, the `version' field is always set to 0xFFFF. */ + /* */ + typedef struct TT_OS2_ + { + FT_UShort version; /* 0x0001 - more or 0xFFFF */ + FT_Short xAvgCharWidth; + FT_UShort usWeightClass; + FT_UShort usWidthClass; + FT_UShort fsType; + FT_Short ySubscriptXSize; + FT_Short ySubscriptYSize; + FT_Short ySubscriptXOffset; + FT_Short ySubscriptYOffset; + FT_Short ySuperscriptXSize; + FT_Short ySuperscriptYSize; + FT_Short ySuperscriptXOffset; + FT_Short ySuperscriptYOffset; + FT_Short yStrikeoutSize; + FT_Short yStrikeoutPosition; + FT_Short sFamilyClass; + + FT_Byte panose[10]; + + FT_ULong ulUnicodeRange1; /* Bits 0-31 */ + FT_ULong ulUnicodeRange2; /* Bits 32-63 */ + FT_ULong ulUnicodeRange3; /* Bits 64-95 */ + FT_ULong ulUnicodeRange4; /* Bits 96-127 */ + + FT_Char achVendID[4]; + + FT_UShort fsSelection; + FT_UShort usFirstCharIndex; + FT_UShort usLastCharIndex; + FT_Short sTypoAscender; + FT_Short sTypoDescender; + FT_Short sTypoLineGap; + FT_UShort usWinAscent; + FT_UShort usWinDescent; + + /* only version 1 and higher: */ + + FT_ULong ulCodePageRange1; /* Bits 0-31 */ + FT_ULong ulCodePageRange2; /* Bits 32-63 */ + + /* only version 2 and higher: */ + + FT_Short sxHeight; + FT_Short sCapHeight; + FT_UShort usDefaultChar; + FT_UShort usBreakChar; + FT_UShort usMaxContext; + + /* only version 5 and higher: */ + + FT_UShort usLowerOpticalPointSize; /* in twips (1/20th points) */ + FT_UShort usUpperOpticalPointSize; /* in twips (1/20th points) */ + + } TT_OS2; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_Postscript */ + /* */ + /* <Description> */ + /* A structure used to model a TrueType PostScript table. All fields */ + /* comply to the TrueType specification. This structure does not */ + /* reference the PostScript glyph names, which can be nevertheless */ + /* accessed with the `ttpost' module. */ + /* */ + typedef struct TT_Postscript_ + { + FT_Fixed FormatType; + FT_Fixed italicAngle; + FT_Short underlinePosition; + FT_Short underlineThickness; + FT_ULong isFixedPitch; + FT_ULong minMemType42; + FT_ULong maxMemType42; + FT_ULong minMemType1; + FT_ULong maxMemType1; + + /* Glyph names follow in the file, but we don't */ + /* load them by default. See the ttpost.c file. */ + + } TT_Postscript; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_PCLT */ + /* */ + /* <Description> */ + /* A structure used to model a TrueType PCLT table. All fields */ + /* comply to the TrueType specification. */ + /* */ + typedef struct TT_PCLT_ + { + FT_Fixed Version; + FT_ULong FontNumber; + FT_UShort Pitch; + FT_UShort xHeight; + FT_UShort Style; + FT_UShort TypeFamily; + FT_UShort CapHeight; + FT_UShort SymbolSet; + FT_Char TypeFace[16]; + FT_Char CharacterComplement[8]; + FT_Char FileName[6]; + FT_Char StrokeWeight; + FT_Char WidthType; + FT_Byte SerifStyle; + FT_Byte Reserved; + + } TT_PCLT; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_MaxProfile */ + /* */ + /* <Description> */ + /* The maximum profile is a table containing many max values, which */ + /* can be used to pre-allocate arrays. This ensures that no memory */ + /* allocation occurs during a glyph load. */ + /* */ + /* <Fields> */ + /* version :: The version number. */ + /* */ + /* numGlyphs :: The number of glyphs in this TrueType */ + /* font. */ + /* */ + /* maxPoints :: The maximum number of points in a */ + /* non-composite TrueType glyph. See also */ + /* the structure element */ + /* `maxCompositePoints'. */ + /* */ + /* maxContours :: The maximum number of contours in a */ + /* non-composite TrueType glyph. See also */ + /* the structure element */ + /* `maxCompositeContours'. */ + /* */ + /* maxCompositePoints :: The maximum number of points in a */ + /* composite TrueType glyph. See also the */ + /* structure element `maxPoints'. */ + /* */ + /* maxCompositeContours :: The maximum number of contours in a */ + /* composite TrueType glyph. See also the */ + /* structure element `maxContours'. */ + /* */ + /* maxZones :: The maximum number of zones used for */ + /* glyph hinting. */ + /* */ + /* maxTwilightPoints :: The maximum number of points in the */ + /* twilight zone used for glyph hinting. */ + /* */ + /* maxStorage :: The maximum number of elements in the */ + /* storage area used for glyph hinting. */ + /* */ + /* maxFunctionDefs :: The maximum number of function */ + /* definitions in the TrueType bytecode for */ + /* this font. */ + /* */ + /* maxInstructionDefs :: The maximum number of instruction */ + /* definitions in the TrueType bytecode for */ + /* this font. */ + /* */ + /* maxStackElements :: The maximum number of stack elements used */ + /* during bytecode interpretation. */ + /* */ + /* maxSizeOfInstructions :: The maximum number of TrueType opcodes */ + /* used for glyph hinting. */ + /* */ + /* maxComponentElements :: The maximum number of simple (i.e., non- */ + /* composite) glyphs in a composite glyph. */ + /* */ + /* maxComponentDepth :: The maximum nesting depth of composite */ + /* glyphs. */ + /* */ + /* <Note> */ + /* This structure is only used during font loading. */ + /* */ + typedef struct TT_MaxProfile_ + { + FT_Fixed version; + FT_UShort numGlyphs; + FT_UShort maxPoints; + FT_UShort maxContours; + FT_UShort maxCompositePoints; + FT_UShort maxCompositeContours; + FT_UShort maxZones; + FT_UShort maxTwilightPoints; + FT_UShort maxStorage; + FT_UShort maxFunctionDefs; + FT_UShort maxInstructionDefs; + FT_UShort maxStackElements; + FT_UShort maxSizeOfInstructions; + FT_UShort maxComponentElements; + FT_UShort maxComponentDepth; + + } TT_MaxProfile; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Sfnt_Tag */ + /* */ + /* <Description> */ + /* An enumeration used to specify the index of an SFNT table. */ + /* Used in the @FT_Get_Sfnt_Table API function. */ + /* */ + /* <Values> */ + /* FT_SFNT_HEAD :: To access the font's @TT_Header structure. */ + /* */ + /* FT_SFNT_MAXP :: To access the font's @TT_MaxProfile structure. */ + /* */ + /* FT_SFNT_OS2 :: To access the font's @TT_OS2 structure. */ + /* */ + /* FT_SFNT_HHEA :: To access the font's @TT_HoriHeader structure. */ + /* */ + /* FT_SFNT_VHEA :: To access the font's @TT_VertHeader struture. */ + /* */ + /* FT_SFNT_POST :: To access the font's @TT_Postscript structure. */ + /* */ + /* FT_SFNT_PCLT :: To access the font's @TT_PCLT structure. */ + /* */ + typedef enum FT_Sfnt_Tag_ + { + FT_SFNT_HEAD, + FT_SFNT_MAXP, + FT_SFNT_OS2, + FT_SFNT_HHEA, + FT_SFNT_VHEA, + FT_SFNT_POST, + FT_SFNT_PCLT, + + FT_SFNT_MAX + + } FT_Sfnt_Tag; + + /* these constants are deprecated; use the corresponding `FT_Sfnt_Tag' */ + /* values instead */ +#define ft_sfnt_head FT_SFNT_HEAD +#define ft_sfnt_maxp FT_SFNT_MAXP +#define ft_sfnt_os2 FT_SFNT_OS2 +#define ft_sfnt_hhea FT_SFNT_HHEA +#define ft_sfnt_vhea FT_SFNT_VHEA +#define ft_sfnt_post FT_SFNT_POST +#define ft_sfnt_pclt FT_SFNT_PCLT + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Sfnt_Table */ + /* */ + /* <Description> */ + /* Return a pointer to a given SFNT table within a face. */ + /* */ + /* <Input> */ + /* face :: A handle to the source. */ + /* */ + /* tag :: The index of the SFNT table. */ + /* */ + /* <Return> */ + /* A type-less pointer to the table. This will be~0 in case of */ + /* error, or if the corresponding table was not found *OR* loaded */ + /* from the file. */ + /* */ + /* Use a typecast according to `tag' to access the structure */ + /* elements. */ + /* */ + /* <Note> */ + /* The table is owned by the face object and disappears with it. */ + /* */ + /* This function is only useful to access SFNT tables that are loaded */ + /* by the sfnt, truetype, and opentype drivers. See @FT_Sfnt_Tag for */ + /* a list. */ + /* */ + /* Here an example how to access the `vhea' table: */ + /* */ + /* { */ + /* TT_VertHeader* vert_header; */ + /* */ + /* */ + /* vert_header = */ + /* (TT_VertHeader*)FT_Get_Sfnt_Table( face, FT_SFNT_VHEA ); */ + /* } */ + /* */ + FT_EXPORT( void* ) + FT_Get_Sfnt_Table( FT_Face face, + FT_Sfnt_Tag tag ); + + + /************************************************************************** + * + * @function: + * FT_Load_Sfnt_Table + * + * @description: + * Load any font table into client memory. + * + * @input: + * face :: + * A handle to the source face. + * + * tag :: + * The four-byte tag of the table to load. Use the value~0 if you want + * to access the whole font file. Otherwise, you can use one of the + * definitions found in the @FT_TRUETYPE_TAGS_H file, or forge a new + * one with @FT_MAKE_TAG. + * + * offset :: + * The starting offset in the table (or file if tag == 0). + * + * @output: + * buffer :: + * The target buffer address. The client must ensure that the memory + * array is big enough to hold the data. + * + * @inout: + * length :: + * If the `length' parameter is NULL, then try to load the whole table. + * Return an error code if it fails. + * + * Else, if `*length' is~0, exit immediately while returning the + * table's (or file) full size in it. + * + * Else the number of bytes to read from the table or file, from the + * starting offset. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If you need to determine the table's length you should first call this + * function with `*length' set to~0, as in the following example: + * + * { + * FT_ULong length = 0; + * + * + * error = FT_Load_Sfnt_Table( face, tag, 0, NULL, &length ); + * if ( error ) { ... table does not exist ... } + * + * buffer = malloc( length ); + * if ( buffer == NULL ) { ... not enough memory ... } + * + * error = FT_Load_Sfnt_Table( face, tag, 0, buffer, &length ); + * if ( error ) { ... could not load table ... } + * } + * + * Note that structures like @TT_Header or @TT_OS2 can't be used with + * this function; they are limited to @FT_Get_Sfnt_Table. Reason is that + * those structures depend on the processor architecture, with varying + * size (e.g. 32bit vs. 64bit) or order (big endian vs. little endian). + * + */ + FT_EXPORT( FT_Error ) + FT_Load_Sfnt_Table( FT_Face face, + FT_ULong tag, + FT_Long offset, + FT_Byte* buffer, + FT_ULong* length ); + + + /************************************************************************** + * + * @function: + * FT_Sfnt_Table_Info + * + * @description: + * Return information on an SFNT table. + * + * @input: + * face :: + * A handle to the source face. + * + * table_index :: + * The index of an SFNT table. The function returns + * FT_Err_Table_Missing for an invalid value. + * + * @inout: + * tag :: + * The name tag of the SFNT table. If the value is NULL, `table_index' + * is ignored, and `length' returns the number of SFNT tables in the + * font. + * + * @output: + * length :: + * The length of the SFNT table (or the number of SFNT tables, depending + * on `tag'). + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * While parsing fonts, FreeType handles SFNT tables with length zero as + * missing. + * + */ + FT_EXPORT( FT_Error ) + FT_Sfnt_Table_Info( FT_Face face, + FT_UInt table_index, + FT_ULong *tag, + FT_ULong *length ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_CMap_Language_ID */ + /* */ + /* <Description> */ + /* Return TrueType/sfnt specific cmap language ID. Definitions of */ + /* language ID values are in `ttnameid.h'. */ + /* */ + /* <Input> */ + /* charmap :: */ + /* The target charmap. */ + /* */ + /* <Return> */ + /* The language ID of `charmap'. If `charmap' doesn't belong to a */ + /* TrueType/sfnt face, just return~0 as the default value. */ + /* */ + /* For a format~14 cmap (to access Unicode IVS), the return value is */ + /* 0xFFFFFFFF. */ + /* */ + FT_EXPORT( FT_ULong ) + FT_Get_CMap_Language_ID( FT_CharMap charmap ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_CMap_Format */ + /* */ + /* <Description> */ + /* Return TrueType/sfnt specific cmap format. */ + /* */ + /* <Input> */ + /* charmap :: */ + /* The target charmap. */ + /* */ + /* <Return> */ + /* The format of `charmap'. If `charmap' doesn't belong to a */ + /* TrueType/sfnt face, return -1. */ + /* */ + FT_EXPORT( FT_Long ) + FT_Get_CMap_Format( FT_CharMap charmap ); + + /* */ + + +FT_END_HEADER + +#endif /* TTTABLES_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/tttags.h b/android/x86/include/freetype/tttags.h new file mode 100644 index 00000000..f3c9aa5f --- /dev/null +++ b/android/x86/include/freetype/tttags.h @@ -0,0 +1,111 @@ +/***************************************************************************/ +/* */ +/* tttags.h */ +/* */ +/* Tags for TrueType and OpenType tables (specification only). */ +/* */ +/* Copyright 1996-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTAGS_H_ +#define TTAGS_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + +#define TTAG_avar FT_MAKE_TAG( 'a', 'v', 'a', 'r' ) +#define TTAG_BASE FT_MAKE_TAG( 'B', 'A', 'S', 'E' ) +#define TTAG_bdat FT_MAKE_TAG( 'b', 'd', 'a', 't' ) +#define TTAG_BDF FT_MAKE_TAG( 'B', 'D', 'F', ' ' ) +#define TTAG_bhed FT_MAKE_TAG( 'b', 'h', 'e', 'd' ) +#define TTAG_bloc FT_MAKE_TAG( 'b', 'l', 'o', 'c' ) +#define TTAG_bsln FT_MAKE_TAG( 'b', 's', 'l', 'n' ) +#define TTAG_CBDT FT_MAKE_TAG( 'C', 'B', 'D', 'T' ) +#define TTAG_CBLC FT_MAKE_TAG( 'C', 'B', 'L', 'C' ) +#define TTAG_CFF FT_MAKE_TAG( 'C', 'F', 'F', ' ' ) +#define TTAG_CID FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) +#define TTAG_cmap FT_MAKE_TAG( 'c', 'm', 'a', 'p' ) +#define TTAG_cvar FT_MAKE_TAG( 'c', 'v', 'a', 'r' ) +#define TTAG_cvt FT_MAKE_TAG( 'c', 'v', 't', ' ' ) +#define TTAG_DSIG FT_MAKE_TAG( 'D', 'S', 'I', 'G' ) +#define TTAG_EBDT FT_MAKE_TAG( 'E', 'B', 'D', 'T' ) +#define TTAG_EBLC FT_MAKE_TAG( 'E', 'B', 'L', 'C' ) +#define TTAG_EBSC FT_MAKE_TAG( 'E', 'B', 'S', 'C' ) +#define TTAG_feat FT_MAKE_TAG( 'f', 'e', 'a', 't' ) +#define TTAG_FOND FT_MAKE_TAG( 'F', 'O', 'N', 'D' ) +#define TTAG_fpgm FT_MAKE_TAG( 'f', 'p', 'g', 'm' ) +#define TTAG_fvar FT_MAKE_TAG( 'f', 'v', 'a', 'r' ) +#define TTAG_gasp FT_MAKE_TAG( 'g', 'a', 's', 'p' ) +#define TTAG_GDEF FT_MAKE_TAG( 'G', 'D', 'E', 'F' ) +#define TTAG_glyf FT_MAKE_TAG( 'g', 'l', 'y', 'f' ) +#define TTAG_GPOS FT_MAKE_TAG( 'G', 'P', 'O', 'S' ) +#define TTAG_GSUB FT_MAKE_TAG( 'G', 'S', 'U', 'B' ) +#define TTAG_gvar FT_MAKE_TAG( 'g', 'v', 'a', 'r' ) +#define TTAG_hdmx FT_MAKE_TAG( 'h', 'd', 'm', 'x' ) +#define TTAG_head FT_MAKE_TAG( 'h', 'e', 'a', 'd' ) +#define TTAG_hhea FT_MAKE_TAG( 'h', 'h', 'e', 'a' ) +#define TTAG_hmtx FT_MAKE_TAG( 'h', 'm', 't', 'x' ) +#define TTAG_JSTF FT_MAKE_TAG( 'J', 'S', 'T', 'F' ) +#define TTAG_just FT_MAKE_TAG( 'j', 'u', 's', 't' ) +#define TTAG_kern FT_MAKE_TAG( 'k', 'e', 'r', 'n' ) +#define TTAG_lcar FT_MAKE_TAG( 'l', 'c', 'a', 'r' ) +#define TTAG_loca FT_MAKE_TAG( 'l', 'o', 'c', 'a' ) +#define TTAG_LTSH FT_MAKE_TAG( 'L', 'T', 'S', 'H' ) +#define TTAG_LWFN FT_MAKE_TAG( 'L', 'W', 'F', 'N' ) +#define TTAG_MATH FT_MAKE_TAG( 'M', 'A', 'T', 'H' ) +#define TTAG_maxp FT_MAKE_TAG( 'm', 'a', 'x', 'p' ) +#define TTAG_META FT_MAKE_TAG( 'M', 'E', 'T', 'A' ) +#define TTAG_MMFX FT_MAKE_TAG( 'M', 'M', 'F', 'X' ) +#define TTAG_MMSD FT_MAKE_TAG( 'M', 'M', 'S', 'D' ) +#define TTAG_mort FT_MAKE_TAG( 'm', 'o', 'r', 't' ) +#define TTAG_morx FT_MAKE_TAG( 'm', 'o', 'r', 'x' ) +#define TTAG_name FT_MAKE_TAG( 'n', 'a', 'm', 'e' ) +#define TTAG_opbd FT_MAKE_TAG( 'o', 'p', 'b', 'd' ) +#define TTAG_OS2 FT_MAKE_TAG( 'O', 'S', '/', '2' ) +#define TTAG_OTTO FT_MAKE_TAG( 'O', 'T', 'T', 'O' ) +#define TTAG_PCLT FT_MAKE_TAG( 'P', 'C', 'L', 'T' ) +#define TTAG_POST FT_MAKE_TAG( 'P', 'O', 'S', 'T' ) +#define TTAG_post FT_MAKE_TAG( 'p', 'o', 's', 't' ) +#define TTAG_prep FT_MAKE_TAG( 'p', 'r', 'e', 'p' ) +#define TTAG_prop FT_MAKE_TAG( 'p', 'r', 'o', 'p' ) +#define TTAG_sbix FT_MAKE_TAG( 's', 'b', 'i', 'x' ) +#define TTAG_sfnt FT_MAKE_TAG( 's', 'f', 'n', 't' ) +#define TTAG_SING FT_MAKE_TAG( 'S', 'I', 'N', 'G' ) +#define TTAG_trak FT_MAKE_TAG( 't', 'r', 'a', 'k' ) +#define TTAG_true FT_MAKE_TAG( 't', 'r', 'u', 'e' ) +#define TTAG_ttc FT_MAKE_TAG( 't', 't', 'c', ' ' ) +#define TTAG_ttcf FT_MAKE_TAG( 't', 't', 'c', 'f' ) +#define TTAG_TYP1 FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) +#define TTAG_typ1 FT_MAKE_TAG( 't', 'y', 'p', '1' ) +#define TTAG_VDMX FT_MAKE_TAG( 'V', 'D', 'M', 'X' ) +#define TTAG_vhea FT_MAKE_TAG( 'v', 'h', 'e', 'a' ) +#define TTAG_vmtx FT_MAKE_TAG( 'v', 'm', 't', 'x' ) +#define TTAG_wOFF FT_MAKE_TAG( 'w', 'O', 'F', 'F' ) + + +FT_END_HEADER + +#endif /* TTAGS_H_ */ + + +/* END */ diff --git a/android/x86/include/freetype/ttunpat.h b/android/x86/include/freetype/ttunpat.h new file mode 100644 index 00000000..ca4676ba --- /dev/null +++ b/android/x86/include/freetype/ttunpat.h @@ -0,0 +1,63 @@ +/***************************************************************************/ +/* */ +/* ttunpat.h */ +/* */ +/* Definitions for the unpatented TrueType hinting system. */ +/* Obsolete, retained for backwards compatibility. */ +/* */ +/* Copyright 2003-2016 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* Written by Graham Asher <graham.asher@btinternet.com> */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTUNPAT_H_ +#define TTUNPAT_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************** + * + * @constant: + * FT_PARAM_TAG_UNPATENTED_HINTING + * + * @description: + * Deprecated. + * + * Previously: A constant used as the tag of an @FT_Parameter structure to + * indicate that unpatented methods only should be used by the TrueType + * bytecode interpreter for a typeface opened by @FT_Open_Face. + * + */ +#define FT_PARAM_TAG_UNPATENTED_HINTING FT_MAKE_TAG( 'u', 'n', 'p', 'a' ) + + /* */ + + +FT_END_HEADER + + +#endif /* TTUNPAT_H_ */ + + +/* END */ diff --git a/android/x86/include/jpeg/jconfig.h b/android/x86/include/jpeg/jconfig.h new file mode 100644 index 00000000..966b1d51 --- /dev/null +++ b/android/x86/include/jpeg/jconfig.h @@ -0,0 +1,54 @@ +/* jconfig.h. Generated from jconfig.cfg by configure. */ +/* jconfig.cfg --- source file edited by configure script */ +/* see jconfig.txt for explanations */ + +#define HAVE_PROTOTYPES 1 +#define HAVE_UNSIGNED_CHAR 1 +#define HAVE_UNSIGNED_SHORT 1 +/* #undef void */ +/* #undef const */ +/* #undef CHAR_IS_UNSIGNED */ +#define HAVE_STDDEF_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_LOCALE_H 1 +/* #undef NEED_BSD_STRINGS */ +/* #undef NEED_SYS_TYPES_H */ +/* #undef NEED_FAR_POINTERS */ +/* #undef NEED_SHORT_EXTERNAL_NAMES */ +/* Define this if you get warnings about undefined structures. */ +/* #undef INCOMPLETE_TYPES_BROKEN */ + +/* Define "boolean" as unsigned char, not int, on Windows systems. */ +#ifdef _WIN32 +#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ +typedef unsigned char boolean; +#endif +#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ +#endif + +#ifdef JPEG_INTERNALS + +/* #undef RIGHT_SHIFT_IS_UNSIGNED */ +#define INLINE __inline__ +/* These are for configuring the JPEG memory manager. */ +/* #undef DEFAULT_MAX_MEM */ +/* #undef NO_MKTEMP */ + +#endif /* JPEG_INTERNALS */ + +#ifdef JPEG_CJPEG_DJPEG + +#define BMP_SUPPORTED /* BMP image file format */ +#define GIF_SUPPORTED /* GIF image file format */ +#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ +/* #undef RLE_SUPPORTED */ +#define TARGA_SUPPORTED /* Targa image file format */ + +/* #undef TWO_FILE_COMMANDLINE */ +/* #undef NEED_SIGNAL_CATCHER */ +/* #undef DONT_USE_B_MODE */ + +/* Define this if you want percent-done progress reports from cjpeg/djpeg. */ +/* #undef PROGRESS_REPORT */ + +#endif /* JPEG_CJPEG_DJPEG */ diff --git a/android/x86/include/jpeg/jerror.h b/android/x86/include/jpeg/jerror.h new file mode 100644 index 00000000..a4b661f7 --- /dev/null +++ b/android/x86/include/jpeg/jerror.h @@ -0,0 +1,304 @@ +/* + * jerror.h + * + * Copyright (C) 1994-1997, Thomas G. Lane. + * Modified 1997-2012 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file defines the error and message codes for the JPEG library. + * Edit this file to add new codes, or to translate the message strings to + * some other language. + * A set of error-reporting macros are defined too. Some applications using + * the JPEG library may wish to include this file to get the error codes + * and/or the macros. + */ + +/* + * To define the enum list of message codes, include this file without + * defining macro JMESSAGE. To create a message string table, include it + * again with a suitable JMESSAGE definition (see jerror.c for an example). + */ +#ifndef JMESSAGE +#ifndef JERROR_H +/* First time through, define the enum list */ +#define JMAKE_ENUM_LIST +#else +/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ +#define JMESSAGE(code,string) +#endif /* JERROR_H */ +#endif /* JMESSAGE */ + +#ifdef JMAKE_ENUM_LIST + +typedef enum { + +#define JMESSAGE(code,string) code , + +#endif /* JMAKE_ENUM_LIST */ + +JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */ + +/* For maintenance convenience, list is alphabetical by message code name */ +JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") +JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix") +JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode") +JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS") +JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request") +JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range") +JMESSAGE(JERR_BAD_DCTSIZE, "DCT scaled block size %dx%d not supported") +JMESSAGE(JERR_BAD_DROP_SAMPLING, + "Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c") +JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition") +JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace") +JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace") +JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length") +JMESSAGE(JERR_BAD_LIB_VERSION, + "Wrong JPEG library version: library is %d, caller expects %d") +JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan") +JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d") +JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d") +JMESSAGE(JERR_BAD_PROGRESSION, + "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d") +JMESSAGE(JERR_BAD_PROG_SCRIPT, + "Invalid progressive parameters at scan script entry %d") +JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors") +JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d") +JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d") +JMESSAGE(JERR_BAD_STRUCT_SIZE, + "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u") +JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access") +JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small") +JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here") +JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet") +JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d") +JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request") +JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d") +JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x") +JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d") +JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d") +JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)") +JMESSAGE(JERR_EMS_READ, "Read from EMS failed") +JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed") +JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan") +JMESSAGE(JERR_FILE_READ, "Input file read error") +JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?") +JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet") +JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow") +JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry") +JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels") +JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") +JMESSAGE(JERR_INPUT_EOF, "Premature end of input file") +JMESSAGE(JERR_MISMATCHED_QUANT_TABLE, + "Cannot transcode due to multiple use of quantization table %d") +JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data") +JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change") +JMESSAGE(JERR_NOTIMPL, "Not implemented yet") +JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time") +JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined") +JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported") +JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined") +JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image") +JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined") +JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x") +JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)") +JMESSAGE(JERR_QUANT_COMPONENTS, + "Cannot quantize more than %d color components") +JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") +JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") +JMESSAGE(JERR_SOF_BEFORE, "Invalid JPEG file structure: %s before SOF") +JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") +JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker") +JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x") +JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers") +JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s") +JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") +JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") +JMESSAGE(JERR_TFILE_WRITE, + "Write failed on temporary file --- out of disk space?") +JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines") +JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x") +JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up") +JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation") +JMESSAGE(JERR_XMS_READ, "Read from XMS failed") +JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed") +JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT) +JMESSAGE(JMSG_VERSION, JVERSION) +JMESSAGE(JTRC_16BIT_TABLES, + "Caution: quantization tables are too coarse for baseline JPEG") +JMESSAGE(JTRC_ADOBE, + "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d") +JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u") +JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u") +JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x") +JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x") +JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d") +JMESSAGE(JTRC_DRI, "Define Restart Interval %u") +JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u") +JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u") +JMESSAGE(JTRC_EOI, "End Of Image") +JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d") +JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d") +JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE, + "Warning: thumbnail image size does not match data length %u") +JMESSAGE(JTRC_JFIF_EXTENSION, + "JFIF extension marker: type 0x%02x, length %u") +JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image") +JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u") +JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x") +JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u") +JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors") +JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors") +JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization") +JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d") +JMESSAGE(JTRC_RST, "RST%d") +JMESSAGE(JTRC_SMOOTH_NOTIMPL, + "Smoothing not supported with nonstandard sampling ratios") +JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d") +JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d") +JMESSAGE(JTRC_SOI, "Start of Image") +JMESSAGE(JTRC_SOS, "Start Of Scan: %d components") +JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d") +JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d") +JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s") +JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s") +JMESSAGE(JTRC_THUMB_JPEG, + "JFIF extension marker: JPEG-compressed thumbnail image, length %u") +JMESSAGE(JTRC_THUMB_PALETTE, + "JFIF extension marker: palette thumbnail image, length %u") +JMESSAGE(JTRC_THUMB_RGB, + "JFIF extension marker: RGB thumbnail image, length %u") +JMESSAGE(JTRC_UNKNOWN_IDS, + "Unrecognized component IDs %d %d %d, assuming YCbCr") +JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u") +JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u") +JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") +JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code") +JMESSAGE(JWRN_BOGUS_PROGRESSION, + "Inconsistent progression sequence for component %d coefficient %d") +JMESSAGE(JWRN_EXTRANEOUS_DATA, + "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x") +JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment") +JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code") +JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d") +JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file") +JMESSAGE(JWRN_MUST_RESYNC, + "Corrupt JPEG data: found marker 0x%02x instead of RST%d") +JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG") +JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines") + +#ifdef JMAKE_ENUM_LIST + + JMSG_LASTMSGCODE +} J_MESSAGE_CODE; + +#undef JMAKE_ENUM_LIST +#endif /* JMAKE_ENUM_LIST */ + +/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ +#undef JMESSAGE + + +#ifndef JERROR_H +#define JERROR_H + +/* Macros to simplify using the error and trace message stuff */ +/* The first parameter is either type of cinfo pointer */ + +/* Fatal errors (print message and exit) */ +#define ERREXIT(cinfo,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT1(cinfo,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT2(cinfo,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT3(cinfo,code,p1,p2,p3) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (cinfo)->err->msg_parm.i[2] = (p3), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT4(cinfo,code,p1,p2,p3,p4) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (cinfo)->err->msg_parm.i[2] = (p3), \ + (cinfo)->err->msg_parm.i[3] = (p4), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXIT6(cinfo,code,p1,p2,p3,p4,p5,p6) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (cinfo)->err->msg_parm.i[2] = (p3), \ + (cinfo)->err->msg_parm.i[3] = (p4), \ + (cinfo)->err->msg_parm.i[4] = (p5), \ + (cinfo)->err->msg_parm.i[5] = (p6), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) +#define ERREXITS(cinfo,code,str) \ + ((cinfo)->err->msg_code = (code), \ + strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) + +#define MAKESTMT(stuff) do { stuff } while (0) + +/* Nonfatal errors (we can keep going, but the data is probably corrupt) */ +#define WARNMS(cinfo,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) +#define WARNMS1(cinfo,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) +#define WARNMS2(cinfo,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) + +/* Informational/debugging messages */ +#define TRACEMS(cinfo,lvl,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) +#define TRACEMS1(cinfo,lvl,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) +#define TRACEMS2(cinfo,lvl,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) +#define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + _mp[4] = (p5); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) +#define TRACEMSS(cinfo,lvl,code,str) \ + ((cinfo)->err->msg_code = (code), \ + strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) + +#endif /* JERROR_H */ diff --git a/android/x86/include/jpeg/jmorecfg.h b/android/x86/include/jpeg/jmorecfg.h new file mode 100644 index 00000000..2407edbe --- /dev/null +++ b/android/x86/include/jpeg/jmorecfg.h @@ -0,0 +1,390 @@ +/* + * jmorecfg.h + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Modified 1997-2012 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains additional configuration options that customize the + * JPEG software for special applications or support machine-dependent + * optimizations. Most users will not need to touch this file. + */ + + +/* + * Define BITS_IN_JSAMPLE as either + * 8 for 8-bit sample values (the usual setting) + * 12 for 12-bit sample values + * Only 8 and 12 are legal data precisions for lossy JPEG according to the + * JPEG standard, and the IJG code does not support anything else! + * We do not support run-time selection of data precision, sorry. + */ + +#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ + + +/* + * Maximum number of components (color channels) allowed in JPEG image. + * To meet the letter of the JPEG spec, set this to 255. However, darn + * few applications need more than 4 channels (maybe 5 for CMYK + alpha + * mask). We recommend 10 as a reasonable compromise; use 4 if you are + * really short on memory. (Each allowed component costs a hundred or so + * bytes of storage, whether actually used in an image or not.) + */ + +#define MAX_COMPONENTS 10 /* maximum number of image components */ + + +/* + * Basic data types. + * You may need to change these if you have a machine with unusual data + * type sizes; for example, "char" not 8 bits, "short" not 16 bits, + * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits, + * but it had better be at least 16. + */ + +/* Representation of a single sample (pixel element value). + * We frequently allocate large arrays of these, so it's important to keep + * them small. But if you have memory to burn and access to char or short + * arrays is very slow on your hardware, you might want to change these. + */ + +#if BITS_IN_JSAMPLE == 8 +/* JSAMPLE should be the smallest type that will hold the values 0..255. + * You can use a signed char by having GETJSAMPLE mask it with 0xFF. + */ + +#ifdef HAVE_UNSIGNED_CHAR + +typedef unsigned char JSAMPLE; +#define GETJSAMPLE(value) ((int) (value)) + +#else /* not HAVE_UNSIGNED_CHAR */ + +typedef char JSAMPLE; +#ifdef CHAR_IS_UNSIGNED +#define GETJSAMPLE(value) ((int) (value)) +#else +#define GETJSAMPLE(value) ((int) (value) & 0xFF) +#endif /* CHAR_IS_UNSIGNED */ + +#endif /* HAVE_UNSIGNED_CHAR */ + +#define MAXJSAMPLE 255 +#define CENTERJSAMPLE 128 + +#endif /* BITS_IN_JSAMPLE == 8 */ + + +#if BITS_IN_JSAMPLE == 12 +/* JSAMPLE should be the smallest type that will hold the values 0..4095. + * On nearly all machines "short" will do nicely. + */ + +typedef short JSAMPLE; +#define GETJSAMPLE(value) ((int) (value)) + +#define MAXJSAMPLE 4095 +#define CENTERJSAMPLE 2048 + +#endif /* BITS_IN_JSAMPLE == 12 */ + + +/* Representation of a DCT frequency coefficient. + * This should be a signed value of at least 16 bits; "short" is usually OK. + * Again, we allocate large arrays of these, but you can change to int + * if you have memory to burn and "short" is really slow. + */ + +typedef short JCOEF; + + +/* Compressed datastreams are represented as arrays of JOCTET. + * These must be EXACTLY 8 bits wide, at least once they are written to + * external storage. Note that when using the stdio data source/destination + * managers, this is also the data type passed to fread/fwrite. + */ + +#ifdef HAVE_UNSIGNED_CHAR + +typedef unsigned char JOCTET; +#define GETJOCTET(value) (value) + +#else /* not HAVE_UNSIGNED_CHAR */ + +typedef char JOCTET; +#ifdef CHAR_IS_UNSIGNED +#define GETJOCTET(value) (value) +#else +#define GETJOCTET(value) ((value) & 0xFF) +#endif /* CHAR_IS_UNSIGNED */ + +#endif /* HAVE_UNSIGNED_CHAR */ + + +/* These typedefs are used for various table entries and so forth. + * They must be at least as wide as specified; but making them too big + * won't cost a huge amount of memory, so we don't provide special + * extraction code like we did for JSAMPLE. (In other words, these + * typedefs live at a different point on the speed/space tradeoff curve.) + */ + +/* UINT8 must hold at least the values 0..255. */ + +#ifdef HAVE_UNSIGNED_CHAR +typedef unsigned char UINT8; +#else /* not HAVE_UNSIGNED_CHAR */ +#ifdef CHAR_IS_UNSIGNED +typedef char UINT8; +#else /* not CHAR_IS_UNSIGNED */ +typedef short UINT8; +#endif /* CHAR_IS_UNSIGNED */ +#endif /* HAVE_UNSIGNED_CHAR */ + +/* UINT16 must hold at least the values 0..65535. */ + +#ifdef HAVE_UNSIGNED_SHORT +typedef unsigned short UINT16; +#else /* not HAVE_UNSIGNED_SHORT */ +typedef unsigned int UINT16; +#endif /* HAVE_UNSIGNED_SHORT */ + +/* INT16 must hold at least the values -32768..32767. */ + +#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */ +typedef short INT16; +#endif + +/* INT32 must hold at least signed 32-bit values. */ + +#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */ +#ifndef _BASETSD_H_ /* Microsoft defines it in basetsd.h */ +#ifndef _BASETSD_H /* MinGW is slightly different */ +#ifndef QGLOBAL_H /* Qt defines it in qglobal.h */ +typedef long INT32; +#endif +#endif +#endif +#endif + +/* Datatype used for image dimensions. The JPEG standard only supports + * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore + * "unsigned int" is sufficient on all machines. However, if you need to + * handle larger images and you don't mind deviating from the spec, you + * can change this datatype. + */ + +typedef unsigned int JDIMENSION; + +#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */ + + +/* These macros are used in all function definitions and extern declarations. + * You could modify them if you need to change function linkage conventions; + * in particular, you'll need to do that to make the library a Windows DLL. + * Another application is to make all functions global for use with debuggers + * or code profilers that require it. + */ + +/* a function called through method pointers: */ +#define METHODDEF(type) static type +/* a function used only in its module: */ +#define LOCAL(type) static type +/* a function referenced thru EXTERNs: */ +#define GLOBAL(type) type +/* a reference to a GLOBAL function: */ +#define EXTERN(type) extern type + + +/* This macro is used to declare a "method", that is, a function pointer. + * We want to supply prototype parameters if the compiler can cope. + * Note that the arglist parameter must be parenthesized! + * Again, you can customize this if you need special linkage keywords. + */ + +#ifdef HAVE_PROTOTYPES +#define JMETHOD(type,methodname,arglist) type (*methodname) arglist +#else +#define JMETHOD(type,methodname,arglist) type (*methodname) () +#endif + + +/* The noreturn type identifier is used to declare functions + * which cannot return. + * Compilers can thus create more optimized code and perform + * better checks for warnings and errors. + * Static analyzer tools can make improved inferences about + * execution paths and are prevented from giving false alerts. + * + * Unfortunately, the proposed specifications of corresponding + * extensions in the Dec 2011 ISO C standard revision (C11), + * GCC, MSVC, etc. are not viable. + * Thus we introduce a user defined type to declare noreturn + * functions at least for clarity. A proper compiler would + * have a suitable noreturn type to match in place of void. + */ + +#ifndef HAVE_NORETURN_T +typedef void noreturn_t; +#endif + + +/* Here is the pseudo-keyword for declaring pointers that must be "far" + * on 80x86 machines. Most of the specialized coding for 80x86 is handled + * by just saying "FAR *" where such a pointer is needed. In a few places + * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol. + */ + +#ifndef FAR +#ifdef NEED_FAR_POINTERS +#define FAR far +#else +#define FAR +#endif +#endif + + +/* + * On a few systems, type boolean and/or its values FALSE, TRUE may appear + * in standard header files. Or you may have conflicts with application- + * specific header files that you want to include together with these files. + * Defining HAVE_BOOLEAN before including jpeglib.h should make it work. + */ + +#ifdef HAVE_BOOLEAN +#ifndef FALSE /* in case these macros already exist */ +#define FALSE 0 /* values of boolean */ +#endif +#ifndef TRUE +#define TRUE 1 +#endif +#else +typedef enum { FALSE = 0, TRUE = 1 } boolean; +#endif + + +/* + * The remaining options affect code selection within the JPEG library, + * but they don't need to be visible to most applications using the library. + * To minimize application namespace pollution, the symbols won't be + * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined. + */ + +#ifdef JPEG_INTERNALS +#define JPEG_INTERNAL_OPTIONS +#endif + +#ifdef JPEG_INTERNAL_OPTIONS + + +/* + * These defines indicate whether to include various optional functions. + * Undefining some of these symbols will produce a smaller but less capable + * library. Note that you can leave certain source files out of the + * compilation/linking process if you've #undef'd the corresponding symbols. + * (You may HAVE to do that if your compiler doesn't like null source files.) + */ + +/* Capability options common to encoder and decoder: */ + +#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */ +#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */ +#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */ + +/* Encoder capability options: */ + +#define C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */ +#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ +#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ +#define DCT_SCALING_SUPPORTED /* Input rescaling via DCT? (Requires DCT_ISLOW)*/ +#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ +/* Note: if you selected 12-bit data precision, it is dangerous to turn off + * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit + * precision, so jchuff.c normally uses entropy optimization to compute + * usable tables for higher precision. If you don't want to do optimization, + * you'll have to supply different default Huffman tables. + * The exact same statements apply for progressive JPEG: the default tables + * don't work for progressive mode. (This may get fixed, however.) + */ +#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */ + +/* Decoder capability options: */ + +#define D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */ +#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ +#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ +#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ +#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */ +#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ +#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ +#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */ +#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */ +#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */ + +/* more capability options later, no doubt */ + + +/* + * Ordering of RGB data in scanlines passed to or from the application. + * If your application wants to deal with data in the order B,G,R, just + * change these macros. You can also deal with formats such as R,G,B,X + * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing + * the offsets will also change the order in which colormap data is organized. + * RESTRICTIONS: + * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats. + * 2. The color quantizer modules will not behave desirably if RGB_PIXELSIZE + * is not 3 (they don't understand about dummy color components!). So you + * can't use color quantization if you change that value. + */ + +#define RGB_RED 0 /* Offset of Red in an RGB scanline element */ +#define RGB_GREEN 1 /* Offset of Green */ +#define RGB_BLUE 2 /* Offset of Blue */ +#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */ + + +/* Definitions for speed-related optimizations. */ + + +/* If your compiler supports inline functions, define INLINE + * as the inline keyword; otherwise define it as empty. + */ + +#ifndef INLINE +#ifdef __GNUC__ /* for instance, GNU C knows about inline */ +#define INLINE __inline__ +#endif +#ifndef INLINE +#define INLINE /* default is to define it as empty */ +#endif +#endif + + +/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying + * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER + * as short on such a machine. MULTIPLIER must be at least 16 bits wide. + */ + +#ifndef MULTIPLIER +#define MULTIPLIER int /* type for fastest integer multiply */ +#endif + + +/* FAST_FLOAT should be either float or double, whichever is done faster + * by your compiler. (Note that this type is only used in the floating point + * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.) + * Typically, float is faster in ANSI C compilers, while double is faster in + * pre-ANSI compilers (because they insist on converting to double anyway). + * The code below therefore chooses float if we have ANSI-style prototypes. + */ + +#ifndef FAST_FLOAT +#ifdef HAVE_PROTOTYPES +#define FAST_FLOAT float +#else +#define FAST_FLOAT double +#endif +#endif + +#endif /* JPEG_INTERNAL_OPTIONS */ diff --git a/android/x86/include/jpeg/jpeglib.h b/android/x86/include/jpeg/jpeglib.h new file mode 100644 index 00000000..0a6dac44 --- /dev/null +++ b/android/x86/include/jpeg/jpeglib.h @@ -0,0 +1,1173 @@ +/* + * jpeglib.h + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * Modified 2002-2012 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file defines the application interface for the JPEG library. + * Most applications using the library need only include this file, + * and perhaps jerror.h if they want to know the exact error codes. + */ + +#ifndef JPEGLIB_H +#define JPEGLIB_H + +/* + * First we include the configuration files that record how this + * installation of the JPEG library is set up. jconfig.h can be + * generated automatically for many systems. jmorecfg.h contains + * manual configuration options that most people need not worry about. + */ + +#ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */ +#include "jconfig.h" /* widely used configuration options */ +#endif +#include "jmorecfg.h" /* seldom changed options */ + + +#ifdef __cplusplus +#ifndef DONT_USE_EXTERN_C +extern "C" { +#endif +#endif + +/* Version IDs for the JPEG library. + * Might be useful for tests like "#if JPEG_LIB_VERSION >= 90". + */ + +#define JPEG_LIB_VERSION 90 /* Compatibility version 9.0 */ +#define JPEG_LIB_VERSION_MAJOR 9 +#define JPEG_LIB_VERSION_MINOR 0 + + +/* Various constants determining the sizes of things. + * All of these are specified by the JPEG standard, so don't change them + * if you want to be compatible. + */ + +#define DCTSIZE 8 /* The basic DCT block is 8x8 coefficients */ +#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */ +#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */ +#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */ +#define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */ +#define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */ +#define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */ +/* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard; + * the PostScript DCT filter can emit files with many more than 10 blocks/MCU. + * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU + * to handle it. We even let you do this from the jconfig.h file. However, + * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe + * sometimes emits noncompliant files doesn't mean you should too. + */ +#define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */ +#ifndef D_MAX_BLOCKS_IN_MCU +#define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */ +#endif + + +/* Data structures for images (arrays of samples and of DCT coefficients). + * On 80x86 machines, the image arrays are too big for near pointers, + * but the pointer arrays can fit in near memory. + */ + +typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */ +typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */ +typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */ + +typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */ +typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */ +typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */ +typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */ + +typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */ + + +/* Types for JPEG compression parameters and working tables. */ + + +/* DCT coefficient quantization tables. */ + +typedef struct { + /* This array gives the coefficient quantizers in natural array order + * (not the zigzag order in which they are stored in a JPEG DQT marker). + * CAUTION: IJG versions prior to v6a kept this array in zigzag order. + */ + UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */ + /* This field is used only during compression. It's initialized FALSE when + * the table is created, and set TRUE when it's been output to the file. + * You could suppress output of a table by setting this to TRUE. + * (See jpeg_suppress_tables for an example.) + */ + boolean sent_table; /* TRUE when table has been output */ +} JQUANT_TBL; + + +/* Huffman coding tables. */ + +typedef struct { + /* These two fields directly represent the contents of a JPEG DHT marker */ + UINT8 bits[17]; /* bits[k] = # of symbols with codes of */ + /* length k bits; bits[0] is unused */ + UINT8 huffval[256]; /* The symbols, in order of incr code length */ + /* This field is used only during compression. It's initialized FALSE when + * the table is created, and set TRUE when it's been output to the file. + * You could suppress output of a table by setting this to TRUE. + * (See jpeg_suppress_tables for an example.) + */ + boolean sent_table; /* TRUE when table has been output */ +} JHUFF_TBL; + + +/* Basic info about one component (color channel). */ + +typedef struct { + /* These values are fixed over the whole image. */ + /* For compression, they must be supplied by parameter setup; */ + /* for decompression, they are read from the SOF marker. */ + int component_id; /* identifier for this component (0..255) */ + int component_index; /* its index in SOF or cinfo->comp_info[] */ + int h_samp_factor; /* horizontal sampling factor (1..4) */ + int v_samp_factor; /* vertical sampling factor (1..4) */ + int quant_tbl_no; /* quantization table selector (0..3) */ + /* These values may vary between scans. */ + /* For compression, they must be supplied by parameter setup; */ + /* for decompression, they are read from the SOS marker. */ + /* The decompressor output side may not use these variables. */ + int dc_tbl_no; /* DC entropy table selector (0..3) */ + int ac_tbl_no; /* AC entropy table selector (0..3) */ + + /* Remaining fields should be treated as private by applications. */ + + /* These values are computed during compression or decompression startup: */ + /* Component's size in DCT blocks. + * Any dummy blocks added to complete an MCU are not counted; therefore + * these values do not depend on whether a scan is interleaved or not. + */ + JDIMENSION width_in_blocks; + JDIMENSION height_in_blocks; + /* Size of a DCT block in samples, + * reflecting any scaling we choose to apply during the DCT step. + * Values from 1 to 16 are supported. + * Note that different components may receive different DCT scalings. + */ + int DCT_h_scaled_size; + int DCT_v_scaled_size; + /* The downsampled dimensions are the component's actual, unpadded number + * of samples at the main buffer (preprocessing/compression interface); + * DCT scaling is included, so + * downsampled_width = ceil(image_width * Hi/Hmax * DCT_h_scaled_size/DCTSIZE) + * and similarly for height. + */ + JDIMENSION downsampled_width; /* actual width in samples */ + JDIMENSION downsampled_height; /* actual height in samples */ + /* This flag is used only for decompression. In cases where some of the + * components will be ignored (eg grayscale output from YCbCr image), + * we can skip most computations for the unused components. + */ + boolean component_needed; /* do we need the value of this component? */ + + /* These values are computed before starting a scan of the component. */ + /* The decompressor output side may not use these variables. */ + int MCU_width; /* number of blocks per MCU, horizontally */ + int MCU_height; /* number of blocks per MCU, vertically */ + int MCU_blocks; /* MCU_width * MCU_height */ + int MCU_sample_width; /* MCU width in samples: MCU_width * DCT_h_scaled_size */ + int last_col_width; /* # of non-dummy blocks across in last MCU */ + int last_row_height; /* # of non-dummy blocks down in last MCU */ + + /* Saved quantization table for component; NULL if none yet saved. + * See jdinput.c comments about the need for this information. + * This field is currently used only for decompression. + */ + JQUANT_TBL * quant_table; + + /* Private per-component storage for DCT or IDCT subsystem. */ + void * dct_table; +} jpeg_component_info; + + +/* The script for encoding a multiple-scan file is an array of these: */ + +typedef struct { + int comps_in_scan; /* number of components encoded in this scan */ + int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */ + int Ss, Se; /* progressive JPEG spectral selection parms */ + int Ah, Al; /* progressive JPEG successive approx. parms */ +} jpeg_scan_info; + +/* The decompressor can save APPn and COM markers in a list of these: */ + +typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr; + +struct jpeg_marker_struct { + jpeg_saved_marker_ptr next; /* next in list, or NULL */ + UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */ + unsigned int original_length; /* # bytes of data in the file */ + unsigned int data_length; /* # bytes of data saved at data[] */ + JOCTET FAR * data; /* the data contained in the marker */ + /* the marker length word is not counted in data_length or original_length */ +}; + +/* Known color spaces. */ + +typedef enum { + JCS_UNKNOWN, /* error/unspecified */ + JCS_GRAYSCALE, /* monochrome */ + JCS_RGB, /* red/green/blue */ + JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */ + JCS_CMYK, /* C/M/Y/K */ + JCS_YCCK /* Y/Cb/Cr/K */ +} J_COLOR_SPACE; + +/* Supported color transforms. */ + +typedef enum { + JCT_NONE = 0, + JCT_SUBTRACT_GREEN = 1 +} J_COLOR_TRANSFORM; + +/* DCT/IDCT algorithm options. */ + +typedef enum { + JDCT_ISLOW, /* slow but accurate integer algorithm */ + JDCT_IFAST, /* faster, less accurate integer method */ + JDCT_FLOAT /* floating-point: accurate, fast on fast HW */ +} J_DCT_METHOD; + +#ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */ +#define JDCT_DEFAULT JDCT_ISLOW +#endif +#ifndef JDCT_FASTEST /* may be overridden in jconfig.h */ +#define JDCT_FASTEST JDCT_IFAST +#endif + +/* Dithering options for decompression. */ + +typedef enum { + JDITHER_NONE, /* no dithering */ + JDITHER_ORDERED, /* simple ordered dither */ + JDITHER_FS /* Floyd-Steinberg error diffusion dither */ +} J_DITHER_MODE; + + +/* Common fields between JPEG compression and decompression master structs. */ + +#define jpeg_common_fields \ + struct jpeg_error_mgr * err; /* Error handler module */\ + struct jpeg_memory_mgr * mem; /* Memory manager module */\ + struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\ + void * client_data; /* Available for use by application */\ + boolean is_decompressor; /* So common code can tell which is which */\ + int global_state /* For checking call sequence validity */ + +/* Routines that are to be used by both halves of the library are declared + * to receive a pointer to this structure. There are no actual instances of + * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct. + */ +struct jpeg_common_struct { + jpeg_common_fields; /* Fields common to both master struct types */ + /* Additional fields follow in an actual jpeg_compress_struct or + * jpeg_decompress_struct. All three structs must agree on these + * initial fields! (This would be a lot cleaner in C++.) + */ +}; + +typedef struct jpeg_common_struct * j_common_ptr; +typedef struct jpeg_compress_struct * j_compress_ptr; +typedef struct jpeg_decompress_struct * j_decompress_ptr; + + +/* Master record for a compression instance */ + +struct jpeg_compress_struct { + jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */ + + /* Destination for compressed data */ + struct jpeg_destination_mgr * dest; + + /* Description of source image --- these fields must be filled in by + * outer application before starting compression. in_color_space must + * be correct before you can even call jpeg_set_defaults(). + */ + + JDIMENSION image_width; /* input image width */ + JDIMENSION image_height; /* input image height */ + int input_components; /* # of color components in input image */ + J_COLOR_SPACE in_color_space; /* colorspace of input image */ + + double input_gamma; /* image gamma of input image */ + + /* Compression parameters --- these fields must be set before calling + * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to + * initialize everything to reasonable defaults, then changing anything + * the application specifically wants to change. That way you won't get + * burnt when new parameters are added. Also note that there are several + * helper routines to simplify changing parameters. + */ + + unsigned int scale_num, scale_denom; /* fraction by which to scale image */ + + JDIMENSION jpeg_width; /* scaled JPEG image width */ + JDIMENSION jpeg_height; /* scaled JPEG image height */ + /* Dimensions of actual JPEG image that will be written to file, + * derived from input dimensions by scaling factors above. + * These fields are computed by jpeg_start_compress(). + * You can also use jpeg_calc_jpeg_dimensions() to determine these values + * in advance of calling jpeg_start_compress(). + */ + + int data_precision; /* bits of precision in image data */ + + int num_components; /* # of color components in JPEG image */ + J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ + + jpeg_component_info * comp_info; + /* comp_info[i] describes component that appears i'th in SOF */ + + JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; + int q_scale_factor[NUM_QUANT_TBLS]; + /* ptrs to coefficient quantization tables, or NULL if not defined, + * and corresponding scale factors (percentage, initialized 100). + */ + + JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; + JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; + /* ptrs to Huffman coding tables, or NULL if not defined */ + + UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ + UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ + UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ + + int num_scans; /* # of entries in scan_info array */ + const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */ + /* The default value of scan_info is NULL, which causes a single-scan + * sequential JPEG file to be emitted. To create a multi-scan file, + * set num_scans and scan_info to point to an array of scan definitions. + */ + + boolean raw_data_in; /* TRUE=caller supplies downsampled data */ + boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ + boolean optimize_coding; /* TRUE=optimize entropy encoding parms */ + boolean CCIR601_sampling; /* TRUE=first samples are cosited */ + boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */ + int smoothing_factor; /* 1..100, or 0 for no input smoothing */ + J_DCT_METHOD dct_method; /* DCT algorithm selector */ + + /* The restart interval can be specified in absolute MCUs by setting + * restart_interval, or in MCU rows by setting restart_in_rows + * (in which case the correct restart_interval will be figured + * for each scan). + */ + unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */ + int restart_in_rows; /* if > 0, MCU rows per restart interval */ + + /* Parameters controlling emission of special markers. */ + + boolean write_JFIF_header; /* should a JFIF marker be written? */ + UINT8 JFIF_major_version; /* What to write for the JFIF version number */ + UINT8 JFIF_minor_version; + /* These three values are not used by the JPEG code, merely copied */ + /* into the JFIF APP0 marker. density_unit can be 0 for unknown, */ + /* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */ + /* ratio is defined by X_density/Y_density even when density_unit=0. */ + UINT8 density_unit; /* JFIF code for pixel size units */ + UINT16 X_density; /* Horizontal pixel density */ + UINT16 Y_density; /* Vertical pixel density */ + boolean write_Adobe_marker; /* should an Adobe marker be written? */ + + J_COLOR_TRANSFORM color_transform; + /* Color transform identifier, writes LSE marker if nonzero */ + + /* State variable: index of next scanline to be written to + * jpeg_write_scanlines(). Application may use this to control its + * processing loop, e.g., "while (next_scanline < image_height)". + */ + + JDIMENSION next_scanline; /* 0 .. image_height-1 */ + + /* Remaining fields are known throughout compressor, but generally + * should not be touched by a surrounding application. + */ + + /* + * These fields are computed during compression startup + */ + boolean progressive_mode; /* TRUE if scan script uses progressive mode */ + int max_h_samp_factor; /* largest h_samp_factor */ + int max_v_samp_factor; /* largest v_samp_factor */ + + int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ + int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ + + JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */ + /* The coefficient controller receives data in units of MCU rows as defined + * for fully interleaved scans (whether the JPEG file is interleaved or not). + * There are v_samp_factor * DCTSIZE sample rows of each component in an + * "iMCU" (interleaved MCU) row. + */ + + /* + * These fields are valid during any one scan. + * They describe the components and MCUs actually appearing in the scan. + */ + int comps_in_scan; /* # of JPEG components in this scan */ + jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; + /* *cur_comp_info[i] describes component that appears i'th in SOS */ + + JDIMENSION MCUs_per_row; /* # of MCUs across the image */ + JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ + + int blocks_in_MCU; /* # of DCT blocks per MCU */ + int MCU_membership[C_MAX_BLOCKS_IN_MCU]; + /* MCU_membership[i] is index in cur_comp_info of component owning */ + /* i'th block in an MCU */ + + int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ + + int block_size; /* the basic DCT block size: 1..16 */ + const int * natural_order; /* natural-order position array */ + int lim_Se; /* min( Se, DCTSIZE2-1 ) */ + + /* + * Links to compression subobjects (methods and private variables of modules) + */ + struct jpeg_comp_master * master; + struct jpeg_c_main_controller * main; + struct jpeg_c_prep_controller * prep; + struct jpeg_c_coef_controller * coef; + struct jpeg_marker_writer * marker; + struct jpeg_color_converter * cconvert; + struct jpeg_downsampler * downsample; + struct jpeg_forward_dct * fdct; + struct jpeg_entropy_encoder * entropy; + jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */ + int script_space_size; +}; + + +/* Master record for a decompression instance */ + +struct jpeg_decompress_struct { + jpeg_common_fields; /* Fields shared with jpeg_compress_struct */ + + /* Source of compressed data */ + struct jpeg_source_mgr * src; + + /* Basic description of image --- filled in by jpeg_read_header(). */ + /* Application may inspect these values to decide how to process image. */ + + JDIMENSION image_width; /* nominal image width (from SOF marker) */ + JDIMENSION image_height; /* nominal image height */ + int num_components; /* # of color components in JPEG image */ + J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ + + /* Decompression processing parameters --- these fields must be set before + * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes + * them to default values. + */ + + J_COLOR_SPACE out_color_space; /* colorspace for output */ + + unsigned int scale_num, scale_denom; /* fraction by which to scale image */ + + double output_gamma; /* image gamma wanted in output */ + + boolean buffered_image; /* TRUE=multiple output passes */ + boolean raw_data_out; /* TRUE=downsampled data wanted */ + + J_DCT_METHOD dct_method; /* IDCT algorithm selector */ + boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */ + boolean do_block_smoothing; /* TRUE=apply interblock smoothing */ + + boolean quantize_colors; /* TRUE=colormapped output wanted */ + /* the following are ignored if not quantize_colors: */ + J_DITHER_MODE dither_mode; /* type of color dithering to use */ + boolean two_pass_quantize; /* TRUE=use two-pass color quantization */ + int desired_number_of_colors; /* max # colors to use in created colormap */ + /* these are significant only in buffered-image mode: */ + boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */ + boolean enable_external_quant;/* enable future use of external colormap */ + boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */ + + /* Description of actual output image that will be returned to application. + * These fields are computed by jpeg_start_decompress(). + * You can also use jpeg_calc_output_dimensions() to determine these values + * in advance of calling jpeg_start_decompress(). + */ + + JDIMENSION output_width; /* scaled image width */ + JDIMENSION output_height; /* scaled image height */ + int out_color_components; /* # of color components in out_color_space */ + int output_components; /* # of color components returned */ + /* output_components is 1 (a colormap index) when quantizing colors; + * otherwise it equals out_color_components. + */ + int rec_outbuf_height; /* min recommended height of scanline buffer */ + /* If the buffer passed to jpeg_read_scanlines() is less than this many rows + * high, space and time will be wasted due to unnecessary data copying. + * Usually rec_outbuf_height will be 1 or 2, at most 4. + */ + + /* When quantizing colors, the output colormap is described by these fields. + * The application can supply a colormap by setting colormap non-NULL before + * calling jpeg_start_decompress; otherwise a colormap is created during + * jpeg_start_decompress or jpeg_start_output. + * The map has out_color_components rows and actual_number_of_colors columns. + */ + int actual_number_of_colors; /* number of entries in use */ + JSAMPARRAY colormap; /* The color map as a 2-D pixel array */ + + /* State variables: these variables indicate the progress of decompression. + * The application may examine these but must not modify them. + */ + + /* Row index of next scanline to be read from jpeg_read_scanlines(). + * Application may use this to control its processing loop, e.g., + * "while (output_scanline < output_height)". + */ + JDIMENSION output_scanline; /* 0 .. output_height-1 */ + + /* Current input scan number and number of iMCU rows completed in scan. + * These indicate the progress of the decompressor input side. + */ + int input_scan_number; /* Number of SOS markers seen so far */ + JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */ + + /* The "output scan number" is the notional scan being displayed by the + * output side. The decompressor will not allow output scan/row number + * to get ahead of input scan/row, but it can fall arbitrarily far behind. + */ + int output_scan_number; /* Nominal scan number being displayed */ + JDIMENSION output_iMCU_row; /* Number of iMCU rows read */ + + /* Current progression status. coef_bits[c][i] indicates the precision + * with which component c's DCT coefficient i (in zigzag order) is known. + * It is -1 when no data has yet been received, otherwise it is the point + * transform (shift) value for the most recent scan of the coefficient + * (thus, 0 at completion of the progression). + * This pointer is NULL when reading a non-progressive file. + */ + int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */ + + /* Internal JPEG parameters --- the application usually need not look at + * these fields. Note that the decompressor output side may not use + * any parameters that can change between scans. + */ + + /* Quantization and Huffman tables are carried forward across input + * datastreams when processing abbreviated JPEG datastreams. + */ + + JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; + /* ptrs to coefficient quantization tables, or NULL if not defined */ + + JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; + JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; + /* ptrs to Huffman coding tables, or NULL if not defined */ + + /* These parameters are never carried across datastreams, since they + * are given in SOF/SOS markers or defined to be reset by SOI. + */ + + int data_precision; /* bits of precision in image data */ + + jpeg_component_info * comp_info; + /* comp_info[i] describes component that appears i'th in SOF */ + + boolean is_baseline; /* TRUE if Baseline SOF0 encountered */ + boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */ + boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ + + UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ + UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ + UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ + + unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */ + + /* These fields record data obtained from optional markers recognized by + * the JPEG library. + */ + boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */ + /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */ + UINT8 JFIF_major_version; /* JFIF version number */ + UINT8 JFIF_minor_version; + UINT8 density_unit; /* JFIF code for pixel size units */ + UINT16 X_density; /* Horizontal pixel density */ + UINT16 Y_density; /* Vertical pixel density */ + boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */ + UINT8 Adobe_transform; /* Color transform code from Adobe marker */ + + J_COLOR_TRANSFORM color_transform; + /* Color transform identifier derived from LSE marker, otherwise zero */ + + boolean CCIR601_sampling; /* TRUE=first samples are cosited */ + + /* Aside from the specific data retained from APPn markers known to the + * library, the uninterpreted contents of any or all APPn and COM markers + * can be saved in a list for examination by the application. + */ + jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */ + + /* Remaining fields are known throughout decompressor, but generally + * should not be touched by a surrounding application. + */ + + /* + * These fields are computed during decompression startup + */ + int max_h_samp_factor; /* largest h_samp_factor */ + int max_v_samp_factor; /* largest v_samp_factor */ + + int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ + int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ + + JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */ + /* The coefficient controller's input and output progress is measured in + * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows + * in fully interleaved JPEG scans, but are used whether the scan is + * interleaved or not. We define an iMCU row as v_samp_factor DCT block + * rows of each component. Therefore, the IDCT output contains + * v_samp_factor*DCT_v_scaled_size sample rows of a component per iMCU row. + */ + + JSAMPLE * sample_range_limit; /* table for fast range-limiting */ + + /* + * These fields are valid during any one scan. + * They describe the components and MCUs actually appearing in the scan. + * Note that the decompressor output side must not use these fields. + */ + int comps_in_scan; /* # of JPEG components in this scan */ + jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; + /* *cur_comp_info[i] describes component that appears i'th in SOS */ + + JDIMENSION MCUs_per_row; /* # of MCUs across the image */ + JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ + + int blocks_in_MCU; /* # of DCT blocks per MCU */ + int MCU_membership[D_MAX_BLOCKS_IN_MCU]; + /* MCU_membership[i] is index in cur_comp_info of component owning */ + /* i'th block in an MCU */ + + int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ + + /* These fields are derived from Se of first SOS marker. + */ + int block_size; /* the basic DCT block size: 1..16 */ + const int * natural_order; /* natural-order position array for entropy decode */ + int lim_Se; /* min( Se, DCTSIZE2-1 ) for entropy decode */ + + /* This field is shared between entropy decoder and marker parser. + * It is either zero or the code of a JPEG marker that has been + * read from the data source, but has not yet been processed. + */ + int unread_marker; + + /* + * Links to decompression subobjects (methods, private variables of modules) + */ + struct jpeg_decomp_master * master; + struct jpeg_d_main_controller * main; + struct jpeg_d_coef_controller * coef; + struct jpeg_d_post_controller * post; + struct jpeg_input_controller * inputctl; + struct jpeg_marker_reader * marker; + struct jpeg_entropy_decoder * entropy; + struct jpeg_inverse_dct * idct; + struct jpeg_upsampler * upsample; + struct jpeg_color_deconverter * cconvert; + struct jpeg_color_quantizer * cquantize; +}; + + +/* "Object" declarations for JPEG modules that may be supplied or called + * directly by the surrounding application. + * As with all objects in the JPEG library, these structs only define the + * publicly visible methods and state variables of a module. Additional + * private fields may exist after the public ones. + */ + + +/* Error handler object */ + +struct jpeg_error_mgr { + /* Error exit handler: does not return to caller */ + JMETHOD(noreturn_t, error_exit, (j_common_ptr cinfo)); + /* Conditionally emit a trace or warning message */ + JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level)); + /* Routine that actually outputs a trace or error message */ + JMETHOD(void, output_message, (j_common_ptr cinfo)); + /* Format a message string for the most recent JPEG error or message */ + JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer)); +#define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */ + /* Reset error state variables at start of a new image */ + JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo)); + + /* The message ID code and any parameters are saved here. + * A message can have one string parameter or up to 8 int parameters. + */ + int msg_code; +#define JMSG_STR_PARM_MAX 80 + union { + int i[8]; + char s[JMSG_STR_PARM_MAX]; + } msg_parm; + + /* Standard state variables for error facility */ + + int trace_level; /* max msg_level that will be displayed */ + + /* For recoverable corrupt-data errors, we emit a warning message, + * but keep going unless emit_message chooses to abort. emit_message + * should count warnings in num_warnings. The surrounding application + * can check for bad data by seeing if num_warnings is nonzero at the + * end of processing. + */ + long num_warnings; /* number of corrupt-data warnings */ + + /* These fields point to the table(s) of error message strings. + * An application can change the table pointer to switch to a different + * message list (typically, to change the language in which errors are + * reported). Some applications may wish to add additional error codes + * that will be handled by the JPEG library error mechanism; the second + * table pointer is used for this purpose. + * + * First table includes all errors generated by JPEG library itself. + * Error code 0 is reserved for a "no such error string" message. + */ + const char * const * jpeg_message_table; /* Library errors */ + int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */ + /* Second table can be added by application (see cjpeg/djpeg for example). + * It contains strings numbered first_addon_message..last_addon_message. + */ + const char * const * addon_message_table; /* Non-library errors */ + int first_addon_message; /* code for first string in addon table */ + int last_addon_message; /* code for last string in addon table */ +}; + + +/* Progress monitor object */ + +struct jpeg_progress_mgr { + JMETHOD(void, progress_monitor, (j_common_ptr cinfo)); + + long pass_counter; /* work units completed in this pass */ + long pass_limit; /* total number of work units in this pass */ + int completed_passes; /* passes completed so far */ + int total_passes; /* total number of passes expected */ +}; + + +/* Data destination object for compression */ + +struct jpeg_destination_mgr { + JOCTET * next_output_byte; /* => next byte to write in buffer */ + size_t free_in_buffer; /* # of byte spaces remaining in buffer */ + + JMETHOD(void, init_destination, (j_compress_ptr cinfo)); + JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo)); + JMETHOD(void, term_destination, (j_compress_ptr cinfo)); +}; + + +/* Data source object for decompression */ + +struct jpeg_source_mgr { + const JOCTET * next_input_byte; /* => next byte to read from buffer */ + size_t bytes_in_buffer; /* # of bytes remaining in buffer */ + + JMETHOD(void, init_source, (j_decompress_ptr cinfo)); + JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo)); + JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes)); + JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired)); + JMETHOD(void, term_source, (j_decompress_ptr cinfo)); +}; + + +/* Memory manager object. + * Allocates "small" objects (a few K total), "large" objects (tens of K), + * and "really big" objects (virtual arrays with backing store if needed). + * The memory manager does not allow individual objects to be freed; rather, + * each created object is assigned to a pool, and whole pools can be freed + * at once. This is faster and more convenient than remembering exactly what + * to free, especially where malloc()/free() are not too speedy. + * NB: alloc routines never return NULL. They exit to error_exit if not + * successful. + */ + +#define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */ +#define JPOOL_IMAGE 1 /* lasts until done with image/datastream */ +#define JPOOL_NUMPOOLS 2 + +typedef struct jvirt_sarray_control * jvirt_sarray_ptr; +typedef struct jvirt_barray_control * jvirt_barray_ptr; + + +struct jpeg_memory_mgr { + /* Method pointers */ + JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id, + size_t sizeofobject)); + JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id, + size_t sizeofobject)); + JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id, + JDIMENSION samplesperrow, + JDIMENSION numrows)); + JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id, + JDIMENSION blocksperrow, + JDIMENSION numrows)); + JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo, + int pool_id, + boolean pre_zero, + JDIMENSION samplesperrow, + JDIMENSION numrows, + JDIMENSION maxaccess)); + JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo, + int pool_id, + boolean pre_zero, + JDIMENSION blocksperrow, + JDIMENSION numrows, + JDIMENSION maxaccess)); + JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo)); + JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo, + jvirt_sarray_ptr ptr, + JDIMENSION start_row, + JDIMENSION num_rows, + boolean writable)); + JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo, + jvirt_barray_ptr ptr, + JDIMENSION start_row, + JDIMENSION num_rows, + boolean writable)); + JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id)); + JMETHOD(void, self_destruct, (j_common_ptr cinfo)); + + /* Limit on memory allocation for this JPEG object. (Note that this is + * merely advisory, not a guaranteed maximum; it only affects the space + * used for virtual-array buffers.) May be changed by outer application + * after creating the JPEG object. + */ + long max_memory_to_use; + + /* Maximum allocation request accepted by alloc_large. */ + long max_alloc_chunk; +}; + + +/* Routine signature for application-supplied marker processing methods. + * Need not pass marker code since it is stored in cinfo->unread_marker. + */ +typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo)); + + +/* Declarations for routines called by application. + * The JPP macro hides prototype parameters from compilers that can't cope. + * Note JPP requires double parentheses. + */ + +#ifdef HAVE_PROTOTYPES +#define JPP(arglist) arglist +#else +#define JPP(arglist) () +#endif + + +/* Short forms of external names for systems with brain-damaged linkers. + * We shorten external names to be unique in the first six letters, which + * is good enough for all known systems. + * (If your compiler itself needs names to be unique in less than 15 + * characters, you are out of luck. Get a better compiler.) + */ + +#ifdef NEED_SHORT_EXTERNAL_NAMES +#define jpeg_std_error jStdError +#define jpeg_CreateCompress jCreaCompress +#define jpeg_CreateDecompress jCreaDecompress +#define jpeg_destroy_compress jDestCompress +#define jpeg_destroy_decompress jDestDecompress +#define jpeg_stdio_dest jStdDest +#define jpeg_stdio_src jStdSrc +#define jpeg_mem_dest jMemDest +#define jpeg_mem_src jMemSrc +#define jpeg_set_defaults jSetDefaults +#define jpeg_set_colorspace jSetColorspace +#define jpeg_default_colorspace jDefColorspace +#define jpeg_set_quality jSetQuality +#define jpeg_set_linear_quality jSetLQuality +#define jpeg_default_qtables jDefQTables +#define jpeg_add_quant_table jAddQuantTable +#define jpeg_quality_scaling jQualityScaling +#define jpeg_simple_progression jSimProgress +#define jpeg_suppress_tables jSuppressTables +#define jpeg_alloc_quant_table jAlcQTable +#define jpeg_alloc_huff_table jAlcHTable +#define jpeg_start_compress jStrtCompress +#define jpeg_write_scanlines jWrtScanlines +#define jpeg_finish_compress jFinCompress +#define jpeg_calc_jpeg_dimensions jCjpegDimensions +#define jpeg_write_raw_data jWrtRawData +#define jpeg_write_marker jWrtMarker +#define jpeg_write_m_header jWrtMHeader +#define jpeg_write_m_byte jWrtMByte +#define jpeg_write_tables jWrtTables +#define jpeg_read_header jReadHeader +#define jpeg_start_decompress jStrtDecompress +#define jpeg_read_scanlines jReadScanlines +#define jpeg_finish_decompress jFinDecompress +#define jpeg_read_raw_data jReadRawData +#define jpeg_has_multiple_scans jHasMultScn +#define jpeg_start_output jStrtOutput +#define jpeg_finish_output jFinOutput +#define jpeg_input_complete jInComplete +#define jpeg_new_colormap jNewCMap +#define jpeg_consume_input jConsumeInput +#define jpeg_core_output_dimensions jCoreDimensions +#define jpeg_calc_output_dimensions jCalcDimensions +#define jpeg_save_markers jSaveMarkers +#define jpeg_set_marker_processor jSetMarker +#define jpeg_read_coefficients jReadCoefs +#define jpeg_write_coefficients jWrtCoefs +#define jpeg_copy_critical_parameters jCopyCrit +#define jpeg_abort_compress jAbrtCompress +#define jpeg_abort_decompress jAbrtDecompress +#define jpeg_abort jAbort +#define jpeg_destroy jDestroy +#define jpeg_resync_to_restart jResyncRestart +#endif /* NEED_SHORT_EXTERNAL_NAMES */ + + +/* Default error-management setup */ +EXTERN(struct jpeg_error_mgr *) jpeg_std_error + JPP((struct jpeg_error_mgr * err)); + +/* Initialization of JPEG compression objects. + * jpeg_create_compress() and jpeg_create_decompress() are the exported + * names that applications should call. These expand to calls on + * jpeg_CreateCompress and jpeg_CreateDecompress with additional information + * passed for version mismatch checking. + * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx. + */ +#define jpeg_create_compress(cinfo) \ + jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \ + (size_t) sizeof(struct jpeg_compress_struct)) +#define jpeg_create_decompress(cinfo) \ + jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \ + (size_t) sizeof(struct jpeg_decompress_struct)) +EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo, + int version, size_t structsize)); +EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo, + int version, size_t structsize)); +/* Destruction of JPEG compression objects */ +EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo)); + +/* Standard data source and destination managers: stdio streams. */ +/* Caller is responsible for opening the file before and closing after. */ +EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile)); +EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile)); + +/* Data source and destination managers: memory buffers. */ +EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo, + unsigned char ** outbuffer, + unsigned long * outsize)); +EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo, + unsigned char * inbuffer, + unsigned long insize)); + +/* Default parameter setup for compression */ +EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo)); +/* Compression parameter setup aids */ +EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo, + J_COLOR_SPACE colorspace)); +EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality, + boolean force_baseline)); +EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo, + int scale_factor, + boolean force_baseline)); +EXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo, + boolean force_baseline)); +EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl, + const unsigned int *basic_table, + int scale_factor, + boolean force_baseline)); +EXTERN(int) jpeg_quality_scaling JPP((int quality)); +EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo, + boolean suppress)); +EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo)); +EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo)); + +/* Main entry points for compression */ +EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo, + boolean write_all_tables)); +EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo, + JSAMPARRAY scanlines, + JDIMENSION num_lines)); +EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo)); + +/* Precalculate JPEG dimensions for current compression parameters. */ +EXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo)); + +/* Replaces jpeg_write_scanlines when writing raw downsampled data. */ +EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo, + JSAMPIMAGE data, + JDIMENSION num_lines)); + +/* Write a special marker. See libjpeg.txt concerning safe usage. */ +EXTERN(void) jpeg_write_marker + JPP((j_compress_ptr cinfo, int marker, + const JOCTET * dataptr, unsigned int datalen)); +/* Same, but piecemeal. */ +EXTERN(void) jpeg_write_m_header + JPP((j_compress_ptr cinfo, int marker, unsigned int datalen)); +EXTERN(void) jpeg_write_m_byte + JPP((j_compress_ptr cinfo, int val)); + +/* Alternate compression function: just write an abbreviated table file */ +EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo)); + +/* Decompression startup: read start of JPEG datastream to see what's there */ +EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo, + boolean require_image)); +/* Return value is one of: */ +#define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */ +#define JPEG_HEADER_OK 1 /* Found valid image datastream */ +#define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */ +/* If you pass require_image = TRUE (normal case), you need not check for + * a TABLES_ONLY return code; an abbreviated file will cause an error exit. + * JPEG_SUSPENDED is only possible if you use a data source module that can + * give a suspension return (the stdio source module doesn't). + */ + +/* Main entry points for decompression */ +EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo)); +EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo, + JSAMPARRAY scanlines, + JDIMENSION max_lines)); +EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo)); + +/* Replaces jpeg_read_scanlines when reading raw downsampled data. */ +EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo, + JSAMPIMAGE data, + JDIMENSION max_lines)); + +/* Additional entry points for buffered-image mode. */ +EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo)); +EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo, + int scan_number)); +EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo)); +EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo)); +EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo)); +EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo)); +/* Return value is one of: */ +/* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */ +#define JPEG_REACHED_SOS 1 /* Reached start of new scan */ +#define JPEG_REACHED_EOI 2 /* Reached end of image */ +#define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */ +#define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */ + +/* Precalculate output dimensions for current decompression parameters. */ +EXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo)); +EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo)); + +/* Control saving of COM and APPn markers into marker_list. */ +EXTERN(void) jpeg_save_markers + JPP((j_decompress_ptr cinfo, int marker_code, + unsigned int length_limit)); + +/* Install a special processing method for COM or APPn markers. */ +EXTERN(void) jpeg_set_marker_processor + JPP((j_decompress_ptr cinfo, int marker_code, + jpeg_marker_parser_method routine)); + +/* Read or write raw DCT coefficients --- useful for lossless transcoding. */ +EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo)); +EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo, + jvirt_barray_ptr * coef_arrays)); +EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo, + j_compress_ptr dstinfo)); + +/* If you choose to abort compression or decompression before completing + * jpeg_finish_(de)compress, then you need to clean up to release memory, + * temporary files, etc. You can just call jpeg_destroy_(de)compress + * if you're done with the JPEG object, but if you want to clean it up and + * reuse it, call this: + */ +EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo)); +EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo)); + +/* Generic versions of jpeg_abort and jpeg_destroy that work on either + * flavor of JPEG object. These may be more convenient in some places. + */ +EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo)); +EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo)); + +/* Default restart-marker-resync procedure for use by data source modules */ +EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo, + int desired)); + + +/* These marker codes are exported since applications and data source modules + * are likely to want to use them. + */ + +#define JPEG_RST0 0xD0 /* RST0 marker code */ +#define JPEG_EOI 0xD9 /* EOI marker code */ +#define JPEG_APP0 0xE0 /* APP0 marker code */ +#define JPEG_COM 0xFE /* COM marker code */ + + +/* If we have a brain-damaged compiler that emits warnings (or worse, errors) + * for structure definitions that are never filled in, keep it quiet by + * supplying dummy definitions for the various substructures. + */ + +#ifdef INCOMPLETE_TYPES_BROKEN +#ifndef JPEG_INTERNALS /* will be defined in jpegint.h */ +struct jvirt_sarray_control { long dummy; }; +struct jvirt_barray_control { long dummy; }; +struct jpeg_comp_master { long dummy; }; +struct jpeg_c_main_controller { long dummy; }; +struct jpeg_c_prep_controller { long dummy; }; +struct jpeg_c_coef_controller { long dummy; }; +struct jpeg_marker_writer { long dummy; }; +struct jpeg_color_converter { long dummy; }; +struct jpeg_downsampler { long dummy; }; +struct jpeg_forward_dct { long dummy; }; +struct jpeg_entropy_encoder { long dummy; }; +struct jpeg_decomp_master { long dummy; }; +struct jpeg_d_main_controller { long dummy; }; +struct jpeg_d_coef_controller { long dummy; }; +struct jpeg_d_post_controller { long dummy; }; +struct jpeg_input_controller { long dummy; }; +struct jpeg_marker_reader { long dummy; }; +struct jpeg_entropy_decoder { long dummy; }; +struct jpeg_inverse_dct { long dummy; }; +struct jpeg_upsampler { long dummy; }; +struct jpeg_color_deconverter { long dummy; }; +struct jpeg_color_quantizer { long dummy; }; +#endif /* JPEG_INTERNALS */ +#endif /* INCOMPLETE_TYPES_BROKEN */ + + +/* + * The JPEG library modules define JPEG_INTERNALS before including this file. + * The internal structure declarations are read only when that is true. + * Applications using the library should not include jpegint.h, but may wish + * to include jerror.h. + */ + +#ifdef JPEG_INTERNALS +#include "jpegint.h" /* fetch private declarations */ +#include "jerror.h" /* fetch error codes too */ +#endif + +#ifdef __cplusplus +#ifndef DONT_USE_EXTERN_C +} +#endif +#endif + +#endif /* JPEGLIB_H */ diff --git a/android/x86/include/openssl/aes.h b/android/x86/include/openssl/aes.h new file mode 100644 index 00000000..245c552a --- /dev/null +++ b/android/x86/include/openssl/aes.h @@ -0,0 +1,92 @@ +/* + * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_AES_H +# define HEADER_AES_H + +# include <openssl/opensslconf.h> + +# include <stddef.h> +# ifdef __cplusplus +extern "C" { +# endif + +# define AES_ENCRYPT 1 +# define AES_DECRYPT 0 + +/* + * Because array size can't be a const in C, the following two are macros. + * Both sizes are in bytes. + */ +# define AES_MAXNR 14 +# define AES_BLOCK_SIZE 16 + +/* This should be a hidden type, but EVP requires that the size be known */ +struct aes_key_st { +# ifdef AES_LONG + unsigned long rd_key[4 * (AES_MAXNR + 1)]; +# else + unsigned int rd_key[4 * (AES_MAXNR + 1)]; +# endif + int rounds; +}; +typedef struct aes_key_st AES_KEY; + +const char *AES_options(void); + +int AES_set_encrypt_key(const unsigned char *userKey, const int bits, + AES_KEY *key); +int AES_set_decrypt_key(const unsigned char *userKey, const int bits, + AES_KEY *key); + +void AES_encrypt(const unsigned char *in, unsigned char *out, + const AES_KEY *key); +void AES_decrypt(const unsigned char *in, unsigned char *out, + const AES_KEY *key); + +void AES_ecb_encrypt(const unsigned char *in, unsigned char *out, + const AES_KEY *key, const int enc); +void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, const int enc); +void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, int *num, const int enc); +void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, int *num, const int enc); +void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, int *num, const int enc); +void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, int *num); +/* NB: the IV is _two_ blocks long */ +void AES_ige_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, const int enc); +/* NB: the IV is _four_ blocks long */ +void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + const AES_KEY *key2, const unsigned char *ivec, + const int enc); + +int AES_wrap_key(AES_KEY *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, unsigned int inlen); +int AES_unwrap_key(AES_KEY *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, unsigned int inlen); + + +# ifdef __cplusplus +} +# endif + +#endif diff --git a/android/x86/include/openssl/asn1.h b/android/x86/include/openssl/asn1.h new file mode 100644 index 00000000..7cf61161 --- /dev/null +++ b/android/x86/include/openssl/asn1.h @@ -0,0 +1,1096 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ASN1_H +# define HEADER_ASN1_H + +# include <time.h> +# include <openssl/e_os2.h> +# include <openssl/opensslconf.h> +# include <openssl/bio.h> +# include <openssl/stack.h> +# include <openssl/safestack.h> + +# include <openssl/symhacks.h> + +# include <openssl/ossl_typ.h> +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/bn.h> +# endif + +# ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +# endif + +#ifdef __cplusplus +extern "C" { +#endif + +# define V_ASN1_UNIVERSAL 0x00 +# define V_ASN1_APPLICATION 0x40 +# define V_ASN1_CONTEXT_SPECIFIC 0x80 +# define V_ASN1_PRIVATE 0xc0 + +# define V_ASN1_CONSTRUCTED 0x20 +# define V_ASN1_PRIMITIVE_TAG 0x1f +# define V_ASN1_PRIMATIVE_TAG 0x1f + +# define V_ASN1_APP_CHOOSE -2/* let the recipient choose */ +# define V_ASN1_OTHER -3/* used in ASN1_TYPE */ +# define V_ASN1_ANY -4/* used in ASN1 template code */ + +# define V_ASN1_UNDEF -1 +/* ASN.1 tag values */ +# define V_ASN1_EOC 0 +# define V_ASN1_BOOLEAN 1 /**/ +# define V_ASN1_INTEGER 2 +# define V_ASN1_BIT_STRING 3 +# define V_ASN1_OCTET_STRING 4 +# define V_ASN1_NULL 5 +# define V_ASN1_OBJECT 6 +# define V_ASN1_OBJECT_DESCRIPTOR 7 +# define V_ASN1_EXTERNAL 8 +# define V_ASN1_REAL 9 +# define V_ASN1_ENUMERATED 10 +# define V_ASN1_UTF8STRING 12 +# define V_ASN1_SEQUENCE 16 +# define V_ASN1_SET 17 +# define V_ASN1_NUMERICSTRING 18 /**/ +# define V_ASN1_PRINTABLESTRING 19 +# define V_ASN1_T61STRING 20 +# define V_ASN1_TELETEXSTRING 20/* alias */ +# define V_ASN1_VIDEOTEXSTRING 21 /**/ +# define V_ASN1_IA5STRING 22 +# define V_ASN1_UTCTIME 23 +# define V_ASN1_GENERALIZEDTIME 24 /**/ +# define V_ASN1_GRAPHICSTRING 25 /**/ +# define V_ASN1_ISO64STRING 26 /**/ +# define V_ASN1_VISIBLESTRING 26/* alias */ +# define V_ASN1_GENERALSTRING 27 /**/ +# define V_ASN1_UNIVERSALSTRING 28 /**/ +# define V_ASN1_BMPSTRING 30 + +/* + * NB the constants below are used internally by ASN1_INTEGER + * and ASN1_ENUMERATED to indicate the sign. They are *not* on + * the wire tag values. + */ + +# define V_ASN1_NEG 0x100 +# define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG) +# define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG) + +/* For use with d2i_ASN1_type_bytes() */ +# define B_ASN1_NUMERICSTRING 0x0001 +# define B_ASN1_PRINTABLESTRING 0x0002 +# define B_ASN1_T61STRING 0x0004 +# define B_ASN1_TELETEXSTRING 0x0004 +# define B_ASN1_VIDEOTEXSTRING 0x0008 +# define B_ASN1_IA5STRING 0x0010 +# define B_ASN1_GRAPHICSTRING 0x0020 +# define B_ASN1_ISO64STRING 0x0040 +# define B_ASN1_VISIBLESTRING 0x0040 +# define B_ASN1_GENERALSTRING 0x0080 +# define B_ASN1_UNIVERSALSTRING 0x0100 +# define B_ASN1_OCTET_STRING 0x0200 +# define B_ASN1_BIT_STRING 0x0400 +# define B_ASN1_BMPSTRING 0x0800 +# define B_ASN1_UNKNOWN 0x1000 +# define B_ASN1_UTF8STRING 0x2000 +# define B_ASN1_UTCTIME 0x4000 +# define B_ASN1_GENERALIZEDTIME 0x8000 +# define B_ASN1_SEQUENCE 0x10000 +/* For use with ASN1_mbstring_copy() */ +# define MBSTRING_FLAG 0x1000 +# define MBSTRING_UTF8 (MBSTRING_FLAG) +# define MBSTRING_ASC (MBSTRING_FLAG|1) +# define MBSTRING_BMP (MBSTRING_FLAG|2) +# define MBSTRING_UNIV (MBSTRING_FLAG|4) +# define SMIME_OLDMIME 0x400 +# define SMIME_CRLFEOL 0x800 +# define SMIME_STREAM 0x1000 + struct X509_algor_st; +DEFINE_STACK_OF(X509_ALGOR) + +# define ASN1_STRING_FLAG_BITS_LEFT 0x08/* Set if 0x07 has bits left value */ +/* + * This indicates that the ASN1_STRING is not a real value but just a place + * holder for the location where indefinite length constructed data should be + * inserted in the memory buffer + */ +# define ASN1_STRING_FLAG_NDEF 0x010 + +/* + * This flag is used by the CMS code to indicate that a string is not + * complete and is a place holder for content when it had all been accessed. + * The flag will be reset when content has been written to it. + */ + +# define ASN1_STRING_FLAG_CONT 0x020 +/* + * This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING + * type. + */ +# define ASN1_STRING_FLAG_MSTRING 0x040 +/* String is embedded and only content should be freed */ +# define ASN1_STRING_FLAG_EMBED 0x080 +/* This is the base type that holds just about everything :-) */ +struct asn1_string_st { + int length; + int type; + unsigned char *data; + /* + * The value of the following field depends on the type being held. It + * is mostly being used for BIT_STRING so if the input data has a + * non-zero 'unused bits' value, it will be handled correctly + */ + long flags; +}; + +/* + * ASN1_ENCODING structure: this is used to save the received encoding of an + * ASN1 type. This is useful to get round problems with invalid encodings + * which can break signatures. + */ + +typedef struct ASN1_ENCODING_st { + unsigned char *enc; /* DER encoding */ + long len; /* Length of encoding */ + int modified; /* set to 1 if 'enc' is invalid */ +} ASN1_ENCODING; + +/* Used with ASN1 LONG type: if a long is set to this it is omitted */ +# define ASN1_LONG_UNDEF 0x7fffffffL + +# define STABLE_FLAGS_MALLOC 0x01 +/* + * A zero passed to ASN1_STRING_TABLE_new_add for the flags is interpreted + * as "don't change" and STABLE_FLAGS_MALLOC is always set. By setting + * STABLE_FLAGS_MALLOC only we can clear the existing value. Use the alias + * STABLE_FLAGS_CLEAR to reflect this. + */ +# define STABLE_FLAGS_CLEAR STABLE_FLAGS_MALLOC +# define STABLE_NO_MASK 0x02 +# define DIRSTRING_TYPE \ + (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING) +# define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING) + +typedef struct asn1_string_table_st { + int nid; + long minsize; + long maxsize; + unsigned long mask; + unsigned long flags; +} ASN1_STRING_TABLE; + +DEFINE_STACK_OF(ASN1_STRING_TABLE) + +/* size limits: this stuff is taken straight from RFC2459 */ + +# define ub_name 32768 +# define ub_common_name 64 +# define ub_locality_name 128 +# define ub_state_name 128 +# define ub_organization_name 64 +# define ub_organization_unit_name 64 +# define ub_title 64 +# define ub_email_address 128 + +/* + * Declarations for template structures: for full definitions see asn1t.h + */ +typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE; +typedef struct ASN1_TLC_st ASN1_TLC; +/* This is just an opaque pointer */ +typedef struct ASN1_VALUE_st ASN1_VALUE; + +/* Declare ASN1 functions: the implement macro in in asn1t.h */ + +# define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type) + +# define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type) + +# define DECLARE_ASN1_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) + +# define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) + +# define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \ + type *d2i_##name(type **a, const unsigned char **in, long len); \ + int i2d_##name(type *a, unsigned char **out); \ + DECLARE_ASN1_ITEM(itname) + +# define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \ + type *d2i_##name(type **a, const unsigned char **in, long len); \ + int i2d_##name(const type *a, unsigned char **out); \ + DECLARE_ASN1_ITEM(name) + +# define DECLARE_ASN1_NDEF_FUNCTION(name) \ + int i2d_##name##_NDEF(name *a, unsigned char **out); + +# define DECLARE_ASN1_FUNCTIONS_const(name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS(name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name) + +# define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + type *name##_new(void); \ + void name##_free(type *a); + +# define DECLARE_ASN1_PRINT_FUNCTION(stname) \ + DECLARE_ASN1_PRINT_FUNCTION_fname(stname, stname) + +# define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \ + int fname##_print_ctx(BIO *out, stname *x, int indent, \ + const ASN1_PCTX *pctx); + +# define D2I_OF(type) type *(*)(type **,const unsigned char **,long) +# define I2D_OF(type) int (*)(type *,unsigned char **) +# define I2D_OF_const(type) int (*)(const type *,unsigned char **) + +# define CHECKED_D2I_OF(type, d2i) \ + ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0))) +# define CHECKED_I2D_OF(type, i2d) \ + ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0))) +# define CHECKED_NEW_OF(type, xnew) \ + ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0))) +# define CHECKED_PTR_OF(type, p) \ + ((void*) (1 ? p : (type*)0)) +# define CHECKED_PPTR_OF(type, p) \ + ((void**) (1 ? p : (type**)0)) + +# define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long) +# define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(type *,unsigned char **) +# define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type) + +TYPEDEF_D2I2D_OF(void); + +/*- + * The following macros and typedefs allow an ASN1_ITEM + * to be embedded in a structure and referenced. Since + * the ASN1_ITEM pointers need to be globally accessible + * (possibly from shared libraries) they may exist in + * different forms. On platforms that support it the + * ASN1_ITEM structure itself will be globally exported. + * Other platforms will export a function that returns + * an ASN1_ITEM pointer. + * + * To handle both cases transparently the macros below + * should be used instead of hard coding an ASN1_ITEM + * pointer in a structure. + * + * The structure will look like this: + * + * typedef struct SOMETHING_st { + * ... + * ASN1_ITEM_EXP *iptr; + * ... + * } SOMETHING; + * + * It would be initialised as e.g.: + * + * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...}; + * + * and the actual pointer extracted with: + * + * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr); + * + * Finally an ASN1_ITEM pointer can be extracted from an + * appropriate reference with: ASN1_ITEM_rptr(X509). This + * would be used when a function takes an ASN1_ITEM * argument. + * + */ + +# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* ASN1_ITEM pointer exported type */ +typedef const ASN1_ITEM ASN1_ITEM_EXP; + +/* Macro to obtain ASN1_ITEM pointer from exported type */ +# define ASN1_ITEM_ptr(iptr) (iptr) + +/* Macro to include ASN1_ITEM pointer from base type */ +# define ASN1_ITEM_ref(iptr) (&(iptr##_it)) + +# define ASN1_ITEM_rptr(ref) (&(ref##_it)) + +# define DECLARE_ASN1_ITEM(name) \ + OPENSSL_EXTERN const ASN1_ITEM name##_it; + +# else + +/* + * Platforms that can't easily handle shared global variables are declared as + * functions returning ASN1_ITEM pointers. + */ + +/* ASN1_ITEM pointer exported type */ +typedef const ASN1_ITEM *ASN1_ITEM_EXP (void); + +/* Macro to obtain ASN1_ITEM pointer from exported type */ +# define ASN1_ITEM_ptr(iptr) (iptr()) + +/* Macro to include ASN1_ITEM pointer from base type */ +# define ASN1_ITEM_ref(iptr) (iptr##_it) + +# define ASN1_ITEM_rptr(ref) (ref##_it()) + +# define DECLARE_ASN1_ITEM(name) \ + const ASN1_ITEM * name##_it(void); + +# endif + +/* Parameters used by ASN1_STRING_print_ex() */ + +/* + * These determine which characters to escape: RFC2253 special characters, + * control characters and MSB set characters + */ + +# define ASN1_STRFLGS_ESC_2253 1 +# define ASN1_STRFLGS_ESC_CTRL 2 +# define ASN1_STRFLGS_ESC_MSB 4 + +/* + * This flag determines how we do escaping: normally RC2253 backslash only, + * set this to use backslash and quote. + */ + +# define ASN1_STRFLGS_ESC_QUOTE 8 + +/* These three flags are internal use only. */ + +/* Character is a valid PrintableString character */ +# define CHARTYPE_PRINTABLESTRING 0x10 +/* Character needs escaping if it is the first character */ +# define CHARTYPE_FIRST_ESC_2253 0x20 +/* Character needs escaping if it is the last character */ +# define CHARTYPE_LAST_ESC_2253 0x40 + +/* + * NB the internal flags are safely reused below by flags handled at the top + * level. + */ + +/* + * If this is set we convert all character strings to UTF8 first + */ + +# define ASN1_STRFLGS_UTF8_CONVERT 0x10 + +/* + * If this is set we don't attempt to interpret content: just assume all + * strings are 1 byte per character. This will produce some pretty odd + * looking output! + */ + +# define ASN1_STRFLGS_IGNORE_TYPE 0x20 + +/* If this is set we include the string type in the output */ +# define ASN1_STRFLGS_SHOW_TYPE 0x40 + +/* + * This determines which strings to display and which to 'dump' (hex dump of + * content octets or DER encoding). We can only dump non character strings or + * everything. If we don't dump 'unknown' they are interpreted as character + * strings with 1 octet per character and are subject to the usual escaping + * options. + */ + +# define ASN1_STRFLGS_DUMP_ALL 0x80 +# define ASN1_STRFLGS_DUMP_UNKNOWN 0x100 + +/* + * These determine what 'dumping' does, we can dump the content octets or the + * DER encoding: both use the RFC2253 #XXXXX notation. + */ + +# define ASN1_STRFLGS_DUMP_DER 0x200 + +/* + * This flag specifies that RC2254 escaping shall be performed. + */ +#define ASN1_STRFLGS_ESC_2254 0x400 + +/* + * All the string flags consistent with RFC2253, escaping control characters + * isn't essential in RFC2253 but it is advisable anyway. + */ + +# define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \ + ASN1_STRFLGS_ESC_CTRL | \ + ASN1_STRFLGS_ESC_MSB | \ + ASN1_STRFLGS_UTF8_CONVERT | \ + ASN1_STRFLGS_DUMP_UNKNOWN | \ + ASN1_STRFLGS_DUMP_DER) + +DEFINE_STACK_OF(ASN1_INTEGER) + +DEFINE_STACK_OF(ASN1_GENERALSTRING) + +DEFINE_STACK_OF(ASN1_UTF8STRING) + +typedef struct asn1_type_st { + int type; + union { + char *ptr; + ASN1_BOOLEAN boolean; + ASN1_STRING *asn1_string; + ASN1_OBJECT *object; + ASN1_INTEGER *integer; + ASN1_ENUMERATED *enumerated; + ASN1_BIT_STRING *bit_string; + ASN1_OCTET_STRING *octet_string; + ASN1_PRINTABLESTRING *printablestring; + ASN1_T61STRING *t61string; + ASN1_IA5STRING *ia5string; + ASN1_GENERALSTRING *generalstring; + ASN1_BMPSTRING *bmpstring; + ASN1_UNIVERSALSTRING *universalstring; + ASN1_UTCTIME *utctime; + ASN1_GENERALIZEDTIME *generalizedtime; + ASN1_VISIBLESTRING *visiblestring; + ASN1_UTF8STRING *utf8string; + /* + * set and sequence are left complete and still contain the set or + * sequence bytes + */ + ASN1_STRING *set; + ASN1_STRING *sequence; + ASN1_VALUE *asn1_value; + } value; +} ASN1_TYPE; + +DEFINE_STACK_OF(ASN1_TYPE) + +typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY; + +DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY) +DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SET_ANY) + +/* This is used to contain a list of bit names */ +typedef struct BIT_STRING_BITNAME_st { + int bitnum; + const char *lname; + const char *sname; +} BIT_STRING_BITNAME; + +# define B_ASN1_TIME \ + B_ASN1_UTCTIME | \ + B_ASN1_GENERALIZEDTIME + +# define B_ASN1_PRINTABLE \ + B_ASN1_NUMERICSTRING| \ + B_ASN1_PRINTABLESTRING| \ + B_ASN1_T61STRING| \ + B_ASN1_IA5STRING| \ + B_ASN1_BIT_STRING| \ + B_ASN1_UNIVERSALSTRING|\ + B_ASN1_BMPSTRING|\ + B_ASN1_UTF8STRING|\ + B_ASN1_SEQUENCE|\ + B_ASN1_UNKNOWN + +# define B_ASN1_DIRECTORYSTRING \ + B_ASN1_PRINTABLESTRING| \ + B_ASN1_TELETEXSTRING|\ + B_ASN1_BMPSTRING|\ + B_ASN1_UNIVERSALSTRING|\ + B_ASN1_UTF8STRING + +# define B_ASN1_DISPLAYTEXT \ + B_ASN1_IA5STRING| \ + B_ASN1_VISIBLESTRING| \ + B_ASN1_BMPSTRING|\ + B_ASN1_UTF8STRING + +DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) + +int ASN1_TYPE_get(const ASN1_TYPE *a); +void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value); +int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value); +int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b); + +ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t); +void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t); + +ASN1_OBJECT *ASN1_OBJECT_new(void); +void ASN1_OBJECT_free(ASN1_OBJECT *a); +int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp); +ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, + long length); + +DECLARE_ASN1_ITEM(ASN1_OBJECT) + +DEFINE_STACK_OF(ASN1_OBJECT) + +ASN1_STRING *ASN1_STRING_new(void); +void ASN1_STRING_free(ASN1_STRING *a); +void ASN1_STRING_clear_free(ASN1_STRING *a); +int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str); +ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *a); +ASN1_STRING *ASN1_STRING_type_new(int type); +int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b); + /* + * Since this is used to store all sorts of things, via macros, for now, + * make its data void * + */ +int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); +void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len); +int ASN1_STRING_length(const ASN1_STRING *x); +void ASN1_STRING_length_set(ASN1_STRING *x, int n); +int ASN1_STRING_type(const ASN1_STRING *x); +DEPRECATEDIN_1_1_0(unsigned char *ASN1_STRING_data(ASN1_STRING *x)) +const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x); + +DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING) +int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length); +int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value); +int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n); +int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, + const unsigned char *flags, int flags_len); + +int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, + BIT_STRING_BITNAME *tbl, int indent); +int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl); +int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value, + BIT_STRING_BITNAME *tbl); + +DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) +ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, + long length); +ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x); +int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y); + +DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED) + +int ASN1_UTCTIME_check(const ASN1_UTCTIME *a); +ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t); +ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, + int offset_day, long offset_sec); +int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str); +int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); + +int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a); +ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, + time_t t); +ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, + time_t t, int offset_day, + long offset_sec); +int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str); +int ASN1_TIME_diff(int *pday, int *psec, + const ASN1_TIME *from, const ASN1_TIME *to); + +DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING) +ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *a); +int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, + const ASN1_OCTET_STRING *b); +int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, + int len); + +DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) +DECLARE_ASN1_FUNCTIONS(ASN1_NULL) +DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) + +int UTF8_getc(const unsigned char *str, int len, unsigned long *val); +int UTF8_putc(unsigned char *str, int len, unsigned long value); + +DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) + +DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) +DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) +DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING) +DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING) +DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME) +DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) +DECLARE_ASN1_FUNCTIONS(ASN1_TIME) + +DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF) + +ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t); +ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, + int offset_day, long offset_sec); +int ASN1_TIME_check(const ASN1_TIME *t); +ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME + **out); +int ASN1_TIME_set_string(ASN1_TIME *s, const char *str); + +int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a); +int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size); +int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a); +int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size); +int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a); +int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size); +int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type); +int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a); + +int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num); +ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, + const char *sn, const char *ln); + +int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a); +int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r); +int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a); +int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r); + +int ASN1_INTEGER_set(ASN1_INTEGER *a, long v); +long ASN1_INTEGER_get(const ASN1_INTEGER *a); +ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai); +BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn); + +int ASN1_ENUMERATED_get_int64(int64_t *pr, const ASN1_ENUMERATED *a); +int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t r); + + +int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); +long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a); +ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai); +BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn); + +/* General */ +/* given a string, return the correct type, max is the maximum length */ +int ASN1_PRINTABLE_type(const unsigned char *s, int max); + +unsigned long ASN1_tag2bit(int tag); + +/* SPECIALS */ +int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, + int *pclass, long omax); +int ASN1_check_infinite_end(unsigned char **p, long len); +int ASN1_const_check_infinite_end(const unsigned char **p, long len); +void ASN1_put_object(unsigned char **pp, int constructed, int length, + int tag, int xclass); +int ASN1_put_eoc(unsigned char **pp); +int ASN1_object_size(int constructed, int length, int tag); + +/* Used to implement other functions */ +void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x); + +# define ASN1_dup_of(type,i2d,d2i,x) \ + ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \ + CHECKED_D2I_OF(type, d2i), \ + CHECKED_PTR_OF(type, x))) + +# define ASN1_dup_of_const(type,i2d,d2i,x) \ + ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \ + CHECKED_D2I_OF(type, d2i), \ + CHECKED_PTR_OF(const type, x))) + +void *ASN1_item_dup(const ASN1_ITEM *it, void *x); + +/* ASN1 alloc/free macros for when a type is only used internally */ + +# define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type)) +# define M_ASN1_free_of(x, type) \ + ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type)) + +# ifndef OPENSSL_NO_STDIO +void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x); + +# define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \ + ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \ + CHECKED_D2I_OF(type, d2i), \ + in, \ + CHECKED_PPTR_OF(type, x))) + +void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x); +int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x); + +# define ASN1_i2d_fp_of(type,i2d,out,x) \ + (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \ + out, \ + CHECKED_PTR_OF(type, x))) + +# define ASN1_i2d_fp_of_const(type,i2d,out,x) \ + (ASN1_i2d_fp(CHECKED_I2D_OF(const type, i2d), \ + out, \ + CHECKED_PTR_OF(const type, x))) + +int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x); +int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags); +# endif + +int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in); + +void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x); + +# define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \ + ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \ + CHECKED_D2I_OF(type, d2i), \ + in, \ + CHECKED_PPTR_OF(type, x))) + +void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x); +int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x); + +# define ASN1_i2d_bio_of(type,i2d,out,x) \ + (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \ + out, \ + CHECKED_PTR_OF(type, x))) + +# define ASN1_i2d_bio_of_const(type,i2d,out,x) \ + (ASN1_i2d_bio(CHECKED_I2D_OF(const type, i2d), \ + out, \ + CHECKED_PTR_OF(const type, x))) + +int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x); +int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a); +int ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a); +int ASN1_TIME_print(BIO *fp, const ASN1_TIME *a); +int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v); +int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags); +int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int off); +int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, + unsigned char *buf, int off); +int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent); +int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, + int dump); +const char *ASN1_tag2str(int tag); + +/* Used to load and write Netscape format cert */ + +int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s); + +int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len); +int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len); +int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, + unsigned char *data, int len); +int ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *a, long *num, + unsigned char *data, int max_len); + +void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it); + +ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, + ASN1_OCTET_STRING **oct); + +void ASN1_STRING_set_default_mask(unsigned long mask); +int ASN1_STRING_set_default_mask_asc(const char *p); +unsigned long ASN1_STRING_get_default_mask(void); +int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, + int inform, unsigned long mask); +int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, + int inform, unsigned long mask, + long minsize, long maxsize); + +ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, + const unsigned char *in, int inlen, + int inform, int nid); +ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid); +int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long); +void ASN1_STRING_TABLE_cleanup(void); + +/* ASN1 template functions */ + +/* Old API compatible functions */ +ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); +void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); +ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in, + long len, const ASN1_ITEM *it); +int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); +int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, + const ASN1_ITEM *it); + +void ASN1_add_oid_module(void); +void ASN1_add_stable_module(void); + +ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf); +ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf); +int ASN1_str2mask(const char *str, unsigned long *pmask); + +/* ASN1 Print flags */ + +/* Indicate missing OPTIONAL fields */ +# define ASN1_PCTX_FLAGS_SHOW_ABSENT 0x001 +/* Mark start and end of SEQUENCE */ +# define ASN1_PCTX_FLAGS_SHOW_SEQUENCE 0x002 +/* Mark start and end of SEQUENCE/SET OF */ +# define ASN1_PCTX_FLAGS_SHOW_SSOF 0x004 +/* Show the ASN1 type of primitives */ +# define ASN1_PCTX_FLAGS_SHOW_TYPE 0x008 +/* Don't show ASN1 type of ANY */ +# define ASN1_PCTX_FLAGS_NO_ANY_TYPE 0x010 +/* Don't show ASN1 type of MSTRINGs */ +# define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE 0x020 +/* Don't show field names in SEQUENCE */ +# define ASN1_PCTX_FLAGS_NO_FIELD_NAME 0x040 +/* Show structure names of each SEQUENCE field */ +# define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME 0x080 +/* Don't show structure name even at top level */ +# define ASN1_PCTX_FLAGS_NO_STRUCT_NAME 0x100 + +int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, + const ASN1_ITEM *it, const ASN1_PCTX *pctx); +ASN1_PCTX *ASN1_PCTX_new(void); +void ASN1_PCTX_free(ASN1_PCTX *p); +unsigned long ASN1_PCTX_get_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags); +unsigned long ASN1_PCTX_get_nm_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags); +unsigned long ASN1_PCTX_get_cert_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags); +unsigned long ASN1_PCTX_get_oid_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags); +unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags); + +ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx)); +void ASN1_SCTX_free(ASN1_SCTX *p); +const ASN1_ITEM *ASN1_SCTX_get_item(ASN1_SCTX *p); +const ASN1_TEMPLATE *ASN1_SCTX_get_template(ASN1_SCTX *p); +unsigned long ASN1_SCTX_get_flags(ASN1_SCTX *p); +void ASN1_SCTX_set_app_data(ASN1_SCTX *p, void *data); +void *ASN1_SCTX_get_app_data(ASN1_SCTX *p); + +const BIO_METHOD *BIO_f_asn1(void); + +BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it); + +int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, + const ASN1_ITEM *it); +int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, + const char *hdr, const ASN1_ITEM *it); +int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, + int ctype_nid, int econt_nid, + STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it); +ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it); +int SMIME_crlf_copy(BIO *in, BIO *out, int flags); +int SMIME_text(BIO *in, BIO *out); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_ASN1_strings(void); + +/* Error codes for the ASN1 functions. */ + +/* Function codes. */ +# define ASN1_F_A2D_ASN1_OBJECT 100 +# define ASN1_F_A2I_ASN1_INTEGER 102 +# define ASN1_F_A2I_ASN1_STRING 103 +# define ASN1_F_APPEND_EXP 176 +# define ASN1_F_ASN1_BIT_STRING_SET_BIT 183 +# define ASN1_F_ASN1_CB 177 +# define ASN1_F_ASN1_CHECK_TLEN 104 +# define ASN1_F_ASN1_COLLECT 106 +# define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108 +# define ASN1_F_ASN1_D2I_FP 109 +# define ASN1_F_ASN1_D2I_READ_BIO 107 +# define ASN1_F_ASN1_DIGEST 184 +# define ASN1_F_ASN1_DO_ADB 110 +# define ASN1_F_ASN1_DO_LOCK 233 +# define ASN1_F_ASN1_DUP 111 +# define ASN1_F_ASN1_EX_C2I 204 +# define ASN1_F_ASN1_FIND_END 190 +# define ASN1_F_ASN1_GENERALIZEDTIME_ADJ 216 +# define ASN1_F_ASN1_GENERATE_V3 178 +# define ASN1_F_ASN1_GET_INT64 224 +# define ASN1_F_ASN1_GET_OBJECT 114 +# define ASN1_F_ASN1_GET_UINT64 225 +# define ASN1_F_ASN1_I2D_BIO 116 +# define ASN1_F_ASN1_I2D_FP 117 +# define ASN1_F_ASN1_ITEM_D2I_FP 206 +# define ASN1_F_ASN1_ITEM_DUP 191 +# define ASN1_F_ASN1_ITEM_EMBED_D2I 120 +# define ASN1_F_ASN1_ITEM_EMBED_NEW 121 +# define ASN1_F_ASN1_ITEM_I2D_BIO 192 +# define ASN1_F_ASN1_ITEM_I2D_FP 193 +# define ASN1_F_ASN1_ITEM_PACK 198 +# define ASN1_F_ASN1_ITEM_SIGN 195 +# define ASN1_F_ASN1_ITEM_SIGN_CTX 220 +# define ASN1_F_ASN1_ITEM_UNPACK 199 +# define ASN1_F_ASN1_ITEM_VERIFY 197 +# define ASN1_F_ASN1_MBSTRING_NCOPY 122 +# define ASN1_F_ASN1_OBJECT_NEW 123 +# define ASN1_F_ASN1_OUTPUT_DATA 214 +# define ASN1_F_ASN1_PCTX_NEW 205 +# define ASN1_F_ASN1_SCTX_NEW 221 +# define ASN1_F_ASN1_SIGN 128 +# define ASN1_F_ASN1_STR2TYPE 179 +# define ASN1_F_ASN1_STRING_GET_INT64 227 +# define ASN1_F_ASN1_STRING_GET_UINT64 230 +# define ASN1_F_ASN1_STRING_SET 186 +# define ASN1_F_ASN1_STRING_TABLE_ADD 129 +# define ASN1_F_ASN1_STRING_TO_BN 228 +# define ASN1_F_ASN1_STRING_TYPE_NEW 130 +# define ASN1_F_ASN1_TEMPLATE_EX_D2I 132 +# define ASN1_F_ASN1_TEMPLATE_NEW 133 +# define ASN1_F_ASN1_TEMPLATE_NOEXP_D2I 131 +# define ASN1_F_ASN1_TIME_ADJ 217 +# define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134 +# define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135 +# define ASN1_F_ASN1_UTCTIME_ADJ 218 +# define ASN1_F_ASN1_VERIFY 137 +# define ASN1_F_B64_READ_ASN1 209 +# define ASN1_F_B64_WRITE_ASN1 210 +# define ASN1_F_BIO_NEW_NDEF 208 +# define ASN1_F_BITSTR_CB 180 +# define ASN1_F_BN_TO_ASN1_STRING 229 +# define ASN1_F_C2I_ASN1_BIT_STRING 189 +# define ASN1_F_C2I_ASN1_INTEGER 194 +# define ASN1_F_C2I_ASN1_OBJECT 196 +# define ASN1_F_C2I_IBUF 226 +# define ASN1_F_COLLECT_DATA 140 +# define ASN1_F_D2I_ASN1_OBJECT 147 +# define ASN1_F_D2I_ASN1_UINTEGER 150 +# define ASN1_F_D2I_AUTOPRIVATEKEY 207 +# define ASN1_F_D2I_PRIVATEKEY 154 +# define ASN1_F_D2I_PUBLICKEY 155 +# define ASN1_F_DO_TCREATE 222 +# define ASN1_F_I2D_ASN1_BIO_STREAM 211 +# define ASN1_F_I2D_DSA_PUBKEY 161 +# define ASN1_F_I2D_EC_PUBKEY 181 +# define ASN1_F_I2D_PRIVATEKEY 163 +# define ASN1_F_I2D_PUBLICKEY 164 +# define ASN1_F_I2D_RSA_PUBKEY 165 +# define ASN1_F_LONG_C2I 166 +# define ASN1_F_OID_MODULE_INIT 174 +# define ASN1_F_PARSE_TAGGING 182 +# define ASN1_F_PKCS5_PBE2_SET_IV 167 +# define ASN1_F_PKCS5_PBE2_SET_SCRYPT 231 +# define ASN1_F_PKCS5_PBE_SET 202 +# define ASN1_F_PKCS5_PBE_SET0_ALGOR 215 +# define ASN1_F_PKCS5_PBKDF2_SET 219 +# define ASN1_F_PKCS5_SCRYPT_SET 232 +# define ASN1_F_SMIME_READ_ASN1 212 +# define ASN1_F_SMIME_TEXT 213 +# define ASN1_F_STBL_MODULE_INIT 223 +# define ASN1_F_X509_CRL_ADD0_REVOKED 169 +# define ASN1_F_X509_INFO_NEW 170 +# define ASN1_F_X509_NAME_ENCODE 203 +# define ASN1_F_X509_NAME_EX_D2I 158 +# define ASN1_F_X509_NAME_EX_NEW 171 +# define ASN1_F_X509_PKEY_NEW 173 + +/* Reason codes. */ +# define ASN1_R_ADDING_OBJECT 171 +# define ASN1_R_ASN1_PARSE_ERROR 203 +# define ASN1_R_ASN1_SIG_PARSE_ERROR 204 +# define ASN1_R_AUX_ERROR 100 +# define ASN1_R_BAD_OBJECT_HEADER 102 +# define ASN1_R_BMPSTRING_IS_WRONG_LENGTH 214 +# define ASN1_R_BN_LIB 105 +# define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106 +# define ASN1_R_BUFFER_TOO_SMALL 107 +# define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 108 +# define ASN1_R_CONTEXT_NOT_INITIALISED 217 +# define ASN1_R_DATA_IS_WRONG 109 +# define ASN1_R_DECODE_ERROR 110 +# define ASN1_R_DEPTH_EXCEEDED 174 +# define ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED 198 +# define ASN1_R_ENCODE_ERROR 112 +# define ASN1_R_ERROR_GETTING_TIME 173 +# define ASN1_R_ERROR_LOADING_SECTION 172 +# define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114 +# define ASN1_R_EXPECTING_AN_INTEGER 115 +# define ASN1_R_EXPECTING_AN_OBJECT 116 +# define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119 +# define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120 +# define ASN1_R_FIELD_MISSING 121 +# define ASN1_R_FIRST_NUM_TOO_LARGE 122 +# define ASN1_R_HEADER_TOO_LONG 123 +# define ASN1_R_ILLEGAL_BITSTRING_FORMAT 175 +# define ASN1_R_ILLEGAL_BOOLEAN 176 +# define ASN1_R_ILLEGAL_CHARACTERS 124 +# define ASN1_R_ILLEGAL_FORMAT 177 +# define ASN1_R_ILLEGAL_HEX 178 +# define ASN1_R_ILLEGAL_IMPLICIT_TAG 179 +# define ASN1_R_ILLEGAL_INTEGER 180 +# define ASN1_R_ILLEGAL_NEGATIVE_VALUE 226 +# define ASN1_R_ILLEGAL_NESTED_TAGGING 181 +# define ASN1_R_ILLEGAL_NULL 125 +# define ASN1_R_ILLEGAL_NULL_VALUE 182 +# define ASN1_R_ILLEGAL_OBJECT 183 +# define ASN1_R_ILLEGAL_OPTIONAL_ANY 126 +# define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170 +# define ASN1_R_ILLEGAL_PADDING 221 +# define ASN1_R_ILLEGAL_TAGGED_ANY 127 +# define ASN1_R_ILLEGAL_TIME_VALUE 184 +# define ASN1_R_ILLEGAL_ZERO_CONTENT 222 +# define ASN1_R_INTEGER_NOT_ASCII_FORMAT 185 +# define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128 +# define ASN1_R_INVALID_BIT_STRING_BITS_LEFT 220 +# define ASN1_R_INVALID_BMPSTRING_LENGTH 129 +# define ASN1_R_INVALID_DIGIT 130 +# define ASN1_R_INVALID_MIME_TYPE 205 +# define ASN1_R_INVALID_MODIFIER 186 +# define ASN1_R_INVALID_NUMBER 187 +# define ASN1_R_INVALID_OBJECT_ENCODING 216 +# define ASN1_R_INVALID_SCRYPT_PARAMETERS 227 +# define ASN1_R_INVALID_SEPARATOR 131 +# define ASN1_R_INVALID_STRING_TABLE_VALUE 218 +# define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133 +# define ASN1_R_INVALID_UTF8STRING 134 +# define ASN1_R_INVALID_VALUE 219 +# define ASN1_R_LIST_ERROR 188 +# define ASN1_R_MIME_NO_CONTENT_TYPE 206 +# define ASN1_R_MIME_PARSE_ERROR 207 +# define ASN1_R_MIME_SIG_PARSE_ERROR 208 +# define ASN1_R_MISSING_EOC 137 +# define ASN1_R_MISSING_SECOND_NUMBER 138 +# define ASN1_R_MISSING_VALUE 189 +# define ASN1_R_MSTRING_NOT_UNIVERSAL 139 +# define ASN1_R_MSTRING_WRONG_TAG 140 +# define ASN1_R_NESTED_ASN1_STRING 197 +# define ASN1_R_NON_HEX_CHARACTERS 141 +# define ASN1_R_NOT_ASCII_FORMAT 190 +# define ASN1_R_NOT_ENOUGH_DATA 142 +# define ASN1_R_NO_CONTENT_TYPE 209 +# define ASN1_R_NO_MATCHING_CHOICE_TYPE 143 +# define ASN1_R_NO_MULTIPART_BODY_FAILURE 210 +# define ASN1_R_NO_MULTIPART_BOUNDARY 211 +# define ASN1_R_NO_SIG_CONTENT_TYPE 212 +# define ASN1_R_NULL_IS_WRONG_LENGTH 144 +# define ASN1_R_OBJECT_NOT_ASCII_FORMAT 191 +# define ASN1_R_ODD_NUMBER_OF_CHARS 145 +# define ASN1_R_SECOND_NUMBER_TOO_LARGE 147 +# define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148 +# define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149 +# define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG 192 +# define ASN1_R_SHORT_LINE 150 +# define ASN1_R_SIG_INVALID_MIME_TYPE 213 +# define ASN1_R_STREAMING_NOT_SUPPORTED 202 +# define ASN1_R_STRING_TOO_LONG 151 +# define ASN1_R_STRING_TOO_SHORT 152 +# define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154 +# define ASN1_R_TIME_NOT_ASCII_FORMAT 193 +# define ASN1_R_TOO_LARGE 223 +# define ASN1_R_TOO_LONG 155 +# define ASN1_R_TOO_SMALL 224 +# define ASN1_R_TYPE_NOT_CONSTRUCTED 156 +# define ASN1_R_TYPE_NOT_PRIMITIVE 195 +# define ASN1_R_UNEXPECTED_EOC 159 +# define ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH 215 +# define ASN1_R_UNKNOWN_FORMAT 160 +# define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161 +# define ASN1_R_UNKNOWN_OBJECT_TYPE 162 +# define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163 +# define ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM 199 +# define ASN1_R_UNKNOWN_TAG 194 +# define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164 +# define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167 +# define ASN1_R_UNSUPPORTED_TYPE 196 +# define ASN1_R_WRONG_INTEGER_TYPE 225 +# define ASN1_R_WRONG_PUBLIC_KEY_TYPE 200 +# define ASN1_R_WRONG_TAG 168 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/asn1_mac.h b/android/x86/include/openssl/asn1_mac.h new file mode 100644 index 00000000..7ac1782a --- /dev/null +++ b/android/x86/include/openssl/asn1_mac.h @@ -0,0 +1,10 @@ +/* + * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#error "This file is obsolete; please update your software." diff --git a/android/x86/include/openssl/asn1t.h b/android/x86/include/openssl/asn1t.h new file mode 100644 index 00000000..8eedfb3f --- /dev/null +++ b/android/x86/include/openssl/asn1t.h @@ -0,0 +1,924 @@ +/* + * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ASN1T_H +# define HEADER_ASN1T_H + +# include <stddef.h> +# include <openssl/e_os2.h> +# include <openssl/asn1.h> + +# ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +# endif + +/* ASN1 template defines, structures and functions */ + +#ifdef __cplusplus +extern "C" { +#endif + +# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ +# define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr)) + +/* Macros for start and end of ASN1_ITEM definition */ + +# define ASN1_ITEM_start(itname) \ + OPENSSL_GLOBAL const ASN1_ITEM itname##_it = { + +# define static_ASN1_ITEM_start(itname) \ + static const ASN1_ITEM itname##_it = { + +# define ASN1_ITEM_end(itname) \ + }; + +# else + +/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ +# define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr())) + +/* Macros for start and end of ASN1_ITEM definition */ + +# define ASN1_ITEM_start(itname) \ + const ASN1_ITEM * itname##_it(void) \ + { \ + static const ASN1_ITEM local_it = { + +# define static_ASN1_ITEM_start(itname) \ + static ASN1_ITEM_start(itname) + +# define ASN1_ITEM_end(itname) \ + }; \ + return &local_it; \ + } + +# endif + +/* Macros to aid ASN1 template writing */ + +# define ASN1_ITEM_TEMPLATE(tname) \ + static const ASN1_TEMPLATE tname##_item_tt + +# define ASN1_ITEM_TEMPLATE_END(tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_PRIMITIVE,\ + -1,\ + &tname##_item_tt,\ + 0,\ + NULL,\ + 0,\ + #tname \ + ASN1_ITEM_end(tname) +# define static_ASN1_ITEM_TEMPLATE_END(tname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_PRIMITIVE,\ + -1,\ + &tname##_item_tt,\ + 0,\ + NULL,\ + 0,\ + #tname \ + ASN1_ITEM_end(tname) + +/* This is a ASN1 type which just embeds a template */ + +/*- + * This pair helps declare a SEQUENCE. We can do: + * + * ASN1_SEQUENCE(stname) = { + * ... SEQUENCE components ... + * } ASN1_SEQUENCE_END(stname) + * + * This will produce an ASN1_ITEM called stname_it + * for a structure called stname. + * + * If you want the same structure but a different + * name then use: + * + * ASN1_SEQUENCE(itname) = { + * ... SEQUENCE components ... + * } ASN1_SEQUENCE_END_name(stname, itname) + * + * This will create an item called itname_it using + * a structure called stname. + */ + +# define ASN1_SEQUENCE(tname) \ + static const ASN1_TEMPLATE tname##_seq_tt[] + +# define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) + +# define static_ASN1_SEQUENCE_END(stname) static_ASN1_SEQUENCE_END_name(stname, stname) + +# define ASN1_SEQUENCE_END_name(stname, tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +# define static_ASN1_SEQUENCE_END_name(stname, tname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +# define ASN1_NDEF_SEQUENCE(tname) \ + ASN1_SEQUENCE(tname) + +# define ASN1_NDEF_SEQUENCE_cb(tname, cb) \ + ASN1_SEQUENCE_cb(tname, cb) + +# define ASN1_SEQUENCE_cb(tname, cb) \ + static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ + ASN1_SEQUENCE(tname) + +# define ASN1_BROKEN_SEQUENCE(tname) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ + ASN1_SEQUENCE(tname) + +# define ASN1_SEQUENCE_ref(tname, cb) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), offsetof(tname, lock), cb, 0}; \ + ASN1_SEQUENCE(tname) + +# define ASN1_SEQUENCE_enc(tname, enc, cb) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ + ASN1_SEQUENCE(tname) + +# define ASN1_NDEF_SEQUENCE_END(tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(tname),\ + #tname \ + ASN1_ITEM_end(tname) +# define static_ASN1_NDEF_SEQUENCE_END(tname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(tname),\ + #tname \ + ASN1_ITEM_end(tname) + +# define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) +# define static_ASN1_BROKEN_SEQUENCE_END(stname) \ + static_ASN1_SEQUENCE_END_ref(stname, stname) + +# define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) + +# define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) +# define static_ASN1_SEQUENCE_END_cb(stname, tname) static_ASN1_SEQUENCE_END_ref(stname, tname) + +# define ASN1_SEQUENCE_END_ref(stname, tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) +# define static_ASN1_SEQUENCE_END_ref(stname, tname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +# define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +/*- + * This pair helps declare a CHOICE type. We can do: + * + * ASN1_CHOICE(chname) = { + * ... CHOICE options ... + * ASN1_CHOICE_END(chname) + * + * This will produce an ASN1_ITEM called chname_it + * for a structure called chname. The structure + * definition must look like this: + * typedef struct { + * int type; + * union { + * ASN1_SOMETHING *opt1; + * ASN1_SOMEOTHER *opt2; + * } value; + * } chname; + * + * the name of the selector must be 'type'. + * to use an alternative selector name use the + * ASN1_CHOICE_END_selector() version. + */ + +# define ASN1_CHOICE(tname) \ + static const ASN1_TEMPLATE tname##_ch_tt[] + +# define ASN1_CHOICE_cb(tname, cb) \ + static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ + ASN1_CHOICE(tname) + +# define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) + +# define static_ASN1_CHOICE_END(stname) static_ASN1_CHOICE_END_name(stname, stname) + +# define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) + +# define static_ASN1_CHOICE_END_name(stname, tname) static_ASN1_CHOICE_END_selector(stname, tname, type) + +# define ASN1_CHOICE_END_selector(stname, tname, selname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE,\ + offsetof(stname,selname) ,\ + tname##_ch_tt,\ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +# define static_ASN1_CHOICE_END_selector(stname, tname, selname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE,\ + offsetof(stname,selname) ,\ + tname##_ch_tt,\ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +# define ASN1_CHOICE_END_cb(stname, tname, selname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE,\ + offsetof(stname,selname) ,\ + tname##_ch_tt,\ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +/* This helps with the template wrapper form of ASN1_ITEM */ + +# define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ + (flags), (tag), 0,\ + #name, ASN1_ITEM_ref(type) } + +/* These help with SEQUENCE or CHOICE components */ + +/* used to declare other types */ + +# define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ + (flags), (tag), offsetof(stname, field),\ + #field, ASN1_ITEM_ref(type) } + +/* implicit and explicit helper macros */ + +# define ASN1_IMP_EX(stname, field, type, tag, ex) \ + ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type) + +# define ASN1_EXP_EX(stname, field, type, tag, ex) \ + ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type) + +/* Any defined by macros: the field used is in the table itself */ + +# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION +# define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } +# define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } +# else +# define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb } +# define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb } +# endif +/* Plain simple type */ +# define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type) +/* Embedded simple type */ +# define ASN1_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_EMBED,0, stname, field, type) + +/* OPTIONAL simple type */ +# define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) + +/* IMPLICIT tagged simple type */ +# define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) + +/* IMPLICIT tagged OPTIONAL simple type */ +# define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) + +/* Same as above but EXPLICIT */ + +# define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) +# define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) + +/* SEQUENCE OF type */ +# define ASN1_SEQUENCE_OF(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) + +/* OPTIONAL SEQUENCE OF */ +# define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) + +/* Same as above but for SET OF */ + +# define ASN1_SET_OF(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) + +# define ASN1_SET_OF_OPT(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) + +/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */ + +# define ASN1_IMP_SET_OF(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) + +# define ASN1_EXP_SET_OF(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) + +# define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) + +# define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) + +# define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) + +# define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) + +# define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) + +# define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) + +/* EXPLICIT using indefinite length constructed form */ +# define ASN1_NDEF_EXP(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF) + +/* EXPLICIT OPTIONAL using indefinite length constructed form */ +# define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF) + +/* Macros for the ASN1_ADB structure */ + +# define ASN1_ADB(name) \ + static const ASN1_ADB_TABLE name##_adbtbl[] + +# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION + +# define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \ + ;\ + static const ASN1_ADB name##_adb = {\ + flags,\ + offsetof(name, field),\ + adb_cb,\ + name##_adbtbl,\ + sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ + def,\ + none\ + } + +# else + +# define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \ + ;\ + static const ASN1_ITEM *name##_adb(void) \ + { \ + static const ASN1_ADB internal_adb = \ + {\ + flags,\ + offsetof(name, field),\ + adb_cb,\ + name##_adbtbl,\ + sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ + def,\ + none\ + }; \ + return (const ASN1_ITEM *) &internal_adb; \ + } \ + void dummy_function(void) + +# endif + +# define ADB_ENTRY(val, template) {val, template} + +# define ASN1_ADB_TEMPLATE(name) \ + static const ASN1_TEMPLATE name##_tt + +/* + * This is the ASN1 template structure that defines a wrapper round the + * actual type. It determines the actual position of the field in the value + * structure, various flags such as OPTIONAL and the field name. + */ + +struct ASN1_TEMPLATE_st { + unsigned long flags; /* Various flags */ + long tag; /* tag, not used if no tagging */ + unsigned long offset; /* Offset of this field in structure */ + const char *field_name; /* Field name */ + ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ +}; + +/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */ + +# define ASN1_TEMPLATE_item(t) (t->item_ptr) +# define ASN1_TEMPLATE_adb(t) (t->item_ptr) + +typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE; +typedef struct ASN1_ADB_st ASN1_ADB; + +struct ASN1_ADB_st { + unsigned long flags; /* Various flags */ + unsigned long offset; /* Offset of selector field */ + int (*adb_cb)(long *psel); /* Application callback */ + const ASN1_ADB_TABLE *tbl; /* Table of possible types */ + long tblcount; /* Number of entries in tbl */ + const ASN1_TEMPLATE *default_tt; /* Type to use if no match */ + const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */ +}; + +struct ASN1_ADB_TABLE_st { + long value; /* NID for an object or value for an int */ + const ASN1_TEMPLATE tt; /* item for this value */ +}; + +/* template flags */ + +/* Field is optional */ +# define ASN1_TFLG_OPTIONAL (0x1) + +/* Field is a SET OF */ +# define ASN1_TFLG_SET_OF (0x1 << 1) + +/* Field is a SEQUENCE OF */ +# define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) + +/* + * Special case: this refers to a SET OF that will be sorted into DER order + * when encoded *and* the corresponding STACK will be modified to match the + * new order. + */ +# define ASN1_TFLG_SET_ORDER (0x3 << 1) + +/* Mask for SET OF or SEQUENCE OF */ +# define ASN1_TFLG_SK_MASK (0x3 << 1) + +/* + * These flags mean the tag should be taken from the tag field. If EXPLICIT + * then the underlying type is used for the inner tag. + */ + +/* IMPLICIT tagging */ +# define ASN1_TFLG_IMPTAG (0x1 << 3) + +/* EXPLICIT tagging, inner tag from underlying type */ +# define ASN1_TFLG_EXPTAG (0x2 << 3) + +# define ASN1_TFLG_TAG_MASK (0x3 << 3) + +/* context specific IMPLICIT */ +# define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT + +/* context specific EXPLICIT */ +# define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT + +/* + * If tagging is in force these determine the type of tag to use. Otherwise + * the tag is determined by the underlying type. These values reflect the + * actual octet format. + */ + +/* Universal tag */ +# define ASN1_TFLG_UNIVERSAL (0x0<<6) +/* Application tag */ +# define ASN1_TFLG_APPLICATION (0x1<<6) +/* Context specific tag */ +# define ASN1_TFLG_CONTEXT (0x2<<6) +/* Private tag */ +# define ASN1_TFLG_PRIVATE (0x3<<6) + +# define ASN1_TFLG_TAG_CLASS (0x3<<6) + +/* + * These are for ANY DEFINED BY type. In this case the 'item' field points to + * an ASN1_ADB structure which contains a table of values to decode the + * relevant type + */ + +# define ASN1_TFLG_ADB_MASK (0x3<<8) + +# define ASN1_TFLG_ADB_OID (0x1<<8) + +# define ASN1_TFLG_ADB_INT (0x1<<9) + +/* + * This flag when present in a SEQUENCE OF, SET OF or EXPLICIT causes + * indefinite length constructed encoding to be used if required. + */ + +# define ASN1_TFLG_NDEF (0x1<<11) + +/* Field is embedded and not a pointer */ +# define ASN1_TFLG_EMBED (0x1 << 12) + +/* This is the actual ASN1 item itself */ + +struct ASN1_ITEM_st { + char itype; /* The item type, primitive, SEQUENCE, CHOICE + * or extern */ + long utype; /* underlying type */ + const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains + * the contents */ + long tcount; /* Number of templates if SEQUENCE or CHOICE */ + const void *funcs; /* functions that handle this type */ + long size; /* Structure size (usually) */ + const char *sname; /* Structure name */ +}; + +/*- + * These are values for the itype field and + * determine how the type is interpreted. + * + * For PRIMITIVE types the underlying type + * determines the behaviour if items is NULL. + * + * Otherwise templates must contain a single + * template and the type is treated in the + * same way as the type specified in the template. + * + * For SEQUENCE types the templates field points + * to the members, the size field is the + * structure size. + * + * For CHOICE types the templates field points + * to each possible member (typically a union) + * and the 'size' field is the offset of the + * selector. + * + * The 'funcs' field is used for application + * specific functions. + * + * The EXTERN type uses a new style d2i/i2d. + * The new style should be used where possible + * because it avoids things like the d2i IMPLICIT + * hack. + * + * MSTRING is a multiple string type, it is used + * for a CHOICE of character strings where the + * actual strings all occupy an ASN1_STRING + * structure. In this case the 'utype' field + * has a special meaning, it is used as a mask + * of acceptable types using the B_ASN1 constants. + * + * NDEF_SEQUENCE is the same as SEQUENCE except + * that it will use indefinite length constructed + * encoding if requested. + * + */ + +# define ASN1_ITYPE_PRIMITIVE 0x0 + +# define ASN1_ITYPE_SEQUENCE 0x1 + +# define ASN1_ITYPE_CHOICE 0x2 + +# define ASN1_ITYPE_EXTERN 0x4 + +# define ASN1_ITYPE_MSTRING 0x5 + +# define ASN1_ITYPE_NDEF_SEQUENCE 0x6 + +/* + * Cache for ASN1 tag and length, so we don't keep re-reading it for things + * like CHOICE + */ + +struct ASN1_TLC_st { + char valid; /* Values below are valid */ + int ret; /* return value */ + long plen; /* length */ + int ptag; /* class value */ + int pclass; /* class value */ + int hdrlen; /* header length */ +}; + +/* Typedefs for ASN1 function pointers */ +typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, + const ASN1_ITEM *it, int tag, int aclass, char opt, + ASN1_TLC *ctx); + +typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, + const ASN1_ITEM *it, int tag, int aclass); +typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); +typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); + +typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval, + int indent, const char *fname, + const ASN1_PCTX *pctx); + +typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, + int *putype, const ASN1_ITEM *it); +typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, + int len, int utype, char *free_cont, + const ASN1_ITEM *it); +typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval, + const ASN1_ITEM *it, int indent, + const ASN1_PCTX *pctx); + +typedef struct ASN1_EXTERN_FUNCS_st { + void *app_data; + ASN1_ex_new_func *asn1_ex_new; + ASN1_ex_free_func *asn1_ex_free; + ASN1_ex_free_func *asn1_ex_clear; + ASN1_ex_d2i *asn1_ex_d2i; + ASN1_ex_i2d *asn1_ex_i2d; + ASN1_ex_print_func *asn1_ex_print; +} ASN1_EXTERN_FUNCS; + +typedef struct ASN1_PRIMITIVE_FUNCS_st { + void *app_data; + unsigned long flags; + ASN1_ex_new_func *prim_new; + ASN1_ex_free_func *prim_free; + ASN1_ex_free_func *prim_clear; + ASN1_primitive_c2i *prim_c2i; + ASN1_primitive_i2c *prim_i2c; + ASN1_primitive_print *prim_print; +} ASN1_PRIMITIVE_FUNCS; + +/* + * This is the ASN1_AUX structure: it handles various miscellaneous + * requirements. For example the use of reference counts and an informational + * callback. The "informational callback" is called at various points during + * the ASN1 encoding and decoding. It can be used to provide minor + * customisation of the structures used. This is most useful where the + * supplied routines *almost* do the right thing but need some extra help at + * a few points. If the callback returns zero then it is assumed a fatal + * error has occurred and the main operation should be abandoned. If major + * changes in the default behaviour are required then an external type is + * more appropriate. + */ + +typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it, + void *exarg); + +typedef struct ASN1_AUX_st { + void *app_data; + int flags; + int ref_offset; /* Offset of reference value */ + int ref_lock; /* Lock type to use */ + ASN1_aux_cb *asn1_cb; + int enc_offset; /* Offset of ASN1_ENCODING structure */ +} ASN1_AUX; + +/* For print related callbacks exarg points to this structure */ +typedef struct ASN1_PRINT_ARG_st { + BIO *out; + int indent; + const ASN1_PCTX *pctx; +} ASN1_PRINT_ARG; + +/* For streaming related callbacks exarg points to this structure */ +typedef struct ASN1_STREAM_ARG_st { + /* BIO to stream through */ + BIO *out; + /* BIO with filters appended */ + BIO *ndef_bio; + /* Streaming I/O boundary */ + unsigned char **boundary; +} ASN1_STREAM_ARG; + +/* Flags in ASN1_AUX */ + +/* Use a reference count */ +# define ASN1_AFLG_REFCOUNT 1 +/* Save the encoding of structure (useful for signatures) */ +# define ASN1_AFLG_ENCODING 2 +/* The Sequence length is invalid */ +# define ASN1_AFLG_BROKEN 4 + +/* operation values for asn1_cb */ + +# define ASN1_OP_NEW_PRE 0 +# define ASN1_OP_NEW_POST 1 +# define ASN1_OP_FREE_PRE 2 +# define ASN1_OP_FREE_POST 3 +# define ASN1_OP_D2I_PRE 4 +# define ASN1_OP_D2I_POST 5 +# define ASN1_OP_I2D_PRE 6 +# define ASN1_OP_I2D_POST 7 +# define ASN1_OP_PRINT_PRE 8 +# define ASN1_OP_PRINT_POST 9 +# define ASN1_OP_STREAM_PRE 10 +# define ASN1_OP_STREAM_POST 11 +# define ASN1_OP_DETACHED_PRE 12 +# define ASN1_OP_DETACHED_POST 13 + +/* Macro to implement a primitive type */ +# define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) +# define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ + ASN1_ITEM_start(itname) \ + ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \ + ASN1_ITEM_end(itname) + +/* Macro to implement a multi string type */ +# define IMPLEMENT_ASN1_MSTRING(itname, mask) \ + ASN1_ITEM_start(itname) \ + ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \ + ASN1_ITEM_end(itname) + +# define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ + ASN1_ITEM_start(sname) \ + ASN1_ITYPE_EXTERN, \ + tag, \ + NULL, \ + 0, \ + &fptrs, \ + 0, \ + #sname \ + ASN1_ITEM_end(sname) + +/* Macro to implement standard functions in terms of ASN1_ITEM structures */ + +# define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) + +# define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) + +# define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ + IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) + +# define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname) + +# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) + +# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \ + pre stname *fname##_new(void) \ + { \ + return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ + } \ + pre void fname##_free(stname *a) \ + { \ + ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ + } + +# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ + stname *fname##_new(void) \ + { \ + return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ + } \ + void fname##_free(stname *a) \ + { \ + ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ + } + +# define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) + +# define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ + stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ + } \ + int i2d_##fname(stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ + } + +# define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \ + int i2d_##stname##_NDEF(stname *a, unsigned char **out) \ + { \ + return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\ + } + +# define IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(stname) \ + static stname *d2i_##stname(stname **a, \ + const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, \ + ASN1_ITEM_rptr(stname)); \ + } \ + static int i2d_##stname(stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((ASN1_VALUE *)a, out, \ + ASN1_ITEM_rptr(stname)); \ + } + +/* + * This includes evil casts to remove const: they will go away when full ASN1 + * constification is done. + */ +# define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ + stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ + } \ + int i2d_##fname(const stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ + } + +# define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ + stname * stname##_dup(stname *x) \ + { \ + return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ + } + +# define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \ + IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname) + +# define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \ + int fname##_print_ctx(BIO *out, stname *x, int indent, \ + const ASN1_PCTX *pctx) \ + { \ + return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \ + ASN1_ITEM_rptr(itname), pctx); \ + } + +# define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ + IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) + +# define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) + +/* external definitions for primitive types */ + +DECLARE_ASN1_ITEM(ASN1_BOOLEAN) +DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) +DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) +DECLARE_ASN1_ITEM(ASN1_SEQUENCE) +DECLARE_ASN1_ITEM(CBIGNUM) +DECLARE_ASN1_ITEM(BIGNUM) +DECLARE_ASN1_ITEM(LONG) +DECLARE_ASN1_ITEM(ZLONG) + +DEFINE_STACK_OF(ASN1_VALUE) + +/* Functions used internally by the ASN1 code */ + +int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); +void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); + +int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, + const ASN1_ITEM *it, int tag, int aclass, char opt, + ASN1_TLC *ctx); + +int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, + const ASN1_ITEM *it, int tag, int aclass); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/x86/include/openssl/async.h b/android/x86/include/openssl/async.h new file mode 100644 index 00000000..5b2e496d --- /dev/null +++ b/android/x86/include/openssl/async.h @@ -0,0 +1,98 @@ +/* + * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <stdlib.h> + +#ifndef HEADER_ASYNC_H +# define HEADER_ASYNC_H + +#if defined(_WIN32) +# if defined(BASETYPES) || defined(_WINDEF_H) +/* application has to include <windows.h> to use this */ +#define OSSL_ASYNC_FD HANDLE +#define OSSL_BAD_ASYNC_FD INVALID_HANDLE_VALUE +# endif +#else +#define OSSL_ASYNC_FD int +#define OSSL_BAD_ASYNC_FD -1 +#endif + + +# ifdef __cplusplus +extern "C" { +# endif + +typedef struct async_job_st ASYNC_JOB; +typedef struct async_wait_ctx_st ASYNC_WAIT_CTX; + +#define ASYNC_ERR 0 +#define ASYNC_NO_JOBS 1 +#define ASYNC_PAUSE 2 +#define ASYNC_FINISH 3 + +int ASYNC_init_thread(size_t max_size, size_t init_size); +void ASYNC_cleanup_thread(void); + +#ifdef OSSL_ASYNC_FD +ASYNC_WAIT_CTX *ASYNC_WAIT_CTX_new(void); +void ASYNC_WAIT_CTX_free(ASYNC_WAIT_CTX *ctx); +int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key, + OSSL_ASYNC_FD fd, + void *custom_data, + void (*cleanup)(ASYNC_WAIT_CTX *, const void *, + OSSL_ASYNC_FD, void *)); +int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key, + OSSL_ASYNC_FD *fd, void **custom_data); +int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd, + size_t *numfds); +int ASYNC_WAIT_CTX_get_changed_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *addfd, + size_t *numaddfds, OSSL_ASYNC_FD *delfd, + size_t *numdelfds); +int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key); +#endif + +int ASYNC_is_capable(void); + +int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *ctx, int *ret, + int (*func)(void *), void *args, size_t size); +int ASYNC_pause_job(void); + +ASYNC_JOB *ASYNC_get_current_job(void); +ASYNC_WAIT_CTX *ASYNC_get_wait_ctx(ASYNC_JOB *job); +void ASYNC_block_pause(void); +void ASYNC_unblock_pause(void); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_ASYNC_strings(void); + +/* Error codes for the ASYNC functions. */ + +/* Function codes. */ +# define ASYNC_F_ASYNC_CTX_NEW 100 +# define ASYNC_F_ASYNC_INIT_THREAD 101 +# define ASYNC_F_ASYNC_JOB_NEW 102 +# define ASYNC_F_ASYNC_PAUSE_JOB 103 +# define ASYNC_F_ASYNC_START_FUNC 104 +# define ASYNC_F_ASYNC_START_JOB 105 + +/* Reason codes. */ +# define ASYNC_R_FAILED_TO_SET_POOL 101 +# define ASYNC_R_FAILED_TO_SWAP_CONTEXT 102 +# define ASYNC_R_INIT_FAILED 105 +# define ASYNC_R_INVALID_POOL_SIZE 103 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/bio.h b/android/x86/include/openssl/bio.h new file mode 100644 index 00000000..9bc941b2 --- /dev/null +++ b/android/x86/include/openssl/bio.h @@ -0,0 +1,854 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BIO_H +# define HEADER_BIO_H + +# include <openssl/e_os2.h> + +# ifndef OPENSSL_NO_STDIO +# include <stdio.h> +# endif +# include <stdarg.h> + +# include <openssl/crypto.h> + +# ifndef OPENSSL_NO_SCTP +# ifndef OPENSSL_SYS_VMS +# include <stdint.h> +# else +# include <inttypes.h> +# endif +# endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* There are the classes of BIOs */ +# define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ +# define BIO_TYPE_FILTER 0x0200 +# define BIO_TYPE_SOURCE_SINK 0x0400 + +/* These are the 'types' of BIOs */ +# define BIO_TYPE_NONE 0 +# define BIO_TYPE_MEM ( 1|BIO_TYPE_SOURCE_SINK) +# define BIO_TYPE_FILE ( 2|BIO_TYPE_SOURCE_SINK) + +# define BIO_TYPE_FD ( 4|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# define BIO_TYPE_SOCKET ( 5|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# define BIO_TYPE_NULL ( 6|BIO_TYPE_SOURCE_SINK) +# define BIO_TYPE_SSL ( 7|BIO_TYPE_FILTER) +# define BIO_TYPE_MD ( 8|BIO_TYPE_FILTER) +# define BIO_TYPE_BUFFER ( 9|BIO_TYPE_FILTER) +# define BIO_TYPE_CIPHER (10|BIO_TYPE_FILTER) +# define BIO_TYPE_BASE64 (11|BIO_TYPE_FILTER) +# define BIO_TYPE_CONNECT (12|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# define BIO_TYPE_ACCEPT (13|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) + +# define BIO_TYPE_NBIO_TEST (16|BIO_TYPE_FILTER)/* server proxy BIO */ +# define BIO_TYPE_NULL_FILTER (17|BIO_TYPE_FILTER) +# define BIO_TYPE_BIO (19|BIO_TYPE_SOURCE_SINK)/* half a BIO pair */ +# define BIO_TYPE_LINEBUFFER (20|BIO_TYPE_FILTER) +# define BIO_TYPE_DGRAM (21|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# define BIO_TYPE_ASN1 (22|BIO_TYPE_FILTER) +# define BIO_TYPE_COMP (23|BIO_TYPE_FILTER) +# ifndef OPENSSL_NO_SCTP +# define BIO_TYPE_DGRAM_SCTP (24|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# endif + +#define BIO_TYPE_START 128 + +/* + * BIO_FILENAME_READ|BIO_CLOSE to open or close on free. + * BIO_set_fp(in,stdin,BIO_NOCLOSE); + */ +# define BIO_NOCLOSE 0x00 +# define BIO_CLOSE 0x01 + +/* + * These are used in the following macros and are passed to BIO_ctrl() + */ +# define BIO_CTRL_RESET 1/* opt - rewind/zero etc */ +# define BIO_CTRL_EOF 2/* opt - are we at the eof */ +# define BIO_CTRL_INFO 3/* opt - extra tit-bits */ +# define BIO_CTRL_SET 4/* man - set the 'IO' type */ +# define BIO_CTRL_GET 5/* man - get the 'IO' type */ +# define BIO_CTRL_PUSH 6/* opt - internal, used to signify change */ +# define BIO_CTRL_POP 7/* opt - internal, used to signify change */ +# define BIO_CTRL_GET_CLOSE 8/* man - set the 'close' on free */ +# define BIO_CTRL_SET_CLOSE 9/* man - set the 'close' on free */ +# define BIO_CTRL_PENDING 10/* opt - is their more data buffered */ +# define BIO_CTRL_FLUSH 11/* opt - 'flush' buffered output */ +# define BIO_CTRL_DUP 12/* man - extra stuff for 'duped' BIO */ +# define BIO_CTRL_WPENDING 13/* opt - number of bytes still to write */ +# define BIO_CTRL_SET_CALLBACK 14/* opt - set callback function */ +# define BIO_CTRL_GET_CALLBACK 15/* opt - set callback function */ + +# define BIO_CTRL_SET_FILENAME 30/* BIO_s_file special */ + +/* dgram BIO stuff */ +# define BIO_CTRL_DGRAM_CONNECT 31/* BIO dgram special */ +# define BIO_CTRL_DGRAM_SET_CONNECTED 32/* allow for an externally connected + * socket to be passed in */ +# define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33/* setsockopt, essentially */ +# define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34/* getsockopt, essentially */ +# define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35/* setsockopt, essentially */ +# define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36/* getsockopt, essentially */ + +# define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37/* flag whether the last */ +# define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38/* I/O operation tiemd out */ + +/* #ifdef IP_MTU_DISCOVER */ +# define BIO_CTRL_DGRAM_MTU_DISCOVER 39/* set DF bit on egress packets */ +/* #endif */ + +# define BIO_CTRL_DGRAM_QUERY_MTU 40/* as kernel for current MTU */ +# define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 +# define BIO_CTRL_DGRAM_GET_MTU 41/* get cached value for MTU */ +# define BIO_CTRL_DGRAM_SET_MTU 42/* set cached value for MTU. + * want to use this if asking + * the kernel fails */ + +# define BIO_CTRL_DGRAM_MTU_EXCEEDED 43/* check whether the MTU was + * exceed in the previous write + * operation */ + +# define BIO_CTRL_DGRAM_GET_PEER 46 +# define BIO_CTRL_DGRAM_SET_PEER 44/* Destination for the data */ + +# define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45/* Next DTLS handshake timeout + * to adjust socket timeouts */ +# define BIO_CTRL_DGRAM_SET_DONT_FRAG 48 + +# define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD 49 + +# define BIO_CTRL_DGRAM_SET_PEEK_MODE 50 + +# ifndef OPENSSL_NO_SCTP +/* SCTP stuff */ +# define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE 50 +# define BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY 51 +# define BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY 52 +# define BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD 53 +# define BIO_CTRL_DGRAM_SCTP_GET_SNDINFO 60 +# define BIO_CTRL_DGRAM_SCTP_SET_SNDINFO 61 +# define BIO_CTRL_DGRAM_SCTP_GET_RCVINFO 62 +# define BIO_CTRL_DGRAM_SCTP_SET_RCVINFO 63 +# define BIO_CTRL_DGRAM_SCTP_GET_PRINFO 64 +# define BIO_CTRL_DGRAM_SCTP_SET_PRINFO 65 +# define BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN 70 +# endif + +/* modifiers */ +# define BIO_FP_READ 0x02 +# define BIO_FP_WRITE 0x04 +# define BIO_FP_APPEND 0x08 +# define BIO_FP_TEXT 0x10 + +# define BIO_FLAGS_READ 0x01 +# define BIO_FLAGS_WRITE 0x02 +# define BIO_FLAGS_IO_SPECIAL 0x04 +# define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) +# define BIO_FLAGS_SHOULD_RETRY 0x08 +# ifndef BIO_FLAGS_UPLINK +/* + * "UPLINK" flag denotes file descriptors provided by application. It + * defaults to 0, as most platforms don't require UPLINK interface. + */ +# define BIO_FLAGS_UPLINK 0 +# endif + +# define BIO_FLAGS_BASE64_NO_NL 0x100 + +/* + * This is used with memory BIOs: + * BIO_FLAGS_MEM_RDONLY means we shouldn't free up or change the data in any way; + * BIO_FLAGS_NONCLEAR_RST means we should't clear data on reset. + */ +# define BIO_FLAGS_MEM_RDONLY 0x200 +# define BIO_FLAGS_NONCLEAR_RST 0x400 + +typedef union bio_addr_st BIO_ADDR; +typedef struct bio_addrinfo_st BIO_ADDRINFO; + +int BIO_get_new_index(void); +void BIO_set_flags(BIO *b, int flags); +int BIO_test_flags(const BIO *b, int flags); +void BIO_clear_flags(BIO *b, int flags); + +# define BIO_get_flags(b) BIO_test_flags(b, ~(0x0)) +# define BIO_set_retry_special(b) \ + BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) +# define BIO_set_retry_read(b) \ + BIO_set_flags(b, (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) +# define BIO_set_retry_write(b) \ + BIO_set_flags(b, (BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) + +/* These are normally used internally in BIOs */ +# define BIO_clear_retry_flags(b) \ + BIO_clear_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) +# define BIO_get_retry_flags(b) \ + BIO_test_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) + +/* These should be used by the application to tell why we should retry */ +# define BIO_should_read(a) BIO_test_flags(a, BIO_FLAGS_READ) +# define BIO_should_write(a) BIO_test_flags(a, BIO_FLAGS_WRITE) +# define BIO_should_io_special(a) BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL) +# define BIO_retry_type(a) BIO_test_flags(a, BIO_FLAGS_RWS) +# define BIO_should_retry(a) BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY) + +/* + * The next three are used in conjunction with the BIO_should_io_special() + * condition. After this returns true, BIO *BIO_get_retry_BIO(BIO *bio, int + * *reason); will walk the BIO stack and return the 'reason' for the special + * and the offending BIO. Given a BIO, BIO_get_retry_reason(bio) will return + * the code. + */ +/* + * Returned from the SSL bio when the certificate retrieval code had an error + */ +# define BIO_RR_SSL_X509_LOOKUP 0x01 +/* Returned from the connect BIO when a connect would have blocked */ +# define BIO_RR_CONNECT 0x02 +/* Returned from the accept BIO when an accept would have blocked */ +# define BIO_RR_ACCEPT 0x03 + +/* These are passed by the BIO callback */ +# define BIO_CB_FREE 0x01 +# define BIO_CB_READ 0x02 +# define BIO_CB_WRITE 0x03 +# define BIO_CB_PUTS 0x04 +# define BIO_CB_GETS 0x05 +# define BIO_CB_CTRL 0x06 + +/* + * The callback is called before and after the underling operation, The + * BIO_CB_RETURN flag indicates if it is after the call + */ +# define BIO_CB_RETURN 0x80 +# define BIO_CB_return(a) ((a)|BIO_CB_RETURN) +# define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) +# define BIO_cb_post(a) ((a)&BIO_CB_RETURN) + +typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi, + long argl, long ret); +BIO_callback_fn BIO_get_callback(const BIO *b); +void BIO_set_callback(BIO *b, BIO_callback_fn callback); +char *BIO_get_callback_arg(const BIO *b); +void BIO_set_callback_arg(BIO *b, char *arg); + +typedef struct bio_method_st BIO_METHOD; + +const char *BIO_method_name(const BIO *b); +int BIO_method_type(const BIO *b); + +typedef void bio_info_cb(BIO *, int, const char *, int, long, long); + +DEFINE_STACK_OF(BIO) + +/* Prefix and suffix callback in ASN1 BIO */ +typedef int asn1_ps_func (BIO *b, unsigned char **pbuf, int *plen, + void *parg); + +# ifndef OPENSSL_NO_SCTP +/* SCTP parameter structs */ +struct bio_dgram_sctp_sndinfo { + uint16_t snd_sid; + uint16_t snd_flags; + uint32_t snd_ppid; + uint32_t snd_context; +}; + +struct bio_dgram_sctp_rcvinfo { + uint16_t rcv_sid; + uint16_t rcv_ssn; + uint16_t rcv_flags; + uint32_t rcv_ppid; + uint32_t rcv_tsn; + uint32_t rcv_cumtsn; + uint32_t rcv_context; +}; + +struct bio_dgram_sctp_prinfo { + uint16_t pr_policy; + uint32_t pr_value; +}; +# endif + +/* + * #define BIO_CONN_get_param_hostname BIO_ctrl + */ + +# define BIO_C_SET_CONNECT 100 +# define BIO_C_DO_STATE_MACHINE 101 +# define BIO_C_SET_NBIO 102 +/* # define BIO_C_SET_PROXY_PARAM 103 */ +# define BIO_C_SET_FD 104 +# define BIO_C_GET_FD 105 +# define BIO_C_SET_FILE_PTR 106 +# define BIO_C_GET_FILE_PTR 107 +# define BIO_C_SET_FILENAME 108 +# define BIO_C_SET_SSL 109 +# define BIO_C_GET_SSL 110 +# define BIO_C_SET_MD 111 +# define BIO_C_GET_MD 112 +# define BIO_C_GET_CIPHER_STATUS 113 +# define BIO_C_SET_BUF_MEM 114 +# define BIO_C_GET_BUF_MEM_PTR 115 +# define BIO_C_GET_BUFF_NUM_LINES 116 +# define BIO_C_SET_BUFF_SIZE 117 +# define BIO_C_SET_ACCEPT 118 +# define BIO_C_SSL_MODE 119 +# define BIO_C_GET_MD_CTX 120 +/* # define BIO_C_GET_PROXY_PARAM 121 */ +# define BIO_C_SET_BUFF_READ_DATA 122/* data to read first */ +# define BIO_C_GET_CONNECT 123 +# define BIO_C_GET_ACCEPT 124 +# define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 +# define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 +# define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 +# define BIO_C_FILE_SEEK 128 +# define BIO_C_GET_CIPHER_CTX 129 +# define BIO_C_SET_BUF_MEM_EOF_RETURN 130/* return end of input + * value */ +# define BIO_C_SET_BIND_MODE 131 +# define BIO_C_GET_BIND_MODE 132 +# define BIO_C_FILE_TELL 133 +# define BIO_C_GET_SOCKS 134 +# define BIO_C_SET_SOCKS 135 + +# define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ +# define BIO_C_GET_WRITE_BUF_SIZE 137 +# define BIO_C_MAKE_BIO_PAIR 138 +# define BIO_C_DESTROY_BIO_PAIR 139 +# define BIO_C_GET_WRITE_GUARANTEE 140 +# define BIO_C_GET_READ_REQUEST 141 +# define BIO_C_SHUTDOWN_WR 142 +# define BIO_C_NREAD0 143 +# define BIO_C_NREAD 144 +# define BIO_C_NWRITE0 145 +# define BIO_C_NWRITE 146 +# define BIO_C_RESET_READ_REQUEST 147 +# define BIO_C_SET_MD_CTX 148 + +# define BIO_C_SET_PREFIX 149 +# define BIO_C_GET_PREFIX 150 +# define BIO_C_SET_SUFFIX 151 +# define BIO_C_GET_SUFFIX 152 + +# define BIO_C_SET_EX_ARG 153 +# define BIO_C_GET_EX_ARG 154 + +# define BIO_C_SET_CONNECT_MODE 155 + +# define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg) +# define BIO_get_app_data(s) BIO_get_ex_data(s,0) + +# define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) + +# ifndef OPENSSL_NO_SOCK +/* IP families we support, for BIO_s_connect() and BIO_s_accept() */ +/* Note: the underlying operating system may not support some of them */ +# define BIO_FAMILY_IPV4 4 +# define BIO_FAMILY_IPV6 6 +# define BIO_FAMILY_IPANY 256 + +/* BIO_s_connect() */ +# define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) +# define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) +# define BIO_set_conn_address(b,addr) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)addr) +# define BIO_set_conn_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,f) +# define BIO_get_conn_hostname(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)) +# define BIO_get_conn_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)) +# define BIO_get_conn_address(b) ((const BIO_ADDR *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2)) +# define BIO_get_conn_ip_family(b) BIO_ctrl(b,BIO_C_GET_CONNECT,3,NULL) +# define BIO_set_conn_mode(b,n) BIO_ctrl(b,BIO_C_SET_CONNECT_MODE,(n),NULL) + +/* BIO_s_accept() */ +# define BIO_set_accept_name(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name) +# define BIO_set_accept_port(b,port) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(char *)port) +# define BIO_get_accept_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)) +# define BIO_get_accept_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,1)) +# define BIO_get_peer_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,2)) +# define BIO_get_peer_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,3)) +/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ +# define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(n)?(void *)"a":NULL) +# define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,3,(char *)bio) +# define BIO_set_accept_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_ACCEPT,4,f) +# define BIO_get_accept_ip_family(b) BIO_ctrl(b,BIO_C_GET_ACCEPT,4,NULL) + +/* Aliases kept for backward compatibility */ +# define BIO_BIND_NORMAL 0 +# define BIO_BIND_REUSEADDR BIO_SOCK_REUSEADDR +# define BIO_BIND_REUSEADDR_IF_UNUSED BIO_SOCK_REUSEADDR +# define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) +# define BIO_get_bind_mode(b) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) + +/* BIO_s_accept() and BIO_s_connect() */ +# define BIO_do_connect(b) BIO_do_handshake(b) +# define BIO_do_accept(b) BIO_do_handshake(b) +# endif /* OPENSSL_NO_SOCK */ + +# define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) + +/* BIO_s_datagram(), BIO_s_fd(), BIO_s_socket(), BIO_s_accept() and BIO_s_connect() */ +# define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) +# define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c) + +/* BIO_s_file() */ +# define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) +# define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) + +/* BIO_s_fd() and BIO_s_file() */ +# define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) +# define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) + +/* + * name is cast to lose const, but might be better to route through a + * function so we can do it safely + */ +# ifdef CONST_STRICT +/* + * If you are wondering why this isn't defined, its because CONST_STRICT is + * purely a compile-time kludge to allow const to be checked. + */ +int BIO_read_filename(BIO *b, const char *name); +# else +# define BIO_read_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_READ,(char *)name) +# endif +# define BIO_write_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_WRITE,name) +# define BIO_append_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_APPEND,name) +# define BIO_rw_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) + +/* + * WARNING WARNING, this ups the reference count on the read bio of the SSL + * structure. This is because the ssl read BIO is now pointed to by the + * next_bio field in the bio. So when you free the BIO, make sure you are + * doing a BIO_free_all() to catch the underlying BIO. + */ +# define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl) +# define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp) +# define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL) +# define BIO_set_ssl_renegotiate_bytes(b,num) \ + BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL) +# define BIO_get_num_renegotiates(b) \ + BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL) +# define BIO_set_ssl_renegotiate_timeout(b,seconds) \ + BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL) + +/* defined in evp.h */ +/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ + +# define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) +# define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) +# define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) +# define BIO_set_mem_eof_return(b,v) \ + BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) + +/* For the BIO_f_buffer() type */ +# define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) +# define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL) +# define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0) +# define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1) +# define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf) + +/* Don't use the next one unless you know what you are doing :-) */ +# define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret)) + +# define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL) +# define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL) +# define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL) +# define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) +# define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) +# define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) +/* ...pending macros have inappropriate return type */ +size_t BIO_ctrl_pending(BIO *b); +size_t BIO_ctrl_wpending(BIO *b); +# define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) +# define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \ + cbp) +# define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb) + +/* For the BIO_f_buffer() type */ +# define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) + +/* For BIO_s_bio() */ +# define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) +# define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) +# define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) +# define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) +# define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL) +/* macros with inappropriate type -- but ...pending macros use int too: */ +# define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) +# define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) +size_t BIO_ctrl_get_write_guarantee(BIO *b); +size_t BIO_ctrl_get_read_request(BIO *b); +int BIO_ctrl_reset_read_request(BIO *b); + +/* ctrl macros for dgram */ +# define BIO_ctrl_dgram_connect(b,peer) \ + (int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)peer) +# define BIO_ctrl_set_connected(b,peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, 0, (char *)peer) +# define BIO_dgram_recv_timedout(b) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL) +# define BIO_dgram_send_timedout(b) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL) +# define BIO_dgram_get_peer(b,peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)peer) +# define BIO_dgram_set_peer(b,peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer) +# define BIO_dgram_get_mtu_overhead(b) \ + (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU_OVERHEAD, 0, NULL) + +#define BIO_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, l, p, newf, dupf, freef) +int BIO_set_ex_data(BIO *bio, int idx, void *data); +void *BIO_get_ex_data(BIO *bio, int idx); +uint64_t BIO_number_read(BIO *bio); +uint64_t BIO_number_written(BIO *bio); + +/* For BIO_f_asn1() */ +int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, + asn1_ps_func *prefix_free); +int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, + asn1_ps_func **pprefix_free); +int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, + asn1_ps_func *suffix_free); +int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, + asn1_ps_func **psuffix_free); + +const BIO_METHOD *BIO_s_file(void); +BIO *BIO_new_file(const char *filename, const char *mode); +# ifndef OPENSSL_NO_STDIO +BIO *BIO_new_fp(FILE *stream, int close_flag); +# endif +BIO *BIO_new(const BIO_METHOD *type); +int BIO_free(BIO *a); +void BIO_set_data(BIO *a, void *ptr); +void *BIO_get_data(BIO *a); +void BIO_set_init(BIO *a, int init); +int BIO_get_init(BIO *a); +void BIO_set_shutdown(BIO *a, int shut); +int BIO_get_shutdown(BIO *a); +void BIO_vfree(BIO *a); +int BIO_up_ref(BIO *a); +int BIO_read(BIO *b, void *data, int len); +int BIO_gets(BIO *bp, char *buf, int size); +int BIO_write(BIO *b, const void *data, int len); +int BIO_puts(BIO *bp, const char *buf); +int BIO_indent(BIO *b, int indent, int max); +long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg); +long BIO_callback_ctrl(BIO *b, int cmd, + void (*fp) (BIO *, int, const char *, int, long, long)); +void *BIO_ptr_ctrl(BIO *bp, int cmd, long larg); +long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg); +BIO *BIO_push(BIO *b, BIO *append); +BIO *BIO_pop(BIO *b); +void BIO_free_all(BIO *a); +BIO *BIO_find_type(BIO *b, int bio_type); +BIO *BIO_next(BIO *b); +void BIO_set_next(BIO *b, BIO *next); +BIO *BIO_get_retry_BIO(BIO *bio, int *reason); +int BIO_get_retry_reason(BIO *bio); +void BIO_set_retry_reason(BIO *bio, int reason); +BIO *BIO_dup_chain(BIO *in); + +int BIO_nread0(BIO *bio, char **buf); +int BIO_nread(BIO *bio, char **buf, int num); +int BIO_nwrite0(BIO *bio, char **buf); +int BIO_nwrite(BIO *bio, char **buf, int num); + +long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, + long argl, long ret); + +const BIO_METHOD *BIO_s_mem(void); +const BIO_METHOD *BIO_s_secmem(void); +BIO *BIO_new_mem_buf(const void *buf, int len); +# ifndef OPENSSL_NO_SOCK +const BIO_METHOD *BIO_s_socket(void); +const BIO_METHOD *BIO_s_connect(void); +const BIO_METHOD *BIO_s_accept(void); +# endif +const BIO_METHOD *BIO_s_fd(void); +const BIO_METHOD *BIO_s_log(void); +const BIO_METHOD *BIO_s_bio(void); +const BIO_METHOD *BIO_s_null(void); +const BIO_METHOD *BIO_f_null(void); +const BIO_METHOD *BIO_f_buffer(void); +const BIO_METHOD *BIO_f_linebuffer(void); +const BIO_METHOD *BIO_f_nbio_test(void); +# ifndef OPENSSL_NO_DGRAM +const BIO_METHOD *BIO_s_datagram(void); +int BIO_dgram_non_fatal_error(int error); +BIO *BIO_new_dgram(int fd, int close_flag); +# ifndef OPENSSL_NO_SCTP +const BIO_METHOD *BIO_s_datagram_sctp(void); +BIO *BIO_new_dgram_sctp(int fd, int close_flag); +int BIO_dgram_is_sctp(BIO *bio); +int BIO_dgram_sctp_notification_cb(BIO *b, + void (*handle_notifications) (BIO *bio, + void *context, + void *buf), + void *context); +int BIO_dgram_sctp_wait_for_dry(BIO *b); +int BIO_dgram_sctp_msg_waiting(BIO *b); +# endif +# endif + +# ifndef OPENSSL_NO_SOCK +int BIO_sock_should_retry(int i); +int BIO_sock_non_fatal_error(int error); +# endif + +int BIO_fd_should_retry(int i); +int BIO_fd_non_fatal_error(int error); +int BIO_dump_cb(int (*cb) (const void *data, size_t len, void *u), + void *u, const char *s, int len); +int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u), + void *u, const char *s, int len, int indent); +int BIO_dump(BIO *b, const char *bytes, int len); +int BIO_dump_indent(BIO *b, const char *bytes, int len, int indent); +# ifndef OPENSSL_NO_STDIO +int BIO_dump_fp(FILE *fp, const char *s, int len); +int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent); +# endif +int BIO_hex_string(BIO *out, int indent, int width, unsigned char *data, + int datalen); + +# ifndef OPENSSL_NO_SOCK +BIO_ADDR *BIO_ADDR_new(void); +int BIO_ADDR_rawmake(BIO_ADDR *ap, int family, + const void *where, size_t wherelen, unsigned short port); +void BIO_ADDR_free(BIO_ADDR *); +void BIO_ADDR_clear(BIO_ADDR *ap); +int BIO_ADDR_family(const BIO_ADDR *ap); +int BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l); +unsigned short BIO_ADDR_rawport(const BIO_ADDR *ap); +char *BIO_ADDR_hostname_string(const BIO_ADDR *ap, int numeric); +char *BIO_ADDR_service_string(const BIO_ADDR *ap, int numeric); +char *BIO_ADDR_path_string(const BIO_ADDR *ap); + +const BIO_ADDRINFO *BIO_ADDRINFO_next(const BIO_ADDRINFO *bai); +int BIO_ADDRINFO_family(const BIO_ADDRINFO *bai); +int BIO_ADDRINFO_socktype(const BIO_ADDRINFO *bai); +int BIO_ADDRINFO_protocol(const BIO_ADDRINFO *bai); +const BIO_ADDR *BIO_ADDRINFO_address(const BIO_ADDRINFO *bai); +void BIO_ADDRINFO_free(BIO_ADDRINFO *bai); + +enum BIO_hostserv_priorities { + BIO_PARSE_PRIO_HOST, BIO_PARSE_PRIO_SERV +}; +int BIO_parse_hostserv(const char *hostserv, char **host, char **service, + enum BIO_hostserv_priorities hostserv_prio); +enum BIO_lookup_type { + BIO_LOOKUP_CLIENT, BIO_LOOKUP_SERVER +}; +int BIO_lookup(const char *host, const char *service, + enum BIO_lookup_type lookup_type, + int family, int socktype, BIO_ADDRINFO **res); +int BIO_sock_error(int sock); +int BIO_socket_ioctl(int fd, long type, void *arg); +int BIO_socket_nbio(int fd, int mode); +int BIO_sock_init(void); +# if OPENSSL_API_COMPAT < 0x10100000L +# define BIO_sock_cleanup() while(0) continue +# endif +int BIO_set_tcp_ndelay(int sock, int turn_on); + +DEPRECATEDIN_1_1_0(struct hostent *BIO_gethostbyname(const char *name)) +DEPRECATEDIN_1_1_0(int BIO_get_port(const char *str, unsigned short *port_ptr)) +DEPRECATEDIN_1_1_0(int BIO_get_host_ip(const char *str, unsigned char *ip)) +DEPRECATEDIN_1_1_0(int BIO_get_accept_socket(char *host_port, int mode)) +DEPRECATEDIN_1_1_0(int BIO_accept(int sock, char **ip_port)) + +union BIO_sock_info_u { + BIO_ADDR *addr; +}; +enum BIO_sock_info_type { + BIO_SOCK_INFO_ADDRESS +}; +int BIO_sock_info(int sock, + enum BIO_sock_info_type type, union BIO_sock_info_u *info); + +# define BIO_SOCK_REUSEADDR 0x01 +# define BIO_SOCK_V6_ONLY 0x02 +# define BIO_SOCK_KEEPALIVE 0x04 +# define BIO_SOCK_NONBLOCK 0x08 +# define BIO_SOCK_NODELAY 0x10 + +int BIO_socket(int domain, int socktype, int protocol, int options); +int BIO_connect(int sock, const BIO_ADDR *addr, int options); +int BIO_listen(int sock, const BIO_ADDR *addr, int options); +int BIO_accept_ex(int accept_sock, BIO_ADDR *addr, int options); +int BIO_closesocket(int sock); + +BIO *BIO_new_socket(int sock, int close_flag); +BIO *BIO_new_connect(const char *host_port); +BIO *BIO_new_accept(const char *host_port); +# endif /* OPENSSL_NO_SOCK*/ + +BIO *BIO_new_fd(int fd, int close_flag); + +int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, + BIO **bio2, size_t writebuf2); +/* + * If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. + * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. Size 0 uses default + * value. + */ + +void BIO_copy_next_retry(BIO *b); + +/* + * long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); + */ + +# ifdef __GNUC__ +# define __bio_h__attr__ __attribute__ +# else +# define __bio_h__attr__(x) +# endif +int BIO_printf(BIO *bio, const char *format, ...) +__bio_h__attr__((__format__(__printf__, 2, 3))); +int BIO_vprintf(BIO *bio, const char *format, va_list args) +__bio_h__attr__((__format__(__printf__, 2, 0))); +int BIO_snprintf(char *buf, size_t n, const char *format, ...) +__bio_h__attr__((__format__(__printf__, 3, 4))); +int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) +__bio_h__attr__((__format__(__printf__, 3, 0))); +# undef __bio_h__attr__ + + +BIO_METHOD *BIO_meth_new(int type, const char *name); +void BIO_meth_free(BIO_METHOD *biom); +int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int); +int BIO_meth_set_write(BIO_METHOD *biom, + int (*write) (BIO *, const char *, int)); +int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int); +int BIO_meth_set_read(BIO_METHOD *biom, + int (*read) (BIO *, char *, int)); +int (*BIO_meth_get_puts(BIO_METHOD *biom)) (BIO *, const char *); +int BIO_meth_set_puts(BIO_METHOD *biom, + int (*puts) (BIO *, const char *)); +int (*BIO_meth_get_gets(BIO_METHOD *biom)) (BIO *, char *, int); +int BIO_meth_set_gets(BIO_METHOD *biom, + int (*gets) (BIO *, char *, int)); +long (*BIO_meth_get_ctrl(BIO_METHOD *biom)) (BIO *, int, long, void *); +int BIO_meth_set_ctrl(BIO_METHOD *biom, + long (*ctrl) (BIO *, int, long, void *)); +int (*BIO_meth_get_create(BIO_METHOD *bion)) (BIO *); +int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *)); +int (*BIO_meth_get_destroy(BIO_METHOD *biom)) (BIO *); +int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *)); +long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom)) + (BIO *, int, bio_info_cb *); +int BIO_meth_set_callback_ctrl(BIO_METHOD *biom, + long (*callback_ctrl) (BIO *, int, + bio_info_cb *)); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_BIO_strings(void); + +/* Error codes for the BIO functions. */ + +/* Function codes. */ +# define BIO_F_ACPT_STATE 100 +# define BIO_F_ADDR_STRINGS 134 +# define BIO_F_BIO_ACCEPT 101 +# define BIO_F_BIO_ACCEPT_EX 137 +# define BIO_F_BIO_ADDR_NEW 144 +# define BIO_F_BIO_CALLBACK_CTRL 131 +# define BIO_F_BIO_CONNECT 138 +# define BIO_F_BIO_CTRL 103 +# define BIO_F_BIO_GETS 104 +# define BIO_F_BIO_GET_HOST_IP 106 +# define BIO_F_BIO_GET_NEW_INDEX 102 +# define BIO_F_BIO_GET_PORT 107 +# define BIO_F_BIO_LISTEN 139 +# define BIO_F_BIO_LOOKUP 135 +# define BIO_F_BIO_MAKE_PAIR 121 +# define BIO_F_BIO_NEW 108 +# define BIO_F_BIO_NEW_FILE 109 +# define BIO_F_BIO_NEW_MEM_BUF 126 +# define BIO_F_BIO_NREAD 123 +# define BIO_F_BIO_NREAD0 124 +# define BIO_F_BIO_NWRITE 125 +# define BIO_F_BIO_NWRITE0 122 +# define BIO_F_BIO_PARSE_HOSTSERV 136 +# define BIO_F_BIO_PUTS 110 +# define BIO_F_BIO_READ 111 +# define BIO_F_BIO_SOCKET 140 +# define BIO_F_BIO_SOCKET_NBIO 142 +# define BIO_F_BIO_SOCK_INFO 141 +# define BIO_F_BIO_SOCK_INIT 112 +# define BIO_F_BIO_WRITE 113 +# define BIO_F_BUFFER_CTRL 114 +# define BIO_F_CONN_CTRL 127 +# define BIO_F_CONN_STATE 115 +# define BIO_F_DGRAM_SCTP_READ 132 +# define BIO_F_DGRAM_SCTP_WRITE 133 +# define BIO_F_FILE_CTRL 116 +# define BIO_F_FILE_READ 130 +# define BIO_F_LINEBUFFER_CTRL 129 +# define BIO_F_MEM_WRITE 117 +# define BIO_F_SSL_NEW 118 + +/* Reason codes. */ +# define BIO_R_ACCEPT_ERROR 100 +# define BIO_R_ADDRINFO_ADDR_IS_NOT_AF_INET 141 +# define BIO_R_AMBIGUOUS_HOST_OR_SERVICE 129 +# define BIO_R_BAD_FOPEN_MODE 101 +# define BIO_R_BROKEN_PIPE 124 +# define BIO_R_CONNECT_ERROR 103 +# define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 +# define BIO_R_GETSOCKNAME_ERROR 132 +# define BIO_R_GETSOCKNAME_TRUNCATED_ADDRESS 133 +# define BIO_R_GETTING_SOCKTYPE 134 +# define BIO_R_INVALID_ARGUMENT 125 +# define BIO_R_INVALID_SOCKET 135 +# define BIO_R_IN_USE 123 +# define BIO_R_LISTEN_V6_ONLY 136 +# define BIO_R_LOOKUP_RETURNED_NOTHING 142 +# define BIO_R_MALFORMED_HOST_OR_SERVICE 130 +# define BIO_R_NBIO_CONNECT_ERROR 110 +# define BIO_R_NO_ACCEPT_ADDR_OR_SERVICE_SPECIFIED 143 +# define BIO_R_NO_HOSTNAME_OR_SERVICE_SPECIFIED 144 +# define BIO_R_NO_PORT_DEFINED 113 +# define BIO_R_NO_SUCH_FILE 128 +# define BIO_R_NULL_PARAMETER 115 +# define BIO_R_UNABLE_TO_BIND_SOCKET 117 +# define BIO_R_UNABLE_TO_CREATE_SOCKET 118 +# define BIO_R_UNABLE_TO_KEEPALIVE 137 +# define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 +# define BIO_R_UNABLE_TO_NODELAY 138 +# define BIO_R_UNABLE_TO_REUSEADDR 139 +# define BIO_R_UNAVAILABLE_IP_FAMILY 145 +# define BIO_R_UNINITIALIZED 120 +# define BIO_R_UNKNOWN_INFO_TYPE 140 +# define BIO_R_UNSUPPORTED_IP_FAMILY 146 +# define BIO_R_UNSUPPORTED_METHOD 121 +# define BIO_R_UNSUPPORTED_PROTOCOL_FAMILY 131 +# define BIO_R_WRITE_TO_READ_ONLY_BIO 126 +# define BIO_R_WSASTARTUP 122 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/blowfish.h b/android/x86/include/openssl/blowfish.h new file mode 100644 index 00000000..cd3e460e --- /dev/null +++ b/android/x86/include/openssl/blowfish.h @@ -0,0 +1,61 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BLOWFISH_H +# define HEADER_BLOWFISH_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_BF +# include <openssl/e_os2.h> +# ifdef __cplusplus +extern "C" { +# endif + +# define BF_ENCRYPT 1 +# define BF_DECRYPT 0 + +/*- + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! BF_LONG has to be at least 32 bits wide. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +# define BF_LONG unsigned int + +# define BF_ROUNDS 16 +# define BF_BLOCK 8 + +typedef struct bf_key_st { + BF_LONG P[BF_ROUNDS + 2]; + BF_LONG S[4 * 256]; +} BF_KEY; + +void BF_set_key(BF_KEY *key, int len, const unsigned char *data); + +void BF_encrypt(BF_LONG *data, const BF_KEY *key); +void BF_decrypt(BF_LONG *data, const BF_KEY *key); + +void BF_ecb_encrypt(const unsigned char *in, unsigned char *out, + const BF_KEY *key, int enc); +void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + const BF_KEY *schedule, unsigned char *ivec, int enc); +void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, const BF_KEY *schedule, + unsigned char *ivec, int *num, int enc); +void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, const BF_KEY *schedule, + unsigned char *ivec, int *num); +const char *BF_options(void); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/bn.h b/android/x86/include/openssl/bn.h new file mode 100644 index 00000000..17bd5213 --- /dev/null +++ b/android/x86/include/openssl/bn.h @@ -0,0 +1,575 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * + * Portions of the attached software ("Contribution") are developed by + * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. + * + * The Contribution is licensed pursuant to the Eric Young open source + * license provided above. + * + * The binary polynomial arithmetic software is originally written by + * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. + * + */ + +#ifndef HEADER_BN_H +# define HEADER_BN_H + +# include <openssl/e_os2.h> +# ifndef OPENSSL_NO_STDIO +# include <stdio.h> +# endif +# include <openssl/opensslconf.h> +# include <openssl/ossl_typ.h> +# include <openssl/crypto.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * 64-bit processor with LP64 ABI + */ +# ifdef SIXTY_FOUR_BIT_LONG +# define BN_ULONG unsigned long +# define BN_BYTES 8 +# endif + +/* + * 64-bit processor other than LP64 ABI + */ +# ifdef SIXTY_FOUR_BIT +# define BN_ULONG unsigned long long +# define BN_BYTES 8 +# endif + +# ifdef THIRTY_TWO_BIT +# define BN_ULONG unsigned int +# define BN_BYTES 4 +# endif + +# define BN_BITS2 (BN_BYTES * 8) +# define BN_BITS (BN_BITS2 * 2) +# define BN_TBIT ((BN_ULONG)1 << (BN_BITS2 - 1)) + +# define BN_FLG_MALLOCED 0x01 +# define BN_FLG_STATIC_DATA 0x02 + +/* + * avoid leaking exponent information through timing, + * BN_mod_exp_mont() will call BN_mod_exp_mont_consttime, + * BN_div() will call BN_div_no_branch, + * BN_mod_inverse() will call BN_mod_inverse_no_branch. + */ +# define BN_FLG_CONSTTIME 0x04 +# define BN_FLG_SECURE 0x08 + +# if OPENSSL_API_COMPAT < 0x00908000L +/* deprecated name for the flag */ +# define BN_FLG_EXP_CONSTTIME BN_FLG_CONSTTIME +# define BN_FLG_FREE 0x8000 /* used for debugging */ +# endif + +void BN_set_flags(BIGNUM *b, int n); +int BN_get_flags(const BIGNUM *b, int n); + +/* Values for |top| in BN_rand() */ +#define BN_RAND_TOP_ANY -1 +#define BN_RAND_TOP_ONE 0 +#define BN_RAND_TOP_TWO 1 + +/* Values for |bottom| in BN_rand() */ +#define BN_RAND_BOTTOM_ANY 0 +#define BN_RAND_BOTTOM_ODD 1 + +/* + * get a clone of a BIGNUM with changed flags, for *temporary* use only (the + * two BIGNUMs cannot be used in parallel!). Also only for *read only* use. The + * value |dest| should be a newly allocated BIGNUM obtained via BN_new() that + * has not been otherwise initialised or used. + */ +void BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags); + +/* Wrapper function to make using BN_GENCB easier */ +int BN_GENCB_call(BN_GENCB *cb, int a, int b); + +BN_GENCB *BN_GENCB_new(void); +void BN_GENCB_free(BN_GENCB *cb); + +/* Populate a BN_GENCB structure with an "old"-style callback */ +void BN_GENCB_set_old(BN_GENCB *gencb, void (*callback) (int, int, void *), + void *cb_arg); + +/* Populate a BN_GENCB structure with a "new"-style callback */ +void BN_GENCB_set(BN_GENCB *gencb, int (*callback) (int, int, BN_GENCB *), + void *cb_arg); + +void *BN_GENCB_get_arg(BN_GENCB *cb); + +# define BN_prime_checks 0 /* default: select number of iterations based + * on the size of the number */ + +/* + * number of Miller-Rabin iterations for an error rate of less than 2^-80 for + * random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook of + * Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996]; + * original paper: Damgaard, Landrock, Pomerance: Average case error + * estimates for the strong probable prime test. -- Math. Comp. 61 (1993) + * 177-194) + */ +# define BN_prime_checks_for_size(b) ((b) >= 1300 ? 2 : \ + (b) >= 850 ? 3 : \ + (b) >= 650 ? 4 : \ + (b) >= 550 ? 5 : \ + (b) >= 450 ? 6 : \ + (b) >= 400 ? 7 : \ + (b) >= 350 ? 8 : \ + (b) >= 300 ? 9 : \ + (b) >= 250 ? 12 : \ + (b) >= 200 ? 15 : \ + (b) >= 150 ? 18 : \ + /* b >= 100 */ 27) + +# define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) + +int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w); +int BN_is_zero(const BIGNUM *a); +int BN_is_one(const BIGNUM *a); +int BN_is_word(const BIGNUM *a, const BN_ULONG w); +int BN_is_odd(const BIGNUM *a); + +# define BN_one(a) (BN_set_word((a),1)) + +void BN_zero_ex(BIGNUM *a); + +# if OPENSSL_API_COMPAT >= 0x00908000L +# define BN_zero(a) BN_zero_ex(a) +# else +# define BN_zero(a) (BN_set_word((a),0)) +# endif + +const BIGNUM *BN_value_one(void); +char *BN_options(void); +BN_CTX *BN_CTX_new(void); +BN_CTX *BN_CTX_secure_new(void); +void BN_CTX_free(BN_CTX *c); +void BN_CTX_start(BN_CTX *ctx); +BIGNUM *BN_CTX_get(BN_CTX *ctx); +void BN_CTX_end(BN_CTX *ctx); +int BN_rand(BIGNUM *rnd, int bits, int top, int bottom); +int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom); +int BN_rand_range(BIGNUM *rnd, const BIGNUM *range); +int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range); +int BN_num_bits(const BIGNUM *a); +int BN_num_bits_word(BN_ULONG l); +int BN_security_bits(int L, int N); +BIGNUM *BN_new(void); +BIGNUM *BN_secure_new(void); +void BN_clear_free(BIGNUM *a); +BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); +void BN_swap(BIGNUM *a, BIGNUM *b); +BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret); +int BN_bn2bin(const BIGNUM *a, unsigned char *to); +int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen); +BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret); +int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen); +BIGNUM *BN_mpi2bn(const unsigned char *s, int len, BIGNUM *ret); +int BN_bn2mpi(const BIGNUM *a, unsigned char *to); +int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); +int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx); +/** BN_set_negative sets sign of a BIGNUM + * \param b pointer to the BIGNUM object + * \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise + */ +void BN_set_negative(BIGNUM *b, int n); +/** BN_is_negative returns 1 if the BIGNUM is negative + * \param a pointer to the BIGNUM object + * \return 1 if a < 0 and 0 otherwise + */ +int BN_is_negative(const BIGNUM *b); + +int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, + BN_CTX *ctx); +# define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx)) +int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); +int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, + BN_CTX *ctx); +int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *m); +int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, + BN_CTX *ctx); +int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *m); +int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, + BN_CTX *ctx); +int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); +int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); +int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m); +int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, + BN_CTX *ctx); +int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m); + +BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w); +BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); +int BN_mul_word(BIGNUM *a, BN_ULONG w); +int BN_add_word(BIGNUM *a, BN_ULONG w); +int BN_sub_word(BIGNUM *a, BN_ULONG w); +int BN_set_word(BIGNUM *a, BN_ULONG w); +BN_ULONG BN_get_word(const BIGNUM *a); + +int BN_cmp(const BIGNUM *a, const BIGNUM *b); +void BN_free(BIGNUM *a); +int BN_is_bit_set(const BIGNUM *a, int n); +int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); +int BN_lshift1(BIGNUM *r, const BIGNUM *a); +int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); + +int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); +int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, + BN_MONT_CTX *in_mont); +int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1, + const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m, + BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); + +int BN_mask_bits(BIGNUM *a, int n); +# ifndef OPENSSL_NO_STDIO +int BN_print_fp(FILE *fp, const BIGNUM *a); +# endif +int BN_print(BIO *bio, const BIGNUM *a); +int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx); +int BN_rshift(BIGNUM *r, const BIGNUM *a, int n); +int BN_rshift1(BIGNUM *r, const BIGNUM *a); +void BN_clear(BIGNUM *a); +BIGNUM *BN_dup(const BIGNUM *a); +int BN_ucmp(const BIGNUM *a, const BIGNUM *b); +int BN_set_bit(BIGNUM *a, int n); +int BN_clear_bit(BIGNUM *a, int n); +char *BN_bn2hex(const BIGNUM *a); +char *BN_bn2dec(const BIGNUM *a); +int BN_hex2bn(BIGNUM **a, const char *str); +int BN_dec2bn(BIGNUM **a, const char *str); +int BN_asc2bn(BIGNUM **a, const char *str); +int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); +int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); /* returns + * -2 for + * error */ +BIGNUM *BN_mod_inverse(BIGNUM *ret, + const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx); +BIGNUM *BN_mod_sqrt(BIGNUM *ret, + const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx); + +void BN_consttime_swap(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords); + +/* Deprecated versions */ +DEPRECATEDIN_0_9_8(BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, + const BIGNUM *add, + const BIGNUM *rem, + void (*callback) (int, int, + void *), + void *cb_arg)) +DEPRECATEDIN_0_9_8(int + BN_is_prime(const BIGNUM *p, int nchecks, + void (*callback) (int, int, void *), + BN_CTX *ctx, void *cb_arg)) +DEPRECATEDIN_0_9_8(int + BN_is_prime_fasttest(const BIGNUM *p, int nchecks, + void (*callback) (int, int, void *), + BN_CTX *ctx, void *cb_arg, + int do_trial_division)) + +/* Newer versions */ +int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, + const BIGNUM *rem, BN_GENCB *cb); +int BN_is_prime_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, BN_GENCB *cb); +int BN_is_prime_fasttest_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, + int do_trial_division, BN_GENCB *cb); + +int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx); + +int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, + const BIGNUM *Xp, const BIGNUM *Xp1, + const BIGNUM *Xp2, const BIGNUM *e, BN_CTX *ctx, + BN_GENCB *cb); +int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, BIGNUM *Xp1, + BIGNUM *Xp2, const BIGNUM *Xp, const BIGNUM *e, + BN_CTX *ctx, BN_GENCB *cb); + +BN_MONT_CTX *BN_MONT_CTX_new(void); +int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + BN_MONT_CTX *mont, BN_CTX *ctx); +int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, + BN_CTX *ctx); +int BN_from_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, + BN_CTX *ctx); +void BN_MONT_CTX_free(BN_MONT_CTX *mont); +int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx); +BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from); +BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock, + const BIGNUM *mod, BN_CTX *ctx); + +/* BN_BLINDING flags */ +# define BN_BLINDING_NO_UPDATE 0x00000001 +# define BN_BLINDING_NO_RECREATE 0x00000002 + +BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod); +void BN_BLINDING_free(BN_BLINDING *b); +int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx); +int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); +int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); +int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *); +int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, + BN_CTX *); + +int BN_BLINDING_is_current_thread(BN_BLINDING *b); +void BN_BLINDING_set_current_thread(BN_BLINDING *b); +int BN_BLINDING_lock(BN_BLINDING *b); +int BN_BLINDING_unlock(BN_BLINDING *b); + +unsigned long BN_BLINDING_get_flags(const BN_BLINDING *); +void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long); +BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b, + const BIGNUM *e, BIGNUM *m, BN_CTX *ctx, + int (*bn_mod_exp) (BIGNUM *r, + const BIGNUM *a, + const BIGNUM *p, + const BIGNUM *m, + BN_CTX *ctx, + BN_MONT_CTX *m_ctx), + BN_MONT_CTX *m_ctx); + +DEPRECATEDIN_0_9_8(void BN_set_params(int mul, int high, int low, int mont)) +DEPRECATEDIN_0_9_8(int BN_get_params(int which)) /* 0, mul, 1 high, 2 low, 3 + * mont */ + +BN_RECP_CTX *BN_RECP_CTX_new(void); +void BN_RECP_CTX_free(BN_RECP_CTX *recp); +int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *rdiv, BN_CTX *ctx); +int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, + BN_RECP_CTX *recp, BN_CTX *ctx); +int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); +int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, + BN_RECP_CTX *recp, BN_CTX *ctx); + +# ifndef OPENSSL_NO_EC2M + +/* + * Functions for arithmetic over binary polynomials represented by BIGNUMs. + * The BIGNUM::neg property of BIGNUMs representing binary polynomials is + * ignored. Note that input arguments are not const so that their bit arrays + * can be expanded to the appropriate size if needed. + */ + +/* + * r = a + b + */ +int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +# define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b) +/* + * r=a mod p + */ +int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); +/* r = (a * b) mod p */ +int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *p, BN_CTX *ctx); +/* r = (a * a) mod p */ +int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +/* r = (1 / b) mod p */ +int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p, BN_CTX *ctx); +/* r = (a / b) mod p */ +int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *p, BN_CTX *ctx); +/* r = (a ^ b) mod p */ +int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *p, BN_CTX *ctx); +/* r = sqrt(a) mod p */ +int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + BN_CTX *ctx); +/* r^2 + r = a mod p */ +int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + BN_CTX *ctx); +# define BN_GF2m_cmp(a, b) BN_ucmp((a), (b)) +/*- + * Some functions allow for representation of the irreducible polynomials + * as an unsigned int[], say p. The irreducible f(t) is then of the form: + * t^p[0] + t^p[1] + ... + t^p[k] + * where m = p[0] > p[1] > ... > p[k] = 0. + */ +/* r = a mod p */ +int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]); +/* r = (a * b) mod p */ +int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const int p[], BN_CTX *ctx); +/* r = (a * a) mod p */ +int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], + BN_CTX *ctx); +/* r = (1 / b) mod p */ +int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const int p[], + BN_CTX *ctx); +/* r = (a / b) mod p */ +int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const int p[], BN_CTX *ctx); +/* r = (a ^ b) mod p */ +int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const int p[], BN_CTX *ctx); +/* r = sqrt(a) mod p */ +int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, + const int p[], BN_CTX *ctx); +/* r^2 + r = a mod p */ +int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a, + const int p[], BN_CTX *ctx); +int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max); +int BN_GF2m_arr2poly(const int p[], BIGNUM *a); + +# endif + +/* + * faster mod functions for the 'NIST primes' 0 <= a < p^2 + */ +int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); + +const BIGNUM *BN_get0_nist_prime_192(void); +const BIGNUM *BN_get0_nist_prime_224(void); +const BIGNUM *BN_get0_nist_prime_256(void); +const BIGNUM *BN_get0_nist_prime_384(void); +const BIGNUM *BN_get0_nist_prime_521(void); + +int (*BN_nist_mod_func(const BIGNUM *p)) (BIGNUM *r, const BIGNUM *a, + const BIGNUM *field, BN_CTX *ctx); + +int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range, + const BIGNUM *priv, const unsigned char *message, + size_t message_len, BN_CTX *ctx); + +/* Primes from RFC 2409 */ +BIGNUM *BN_get_rfc2409_prime_768(BIGNUM *bn); +BIGNUM *BN_get_rfc2409_prime_1024(BIGNUM *bn); + +/* Primes from RFC 3526 */ +BIGNUM *BN_get_rfc3526_prime_1536(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_2048(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_3072(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_4096(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_6144(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_8192(BIGNUM *bn); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define get_rfc2409_prime_768 BN_get_rfc2409_prime_768 +# define get_rfc2409_prime_1024 BN_get_rfc2409_prime_1024 +# define get_rfc3526_prime_1536 BN_get_rfc3526_prime_1536 +# define get_rfc3526_prime_2048 BN_get_rfc3526_prime_2048 +# define get_rfc3526_prime_3072 BN_get_rfc3526_prime_3072 +# define get_rfc3526_prime_4096 BN_get_rfc3526_prime_4096 +# define get_rfc3526_prime_6144 BN_get_rfc3526_prime_6144 +# define get_rfc3526_prime_8192 BN_get_rfc3526_prime_8192 +# endif + +int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_BN_strings(void); + +/* Error codes for the BN functions. */ + +/* Function codes. */ +# define BN_F_BNRAND 127 +# define BN_F_BN_BLINDING_CONVERT_EX 100 +# define BN_F_BN_BLINDING_CREATE_PARAM 128 +# define BN_F_BN_BLINDING_INVERT_EX 101 +# define BN_F_BN_BLINDING_NEW 102 +# define BN_F_BN_BLINDING_UPDATE 103 +# define BN_F_BN_BN2DEC 104 +# define BN_F_BN_BN2HEX 105 +# define BN_F_BN_COMPUTE_WNAF 142 +# define BN_F_BN_CTX_GET 116 +# define BN_F_BN_CTX_NEW 106 +# define BN_F_BN_CTX_START 129 +# define BN_F_BN_DIV 107 +# define BN_F_BN_DIV_RECP 130 +# define BN_F_BN_EXP 123 +# define BN_F_BN_EXPAND_INTERNAL 120 +# define BN_F_BN_GENCB_NEW 143 +# define BN_F_BN_GENERATE_DSA_NONCE 140 +# define BN_F_BN_GENERATE_PRIME_EX 141 +# define BN_F_BN_GF2M_MOD 131 +# define BN_F_BN_GF2M_MOD_EXP 132 +# define BN_F_BN_GF2M_MOD_MUL 133 +# define BN_F_BN_GF2M_MOD_SOLVE_QUAD 134 +# define BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR 135 +# define BN_F_BN_GF2M_MOD_SQR 136 +# define BN_F_BN_GF2M_MOD_SQRT 137 +# define BN_F_BN_LSHIFT 145 +# define BN_F_BN_MOD_EXP2_MONT 118 +# define BN_F_BN_MOD_EXP_MONT 109 +# define BN_F_BN_MOD_EXP_MONT_CONSTTIME 124 +# define BN_F_BN_MOD_EXP_MONT_WORD 117 +# define BN_F_BN_MOD_EXP_RECP 125 +# define BN_F_BN_MOD_EXP_SIMPLE 126 +# define BN_F_BN_MOD_INVERSE 110 +# define BN_F_BN_MOD_INVERSE_NO_BRANCH 139 +# define BN_F_BN_MOD_LSHIFT_QUICK 119 +# define BN_F_BN_MOD_SQRT 121 +# define BN_F_BN_MPI2BN 112 +# define BN_F_BN_NEW 113 +# define BN_F_BN_RAND 114 +# define BN_F_BN_RAND_RANGE 122 +# define BN_F_BN_RSHIFT 146 +# define BN_F_BN_SET_WORDS 144 +# define BN_F_BN_USUB 115 + +/* Reason codes. */ +# define BN_R_ARG2_LT_ARG3 100 +# define BN_R_BAD_RECIPROCAL 101 +# define BN_R_BIGNUM_TOO_LONG 114 +# define BN_R_BITS_TOO_SMALL 118 +# define BN_R_CALLED_WITH_EVEN_MODULUS 102 +# define BN_R_DIV_BY_ZERO 103 +# define BN_R_ENCODING_ERROR 104 +# define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105 +# define BN_R_INPUT_NOT_REDUCED 110 +# define BN_R_INVALID_LENGTH 106 +# define BN_R_INVALID_RANGE 115 +# define BN_R_INVALID_SHIFT 119 +# define BN_R_NOT_A_SQUARE 111 +# define BN_R_NOT_INITIALIZED 107 +# define BN_R_NO_INVERSE 108 +# define BN_R_NO_SOLUTION 116 +# define BN_R_PRIVATE_KEY_TOO_LARGE 117 +# define BN_R_P_IS_NOT_PRIME 112 +# define BN_R_TOO_MANY_ITERATIONS 113 +# define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/buffer.h b/android/x86/include/openssl/buffer.h new file mode 100644 index 00000000..91f0e07f --- /dev/null +++ b/android/x86/include/openssl/buffer.h @@ -0,0 +1,76 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BUFFER_H +# define HEADER_BUFFER_H + +# include <openssl/ossl_typ.h> +# ifndef HEADER_CRYPTO_H +# include <openssl/crypto.h> +# endif + + +#ifdef __cplusplus +extern "C" { +#endif + +# include <stddef.h> + +# if !defined(NO_SYS_TYPES_H) +# include <sys/types.h> +# endif + +/* + * These names are outdated as of OpenSSL 1.1; a future release + * will move them to be deprecated. + */ +# define BUF_strdup(s) OPENSSL_strdup(s) +# define BUF_strndup(s, size) OPENSSL_strndup(s, size) +# define BUF_memdup(data, size) OPENSSL_memdup(data, size) +# define BUF_strlcpy(dst, src, size) OPENSSL_strlcpy(dst, src, size) +# define BUF_strlcat(dst, src, size) OPENSSL_strlcat(dst, src, size) +# define BUF_strnlen(str, maxlen) OPENSSL_strnlen(str, maxlen) + +struct buf_mem_st { + size_t length; /* current number of bytes */ + char *data; + size_t max; /* size of buffer */ + unsigned long flags; +}; + +# define BUF_MEM_FLAG_SECURE 0x01 + +BUF_MEM *BUF_MEM_new(void); +BUF_MEM *BUF_MEM_new_ex(unsigned long flags); +void BUF_MEM_free(BUF_MEM *a); +size_t BUF_MEM_grow(BUF_MEM *str, size_t len); +size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len); +void BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_BUF_strings(void); + +/* Error codes for the BUF functions. */ + +/* Function codes. */ +# define BUF_F_BUF_MEM_GROW 100 +# define BUF_F_BUF_MEM_GROW_CLEAN 105 +# define BUF_F_BUF_MEM_NEW 101 + +/* Reason codes. */ + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/camellia.h b/android/x86/include/openssl/camellia.h new file mode 100644 index 00000000..151f3c13 --- /dev/null +++ b/android/x86/include/openssl/camellia.h @@ -0,0 +1,83 @@ +/* + * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CAMELLIA_H +# define HEADER_CAMELLIA_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_CAMELLIA +# include <stddef.h> +#ifdef __cplusplus +extern "C" { +#endif + +# define CAMELLIA_ENCRYPT 1 +# define CAMELLIA_DECRYPT 0 + +/* + * Because array size can't be a const in C, the following two are macros. + * Both sizes are in bytes. + */ + +/* This should be a hidden type, but EVP requires that the size be known */ + +# define CAMELLIA_BLOCK_SIZE 16 +# define CAMELLIA_TABLE_BYTE_LEN 272 +# define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4) + +typedef unsigned int KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN]; /* to match + * with WORD */ + +struct camellia_key_st { + union { + double d; /* ensures 64-bit align */ + KEY_TABLE_TYPE rd_key; + } u; + int grand_rounds; +}; +typedef struct camellia_key_st CAMELLIA_KEY; + +int Camellia_set_key(const unsigned char *userKey, const int bits, + CAMELLIA_KEY *key); + +void Camellia_encrypt(const unsigned char *in, unsigned char *out, + const CAMELLIA_KEY *key); +void Camellia_decrypt(const unsigned char *in, unsigned char *out, + const CAMELLIA_KEY *key); + +void Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out, + const CAMELLIA_KEY *key, const int enc); +void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, const int enc); +void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, int *num, const int enc); +void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, int *num, const int enc); +void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, int *num, const int enc); +void Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, int *num); +void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char ivec[CAMELLIA_BLOCK_SIZE], + unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE], + unsigned int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/cast.h b/android/x86/include/openssl/cast.h new file mode 100644 index 00000000..2cc89ae0 --- /dev/null +++ b/android/x86/include/openssl/cast.h @@ -0,0 +1,53 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CAST_H +# define HEADER_CAST_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_CAST +# ifdef __cplusplus +extern "C" { +# endif + +# define CAST_ENCRYPT 1 +# define CAST_DECRYPT 0 + +# define CAST_LONG unsigned int + +# define CAST_BLOCK 8 +# define CAST_KEY_LENGTH 16 + +typedef struct cast_key_st { + CAST_LONG data[32]; + int short_key; /* Use reduced rounds for short key */ +} CAST_KEY; + +void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); +void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, + const CAST_KEY *key, int enc); +void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key); +void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key); +void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, + long length, const CAST_KEY *ks, unsigned char *iv, + int enc); +void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, const CAST_KEY *schedule, + unsigned char *ivec, int *num, int enc); +void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, const CAST_KEY *schedule, + unsigned char *ivec, int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/cmac.h b/android/x86/include/openssl/cmac.h new file mode 100644 index 00000000..3535a9ab --- /dev/null +++ b/android/x86/include/openssl/cmac.h @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CMAC_H +# define HEADER_CMAC_H + +# ifndef OPENSSL_NO_CMAC + +#ifdef __cplusplus +extern "C" { +#endif + +# include <openssl/evp.h> + +/* Opaque */ +typedef struct CMAC_CTX_st CMAC_CTX; + +CMAC_CTX *CMAC_CTX_new(void); +void CMAC_CTX_cleanup(CMAC_CTX *ctx); +void CMAC_CTX_free(CMAC_CTX *ctx); +EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx); +int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in); + +int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen, + const EVP_CIPHER *cipher, ENGINE *impl); +int CMAC_Update(CMAC_CTX *ctx, const void *data, size_t dlen); +int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen); +int CMAC_resume(CMAC_CTX *ctx); + +#ifdef __cplusplus +} +#endif + +# endif +#endif diff --git a/android/x86/include/openssl/cms.h b/android/x86/include/openssl/cms.h new file mode 100644 index 00000000..7e534e0d --- /dev/null +++ b/android/x86/include/openssl/cms.h @@ -0,0 +1,512 @@ +/* + * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CMS_H +# define HEADER_CMS_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_CMS +# include <openssl/x509.h> +# include <openssl/x509v3.h> +# ifdef __cplusplus +extern "C" { +# endif + +typedef struct CMS_ContentInfo_st CMS_ContentInfo; +typedef struct CMS_SignerInfo_st CMS_SignerInfo; +typedef struct CMS_CertificateChoices CMS_CertificateChoices; +typedef struct CMS_RevocationInfoChoice_st CMS_RevocationInfoChoice; +typedef struct CMS_RecipientInfo_st CMS_RecipientInfo; +typedef struct CMS_ReceiptRequest_st CMS_ReceiptRequest; +typedef struct CMS_Receipt_st CMS_Receipt; +typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey; +typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute; + +DEFINE_STACK_OF(CMS_SignerInfo) +DEFINE_STACK_OF(CMS_RecipientEncryptedKey) +DEFINE_STACK_OF(CMS_RecipientInfo) +DEFINE_STACK_OF(CMS_RevocationInfoChoice) +DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo) +DECLARE_ASN1_FUNCTIONS(CMS_ReceiptRequest) +DECLARE_ASN1_PRINT_FUNCTION(CMS_ContentInfo) + +# define CMS_SIGNERINFO_ISSUER_SERIAL 0 +# define CMS_SIGNERINFO_KEYIDENTIFIER 1 + +# define CMS_RECIPINFO_NONE -1 +# define CMS_RECIPINFO_TRANS 0 +# define CMS_RECIPINFO_AGREE 1 +# define CMS_RECIPINFO_KEK 2 +# define CMS_RECIPINFO_PASS 3 +# define CMS_RECIPINFO_OTHER 4 + +/* S/MIME related flags */ + +# define CMS_TEXT 0x1 +# define CMS_NOCERTS 0x2 +# define CMS_NO_CONTENT_VERIFY 0x4 +# define CMS_NO_ATTR_VERIFY 0x8 +# define CMS_NOSIGS \ + (CMS_NO_CONTENT_VERIFY|CMS_NO_ATTR_VERIFY) +# define CMS_NOINTERN 0x10 +# define CMS_NO_SIGNER_CERT_VERIFY 0x20 +# define CMS_NOVERIFY 0x20 +# define CMS_DETACHED 0x40 +# define CMS_BINARY 0x80 +# define CMS_NOATTR 0x100 +# define CMS_NOSMIMECAP 0x200 +# define CMS_NOOLDMIMETYPE 0x400 +# define CMS_CRLFEOL 0x800 +# define CMS_STREAM 0x1000 +# define CMS_NOCRL 0x2000 +# define CMS_PARTIAL 0x4000 +# define CMS_REUSE_DIGEST 0x8000 +# define CMS_USE_KEYID 0x10000 +# define CMS_DEBUG_DECRYPT 0x20000 +# define CMS_KEY_PARAM 0x40000 +# define CMS_ASCIICRLF 0x80000 + +const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms); + +BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont); +int CMS_dataFinal(CMS_ContentInfo *cms, BIO *bio); + +ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms); +int CMS_is_detached(CMS_ContentInfo *cms); +int CMS_set_detached(CMS_ContentInfo *cms, int detached); + +# ifdef HEADER_PEM_H +DECLARE_PEM_rw_const(CMS, CMS_ContentInfo) +# endif +int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms); +CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms); +int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms); + +BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms); +int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags); +int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, + int flags); +CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont); +int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags); + +int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, + unsigned int flags); + +CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, + STACK_OF(X509) *certs, BIO *data, + unsigned int flags); + +CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, + X509 *signcert, EVP_PKEY *pkey, + STACK_OF(X509) *certs, unsigned int flags); + +int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags); +CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags); + +int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, + unsigned int flags); +CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md, + unsigned int flags); + +int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, + const unsigned char *key, size_t keylen, + BIO *dcont, BIO *out, unsigned int flags); + +CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, + const unsigned char *key, + size_t keylen, unsigned int flags); + +int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph, + const unsigned char *key, size_t keylen); + +int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, + X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags); + +int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms, + STACK_OF(X509) *certs, + X509_STORE *store, unsigned int flags); + +STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms); + +CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in, + const EVP_CIPHER *cipher, unsigned int flags); + +int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert, + BIO *dcont, BIO *out, unsigned int flags); + +int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert); +int CMS_decrypt_set1_key(CMS_ContentInfo *cms, + unsigned char *key, size_t keylen, + const unsigned char *id, size_t idlen); +int CMS_decrypt_set1_password(CMS_ContentInfo *cms, + unsigned char *pass, ossl_ssize_t passlen); + +STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms); +int CMS_RecipientInfo_type(CMS_RecipientInfo *ri); +EVP_PKEY_CTX *CMS_RecipientInfo_get0_pkey_ctx(CMS_RecipientInfo *ri); +CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher); +CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms, + X509 *recip, unsigned int flags); +int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey); +int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert); +int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri, + EVP_PKEY **pk, X509 **recip, + X509_ALGOR **palg); +int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri, + ASN1_OCTET_STRING **keyid, + X509_NAME **issuer, + ASN1_INTEGER **sno); + +CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid, + unsigned char *key, size_t keylen, + unsigned char *id, size_t idlen, + ASN1_GENERALIZEDTIME *date, + ASN1_OBJECT *otherTypeId, + ASN1_TYPE *otherType); + +int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri, + X509_ALGOR **palg, + ASN1_OCTET_STRING **pid, + ASN1_GENERALIZEDTIME **pdate, + ASN1_OBJECT **potherid, + ASN1_TYPE **pothertype); + +int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri, + unsigned char *key, size_t keylen); + +int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri, + const unsigned char *id, size_t idlen); + +int CMS_RecipientInfo_set0_password(CMS_RecipientInfo *ri, + unsigned char *pass, + ossl_ssize_t passlen); + +CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms, + int iter, int wrap_nid, + int pbe_nid, + unsigned char *pass, + ossl_ssize_t passlen, + const EVP_CIPHER *kekciph); + +int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri); +int CMS_RecipientInfo_encrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri); + +int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, + unsigned int flags); +CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags); + +int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid); +const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms); + +CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms); +int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert); +int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert); +STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms); + +CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms); +int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl); +int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl); +STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms); + +int CMS_SignedData_init(CMS_ContentInfo *cms); +CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, + X509 *signer, EVP_PKEY *pk, const EVP_MD *md, + unsigned int flags); +EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si); +EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si); +STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms); + +void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer); +int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si, + ASN1_OCTET_STRING **keyid, + X509_NAME **issuer, ASN1_INTEGER **sno); +int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert); +int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *certs, + unsigned int flags); +void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, + X509 **signer, X509_ALGOR **pdig, + X509_ALGOR **psig); +ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si); +int CMS_SignerInfo_sign(CMS_SignerInfo *si); +int CMS_SignerInfo_verify(CMS_SignerInfo *si); +int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain); + +int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs); +int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs, + int algnid, int keysize); +int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap); + +int CMS_signed_get_attr_count(const CMS_SignerInfo *si); +int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, + int lastpos); +int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj, + int lastpos); +X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc); +X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc); +int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); +int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si, + const ASN1_OBJECT *obj, int type, + const void *bytes, int len); +int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si, + int nid, int type, + const void *bytes, int len); +int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si, + const char *attrname, int type, + const void *bytes, int len); +void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *oid, + int lastpos, int type); + +int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si); +int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid, + int lastpos); +int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, + const ASN1_OBJECT *obj, int lastpos); +X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc); +X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc); +int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); +int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si, + const ASN1_OBJECT *obj, int type, + const void *bytes, int len); +int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si, + int nid, int type, + const void *bytes, int len); +int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si, + const char *attrname, int type, + const void *bytes, int len); +void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid, + int lastpos, int type); + +# ifdef HEADER_X509V3_H + +int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr); +CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen, + int allorfirst, + STACK_OF(GENERAL_NAMES) + *receiptList, STACK_OF(GENERAL_NAMES) + *receiptsTo); +int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr); +void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, + ASN1_STRING **pcid, + int *pallorfirst, + STACK_OF(GENERAL_NAMES) **plist, + STACK_OF(GENERAL_NAMES) **prto); +# endif +int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri, + X509_ALGOR **palg, + ASN1_OCTET_STRING **pukm); +STACK_OF(CMS_RecipientEncryptedKey) +*CMS_RecipientInfo_kari_get0_reks(CMS_RecipientInfo *ri); + +int CMS_RecipientInfo_kari_get0_orig_id(CMS_RecipientInfo *ri, + X509_ALGOR **pubalg, + ASN1_BIT_STRING **pubkey, + ASN1_OCTET_STRING **keyid, + X509_NAME **issuer, + ASN1_INTEGER **sno); + +int CMS_RecipientInfo_kari_orig_id_cmp(CMS_RecipientInfo *ri, X509 *cert); + +int CMS_RecipientEncryptedKey_get0_id(CMS_RecipientEncryptedKey *rek, + ASN1_OCTET_STRING **keyid, + ASN1_GENERALIZEDTIME **tm, + CMS_OtherKeyAttribute **other, + X509_NAME **issuer, ASN1_INTEGER **sno); +int CMS_RecipientEncryptedKey_cert_cmp(CMS_RecipientEncryptedKey *rek, + X509 *cert); +int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk); +EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri); +int CMS_RecipientInfo_kari_decrypt(CMS_ContentInfo *cms, + CMS_RecipientInfo *ri, + CMS_RecipientEncryptedKey *rek); + +int CMS_SharedInfo_encode(unsigned char **pder, X509_ALGOR *kekalg, + ASN1_OCTET_STRING *ukm, int keylen); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_CMS_strings(void); + +/* Error codes for the CMS functions. */ + +/* Function codes. */ +# define CMS_F_CHECK_CONTENT 99 +# define CMS_F_CMS_ADD0_CERT 164 +# define CMS_F_CMS_ADD0_RECIPIENT_KEY 100 +# define CMS_F_CMS_ADD0_RECIPIENT_PASSWORD 165 +# define CMS_F_CMS_ADD1_RECEIPTREQUEST 158 +# define CMS_F_CMS_ADD1_RECIPIENT_CERT 101 +# define CMS_F_CMS_ADD1_SIGNER 102 +# define CMS_F_CMS_ADD1_SIGNINGTIME 103 +# define CMS_F_CMS_COMPRESS 104 +# define CMS_F_CMS_COMPRESSEDDATA_CREATE 105 +# define CMS_F_CMS_COMPRESSEDDATA_INIT_BIO 106 +# define CMS_F_CMS_COPY_CONTENT 107 +# define CMS_F_CMS_COPY_MESSAGEDIGEST 108 +# define CMS_F_CMS_DATA 109 +# define CMS_F_CMS_DATAFINAL 110 +# define CMS_F_CMS_DATAINIT 111 +# define CMS_F_CMS_DECRYPT 112 +# define CMS_F_CMS_DECRYPT_SET1_KEY 113 +# define CMS_F_CMS_DECRYPT_SET1_PASSWORD 166 +# define CMS_F_CMS_DECRYPT_SET1_PKEY 114 +# define CMS_F_CMS_DIGESTALGORITHM_FIND_CTX 115 +# define CMS_F_CMS_DIGESTALGORITHM_INIT_BIO 116 +# define CMS_F_CMS_DIGESTEDDATA_DO_FINAL 117 +# define CMS_F_CMS_DIGEST_VERIFY 118 +# define CMS_F_CMS_ENCODE_RECEIPT 161 +# define CMS_F_CMS_ENCRYPT 119 +# define CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO 120 +# define CMS_F_CMS_ENCRYPTEDDATA_DECRYPT 121 +# define CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT 122 +# define CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY 123 +# define CMS_F_CMS_ENVELOPEDDATA_CREATE 124 +# define CMS_F_CMS_ENVELOPEDDATA_INIT_BIO 125 +# define CMS_F_CMS_ENVELOPED_DATA_INIT 126 +# define CMS_F_CMS_ENV_ASN1_CTRL 171 +# define CMS_F_CMS_FINAL 127 +# define CMS_F_CMS_GET0_CERTIFICATE_CHOICES 128 +# define CMS_F_CMS_GET0_CONTENT 129 +# define CMS_F_CMS_GET0_ECONTENT_TYPE 130 +# define CMS_F_CMS_GET0_ENVELOPED 131 +# define CMS_F_CMS_GET0_REVOCATION_CHOICES 132 +# define CMS_F_CMS_GET0_SIGNED 133 +# define CMS_F_CMS_MSGSIGDIGEST_ADD1 162 +# define CMS_F_CMS_RECEIPTREQUEST_CREATE0 159 +# define CMS_F_CMS_RECEIPT_VERIFY 160 +# define CMS_F_CMS_RECIPIENTINFO_DECRYPT 134 +# define CMS_F_CMS_RECIPIENTINFO_ENCRYPT 169 +# define CMS_F_CMS_RECIPIENTINFO_KARI_ENCRYPT 178 +# define CMS_F_CMS_RECIPIENTINFO_KARI_GET0_ALG 175 +# define CMS_F_CMS_RECIPIENTINFO_KARI_GET0_ORIG_ID 173 +# define CMS_F_CMS_RECIPIENTINFO_KARI_GET0_REKS 172 +# define CMS_F_CMS_RECIPIENTINFO_KARI_ORIG_ID_CMP 174 +# define CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT 135 +# define CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT 136 +# define CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID 137 +# define CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP 138 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP 139 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT 140 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT 141 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS 142 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID 143 +# define CMS_F_CMS_RECIPIENTINFO_PWRI_CRYPT 167 +# define CMS_F_CMS_RECIPIENTINFO_SET0_KEY 144 +# define CMS_F_CMS_RECIPIENTINFO_SET0_PASSWORD 168 +# define CMS_F_CMS_RECIPIENTINFO_SET0_PKEY 145 +# define CMS_F_CMS_SD_ASN1_CTRL 170 +# define CMS_F_CMS_SET1_IAS 176 +# define CMS_F_CMS_SET1_KEYID 177 +# define CMS_F_CMS_SET1_SIGNERIDENTIFIER 146 +# define CMS_F_CMS_SET_DETACHED 147 +# define CMS_F_CMS_SIGN 148 +# define CMS_F_CMS_SIGNED_DATA_INIT 149 +# define CMS_F_CMS_SIGNERINFO_CONTENT_SIGN 150 +# define CMS_F_CMS_SIGNERINFO_SIGN 151 +# define CMS_F_CMS_SIGNERINFO_VERIFY 152 +# define CMS_F_CMS_SIGNERINFO_VERIFY_CERT 153 +# define CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT 154 +# define CMS_F_CMS_SIGN_RECEIPT 163 +# define CMS_F_CMS_STREAM 155 +# define CMS_F_CMS_UNCOMPRESS 156 +# define CMS_F_CMS_VERIFY 157 + +/* Reason codes. */ +# define CMS_R_ADD_SIGNER_ERROR 99 +# define CMS_R_CERTIFICATE_ALREADY_PRESENT 175 +# define CMS_R_CERTIFICATE_HAS_NO_KEYID 160 +# define CMS_R_CERTIFICATE_VERIFY_ERROR 100 +# define CMS_R_CIPHER_INITIALISATION_ERROR 101 +# define CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR 102 +# define CMS_R_CMS_DATAFINAL_ERROR 103 +# define CMS_R_CMS_LIB 104 +# define CMS_R_CONTENTIDENTIFIER_MISMATCH 170 +# define CMS_R_CONTENT_NOT_FOUND 105 +# define CMS_R_CONTENT_TYPE_MISMATCH 171 +# define CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA 106 +# define CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA 107 +# define CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA 108 +# define CMS_R_CONTENT_VERIFY_ERROR 109 +# define CMS_R_CTRL_ERROR 110 +# define CMS_R_CTRL_FAILURE 111 +# define CMS_R_DECRYPT_ERROR 112 +# define CMS_R_ERROR_GETTING_PUBLIC_KEY 113 +# define CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE 114 +# define CMS_R_ERROR_SETTING_KEY 115 +# define CMS_R_ERROR_SETTING_RECIPIENTINFO 116 +# define CMS_R_INVALID_ENCRYPTED_KEY_LENGTH 117 +# define CMS_R_INVALID_KEY_ENCRYPTION_PARAMETER 176 +# define CMS_R_INVALID_KEY_LENGTH 118 +# define CMS_R_MD_BIO_INIT_ERROR 119 +# define CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH 120 +# define CMS_R_MESSAGEDIGEST_WRONG_LENGTH 121 +# define CMS_R_MSGSIGDIGEST_ERROR 172 +# define CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE 162 +# define CMS_R_MSGSIGDIGEST_WRONG_LENGTH 163 +# define CMS_R_NEED_ONE_SIGNER 164 +# define CMS_R_NOT_A_SIGNED_RECEIPT 165 +# define CMS_R_NOT_ENCRYPTED_DATA 122 +# define CMS_R_NOT_KEK 123 +# define CMS_R_NOT_KEY_AGREEMENT 181 +# define CMS_R_NOT_KEY_TRANSPORT 124 +# define CMS_R_NOT_PWRI 177 +# define CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 125 +# define CMS_R_NO_CIPHER 126 +# define CMS_R_NO_CONTENT 127 +# define CMS_R_NO_CONTENT_TYPE 173 +# define CMS_R_NO_DEFAULT_DIGEST 128 +# define CMS_R_NO_DIGEST_SET 129 +# define CMS_R_NO_KEY 130 +# define CMS_R_NO_KEY_OR_CERT 174 +# define CMS_R_NO_MATCHING_DIGEST 131 +# define CMS_R_NO_MATCHING_RECIPIENT 132 +# define CMS_R_NO_MATCHING_SIGNATURE 166 +# define CMS_R_NO_MSGSIGDIGEST 167 +# define CMS_R_NO_PASSWORD 178 +# define CMS_R_NO_PRIVATE_KEY 133 +# define CMS_R_NO_PUBLIC_KEY 134 +# define CMS_R_NO_RECEIPT_REQUEST 168 +# define CMS_R_NO_SIGNERS 135 +# define CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 136 +# define CMS_R_RECEIPT_DECODE_ERROR 169 +# define CMS_R_RECIPIENT_ERROR 137 +# define CMS_R_SIGNER_CERTIFICATE_NOT_FOUND 138 +# define CMS_R_SIGNFINAL_ERROR 139 +# define CMS_R_SMIME_TEXT_ERROR 140 +# define CMS_R_STORE_INIT_ERROR 141 +# define CMS_R_TYPE_NOT_COMPRESSED_DATA 142 +# define CMS_R_TYPE_NOT_DATA 143 +# define CMS_R_TYPE_NOT_DIGESTED_DATA 144 +# define CMS_R_TYPE_NOT_ENCRYPTED_DATA 145 +# define CMS_R_TYPE_NOT_ENVELOPED_DATA 146 +# define CMS_R_UNABLE_TO_FINALIZE_CONTEXT 147 +# define CMS_R_UNKNOWN_CIPHER 148 +# define CMS_R_UNKNOWN_DIGEST_ALGORIHM 149 +# define CMS_R_UNKNOWN_ID 150 +# define CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM 151 +# define CMS_R_UNSUPPORTED_CONTENT_TYPE 152 +# define CMS_R_UNSUPPORTED_KEK_ALGORITHM 153 +# define CMS_R_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM 179 +# define CMS_R_UNSUPPORTED_RECIPIENT_TYPE 154 +# define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE 155 +# define CMS_R_UNSUPPORTED_TYPE 156 +# define CMS_R_UNWRAP_ERROR 157 +# define CMS_R_UNWRAP_FAILURE 180 +# define CMS_R_VERIFICATION_FAILURE 158 +# define CMS_R_WRAP_ERROR 159 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/comp.h b/android/x86/include/openssl/comp.h new file mode 100644 index 00000000..260ff1e0 --- /dev/null +++ b/android/x86/include/openssl/comp.h @@ -0,0 +1,72 @@ +/* + * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_COMP_H +# define HEADER_COMP_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_COMP +# include <openssl/crypto.h> +# ifdef __cplusplus +extern "C" { +# endif + + + +COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); +const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx); +int COMP_CTX_get_type(const COMP_CTX* comp); +int COMP_get_type(const COMP_METHOD *meth); +const char *COMP_get_name(const COMP_METHOD *meth); +void COMP_CTX_free(COMP_CTX *ctx); + +int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, + unsigned char *in, int ilen); +int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, + unsigned char *in, int ilen); + +COMP_METHOD *COMP_zlib(void); + +#if OPENSSL_API_COMPAT < 0x10100000L +#define COMP_zlib_cleanup() while(0) continue +#endif + +# ifdef HEADER_BIO_H +# ifdef ZLIB +const BIO_METHOD *BIO_f_zlib(void); +# endif +# endif + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_COMP_strings(void); + +/* Error codes for the COMP functions. */ + +/* Function codes. */ +# define COMP_F_BIO_ZLIB_FLUSH 99 +# define COMP_F_BIO_ZLIB_NEW 100 +# define COMP_F_BIO_ZLIB_READ 101 +# define COMP_F_BIO_ZLIB_WRITE 102 + +/* Reason codes. */ +# define COMP_R_ZLIB_DEFLATE_ERROR 99 +# define COMP_R_ZLIB_INFLATE_ERROR 100 +# define COMP_R_ZLIB_NOT_SUPPORTED 101 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/conf.h b/android/x86/include/openssl/conf.h new file mode 100644 index 00000000..462e3c9d --- /dev/null +++ b/android/x86/include/openssl/conf.h @@ -0,0 +1,216 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CONF_H +# define HEADER_CONF_H + +# include <openssl/bio.h> +# include <openssl/lhash.h> +# include <openssl/stack.h> +# include <openssl/safestack.h> +# include <openssl/e_os2.h> + +# include <openssl/ossl_typ.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char *section; + char *name; + char *value; +} CONF_VALUE; + +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_LHASH_OF(CONF_VALUE); + +struct conf_st; +struct conf_method_st; +typedef struct conf_method_st CONF_METHOD; + +struct conf_method_st { + const char *name; + CONF *(*create) (CONF_METHOD *meth); + int (*init) (CONF *conf); + int (*destroy) (CONF *conf); + int (*destroy_data) (CONF *conf); + int (*load_bio) (CONF *conf, BIO *bp, long *eline); + int (*dump) (const CONF *conf, BIO *bp); + int (*is_number) (const CONF *conf, char c); + int (*to_int) (const CONF *conf, char c); + int (*load) (CONF *conf, const char *name, long *eline); +}; + +/* Module definitions */ + +typedef struct conf_imodule_st CONF_IMODULE; +typedef struct conf_module_st CONF_MODULE; + +DEFINE_STACK_OF(CONF_MODULE) +DEFINE_STACK_OF(CONF_IMODULE) + +/* DSO module function typedefs */ +typedef int conf_init_func (CONF_IMODULE *md, const CONF *cnf); +typedef void conf_finish_func (CONF_IMODULE *md); + +# define CONF_MFLAGS_IGNORE_ERRORS 0x1 +# define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2 +# define CONF_MFLAGS_SILENT 0x4 +# define CONF_MFLAGS_NO_DSO 0x8 +# define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10 +# define CONF_MFLAGS_DEFAULT_SECTION 0x20 + +int CONF_set_default_method(CONF_METHOD *meth); +void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash); +LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file, + long *eline); +# ifndef OPENSSL_NO_STDIO +LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp, + long *eline); +# endif +LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp, + long *eline); +STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf, + const char *section); +char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group, + const char *name); +long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group, + const char *name); +void CONF_free(LHASH_OF(CONF_VALUE) *conf); +#ifndef OPENSSL_NO_STDIO +int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out); +#endif +int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out); + +DEPRECATEDIN_1_1_0(void OPENSSL_config(const char *config_name)) + +#if OPENSSL_API_COMPAT < 0x10100000L +# define OPENSSL_no_config() \ + OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL) +#endif + +/* + * New conf code. The semantics are different from the functions above. If + * that wasn't the case, the above functions would have been replaced + */ + +struct conf_st { + CONF_METHOD *meth; + void *meth_data; + LHASH_OF(CONF_VALUE) *data; +}; + +CONF *NCONF_new(CONF_METHOD *meth); +CONF_METHOD *NCONF_default(void); +CONF_METHOD *NCONF_WIN32(void); +void NCONF_free(CONF *conf); +void NCONF_free_data(CONF *conf); + +int NCONF_load(CONF *conf, const char *file, long *eline); +# ifndef OPENSSL_NO_STDIO +int NCONF_load_fp(CONF *conf, FILE *fp, long *eline); +# endif +int NCONF_load_bio(CONF *conf, BIO *bp, long *eline); +STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, + const char *section); +char *NCONF_get_string(const CONF *conf, const char *group, const char *name); +int NCONF_get_number_e(const CONF *conf, const char *group, const char *name, + long *result); +#ifndef OPENSSL_NO_STDIO +int NCONF_dump_fp(const CONF *conf, FILE *out); +#endif +int NCONF_dump_bio(const CONF *conf, BIO *out); + +#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r) + +/* Module functions */ + +int CONF_modules_load(const CONF *cnf, const char *appname, + unsigned long flags); +int CONF_modules_load_file(const char *filename, const char *appname, + unsigned long flags); +void CONF_modules_unload(int all); +void CONF_modules_finish(void); +#if OPENSSL_API_COMPAT < 0x10100000L +# define CONF_modules_free() while(0) continue +#endif +int CONF_module_add(const char *name, conf_init_func *ifunc, + conf_finish_func *ffunc); + +const char *CONF_imodule_get_name(const CONF_IMODULE *md); +const char *CONF_imodule_get_value(const CONF_IMODULE *md); +void *CONF_imodule_get_usr_data(const CONF_IMODULE *md); +void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data); +CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md); +unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md); +void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags); +void *CONF_module_get_usr_data(CONF_MODULE *pmod); +void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data); + +char *CONF_get1_default_config_file(void); + +int CONF_parse_list(const char *list, int sep, int nospc, + int (*list_cb) (const char *elem, int len, void *usr), + void *arg); + +void OPENSSL_load_builtin_modules(void); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_CONF_strings(void); + +/* Error codes for the CONF functions. */ + +/* Function codes. */ +# define CONF_F_CONF_DUMP_FP 104 +# define CONF_F_CONF_LOAD 100 +# define CONF_F_CONF_LOAD_FP 103 +# define CONF_F_CONF_PARSE_LIST 119 +# define CONF_F_DEF_LOAD 120 +# define CONF_F_DEF_LOAD_BIO 121 +# define CONF_F_MODULE_INIT 115 +# define CONF_F_MODULE_LOAD_DSO 117 +# define CONF_F_MODULE_RUN 118 +# define CONF_F_NCONF_DUMP_BIO 105 +# define CONF_F_NCONF_DUMP_FP 106 +# define CONF_F_NCONF_GET_NUMBER_E 112 +# define CONF_F_NCONF_GET_SECTION 108 +# define CONF_F_NCONF_GET_STRING 109 +# define CONF_F_NCONF_LOAD 113 +# define CONF_F_NCONF_LOAD_BIO 110 +# define CONF_F_NCONF_LOAD_FP 114 +# define CONF_F_NCONF_NEW 111 +# define CONF_F_STR_COPY 101 + +/* Reason codes. */ +# define CONF_R_ERROR_LOADING_DSO 110 +# define CONF_R_LIST_CANNOT_BE_NULL 115 +# define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100 +# define CONF_R_MISSING_EQUAL_SIGN 101 +# define CONF_R_MISSING_INIT_FUNCTION 112 +# define CONF_R_MODULE_INITIALIZATION_ERROR 109 +# define CONF_R_NO_CLOSE_BRACE 102 +# define CONF_R_NO_CONF 105 +# define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106 +# define CONF_R_NO_SECTION 107 +# define CONF_R_NO_SUCH_FILE 114 +# define CONF_R_NO_VALUE 108 +# define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 +# define CONF_R_UNKNOWN_MODULE_NAME 113 +# define CONF_R_VARIABLE_HAS_NO_VALUE 104 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/conf_api.h b/android/x86/include/openssl/conf_api.h new file mode 100644 index 00000000..a0275ad7 --- /dev/null +++ b/android/x86/include/openssl/conf_api.h @@ -0,0 +1,40 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CONF_API_H +# define HEADER_CONF_API_H + +# include <openssl/lhash.h> +# include <openssl/conf.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Up until OpenSSL 0.9.5a, this was new_section */ +CONF_VALUE *_CONF_new_section(CONF *conf, const char *section); +/* Up until OpenSSL 0.9.5a, this was get_section */ +CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section); +/* Up until OpenSSL 0.9.5a, this was CONF_get_section */ +STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, + const char *section); + +int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value); +char *_CONF_get_string(const CONF *conf, const char *section, + const char *name); +long _CONF_get_number(const CONF *conf, const char *section, + const char *name); + +int _CONF_new_data(CONF *conf); +void _CONF_free_data(CONF *conf); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/x86/include/openssl/crypto.h b/android/x86/include/openssl/crypto.h new file mode 100644 index 00000000..bd0b1408 --- /dev/null +++ b/android/x86/include/openssl/crypto.h @@ -0,0 +1,463 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECDH support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ + +#ifndef HEADER_CRYPTO_H +# define HEADER_CRYPTO_H + +# include <stdlib.h> +# include <time.h> + +# include <openssl/e_os2.h> + +# ifndef OPENSSL_NO_STDIO +# include <stdio.h> +# endif + +# include <openssl/stack.h> +# include <openssl/safestack.h> +# include <openssl/opensslv.h> +# include <openssl/ossl_typ.h> +# include <openssl/opensslconf.h> + +# ifdef CHARSET_EBCDIC +# include <openssl/ebcdic.h> +# endif + +/* + * Resolve problems on some operating systems with symbol names that clash + * one way or another + */ +# include <openssl/symhacks.h> + +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/opensslv.h> +# endif + +#ifdef __cplusplus +extern "C" { +#endif + +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSLeay OpenSSL_version_num +# define SSLeay_version OpenSSL_version +# define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER +# define SSLEAY_VERSION OPENSSL_VERSION +# define SSLEAY_CFLAGS OPENSSL_CFLAGS +# define SSLEAY_BUILT_ON OPENSSL_BUILT_ON +# define SSLEAY_PLATFORM OPENSSL_PLATFORM +# define SSLEAY_DIR OPENSSL_DIR + +/* + * Old type for allocating dynamic locks. No longer used. Use the new thread + * API instead. + */ +typedef struct { + int dummy; +} CRYPTO_dynlock; + +# endif /* OPENSSL_API_COMPAT */ + +typedef void CRYPTO_RWLOCK; + +CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void); +int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock); +int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock); +int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock); +void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock); + +int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock); + +/* + * The following can be used to detect memory leaks in the library. If + * used, it turns on malloc checking + */ +# define CRYPTO_MEM_CHECK_OFF 0x0 /* Control only */ +# define CRYPTO_MEM_CHECK_ON 0x1 /* Control and mode bit */ +# define CRYPTO_MEM_CHECK_ENABLE 0x2 /* Control and mode bit */ +# define CRYPTO_MEM_CHECK_DISABLE 0x3 /* Control only */ + +struct crypto_ex_data_st { + STACK_OF(void) *sk; +}; +DEFINE_STACK_OF(void) + +/* + * Per class, we have a STACK of function pointers. + */ +# define CRYPTO_EX_INDEX_SSL 0 +# define CRYPTO_EX_INDEX_SSL_CTX 1 +# define CRYPTO_EX_INDEX_SSL_SESSION 2 +# define CRYPTO_EX_INDEX_X509 3 +# define CRYPTO_EX_INDEX_X509_STORE 4 +# define CRYPTO_EX_INDEX_X509_STORE_CTX 5 +# define CRYPTO_EX_INDEX_DH 6 +# define CRYPTO_EX_INDEX_DSA 7 +# define CRYPTO_EX_INDEX_EC_KEY 8 +# define CRYPTO_EX_INDEX_RSA 9 +# define CRYPTO_EX_INDEX_ENGINE 10 +# define CRYPTO_EX_INDEX_UI 11 +# define CRYPTO_EX_INDEX_BIO 12 +# define CRYPTO_EX_INDEX_APP 13 +# define CRYPTO_EX_INDEX__COUNT 14 + +/* + * This is the default callbacks, but we can have others as well: this is + * needed in Win32 where the application malloc and the library malloc may + * not be the same. + */ +#define OPENSSL_malloc_init() \ + CRYPTO_set_mem_functions(CRYPTO_malloc, CRYPTO_realloc, CRYPTO_free) + +int CRYPTO_mem_ctrl(int mode); + +# define OPENSSL_malloc(num) \ + CRYPTO_malloc(num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_zalloc(num) \ + CRYPTO_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_realloc(addr, num) \ + CRYPTO_realloc(addr, num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_clear_realloc(addr, old_num, num) \ + CRYPTO_clear_realloc(addr, old_num, num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_clear_free(addr, num) \ + CRYPTO_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_free(addr) \ + CRYPTO_free(addr, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_memdup(str, s) \ + CRYPTO_memdup((str), s, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_strdup(str) \ + CRYPTO_strdup(str, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_strndup(str, n) \ + CRYPTO_strndup(str, n, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_secure_malloc(num) \ + CRYPTO_secure_malloc(num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_secure_zalloc(num) \ + CRYPTO_secure_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_secure_free(addr) \ + CRYPTO_secure_free(addr, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_secure_actual_size(ptr) \ + CRYPTO_secure_actual_size(ptr) + +size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz); +size_t OPENSSL_strlcat(char *dst, const char *src, size_t siz); +size_t OPENSSL_strnlen(const char *str, size_t maxlen); +char *OPENSSL_buf2hexstr(const unsigned char *buffer, long len); +unsigned char *OPENSSL_hexstr2buf(const char *str, long *len); +int OPENSSL_hexchar2int(unsigned char c); + +# define OPENSSL_MALLOC_MAX_NELEMS(type) (((1U<<(sizeof(int)*8-1))-1)/sizeof(type)) + +unsigned long OpenSSL_version_num(void); +const char *OpenSSL_version(int type); +# define OPENSSL_VERSION 0 +# define OPENSSL_CFLAGS 1 +# define OPENSSL_BUILT_ON 2 +# define OPENSSL_PLATFORM 3 +# define OPENSSL_DIR 4 +# define OPENSSL_ENGINES_DIR 5 + +int OPENSSL_issetugid(void); + +typedef void CRYPTO_EX_new (void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +typedef void CRYPTO_EX_free (void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +typedef int CRYPTO_EX_dup (CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, + void *srcp, int idx, long argl, void *argp); +__owur int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, + CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, + CRYPTO_EX_free *free_func); +/* No longer use an index. */ +int CRYPTO_free_ex_index(int class_index, int idx); + +/* + * Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a + * given class (invokes whatever per-class callbacks are applicable) + */ +int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); +int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, + const CRYPTO_EX_DATA *from); + +void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); + +/* + * Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular + * index (relative to the class type involved) + */ +int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val); +void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx); + +# if OPENSSL_API_COMPAT < 0x10100000L +/* + * This function cleans up all "ex_data" state. It mustn't be called under + * potential race-conditions. + */ +# define CRYPTO_cleanup_all_ex_data() while(0) continue + +/* + * The old locking functions have been removed completely without compatibility + * macros. This is because the old functions either could not properly report + * errors, or the returned error values were not clearly documented. + * Replacing the locking functions with with no-ops would cause race condition + * issues in the affected applications. It is far better for them to fail at + * compile time. + * On the other hand, the locking callbacks are no longer used. Consequently, + * the callback management functions can be safely replaced with no-op macros. + */ +# define CRYPTO_num_locks() (1) +# define CRYPTO_set_locking_callback(func) +# define CRYPTO_get_locking_callback() (NULL) +# define CRYPTO_set_add_lock_callback(func) +# define CRYPTO_get_add_lock_callback() (NULL) + +/* + * These defines where used in combination with the old locking callbacks, + * they are not called anymore, but old code that's not called might still + * use them. + */ +# define CRYPTO_LOCK 1 +# define CRYPTO_UNLOCK 2 +# define CRYPTO_READ 4 +# define CRYPTO_WRITE 8 + +/* This structure is no longer used */ +typedef struct crypto_threadid_st { + int dummy; +} CRYPTO_THREADID; +/* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */ +# define CRYPTO_THREADID_set_numeric(id, val) +# define CRYPTO_THREADID_set_pointer(id, ptr) +# define CRYPTO_THREADID_set_callback(threadid_func) (0) +# define CRYPTO_THREADID_get_callback() (NULL) +# define CRYPTO_THREADID_current(id) +# define CRYPTO_THREADID_cmp(a, b) (-1) +# define CRYPTO_THREADID_cpy(dest, src) +# define CRYPTO_THREADID_hash(id) (0UL) + +# if OPENSSL_API_COMPAT < 0x10000000L +# define CRYPTO_set_id_callback(func) +# define CRYPTO_get_id_callback() (NULL) +# define CRYPTO_thread_id() (0UL) +# endif /* OPENSSL_API_COMPAT < 0x10000000L */ + +# define CRYPTO_set_dynlock_create_callback(dyn_create_function) +# define CRYPTO_set_dynlock_lock_callback(dyn_lock_function) +# define CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function) +# define CRYPTO_get_dynlock_create_callback() (NULL) +# define CRYPTO_get_dynlock_lock_callback() (NULL) +# define CRYPTO_get_dynlock_destroy_callback() (NULL) +# endif /* OPENSSL_API_COMPAT < 0x10100000L */ + +int CRYPTO_set_mem_functions( + void *(*m) (size_t, const char *, int), + void *(*r) (void *, size_t, const char *, int), + void (*f) (void *, const char *, int)); +int CRYPTO_set_mem_debug(int flag); +void CRYPTO_get_mem_functions( + void *(**m) (size_t, const char *, int), + void *(**r) (void *, size_t, const char *, int), + void (**f) (void *, const char *, int)); + +void *CRYPTO_malloc(size_t num, const char *file, int line); +void *CRYPTO_zalloc(size_t num, const char *file, int line); +void *CRYPTO_memdup(const void *str, size_t siz, const char *file, int line); +char *CRYPTO_strdup(const char *str, const char *file, int line); +char *CRYPTO_strndup(const char *str, size_t s, const char *file, int line); +void CRYPTO_free(void *ptr, const char *file, int line); +void CRYPTO_clear_free(void *ptr, size_t num, const char *file, int line); +void *CRYPTO_realloc(void *addr, size_t num, const char *file, int line); +void *CRYPTO_clear_realloc(void *addr, size_t old_num, size_t num, + const char *file, int line); + +int CRYPTO_secure_malloc_init(size_t sz, int minsize); +int CRYPTO_secure_malloc_done(void); +void *CRYPTO_secure_malloc(size_t num, const char *file, int line); +void *CRYPTO_secure_zalloc(size_t num, const char *file, int line); +void CRYPTO_secure_free(void *ptr, const char *file, int line); +int CRYPTO_secure_allocated(const void *ptr); +int CRYPTO_secure_malloc_initialized(void); +size_t CRYPTO_secure_actual_size(void *ptr); +size_t CRYPTO_secure_used(void); + +void OPENSSL_cleanse(void *ptr, size_t len); + +# ifndef OPENSSL_NO_CRYPTO_MDEBUG +# define OPENSSL_mem_debug_push(info) \ + CRYPTO_mem_debug_push(info, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_mem_debug_pop() \ + CRYPTO_mem_debug_pop() +int CRYPTO_mem_debug_push(const char *info, const char *file, int line); +int CRYPTO_mem_debug_pop(void); + +/*- + * Debugging functions (enabled by CRYPTO_set_mem_debug(1)) + * The flag argument has the following significance: + * 0: called before the actual memory allocation has taken place + * 1: called after the actual memory allocation has taken place + */ +void CRYPTO_mem_debug_malloc(void *addr, size_t num, int flag, + const char *file, int line); +void CRYPTO_mem_debug_realloc(void *addr1, void *addr2, size_t num, int flag, + const char *file, int line); +void CRYPTO_mem_debug_free(void *addr, int flag, + const char *file, int line); + +# ifndef OPENSSL_NO_STDIO +int CRYPTO_mem_leaks_fp(FILE *); +# endif +int CRYPTO_mem_leaks(BIO *bio); +# endif + +/* die if we have to */ +ossl_noreturn void OPENSSL_die(const char *assertion, const char *file, int line); +# if OPENSSL_API_COMPAT < 0x10100000L +# define OpenSSLDie(f,l,a) OPENSSL_die((a),(f),(l)) +# endif +# define OPENSSL_assert(e) \ + (void)((e) ? 0 : (OPENSSL_die("assertion failed: " #e, OPENSSL_FILE, OPENSSL_LINE), 1)) + +int OPENSSL_isservice(void); + +int FIPS_mode(void); +int FIPS_mode_set(int r); + +void OPENSSL_init(void); + +struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result); +int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec); +int OPENSSL_gmtime_diff(int *pday, int *psec, + const struct tm *from, const struct tm *to); + +/* + * CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal. + * It takes an amount of time dependent on |len|, but independent of the + * contents of |a| and |b|. Unlike memcmp, it cannot be used to put elements + * into a defined order as the return value when a != b is undefined, other + * than to be non-zero. + */ +int CRYPTO_memcmp(const volatile void * volatile in_a, + const volatile void * volatile in_b, + size_t len); + +/* Standard initialisation options */ +# define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0x00000001L +# define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L +# define OPENSSL_INIT_ADD_ALL_CIPHERS 0x00000004L +# define OPENSSL_INIT_ADD_ALL_DIGESTS 0x00000008L +# define OPENSSL_INIT_NO_ADD_ALL_CIPHERS 0x00000010L +# define OPENSSL_INIT_NO_ADD_ALL_DIGESTS 0x00000020L +# define OPENSSL_INIT_LOAD_CONFIG 0x00000040L +# define OPENSSL_INIT_NO_LOAD_CONFIG 0x00000080L +# define OPENSSL_INIT_ASYNC 0x00000100L +# define OPENSSL_INIT_ENGINE_RDRAND 0x00000200L +# define OPENSSL_INIT_ENGINE_DYNAMIC 0x00000400L +# define OPENSSL_INIT_ENGINE_OPENSSL 0x00000800L +# define OPENSSL_INIT_ENGINE_CRYPTODEV 0x00001000L +# define OPENSSL_INIT_ENGINE_CAPI 0x00002000L +# define OPENSSL_INIT_ENGINE_PADLOCK 0x00004000L +# define OPENSSL_INIT_ENGINE_AFALG 0x00008000L +/* OPENSSL_INIT flag 0x00010000 reserved for internal use */ +/* OPENSSL_INIT flag range 0xfff00000 reserved for OPENSSL_init_ssl() */ +/* Max OPENSSL_INIT flag value is 0x80000000 */ + +/* openssl and dasync not counted as builtin */ +# define OPENSSL_INIT_ENGINE_ALL_BUILTIN \ + (OPENSSL_INIT_ENGINE_RDRAND | OPENSSL_INIT_ENGINE_DYNAMIC \ + | OPENSSL_INIT_ENGINE_CRYPTODEV | OPENSSL_INIT_ENGINE_CAPI | \ + OPENSSL_INIT_ENGINE_PADLOCK) + + +/* Library initialisation functions */ +void OPENSSL_cleanup(void); +int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings); +int OPENSSL_atexit(void (*handler)(void)); +void OPENSSL_thread_stop(void); + +/* Low-level control of initialization */ +OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void); +# ifndef OPENSSL_NO_STDIO +int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *settings, + const char *config_file); +# endif +void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *settings); + +# if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) +# if defined(_WIN32) +# if defined(BASETYPES) || defined(_WINDEF_H) +/* application has to include <windows.h> in order to use this */ +typedef DWORD CRYPTO_THREAD_LOCAL; +typedef DWORD CRYPTO_THREAD_ID; + +typedef LONG CRYPTO_ONCE; +# define CRYPTO_ONCE_STATIC_INIT 0 +# endif +# else +# include <pthread.h> +typedef pthread_once_t CRYPTO_ONCE; +typedef pthread_key_t CRYPTO_THREAD_LOCAL; +typedef pthread_t CRYPTO_THREAD_ID; + +# define CRYPTO_ONCE_STATIC_INIT PTHREAD_ONCE_INIT +# endif +# endif + +# if !defined(CRYPTO_ONCE_STATIC_INIT) +typedef unsigned int CRYPTO_ONCE; +typedef unsigned int CRYPTO_THREAD_LOCAL; +typedef unsigned int CRYPTO_THREAD_ID; +# define CRYPTO_ONCE_STATIC_INIT 0 +# endif + +int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void)); + +int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *)); +void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key); +int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val); +int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key); + +CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void); +int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_CRYPTO_strings(void); + +/* Error codes for the CRYPTO functions. */ + +/* Function codes. */ +# define CRYPTO_F_CRYPTO_DUP_EX_DATA 110 +# define CRYPTO_F_CRYPTO_FREE_EX_DATA 111 +# define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100 +# define CRYPTO_F_CRYPTO_MEMDUP 115 +# define CRYPTO_F_CRYPTO_NEW_EX_DATA 112 +# define CRYPTO_F_CRYPTO_SET_EX_DATA 102 +# define CRYPTO_F_FIPS_MODE_SET 109 +# define CRYPTO_F_GET_AND_LOCK 113 +# define CRYPTO_F_OPENSSL_BUF2HEXSTR 117 +# define CRYPTO_F_OPENSSL_HEXSTR2BUF 118 +# define CRYPTO_F_OPENSSL_INIT_CRYPTO 116 + +/* Reason codes. */ +# define CRYPTO_R_FIPS_MODE_NOT_SUPPORTED 101 +# define CRYPTO_R_ILLEGAL_HEX_DIGIT 102 +# define CRYPTO_R_ODD_NUMBER_OF_DIGITS 103 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/ct.h b/android/x86/include/openssl/ct.h new file mode 100644 index 00000000..6c632652 --- /dev/null +++ b/android/x86/include/openssl/ct.h @@ -0,0 +1,518 @@ +/* + * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CT_H +# define HEADER_CT_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_CT +# include <openssl/ossl_typ.h> +# include <openssl/safestack.h> +# include <openssl/x509.h> +# ifdef __cplusplus +extern "C" { +# endif + + +/* Minimum RSA key size, from RFC6962 */ +# define SCT_MIN_RSA_BITS 2048 + +/* All hashes are SHA256 in v1 of Certificate Transparency */ +# define CT_V1_HASHLEN SHA256_DIGEST_LENGTH + +typedef enum { + CT_LOG_ENTRY_TYPE_NOT_SET = -1, + CT_LOG_ENTRY_TYPE_X509 = 0, + CT_LOG_ENTRY_TYPE_PRECERT = 1 +} ct_log_entry_type_t; + +typedef enum { + SCT_VERSION_NOT_SET = -1, + SCT_VERSION_V1 = 0 +} sct_version_t; + +typedef enum { + SCT_SOURCE_UNKNOWN, + SCT_SOURCE_TLS_EXTENSION, + SCT_SOURCE_X509V3_EXTENSION, + SCT_SOURCE_OCSP_STAPLED_RESPONSE +} sct_source_t; + +typedef enum { + SCT_VALIDATION_STATUS_NOT_SET, + SCT_VALIDATION_STATUS_UNKNOWN_LOG, + SCT_VALIDATION_STATUS_VALID, + SCT_VALIDATION_STATUS_INVALID, + SCT_VALIDATION_STATUS_UNVERIFIED, + SCT_VALIDATION_STATUS_UNKNOWN_VERSION +} sct_validation_status_t; + +DEFINE_STACK_OF(SCT) +DEFINE_STACK_OF(CTLOG) + +/****************************************** + * CT policy evaluation context functions * + ******************************************/ + +/* + * Creates a new, empty policy evaluation context. + * The caller is responsible for calling CT_POLICY_EVAL_CTX_free when finished + * with the CT_POLICY_EVAL_CTX. + */ +CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void); + +/* Deletes a policy evaluation context and anything it owns. */ +void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx); + +/* Gets the peer certificate that the SCTs are for */ +X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx); + +/* + * Sets the certificate associated with the received SCTs. + * Increments the reference count of cert. + * Returns 1 on success, 0 otherwise. + */ +int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert); + +/* Gets the issuer of the aforementioned certificate */ +X509* CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx); + +/* + * Sets the issuer of the certificate associated with the received SCTs. + * Increments the reference count of issuer. + * Returns 1 on success, 0 otherwise. + */ +int CT_POLICY_EVAL_CTX_set1_issuer(CT_POLICY_EVAL_CTX *ctx, X509 *issuer); + +/* Gets the CT logs that are trusted sources of SCTs */ +const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(const CT_POLICY_EVAL_CTX *ctx); + +/* Sets the log store that is in use. It must outlive the CT_POLICY_EVAL_CTX. */ +void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx, + CTLOG_STORE *log_store); + +/***************** + * SCT functions * + *****************/ + +/* + * Creates a new, blank SCT. + * The caller is responsible for calling SCT_free when finished with the SCT. + */ +SCT *SCT_new(void); + +/* + * Creates a new SCT from some base64-encoded strings. + * The caller is responsible for calling SCT_free when finished with the SCT. + */ +SCT *SCT_new_from_base64(unsigned char version, + const char *logid_base64, + ct_log_entry_type_t entry_type, + uint64_t timestamp, + const char *extensions_base64, + const char *signature_base64); + +/* + * Frees the SCT and the underlying data structures. + */ +void SCT_free(SCT *sct); + +/* + * Free a stack of SCTs, and the underlying SCTs themselves. + * Intended to be compatible with X509V3_EXT_FREE. + */ +void SCT_LIST_free(STACK_OF(SCT) *a); + +/* + * Returns the version of the SCT. + */ +sct_version_t SCT_get_version(const SCT *sct); + +/* + * Set the version of an SCT. + * Returns 1 on success, 0 if the version is unrecognized. + */ +__owur int SCT_set_version(SCT *sct, sct_version_t version); + +/* + * Returns the log entry type of the SCT. + */ +ct_log_entry_type_t SCT_get_log_entry_type(const SCT *sct); + +/* + * Set the log entry type of an SCT. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set_log_entry_type(SCT *sct, ct_log_entry_type_t entry_type); + +/* + * Gets the ID of the log that an SCT came from. + * Ownership of the log ID remains with the SCT. + * Returns the length of the log ID. + */ +size_t SCT_get0_log_id(const SCT *sct, unsigned char **log_id); + +/* + * Set the log ID of an SCT to point directly to the *log_id specified. + * The SCT takes ownership of the specified pointer. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len); + +/* + * Set the log ID of an SCT. + * This makes a copy of the log_id. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set1_log_id(SCT *sct, const unsigned char *log_id, + size_t log_id_len); + +/* + * Returns the timestamp for the SCT (epoch time in milliseconds). + */ +uint64_t SCT_get_timestamp(const SCT *sct); + +/* + * Set the timestamp of an SCT (epoch time in milliseconds). + */ +void SCT_set_timestamp(SCT *sct, uint64_t timestamp); + +/* + * Return the NID for the signature used by the SCT. + * For CT v1, this will be either NID_sha256WithRSAEncryption or + * NID_ecdsa_with_SHA256 (or NID_undef if incorrect/unset). + */ +int SCT_get_signature_nid(const SCT *sct); + +/* + * Set the signature type of an SCT + * For CT v1, this should be either NID_sha256WithRSAEncryption or + * NID_ecdsa_with_SHA256. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set_signature_nid(SCT *sct, int nid); + +/* + * Set *ext to point to the extension data for the SCT. ext must not be NULL. + * The SCT retains ownership of this pointer. + * Returns length of the data pointed to. + */ +size_t SCT_get0_extensions(const SCT *sct, unsigned char **ext); + +/* + * Set the extensions of an SCT to point directly to the *ext specified. + * The SCT takes ownership of the specified pointer. + */ +void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len); + +/* + * Set the extensions of an SCT. + * This takes a copy of the ext. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set1_extensions(SCT *sct, const unsigned char *ext, + size_t ext_len); + +/* + * Set *sig to point to the signature for the SCT. sig must not be NULL. + * The SCT retains ownership of this pointer. + * Returns length of the data pointed to. + */ +size_t SCT_get0_signature(const SCT *sct, unsigned char **sig); + +/* + * Set the signature of an SCT to point directly to the *sig specified. + * The SCT takes ownership of the specified pointer. + */ +void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len); + +/* + * Set the signature of an SCT to be a copy of the *sig specified. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set1_signature(SCT *sct, const unsigned char *sig, + size_t sig_len); + +/* + * The origin of this SCT, e.g. TLS extension, OCSP response, etc. + */ +sct_source_t SCT_get_source(const SCT *sct); + +/* + * Set the origin of this SCT, e.g. TLS extension, OCSP response, etc. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set_source(SCT *sct, sct_source_t source); + +/* + * Returns a text string describing the validation status of |sct|. + */ +const char *SCT_validation_status_string(const SCT *sct); + +/* + * Pretty-prints an |sct| to |out|. + * It will be indented by the number of spaces specified by |indent|. + * If |logs| is not NULL, it will be used to lookup the CT log that the SCT came + * from, so that the log name can be printed. + */ +void SCT_print(const SCT *sct, BIO *out, int indent, const CTLOG_STORE *logs); + +/* + * Pretty-prints an |sct_list| to |out|. + * It will be indented by the number of spaces specified by |indent|. + * SCTs will be delimited by |separator|. + * If |logs| is not NULL, it will be used to lookup the CT log that each SCT + * came from, so that the log names can be printed. + */ +void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent, + const char *separator, const CTLOG_STORE *logs); + +/* + * Gets the last result of validating this SCT. + * If it has not been validated yet, returns SCT_VALIDATION_STATUS_NOT_SET. + */ +sct_validation_status_t SCT_get_validation_status(const SCT *sct); + +/* + * Validates the given SCT with the provided context. + * Sets the "validation_status" field of the SCT. + * Returns 1 if the SCT is valid and the signature verifies. + * Returns 0 if the SCT is invalid or could not be verified. + * Returns -1 if an error occurs. + */ +__owur int SCT_validate(SCT *sct, const CT_POLICY_EVAL_CTX *ctx); + +/* + * Validates the given list of SCTs with the provided context. + * Sets the "validation_status" field of each SCT. + * Returns 1 if there are no invalid SCTs and all signatures verify. + * Returns 0 if at least one SCT is invalid or could not be verified. + * Returns a negative integer if an error occurs. + */ +__owur int SCT_LIST_validate(const STACK_OF(SCT) *scts, + CT_POLICY_EVAL_CTX *ctx); + + +/********************************* + * SCT parsing and serialisation * + *********************************/ + +/* + * Serialize (to TLS format) a stack of SCTs and return the length. + * "a" must not be NULL. + * If "pp" is NULL, just return the length of what would have been serialized. + * If "pp" is not NULL and "*pp" is null, function will allocate a new pointer + * for data that caller is responsible for freeing (only if function returns + * successfully). + * If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring + * that "*pp" is large enough to accept all of the serialized data. + * Returns < 0 on error, >= 0 indicating bytes written (or would have been) + * on success. + */ +__owur int i2o_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp); + +/* + * Convert TLS format SCT list to a stack of SCTs. + * If "a" or "*a" is NULL, a new stack will be created that the caller is + * responsible for freeing (by calling SCT_LIST_free). + * "**pp" and "*pp" must not be NULL. + * Upon success, "*pp" will point to after the last bytes read, and a stack + * will be returned. + * Upon failure, a NULL pointer will be returned, and the position of "*pp" is + * not defined. + */ +STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp, + size_t len); + +/* + * Serialize (to DER format) a stack of SCTs and return the length. + * "a" must not be NULL. + * If "pp" is NULL, just returns the length of what would have been serialized. + * If "pp" is not NULL and "*pp" is null, function will allocate a new pointer + * for data that caller is responsible for freeing (only if function returns + * successfully). + * If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring + * that "*pp" is large enough to accept all of the serialized data. + * Returns < 0 on error, >= 0 indicating bytes written (or would have been) + * on success. + */ +__owur int i2d_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp); + +/* + * Parses an SCT list in DER format and returns it. + * If "a" or "*a" is NULL, a new stack will be created that the caller is + * responsible for freeing (by calling SCT_LIST_free). + * "**pp" and "*pp" must not be NULL. + * Upon success, "*pp" will point to after the last bytes read, and a stack + * will be returned. + * Upon failure, a NULL pointer will be returned, and the position of "*pp" is + * not defined. + */ +STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp, + long len); + +/* + * Serialize (to TLS format) an |sct| and write it to |out|. + * If |out| is null, no SCT will be output but the length will still be returned. + * If |out| points to a null pointer, a string will be allocated to hold the + * TLS-format SCT. It is the responsibility of the caller to free it. + * If |out| points to an allocated string, the TLS-format SCT will be written + * to it. + * The length of the SCT in TLS format will be returned. + */ +__owur int i2o_SCT(const SCT *sct, unsigned char **out); + +/* + * Parses an SCT in TLS format and returns it. + * If |psct| is not null, it will end up pointing to the parsed SCT. If it + * already points to a non-null pointer, the pointer will be free'd. + * |in| should be a pointer to a string containing the TLS-format SCT. + * |in| will be advanced to the end of the SCT if parsing succeeds. + * |len| should be the length of the SCT in |in|. + * Returns NULL if an error occurs. + * If the SCT is an unsupported version, only the SCT's 'sct' and 'sct_len' + * fields will be populated (with |in| and |len| respectively). + */ +SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len); + +/******************** + * CT log functions * + ********************/ + +/* + * Creates a new CT log instance with the given |public_key| and |name|. + * Takes ownership of |public_key| but copies |name|. + * Returns NULL if malloc fails or if |public_key| cannot be converted to DER. + * Should be deleted by the caller using CTLOG_free when no longer needed. + */ +CTLOG *CTLOG_new(EVP_PKEY *public_key, const char *name); + +/* + * Creates a new CTLOG instance with the base64-encoded SubjectPublicKeyInfo DER + * in |pkey_base64|. The |name| is a string to help users identify this log. + * Returns 1 on success, 0 on failure. + * Should be deleted by the caller using CTLOG_free when no longer needed. + */ +int CTLOG_new_from_base64(CTLOG ** ct_log, + const char *pkey_base64, const char *name); + +/* + * Deletes a CT log instance and its fields. + */ +void CTLOG_free(CTLOG *log); + +/* Gets the name of the CT log */ +const char *CTLOG_get0_name(const CTLOG *log); +/* Gets the ID of the CT log */ +void CTLOG_get0_log_id(const CTLOG *log, const uint8_t **log_id, + size_t *log_id_len); +/* Gets the public key of the CT log */ +EVP_PKEY *CTLOG_get0_public_key(const CTLOG *log); + +/************************** + * CT log store functions * + **************************/ + +/* + * Creates a new CT log store. + * Should be deleted by the caller using CTLOG_STORE_free when no longer needed. + */ +CTLOG_STORE *CTLOG_STORE_new(void); + +/* + * Deletes a CT log store and all of the CT log instances held within. + */ +void CTLOG_STORE_free(CTLOG_STORE *store); + +/* + * Finds a CT log in the store based on its log ID. + * Returns the CT log, or NULL if no match is found. + */ +const CTLOG *CTLOG_STORE_get0_log_by_id(const CTLOG_STORE *store, + const uint8_t *log_id, + size_t log_id_len); + +/* + * Loads a CT log list into a |store| from a |file|. + * Returns 1 if loading is successful, or 0 otherwise. + */ +__owur int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file); + +/* + * Loads the default CT log list into a |store|. + * See internal/cryptlib.h for the environment variable and file path that are + * consulted to find the default file. + * Returns 1 if loading is successful, or 0 otherwise. + */ +__owur int CTLOG_STORE_load_default_file(CTLOG_STORE *store); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_CT_strings(void); + +/* Error codes for the CT functions. */ + +/* Function codes. */ +# define CT_F_CTLOG_NEW 117 +# define CT_F_CTLOG_NEW_FROM_BASE64 118 +# define CT_F_CTLOG_NEW_FROM_CONF 119 +# define CT_F_CTLOG_NEW_NULL 120 +# define CT_F_CTLOG_STORE_LOAD_CTX_NEW 122 +# define CT_F_CTLOG_STORE_LOAD_FILE 123 +# define CT_F_CTLOG_STORE_LOAD_LOG 130 +# define CT_F_CTLOG_STORE_NEW 131 +# define CT_F_CT_BASE64_DECODE 124 +# define CT_F_CT_POLICY_EVAL_CTX_NEW 133 +# define CT_F_CT_V1_LOG_ID_FROM_PKEY 125 +# define CT_F_I2O_SCT 107 +# define CT_F_I2O_SCT_LIST 108 +# define CT_F_I2O_SCT_SIGNATURE 109 +# define CT_F_O2I_SCT 110 +# define CT_F_O2I_SCT_LIST 111 +# define CT_F_O2I_SCT_SIGNATURE 112 +# define CT_F_SCT_CTX_NEW 126 +# define CT_F_SCT_NEW 100 +# define CT_F_SCT_NEW_FROM_BASE64 127 +# define CT_F_SCT_SET0_LOG_ID 101 +# define CT_F_SCT_SET1_EXTENSIONS 114 +# define CT_F_SCT_SET1_LOG_ID 115 +# define CT_F_SCT_SET1_SIGNATURE 116 +# define CT_F_SCT_SET_LOG_ENTRY_TYPE 102 +# define CT_F_SCT_SET_SIGNATURE_NID 103 +# define CT_F_SCT_SET_VERSION 104 +# define CT_F_SCT_CTX_VERIFY 128 + +/* Reason codes. */ +# define CT_R_BASE64_DECODE_ERROR 108 +# define CT_R_INVALID_LOG_ID_LENGTH 100 +# define CT_R_LOG_CONF_INVALID 109 +# define CT_R_LOG_CONF_INVALID_KEY 110 +# define CT_R_LOG_CONF_MISSING_DESCRIPTION 111 +# define CT_R_LOG_CONF_MISSING_KEY 112 +# define CT_R_LOG_KEY_INVALID 113 +# define CT_R_SCT_INVALID 104 +# define CT_R_SCT_INVALID_SIGNATURE 107 +# define CT_R_SCT_LIST_INVALID 105 +# define CT_R_SCT_LOG_ID_MISMATCH 114 +# define CT_R_SCT_NOT_SET 106 +# define CT_R_SCT_UNSUPPORTED_VERSION 115 +# define CT_R_UNRECOGNIZED_SIGNATURE_NID 101 +# define CT_R_UNSUPPORTED_ENTRY_TYPE 102 +# define CT_R_UNSUPPORTED_VERSION 103 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/des.h b/android/x86/include/openssl/des.h new file mode 100644 index 00000000..be4abbdf --- /dev/null +++ b/android/x86/include/openssl/des.h @@ -0,0 +1,174 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DES_H +# define HEADER_DES_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_DES +# ifdef __cplusplus +extern "C" { +# endif +# include <openssl/e_os2.h> + +typedef unsigned int DES_LONG; + +# ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +# endif + +typedef unsigned char DES_cblock[8]; +typedef /* const */ unsigned char const_DES_cblock[8]; +/* + * With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * and + * const_DES_cblock * are incompatible pointer types. + */ + +typedef struct DES_ks { + union { + DES_cblock cblock; + /* + * make sure things are correct size on machines with 8 byte longs + */ + DES_LONG deslong[2]; + } ks[16]; +} DES_key_schedule; + +# define DES_KEY_SZ (sizeof(DES_cblock)) +# define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) + +# define DES_ENCRYPT 1 +# define DES_DECRYPT 0 + +# define DES_CBC_MODE 0 +# define DES_PCBC_MODE 1 + +# define DES_ecb2_encrypt(i,o,k1,k2,e) \ + DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) + +# define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ + DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) + +# define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ + DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) + +# define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ + DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) + +OPENSSL_DECLARE_GLOBAL(int, DES_check_key); /* defaults to false */ +# define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key) + +const char *DES_options(void); +void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, + DES_key_schedule *ks1, DES_key_schedule *ks2, + DES_key_schedule *ks3, int enc); +DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output, + long length, DES_key_schedule *schedule, + const_DES_cblock *ivec); +/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ +void DES_cbc_encrypt(const unsigned char *input, unsigned char *output, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int enc); +void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int enc); +void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, const_DES_cblock *inw, + const_DES_cblock *outw, int enc); +void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int enc); +void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, + DES_key_schedule *ks, int enc); + +/* + * This is the DES encryption function that gets called by just about every + * other DES routine in the library. You should not use this function except + * to implement 'modes' of DES. I say this because the functions that call + * this routine do the conversion from 'char *' to long, and this needs to be + * done to make sure 'non-aligned' memory access do not occur. The + * characters are loaded 'little endian'. Data is a pointer to 2 unsigned + * long's and ks is the DES_key_schedule to use. enc, is non zero specifies + * encryption, zero if decryption. + */ +void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc); + +/* + * This functions is the same as DES_encrypt1() except that the DES initial + * permutation (IP) and final permutation (FP) have been left out. As for + * DES_encrypt1(), you should not use this function. It is used by the + * routines in the library that implement triple DES. IP() DES_encrypt2() + * DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1() + * DES_encrypt1() DES_encrypt1() except faster :-). + */ +void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc); + +void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3); +void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3); +void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, + long length, + DES_key_schedule *ks1, DES_key_schedule *ks2, + DES_key_schedule *ks3, DES_cblock *ivec, int enc); +void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3, + DES_cblock *ivec, int *num, int enc); +void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out, + int numbits, long length, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3, + DES_cblock *ivec, int enc); +void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3, + DES_cblock *ivec, int *num); +char *DES_fcrypt(const char *buf, const char *salt, char *ret); +char *DES_crypt(const char *buf, const char *salt); +void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits, + long length, DES_key_schedule *schedule, + DES_cblock *ivec); +void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int enc); +DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[], + long length, int out_count, DES_cblock *seed); +int DES_random_key(DES_cblock *ret); +void DES_set_odd_parity(DES_cblock *key); +int DES_check_key_parity(const_DES_cblock *key); +int DES_is_weak_key(const_DES_cblock *key); +/* + * DES_set_key (= set_key = DES_key_sched = key_sched) calls + * DES_set_key_checked if global variable DES_check_key is set, + * DES_set_key_unchecked otherwise. + */ +int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule); +int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule); +int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule); +void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule); +void DES_string_to_key(const char *str, DES_cblock *key); +void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2); +void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int *num, int enc); +void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int *num); + +# define DES_fixup_key_parity DES_set_odd_parity + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/dh.h b/android/x86/include/openssl/dh.h new file mode 100644 index 00000000..ae309e7b --- /dev/null +++ b/android/x86/include/openssl/dh.h @@ -0,0 +1,343 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DH_H +# define HEADER_DH_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_DH +# include <openssl/e_os2.h> +# include <openssl/bio.h> +# include <openssl/asn1.h> +# include <openssl/ossl_typ.h> +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/bn.h> +# endif + +# ifdef __cplusplus +extern "C" { +# endif + +# ifndef OPENSSL_DH_MAX_MODULUS_BITS +# define OPENSSL_DH_MAX_MODULUS_BITS 10000 +# endif + +# define OPENSSL_DH_FIPS_MIN_MODULUS_BITS 1024 + +# define DH_FLAG_CACHE_MONT_P 0x01 + +# if OPENSSL_API_COMPAT < 0x10100000L +/* + * Does nothing. Previously this switched off constant time behaviour. + */ +# define DH_FLAG_NO_EXP_CONSTTIME 0x00 +# endif + +/* + * If this flag is set the DH method is FIPS compliant and can be used in + * FIPS mode. This is set in the validated module method. If an application + * sets this flag in its own methods it is its responsibility to ensure the + * result is compliant. + */ + +# define DH_FLAG_FIPS_METHOD 0x0400 + +/* + * If this flag is set the operations normally disabled in FIPS mode are + * permitted it is then the applications responsibility to ensure that the + * usage is compliant. + */ + +# define DH_FLAG_NON_FIPS_ALLOW 0x0400 + +/* Already defined in ossl_typ.h */ +/* typedef struct dh_st DH; */ +/* typedef struct dh_method DH_METHOD; */ + +DECLARE_ASN1_ITEM(DHparams) + +# define DH_GENERATOR_2 2 +/* #define DH_GENERATOR_3 3 */ +# define DH_GENERATOR_5 5 + +/* DH_check error codes */ +# define DH_CHECK_P_NOT_PRIME 0x01 +# define DH_CHECK_P_NOT_SAFE_PRIME 0x02 +# define DH_UNABLE_TO_CHECK_GENERATOR 0x04 +# define DH_NOT_SUITABLE_GENERATOR 0x08 +# define DH_CHECK_Q_NOT_PRIME 0x10 +# define DH_CHECK_INVALID_Q_VALUE 0x20 +# define DH_CHECK_INVALID_J_VALUE 0x40 + +/* DH_check_pub_key error codes */ +# define DH_CHECK_PUBKEY_TOO_SMALL 0x01 +# define DH_CHECK_PUBKEY_TOO_LARGE 0x02 +# define DH_CHECK_PUBKEY_INVALID 0x04 + +/* + * primes p where (p-1)/2 is prime too are called "safe"; we define this for + * backward compatibility: + */ +# define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME + +# define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ + (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x)) +# define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \ + (unsigned char *)(x)) +# define d2i_DHparams_bio(bp,x) ASN1_d2i_bio_of(DH,DH_new,d2i_DHparams,bp,x) +# define i2d_DHparams_bio(bp,x) ASN1_i2d_bio_of_const(DH,i2d_DHparams,bp,x) + +DH *DHparams_dup(DH *); + +const DH_METHOD *DH_OpenSSL(void); + +void DH_set_default_method(const DH_METHOD *meth); +const DH_METHOD *DH_get_default_method(void); +int DH_set_method(DH *dh, const DH_METHOD *meth); +DH *DH_new_method(ENGINE *engine); + +DH *DH_new(void); +void DH_free(DH *dh); +int DH_up_ref(DH *dh); +int DH_bits(const DH *dh); +int DH_size(const DH *dh); +int DH_security_bits(const DH *dh); +#define DH_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DH, l, p, newf, dupf, freef) +int DH_set_ex_data(DH *d, int idx, void *arg); +void *DH_get_ex_data(DH *d, int idx); + +/* Deprecated version */ +DEPRECATEDIN_0_9_8(DH *DH_generate_parameters(int prime_len, int generator, + void (*callback) (int, int, + void *), + void *cb_arg)) + +/* New version */ +int DH_generate_parameters_ex(DH *dh, int prime_len, int generator, + BN_GENCB *cb); + +int DH_check(const DH *dh, int *codes); +int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *codes); +int DH_generate_key(DH *dh); +int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh); +int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh); +DH *d2i_DHparams(DH **a, const unsigned char **pp, long length); +int i2d_DHparams(const DH *a, unsigned char **pp); +DH *d2i_DHxparams(DH **a, const unsigned char **pp, long length); +int i2d_DHxparams(const DH *a, unsigned char **pp); +# ifndef OPENSSL_NO_STDIO +int DHparams_print_fp(FILE *fp, const DH *x); +# endif +int DHparams_print(BIO *bp, const DH *x); + +/* RFC 5114 parameters */ +DH *DH_get_1024_160(void); +DH *DH_get_2048_224(void); +DH *DH_get_2048_256(void); + +# ifndef OPENSSL_NO_CMS +/* RFC2631 KDF */ +int DH_KDF_X9_42(unsigned char *out, size_t outlen, + const unsigned char *Z, size_t Zlen, + ASN1_OBJECT *key_oid, + const unsigned char *ukm, size_t ukmlen, const EVP_MD *md); +# endif + +void DH_get0_pqg(const DH *dh, + const BIGNUM **p, const BIGNUM **q, const BIGNUM **g); +int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g); +void DH_get0_key(const DH *dh, + const BIGNUM **pub_key, const BIGNUM **priv_key); +int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key); +void DH_clear_flags(DH *dh, int flags); +int DH_test_flags(const DH *dh, int flags); +void DH_set_flags(DH *dh, int flags); +ENGINE *DH_get0_engine(DH *d); +long DH_get_length(const DH *dh); +int DH_set_length(DH *dh, long length); + +DH_METHOD *DH_meth_new(const char *name, int flags); +void DH_meth_free(DH_METHOD *dhm); +DH_METHOD *DH_meth_dup(const DH_METHOD *dhm); +const char *DH_meth_get0_name(const DH_METHOD *dhm); +int DH_meth_set1_name(DH_METHOD *dhm, const char *name); +int DH_meth_get_flags(DH_METHOD *dhm); +int DH_meth_set_flags(DH_METHOD *dhm, int flags); +void *DH_meth_get0_app_data(const DH_METHOD *dhm); +int DH_meth_set0_app_data(DH_METHOD *dhm, void *app_data); +int (*DH_meth_get_generate_key(const DH_METHOD *dhm)) (DH *); +int DH_meth_set_generate_key(DH_METHOD *dhm, int (*generate_key) (DH *)); +int (*DH_meth_get_compute_key(const DH_METHOD *dhm)) + (unsigned char *key, const BIGNUM *pub_key, DH *dh); +int DH_meth_set_compute_key(DH_METHOD *dhm, + int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh)); +int (*DH_meth_get_bn_mod_exp(const DH_METHOD *dhm)) + (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, + BN_CTX *, BN_MONT_CTX *); +int DH_meth_set_bn_mod_exp(DH_METHOD *dhm, + int (*bn_mod_exp) (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, + const BIGNUM *, BN_CTX *, BN_MONT_CTX *)); +int (*DH_meth_get_init(const DH_METHOD *dhm))(DH *); +int DH_meth_set_init(DH_METHOD *dhm, int (*init)(DH *)); +int (*DH_meth_get_finish(const DH_METHOD *dhm)) (DH *); +int DH_meth_set_finish(DH_METHOD *dhm, int (*finish) (DH *)); +int (*DH_meth_get_generate_params(const DH_METHOD *dhm)) + (DH *, int, int, BN_GENCB *); +int DH_meth_set_generate_params(DH_METHOD *dhm, + int (*generate_params) (DH *, int, int, BN_GENCB *)); + + +# define EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN, len, NULL) + +# define EVP_PKEY_CTX_set_dh_paramgen_subprime_len(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_PARAMGEN_SUBPRIME_LEN, len, NULL) + +# define EVP_PKEY_CTX_set_dh_paramgen_type(ctx, typ) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_PARAMGEN_TYPE, typ, NULL) + +# define EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, gen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR, gen, NULL) + +# define EVP_PKEY_CTX_set_dh_rfc5114(ctx, gen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_RFC5114, gen, NULL) + +# define EVP_PKEY_CTX_set_dhx_rfc5114(ctx, gen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_RFC5114, gen, NULL) + +# define EVP_PKEY_CTX_set_dh_kdf_type(ctx, kdf) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_TYPE, kdf, NULL) + +# define EVP_PKEY_CTX_get_dh_kdf_type(ctx) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_TYPE, -2, NULL) + +# define EVP_PKEY_CTX_set0_dh_kdf_oid(ctx, oid) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_OID, 0, (void *)oid) + +# define EVP_PKEY_CTX_get0_dh_kdf_oid(ctx, poid) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_DH_KDF_OID, 0, (void *)poid) + +# define EVP_PKEY_CTX_set_dh_kdf_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_MD, 0, (void *)md) + +# define EVP_PKEY_CTX_get_dh_kdf_md(ctx, pmd) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_DH_KDF_MD, 0, (void *)pmd) + +# define EVP_PKEY_CTX_set_dh_kdf_outlen(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_OUTLEN, len, NULL) + +# define EVP_PKEY_CTX_get_dh_kdf_outlen(ctx, plen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_DH_KDF_OUTLEN, 0, (void *)plen) + +# define EVP_PKEY_CTX_set0_dh_kdf_ukm(ctx, p, plen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_UKM, plen, (void *)p) + +# define EVP_PKEY_CTX_get0_dh_kdf_ukm(ctx, p) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_DH_KDF_UKM, 0, (void *)p) + +# define EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR (EVP_PKEY_ALG_CTRL + 2) +# define EVP_PKEY_CTRL_DH_RFC5114 (EVP_PKEY_ALG_CTRL + 3) +# define EVP_PKEY_CTRL_DH_PARAMGEN_SUBPRIME_LEN (EVP_PKEY_ALG_CTRL + 4) +# define EVP_PKEY_CTRL_DH_PARAMGEN_TYPE (EVP_PKEY_ALG_CTRL + 5) +# define EVP_PKEY_CTRL_DH_KDF_TYPE (EVP_PKEY_ALG_CTRL + 6) +# define EVP_PKEY_CTRL_DH_KDF_MD (EVP_PKEY_ALG_CTRL + 7) +# define EVP_PKEY_CTRL_GET_DH_KDF_MD (EVP_PKEY_ALG_CTRL + 8) +# define EVP_PKEY_CTRL_DH_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 9) +# define EVP_PKEY_CTRL_GET_DH_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 10) +# define EVP_PKEY_CTRL_DH_KDF_UKM (EVP_PKEY_ALG_CTRL + 11) +# define EVP_PKEY_CTRL_GET_DH_KDF_UKM (EVP_PKEY_ALG_CTRL + 12) +# define EVP_PKEY_CTRL_DH_KDF_OID (EVP_PKEY_ALG_CTRL + 13) +# define EVP_PKEY_CTRL_GET_DH_KDF_OID (EVP_PKEY_ALG_CTRL + 14) + +/* KDF types */ +# define EVP_PKEY_DH_KDF_NONE 1 +# ifndef OPENSSL_NO_CMS +# define EVP_PKEY_DH_KDF_X9_42 2 +# endif + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_DH_strings(void); + +/* Error codes for the DH functions. */ + +/* Function codes. */ +# define DH_F_COMPUTE_KEY 102 +# define DH_F_DHPARAMS_PRINT_FP 101 +# define DH_F_DH_BUILTIN_GENPARAMS 106 +# define DH_F_DH_CMS_DECRYPT 114 +# define DH_F_DH_CMS_SET_PEERKEY 115 +# define DH_F_DH_CMS_SET_SHARED_INFO 116 +# define DH_F_DH_METH_DUP 117 +# define DH_F_DH_METH_NEW 118 +# define DH_F_DH_METH_SET1_NAME 119 +# define DH_F_DH_NEW_METHOD 105 +# define DH_F_DH_PARAM_DECODE 107 +# define DH_F_DH_PRIV_DECODE 110 +# define DH_F_DH_PRIV_ENCODE 111 +# define DH_F_DH_PUB_DECODE 108 +# define DH_F_DH_PUB_ENCODE 109 +# define DH_F_DO_DH_PRINT 100 +# define DH_F_GENERATE_KEY 103 +# define DH_F_PKEY_DH_DERIVE 112 +# define DH_F_PKEY_DH_KEYGEN 113 + +/* Reason codes. */ +# define DH_R_BAD_GENERATOR 101 +# define DH_R_BN_DECODE_ERROR 109 +# define DH_R_BN_ERROR 106 +# define DH_R_DECODE_ERROR 104 +# define DH_R_INVALID_PUBKEY 102 +# define DH_R_KDF_PARAMETER_ERROR 112 +# define DH_R_KEYS_NOT_SET 108 +# define DH_R_MODULUS_TOO_LARGE 103 +# define DH_R_NO_PARAMETERS_SET 107 +# define DH_R_NO_PRIVATE_VALUE 100 +# define DH_R_PARAMETER_ENCODING_ERROR 105 +# define DH_R_PEER_KEY_ERROR 111 +# define DH_R_SHARED_INFO_ERROR 113 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/dsa.h b/android/x86/include/openssl/dsa.h new file mode 100644 index 00000000..cb5fbc2f --- /dev/null +++ b/android/x86/include/openssl/dsa.h @@ -0,0 +1,282 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * The DSS routines are based on patches supplied by + * Steven Schoch <schoch@sheba.arc.nasa.gov>. + */ + +#ifndef HEADER_DSA_H +# define HEADER_DSA_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_DSA +# ifdef __cplusplus +extern "C" { +# endif +# include <openssl/e_os2.h> +# include <openssl/bio.h> +# include <openssl/crypto.h> +# include <openssl/ossl_typ.h> +# include <openssl/opensslconf.h> +# include <openssl/bn.h> +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/dh.h> +# endif + +# ifndef OPENSSL_DSA_MAX_MODULUS_BITS +# define OPENSSL_DSA_MAX_MODULUS_BITS 10000 +# endif + +# define OPENSSL_DSA_FIPS_MIN_MODULUS_BITS 1024 + +# define DSA_FLAG_CACHE_MONT_P 0x01 +# if OPENSSL_API_COMPAT < 0x10100000L +/* + * Does nothing. Previously this switched off constant time behaviour. + */ +# define DSA_FLAG_NO_EXP_CONSTTIME 0x00 +# endif + +/* + * If this flag is set the DSA method is FIPS compliant and can be used in + * FIPS mode. This is set in the validated module method. If an application + * sets this flag in its own methods it is its responsibility to ensure the + * result is compliant. + */ + +# define DSA_FLAG_FIPS_METHOD 0x0400 + +/* + * If this flag is set the operations normally disabled in FIPS mode are + * permitted it is then the applications responsibility to ensure that the + * usage is compliant. + */ + +# define DSA_FLAG_NON_FIPS_ALLOW 0x0400 +# define DSA_FLAG_FIPS_CHECKED 0x0800 + +/* Already defined in ossl_typ.h */ +/* typedef struct dsa_st DSA; */ +/* typedef struct dsa_method DSA_METHOD; */ + +typedef struct DSA_SIG_st DSA_SIG; + +# define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ + (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x)) +# define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \ + (unsigned char *)(x)) +# define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x) +# define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x) + +DSA *DSAparams_dup(DSA *x); +DSA_SIG *DSA_SIG_new(void); +void DSA_SIG_free(DSA_SIG *a); +int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp); +DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length); +void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); +int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s); + +DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); +int DSA_do_verify(const unsigned char *dgst, int dgst_len, + DSA_SIG *sig, DSA *dsa); + +const DSA_METHOD *DSA_OpenSSL(void); + +void DSA_set_default_method(const DSA_METHOD *); +const DSA_METHOD *DSA_get_default_method(void); +int DSA_set_method(DSA *dsa, const DSA_METHOD *); +const DSA_METHOD *DSA_get_method(DSA *d); + +DSA *DSA_new(void); +DSA *DSA_new_method(ENGINE *engine); +void DSA_free(DSA *r); +/* "up" the DSA object's reference count */ +int DSA_up_ref(DSA *r); +int DSA_size(const DSA *); +int DSA_bits(const DSA *d); +int DSA_security_bits(const DSA *d); + /* next 4 return -1 on error */ +int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); +int DSA_sign(int type, const unsigned char *dgst, int dlen, + unsigned char *sig, unsigned int *siglen, DSA *dsa); +int DSA_verify(int type, const unsigned char *dgst, int dgst_len, + const unsigned char *sigbuf, int siglen, DSA *dsa); +#define DSA_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, l, p, newf, dupf, freef) +int DSA_set_ex_data(DSA *d, int idx, void *arg); +void *DSA_get_ex_data(DSA *d, int idx); + +DSA *d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length); +DSA *d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length); +DSA *d2i_DSAparams(DSA **a, const unsigned char **pp, long length); + +/* Deprecated version */ +DEPRECATEDIN_0_9_8(DSA *DSA_generate_parameters(int bits, + unsigned char *seed, + int seed_len, + int *counter_ret, + unsigned long *h_ret, void + (*callback) (int, int, + void *), + void *cb_arg)) + +/* New version */ +int DSA_generate_parameters_ex(DSA *dsa, int bits, + const unsigned char *seed, int seed_len, + int *counter_ret, unsigned long *h_ret, + BN_GENCB *cb); + +int DSA_generate_key(DSA *a); +int i2d_DSAPublicKey(const DSA *a, unsigned char **pp); +int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp); +int i2d_DSAparams(const DSA *a, unsigned char **pp); + +int DSAparams_print(BIO *bp, const DSA *x); +int DSA_print(BIO *bp, const DSA *x, int off); +# ifndef OPENSSL_NO_STDIO +int DSAparams_print_fp(FILE *fp, const DSA *x); +int DSA_print_fp(FILE *bp, const DSA *x, int off); +# endif + +# define DSS_prime_checks 50 +/* + * Primality test according to FIPS PUB 186[-1], Appendix 2.1: 50 rounds of + * Rabin-Miller + */ +# define DSA_is_prime(n, callback, cb_arg) \ + BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg) + +# ifndef OPENSSL_NO_DH +/* + * Convert DSA structure (key or just parameters) into DH structure (be + * careful to avoid small subgroup attacks when using this!) + */ +DH *DSA_dup_DH(const DSA *r); +# endif + +# define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL) + +# define EVP_PKEY_CTRL_DSA_PARAMGEN_BITS (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS (EVP_PKEY_ALG_CTRL + 2) +# define EVP_PKEY_CTRL_DSA_PARAMGEN_MD (EVP_PKEY_ALG_CTRL + 3) + +void DSA_get0_pqg(const DSA *d, + const BIGNUM **p, const BIGNUM **q, const BIGNUM **g); +int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g); +void DSA_get0_key(const DSA *d, + const BIGNUM **pub_key, const BIGNUM **priv_key); +int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key); +void DSA_clear_flags(DSA *d, int flags); +int DSA_test_flags(const DSA *d, int flags); +void DSA_set_flags(DSA *d, int flags); +ENGINE *DSA_get0_engine(DSA *d); + +DSA_METHOD *DSA_meth_new(const char *name, int flags); +void DSA_meth_free(DSA_METHOD *dsam); +DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam); +const char *DSA_meth_get0_name(const DSA_METHOD *dsam); +int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name); +int DSA_meth_get_flags(DSA_METHOD *dsam); +int DSA_meth_set_flags(DSA_METHOD *dsam, int flags); +void *DSA_meth_get0_app_data(const DSA_METHOD *dsam); +int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data); +DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam)) + (const unsigned char *, int, DSA *); +int DSA_meth_set_sign(DSA_METHOD *dsam, + DSA_SIG *(*sign) (const unsigned char *, int, DSA *)); +int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam)) + (DSA *, BN_CTX *, BIGNUM **, BIGNUM **); +int DSA_meth_set_sign_setup(DSA_METHOD *dsam, + int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **)); +int (*DSA_meth_get_verify(const DSA_METHOD *dsam)) + (const unsigned char *, int , DSA_SIG *, DSA *); +int DSA_meth_set_verify(DSA_METHOD *dsam, + int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *)); +int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam)) + (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, + const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *); +int DSA_meth_set_mod_exp(DSA_METHOD *dsam, + int (*mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, + const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *, + BN_MONT_CTX *)); +int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam)) + (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, + BN_CTX *, BN_MONT_CTX *); +int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam, + int (*bn_mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, + const BIGNUM *, BN_CTX *, BN_MONT_CTX *)); +int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *); +int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *)); +int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *); +int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *)); +int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam)) + (DSA *, int, const unsigned char *, int, int *, unsigned long *, + BN_GENCB *); +int DSA_meth_set_paramgen(DSA_METHOD *dsam, + int (*paramgen) (DSA *, int, const unsigned char *, int, int *, + unsigned long *, BN_GENCB *)); +int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *); +int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *)); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_DSA_strings(void); + +/* Error codes for the DSA functions. */ + +/* Function codes. */ +# define DSA_F_DSAPARAMS_PRINT 100 +# define DSA_F_DSAPARAMS_PRINT_FP 101 +# define DSA_F_DSA_BUILTIN_PARAMGEN 125 +# define DSA_F_DSA_BUILTIN_PARAMGEN2 126 +# define DSA_F_DSA_DO_SIGN 112 +# define DSA_F_DSA_DO_VERIFY 113 +# define DSA_F_DSA_METH_DUP 127 +# define DSA_F_DSA_METH_NEW 128 +# define DSA_F_DSA_METH_SET1_NAME 129 +# define DSA_F_DSA_NEW_METHOD 103 +# define DSA_F_DSA_PARAM_DECODE 119 +# define DSA_F_DSA_PRINT_FP 105 +# define DSA_F_DSA_PRIV_DECODE 115 +# define DSA_F_DSA_PRIV_ENCODE 116 +# define DSA_F_DSA_PUB_DECODE 117 +# define DSA_F_DSA_PUB_ENCODE 118 +# define DSA_F_DSA_SIGN 106 +# define DSA_F_DSA_SIGN_SETUP 107 +# define DSA_F_DSA_SIG_NEW 102 +# define DSA_F_OLD_DSA_PRIV_DECODE 122 +# define DSA_F_PKEY_DSA_CTRL 120 +# define DSA_F_PKEY_DSA_KEYGEN 121 + +/* Reason codes. */ +# define DSA_R_BAD_Q_VALUE 102 +# define DSA_R_BN_DECODE_ERROR 108 +# define DSA_R_BN_ERROR 109 +# define DSA_R_DECODE_ERROR 104 +# define DSA_R_INVALID_DIGEST_TYPE 106 +# define DSA_R_INVALID_PARAMETERS 112 +# define DSA_R_MISSING_PARAMETERS 101 +# define DSA_R_MODULUS_TOO_LARGE 103 +# define DSA_R_NO_PARAMETERS_SET 107 +# define DSA_R_PARAMETER_ENCODING_ERROR 105 +# define DSA_R_Q_NOT_PRIME 113 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/dtls1.h b/android/x86/include/openssl/dtls1.h new file mode 100644 index 00000000..f4769f83 --- /dev/null +++ b/android/x86/include/openssl/dtls1.h @@ -0,0 +1,56 @@ +/* + * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DTLS1_H +# define HEADER_DTLS1_H + +#ifdef __cplusplus +extern "C" { +#endif + +# define DTLS1_VERSION 0xFEFF +# define DTLS1_2_VERSION 0xFEFD +# define DTLS_MIN_VERSION DTLS1_VERSION +# define DTLS_MAX_VERSION DTLS1_2_VERSION +# define DTLS1_VERSION_MAJOR 0xFE + +# define DTLS1_BAD_VER 0x0100 + +/* Special value for method supporting multiple versions */ +# define DTLS_ANY_VERSION 0x1FFFF + +/* lengths of messages */ +# define DTLS1_COOKIE_LENGTH 256 + +# define DTLS1_RT_HEADER_LENGTH 13 + +# define DTLS1_HM_HEADER_LENGTH 12 + +# define DTLS1_HM_BAD_FRAGMENT -2 +# define DTLS1_HM_FRAGMENT_RETRY -3 + +# define DTLS1_CCS_HEADER_LENGTH 1 + +# ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE +# define DTLS1_AL_HEADER_LENGTH 7 +# else +# define DTLS1_AL_HEADER_LENGTH 2 +# endif + + +/* Timeout multipliers (timeout slice is defined in apps/timeouts.h */ +# define DTLS1_TMO_READ_COUNT 2 +# define DTLS1_TMO_WRITE_COUNT 2 + +# define DTLS1_TMO_ALERT_COUNT 12 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/x86/include/openssl/e_os2.h b/android/x86/include/openssl/e_os2.h new file mode 100644 index 00000000..99ea3477 --- /dev/null +++ b/android/x86/include/openssl/e_os2.h @@ -0,0 +1,311 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_E_OS2_H +# define HEADER_E_OS2_H + +# include <openssl/opensslconf.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Detect operating systems. This probably needs completing. + * The result is that at least one OPENSSL_SYS_os macro should be defined. + * However, if none is defined, Unix is assumed. + **/ + +# define OPENSSL_SYS_UNIX + +/* --------------------- Microsoft operating systems ---------------------- */ + +/* + * Note that MSDOS actually denotes 32-bit environments running on top of + * MS-DOS, such as DJGPP one. + */ +# if defined(OPENSSL_SYS_MSDOS) +# undef OPENSSL_SYS_UNIX +# endif + +/* + * For 32 bit environment, there seems to be the CygWin environment and then + * all the others that try to do the same thing Microsoft does... + */ +/* + * UEFI lives here because it might be built with a Microsoft toolchain and + * we need to avoid the false positive match on Windows. + */ +# if defined(OPENSSL_SYS_UEFI) +# undef OPENSSL_SYS_UNIX +# elif defined(OPENSSL_SYS_UWIN) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WIN32_UWIN +# else +# if defined(__CYGWIN__) || defined(OPENSSL_SYS_CYGWIN) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WIN32_CYGWIN +# else +# if defined(_WIN32) || defined(OPENSSL_SYS_WIN32) +# undef OPENSSL_SYS_UNIX +# if !defined(OPENSSL_SYS_WIN32) +# define OPENSSL_SYS_WIN32 +# endif +# endif +# if defined(_WIN64) || defined(OPENSSL_SYS_WIN64) +# undef OPENSSL_SYS_UNIX +# if !defined(OPENSSL_SYS_WIN64) +# define OPENSSL_SYS_WIN64 +# endif +# endif +# if defined(OPENSSL_SYS_WINNT) +# undef OPENSSL_SYS_UNIX +# endif +# if defined(OPENSSL_SYS_WINCE) +# undef OPENSSL_SYS_UNIX +# endif +# endif +# endif + +/* Anything that tries to look like Microsoft is "Windows" */ +# if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WINDOWS +# ifndef OPENSSL_SYS_MSDOS +# define OPENSSL_SYS_MSDOS +# endif +# endif + +/* + * DLL settings. This part is a bit tough, because it's up to the + * application implementor how he or she will link the application, so it + * requires some macro to be used. + */ +# ifdef OPENSSL_SYS_WINDOWS +# ifndef OPENSSL_OPT_WINDLL +# if defined(_WINDLL) /* This is used when building OpenSSL to + * indicate that DLL linkage should be used */ +# define OPENSSL_OPT_WINDLL +# endif +# endif +# endif + +/* ------------------------------- OpenVMS -------------------------------- */ +# if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS) +# if !defined(OPENSSL_SYS_VMS) +# undef OPENSSL_SYS_UNIX +# endif +# define OPENSSL_SYS_VMS +# if defined(__DECC) +# define OPENSSL_SYS_VMS_DECC +# elif defined(__DECCXX) +# define OPENSSL_SYS_VMS_DECC +# define OPENSSL_SYS_VMS_DECCXX +# else +# define OPENSSL_SYS_VMS_NODECC +# endif +# endif + +/* -------------------------------- Unix ---------------------------------- */ +# ifdef OPENSSL_SYS_UNIX +# if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX) +# define OPENSSL_SYS_LINUX +# endif +# if defined(_AIX) && !defined(OPENSSL_SYS_AIX) +# define OPENSSL_SYS_AIX +# endif +# endif + +/* -------------------------------- VOS ----------------------------------- */ +# if defined(__VOS__) && !defined(OPENSSL_SYS_VOS) +# define OPENSSL_SYS_VOS +# ifdef __HPPA__ +# define OPENSSL_SYS_VOS_HPPA +# endif +# ifdef __IA32__ +# define OPENSSL_SYS_VOS_IA32 +# endif +# endif + +/** + * That's it for OS-specific stuff + *****************************************************************************/ + +/* Specials for I/O an exit */ +# ifdef OPENSSL_SYS_MSDOS +# define OPENSSL_UNISTD_IO <io.h> +# define OPENSSL_DECLARE_EXIT extern void exit(int); +# else +# define OPENSSL_UNISTD_IO OPENSSL_UNISTD +# define OPENSSL_DECLARE_EXIT /* declared in unistd.h */ +# endif + +/*- + * Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare + * certain global symbols that, with some compilers under VMS, have to be + * defined and declared explicitly with globaldef and globalref. + * Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare + * DLL exports and imports for compilers under Win32. These are a little + * more complicated to use. Basically, for any library that exports some + * global variables, the following code must be present in the header file + * that declares them, before OPENSSL_EXTERN is used: + * + * #ifdef SOME_BUILD_FLAG_MACRO + * # undef OPENSSL_EXTERN + * # define OPENSSL_EXTERN OPENSSL_EXPORT + * #endif + * + * The default is to have OPENSSL_EXPORT, OPENSSL_EXTERN and OPENSSL_GLOBAL + * have some generally sensible values. + */ + +# if defined(OPENSSL_SYS_VMS_NODECC) +# define OPENSSL_EXPORT globalref +# define OPENSSL_EXTERN globalref +# define OPENSSL_GLOBAL globaldef +# elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL) +# define OPENSSL_EXPORT extern __declspec(dllexport) +# define OPENSSL_EXTERN extern __declspec(dllimport) +# define OPENSSL_GLOBAL +# else +# define OPENSSL_EXPORT extern +# define OPENSSL_EXTERN extern +# define OPENSSL_GLOBAL +# endif + +/*- + * Macros to allow global variables to be reached through function calls when + * required (if a shared library version requires it, for example. + * The way it's done allows definitions like this: + * + * // in foobar.c + * OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0) + * // in foobar.h + * OPENSSL_DECLARE_GLOBAL(int,foobar); + * #define foobar OPENSSL_GLOBAL_REF(foobar) + */ +# ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION +# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \ + type *_shadow_##name(void) \ + { static type _hide_##name=value; return &_hide_##name; } +# define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void) +# define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name())) +# else +# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value; +# define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name +# define OPENSSL_GLOBAL_REF(name) _shadow_##name +# endif + +# ifdef _WIN32 +# ifdef _WIN64 +# define ossl_ssize_t __int64 +# define OSSL_SSIZE_MAX _I64_MAX +# else +# define ossl_ssize_t int +# define OSSL_SSIZE_MAX INT_MAX +# endif +# endif + +# if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t) +# define ossl_ssize_t int +# define OSSL_SSIZE_MAX INT_MAX +# endif + +# ifndef ossl_ssize_t +# define ossl_ssize_t ssize_t +# if defined(SSIZE_MAX) +# define OSSL_SSIZE_MAX SSIZE_MAX +# elif defined(_POSIX_SSIZE_MAX) +# define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX +# endif +# endif + +# ifdef DEBUG_UNUSED +# define __owur __attribute__((__warn_unused_result__)) +# else +# define __owur +# endif + +/* Standard integer types */ +# if defined(OPENSSL_SYS_UEFI) +typedef INT8 int8_t; +typedef UINT8 uint8_t; +typedef INT16 int16_t; +typedef UINT16 uint16_t; +typedef INT32 int32_t; +typedef UINT32 uint32_t; +typedef INT64 int64_t; +typedef UINT64 uint64_t; +# define PRIu64 "%Lu" +# elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + defined(__osf__) || defined(__sgi) || defined(__hpux) || \ + defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__) +# include <inttypes.h> +# elif defined(_MSC_VER) && _MSC_VER<=1500 +/* + * minimally required typdefs for systems not supporting inttypes.h or + * stdint.h: currently just older VC++ + */ +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef short int16_t; +typedef unsigned short uint16_t; +typedef int int32_t; +typedef unsigned int uint32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +# else +# include <stdint.h> +# endif + +/* + * We need a format operator for some client tools for uint64_t. If inttypes.h + * isn't available or did not define it, just go with hard-coded. + */ +# ifndef PRIu64 +# ifdef SIXTY_FOUR_BIT_LONG +# define PRIu64 "lu" +# else +# define PRIu64 "llu" +# endif +# endif + +/* ossl_inline: portable inline definition usable in public headers */ +# if !defined(inline) && !defined(__cplusplus) +# if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L + /* just use inline */ +# define ossl_inline inline +# elif defined(__GNUC__) && __GNUC__>=2 +# define ossl_inline __inline__ +# elif defined(_MSC_VER) + /* + * Visual Studio: inline is available in C++ only, however + * __inline is available for C, see + * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx + */ +# define ossl_inline __inline +# else +# define ossl_inline +# endif +# else +# define ossl_inline inline +# endif + +# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +# define ossl_noreturn _Noreturn +# elif defined(__GNUC__) && __GNUC__ >= 2 +# define ossl_noreturn __attribute__((noreturn)) +# else +# define ossl_noreturn +# endif + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/x86/include/openssl/ebcdic.h b/android/x86/include/openssl/ebcdic.h new file mode 100644 index 00000000..aa012855 --- /dev/null +++ b/android/x86/include/openssl/ebcdic.h @@ -0,0 +1,33 @@ +/* + * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_EBCDIC_H +# define HEADER_EBCDIC_H + +# include <stdlib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Avoid name clashes with other applications */ +# define os_toascii _openssl_os_toascii +# define os_toebcdic _openssl_os_toebcdic +# define ebcdic2ascii _openssl_ebcdic2ascii +# define ascii2ebcdic _openssl_ascii2ebcdic + +extern const unsigned char os_toascii[256]; +extern const unsigned char os_toebcdic[256]; +void *ebcdic2ascii(void *dest, const void *srce, size_t count); +void *ascii2ebcdic(void *dest, const void *srce, size_t count); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/x86/include/openssl/ec.h b/android/x86/include/openssl/ec.h new file mode 100644 index 00000000..656cb410 --- /dev/null +++ b/android/x86/include/openssl/ec.h @@ -0,0 +1,1581 @@ +/* + * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * + * Portions of the attached software ("Contribution") are developed by + * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. + * + * The Contribution is licensed pursuant to the OpenSSL open source + * license provided above. + * + * The elliptic curve binary polynomial software is originally written by + * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. + * + */ + +#ifndef HEADER_EC_H +# define HEADER_EC_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_EC +# include <openssl/asn1.h> +# include <openssl/symhacks.h> +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/bn.h> +# endif +# ifdef __cplusplus +extern "C" { +# endif + +# ifndef OPENSSL_ECC_MAX_FIELD_BITS +# define OPENSSL_ECC_MAX_FIELD_BITS 661 +# endif + +/** Enum for the point conversion form as defined in X9.62 (ECDSA) + * for the encoding of a elliptic curve point (x,y) */ +typedef enum { + /** the point is encoded as z||x, where the octet z specifies + * which solution of the quadratic equation y is */ + POINT_CONVERSION_COMPRESSED = 2, + /** the point is encoded as z||x||y, where z is the octet 0x04 */ + POINT_CONVERSION_UNCOMPRESSED = 4, + /** the point is encoded as z||x||y, where the octet z specifies + * which solution of the quadratic equation y is */ + POINT_CONVERSION_HYBRID = 6 +} point_conversion_form_t; + +typedef struct ec_method_st EC_METHOD; +typedef struct ec_group_st EC_GROUP; +typedef struct ec_point_st EC_POINT; +typedef struct ecpk_parameters_st ECPKPARAMETERS; +typedef struct ec_parameters_st ECPARAMETERS; + +/********************************************************************/ +/* EC_METHODs for curves over GF(p) */ +/********************************************************************/ + +/** Returns the basic GFp ec methods which provides the basis for the + * optimized methods. + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_simple_method(void); + +/** Returns GFp methods using montgomery multiplication. + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_mont_method(void); + +/** Returns GFp methods using optimized methods for NIST recommended curves + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_nist_method(void); + +# ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 +/** Returns 64-bit optimized methods for nistp224 + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_nistp224_method(void); + +/** Returns 64-bit optimized methods for nistp256 + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_nistp256_method(void); + +/** Returns 64-bit optimized methods for nistp521 + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_nistp521_method(void); +# endif + +# ifndef OPENSSL_NO_EC2M +/********************************************************************/ +/* EC_METHOD for curves over GF(2^m) */ +/********************************************************************/ + +/** Returns the basic GF2m ec method + * \return EC_METHOD object + */ +const EC_METHOD *EC_GF2m_simple_method(void); + +# endif + +/********************************************************************/ +/* EC_GROUP functions */ +/********************************************************************/ + +/** Creates a new EC_GROUP object + * \param meth EC_METHOD to use + * \return newly created EC_GROUP object or NULL in case of an error. + */ +EC_GROUP *EC_GROUP_new(const EC_METHOD *meth); + +/** Frees a EC_GROUP object + * \param group EC_GROUP object to be freed. + */ +void EC_GROUP_free(EC_GROUP *group); + +/** Clears and frees a EC_GROUP object + * \param group EC_GROUP object to be cleared and freed. + */ +void EC_GROUP_clear_free(EC_GROUP *group); + +/** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD. + * \param dst destination EC_GROUP object + * \param src source EC_GROUP object + * \return 1 on success and 0 if an error occurred. + */ +int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src); + +/** Creates a new EC_GROUP object and copies the copies the content + * form src to the newly created EC_KEY object + * \param src source EC_GROUP object + * \return newly created EC_GROUP object or NULL in case of an error. + */ +EC_GROUP *EC_GROUP_dup(const EC_GROUP *src); + +/** Returns the EC_METHOD of the EC_GROUP object. + * \param group EC_GROUP object + * \return EC_METHOD used in this EC_GROUP object. + */ +const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group); + +/** Returns the field type of the EC_METHOD. + * \param meth EC_METHOD object + * \return NID of the underlying field type OID. + */ +int EC_METHOD_get_field_type(const EC_METHOD *meth); + +/** Sets the generator and it's order/cofactor of a EC_GROUP object. + * \param group EC_GROUP object + * \param generator EC_POINT object with the generator. + * \param order the order of the group generated by the generator. + * \param cofactor the index of the sub-group generated by the generator + * in the group of all points on the elliptic curve. + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, + const BIGNUM *order, const BIGNUM *cofactor); + +/** Returns the generator of a EC_GROUP object. + * \param group EC_GROUP object + * \return the currently used generator (possibly NULL). + */ +const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group); + +/** Returns the montgomery data for order(Generator) + * \param group EC_GROUP object + * \return the currently used montgomery data (possibly NULL). +*/ +BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group); + +/** Gets the order of a EC_GROUP + * \param group EC_GROUP object + * \param order BIGNUM to which the order is copied + * \param ctx unused + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx); + +/** Gets the order of an EC_GROUP + * \param group EC_GROUP object + * \return the group order + */ +const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group); + +/** Gets the number of bits of the order of an EC_GROUP + * \param group EC_GROUP object + * \return number of bits of group order. + */ +int EC_GROUP_order_bits(const EC_GROUP *group); + +/** Gets the cofactor of a EC_GROUP + * \param group EC_GROUP object + * \param cofactor BIGNUM to which the cofactor is copied + * \param ctx unused + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, + BN_CTX *ctx); + +/** Gets the cofactor of an EC_GROUP + * \param group EC_GROUP object + * \return the group cofactor + */ +const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group); + +/** Sets the name of a EC_GROUP object + * \param group EC_GROUP object + * \param nid NID of the curve name OID + */ +void EC_GROUP_set_curve_name(EC_GROUP *group, int nid); + +/** Returns the curve name of a EC_GROUP object + * \param group EC_GROUP object + * \return NID of the curve name OID or 0 if not set. + */ +int EC_GROUP_get_curve_name(const EC_GROUP *group); + +void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); +int EC_GROUP_get_asn1_flag(const EC_GROUP *group); + +void EC_GROUP_set_point_conversion_form(EC_GROUP *group, + point_conversion_form_t form); +point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *); + +unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x); +size_t EC_GROUP_get_seed_len(const EC_GROUP *); +size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len); + +/** Sets the parameter of a ec over GFp defined by y^2 = x^3 + a*x + b + * \param group EC_GROUP object + * \param p BIGNUM with the prime number + * \param a BIGNUM with parameter a of the equation + * \param b BIGNUM with parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, + const BIGNUM *b, BN_CTX *ctx); + +/** Gets the parameter of the ec over GFp defined by y^2 = x^3 + a*x + b + * \param group EC_GROUP object + * \param p BIGNUM for the prime number + * \param a BIGNUM for parameter a of the equation + * \param b BIGNUM for parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, + BIGNUM *b, BN_CTX *ctx); + +# ifndef OPENSSL_NO_EC2M +/** Sets the parameter of a ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b + * \param group EC_GROUP object + * \param p BIGNUM with the polynomial defining the underlying field + * \param a BIGNUM with parameter a of the equation + * \param b BIGNUM with parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, + const BIGNUM *b, BN_CTX *ctx); + +/** Gets the parameter of the ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b + * \param group EC_GROUP object + * \param p BIGNUM for the polynomial defining the underlying field + * \param a BIGNUM for parameter a of the equation + * \param b BIGNUM for parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, + BIGNUM *b, BN_CTX *ctx); +# endif +/** Returns the number of bits needed to represent a field element + * \param group EC_GROUP object + * \return number of bits needed to represent a field element + */ +int EC_GROUP_get_degree(const EC_GROUP *group); + +/** Checks whether the parameter in the EC_GROUP define a valid ec group + * \param group EC_GROUP object + * \param ctx BN_CTX object (optional) + * \return 1 if group is a valid ec group and 0 otherwise + */ +int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx); + +/** Checks whether the discriminant of the elliptic curve is zero or not + * \param group EC_GROUP object + * \param ctx BN_CTX object (optional) + * \return 1 if the discriminant is not zero and 0 otherwise + */ +int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx); + +/** Compares two EC_GROUP objects + * \param a first EC_GROUP object + * \param b second EC_GROUP object + * \param ctx BN_CTX object (optional) + * \return 0 if the groups are equal, 1 if not, or -1 on error + */ +int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx); + +/* + * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after + * choosing an appropriate EC_METHOD + */ + +/** Creates a new EC_GROUP object with the specified parameters defined + * over GFp (defined by the equation y^2 = x^3 + a*x + b) + * \param p BIGNUM with the prime number + * \param a BIGNUM with the parameter a of the equation + * \param b BIGNUM with the parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return newly created EC_GROUP object with the specified parameters + */ +EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, + const BIGNUM *b, BN_CTX *ctx); +# ifndef OPENSSL_NO_EC2M +/** Creates a new EC_GROUP object with the specified parameters defined + * over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b) + * \param p BIGNUM with the polynomial defining the underlying field + * \param a BIGNUM with the parameter a of the equation + * \param b BIGNUM with the parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return newly created EC_GROUP object with the specified parameters + */ +EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, + const BIGNUM *b, BN_CTX *ctx); +# endif + +/** Creates a EC_GROUP object with a curve specified by a NID + * \param nid NID of the OID of the curve name + * \return newly created EC_GROUP object with specified curve or NULL + * if an error occurred + */ +EC_GROUP *EC_GROUP_new_by_curve_name(int nid); + +/** Creates a new EC_GROUP object from an ECPARAMETERS object + * \param params pointer to the ECPARAMETERS object + * \return newly created EC_GROUP object with specified curve or NULL + * if an error occurred + */ +EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params); + +/** Creates an ECPARAMETERS object for the the given EC_GROUP object. + * \param group pointer to the EC_GROUP object + * \param params pointer to an existing ECPARAMETERS object or NULL + * \return pointer to the new ECPARAMETERS object or NULL + * if an error occurred. + */ +ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, + ECPARAMETERS *params); + +/** Creates a new EC_GROUP object from an ECPKPARAMETERS object + * \param params pointer to an existing ECPKPARAMETERS object, or NULL + * \return newly created EC_GROUP object with specified curve, or NULL + * if an error occurred + */ +EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params); + +/** Creates an ECPKPARAMETERS object for the the given EC_GROUP object. + * \param group pointer to the EC_GROUP object + * \param params pointer to an existing ECPKPARAMETERS object or NULL + * \return pointer to the new ECPKPARAMETERS object or NULL + * if an error occurred. + */ +ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group, + ECPKPARAMETERS *params); + +/********************************************************************/ +/* handling of internal curves */ +/********************************************************************/ + +typedef struct { + int nid; + const char *comment; +} EC_builtin_curve; + +/* + * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all + * available curves or zero if a error occurred. In case r is not zero, + * nitems EC_builtin_curve structures are filled with the data of the first + * nitems internal groups + */ +size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); + +const char *EC_curve_nid2nist(int nid); +int EC_curve_nist2nid(const char *name); + +/********************************************************************/ +/* EC_POINT functions */ +/********************************************************************/ + +/** Creates a new EC_POINT object for the specified EC_GROUP + * \param group EC_GROUP the underlying EC_GROUP object + * \return newly created EC_POINT object or NULL if an error occurred + */ +EC_POINT *EC_POINT_new(const EC_GROUP *group); + +/** Frees a EC_POINT object + * \param point EC_POINT object to be freed + */ +void EC_POINT_free(EC_POINT *point); + +/** Clears and frees a EC_POINT object + * \param point EC_POINT object to be cleared and freed + */ +void EC_POINT_clear_free(EC_POINT *point); + +/** Copies EC_POINT object + * \param dst destination EC_POINT object + * \param src source EC_POINT object + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src); + +/** Creates a new EC_POINT object and copies the content of the supplied + * EC_POINT + * \param src source EC_POINT object + * \param group underlying the EC_GROUP object + * \return newly created EC_POINT object or NULL if an error occurred + */ +EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); + +/** Returns the EC_METHOD used in EC_POINT object + * \param point EC_POINT object + * \return the EC_METHOD used + */ +const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); + +/** Sets a point to infinity (neutral element) + * \param group underlying EC_GROUP object + * \param point EC_POINT to set to infinity + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); + +/** Sets the jacobian projective coordinates of a EC_POINT over GFp + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with the x-coordinate + * \param y BIGNUM with the y-coordinate + * \param z BIGNUM with the z-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, + EC_POINT *p, const BIGNUM *x, + const BIGNUM *y, const BIGNUM *z, + BN_CTX *ctx); + +/** Gets the jacobian projective coordinates of a EC_POINT over GFp + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM for the x-coordinate + * \param y BIGNUM for the y-coordinate + * \param z BIGNUM for the z-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, + const EC_POINT *p, BIGNUM *x, + BIGNUM *y, BIGNUM *z, + BN_CTX *ctx); + +/** Sets the affine coordinates of a EC_POINT over GFp + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with the x-coordinate + * \param y BIGNUM with the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, + const BIGNUM *x, const BIGNUM *y, + BN_CTX *ctx); + +/** Gets the affine coordinates of a EC_POINT over GFp + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM for the x-coordinate + * \param y BIGNUM for the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, + const EC_POINT *p, BIGNUM *x, + BIGNUM *y, BN_CTX *ctx); + +/** Sets the x9.62 compressed coordinates of a EC_POINT over GFp + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with x-coordinate + * \param y_bit integer with the y-Bit (either 0 or 1) + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, + EC_POINT *p, const BIGNUM *x, + int y_bit, BN_CTX *ctx); +# ifndef OPENSSL_NO_EC2M +/** Sets the affine coordinates of a EC_POINT over GF2m + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with the x-coordinate + * \param y BIGNUM with the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p, + const BIGNUM *x, const BIGNUM *y, + BN_CTX *ctx); + +/** Gets the affine coordinates of a EC_POINT over GF2m + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM for the x-coordinate + * \param y BIGNUM for the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, + const EC_POINT *p, BIGNUM *x, + BIGNUM *y, BN_CTX *ctx); + +/** Sets the x9.62 compressed coordinates of a EC_POINT over GF2m + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with x-coordinate + * \param y_bit integer with the y-Bit (either 0 or 1) + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, + EC_POINT *p, const BIGNUM *x, + int y_bit, BN_CTX *ctx); +# endif +/** Encodes a EC_POINT object to a octet string + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param form point conversion form + * \param buf memory buffer for the result. If NULL the function returns + * required buffer size. + * \param len length of the memory buffer + * \param ctx BN_CTX object (optional) + * \return the length of the encoded octet string or 0 if an error occurred + */ +size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p, + point_conversion_form_t form, + unsigned char *buf, size_t len, BN_CTX *ctx); + +/** Decodes a EC_POINT from a octet string + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param buf memory buffer with the encoded ec point + * \param len length of the encoded ec point + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, + const unsigned char *buf, size_t len, BN_CTX *ctx); + +/** Encodes an EC_POINT object to an allocated octet string + * \param group underlying EC_GROUP object + * \param point EC_POINT object + * \param form point conversion form + * \param pbuf returns pointer to allocated buffer + * \param len length of the memory buffer + * \param ctx BN_CTX object (optional) + * \return the length of the encoded octet string or 0 if an error occurred + */ + +size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point, + point_conversion_form_t form, + unsigned char **pbuf, BN_CTX *ctx); + +/* other interfaces to point2oct/oct2point: */ +BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *, + point_conversion_form_t form, BIGNUM *, BN_CTX *); +EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *, + EC_POINT *, BN_CTX *); +char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *, + point_conversion_form_t form, BN_CTX *); +EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *, + EC_POINT *, BN_CTX *); + +/********************************************************************/ +/* functions for doing EC_POINT arithmetic */ +/********************************************************************/ + +/** Computes the sum of two EC_POINT + * \param group underlying EC_GROUP object + * \param r EC_POINT object for the result (r = a + b) + * \param a EC_POINT object with the first summand + * \param b EC_POINT object with the second summand + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, + const EC_POINT *b, BN_CTX *ctx); + +/** Computes the double of a EC_POINT + * \param group underlying EC_GROUP object + * \param r EC_POINT object for the result (r = 2 * a) + * \param a EC_POINT object + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, + BN_CTX *ctx); + +/** Computes the inverse of a EC_POINT + * \param group underlying EC_GROUP object + * \param a EC_POINT object to be inverted (it's used for the result as well) + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx); + +/** Checks whether the point is the neutral element of the group + * \param group the underlying EC_GROUP object + * \param p EC_POINT object + * \return 1 if the point is the neutral element and 0 otherwise + */ +int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p); + +/** Checks whether the point is on the curve + * \param group underlying EC_GROUP object + * \param point EC_POINT object to check + * \param ctx BN_CTX object (optional) + * \return 1 if the point is on the curve, 0 if not, or -1 on error + */ +int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, + BN_CTX *ctx); + +/** Compares two EC_POINTs + * \param group underlying EC_GROUP object + * \param a first EC_POINT object + * \param b second EC_POINT object + * \param ctx BN_CTX object (optional) + * \return 1 if the points are not equal, 0 if they are, or -1 on error + */ +int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, + BN_CTX *ctx); + +int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx); +int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, + EC_POINT *points[], BN_CTX *ctx); + +/** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i] + * \param group underlying EC_GROUP object + * \param r EC_POINT object for the result + * \param n BIGNUM with the multiplier for the group generator (optional) + * \param num number further summands + * \param p array of size num of EC_POINT objects + * \param m array of size num of BIGNUM objects + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, + size_t num, const EC_POINT *p[], const BIGNUM *m[], + BN_CTX *ctx); + +/** Computes r = generator * n + q * m + * \param group underlying EC_GROUP object + * \param r EC_POINT object for the result + * \param n BIGNUM with the multiplier for the group generator (optional) + * \param q EC_POINT object with the first factor of the second summand + * \param m BIGNUM with the second factor of the second summand + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, + const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx); + +/** Stores multiples of generator for faster point multiplication + * \param group EC_GROUP object + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx); + +/** Reports whether a precomputation has been done + * \param group EC_GROUP object + * \return 1 if a pre-computation has been done and 0 otherwise + */ +int EC_GROUP_have_precompute_mult(const EC_GROUP *group); + +/********************************************************************/ +/* ASN1 stuff */ +/********************************************************************/ + +DECLARE_ASN1_ITEM(ECPKPARAMETERS) +DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS) +DECLARE_ASN1_ITEM(ECPARAMETERS) +DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS) + +/* + * EC_GROUP_get_basis_type() returns the NID of the basis type used to + * represent the field elements + */ +int EC_GROUP_get_basis_type(const EC_GROUP *); +# ifndef OPENSSL_NO_EC2M +int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k); +int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1, + unsigned int *k2, unsigned int *k3); +# endif + +# define OPENSSL_EC_EXPLICIT_CURVE 0x000 +# define OPENSSL_EC_NAMED_CURVE 0x001 + +EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len); +int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out); + +# define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x) +# define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x) +# define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \ + (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x)) +# define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \ + (unsigned char *)(x)) + +int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off); +# ifndef OPENSSL_NO_STDIO +int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off); +# endif + +/********************************************************************/ +/* EC_KEY functions */ +/********************************************************************/ + +/* some values for the encoding_flag */ +# define EC_PKEY_NO_PARAMETERS 0x001 +# define EC_PKEY_NO_PUBKEY 0x002 + +/* some values for the flags field */ +# define EC_FLAG_NON_FIPS_ALLOW 0x1 +# define EC_FLAG_FIPS_CHECKED 0x2 +# define EC_FLAG_COFACTOR_ECDH 0x1000 + +/** Creates a new EC_KEY object. + * \return EC_KEY object or NULL if an error occurred. + */ +EC_KEY *EC_KEY_new(void); + +int EC_KEY_get_flags(const EC_KEY *key); + +void EC_KEY_set_flags(EC_KEY *key, int flags); + +void EC_KEY_clear_flags(EC_KEY *key, int flags); + +/** Creates a new EC_KEY object using a named curve as underlying + * EC_GROUP object. + * \param nid NID of the named curve. + * \return EC_KEY object or NULL if an error occurred. + */ +EC_KEY *EC_KEY_new_by_curve_name(int nid); + +/** Frees a EC_KEY object. + * \param key EC_KEY object to be freed. + */ +void EC_KEY_free(EC_KEY *key); + +/** Copies a EC_KEY object. + * \param dst destination EC_KEY object + * \param src src EC_KEY object + * \return dst or NULL if an error occurred. + */ +EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src); + +/** Creates a new EC_KEY object and copies the content from src to it. + * \param src the source EC_KEY object + * \return newly created EC_KEY object or NULL if an error occurred. + */ +EC_KEY *EC_KEY_dup(const EC_KEY *src); + +/** Increases the internal reference count of a EC_KEY object. + * \param key EC_KEY object + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_up_ref(EC_KEY *key); + +/** Returns the EC_GROUP object of a EC_KEY object + * \param key EC_KEY object + * \return the EC_GROUP object (possibly NULL). + */ +const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key); + +/** Sets the EC_GROUP of a EC_KEY object. + * \param key EC_KEY object + * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY + * object will use an own copy of the EC_GROUP). + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group); + +/** Returns the private key of a EC_KEY object. + * \param key EC_KEY object + * \return a BIGNUM with the private key (possibly NULL). + */ +const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key); + +/** Sets the private key of a EC_KEY object. + * \param key EC_KEY object + * \param prv BIGNUM with the private key (note: the EC_KEY object + * will use an own copy of the BIGNUM). + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv); + +/** Returns the public key of a EC_KEY object. + * \param key the EC_KEY object + * \return a EC_POINT object with the public key (possibly NULL) + */ +const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key); + +/** Sets the public key of a EC_KEY object. + * \param key EC_KEY object + * \param pub EC_POINT object with the public key (note: the EC_KEY object + * will use an own copy of the EC_POINT object). + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub); + +unsigned EC_KEY_get_enc_flags(const EC_KEY *key); +void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags); +point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key); +void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform); + +#define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef) +int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg); +void *EC_KEY_get_ex_data(const EC_KEY *key, int idx); + +/* wrapper functions for the underlying EC_GROUP object */ +void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag); + +/** Creates a table of pre-computed multiples of the generator to + * accelerate further EC_KEY operations. + * \param key EC_KEY object + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx); + +/** Creates a new ec private (and optional a new public) key. + * \param key EC_KEY object + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_generate_key(EC_KEY *key); + +/** Verifies that a private and/or public key is valid. + * \param key the EC_KEY object + * \return 1 on success and 0 otherwise. + */ +int EC_KEY_check_key(const EC_KEY *key); + +/** Indicates if an EC_KEY can be used for signing. + * \param key the EC_KEY object + * \return 1 if can can sign and 0 otherwise. + */ +int EC_KEY_can_sign(const EC_KEY *eckey); + +/** Sets a public key from affine coordinates performing + * necessary NIST PKV tests. + * \param key the EC_KEY object + * \param x public key x coordinate + * \param y public key y coordinate + * \return 1 on success and 0 otherwise. + */ +int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, + BIGNUM *y); + +/** Encodes an EC_KEY public key to an allocated octet string + * \param key key to encode + * \param form point conversion form + * \param pbuf returns pointer to allocated buffer + * \param len length of the memory buffer + * \param ctx BN_CTX object (optional) + * \return the length of the encoded octet string or 0 if an error occurred + */ + +size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form, + unsigned char **pbuf, BN_CTX *ctx); + +/** Decodes a EC_KEY public key from a octet string + * \param key key to decode + * \param buf memory buffer with the encoded ec point + * \param len length of the encoded ec point + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ + +int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len, + BN_CTX *ctx); + +/** Decodes an EC_KEY private key from an octet string + * \param key key to decode + * \param buf memory buffer with the encoded private key + * \param len length of the encoded key + * \return 1 on success and 0 if an error occurred + */ + +int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf, size_t len); + +/** Encodes a EC_KEY private key to an octet string + * \param key key to encode + * \param buf memory buffer for the result. If NULL the function returns + * required buffer size. + * \param len length of the memory buffer + * \return the length of the encoded octet string or 0 if an error occurred + */ + +size_t EC_KEY_priv2oct(const EC_KEY *key, unsigned char *buf, size_t len); + +/** Encodes an EC_KEY private key to an allocated octet string + * \param key key to encode + * \param pbuf returns pointer to allocated buffer + * \return the length of the encoded octet string or 0 if an error occurred + */ + +size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf); + +/********************************************************************/ +/* de- and encoding functions for SEC1 ECPrivateKey */ +/********************************************************************/ + +/** Decodes a private key from a memory buffer. + * \param key a pointer to a EC_KEY object which should be used (or NULL) + * \param in pointer to memory with the DER encoded private key + * \param len length of the DER encoded private key + * \return the decoded private key or NULL if an error occurred. + */ +EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len); + +/** Encodes a private key object and stores the result in a buffer. + * \param key the EC_KEY object to encode + * \param out the buffer for the result (if NULL the function returns number + * of bytes needed). + * \return 1 on success and 0 if an error occurred. + */ +int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out); + +/********************************************************************/ +/* de- and encoding functions for EC parameters */ +/********************************************************************/ + +/** Decodes ec parameter from a memory buffer. + * \param key a pointer to a EC_KEY object which should be used (or NULL) + * \param in pointer to memory with the DER encoded ec parameters + * \param len length of the DER encoded ec parameters + * \return a EC_KEY object with the decoded parameters or NULL if an error + * occurred. + */ +EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len); + +/** Encodes ec parameter and stores the result in a buffer. + * \param key the EC_KEY object with ec parameters to encode + * \param out the buffer for the result (if NULL the function returns number + * of bytes needed). + * \return 1 on success and 0 if an error occurred. + */ +int i2d_ECParameters(EC_KEY *key, unsigned char **out); + +/********************************************************************/ +/* de- and encoding functions for EC public key */ +/* (octet string, not DER -- hence 'o2i' and 'i2o') */ +/********************************************************************/ + +/** Decodes a ec public key from a octet string. + * \param key a pointer to a EC_KEY object which should be used + * \param in memory buffer with the encoded public key + * \param len length of the encoded public key + * \return EC_KEY object with decoded public key or NULL if an error + * occurred. + */ +EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len); + +/** Encodes a ec public key in an octet string. + * \param key the EC_KEY object with the public key + * \param out the buffer for the result (if NULL the function returns number + * of bytes needed). + * \return 1 on success and 0 if an error occurred + */ +int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out); + +/** Prints out the ec parameters on human readable form. + * \param bp BIO object to which the information is printed + * \param key EC_KEY object + * \return 1 on success and 0 if an error occurred + */ +int ECParameters_print(BIO *bp, const EC_KEY *key); + +/** Prints out the contents of a EC_KEY object + * \param bp BIO object to which the information is printed + * \param key EC_KEY object + * \param off line offset + * \return 1 on success and 0 if an error occurred + */ +int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); + +# ifndef OPENSSL_NO_STDIO +/** Prints out the ec parameters on human readable form. + * \param fp file descriptor to which the information is printed + * \param key EC_KEY object + * \return 1 on success and 0 if an error occurred + */ +int ECParameters_print_fp(FILE *fp, const EC_KEY *key); + +/** Prints out the contents of a EC_KEY object + * \param fp file descriptor to which the information is printed + * \param key EC_KEY object + * \param off line offset + * \return 1 on success and 0 if an error occurred + */ +int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); + +# endif + +const EC_KEY_METHOD *EC_KEY_OpenSSL(void); +const EC_KEY_METHOD *EC_KEY_get_default_method(void); +void EC_KEY_set_default_method(const EC_KEY_METHOD *meth); +const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key); +int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth); +EC_KEY *EC_KEY_new_method(ENGINE *engine); + +int ECDH_KDF_X9_62(unsigned char *out, size_t outlen, + const unsigned char *Z, size_t Zlen, + const unsigned char *sinfo, size_t sinfolen, + const EVP_MD *md); + +int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, + const EC_KEY *ecdh, + void *(*KDF) (const void *in, size_t inlen, + void *out, size_t *outlen)); + +typedef struct ECDSA_SIG_st ECDSA_SIG; + +/** Allocates and initialize a ECDSA_SIG structure + * \return pointer to a ECDSA_SIG structure or NULL if an error occurred + */ +ECDSA_SIG *ECDSA_SIG_new(void); + +/** frees a ECDSA_SIG structure + * \param sig pointer to the ECDSA_SIG structure + */ +void ECDSA_SIG_free(ECDSA_SIG *sig); + +/** DER encode content of ECDSA_SIG object (note: this function modifies *pp + * (*pp += length of the DER encoded signature)). + * \param sig pointer to the ECDSA_SIG object + * \param pp pointer to a unsigned char pointer for the output or NULL + * \return the length of the DER encoded ECDSA_SIG object or 0 + */ +int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp); + +/** Decodes a DER encoded ECDSA signature (note: this function changes *pp + * (*pp += len)). + * \param sig pointer to ECDSA_SIG pointer (may be NULL) + * \param pp memory buffer with the DER encoded signature + * \param len length of the buffer + * \return pointer to the decoded ECDSA_SIG structure (or NULL) + */ +ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len); + +/** Accessor for r and s fields of ECDSA_SIG + * \param sig pointer to ECDSA_SIG pointer + * \param pr pointer to BIGNUM pointer for r (may be NULL) + * \param ps pointer to BIGNUM pointer for s (may be NULL) + */ +void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); + +/** Setter for r and s fields of ECDSA_SIG + * \param sig pointer to ECDSA_SIG pointer + * \param r pointer to BIGNUM for r (may be NULL) + * \param s pointer to BIGNUM for s (may be NULL) + */ +int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s); + +/** Computes the ECDSA signature of the given hash value using + * the supplied private key and returns the created signature. + * \param dgst pointer to the hash value + * \param dgst_len length of the hash value + * \param eckey EC_KEY object containing a private EC key + * \return pointer to a ECDSA_SIG structure or NULL if an error occurred + */ +ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, + EC_KEY *eckey); + +/** Computes ECDSA signature of a given hash value using the supplied + * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). + * \param dgst pointer to the hash value to sign + * \param dgstlen length of the hash value + * \param kinv BIGNUM with a pre-computed inverse k (optional) + * \param rp BIGNUM with a pre-computed rp value (optional), + * see ECDSA_sign_setup + * \param eckey EC_KEY object containing a private EC key + * \return pointer to a ECDSA_SIG structure or NULL if an error occurred + */ +ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, + const BIGNUM *kinv, const BIGNUM *rp, + EC_KEY *eckey); + +/** Verifies that the supplied signature is a valid ECDSA + * signature of the supplied hash value using the supplied public key. + * \param dgst pointer to the hash value + * \param dgst_len length of the hash value + * \param sig ECDSA_SIG structure + * \param eckey EC_KEY object containing a public EC key + * \return 1 if the signature is valid, 0 if the signature is invalid + * and -1 on error + */ +int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, + const ECDSA_SIG *sig, EC_KEY *eckey); + +/** Precompute parts of the signing operation + * \param eckey EC_KEY object containing a private EC key + * \param ctx BN_CTX object (optional) + * \param kinv BIGNUM pointer for the inverse of k + * \param rp BIGNUM pointer for x coordinate of k * generator + * \return 1 on success and 0 otherwise + */ +int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp); + +/** Computes ECDSA signature of a given hash value using the supplied + * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). + * \param type this parameter is ignored + * \param dgst pointer to the hash value to sign + * \param dgstlen length of the hash value + * \param sig memory for the DER encoded created signature + * \param siglen pointer to the length of the returned signature + * \param eckey EC_KEY object containing a private EC key + * \return 1 on success and 0 otherwise + */ +int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, + unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); + +/** Computes ECDSA signature of a given hash value using the supplied + * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). + * \param type this parameter is ignored + * \param dgst pointer to the hash value to sign + * \param dgstlen length of the hash value + * \param sig buffer to hold the DER encoded signature + * \param siglen pointer to the length of the returned signature + * \param kinv BIGNUM with a pre-computed inverse k (optional) + * \param rp BIGNUM with a pre-computed rp value (optional), + * see ECDSA_sign_setup + * \param eckey EC_KEY object containing a private EC key + * \return 1 on success and 0 otherwise + */ +int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, + unsigned char *sig, unsigned int *siglen, + const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); + +/** Verifies that the given signature is valid ECDSA signature + * of the supplied hash value using the specified public key. + * \param type this parameter is ignored + * \param dgst pointer to the hash value + * \param dgstlen length of the hash value + * \param sig pointer to the DER encoded signature + * \param siglen length of the DER encoded signature + * \param eckey EC_KEY object containing a public EC key + * \return 1 if the signature is valid, 0 if the signature is invalid + * and -1 on error + */ +int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, + const unsigned char *sig, int siglen, EC_KEY *eckey); + +/** Returns the maximum length of the DER encoded signature + * \param eckey EC_KEY object + * \return numbers of bytes required for the DER encoded signature + */ +int ECDSA_size(const EC_KEY *eckey); + +/********************************************************************/ +/* EC_KEY_METHOD constructors, destructors, writers and accessors */ +/********************************************************************/ + +EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth); +void EC_KEY_METHOD_free(EC_KEY_METHOD *meth); +void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, + int (*init)(EC_KEY *key), + void (*finish)(EC_KEY *key), + int (*copy)(EC_KEY *dest, const EC_KEY *src), + int (*set_group)(EC_KEY *key, const EC_GROUP *grp), + int (*set_private)(EC_KEY *key, + const BIGNUM *priv_key), + int (*set_public)(EC_KEY *key, + const EC_POINT *pub_key)); + +void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth, + int (*keygen)(EC_KEY *key)); + +void EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth, + int (*ckey)(unsigned char **psec, + size_t *pseclen, + const EC_POINT *pub_key, + const EC_KEY *ecdh)); + +void EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth, + int (*sign)(int type, const unsigned char *dgst, + int dlen, unsigned char *sig, + unsigned int *siglen, + const BIGNUM *kinv, const BIGNUM *r, + EC_KEY *eckey), + int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, + BIGNUM **kinvp, BIGNUM **rp), + ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, + int dgst_len, + const BIGNUM *in_kinv, + const BIGNUM *in_r, + EC_KEY *eckey)); + +void EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth, + int (*verify)(int type, const unsigned + char *dgst, int dgst_len, + const unsigned char *sigbuf, + int sig_len, EC_KEY *eckey), + int (*verify_sig)(const unsigned char *dgst, + int dgst_len, + const ECDSA_SIG *sig, + EC_KEY *eckey)); + +void EC_KEY_METHOD_get_init(EC_KEY_METHOD *meth, + int (**pinit)(EC_KEY *key), + void (**pfinish)(EC_KEY *key), + int (**pcopy)(EC_KEY *dest, const EC_KEY *src), + int (**pset_group)(EC_KEY *key, + const EC_GROUP *grp), + int (**pset_private)(EC_KEY *key, + const BIGNUM *priv_key), + int (**pset_public)(EC_KEY *key, + const EC_POINT *pub_key)); + +void EC_KEY_METHOD_get_keygen(EC_KEY_METHOD *meth, + int (**pkeygen)(EC_KEY *key)); + +void EC_KEY_METHOD_get_compute_key(EC_KEY_METHOD *meth, + int (**pck)(unsigned char **psec, + size_t *pseclen, + const EC_POINT *pub_key, + const EC_KEY *ecdh)); + +void EC_KEY_METHOD_get_sign(EC_KEY_METHOD *meth, + int (**psign)(int type, const unsigned char *dgst, + int dlen, unsigned char *sig, + unsigned int *siglen, + const BIGNUM *kinv, const BIGNUM *r, + EC_KEY *eckey), + int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, + BIGNUM **kinvp, BIGNUM **rp), + ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, + int dgst_len, + const BIGNUM *in_kinv, + const BIGNUM *in_r, + EC_KEY *eckey)); + +void EC_KEY_METHOD_get_verify(EC_KEY_METHOD *meth, + int (**pverify)(int type, const unsigned + char *dgst, int dgst_len, + const unsigned char *sigbuf, + int sig_len, EC_KEY *eckey), + int (**pverify_sig)(const unsigned char *dgst, + int dgst_len, + const ECDSA_SIG *sig, + EC_KEY *eckey)); + +# define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) + +# ifndef __cplusplus +# if defined(__SUNPRO_C) +# if __SUNPRO_C >= 0x520 +# pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) +# endif +# endif +# endif + +# define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL) + +# define EVP_PKEY_CTX_set_ec_param_enc(ctx, flag) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_EC_PARAM_ENC, flag, NULL) + +# define EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, flag) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_ECDH_COFACTOR, flag, NULL) + +# define EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_ECDH_COFACTOR, -2, NULL) + +# define EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, kdf) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_TYPE, kdf, NULL) + +# define EVP_PKEY_CTX_get_ecdh_kdf_type(ctx) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_TYPE, -2, NULL) + +# define EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_MD, 0, (void *)md) + +# define EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, pmd) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_EC_KDF_MD, 0, (void *)pmd) + +# define EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_OUTLEN, len, NULL) + +# define EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, plen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN, 0, (void *)plen) + +# define EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p, plen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_UKM, plen, (void *)p) + +# define EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_EC_KDF_UKM, 0, (void *)p) + +# define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_EC_PARAM_ENC (EVP_PKEY_ALG_CTRL + 2) +# define EVP_PKEY_CTRL_EC_ECDH_COFACTOR (EVP_PKEY_ALG_CTRL + 3) +# define EVP_PKEY_CTRL_EC_KDF_TYPE (EVP_PKEY_ALG_CTRL + 4) +# define EVP_PKEY_CTRL_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 5) +# define EVP_PKEY_CTRL_GET_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 6) +# define EVP_PKEY_CTRL_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 7) +# define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 8) +# define EVP_PKEY_CTRL_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 9) +# define EVP_PKEY_CTRL_GET_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 10) +/* KDF types */ +# define EVP_PKEY_ECDH_KDF_NONE 1 +# define EVP_PKEY_ECDH_KDF_X9_62 2 + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_EC_strings(void); + +/* Error codes for the EC functions. */ + +/* Function codes. */ +# define EC_F_BN_TO_FELEM 224 +# define EC_F_D2I_ECPARAMETERS 144 +# define EC_F_D2I_ECPKPARAMETERS 145 +# define EC_F_D2I_ECPRIVATEKEY 146 +# define EC_F_DO_EC_KEY_PRINT 221 +# define EC_F_ECDH_CMS_DECRYPT 238 +# define EC_F_ECDH_CMS_SET_SHARED_INFO 239 +# define EC_F_ECDH_COMPUTE_KEY 246 +# define EC_F_ECDH_SIMPLE_COMPUTE_KEY 257 +# define EC_F_ECDSA_DO_SIGN_EX 251 +# define EC_F_ECDSA_DO_VERIFY 252 +# define EC_F_ECDSA_SIGN_EX 254 +# define EC_F_ECDSA_SIGN_SETUP 248 +# define EC_F_ECDSA_SIG_NEW 265 +# define EC_F_ECDSA_VERIFY 253 +# define EC_F_ECKEY_PARAM2TYPE 223 +# define EC_F_ECKEY_PARAM_DECODE 212 +# define EC_F_ECKEY_PRIV_DECODE 213 +# define EC_F_ECKEY_PRIV_ENCODE 214 +# define EC_F_ECKEY_PUB_DECODE 215 +# define EC_F_ECKEY_PUB_ENCODE 216 +# define EC_F_ECKEY_TYPE2PARAM 220 +# define EC_F_ECPARAMETERS_PRINT 147 +# define EC_F_ECPARAMETERS_PRINT_FP 148 +# define EC_F_ECPKPARAMETERS_PRINT 149 +# define EC_F_ECPKPARAMETERS_PRINT_FP 150 +# define EC_F_ECP_NISTZ256_GET_AFFINE 240 +# define EC_F_ECP_NISTZ256_MULT_PRECOMPUTE 243 +# define EC_F_ECP_NISTZ256_POINTS_MUL 241 +# define EC_F_ECP_NISTZ256_PRE_COMP_NEW 244 +# define EC_F_ECP_NISTZ256_WINDOWED_MUL 242 +# define EC_F_ECX_KEY_OP 266 +# define EC_F_ECX_PRIV_ENCODE 267 +# define EC_F_ECX_PUB_ENCODE 268 +# define EC_F_EC_ASN1_GROUP2CURVE 153 +# define EC_F_EC_ASN1_GROUP2FIELDID 154 +# define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY 208 +# define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT 159 +# define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE 195 +# define EC_F_EC_GF2M_SIMPLE_OCT2POINT 160 +# define EC_F_EC_GF2M_SIMPLE_POINT2OCT 161 +# define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162 +# define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163 +# define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES 164 +# define EC_F_EC_GFP_MONT_FIELD_DECODE 133 +# define EC_F_EC_GFP_MONT_FIELD_ENCODE 134 +# define EC_F_EC_GFP_MONT_FIELD_MUL 131 +# define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE 209 +# define EC_F_EC_GFP_MONT_FIELD_SQR 132 +# define EC_F_EC_GFP_MONT_GROUP_SET_CURVE 189 +# define EC_F_EC_GFP_NISTP224_GROUP_SET_CURVE 225 +# define EC_F_EC_GFP_NISTP224_POINTS_MUL 228 +# define EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES 226 +# define EC_F_EC_GFP_NISTP256_GROUP_SET_CURVE 230 +# define EC_F_EC_GFP_NISTP256_POINTS_MUL 231 +# define EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES 232 +# define EC_F_EC_GFP_NISTP521_GROUP_SET_CURVE 233 +# define EC_F_EC_GFP_NISTP521_POINTS_MUL 234 +# define EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES 235 +# define EC_F_EC_GFP_NIST_FIELD_MUL 200 +# define EC_F_EC_GFP_NIST_FIELD_SQR 201 +# define EC_F_EC_GFP_NIST_GROUP_SET_CURVE 202 +# define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT 165 +# define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE 166 +# define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102 +# define EC_F_EC_GFP_SIMPLE_OCT2POINT 103 +# define EC_F_EC_GFP_SIMPLE_POINT2OCT 104 +# define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137 +# define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES 167 +# define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES 168 +# define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES 169 +# define EC_F_EC_GROUP_CHECK 170 +# define EC_F_EC_GROUP_CHECK_DISCRIMINANT 171 +# define EC_F_EC_GROUP_COPY 106 +# define EC_F_EC_GROUP_GET_CURVE_GF2M 172 +# define EC_F_EC_GROUP_GET_CURVE_GFP 130 +# define EC_F_EC_GROUP_GET_DEGREE 173 +# define EC_F_EC_GROUP_GET_ECPARAMETERS 261 +# define EC_F_EC_GROUP_GET_ECPKPARAMETERS 262 +# define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS 193 +# define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS 194 +# define EC_F_EC_GROUP_NEW 108 +# define EC_F_EC_GROUP_NEW_BY_CURVE_NAME 174 +# define EC_F_EC_GROUP_NEW_FROM_DATA 175 +# define EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS 263 +# define EC_F_EC_GROUP_NEW_FROM_ECPKPARAMETERS 264 +# define EC_F_EC_GROUP_SET_CURVE_GF2M 176 +# define EC_F_EC_GROUP_SET_CURVE_GFP 109 +# define EC_F_EC_GROUP_SET_GENERATOR 111 +# define EC_F_EC_KEY_CHECK_KEY 177 +# define EC_F_EC_KEY_COPY 178 +# define EC_F_EC_KEY_GENERATE_KEY 179 +# define EC_F_EC_KEY_NEW 182 +# define EC_F_EC_KEY_NEW_METHOD 245 +# define EC_F_EC_KEY_OCT2PRIV 255 +# define EC_F_EC_KEY_PRINT 180 +# define EC_F_EC_KEY_PRINT_FP 181 +# define EC_F_EC_KEY_PRIV2OCT 256 +# define EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES 229 +# define EC_F_EC_KEY_SIMPLE_CHECK_KEY 258 +# define EC_F_EC_KEY_SIMPLE_OCT2PRIV 259 +# define EC_F_EC_KEY_SIMPLE_PRIV2OCT 260 +# define EC_F_EC_POINTS_MAKE_AFFINE 136 +# define EC_F_EC_POINT_ADD 112 +# define EC_F_EC_POINT_CMP 113 +# define EC_F_EC_POINT_COPY 114 +# define EC_F_EC_POINT_DBL 115 +# define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M 183 +# define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116 +# define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117 +# define EC_F_EC_POINT_INVERT 210 +# define EC_F_EC_POINT_IS_AT_INFINITY 118 +# define EC_F_EC_POINT_IS_ON_CURVE 119 +# define EC_F_EC_POINT_MAKE_AFFINE 120 +# define EC_F_EC_POINT_NEW 121 +# define EC_F_EC_POINT_OCT2POINT 122 +# define EC_F_EC_POINT_POINT2OCT 123 +# define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M 185 +# define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124 +# define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M 186 +# define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125 +# define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126 +# define EC_F_EC_POINT_SET_TO_INFINITY 127 +# define EC_F_EC_PRE_COMP_NEW 196 +# define EC_F_EC_WNAF_MUL 187 +# define EC_F_EC_WNAF_PRECOMPUTE_MULT 188 +# define EC_F_I2D_ECPARAMETERS 190 +# define EC_F_I2D_ECPKPARAMETERS 191 +# define EC_F_I2D_ECPRIVATEKEY 192 +# define EC_F_I2O_ECPUBLICKEY 151 +# define EC_F_NISTP224_PRE_COMP_NEW 227 +# define EC_F_NISTP256_PRE_COMP_NEW 236 +# define EC_F_NISTP521_PRE_COMP_NEW 237 +# define EC_F_O2I_ECPUBLICKEY 152 +# define EC_F_OLD_EC_PRIV_DECODE 222 +# define EC_F_OSSL_ECDH_COMPUTE_KEY 247 +# define EC_F_OSSL_ECDSA_SIGN_SIG 249 +# define EC_F_OSSL_ECDSA_VERIFY_SIG 250 +# define EC_F_PKEY_ECX_DERIVE 269 +# define EC_F_PKEY_EC_CTRL 197 +# define EC_F_PKEY_EC_CTRL_STR 198 +# define EC_F_PKEY_EC_DERIVE 217 +# define EC_F_PKEY_EC_KEYGEN 199 +# define EC_F_PKEY_EC_PARAMGEN 219 +# define EC_F_PKEY_EC_SIGN 218 + +/* Reason codes. */ +# define EC_R_ASN1_ERROR 115 +# define EC_R_BAD_SIGNATURE 156 +# define EC_R_BIGNUM_OUT_OF_RANGE 144 +# define EC_R_BUFFER_TOO_SMALL 100 +# define EC_R_COORDINATES_OUT_OF_RANGE 146 +# define EC_R_CURVE_DOES_NOT_SUPPORT_ECDH 160 +# define EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING 159 +# define EC_R_D2I_ECPKPARAMETERS_FAILURE 117 +# define EC_R_DECODE_ERROR 142 +# define EC_R_DISCRIMINANT_IS_ZERO 118 +# define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 119 +# define EC_R_FIELD_TOO_LARGE 143 +# define EC_R_GF2M_NOT_SUPPORTED 147 +# define EC_R_GROUP2PKPARAMETERS_FAILURE 120 +# define EC_R_I2D_ECPKPARAMETERS_FAILURE 121 +# define EC_R_INCOMPATIBLE_OBJECTS 101 +# define EC_R_INVALID_ARGUMENT 112 +# define EC_R_INVALID_COMPRESSED_POINT 110 +# define EC_R_INVALID_COMPRESSION_BIT 109 +# define EC_R_INVALID_CURVE 141 +# define EC_R_INVALID_DIGEST 151 +# define EC_R_INVALID_DIGEST_TYPE 138 +# define EC_R_INVALID_ENCODING 102 +# define EC_R_INVALID_FIELD 103 +# define EC_R_INVALID_FORM 104 +# define EC_R_INVALID_GROUP_ORDER 122 +# define EC_R_INVALID_KEY 116 +# define EC_R_INVALID_OUTPUT_LENGTH 161 +# define EC_R_INVALID_PEER_KEY 133 +# define EC_R_INVALID_PENTANOMIAL_BASIS 132 +# define EC_R_INVALID_PRIVATE_KEY 123 +# define EC_R_INVALID_TRINOMIAL_BASIS 137 +# define EC_R_KDF_PARAMETER_ERROR 148 +# define EC_R_KEYS_NOT_SET 140 +# define EC_R_MISSING_PARAMETERS 124 +# define EC_R_MISSING_PRIVATE_KEY 125 +# define EC_R_NEED_NEW_SETUP_VALUES 157 +# define EC_R_NOT_A_NIST_PRIME 135 +# define EC_R_NOT_IMPLEMENTED 126 +# define EC_R_NOT_INITIALIZED 111 +# define EC_R_NO_PARAMETERS_SET 139 +# define EC_R_NO_PRIVATE_VALUE 154 +# define EC_R_OPERATION_NOT_SUPPORTED 152 +# define EC_R_PASSED_NULL_PARAMETER 134 +# define EC_R_PEER_KEY_ERROR 149 +# define EC_R_PKPARAMETERS2GROUP_FAILURE 127 +# define EC_R_POINT_ARITHMETIC_FAILURE 155 +# define EC_R_POINT_AT_INFINITY 106 +# define EC_R_POINT_IS_NOT_ON_CURVE 107 +# define EC_R_RANDOM_NUMBER_GENERATION_FAILED 158 +# define EC_R_SHARED_INFO_ERROR 150 +# define EC_R_SLOT_FULL 108 +# define EC_R_UNDEFINED_GENERATOR 113 +# define EC_R_UNDEFINED_ORDER 128 +# define EC_R_UNKNOWN_GROUP 129 +# define EC_R_UNKNOWN_ORDER 114 +# define EC_R_UNSUPPORTED_FIELD 131 +# define EC_R_WRONG_CURVE_PARAMETERS 145 +# define EC_R_WRONG_ORDER 130 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/ecdh.h b/android/x86/include/openssl/ecdh.h new file mode 100644 index 00000000..681f3d5e --- /dev/null +++ b/android/x86/include/openssl/ecdh.h @@ -0,0 +1,10 @@ +/* + * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <openssl/ec.h> diff --git a/android/x86/include/openssl/ecdsa.h b/android/x86/include/openssl/ecdsa.h new file mode 100644 index 00000000..681f3d5e --- /dev/null +++ b/android/x86/include/openssl/ecdsa.h @@ -0,0 +1,10 @@ +/* + * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <openssl/ec.h> diff --git a/android/x86/include/openssl/engine.h b/android/x86/include/openssl/engine.h new file mode 100644 index 00000000..319371e4 --- /dev/null +++ b/android/x86/include/openssl/engine.h @@ -0,0 +1,842 @@ +/* + * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECDH support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ + +#ifndef HEADER_ENGINE_H +# define HEADER_ENGINE_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_ENGINE +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/bn.h> +# include <openssl/rsa.h> +# include <openssl/dsa.h> +# include <openssl/dh.h> +# include <openssl/ec.h> +# include <openssl/rand.h> +# include <openssl/ui.h> +# include <openssl/err.h> +# endif +# include <openssl/ossl_typ.h> +# include <openssl/symhacks.h> +# include <openssl/x509.h> +# ifdef __cplusplus +extern "C" { +# endif + +/* + * These flags are used to control combinations of algorithm (methods) by + * bitwise "OR"ing. + */ +# define ENGINE_METHOD_RSA (unsigned int)0x0001 +# define ENGINE_METHOD_DSA (unsigned int)0x0002 +# define ENGINE_METHOD_DH (unsigned int)0x0004 +# define ENGINE_METHOD_RAND (unsigned int)0x0008 +# define ENGINE_METHOD_CIPHERS (unsigned int)0x0040 +# define ENGINE_METHOD_DIGESTS (unsigned int)0x0080 +# define ENGINE_METHOD_PKEY_METHS (unsigned int)0x0200 +# define ENGINE_METHOD_PKEY_ASN1_METHS (unsigned int)0x0400 +# define ENGINE_METHOD_EC (unsigned int)0x0800 +/* Obvious all-or-nothing cases. */ +# define ENGINE_METHOD_ALL (unsigned int)0xFFFF +# define ENGINE_METHOD_NONE (unsigned int)0x0000 + +/* + * This(ese) flag(s) controls behaviour of the ENGINE_TABLE mechanism used + * internally to control registration of ENGINE implementations, and can be + * set by ENGINE_set_table_flags(). The "NOINIT" flag prevents attempts to + * initialise registered ENGINEs if they are not already initialised. + */ +# define ENGINE_TABLE_FLAG_NOINIT (unsigned int)0x0001 + +/* ENGINE flags that can be set by ENGINE_set_flags(). */ +/* Not used */ +/* #define ENGINE_FLAGS_MALLOCED 0x0001 */ + +/* + * This flag is for ENGINEs that wish to handle the various 'CMD'-related + * control commands on their own. Without this flag, ENGINE_ctrl() handles + * these control commands on behalf of the ENGINE using their "cmd_defns" + * data. + */ +# define ENGINE_FLAGS_MANUAL_CMD_CTRL (int)0x0002 + +/* + * This flag is for ENGINEs who return new duplicate structures when found + * via "ENGINE_by_id()". When an ENGINE must store state (eg. if + * ENGINE_ctrl() commands are called in sequence as part of some stateful + * process like key-generation setup and execution), it can set this flag - + * then each attempt to obtain the ENGINE will result in it being copied into + * a new structure. Normally, ENGINEs don't declare this flag so + * ENGINE_by_id() just increments the existing ENGINE's structural reference + * count. + */ +# define ENGINE_FLAGS_BY_ID_COPY (int)0x0004 + +/* + * This flag if for an ENGINE that does not want its methods registered as + * part of ENGINE_register_all_complete() for example if the methods are not + * usable as default methods. + */ + +# define ENGINE_FLAGS_NO_REGISTER_ALL (int)0x0008 + +/* + * ENGINEs can support their own command types, and these flags are used in + * ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input + * each command expects. Currently only numeric and string input is + * supported. If a control command supports none of the _NUMERIC, _STRING, or + * _NO_INPUT options, then it is regarded as an "internal" control command - + * and not for use in config setting situations. As such, they're not + * available to the ENGINE_ctrl_cmd_string() function, only raw ENGINE_ctrl() + * access. Changes to this list of 'command types' should be reflected + * carefully in ENGINE_cmd_is_executable() and ENGINE_ctrl_cmd_string(). + */ + +/* accepts a 'long' input value (3rd parameter to ENGINE_ctrl) */ +# define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001 +/* + * accepts string input (cast from 'void*' to 'const char *', 4th parameter + * to ENGINE_ctrl) + */ +# define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002 +/* + * Indicates that the control command takes *no* input. Ie. the control + * command is unparameterised. + */ +# define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004 +/* + * Indicates that the control command is internal. This control command won't + * be shown in any output, and is only usable through the ENGINE_ctrl_cmd() + * function. + */ +# define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008 + +/* + * NB: These 3 control commands are deprecated and should not be used. + * ENGINEs relying on these commands should compile conditional support for + * compatibility (eg. if these symbols are defined) but should also migrate + * the same functionality to their own ENGINE-specific control functions that + * can be "discovered" by calling applications. The fact these control + * commands wouldn't be "executable" (ie. usable by text-based config) + * doesn't change the fact that application code can find and use them + * without requiring per-ENGINE hacking. + */ + +/* + * These flags are used to tell the ctrl function what should be done. All + * command numbers are shared between all engines, even if some don't make + * sense to some engines. In such a case, they do nothing but return the + * error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED. + */ +# define ENGINE_CTRL_SET_LOGSTREAM 1 +# define ENGINE_CTRL_SET_PASSWORD_CALLBACK 2 +# define ENGINE_CTRL_HUP 3/* Close and reinitialise + * any handles/connections + * etc. */ +# define ENGINE_CTRL_SET_USER_INTERFACE 4/* Alternative to callback */ +# define ENGINE_CTRL_SET_CALLBACK_DATA 5/* User-specific data, used + * when calling the password + * callback and the user + * interface */ +# define ENGINE_CTRL_LOAD_CONFIGURATION 6/* Load a configuration, + * given a string that + * represents a file name + * or so */ +# define ENGINE_CTRL_LOAD_SECTION 7/* Load data from a given + * section in the already + * loaded configuration */ + +/* + * These control commands allow an application to deal with an arbitrary + * engine in a dynamic way. Warn: Negative return values indicate errors FOR + * THESE COMMANDS because zero is used to indicate 'end-of-list'. Other + * commands, including ENGINE-specific command types, return zero for an + * error. An ENGINE can choose to implement these ctrl functions, and can + * internally manage things however it chooses - it does so by setting the + * ENGINE_FLAGS_MANUAL_CMD_CTRL flag (using ENGINE_set_flags()). Otherwise + * the ENGINE_ctrl() code handles this on the ENGINE's behalf using the + * cmd_defns data (set using ENGINE_set_cmd_defns()). This means an ENGINE's + * ctrl() handler need only implement its own commands - the above "meta" + * commands will be taken care of. + */ + +/* + * Returns non-zero if the supplied ENGINE has a ctrl() handler. If "not", + * then all the remaining control commands will return failure, so it is + * worth checking this first if the caller is trying to "discover" the + * engine's capabilities and doesn't want errors generated unnecessarily. + */ +# define ENGINE_CTRL_HAS_CTRL_FUNCTION 10 +/* + * Returns a positive command number for the first command supported by the + * engine. Returns zero if no ctrl commands are supported. + */ +# define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11 +/* + * The 'long' argument specifies a command implemented by the engine, and the + * return value is the next command supported, or zero if there are no more. + */ +# define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12 +/* + * The 'void*' argument is a command name (cast from 'const char *'), and the + * return value is the command that corresponds to it. + */ +# define ENGINE_CTRL_GET_CMD_FROM_NAME 13 +/* + * The next two allow a command to be converted into its corresponding string + * form. In each case, the 'long' argument supplies the command. In the + * NAME_LEN case, the return value is the length of the command name (not + * counting a trailing EOL). In the NAME case, the 'void*' argument must be a + * string buffer large enough, and it will be populated with the name of the + * command (WITH a trailing EOL). + */ +# define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14 +# define ENGINE_CTRL_GET_NAME_FROM_CMD 15 +/* The next two are similar but give a "short description" of a command. */ +# define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16 +# define ENGINE_CTRL_GET_DESC_FROM_CMD 17 +/* + * With this command, the return value is the OR'd combination of + * ENGINE_CMD_FLAG_*** values that indicate what kind of input a given + * engine-specific ctrl command expects. + */ +# define ENGINE_CTRL_GET_CMD_FLAGS 18 + +/* + * ENGINE implementations should start the numbering of their own control + * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). + */ +# define ENGINE_CMD_BASE 200 + +/* + * NB: These 2 nCipher "chil" control commands are deprecated, and their + * functionality is now available through ENGINE-specific control commands + * (exposed through the above-mentioned 'CMD'-handling). Code using these 2 + * commands should be migrated to the more general command handling before + * these are removed. + */ + +/* Flags specific to the nCipher "chil" engine */ +# define ENGINE_CTRL_CHIL_SET_FORKCHECK 100 + /* + * Depending on the value of the (long)i argument, this sets or + * unsets the SimpleForkCheck flag in the CHIL API to enable or + * disable checking and workarounds for applications that fork(). + */ +# define ENGINE_CTRL_CHIL_NO_LOCKING 101 + /* + * This prevents the initialisation function from providing mutex + * callbacks to the nCipher library. + */ + +/* + * If an ENGINE supports its own specific control commands and wishes the + * framework to handle the above 'ENGINE_CMD_***'-manipulation commands on + * its behalf, it should supply a null-terminated array of ENGINE_CMD_DEFN + * entries to ENGINE_set_cmd_defns(). It should also implement a ctrl() + * handler that supports the stated commands (ie. the "cmd_num" entries as + * described by the array). NB: The array must be ordered in increasing order + * of cmd_num. "null-terminated" means that the last ENGINE_CMD_DEFN element + * has cmd_num set to zero and/or cmd_name set to NULL. + */ +typedef struct ENGINE_CMD_DEFN_st { + unsigned int cmd_num; /* The command number */ + const char *cmd_name; /* The command name itself */ + const char *cmd_desc; /* A short description of the command */ + unsigned int cmd_flags; /* The input the command expects */ +} ENGINE_CMD_DEFN; + +/* Generic function pointer */ +typedef int (*ENGINE_GEN_FUNC_PTR) (void); +/* Generic function pointer taking no arguments */ +typedef int (*ENGINE_GEN_INT_FUNC_PTR) (ENGINE *); +/* Specific control function pointer */ +typedef int (*ENGINE_CTRL_FUNC_PTR) (ENGINE *, int, long, void *, + void (*f) (void)); +/* Generic load_key function pointer */ +typedef EVP_PKEY *(*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *, + UI_METHOD *ui_method, + void *callback_data); +typedef int (*ENGINE_SSL_CLIENT_CERT_PTR) (ENGINE *, SSL *ssl, + STACK_OF(X509_NAME) *ca_dn, + X509 **pcert, EVP_PKEY **pkey, + STACK_OF(X509) **pother, + UI_METHOD *ui_method, + void *callback_data); +/*- + * These callback types are for an ENGINE's handler for cipher and digest logic. + * These handlers have these prototypes; + * int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid); + * int foo(ENGINE *e, const EVP_MD **digest, const int **nids, int nid); + * Looking at how to implement these handlers in the case of cipher support, if + * the framework wants the EVP_CIPHER for 'nid', it will call; + * foo(e, &p_evp_cipher, NULL, nid); (return zero for failure) + * If the framework wants a list of supported 'nid's, it will call; + * foo(e, NULL, &p_nids, 0); (returns number of 'nids' or -1 for error) + */ +/* + * Returns to a pointer to the array of supported cipher 'nid's. If the + * second parameter is non-NULL it is set to the size of the returned array. + */ +typedef int (*ENGINE_CIPHERS_PTR) (ENGINE *, const EVP_CIPHER **, + const int **, int); +typedef int (*ENGINE_DIGESTS_PTR) (ENGINE *, const EVP_MD **, const int **, + int); +typedef int (*ENGINE_PKEY_METHS_PTR) (ENGINE *, EVP_PKEY_METHOD **, + const int **, int); +typedef int (*ENGINE_PKEY_ASN1_METHS_PTR) (ENGINE *, EVP_PKEY_ASN1_METHOD **, + const int **, int); +/* + * STRUCTURE functions ... all of these functions deal with pointers to + * ENGINE structures where the pointers have a "structural reference". This + * means that their reference is to allowed access to the structure but it + * does not imply that the structure is functional. To simply increment or + * decrement the structural reference count, use ENGINE_by_id and + * ENGINE_free. NB: This is not required when iterating using ENGINE_get_next + * as it will automatically decrement the structural reference count of the + * "current" ENGINE and increment the structural reference count of the + * ENGINE it returns (unless it is NULL). + */ + +/* Get the first/last "ENGINE" type available. */ +ENGINE *ENGINE_get_first(void); +ENGINE *ENGINE_get_last(void); +/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */ +ENGINE *ENGINE_get_next(ENGINE *e); +ENGINE *ENGINE_get_prev(ENGINE *e); +/* Add another "ENGINE" type into the array. */ +int ENGINE_add(ENGINE *e); +/* Remove an existing "ENGINE" type from the array. */ +int ENGINE_remove(ENGINE *e); +/* Retrieve an engine from the list by its unique "id" value. */ +ENGINE *ENGINE_by_id(const char *id); + +#if OPENSSL_API_COMPAT < 0x10100000L +# define ENGINE_load_openssl() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_OPENSSL, NULL) +# define ENGINE_load_dynamic() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_DYNAMIC, NULL) +# ifndef OPENSSL_NO_STATIC_ENGINE +# define ENGINE_load_padlock() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_PADLOCK, NULL) +# define ENGINE_load_capi() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_CAPI, NULL) +# define ENGINE_load_dasync() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_DASYNC, NULL) +# define ENGINE_load_afalg() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_AFALG, NULL) +# endif +# define ENGINE_load_cryptodev() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_CRYPTODEV, NULL) +# define ENGINE_load_rdrand() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_RDRAND, NULL) +#endif +void ENGINE_load_builtin_engines(void); + +/* + * Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation + * "registry" handling. + */ +unsigned int ENGINE_get_table_flags(void); +void ENGINE_set_table_flags(unsigned int flags); + +/*- Manage registration of ENGINEs per "table". For each type, there are 3 + * functions; + * ENGINE_register_***(e) - registers the implementation from 'e' (if it has one) + * ENGINE_unregister_***(e) - unregister the implementation from 'e' + * ENGINE_register_all_***() - call ENGINE_register_***() for each 'e' in the list + * Cleanup is automatically registered from each table when required. + */ + +int ENGINE_register_RSA(ENGINE *e); +void ENGINE_unregister_RSA(ENGINE *e); +void ENGINE_register_all_RSA(void); + +int ENGINE_register_DSA(ENGINE *e); +void ENGINE_unregister_DSA(ENGINE *e); +void ENGINE_register_all_DSA(void); + +int ENGINE_register_EC(ENGINE *e); +void ENGINE_unregister_EC(ENGINE *e); +void ENGINE_register_all_EC(void); + +int ENGINE_register_DH(ENGINE *e); +void ENGINE_unregister_DH(ENGINE *e); +void ENGINE_register_all_DH(void); + +int ENGINE_register_RAND(ENGINE *e); +void ENGINE_unregister_RAND(ENGINE *e); +void ENGINE_register_all_RAND(void); + +int ENGINE_register_ciphers(ENGINE *e); +void ENGINE_unregister_ciphers(ENGINE *e); +void ENGINE_register_all_ciphers(void); + +int ENGINE_register_digests(ENGINE *e); +void ENGINE_unregister_digests(ENGINE *e); +void ENGINE_register_all_digests(void); + +int ENGINE_register_pkey_meths(ENGINE *e); +void ENGINE_unregister_pkey_meths(ENGINE *e); +void ENGINE_register_all_pkey_meths(void); + +int ENGINE_register_pkey_asn1_meths(ENGINE *e); +void ENGINE_unregister_pkey_asn1_meths(ENGINE *e); +void ENGINE_register_all_pkey_asn1_meths(void); + +/* + * These functions register all support from the above categories. Note, use + * of these functions can result in static linkage of code your application + * may not need. If you only need a subset of functionality, consider using + * more selective initialisation. + */ +int ENGINE_register_complete(ENGINE *e); +int ENGINE_register_all_complete(void); + +/* + * Send parametrised control commands to the engine. The possibilities to + * send down an integer, a pointer to data or a function pointer are + * provided. Any of the parameters may or may not be NULL, depending on the + * command number. In actuality, this function only requires a structural + * (rather than functional) reference to an engine, but many control commands + * may require the engine be functional. The caller should be aware of trying + * commands that require an operational ENGINE, and only use functional + * references in such situations. + */ +int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)); + +/* + * This function tests if an ENGINE-specific command is usable as a + * "setting". Eg. in an application's config file that gets processed through + * ENGINE_ctrl_cmd_string(). If this returns zero, it is not available to + * ENGINE_ctrl_cmd_string(), only ENGINE_ctrl(). + */ +int ENGINE_cmd_is_executable(ENGINE *e, int cmd); + +/* + * This function works like ENGINE_ctrl() with the exception of taking a + * command name instead of a command number, and can handle optional + * commands. See the comment on ENGINE_ctrl_cmd_string() for an explanation + * on how to use the cmd_name and cmd_optional. + */ +int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, + long i, void *p, void (*f) (void), int cmd_optional); + +/* + * This function passes a command-name and argument to an ENGINE. The + * cmd_name is converted to a command number and the control command is + * called using 'arg' as an argument (unless the ENGINE doesn't support such + * a command, in which case no control command is called). The command is + * checked for input flags, and if necessary the argument will be converted + * to a numeric value. If cmd_optional is non-zero, then if the ENGINE + * doesn't support the given cmd_name the return value will be success + * anyway. This function is intended for applications to use so that users + * (or config files) can supply engine-specific config data to the ENGINE at + * run-time to control behaviour of specific engines. As such, it shouldn't + * be used for calling ENGINE_ctrl() functions that return data, deal with + * binary data, or that are otherwise supposed to be used directly through + * ENGINE_ctrl() in application code. Any "return" data from an ENGINE_ctrl() + * operation in this function will be lost - the return value is interpreted + * as failure if the return value is zero, success otherwise, and this + * function returns a boolean value as a result. In other words, vendors of + * 'ENGINE'-enabled devices should write ENGINE implementations with + * parameterisations that work in this scheme, so that compliant ENGINE-based + * applications can work consistently with the same configuration for the + * same ENGINE-enabled devices, across applications. + */ +int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, + int cmd_optional); + +/* + * These functions are useful for manufacturing new ENGINE structures. They + * don't address reference counting at all - one uses them to populate an + * ENGINE structure with personalised implementations of things prior to + * using it directly or adding it to the builtin ENGINE list in OpenSSL. + * These are also here so that the ENGINE structure doesn't have to be + * exposed and break binary compatibility! + */ +ENGINE *ENGINE_new(void); +int ENGINE_free(ENGINE *e); +int ENGINE_up_ref(ENGINE *e); +int ENGINE_set_id(ENGINE *e, const char *id); +int ENGINE_set_name(ENGINE *e, const char *name); +int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); +int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); +int ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ecdsa_meth); +int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); +int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); +int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f); +int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f); +int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f); +int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f); +int ENGINE_set_load_privkey_function(ENGINE *e, + ENGINE_LOAD_KEY_PTR loadpriv_f); +int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f); +int ENGINE_set_load_ssl_client_cert_function(ENGINE *e, + ENGINE_SSL_CLIENT_CERT_PTR + loadssl_f); +int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f); +int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f); +int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f); +int ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f); +int ENGINE_set_flags(ENGINE *e, int flags); +int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns); +/* These functions allow control over any per-structure ENGINE data. */ +#define ENGINE_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, l, p, newf, dupf, freef) +int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg); +void *ENGINE_get_ex_data(const ENGINE *e, int idx); + +#if OPENSSL_API_COMPAT < 0x10100000L +/* + * This function previously cleaned up anything that needs it. Auto-deinit will + * now take care of it so it is no longer required to call this function. + */ +# define ENGINE_cleanup() while(0) continue +#endif + +/* + * These return values from within the ENGINE structure. These can be useful + * with functional references as well as structural references - it depends + * which you obtained. Using the result for functional purposes if you only + * obtained a structural reference may be problematic! + */ +const char *ENGINE_get_id(const ENGINE *e); +const char *ENGINE_get_name(const ENGINE *e); +const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); +const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); +const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e); +const DH_METHOD *ENGINE_get_DH(const ENGINE *e); +const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); +ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e); +ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e); +ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e); +ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e); +ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e); +ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e); +ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE + *e); +ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e); +ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e); +ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e); +ENGINE_PKEY_ASN1_METHS_PTR ENGINE_get_pkey_asn1_meths(const ENGINE *e); +const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid); +const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid); +const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid); +const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid); +const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth_str(ENGINE *e, + const char *str, + int len); +const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe, + const char *str, + int len); +const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e); +int ENGINE_get_flags(const ENGINE *e); + +/* + * FUNCTIONAL functions. These functions deal with ENGINE structures that + * have (or will) be initialised for use. Broadly speaking, the structural + * functions are useful for iterating the list of available engine types, + * creating new engine types, and other "list" operations. These functions + * actually deal with ENGINEs that are to be used. As such these functions + * can fail (if applicable) when particular engines are unavailable - eg. if + * a hardware accelerator is not attached or not functioning correctly. Each + * ENGINE has 2 reference counts; structural and functional. Every time a + * functional reference is obtained or released, a corresponding structural + * reference is automatically obtained or released too. + */ + +/* + * Initialise a engine type for use (or up its reference count if it's + * already in use). This will fail if the engine is not currently operational + * and cannot initialise. + */ +int ENGINE_init(ENGINE *e); +/* + * Free a functional reference to a engine type. This does not require a + * corresponding call to ENGINE_free as it also releases a structural + * reference. + */ +int ENGINE_finish(ENGINE *e); + +/* + * The following functions handle keys that are stored in some secondary + * location, handled by the engine. The storage may be on a card or + * whatever. + */ +EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, + UI_METHOD *ui_method, void *callback_data); +EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, + UI_METHOD *ui_method, void *callback_data); +int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, + STACK_OF(X509_NAME) *ca_dn, X509 **pcert, + EVP_PKEY **ppkey, STACK_OF(X509) **pother, + UI_METHOD *ui_method, void *callback_data); + +/* + * This returns a pointer for the current ENGINE structure that is (by + * default) performing any RSA operations. The value returned is an + * incremented reference, so it should be free'd (ENGINE_finish) before it is + * discarded. + */ +ENGINE *ENGINE_get_default_RSA(void); +/* Same for the other "methods" */ +ENGINE *ENGINE_get_default_DSA(void); +ENGINE *ENGINE_get_default_EC(void); +ENGINE *ENGINE_get_default_DH(void); +ENGINE *ENGINE_get_default_RAND(void); +/* + * These functions can be used to get a functional reference to perform + * ciphering or digesting corresponding to "nid". + */ +ENGINE *ENGINE_get_cipher_engine(int nid); +ENGINE *ENGINE_get_digest_engine(int nid); +ENGINE *ENGINE_get_pkey_meth_engine(int nid); +ENGINE *ENGINE_get_pkey_asn1_meth_engine(int nid); + +/* + * This sets a new default ENGINE structure for performing RSA operations. If + * the result is non-zero (success) then the ENGINE structure will have had + * its reference count up'd so the caller should still free their own + * reference 'e'. + */ +int ENGINE_set_default_RSA(ENGINE *e); +int ENGINE_set_default_string(ENGINE *e, const char *def_list); +/* Same for the other "methods" */ +int ENGINE_set_default_DSA(ENGINE *e); +int ENGINE_set_default_EC(ENGINE *e); +int ENGINE_set_default_DH(ENGINE *e); +int ENGINE_set_default_RAND(ENGINE *e); +int ENGINE_set_default_ciphers(ENGINE *e); +int ENGINE_set_default_digests(ENGINE *e); +int ENGINE_set_default_pkey_meths(ENGINE *e); +int ENGINE_set_default_pkey_asn1_meths(ENGINE *e); + +/* + * The combination "set" - the flags are bitwise "OR"d from the + * ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()" + * function, this function can result in unnecessary static linkage. If your + * application requires only specific functionality, consider using more + * selective functions. + */ +int ENGINE_set_default(ENGINE *e, unsigned int flags); + +void ENGINE_add_conf_module(void); + +/* Deprecated functions ... */ +/* int ENGINE_clear_defaults(void); */ + +/**************************/ +/* DYNAMIC ENGINE SUPPORT */ +/**************************/ + +/* Binary/behaviour compatibility levels */ +# define OSSL_DYNAMIC_VERSION (unsigned long)0x00030000 +/* + * Binary versions older than this are too old for us (whether we're a loader + * or a loadee) + */ +# define OSSL_DYNAMIC_OLDEST (unsigned long)0x00030000 + +/* + * When compiling an ENGINE entirely as an external shared library, loadable + * by the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' + * structure type provides the calling application's (or library's) error + * functionality and memory management function pointers to the loaded + * library. These should be used/set in the loaded library code so that the + * loading application's 'state' will be used/changed in all operations. The + * 'static_state' pointer allows the loaded library to know if it shares the + * same static data as the calling application (or library), and thus whether + * these callbacks need to be set or not. + */ +typedef void *(*dyn_MEM_malloc_fn) (size_t, const char *, int); +typedef void *(*dyn_MEM_realloc_fn) (void *, size_t, const char *, int); +typedef void (*dyn_MEM_free_fn) (void *, const char *, int); +typedef struct st_dynamic_MEM_fns { + dyn_MEM_malloc_fn malloc_fn; + dyn_MEM_realloc_fn realloc_fn; + dyn_MEM_free_fn free_fn; +} dynamic_MEM_fns; +/* + * FIXME: Perhaps the memory and locking code (crypto.h) should declare and + * use these types so we (and any other dependent code) can simplify a bit?? + */ +/* The top-level structure */ +typedef struct st_dynamic_fns { + void *static_state; + dynamic_MEM_fns mem_fns; +} dynamic_fns; + +/* + * The version checking function should be of this prototype. NB: The + * ossl_version value passed in is the OSSL_DYNAMIC_VERSION of the loading + * code. If this function returns zero, it indicates a (potential) version + * incompatibility and the loaded library doesn't believe it can proceed. + * Otherwise, the returned value is the (latest) version supported by the + * loading library. The loader may still decide that the loaded code's + * version is unsatisfactory and could veto the load. The function is + * expected to be implemented with the symbol name "v_check", and a default + * implementation can be fully instantiated with + * IMPLEMENT_DYNAMIC_CHECK_FN(). + */ +typedef unsigned long (*dynamic_v_check_fn) (unsigned long ossl_version); +# define IMPLEMENT_DYNAMIC_CHECK_FN() \ + OPENSSL_EXPORT unsigned long v_check(unsigned long v); \ + OPENSSL_EXPORT unsigned long v_check(unsigned long v) { \ + if (v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \ + return 0; } + +/* + * This function is passed the ENGINE structure to initialise with its own + * function and command settings. It should not adjust the structural or + * functional reference counts. If this function returns zero, (a) the load + * will be aborted, (b) the previous ENGINE state will be memcpy'd back onto + * the structure, and (c) the shared library will be unloaded. So + * implementations should do their own internal cleanup in failure + * circumstances otherwise they could leak. The 'id' parameter, if non-NULL, + * represents the ENGINE id that the loader is looking for. If this is NULL, + * the shared library can choose to return failure or to initialise a + * 'default' ENGINE. If non-NULL, the shared library must initialise only an + * ENGINE matching the passed 'id'. The function is expected to be + * implemented with the symbol name "bind_engine". A standard implementation + * can be instantiated with IMPLEMENT_DYNAMIC_BIND_FN(fn) where the parameter + * 'fn' is a callback function that populates the ENGINE structure and + * returns an int value (zero for failure). 'fn' should have prototype; + * [static] int fn(ENGINE *e, const char *id); + */ +typedef int (*dynamic_bind_engine) (ENGINE *e, const char *id, + const dynamic_fns *fns); +# define IMPLEMENT_DYNAMIC_BIND_FN(fn) \ + OPENSSL_EXPORT \ + int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); \ + OPENSSL_EXPORT \ + int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \ + if (ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \ + CRYPTO_set_mem_functions(fns->mem_fns.malloc_fn, \ + fns->mem_fns.realloc_fn, \ + fns->mem_fns.free_fn); \ + skip_cbs: \ + if (!fn(e, id)) return 0; \ + return 1; } + +/* + * If the loading application (or library) and the loaded ENGINE library + * share the same static data (eg. they're both dynamically linked to the + * same libcrypto.so) we need a way to avoid trying to set system callbacks - + * this would fail, and for the same reason that it's unnecessary to try. If + * the loaded ENGINE has (or gets from through the loader) its own copy of + * the libcrypto static data, we will need to set the callbacks. The easiest + * way to detect this is to have a function that returns a pointer to some + * static data and let the loading application and loaded ENGINE compare + * their respective values. + */ +void *ENGINE_get_static_state(void); + +# if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) +DEPRECATEDIN_1_1_0(void ENGINE_setup_bsd_cryptodev(void)) +# endif + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_ENGINE_strings(void); + +/* Error codes for the ENGINE functions. */ + +/* Function codes. */ +# define ENGINE_F_DYNAMIC_CTRL 180 +# define ENGINE_F_DYNAMIC_GET_DATA_CTX 181 +# define ENGINE_F_DYNAMIC_LOAD 182 +# define ENGINE_F_DYNAMIC_SET_DATA_CTX 183 +# define ENGINE_F_ENGINE_ADD 105 +# define ENGINE_F_ENGINE_BY_ID 106 +# define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170 +# define ENGINE_F_ENGINE_CTRL 142 +# define ENGINE_F_ENGINE_CTRL_CMD 178 +# define ENGINE_F_ENGINE_CTRL_CMD_STRING 171 +# define ENGINE_F_ENGINE_FINISH 107 +# define ENGINE_F_ENGINE_GET_CIPHER 185 +# define ENGINE_F_ENGINE_GET_DIGEST 186 +# define ENGINE_F_ENGINE_GET_FIRST 195 +# define ENGINE_F_ENGINE_GET_LAST 196 +# define ENGINE_F_ENGINE_GET_NEXT 115 +# define ENGINE_F_ENGINE_GET_PKEY_ASN1_METH 193 +# define ENGINE_F_ENGINE_GET_PKEY_METH 192 +# define ENGINE_F_ENGINE_GET_PREV 116 +# define ENGINE_F_ENGINE_INIT 119 +# define ENGINE_F_ENGINE_LIST_ADD 120 +# define ENGINE_F_ENGINE_LIST_REMOVE 121 +# define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150 +# define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151 +# define ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT 194 +# define ENGINE_F_ENGINE_NEW 122 +# define ENGINE_F_ENGINE_PKEY_ASN1_FIND_STR 197 +# define ENGINE_F_ENGINE_REMOVE 123 +# define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189 +# define ENGINE_F_ENGINE_SET_ID 129 +# define ENGINE_F_ENGINE_SET_NAME 130 +# define ENGINE_F_ENGINE_TABLE_REGISTER 184 +# define ENGINE_F_ENGINE_UNLOCKED_FINISH 191 +# define ENGINE_F_ENGINE_UP_REF 190 +# define ENGINE_F_INT_CTRL_HELPER 172 +# define ENGINE_F_INT_ENGINE_CONFIGURE 188 +# define ENGINE_F_INT_ENGINE_MODULE_INIT 187 + +/* Reason codes. */ +# define ENGINE_R_ALREADY_LOADED 100 +# define ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER 133 +# define ENGINE_R_CMD_NOT_EXECUTABLE 134 +# define ENGINE_R_COMMAND_TAKES_INPUT 135 +# define ENGINE_R_COMMAND_TAKES_NO_INPUT 136 +# define ENGINE_R_CONFLICTING_ENGINE_ID 103 +# define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED 119 +# define ENGINE_R_DSO_FAILURE 104 +# define ENGINE_R_DSO_NOT_FOUND 132 +# define ENGINE_R_ENGINES_SECTION_ERROR 148 +# define ENGINE_R_ENGINE_CONFIGURATION_ERROR 102 +# define ENGINE_R_ENGINE_IS_NOT_IN_LIST 105 +# define ENGINE_R_ENGINE_SECTION_ERROR 149 +# define ENGINE_R_FAILED_LOADING_PRIVATE_KEY 128 +# define ENGINE_R_FAILED_LOADING_PUBLIC_KEY 129 +# define ENGINE_R_FINISH_FAILED 106 +# define ENGINE_R_ID_OR_NAME_MISSING 108 +# define ENGINE_R_INIT_FAILED 109 +# define ENGINE_R_INTERNAL_LIST_ERROR 110 +# define ENGINE_R_INVALID_ARGUMENT 143 +# define ENGINE_R_INVALID_CMD_NAME 137 +# define ENGINE_R_INVALID_CMD_NUMBER 138 +# define ENGINE_R_INVALID_INIT_VALUE 151 +# define ENGINE_R_INVALID_STRING 150 +# define ENGINE_R_NOT_INITIALISED 117 +# define ENGINE_R_NOT_LOADED 112 +# define ENGINE_R_NO_CONTROL_FUNCTION 120 +# define ENGINE_R_NO_INDEX 144 +# define ENGINE_R_NO_LOAD_FUNCTION 125 +# define ENGINE_R_NO_REFERENCE 130 +# define ENGINE_R_NO_SUCH_ENGINE 116 +# define ENGINE_R_UNIMPLEMENTED_CIPHER 146 +# define ENGINE_R_UNIMPLEMENTED_DIGEST 147 +# define ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD 101 +# define ENGINE_R_VERSION_INCOMPATIBILITY 145 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/err.h b/android/x86/include/openssl/err.h new file mode 100644 index 00000000..f9390919 --- /dev/null +++ b/android/x86/include/openssl/err.h @@ -0,0 +1,259 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ERR_H +# define HEADER_ERR_H + +# include <openssl/e_os2.h> + +# ifndef OPENSSL_NO_STDIO +# include <stdio.h> +# include <stdlib.h> +# endif + +# include <openssl/ossl_typ.h> +# include <openssl/bio.h> +# include <openssl/lhash.h> + +#ifdef __cplusplus +extern "C" { +#endif + +# ifndef OPENSSL_NO_ERR +# define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e) +# else +# define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0) +# endif + +# include <errno.h> + +# define ERR_TXT_MALLOCED 0x01 +# define ERR_TXT_STRING 0x02 + +# define ERR_FLAG_MARK 0x01 + +# define ERR_NUM_ERRORS 16 +typedef struct err_state_st { + int err_flags[ERR_NUM_ERRORS]; + unsigned long err_buffer[ERR_NUM_ERRORS]; + char *err_data[ERR_NUM_ERRORS]; + int err_data_flags[ERR_NUM_ERRORS]; + const char *err_file[ERR_NUM_ERRORS]; + int err_line[ERR_NUM_ERRORS]; + int top, bottom; +} ERR_STATE; + +/* library */ +# define ERR_LIB_NONE 1 +# define ERR_LIB_SYS 2 +# define ERR_LIB_BN 3 +# define ERR_LIB_RSA 4 +# define ERR_LIB_DH 5 +# define ERR_LIB_EVP 6 +# define ERR_LIB_BUF 7 +# define ERR_LIB_OBJ 8 +# define ERR_LIB_PEM 9 +# define ERR_LIB_DSA 10 +# define ERR_LIB_X509 11 +/* #define ERR_LIB_METH 12 */ +# define ERR_LIB_ASN1 13 +# define ERR_LIB_CONF 14 +# define ERR_LIB_CRYPTO 15 +# define ERR_LIB_EC 16 +# define ERR_LIB_SSL 20 +/* #define ERR_LIB_SSL23 21 */ +/* #define ERR_LIB_SSL2 22 */ +/* #define ERR_LIB_SSL3 23 */ +/* #define ERR_LIB_RSAREF 30 */ +/* #define ERR_LIB_PROXY 31 */ +# define ERR_LIB_BIO 32 +# define ERR_LIB_PKCS7 33 +# define ERR_LIB_X509V3 34 +# define ERR_LIB_PKCS12 35 +# define ERR_LIB_RAND 36 +# define ERR_LIB_DSO 37 +# define ERR_LIB_ENGINE 38 +# define ERR_LIB_OCSP 39 +# define ERR_LIB_UI 40 +# define ERR_LIB_COMP 41 +# define ERR_LIB_ECDSA 42 +# define ERR_LIB_ECDH 43 +# define ERR_LIB_STORE 44 +# define ERR_LIB_FIPS 45 +# define ERR_LIB_CMS 46 +# define ERR_LIB_TS 47 +# define ERR_LIB_HMAC 48 +# define ERR_LIB_JPAKE 49 +# define ERR_LIB_CT 50 +# define ERR_LIB_ASYNC 51 +# define ERR_LIB_KDF 52 + +# define ERR_LIB_USER 128 + +# define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ECerr(f,r) ERR_PUT_error(ERR_LIB_EC,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ECDSAerr(f,r) ERR_PUT_error(ERR_LIB_ECDSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ECDHerr(f,r) ERR_PUT_error(ERR_LIB_ECDH,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define STOREerr(f,r) ERR_PUT_error(ERR_LIB_STORE,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define CMSerr(f,r) ERR_PUT_error(ERR_LIB_CMS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define CTerr(f,r) ERR_PUT_error(ERR_LIB_CT,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ASYNCerr(f,r) ERR_PUT_error(ERR_LIB_ASYNC,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define KDFerr(f,r) ERR_PUT_error(ERR_LIB_KDF,(f),(r),OPENSSL_FILE,OPENSSL_LINE) + +# define ERR_PACK(l,f,r) ( \ + (((unsigned int)(l) & 0x0FF) << 24L) | \ + (((unsigned int)(f) & 0xFFF) << 12L) | \ + (((unsigned int)(r) & 0xFFF) ) ) +# define ERR_GET_LIB(l) (int)(((l) >> 24L) & 0x0FFL) +# define ERR_GET_FUNC(l) (int)(((l) >> 12L) & 0xFFFL) +# define ERR_GET_REASON(l) (int)( (l) & 0xFFFL) + +/* OS functions */ +# define SYS_F_FOPEN 1 +# define SYS_F_CONNECT 2 +# define SYS_F_GETSERVBYNAME 3 +# define SYS_F_SOCKET 4 +# define SYS_F_IOCTLSOCKET 5 +# define SYS_F_BIND 6 +# define SYS_F_LISTEN 7 +# define SYS_F_ACCEPT 8 +# define SYS_F_WSASTARTUP 9/* Winsock stuff */ +# define SYS_F_OPENDIR 10 +# define SYS_F_FREAD 11 +# define SYS_F_GETADDRINFO 12 +# define SYS_F_GETNAMEINFO 13 +# define SYS_F_SETSOCKOPT 14 +# define SYS_F_GETSOCKOPT 15 +# define SYS_F_GETSOCKNAME 16 +# define SYS_F_GETHOSTBYNAME 17 + +/* reasons */ +# define ERR_R_SYS_LIB ERR_LIB_SYS/* 2 */ +# define ERR_R_BN_LIB ERR_LIB_BN/* 3 */ +# define ERR_R_RSA_LIB ERR_LIB_RSA/* 4 */ +# define ERR_R_DH_LIB ERR_LIB_DH/* 5 */ +# define ERR_R_EVP_LIB ERR_LIB_EVP/* 6 */ +# define ERR_R_BUF_LIB ERR_LIB_BUF/* 7 */ +# define ERR_R_OBJ_LIB ERR_LIB_OBJ/* 8 */ +# define ERR_R_PEM_LIB ERR_LIB_PEM/* 9 */ +# define ERR_R_DSA_LIB ERR_LIB_DSA/* 10 */ +# define ERR_R_X509_LIB ERR_LIB_X509/* 11 */ +# define ERR_R_ASN1_LIB ERR_LIB_ASN1/* 13 */ +# define ERR_R_EC_LIB ERR_LIB_EC/* 16 */ +# define ERR_R_BIO_LIB ERR_LIB_BIO/* 32 */ +# define ERR_R_PKCS7_LIB ERR_LIB_PKCS7/* 33 */ +# define ERR_R_X509V3_LIB ERR_LIB_X509V3/* 34 */ +# define ERR_R_ENGINE_LIB ERR_LIB_ENGINE/* 38 */ +# define ERR_R_ECDSA_LIB ERR_LIB_ECDSA/* 42 */ + +# define ERR_R_NESTED_ASN1_ERROR 58 +# define ERR_R_MISSING_ASN1_EOS 63 + +/* fatal error */ +# define ERR_R_FATAL 64 +# define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL) +# define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL) +# define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL) +# define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL) +# define ERR_R_DISABLED (5|ERR_R_FATAL) +# define ERR_R_INIT_FAIL (6|ERR_R_FATAL) +# define ERR_R_PASSED_INVALID_ARGUMENT (7) + +/* + * 99 is the maximum possible ERR_R_... code, higher values are reserved for + * the individual libraries + */ + +typedef struct ERR_string_data_st { + unsigned long error; + const char *string; +} ERR_STRING_DATA; + +DEFINE_LHASH_OF(ERR_STRING_DATA); + +void ERR_put_error(int lib, int func, int reason, const char *file, int line); +void ERR_set_error_data(char *data, int flags); + +unsigned long ERR_get_error(void); +unsigned long ERR_get_error_line(const char **file, int *line); +unsigned long ERR_get_error_line_data(const char **file, int *line, + const char **data, int *flags); +unsigned long ERR_peek_error(void); +unsigned long ERR_peek_error_line(const char **file, int *line); +unsigned long ERR_peek_error_line_data(const char **file, int *line, + const char **data, int *flags); +unsigned long ERR_peek_last_error(void); +unsigned long ERR_peek_last_error_line(const char **file, int *line); +unsigned long ERR_peek_last_error_line_data(const char **file, int *line, + const char **data, int *flags); +void ERR_clear_error(void); +char *ERR_error_string(unsigned long e, char *buf); +void ERR_error_string_n(unsigned long e, char *buf, size_t len); +const char *ERR_lib_error_string(unsigned long e); +const char *ERR_func_error_string(unsigned long e); +const char *ERR_reason_error_string(unsigned long e); +void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), + void *u); +# ifndef OPENSSL_NO_STDIO +void ERR_print_errors_fp(FILE *fp); +# endif +void ERR_print_errors(BIO *bp); +void ERR_add_error_data(int num, ...); +void ERR_add_error_vdata(int num, va_list args); +int ERR_load_strings(int lib, ERR_STRING_DATA str[]); +int ERR_unload_strings(int lib, ERR_STRING_DATA str[]); +int ERR_load_ERR_strings(void); + +#if OPENSSL_API_COMPAT < 0x10100000L +# define ERR_load_crypto_strings() \ + OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL) +# define ERR_free_strings() while(0) continue +#endif + +DEPRECATEDIN_1_1_0(void ERR_remove_thread_state(void *)) +DEPRECATEDIN_1_0_0(void ERR_remove_state(unsigned long pid)) +ERR_STATE *ERR_get_state(void); + +int ERR_get_next_error_library(void); + +int ERR_set_mark(void); +int ERR_pop_to_mark(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/android/x86/include/openssl/evp.h b/android/x86/include/openssl/evp.h new file mode 100644 index 00000000..b9c83b2b --- /dev/null +++ b/android/x86/include/openssl/evp.h @@ -0,0 +1,1586 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ENVELOPE_H +# define HEADER_ENVELOPE_H + +# include <openssl/opensslconf.h> +# include <openssl/ossl_typ.h> +# include <openssl/symhacks.h> +# include <openssl/bio.h> + +# define EVP_MAX_MD_SIZE 64/* longest known is SHA512 */ +# define EVP_MAX_KEY_LENGTH 64 +# define EVP_MAX_IV_LENGTH 16 +# define EVP_MAX_BLOCK_LENGTH 32 + +# define PKCS5_SALT_LEN 8 +/* Default PKCS#5 iteration count */ +# define PKCS5_DEFAULT_ITER 2048 + +# include <openssl/objects.h> + +# define EVP_PK_RSA 0x0001 +# define EVP_PK_DSA 0x0002 +# define EVP_PK_DH 0x0004 +# define EVP_PK_EC 0x0008 +# define EVP_PKT_SIGN 0x0010 +# define EVP_PKT_ENC 0x0020 +# define EVP_PKT_EXCH 0x0040 +# define EVP_PKS_RSA 0x0100 +# define EVP_PKS_DSA 0x0200 +# define EVP_PKS_EC 0x0400 + +# define EVP_PKEY_NONE NID_undef +# define EVP_PKEY_RSA NID_rsaEncryption +# define EVP_PKEY_RSA2 NID_rsa +# define EVP_PKEY_DSA NID_dsa +# define EVP_PKEY_DSA1 NID_dsa_2 +# define EVP_PKEY_DSA2 NID_dsaWithSHA +# define EVP_PKEY_DSA3 NID_dsaWithSHA1 +# define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 +# define EVP_PKEY_DH NID_dhKeyAgreement +# define EVP_PKEY_DHX NID_dhpublicnumber +# define EVP_PKEY_EC NID_X9_62_id_ecPublicKey +# define EVP_PKEY_HMAC NID_hmac +# define EVP_PKEY_CMAC NID_cmac +# define EVP_PKEY_TLS1_PRF NID_tls1_prf +# define EVP_PKEY_HKDF NID_hkdf + +#ifdef __cplusplus +extern "C" { +#endif + +# define EVP_PKEY_MO_SIGN 0x0001 +# define EVP_PKEY_MO_VERIFY 0x0002 +# define EVP_PKEY_MO_ENCRYPT 0x0004 +# define EVP_PKEY_MO_DECRYPT 0x0008 + +# ifndef EVP_MD +EVP_MD *EVP_MD_meth_new(int md_type, int pkey_type); +EVP_MD *EVP_MD_meth_dup(const EVP_MD *md); +void EVP_MD_meth_free(EVP_MD *md); + +int EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize); +int EVP_MD_meth_set_result_size(EVP_MD *md, int resultsize); +int EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize); +int EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags); +int EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx)); +int EVP_MD_meth_set_update(EVP_MD *md, int (*update)(EVP_MD_CTX *ctx, + const void *data, + size_t count)); +int EVP_MD_meth_set_final(EVP_MD *md, int (*final)(EVP_MD_CTX *ctx, + unsigned char *md)); +int EVP_MD_meth_set_copy(EVP_MD *md, int (*copy)(EVP_MD_CTX *to, + const EVP_MD_CTX *from)); +int EVP_MD_meth_set_cleanup(EVP_MD *md, int (*cleanup)(EVP_MD_CTX *ctx)); +int EVP_MD_meth_set_ctrl(EVP_MD *md, int (*ctrl)(EVP_MD_CTX *ctx, int cmd, + int p1, void *p2)); + +int EVP_MD_meth_get_input_blocksize(const EVP_MD *md); +int EVP_MD_meth_get_result_size(const EVP_MD *md); +int EVP_MD_meth_get_app_datasize(const EVP_MD *md); +unsigned long EVP_MD_meth_get_flags(const EVP_MD *md); +int (*EVP_MD_meth_get_init(const EVP_MD *md))(EVP_MD_CTX *ctx); +int (*EVP_MD_meth_get_update(const EVP_MD *md))(EVP_MD_CTX *ctx, + const void *data, + size_t count); +int (*EVP_MD_meth_get_final(const EVP_MD *md))(EVP_MD_CTX *ctx, + unsigned char *md); +int (*EVP_MD_meth_get_copy(const EVP_MD *md))(EVP_MD_CTX *to, + const EVP_MD_CTX *from); +int (*EVP_MD_meth_get_cleanup(const EVP_MD *md))(EVP_MD_CTX *ctx); +int (*EVP_MD_meth_get_ctrl(const EVP_MD *md))(EVP_MD_CTX *ctx, int cmd, + int p1, void *p2); + +/* digest can only handle a single block */ +# define EVP_MD_FLAG_ONESHOT 0x0001 + +/* DigestAlgorithmIdentifier flags... */ + +# define EVP_MD_FLAG_DIGALGID_MASK 0x0018 + +/* NULL or absent parameter accepted. Use NULL */ + +# define EVP_MD_FLAG_DIGALGID_NULL 0x0000 + +/* NULL or absent parameter accepted. Use NULL for PKCS#1 otherwise absent */ + +# define EVP_MD_FLAG_DIGALGID_ABSENT 0x0008 + +/* Custom handling via ctrl */ + +# define EVP_MD_FLAG_DIGALGID_CUSTOM 0x0018 + +/* Note if suitable for use in FIPS mode */ +# define EVP_MD_FLAG_FIPS 0x0400 + +/* Digest ctrls */ + +# define EVP_MD_CTRL_DIGALGID 0x1 +# define EVP_MD_CTRL_MICALG 0x2 + +/* Minimum Algorithm specific ctrl value */ + +# define EVP_MD_CTRL_ALG_CTRL 0x1000 + +# endif /* !EVP_MD */ + +/* values for EVP_MD_CTX flags */ + +# define EVP_MD_CTX_FLAG_ONESHOT 0x0001/* digest update will be + * called once only */ +# define EVP_MD_CTX_FLAG_CLEANED 0x0002/* context has already been + * cleaned */ +# define EVP_MD_CTX_FLAG_REUSE 0x0004/* Don't free up ctx->md_data + * in EVP_MD_CTX_reset */ +/* + * FIPS and pad options are ignored in 1.0.0, definitions are here so we + * don't accidentally reuse the values for other purposes. + */ + +# define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008/* Allow use of non FIPS + * digest in FIPS mode */ + +/* + * The following PAD options are also currently ignored in 1.0.0, digest + * parameters are handled through EVP_DigestSign*() and EVP_DigestVerify*() + * instead. + */ +# define EVP_MD_CTX_FLAG_PAD_MASK 0xF0/* RSA mode to use */ +# define EVP_MD_CTX_FLAG_PAD_PKCS1 0x00/* PKCS#1 v1.5 mode */ +# define EVP_MD_CTX_FLAG_PAD_X931 0x10/* X9.31 mode */ +# define EVP_MD_CTX_FLAG_PAD_PSS 0x20/* PSS mode */ + +# define EVP_MD_CTX_FLAG_NO_INIT 0x0100/* Don't initialize md_data */ +/* + * Some functions such as EVP_DigestSign only finalise copies of internal + * contexts so additional data can be included after the finalisation call. + * This is inefficient if this functionality is not required: it is disabled + * if the following flag is set. + */ +# define EVP_MD_CTX_FLAG_FINALISE 0x0200 + +EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len); +EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher); +void EVP_CIPHER_meth_free(EVP_CIPHER *cipher); + +int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len); +int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags); +int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size); +int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher, + int (*init) (EVP_CIPHER_CTX *ctx, + const unsigned char *key, + const unsigned char *iv, + int enc)); +int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher, + int (*do_cipher) (EVP_CIPHER_CTX *ctx, + unsigned char *out, + const unsigned char *in, + size_t inl)); +int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher, + int (*cleanup) (EVP_CIPHER_CTX *)); +int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher, + int (*set_asn1_parameters) (EVP_CIPHER_CTX *, + ASN1_TYPE *)); +int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher, + int (*get_asn1_parameters) (EVP_CIPHER_CTX *, + ASN1_TYPE *)); +int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher, + int (*ctrl) (EVP_CIPHER_CTX *, int type, + int arg, void *ptr)); + +int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx, + const unsigned char *key, + const unsigned char *iv, + int enc); +int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx, + unsigned char *out, + const unsigned char *in, + size_t inl); +int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *); +int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, + ASN1_TYPE *); +int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, + ASN1_TYPE *); +int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, + int type, int arg, + void *ptr); + +/* Values for cipher flags */ + +/* Modes for ciphers */ + +# define EVP_CIPH_STREAM_CIPHER 0x0 +# define EVP_CIPH_ECB_MODE 0x1 +# define EVP_CIPH_CBC_MODE 0x2 +# define EVP_CIPH_CFB_MODE 0x3 +# define EVP_CIPH_OFB_MODE 0x4 +# define EVP_CIPH_CTR_MODE 0x5 +# define EVP_CIPH_GCM_MODE 0x6 +# define EVP_CIPH_CCM_MODE 0x7 +# define EVP_CIPH_XTS_MODE 0x10001 +# define EVP_CIPH_WRAP_MODE 0x10002 +# define EVP_CIPH_OCB_MODE 0x10003 +# define EVP_CIPH_MODE 0xF0007 +/* Set if variable length cipher */ +# define EVP_CIPH_VARIABLE_LENGTH 0x8 +/* Set if the iv handling should be done by the cipher itself */ +# define EVP_CIPH_CUSTOM_IV 0x10 +/* Set if the cipher's init() function should be called if key is NULL */ +# define EVP_CIPH_ALWAYS_CALL_INIT 0x20 +/* Call ctrl() to init cipher parameters */ +# define EVP_CIPH_CTRL_INIT 0x40 +/* Don't use standard key length function */ +# define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80 +/* Don't use standard block padding */ +# define EVP_CIPH_NO_PADDING 0x100 +/* cipher handles random key generation */ +# define EVP_CIPH_RAND_KEY 0x200 +/* cipher has its own additional copying logic */ +# define EVP_CIPH_CUSTOM_COPY 0x400 +/* Allow use default ASN1 get/set iv */ +# define EVP_CIPH_FLAG_DEFAULT_ASN1 0x1000 +/* Buffer length in bits not bytes: CFB1 mode only */ +# define EVP_CIPH_FLAG_LENGTH_BITS 0x2000 +/* Note if suitable for use in FIPS mode */ +# define EVP_CIPH_FLAG_FIPS 0x4000 +/* Allow non FIPS cipher in FIPS mode */ +# define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0x8000 +/* + * Cipher handles any and all padding logic as well as finalisation. + */ +# define EVP_CIPH_FLAG_CUSTOM_CIPHER 0x100000 +# define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000 +# define EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK 0x400000 +/* Cipher can handle pipeline operations */ +# define EVP_CIPH_FLAG_PIPELINE 0X800000 + +/* + * Cipher context flag to indicate we can handle wrap mode: if allowed in + * older applications it could overflow buffers. + */ + +# define EVP_CIPHER_CTX_FLAG_WRAP_ALLOW 0x1 + +/* ctrl() values */ + +# define EVP_CTRL_INIT 0x0 +# define EVP_CTRL_SET_KEY_LENGTH 0x1 +# define EVP_CTRL_GET_RC2_KEY_BITS 0x2 +# define EVP_CTRL_SET_RC2_KEY_BITS 0x3 +# define EVP_CTRL_GET_RC5_ROUNDS 0x4 +# define EVP_CTRL_SET_RC5_ROUNDS 0x5 +# define EVP_CTRL_RAND_KEY 0x6 +# define EVP_CTRL_PBE_PRF_NID 0x7 +# define EVP_CTRL_COPY 0x8 +# define EVP_CTRL_AEAD_SET_IVLEN 0x9 +# define EVP_CTRL_AEAD_GET_TAG 0x10 +# define EVP_CTRL_AEAD_SET_TAG 0x11 +# define EVP_CTRL_AEAD_SET_IV_FIXED 0x12 +# define EVP_CTRL_GCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN +# define EVP_CTRL_GCM_GET_TAG EVP_CTRL_AEAD_GET_TAG +# define EVP_CTRL_GCM_SET_TAG EVP_CTRL_AEAD_SET_TAG +# define EVP_CTRL_GCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED +# define EVP_CTRL_GCM_IV_GEN 0x13 +# define EVP_CTRL_CCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN +# define EVP_CTRL_CCM_GET_TAG EVP_CTRL_AEAD_GET_TAG +# define EVP_CTRL_CCM_SET_TAG EVP_CTRL_AEAD_SET_TAG +# define EVP_CTRL_CCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED +# define EVP_CTRL_CCM_SET_L 0x14 +# define EVP_CTRL_CCM_SET_MSGLEN 0x15 +/* + * AEAD cipher deduces payload length and returns number of bytes required to + * store MAC and eventual padding. Subsequent call to EVP_Cipher even + * appends/verifies MAC. + */ +# define EVP_CTRL_AEAD_TLS1_AAD 0x16 +/* Used by composite AEAD ciphers, no-op in GCM, CCM... */ +# define EVP_CTRL_AEAD_SET_MAC_KEY 0x17 +/* Set the GCM invocation field, decrypt only */ +# define EVP_CTRL_GCM_SET_IV_INV 0x18 + +# define EVP_CTRL_TLS1_1_MULTIBLOCK_AAD 0x19 +# define EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT 0x1a +# define EVP_CTRL_TLS1_1_MULTIBLOCK_DECRYPT 0x1b +# define EVP_CTRL_TLS1_1_MULTIBLOCK_MAX_BUFSIZE 0x1c + +# define EVP_CTRL_SSL3_MASTER_SECRET 0x1d + +/* EVP_CTRL_SET_SBOX takes the char * specifying S-boxes */ +# define EVP_CTRL_SET_SBOX 0x1e +/* + * EVP_CTRL_SBOX_USED takes a 'size_t' and 'char *', pointing at a + * pre-allocated buffer with specified size + */ +# define EVP_CTRL_SBOX_USED 0x1f +/* EVP_CTRL_KEY_MESH takes 'size_t' number of bytes to mesh the key after, + * 0 switches meshing off + */ +# define EVP_CTRL_KEY_MESH 0x20 +/* EVP_CTRL_BLOCK_PADDING_MODE takes the padding mode */ +# define EVP_CTRL_BLOCK_PADDING_MODE 0x21 + +/* Set the output buffers to use for a pipelined operation */ +# define EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS 0x22 +/* Set the input buffers to use for a pipelined operation */ +# define EVP_CTRL_SET_PIPELINE_INPUT_BUFS 0x23 +/* Set the input buffer lengths to use for a pipelined operation */ +# define EVP_CTRL_SET_PIPELINE_INPUT_LENS 0x24 + +/* Padding modes */ +#define EVP_PADDING_PKCS7 1 +#define EVP_PADDING_ISO7816_4 2 +#define EVP_PADDING_ANSI923 3 +#define EVP_PADDING_ISO10126 4 +#define EVP_PADDING_ZERO 5 + +/* RFC 5246 defines additional data to be 13 bytes in length */ +# define EVP_AEAD_TLS1_AAD_LEN 13 + +typedef struct { + unsigned char *out; + const unsigned char *inp; + size_t len; + unsigned int interleave; +} EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM; + +/* GCM TLS constants */ +/* Length of fixed part of IV derived from PRF */ +# define EVP_GCM_TLS_FIXED_IV_LEN 4 +/* Length of explicit part of IV part of TLS records */ +# define EVP_GCM_TLS_EXPLICIT_IV_LEN 8 +/* Length of tag for TLS */ +# define EVP_GCM_TLS_TAG_LEN 16 + +/* CCM TLS constants */ +/* Length of fixed part of IV derived from PRF */ +# define EVP_CCM_TLS_FIXED_IV_LEN 4 +/* Length of explicit part of IV part of TLS records */ +# define EVP_CCM_TLS_EXPLICIT_IV_LEN 8 + +typedef struct evp_cipher_info_st { + const EVP_CIPHER *cipher; + unsigned char iv[EVP_MAX_IV_LENGTH]; +} EVP_CIPHER_INFO; + + +/* Password based encryption function */ +typedef int (EVP_PBE_KEYGEN) (EVP_CIPHER_CTX *ctx, const char *pass, + int passlen, ASN1_TYPE *param, + const EVP_CIPHER *cipher, const EVP_MD *md, + int en_de); + +# ifndef OPENSSL_NO_RSA +# define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ + (char *)(rsa)) +# endif + +# ifndef OPENSSL_NO_DSA +# define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ + (char *)(dsa)) +# endif + +# ifndef OPENSSL_NO_DH +# define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\ + (char *)(dh)) +# endif + +# ifndef OPENSSL_NO_EC +# define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC,\ + (char *)(eckey)) +# endif + +/* Add some extra combinations */ +# define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) +# define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) +# define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) +# define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) + +int EVP_MD_type(const EVP_MD *md); +# define EVP_MD_nid(e) EVP_MD_type(e) +# define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e)) +int EVP_MD_pkey_type(const EVP_MD *md); +int EVP_MD_size(const EVP_MD *md); +int EVP_MD_block_size(const EVP_MD *md); +unsigned long EVP_MD_flags(const EVP_MD *md); + +const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx); +int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx, + const void *data, size_t count); +void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx, + int (*update) (EVP_MD_CTX *ctx, + const void *data, size_t count)); +# define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) +# define EVP_MD_CTX_block_size(e) EVP_MD_block_size(EVP_MD_CTX_md(e)) +# define EVP_MD_CTX_type(e) EVP_MD_type(EVP_MD_CTX_md(e)) +EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx); +void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx); + +int EVP_CIPHER_nid(const EVP_CIPHER *cipher); +# define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e)) +int EVP_CIPHER_block_size(const EVP_CIPHER *cipher); +int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *cipher); +int EVP_CIPHER_key_length(const EVP_CIPHER *cipher); +int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher); +unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher); +# define EVP_CIPHER_mode(e) (EVP_CIPHER_flags(e) & EVP_CIPH_MODE) + +const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx); +const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx); +const unsigned char *EVP_CIPHER_CTX_original_iv(const EVP_CIPHER_CTX *ctx); +unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx); +unsigned char *EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_num(const EVP_CIPHER_CTX *ctx); +void EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num); +int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in); +void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx); +void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data); +void *EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx); +void *EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data); +# define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) +# if OPENSSL_API_COMPAT < 0x10100000L +# define EVP_CIPHER_CTX_flags(c) EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(c)) +# endif +# define EVP_CIPHER_CTX_mode(c) EVP_CIPHER_mode(EVP_CIPHER_CTX_cipher(c)) + +# define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) +# define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) + +# define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) +# define EVP_SignInit(a,b) EVP_DigestInit(a,b) +# define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) +# define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) +# define EVP_VerifyInit(a,b) EVP_DigestInit(a,b) +# define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) +# define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) +# define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) +# define EVP_DigestSignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) +# define EVP_DigestVerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) + +# ifdef CONST_STRICT +void BIO_set_md(BIO *, const EVP_MD *md); +# else +# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md) +# endif +# define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp) +# define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp) +# define BIO_set_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_SET_MD_CTX,0,(char *)mdcp) +# define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) +# define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp) + +/*__owur*/ int EVP_Cipher(EVP_CIPHER_CTX *c, + unsigned char *out, + const unsigned char *in, unsigned int inl); + +# define EVP_add_cipher_alias(n,alias) \ + OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n)) +# define EVP_add_digest_alias(n,alias) \ + OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n)) +# define EVP_delete_cipher_alias(alias) \ + OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS); +# define EVP_delete_digest_alias(alias) \ + OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS); + +int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2); +EVP_MD_CTX *EVP_MD_CTX_new(void); +int EVP_MD_CTX_reset(EVP_MD_CTX *ctx); +void EVP_MD_CTX_free(EVP_MD_CTX *ctx); +# define EVP_MD_CTX_create() EVP_MD_CTX_new() +# define EVP_MD_CTX_init(ctx) EVP_MD_CTX_reset((ctx)) +# define EVP_MD_CTX_destroy(ctx) EVP_MD_CTX_free((ctx)) +__owur int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); +void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); +void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); +int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); +__owur int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, + ENGINE *impl); +__owur int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, + size_t cnt); +__owur int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, + unsigned int *s); +__owur int EVP_Digest(const void *data, size_t count, + unsigned char *md, unsigned int *size, + const EVP_MD *type, ENGINE *impl); + +__owur int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in); +__owur int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); +__owur int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, + unsigned int *s); + +#ifndef OPENSSL_NO_UI +int EVP_read_pw_string(char *buf, int length, const char *prompt, int verify); +int EVP_read_pw_string_min(char *buf, int minlen, int maxlen, + const char *prompt, int verify); +void EVP_set_pw_prompt(const char *prompt); +char *EVP_get_pw_prompt(void); +#endif + +__owur int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, + const unsigned char *salt, + const unsigned char *data, int datal, int count, + unsigned char *key, unsigned char *iv); + +void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags); +void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags); +int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags); + +__owur int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv); +/*__owur*/ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, + const EVP_CIPHER *cipher, ENGINE *impl, + const unsigned char *key, + const unsigned char *iv); +/*__owur*/ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl, const unsigned char *in, int inl); +/*__owur*/ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl); +/*__owur*/ int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl); + +__owur int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv); +/*__owur*/ int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, + const EVP_CIPHER *cipher, ENGINE *impl, + const unsigned char *key, + const unsigned char *iv); +/*__owur*/ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl, const unsigned char *in, int inl); +__owur int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, + int *outl); +/*__owur*/ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, + int *outl); + +__owur int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv, + int enc); +/*__owur*/ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, + const EVP_CIPHER *cipher, ENGINE *impl, + const unsigned char *key, + const unsigned char *iv, int enc); +__owur int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl, const unsigned char *in, int inl); +__owur int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, + int *outl); +__owur int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, + int *outl); + +__owur int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s, + EVP_PKEY *pkey); + +__owur int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, + unsigned int siglen, EVP_PKEY *pkey); + +/*__owur*/ int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, + const EVP_MD *type, ENGINE *e, + EVP_PKEY *pkey); +__owur int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, + size_t *siglen); + +__owur int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, + const EVP_MD *type, ENGINE *e, + EVP_PKEY *pkey); +__owur int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, + size_t siglen); + +# ifndef OPENSSL_NO_RSA +__owur int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, + const unsigned char *ek, int ekl, + const unsigned char *iv, EVP_PKEY *priv); +__owur int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); + +__owur int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, + unsigned char **ek, int *ekl, unsigned char *iv, + EVP_PKEY **pubk, int npubk); +__owur int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); +# endif + +EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void); +void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx); +int EVP_ENCODE_CTX_copy(EVP_ENCODE_CTX *dctx, EVP_ENCODE_CTX *sctx); +int EVP_ENCODE_CTX_num(EVP_ENCODE_CTX *ctx); +void EVP_EncodeInit(EVP_ENCODE_CTX *ctx); +int EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, + const unsigned char *in, int inl); +void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl); +int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n); + +void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); +int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, + const unsigned char *in, int inl); +int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned + char *out, int *outl); +int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define EVP_CIPHER_CTX_init(c) EVP_CIPHER_CTX_reset(c) +# define EVP_CIPHER_CTX_cleanup(c) EVP_CIPHER_CTX_reset(c) +# endif +EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void); +int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c); +void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *c); +int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); +int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad); +int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); +int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key); + +const BIO_METHOD *BIO_f_md(void); +const BIO_METHOD *BIO_f_base64(void); +const BIO_METHOD *BIO_f_cipher(void); +const BIO_METHOD *BIO_f_reliable(void); +__owur int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k, + const unsigned char *i, int enc); + +const EVP_MD *EVP_md_null(void); +# ifndef OPENSSL_NO_MD2 +const EVP_MD *EVP_md2(void); +# endif +# ifndef OPENSSL_NO_MD4 +const EVP_MD *EVP_md4(void); +# endif +# ifndef OPENSSL_NO_MD5 +const EVP_MD *EVP_md5(void); +const EVP_MD *EVP_md5_sha1(void); +# endif +# ifndef OPENSSL_NO_BLAKE2 +const EVP_MD *EVP_blake2b512(void); +const EVP_MD *EVP_blake2s256(void); +# endif +const EVP_MD *EVP_sha1(void); +const EVP_MD *EVP_sha224(void); +const EVP_MD *EVP_sha256(void); +const EVP_MD *EVP_sha384(void); +const EVP_MD *EVP_sha512(void); +# ifndef OPENSSL_NO_MDC2 +const EVP_MD *EVP_mdc2(void); +# endif +# ifndef OPENSSL_NO_RMD160 +const EVP_MD *EVP_ripemd160(void); +# endif +# ifndef OPENSSL_NO_WHIRLPOOL +const EVP_MD *EVP_whirlpool(void); +# endif +const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ +# ifndef OPENSSL_NO_DES +const EVP_CIPHER *EVP_des_ecb(void); +const EVP_CIPHER *EVP_des_ede(void); +const EVP_CIPHER *EVP_des_ede3(void); +const EVP_CIPHER *EVP_des_ede_ecb(void); +const EVP_CIPHER *EVP_des_ede3_ecb(void); +const EVP_CIPHER *EVP_des_cfb64(void); +# define EVP_des_cfb EVP_des_cfb64 +const EVP_CIPHER *EVP_des_cfb1(void); +const EVP_CIPHER *EVP_des_cfb8(void); +const EVP_CIPHER *EVP_des_ede_cfb64(void); +# define EVP_des_ede_cfb EVP_des_ede_cfb64 +const EVP_CIPHER *EVP_des_ede3_cfb64(void); +# define EVP_des_ede3_cfb EVP_des_ede3_cfb64 +const EVP_CIPHER *EVP_des_ede3_cfb1(void); +const EVP_CIPHER *EVP_des_ede3_cfb8(void); +const EVP_CIPHER *EVP_des_ofb(void); +const EVP_CIPHER *EVP_des_ede_ofb(void); +const EVP_CIPHER *EVP_des_ede3_ofb(void); +const EVP_CIPHER *EVP_des_cbc(void); +const EVP_CIPHER *EVP_des_ede_cbc(void); +const EVP_CIPHER *EVP_des_ede3_cbc(void); +const EVP_CIPHER *EVP_desx_cbc(void); +const EVP_CIPHER *EVP_des_ede3_wrap(void); +/* + * This should now be supported through the dev_crypto ENGINE. But also, why + * are rc4 and md5 declarations made here inside a "NO_DES" precompiler + * branch? + */ +# endif +# ifndef OPENSSL_NO_RC4 +const EVP_CIPHER *EVP_rc4(void); +const EVP_CIPHER *EVP_rc4_40(void); +# ifndef OPENSSL_NO_MD5 +const EVP_CIPHER *EVP_rc4_hmac_md5(void); +# endif +# endif +# ifndef OPENSSL_NO_IDEA +const EVP_CIPHER *EVP_idea_ecb(void); +const EVP_CIPHER *EVP_idea_cfb64(void); +# define EVP_idea_cfb EVP_idea_cfb64 +const EVP_CIPHER *EVP_idea_ofb(void); +const EVP_CIPHER *EVP_idea_cbc(void); +# endif +# ifndef OPENSSL_NO_RC2 +const EVP_CIPHER *EVP_rc2_ecb(void); +const EVP_CIPHER *EVP_rc2_cbc(void); +const EVP_CIPHER *EVP_rc2_40_cbc(void); +const EVP_CIPHER *EVP_rc2_64_cbc(void); +const EVP_CIPHER *EVP_rc2_cfb64(void); +# define EVP_rc2_cfb EVP_rc2_cfb64 +const EVP_CIPHER *EVP_rc2_ofb(void); +# endif +# ifndef OPENSSL_NO_BF +const EVP_CIPHER *EVP_bf_ecb(void); +const EVP_CIPHER *EVP_bf_cbc(void); +const EVP_CIPHER *EVP_bf_cfb64(void); +# define EVP_bf_cfb EVP_bf_cfb64 +const EVP_CIPHER *EVP_bf_ofb(void); +# endif +# ifndef OPENSSL_NO_CAST +const EVP_CIPHER *EVP_cast5_ecb(void); +const EVP_CIPHER *EVP_cast5_cbc(void); +const EVP_CIPHER *EVP_cast5_cfb64(void); +# define EVP_cast5_cfb EVP_cast5_cfb64 +const EVP_CIPHER *EVP_cast5_ofb(void); +# endif +# ifndef OPENSSL_NO_RC5 +const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void); +const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void); +const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void); +# define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64 +const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); +# endif +const EVP_CIPHER *EVP_aes_128_ecb(void); +const EVP_CIPHER *EVP_aes_128_cbc(void); +const EVP_CIPHER *EVP_aes_128_cfb1(void); +const EVP_CIPHER *EVP_aes_128_cfb8(void); +const EVP_CIPHER *EVP_aes_128_cfb128(void); +# define EVP_aes_128_cfb EVP_aes_128_cfb128 +const EVP_CIPHER *EVP_aes_128_ofb(void); +const EVP_CIPHER *EVP_aes_128_ctr(void); +const EVP_CIPHER *EVP_aes_128_ccm(void); +const EVP_CIPHER *EVP_aes_128_gcm(void); +const EVP_CIPHER *EVP_aes_128_xts(void); +const EVP_CIPHER *EVP_aes_128_wrap(void); +const EVP_CIPHER *EVP_aes_128_wrap_pad(void); +# ifndef OPENSSL_NO_OCB +const EVP_CIPHER *EVP_aes_128_ocb(void); +# endif +const EVP_CIPHER *EVP_aes_192_ecb(void); +const EVP_CIPHER *EVP_aes_192_cbc(void); +const EVP_CIPHER *EVP_aes_192_cfb1(void); +const EVP_CIPHER *EVP_aes_192_cfb8(void); +const EVP_CIPHER *EVP_aes_192_cfb128(void); +# define EVP_aes_192_cfb EVP_aes_192_cfb128 +const EVP_CIPHER *EVP_aes_192_ofb(void); +const EVP_CIPHER *EVP_aes_192_ctr(void); +const EVP_CIPHER *EVP_aes_192_ccm(void); +const EVP_CIPHER *EVP_aes_192_gcm(void); +const EVP_CIPHER *EVP_aes_192_wrap(void); +const EVP_CIPHER *EVP_aes_192_wrap_pad(void); +# ifndef OPENSSL_NO_OCB +const EVP_CIPHER *EVP_aes_192_ocb(void); +# endif +const EVP_CIPHER *EVP_aes_256_ecb(void); +const EVP_CIPHER *EVP_aes_256_cbc(void); +const EVP_CIPHER *EVP_aes_256_cfb1(void); +const EVP_CIPHER *EVP_aes_256_cfb8(void); +const EVP_CIPHER *EVP_aes_256_cfb128(void); +# define EVP_aes_256_cfb EVP_aes_256_cfb128 +const EVP_CIPHER *EVP_aes_256_ofb(void); +const EVP_CIPHER *EVP_aes_256_ctr(void); +const EVP_CIPHER *EVP_aes_256_ccm(void); +const EVP_CIPHER *EVP_aes_256_gcm(void); +const EVP_CIPHER *EVP_aes_256_xts(void); +const EVP_CIPHER *EVP_aes_256_wrap(void); +const EVP_CIPHER *EVP_aes_256_wrap_pad(void); +# ifndef OPENSSL_NO_OCB +const EVP_CIPHER *EVP_aes_256_ocb(void); +# endif +const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void); +const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha1(void); +const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha256(void); +const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha256(void); +# ifndef OPENSSL_NO_CAMELLIA +const EVP_CIPHER *EVP_camellia_128_ecb(void); +const EVP_CIPHER *EVP_camellia_128_cbc(void); +const EVP_CIPHER *EVP_camellia_128_cfb1(void); +const EVP_CIPHER *EVP_camellia_128_cfb8(void); +const EVP_CIPHER *EVP_camellia_128_cfb128(void); +# define EVP_camellia_128_cfb EVP_camellia_128_cfb128 +const EVP_CIPHER *EVP_camellia_128_ofb(void); +const EVP_CIPHER *EVP_camellia_128_ctr(void); +const EVP_CIPHER *EVP_camellia_192_ecb(void); +const EVP_CIPHER *EVP_camellia_192_cbc(void); +const EVP_CIPHER *EVP_camellia_192_cfb1(void); +const EVP_CIPHER *EVP_camellia_192_cfb8(void); +const EVP_CIPHER *EVP_camellia_192_cfb128(void); +# define EVP_camellia_192_cfb EVP_camellia_192_cfb128 +const EVP_CIPHER *EVP_camellia_192_ofb(void); +const EVP_CIPHER *EVP_camellia_192_ctr(void); +const EVP_CIPHER *EVP_camellia_256_ecb(void); +const EVP_CIPHER *EVP_camellia_256_cbc(void); +const EVP_CIPHER *EVP_camellia_256_cfb1(void); +const EVP_CIPHER *EVP_camellia_256_cfb8(void); +const EVP_CIPHER *EVP_camellia_256_cfb128(void); +# define EVP_camellia_256_cfb EVP_camellia_256_cfb128 +const EVP_CIPHER *EVP_camellia_256_ofb(void); +const EVP_CIPHER *EVP_camellia_256_ctr(void); +# endif +# ifndef OPENSSL_NO_CHACHA +const EVP_CIPHER *EVP_chacha20(void); +# ifndef OPENSSL_NO_POLY1305 +const EVP_CIPHER *EVP_chacha20_poly1305(void); +# endif +# endif + +# ifndef OPENSSL_NO_SEED +const EVP_CIPHER *EVP_seed_ecb(void); +const EVP_CIPHER *EVP_seed_cbc(void); +const EVP_CIPHER *EVP_seed_cfb128(void); +# define EVP_seed_cfb EVP_seed_cfb128 +const EVP_CIPHER *EVP_seed_ofb(void); +# endif + +# if OPENSSL_API_COMPAT < 0x10100000L +# define OPENSSL_add_all_algorithms_conf() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ + | OPENSSL_INIT_ADD_ALL_DIGESTS \ + | OPENSSL_INIT_LOAD_CONFIG, NULL) +# define OPENSSL_add_all_algorithms_noconf() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ + | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL) + +# ifdef OPENSSL_LOAD_CONF +# define OpenSSL_add_all_algorithms() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ + | OPENSSL_INIT_ADD_ALL_DIGESTS \ + | OPENSSL_INIT_LOAD_CONFIG, NULL) +# else +# define OpenSSL_add_all_algorithms() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ + | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL) +# endif + +# define OpenSSL_add_all_ciphers() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL) +# define OpenSSL_add_all_digests() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL) + +# define EVP_cleanup() while(0) continue +# endif + +int EVP_add_cipher(const EVP_CIPHER *cipher); +int EVP_add_digest(const EVP_MD *digest); + +const EVP_CIPHER *EVP_get_cipherbyname(const char *name); +const EVP_MD *EVP_get_digestbyname(const char *name); + +void EVP_CIPHER_do_all(void (*fn) (const EVP_CIPHER *ciph, + const char *from, const char *to, void *x), + void *arg); +void EVP_CIPHER_do_all_sorted(void (*fn) + (const EVP_CIPHER *ciph, const char *from, + const char *to, void *x), void *arg); + +void EVP_MD_do_all(void (*fn) (const EVP_MD *ciph, + const char *from, const char *to, void *x), + void *arg); +void EVP_MD_do_all_sorted(void (*fn) + (const EVP_MD *ciph, const char *from, + const char *to, void *x), void *arg); + +int EVP_PKEY_decrypt_old(unsigned char *dec_key, + const unsigned char *enc_key, int enc_key_len, + EVP_PKEY *private_key); +int EVP_PKEY_encrypt_old(unsigned char *enc_key, + const unsigned char *key, int key_len, + EVP_PKEY *pub_key); +int EVP_PKEY_type(int type); +int EVP_PKEY_id(const EVP_PKEY *pkey); +int EVP_PKEY_base_id(const EVP_PKEY *pkey); +int EVP_PKEY_bits(const EVP_PKEY *pkey); +int EVP_PKEY_security_bits(const EVP_PKEY *pkey); +int EVP_PKEY_size(EVP_PKEY *pkey); +int EVP_PKEY_set_type(EVP_PKEY *pkey, int type); +int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len); +int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key); +void *EVP_PKEY_get0(const EVP_PKEY *pkey); +const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len); + +# ifndef OPENSSL_NO_RSA +struct rsa_st; +int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key); +struct rsa_st *EVP_PKEY_get0_RSA(EVP_PKEY *pkey); +struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); +# endif +# ifndef OPENSSL_NO_DSA +struct dsa_st; +int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key); +struct dsa_st *EVP_PKEY_get0_DSA(EVP_PKEY *pkey); +struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); +# endif +# ifndef OPENSSL_NO_DH +struct dh_st; +int EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key); +struct dh_st *EVP_PKEY_get0_DH(EVP_PKEY *pkey); +struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey); +# endif +# ifndef OPENSSL_NO_EC +struct ec_key_st; +int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); +struct ec_key_st *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey); +struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); +# endif + +EVP_PKEY *EVP_PKEY_new(void); +int EVP_PKEY_up_ref(EVP_PKEY *pkey); +void EVP_PKEY_free(EVP_PKEY *pkey); + +EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, + long length); +int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp); + +EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, + long length); +EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, + long length); +int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); + +int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); +int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); +int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode); +int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b); + +int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b); + +int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, + int indent, ASN1_PCTX *pctx); +int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, + int indent, ASN1_PCTX *pctx); +int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, + int indent, ASN1_PCTX *pctx); + +int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid); + +int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey, + const unsigned char *pt, size_t ptlen); +size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt); + +int EVP_CIPHER_type(const EVP_CIPHER *ctx); + +/* calls methods */ +int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); +int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); + +/* These are used by EVP_CIPHER methods */ +int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); +int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); + +/* PKCS5 password based encryption */ +int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, + const EVP_MD *md, int en_de); +int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, + const unsigned char *salt, int saltlen, int iter, + int keylen, unsigned char *out); +int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, + const unsigned char *salt, int saltlen, int iter, + const EVP_MD *digest, int keylen, unsigned char *out); +int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, + const EVP_MD *md, int en_de); + +#ifndef OPENSSL_NO_SCRYPT +int EVP_PBE_scrypt(const char *pass, size_t passlen, + const unsigned char *salt, size_t saltlen, + uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, + unsigned char *key, size_t keylen); + +int PKCS5_v2_scrypt_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, + int passlen, ASN1_TYPE *param, + const EVP_CIPHER *c, const EVP_MD *md, int en_de); +#endif + +void PKCS5_PBE_add(void); + +int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de); + +/* PBE type */ + +/* Can appear as the outermost AlgorithmIdentifier */ +# define EVP_PBE_TYPE_OUTER 0x0 +/* Is an PRF type OID */ +# define EVP_PBE_TYPE_PRF 0x1 +/* Is a PKCS#5 v2.0 KDF */ +# define EVP_PBE_TYPE_KDF 0x2 + +int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, + int md_nid, EVP_PBE_KEYGEN *keygen); +int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md, + EVP_PBE_KEYGEN *keygen); +int EVP_PBE_find(int type, int pbe_nid, int *pcnid, int *pmnid, + EVP_PBE_KEYGEN **pkeygen); +void EVP_PBE_cleanup(void); +int EVP_PBE_get(int *ptype, int *ppbe_nid, size_t num); + +# define ASN1_PKEY_ALIAS 0x1 +# define ASN1_PKEY_DYNAMIC 0x2 +# define ASN1_PKEY_SIGPARAM_NULL 0x4 + +# define ASN1_PKEY_CTRL_PKCS7_SIGN 0x1 +# define ASN1_PKEY_CTRL_PKCS7_ENCRYPT 0x2 +# define ASN1_PKEY_CTRL_DEFAULT_MD_NID 0x3 +# define ASN1_PKEY_CTRL_CMS_SIGN 0x5 +# define ASN1_PKEY_CTRL_CMS_ENVELOPE 0x7 +# define ASN1_PKEY_CTRL_CMS_RI_TYPE 0x8 + +# define ASN1_PKEY_CTRL_SET1_TLS_ENCPT 0x9 +# define ASN1_PKEY_CTRL_GET1_TLS_ENCPT 0xa + +int EVP_PKEY_asn1_get_count(void); +const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx); +const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type); +const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, + const char *str, int len); +int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth); +int EVP_PKEY_asn1_add_alias(int to, int from); +int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id, + int *ppkey_flags, const char **pinfo, + const char **ppem_str, + const EVP_PKEY_ASN1_METHOD *ameth); + +const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(const EVP_PKEY *pkey); +EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags, + const char *pem_str, + const char *info); +void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, + const EVP_PKEY_ASN1_METHOD *src); +void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth); +void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, + int (*pub_decode) (EVP_PKEY *pk, + X509_PUBKEY *pub), + int (*pub_encode) (X509_PUBKEY *pub, + const EVP_PKEY *pk), + int (*pub_cmp) (const EVP_PKEY *a, + const EVP_PKEY *b), + int (*pub_print) (BIO *out, + const EVP_PKEY *pkey, + int indent, ASN1_PCTX *pctx), + int (*pkey_size) (const EVP_PKEY *pk), + int (*pkey_bits) (const EVP_PKEY *pk)); +void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, + int (*priv_decode) (EVP_PKEY *pk, + const PKCS8_PRIV_KEY_INFO + *p8inf), + int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, + const EVP_PKEY *pk), + int (*priv_print) (BIO *out, + const EVP_PKEY *pkey, + int indent, + ASN1_PCTX *pctx)); +void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, + int (*param_decode) (EVP_PKEY *pkey, + const unsigned char **pder, + int derlen), + int (*param_encode) (const EVP_PKEY *pkey, + unsigned char **pder), + int (*param_missing) (const EVP_PKEY *pk), + int (*param_copy) (EVP_PKEY *to, + const EVP_PKEY *from), + int (*param_cmp) (const EVP_PKEY *a, + const EVP_PKEY *b), + int (*param_print) (BIO *out, + const EVP_PKEY *pkey, + int indent, + ASN1_PCTX *pctx)); + +void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, + void (*pkey_free) (EVP_PKEY *pkey)); +void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, + int (*pkey_ctrl) (EVP_PKEY *pkey, int op, + long arg1, void *arg2)); +void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth, + int (*item_verify) (EVP_MD_CTX *ctx, + const ASN1_ITEM *it, + void *asn, + X509_ALGOR *a, + ASN1_BIT_STRING *sig, + EVP_PKEY *pkey), + int (*item_sign) (EVP_MD_CTX *ctx, + const ASN1_ITEM *it, + void *asn, + X509_ALGOR *alg1, + X509_ALGOR *alg2, + ASN1_BIT_STRING *sig)); + +void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth, + int (*pkey_security_bits) (const EVP_PKEY + *pk)); + +# define EVP_PKEY_OP_UNDEFINED 0 +# define EVP_PKEY_OP_PARAMGEN (1<<1) +# define EVP_PKEY_OP_KEYGEN (1<<2) +# define EVP_PKEY_OP_SIGN (1<<3) +# define EVP_PKEY_OP_VERIFY (1<<4) +# define EVP_PKEY_OP_VERIFYRECOVER (1<<5) +# define EVP_PKEY_OP_SIGNCTX (1<<6) +# define EVP_PKEY_OP_VERIFYCTX (1<<7) +# define EVP_PKEY_OP_ENCRYPT (1<<8) +# define EVP_PKEY_OP_DECRYPT (1<<9) +# define EVP_PKEY_OP_DERIVE (1<<10) + +# define EVP_PKEY_OP_TYPE_SIG \ + (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY | EVP_PKEY_OP_VERIFYRECOVER \ + | EVP_PKEY_OP_SIGNCTX | EVP_PKEY_OP_VERIFYCTX) + +# define EVP_PKEY_OP_TYPE_CRYPT \ + (EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT) + +# define EVP_PKEY_OP_TYPE_NOGEN \ + (EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_DERIVE) + +# define EVP_PKEY_OP_TYPE_GEN \ + (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN) + +# define EVP_PKEY_CTX_set_signature_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, \ + EVP_PKEY_CTRL_MD, 0, (void *)md) + +# define EVP_PKEY_CTX_get_signature_md(ctx, pmd) \ + EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, \ + EVP_PKEY_CTRL_GET_MD, 0, (void *)pmd) + +# define EVP_PKEY_CTX_set_mac_key(ctx, key, len) \ + EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_SET_MAC_KEY, len, (void *)key) + +# define EVP_PKEY_CTRL_MD 1 +# define EVP_PKEY_CTRL_PEER_KEY 2 + +# define EVP_PKEY_CTRL_PKCS7_ENCRYPT 3 +# define EVP_PKEY_CTRL_PKCS7_DECRYPT 4 + +# define EVP_PKEY_CTRL_PKCS7_SIGN 5 + +# define EVP_PKEY_CTRL_SET_MAC_KEY 6 + +# define EVP_PKEY_CTRL_DIGESTINIT 7 + +/* Used by GOST key encryption in TLS */ +# define EVP_PKEY_CTRL_SET_IV 8 + +# define EVP_PKEY_CTRL_CMS_ENCRYPT 9 +# define EVP_PKEY_CTRL_CMS_DECRYPT 10 +# define EVP_PKEY_CTRL_CMS_SIGN 11 + +# define EVP_PKEY_CTRL_CIPHER 12 + +# define EVP_PKEY_CTRL_GET_MD 13 + +# define EVP_PKEY_ALG_CTRL 0x1000 + +# define EVP_PKEY_FLAG_AUTOARGLEN 2 +/* + * Method handles all operations: don't assume any digest related defaults. + */ +# define EVP_PKEY_FLAG_SIGCTX_CUSTOM 4 + +const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type); +EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags); +void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, + const EVP_PKEY_METHOD *meth); +void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src); +void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth); +int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth); + +EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); +EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e); +EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx); +void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); + +int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, + int cmd, int p1, void *p2); +int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, + const char *value); + +int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str); +int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex); + +int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx); +void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen); + +EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, + const unsigned char *key, int keylen); + +void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data); +void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx); +EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx); + +EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx); + +void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data); +void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx); + +int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, + unsigned char *sig, size_t *siglen, + const unsigned char *tbs, size_t tbslen); +int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, + const unsigned char *sig, size_t siglen, + const unsigned char *tbs, size_t tbslen); +int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, + unsigned char *rout, size_t *routlen, + const unsigned char *sig, size_t siglen); +int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, + unsigned char *out, size_t *outlen, + const unsigned char *in, size_t inlen); +int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, + unsigned char *out, size_t *outlen, + const unsigned char *in, size_t inlen); + +int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); +int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen); + +typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx); + +int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); +int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); + +void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb); +EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx); + +int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx); + +void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth, + int (*init) (EVP_PKEY_CTX *ctx)); + +void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth, + int (*copy) (EVP_PKEY_CTX *dst, + EVP_PKEY_CTX *src)); + +void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth, + void (*cleanup) (EVP_PKEY_CTX *ctx)); + +void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth, + int (*paramgen_init) (EVP_PKEY_CTX *ctx), + int (*paramgen) (EVP_PKEY_CTX *ctx, + EVP_PKEY *pkey)); + +void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth, + int (*keygen_init) (EVP_PKEY_CTX *ctx), + int (*keygen) (EVP_PKEY_CTX *ctx, + EVP_PKEY *pkey)); + +void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth, + int (*sign_init) (EVP_PKEY_CTX *ctx), + int (*sign) (EVP_PKEY_CTX *ctx, + unsigned char *sig, size_t *siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth, + int (*verify_init) (EVP_PKEY_CTX *ctx), + int (*verify) (EVP_PKEY_CTX *ctx, + const unsigned char *sig, + size_t siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth, + int (*verify_recover_init) (EVP_PKEY_CTX + *ctx), + int (*verify_recover) (EVP_PKEY_CTX + *ctx, + unsigned char + *sig, + size_t *siglen, + const unsigned + char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth, + int (*signctx_init) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx), + int (*signctx) (EVP_PKEY_CTX *ctx, + unsigned char *sig, + size_t *siglen, + EVP_MD_CTX *mctx)); + +void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth, + int (*verifyctx_init) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx), + int (*verifyctx) (EVP_PKEY_CTX *ctx, + const unsigned char *sig, + int siglen, + EVP_MD_CTX *mctx)); + +void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth, + int (*encrypt_init) (EVP_PKEY_CTX *ctx), + int (*encryptfn) (EVP_PKEY_CTX *ctx, + unsigned char *out, + size_t *outlen, + const unsigned char *in, + size_t inlen)); + +void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth, + int (*decrypt_init) (EVP_PKEY_CTX *ctx), + int (*decrypt) (EVP_PKEY_CTX *ctx, + unsigned char *out, + size_t *outlen, + const unsigned char *in, + size_t inlen)); + +void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth, + int (*derive_init) (EVP_PKEY_CTX *ctx), + int (*derive) (EVP_PKEY_CTX *ctx, + unsigned char *key, + size_t *keylen)); + +void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth, + int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, + void *p2), + int (*ctrl_str) (EVP_PKEY_CTX *ctx, + const char *type, + const char *value)); + +void EVP_PKEY_meth_get_init(EVP_PKEY_METHOD *pmeth, + int (**pinit) (EVP_PKEY_CTX *ctx)); + +void EVP_PKEY_meth_get_copy(EVP_PKEY_METHOD *pmeth, + int (**pcopy) (EVP_PKEY_CTX *dst, + EVP_PKEY_CTX *src)); + +void EVP_PKEY_meth_get_cleanup(EVP_PKEY_METHOD *pmeth, + void (**pcleanup) (EVP_PKEY_CTX *ctx)); + +void EVP_PKEY_meth_get_paramgen(EVP_PKEY_METHOD *pmeth, + int (**pparamgen_init) (EVP_PKEY_CTX *ctx), + int (**pparamgen) (EVP_PKEY_CTX *ctx, + EVP_PKEY *pkey)); + +void EVP_PKEY_meth_get_keygen(EVP_PKEY_METHOD *pmeth, + int (**pkeygen_init) (EVP_PKEY_CTX *ctx), + int (**pkeygen) (EVP_PKEY_CTX *ctx, + EVP_PKEY *pkey)); + +void EVP_PKEY_meth_get_sign(EVP_PKEY_METHOD *pmeth, + int (**psign_init) (EVP_PKEY_CTX *ctx), + int (**psign) (EVP_PKEY_CTX *ctx, + unsigned char *sig, size_t *siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_get_verify(EVP_PKEY_METHOD *pmeth, + int (**pverify_init) (EVP_PKEY_CTX *ctx), + int (**pverify) (EVP_PKEY_CTX *ctx, + const unsigned char *sig, + size_t siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_get_verify_recover(EVP_PKEY_METHOD *pmeth, + int (**pverify_recover_init) (EVP_PKEY_CTX + *ctx), + int (**pverify_recover) (EVP_PKEY_CTX + *ctx, + unsigned char + *sig, + size_t *siglen, + const unsigned + char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_get_signctx(EVP_PKEY_METHOD *pmeth, + int (**psignctx_init) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx), + int (**psignctx) (EVP_PKEY_CTX *ctx, + unsigned char *sig, + size_t *siglen, + EVP_MD_CTX *mctx)); + +void EVP_PKEY_meth_get_verifyctx(EVP_PKEY_METHOD *pmeth, + int (**pverifyctx_init) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx), + int (**pverifyctx) (EVP_PKEY_CTX *ctx, + const unsigned char *sig, + int siglen, + EVP_MD_CTX *mctx)); + +void EVP_PKEY_meth_get_encrypt(EVP_PKEY_METHOD *pmeth, + int (**pencrypt_init) (EVP_PKEY_CTX *ctx), + int (**pencryptfn) (EVP_PKEY_CTX *ctx, + unsigned char *out, + size_t *outlen, + const unsigned char *in, + size_t inlen)); + +void EVP_PKEY_meth_get_decrypt(EVP_PKEY_METHOD *pmeth, + int (**pdecrypt_init) (EVP_PKEY_CTX *ctx), + int (**pdecrypt) (EVP_PKEY_CTX *ctx, + unsigned char *out, + size_t *outlen, + const unsigned char *in, + size_t inlen)); + +void EVP_PKEY_meth_get_derive(EVP_PKEY_METHOD *pmeth, + int (**pderive_init) (EVP_PKEY_CTX *ctx), + int (**pderive) (EVP_PKEY_CTX *ctx, + unsigned char *key, + size_t *keylen)); + +void EVP_PKEY_meth_get_ctrl(EVP_PKEY_METHOD *pmeth, + int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1, + void *p2), + int (**pctrl_str) (EVP_PKEY_CTX *ctx, + const char *type, + const char *value)); + +void EVP_add_alg_module(void); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_EVP_strings(void); + +/* Error codes for the EVP functions. */ + +/* Function codes. */ +# define EVP_F_AESNI_INIT_KEY 165 +# define EVP_F_AES_INIT_KEY 133 +# define EVP_F_AES_T4_INIT_KEY 178 +# define EVP_F_ALG_MODULE_INIT 177 +# define EVP_F_CAMELLIA_INIT_KEY 159 +# define EVP_F_CHACHA20_POLY1305_CTRL 182 +# define EVP_F_CMLL_T4_INIT_KEY 179 +# define EVP_F_DO_SIGVER_INIT 161 +# define EVP_F_EVP_CIPHERINIT_EX 123 +# define EVP_F_EVP_CIPHER_CTX_COPY 163 +# define EVP_F_EVP_CIPHER_CTX_CTRL 124 +# define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122 +# define EVP_F_EVP_DECRYPTFINAL_EX 101 +# define EVP_F_EVP_DECRYPTUPDATE 166 +# define EVP_F_EVP_DIGESTINIT_EX 128 +# define EVP_F_EVP_ENCRYPTFINAL_EX 127 +# define EVP_F_EVP_ENCRYPTUPDATE 167 +# define EVP_F_EVP_MD_CTX_COPY_EX 110 +# define EVP_F_EVP_MD_SIZE 162 +# define EVP_F_EVP_OPENINIT 102 +# define EVP_F_EVP_PBE_ALG_ADD 115 +# define EVP_F_EVP_PBE_ALG_ADD_TYPE 160 +# define EVP_F_EVP_PBE_CIPHERINIT 116 +# define EVP_F_EVP_PBE_SCRYPT 181 +# define EVP_F_EVP_PKCS82PKEY 111 +# define EVP_F_EVP_PKEY2PKCS8 113 +# define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 +# define EVP_F_EVP_PKEY_CTX_CTRL 137 +# define EVP_F_EVP_PKEY_CTX_CTRL_STR 150 +# define EVP_F_EVP_PKEY_CTX_DUP 156 +# define EVP_F_EVP_PKEY_DECRYPT 104 +# define EVP_F_EVP_PKEY_DECRYPT_INIT 138 +# define EVP_F_EVP_PKEY_DECRYPT_OLD 151 +# define EVP_F_EVP_PKEY_DERIVE 153 +# define EVP_F_EVP_PKEY_DERIVE_INIT 154 +# define EVP_F_EVP_PKEY_DERIVE_SET_PEER 155 +# define EVP_F_EVP_PKEY_ENCRYPT 105 +# define EVP_F_EVP_PKEY_ENCRYPT_INIT 139 +# define EVP_F_EVP_PKEY_ENCRYPT_OLD 152 +# define EVP_F_EVP_PKEY_GET0_DH 119 +# define EVP_F_EVP_PKEY_GET0_DSA 120 +# define EVP_F_EVP_PKEY_GET0_EC_KEY 131 +# define EVP_F_EVP_PKEY_GET0_HMAC 183 +# define EVP_F_EVP_PKEY_GET0_RSA 121 +# define EVP_F_EVP_PKEY_KEYGEN 146 +# define EVP_F_EVP_PKEY_KEYGEN_INIT 147 +# define EVP_F_EVP_PKEY_NEW 106 +# define EVP_F_EVP_PKEY_PARAMGEN 148 +# define EVP_F_EVP_PKEY_PARAMGEN_INIT 149 +# define EVP_F_EVP_PKEY_SIGN 140 +# define EVP_F_EVP_PKEY_SIGN_INIT 141 +# define EVP_F_EVP_PKEY_VERIFY 142 +# define EVP_F_EVP_PKEY_VERIFY_INIT 143 +# define EVP_F_EVP_PKEY_VERIFY_RECOVER 144 +# define EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT 145 +# define EVP_F_EVP_SIGNFINAL 107 +# define EVP_F_EVP_VERIFYFINAL 108 +# define EVP_F_INT_CTX_NEW 157 +# define EVP_F_PKCS5_PBE_KEYIVGEN 117 +# define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118 +# define EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN 164 +# define EVP_F_PKCS5_V2_SCRYPT_KEYIVGEN 180 +# define EVP_F_PKEY_SET_TYPE 158 +# define EVP_F_RC2_MAGIC_TO_METH 109 +# define EVP_F_RC5_CTRL 125 + +/* Reason codes. */ +# define EVP_R_AES_KEY_SETUP_FAILED 143 +# define EVP_R_BAD_DECRYPT 100 +# define EVP_R_BUFFER_TOO_SMALL 155 +# define EVP_R_CAMELLIA_KEY_SETUP_FAILED 157 +# define EVP_R_CIPHER_PARAMETER_ERROR 122 +# define EVP_R_COMMAND_NOT_SUPPORTED 147 +# define EVP_R_COPY_ERROR 173 +# define EVP_R_CTRL_NOT_IMPLEMENTED 132 +# define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133 +# define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138 +# define EVP_R_DECODE_ERROR 114 +# define EVP_R_DIFFERENT_KEY_TYPES 101 +# define EVP_R_DIFFERENT_PARAMETERS 153 +# define EVP_R_ERROR_LOADING_SECTION 165 +# define EVP_R_ERROR_SETTING_FIPS_MODE 166 +# define EVP_R_EXPECTING_AN_HMAC_KEY 174 +# define EVP_R_EXPECTING_AN_RSA_KEY 127 +# define EVP_R_EXPECTING_A_DH_KEY 128 +# define EVP_R_EXPECTING_A_DSA_KEY 129 +# define EVP_R_EXPECTING_A_EC_KEY 142 +# define EVP_R_FIPS_MODE_NOT_SUPPORTED 167 +# define EVP_R_ILLEGAL_SCRYPT_PARAMETERS 171 +# define EVP_R_INITIALIZATION_ERROR 134 +# define EVP_R_INPUT_NOT_INITIALIZED 111 +# define EVP_R_INVALID_DIGEST 152 +# define EVP_R_INVALID_FIPS_MODE 168 +# define EVP_R_INVALID_KEY_LENGTH 130 +# define EVP_R_INVALID_OPERATION 148 +# define EVP_R_KEYGEN_FAILURE 120 +# define EVP_R_MEMORY_LIMIT_EXCEEDED 172 +# define EVP_R_MESSAGE_DIGEST_IS_NULL 159 +# define EVP_R_METHOD_NOT_SUPPORTED 144 +# define EVP_R_MISSING_PARAMETERS 103 +# define EVP_R_NO_CIPHER_SET 131 +# define EVP_R_NO_DEFAULT_DIGEST 158 +# define EVP_R_NO_DIGEST_SET 139 +# define EVP_R_NO_KEY_SET 154 +# define EVP_R_NO_OPERATION_SET 149 +# define EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 150 +# define EVP_R_OPERATON_NOT_INITIALIZED 151 +# define EVP_R_PARTIALLY_OVERLAPPING 162 +# define EVP_R_PRIVATE_KEY_DECODE_ERROR 145 +# define EVP_R_PRIVATE_KEY_ENCODE_ERROR 146 +# define EVP_R_PUBLIC_KEY_NOT_RSA 106 +# define EVP_R_UNKNOWN_CIPHER 160 +# define EVP_R_UNKNOWN_DIGEST 161 +# define EVP_R_UNKNOWN_OPTION 169 +# define EVP_R_UNKNOWN_PBE_ALGORITHM 121 +# define EVP_R_UNSUPPORTED_NUMBER_OF_ROUNDS 135 +# define EVP_R_UNSUPPORTED_ALGORITHM 156 +# define EVP_R_UNSUPPORTED_CIPHER 107 +# define EVP_R_UNSUPPORTED_KEYLENGTH 123 +# define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124 +# define EVP_R_UNSUPPORTED_KEY_SIZE 108 +# define EVP_R_UNSUPPORTED_PRF 125 +# define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118 +# define EVP_R_UNSUPPORTED_SALT_TYPE 126 +# define EVP_R_WRAP_MODE_NOT_ALLOWED 170 +# define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/hmac.h b/android/x86/include/openssl/hmac.h new file mode 100644 index 00000000..9f068960 --- /dev/null +++ b/android/x86/include/openssl/hmac.h @@ -0,0 +1,49 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_HMAC_H +# define HEADER_HMAC_H + +# include <openssl/opensslconf.h> + +# include <openssl/evp.h> + +# define HMAC_MAX_MD_CBLOCK 128/* largest known is SHA512 */ + +#ifdef __cplusplus +extern "C" { +#endif + +size_t HMAC_size(const HMAC_CTX *e); +HMAC_CTX *HMAC_CTX_new(void); +int HMAC_CTX_reset(HMAC_CTX *ctx); +void HMAC_CTX_free(HMAC_CTX *ctx); + +DEPRECATEDIN_1_1_0(__owur int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, + const EVP_MD *md)) + +/*__owur*/ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, + const EVP_MD *md, ENGINE *impl); +/*__owur*/ int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, + size_t len); +/*__owur*/ int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, + unsigned int *len); +unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, + const unsigned char *d, size_t n, unsigned char *md, + unsigned int *md_len); +__owur int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); + +void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); +const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/android/x86/include/openssl/idea.h b/android/x86/include/openssl/idea.h new file mode 100644 index 00000000..4334f3ea --- /dev/null +++ b/android/x86/include/openssl/idea.h @@ -0,0 +1,64 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_IDEA_H +# define HEADER_IDEA_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_IDEA +# ifdef __cplusplus +extern "C" { +# endif + +typedef unsigned int IDEA_INT; + +# define IDEA_ENCRYPT 1 +# define IDEA_DECRYPT 0 + +# define IDEA_BLOCK 8 +# define IDEA_KEY_LENGTH 16 + +typedef struct idea_key_st { + IDEA_INT data[9][6]; +} IDEA_KEY_SCHEDULE; + +const char *IDEA_options(void); +void IDEA_ecb_encrypt(const unsigned char *in, unsigned char *out, + IDEA_KEY_SCHEDULE *ks); +void IDEA_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); +void IDEA_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk); +void IDEA_cbc_encrypt(const unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, + int enc); +void IDEA_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, + int *num, int enc); +void IDEA_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, + int *num); +void IDEA_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define idea_options IDEA_options +# define idea_ecb_encrypt IDEA_ecb_encrypt +# define idea_set_encrypt_key IDEA_set_encrypt_key +# define idea_set_decrypt_key IDEA_set_decrypt_key +# define idea_cbc_encrypt IDEA_cbc_encrypt +# define idea_cfb64_encrypt IDEA_cfb64_encrypt +# define idea_ofb64_encrypt IDEA_ofb64_encrypt +# define idea_encrypt IDEA_encrypt +# endif + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/kdf.h b/android/x86/include/openssl/kdf.h new file mode 100644 index 00000000..9f87f788 --- /dev/null +++ b/android/x86/include/openssl/kdf.h @@ -0,0 +1,75 @@ +/* + * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_KDF_H +# define HEADER_KDF_H + +#ifdef __cplusplus +extern "C" { +#endif + +# define EVP_PKEY_CTRL_TLS_MD (EVP_PKEY_ALG_CTRL) +# define EVP_PKEY_CTRL_TLS_SECRET (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_TLS_SEED (EVP_PKEY_ALG_CTRL + 2) +# define EVP_PKEY_CTRL_HKDF_MD (EVP_PKEY_ALG_CTRL + 3) +# define EVP_PKEY_CTRL_HKDF_SALT (EVP_PKEY_ALG_CTRL + 4) +# define EVP_PKEY_CTRL_HKDF_KEY (EVP_PKEY_ALG_CTRL + 5) +# define EVP_PKEY_CTRL_HKDF_INFO (EVP_PKEY_ALG_CTRL + 6) + +# define EVP_PKEY_CTX_set_tls1_prf_md(pctx, md) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_TLS_MD, 0, (void *)md) + +# define EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, sec, seclen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_TLS_SECRET, seclen, (void *)sec) + +# define EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed, seedlen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_TLS_SEED, seedlen, (void *)seed) + +# define EVP_PKEY_CTX_set_hkdf_md(pctx, md) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_HKDF_MD, 0, (void *)md) + +# define EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, saltlen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_HKDF_SALT, saltlen, (void *)salt) + +# define EVP_PKEY_CTX_set1_hkdf_key(pctx, key, keylen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_HKDF_KEY, keylen, (void *)key) + +# define EVP_PKEY_CTX_add1_hkdf_info(pctx, info, infolen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_HKDF_INFO, infolen, (void *)info) + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_KDF_strings(void); + +/* Error codes for the KDF functions. */ + +/* Function codes. */ +# define KDF_F_PKEY_TLS1_PRF_CTRL_STR 100 +# define KDF_F_PKEY_TLS1_PRF_DERIVE 101 + +/* Reason codes. */ +# define KDF_R_INVALID_DIGEST 100 +# define KDF_R_MISSING_PARAMETER 101 +# define KDF_R_VALUE_MISSING 102 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/lhash.h b/android/x86/include/openssl/lhash.h new file mode 100644 index 00000000..e2ccb65d --- /dev/null +++ b/android/x86/include/openssl/lhash.h @@ -0,0 +1,204 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * Header for dynamic hash table routines Author - Eric Young + */ + +#ifndef HEADER_LHASH_H +# define HEADER_LHASH_H + +# include <openssl/e_os2.h> +# include <openssl/bio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct lhash_node_st OPENSSL_LH_NODE; +typedef int (*OPENSSL_LH_COMPFUNC) (const void *, const void *); +typedef unsigned long (*OPENSSL_LH_HASHFUNC) (const void *); +typedef void (*OPENSSL_LH_DOALL_FUNC) (void *); +typedef void (*OPENSSL_LH_DOALL_FUNCARG) (void *, void *); +typedef struct lhash_st OPENSSL_LHASH; + +/* + * Macros for declaring and implementing type-safe wrappers for LHASH + * callbacks. This way, callbacks can be provided to LHASH structures without + * function pointer casting and the macro-defined callbacks provide + * per-variable casting before deferring to the underlying type-specific + * callbacks. NB: It is possible to place a "static" in front of both the + * DECLARE and IMPLEMENT macros if the functions are strictly internal. + */ + +/* First: "hash" functions */ +# define DECLARE_LHASH_HASH_FN(name, o_type) \ + unsigned long name##_LHASH_HASH(const void *); +# define IMPLEMENT_LHASH_HASH_FN(name, o_type) \ + unsigned long name##_LHASH_HASH(const void *arg) { \ + const o_type *a = arg; \ + return name##_hash(a); } +# define LHASH_HASH_FN(name) name##_LHASH_HASH + +/* Second: "compare" functions */ +# define DECLARE_LHASH_COMP_FN(name, o_type) \ + int name##_LHASH_COMP(const void *, const void *); +# define IMPLEMENT_LHASH_COMP_FN(name, o_type) \ + int name##_LHASH_COMP(const void *arg1, const void *arg2) { \ + const o_type *a = arg1; \ + const o_type *b = arg2; \ + return name##_cmp(a,b); } +# define LHASH_COMP_FN(name) name##_LHASH_COMP + +/* Fourth: "doall_arg" functions */ +# define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ + void name##_LHASH_DOALL_ARG(void *, void *); +# define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ + void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \ + o_type *a = arg1; \ + a_type *b = arg2; \ + name##_doall_arg(a, b); } +# define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG + + +# define LH_LOAD_MULT 256 + +int OPENSSL_LH_error(OPENSSL_LHASH *lh); +OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c); +void OPENSSL_LH_free(OPENSSL_LHASH *lh); +void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data); +void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data); +void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data); +void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func); +void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg); +unsigned long OPENSSL_LH_strhash(const char *c); +unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh); +unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh); +void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load); + +# ifndef OPENSSL_NO_STDIO +void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp); +void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp); +void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp); +# endif +void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out); +void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out); +void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define _LHASH OPENSSL_LHASH +# define LHASH_NODE OPENSSL_LH_NODE +# define lh_error OPENSSL_LH_error +# define lh_new OPENSSL_lh_new +# define lh_free OPENSSL_LH_free +# define lh_insert OPENSSL_LH_insert +# define lh_delete OPENSSL_LH_delete +# define lh_retrieve OPENSSL_LH_retrieve +# define lh_doall OPENSSL_LH_doall +# define lh_doall_arg OPENSSL_LH_doall_arg +# define lh_strhash OPENSSL_LH_strhash +# define lh_num_items OPENSSL_LH_num_items +# ifndef OPENSSL_NO_STDIO +# define lh_stats OPENSSL_LH_stats +# define lh_node_stats OPENSSL_LH_node_stats +# define lh_node_usage_stats OPENSSL_LH_node_usage_stats +# endif +# define lh_stats_bio OPENSSL_LH_stats_bio +# define lh_node_stats_bio OPENSSL_LH_node_stats_bio +# define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio +# endif + +/* Type checking... */ + +# define LHASH_OF(type) struct lhash_st_##type + +# define DEFINE_LHASH_OF(type) \ + LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \ + static ossl_inline LHASH_OF(type) * \ + lh_##type##_new(unsigned long (*hfn)(const type *), \ + int (*cfn)(const type *, const type *)) \ + { \ + return (LHASH_OF(type) *) \ + OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn); \ + } \ + static ossl_inline void lh_##type##_free(LHASH_OF(type) *lh) \ + { \ + OPENSSL_LH_free((OPENSSL_LHASH *)lh); \ + } \ + static ossl_inline type *lh_##type##_insert(LHASH_OF(type) *lh, type *d) \ + { \ + return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \ + } \ + static ossl_inline type *lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \ + { \ + return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \ + } \ + static ossl_inline type *lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \ + { \ + return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \ + } \ + static ossl_inline int lh_##type##_error(LHASH_OF(type) *lh) \ + { \ + return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \ + } \ + static ossl_inline unsigned long lh_##type##_num_items(LHASH_OF(type) *lh) \ + { \ + return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \ + } \ + static ossl_inline void lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ + { \ + OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \ + } \ + static ossl_inline void lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ + { \ + OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \ + } \ + static ossl_inline void lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ + { \ + OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \ + } \ + static ossl_inline unsigned long lh_##type##_get_down_load(LHASH_OF(type) *lh) \ + { \ + return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \ + } \ + static ossl_inline void lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \ + { \ + OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \ + } \ + static ossl_inline void lh_##type##_doall(LHASH_OF(type) *lh, \ + void (*doall)(type *)) \ + { \ + OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \ + } \ + LHASH_OF(type) + +#define IMPLEMENT_LHASH_DOALL_ARG_CONST(type, argtype) \ + int_implement_lhash_doall(type, argtype, const type) + +#define IMPLEMENT_LHASH_DOALL_ARG(type, argtype) \ + int_implement_lhash_doall(type, argtype, type) + +#define int_implement_lhash_doall(type, argtype, cbargtype) \ + static ossl_inline void \ + lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \ + void (*fn)(cbargtype *, argtype *), \ + argtype *arg) \ + { \ + OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg); \ + } \ + LHASH_OF(type) + +DEFINE_LHASH_OF(OPENSSL_STRING); +DEFINE_LHASH_OF(OPENSSL_CSTRING); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/android/x86/include/openssl/md2.h b/android/x86/include/openssl/md2.h new file mode 100644 index 00000000..7faf8e3d --- /dev/null +++ b/android/x86/include/openssl/md2.h @@ -0,0 +1,44 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_MD2_H +# define HEADER_MD2_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_MD2 +# include <stddef.h> +# ifdef __cplusplus +extern "C" { +# endif + +typedef unsigned char MD2_INT; + +# define MD2_DIGEST_LENGTH 16 +# define MD2_BLOCK 16 + +typedef struct MD2state_st { + unsigned int num; + unsigned char data[MD2_BLOCK]; + MD2_INT cksm[MD2_BLOCK]; + MD2_INT state[MD2_BLOCK]; +} MD2_CTX; + +const char *MD2_options(void); +int MD2_Init(MD2_CTX *c); +int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len); +int MD2_Final(unsigned char *md, MD2_CTX *c); +unsigned char *MD2(const unsigned char *d, size_t n, unsigned char *md); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/md4.h b/android/x86/include/openssl/md4.h new file mode 100644 index 00000000..940e29db --- /dev/null +++ b/android/x86/include/openssl/md4.h @@ -0,0 +1,51 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_MD4_H +# define HEADER_MD4_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_MD4 +# include <openssl/e_os2.h> +# include <stddef.h> +# ifdef __cplusplus +extern "C" { +# endif + +/*- + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! MD4_LONG has to be at least 32 bits wide. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +# define MD4_LONG unsigned int + +# define MD4_CBLOCK 64 +# define MD4_LBLOCK (MD4_CBLOCK/4) +# define MD4_DIGEST_LENGTH 16 + +typedef struct MD4state_st { + MD4_LONG A, B, C, D; + MD4_LONG Nl, Nh; + MD4_LONG data[MD4_LBLOCK]; + unsigned int num; +} MD4_CTX; + +int MD4_Init(MD4_CTX *c); +int MD4_Update(MD4_CTX *c, const void *data, size_t len); +int MD4_Final(unsigned char *md, MD4_CTX *c); +unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md); +void MD4_Transform(MD4_CTX *c, const unsigned char *b); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/md5.h b/android/x86/include/openssl/md5.h new file mode 100644 index 00000000..2deb7721 --- /dev/null +++ b/android/x86/include/openssl/md5.h @@ -0,0 +1,50 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_MD5_H +# define HEADER_MD5_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_MD5 +# include <openssl/e_os2.h> +# include <stddef.h> +# ifdef __cplusplus +extern "C" { +# endif + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! MD5_LONG has to be at least 32 bits wide. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +# define MD5_LONG unsigned int + +# define MD5_CBLOCK 64 +# define MD5_LBLOCK (MD5_CBLOCK/4) +# define MD5_DIGEST_LENGTH 16 + +typedef struct MD5state_st { + MD5_LONG A, B, C, D; + MD5_LONG Nl, Nh; + MD5_LONG data[MD5_LBLOCK]; + unsigned int num; +} MD5_CTX; + +int MD5_Init(MD5_CTX *c); +int MD5_Update(MD5_CTX *c, const void *data, size_t len); +int MD5_Final(unsigned char *md, MD5_CTX *c); +unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); +void MD5_Transform(MD5_CTX *c, const unsigned char *b); +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/mdc2.h b/android/x86/include/openssl/mdc2.h new file mode 100644 index 00000000..aabd2bfa --- /dev/null +++ b/android/x86/include/openssl/mdc2.h @@ -0,0 +1,42 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_MDC2_H +# define HEADER_MDC2_H + +# include <openssl/opensslconf.h> + +#ifndef OPENSSL_NO_MDC2 +# include <stdlib.h> +# include <openssl/des.h> +# ifdef __cplusplus +extern "C" { +# endif + +# define MDC2_BLOCK 8 +# define MDC2_DIGEST_LENGTH 16 + +typedef struct mdc2_ctx_st { + unsigned int num; + unsigned char data[MDC2_BLOCK]; + DES_cblock h, hh; + int pad_type; /* either 1 or 2, default 1 */ +} MDC2_CTX; + +int MDC2_Init(MDC2_CTX *c); +int MDC2_Update(MDC2_CTX *c, const unsigned char *data, size_t len); +int MDC2_Final(unsigned char *md, MDC2_CTX *c); +unsigned char *MDC2(const unsigned char *d, size_t n, unsigned char *md); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/modes.h b/android/x86/include/openssl/modes.h new file mode 100644 index 00000000..a04c6a59 --- /dev/null +++ b/android/x86/include/openssl/modes.h @@ -0,0 +1,203 @@ +/* + * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif +typedef void (*block128_f) (const unsigned char in[16], + unsigned char out[16], const void *key); + +typedef void (*cbc128_f) (const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], int enc); + +typedef void (*ctr128_f) (const unsigned char *in, unsigned char *out, + size_t blocks, const void *key, + const unsigned char ivec[16]); + +typedef void (*ccm128_f) (const unsigned char *in, unsigned char *out, + size_t blocks, const void *key, + const unsigned char ivec[16], + unsigned char cmac[16]); + +void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], block128_f block); +void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], block128_f block); + +void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], + unsigned char ecount_buf[16], unsigned int *num, + block128_f block); + +void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], + unsigned char ecount_buf[16], + unsigned int *num, ctr128_f ctr); + +void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], int *num, + block128_f block); + +void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], int *num, + int enc, block128_f block); +void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const void *key, + unsigned char ivec[16], int *num, + int enc, block128_f block); +void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out, + size_t bits, const void *key, + unsigned char ivec[16], int *num, + int enc, block128_f block); + +size_t CRYPTO_cts128_encrypt_block(const unsigned char *in, + unsigned char *out, size_t len, + const void *key, unsigned char ivec[16], + block128_f block); +size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], cbc128_f cbc); +size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, + unsigned char *out, size_t len, + const void *key, unsigned char ivec[16], + block128_f block); +size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], cbc128_f cbc); + +size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in, + unsigned char *out, size_t len, + const void *key, + unsigned char ivec[16], + block128_f block); +size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], cbc128_f cbc); +size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, + unsigned char *out, size_t len, + const void *key, + unsigned char ivec[16], + block128_f block); +size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], cbc128_f cbc); + +typedef struct gcm128_context GCM128_CONTEXT; + +GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block); +void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block); +void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv, + size_t len); +int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad, + size_t len); +int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len); +int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len); +int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len, ctr128_f stream); +int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len, ctr128_f stream); +int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag, + size_t len); +void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len); +void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx); + +typedef struct ccm128_context CCM128_CONTEXT; + +void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx, + unsigned int M, unsigned int L, void *key, + block128_f block); +int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, const unsigned char *nonce, + size_t nlen, size_t mlen); +void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, const unsigned char *aad, + size_t alen); +int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, const unsigned char *inp, + unsigned char *out, size_t len); +int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, const unsigned char *inp, + unsigned char *out, size_t len); +int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp, + unsigned char *out, size_t len, + ccm128_f stream); +int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp, + unsigned char *out, size_t len, + ccm128_f stream); +size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len); + +typedef struct xts128_context XTS128_CONTEXT; + +int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, + const unsigned char iv[16], + const unsigned char *inp, unsigned char *out, + size_t len, int enc); + +size_t CRYPTO_128_wrap(void *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, size_t inlen, + block128_f block); + +size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, size_t inlen, + block128_f block); +size_t CRYPTO_128_wrap_pad(void *key, const unsigned char *icv, + unsigned char *out, const unsigned char *in, + size_t inlen, block128_f block); +size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv, + unsigned char *out, const unsigned char *in, + size_t inlen, block128_f block); + +#ifndef OPENSSL_NO_OCB +typedef struct ocb128_context OCB128_CONTEXT; + +typedef void (*ocb128_f) (const unsigned char *in, unsigned char *out, + size_t blocks, const void *key, + size_t start_block_num, + unsigned char offset_i[16], + const unsigned char L_[][16], + unsigned char checksum[16]); + +OCB128_CONTEXT *CRYPTO_ocb128_new(void *keyenc, void *keydec, + block128_f encrypt, block128_f decrypt, + ocb128_f stream); +int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec, + block128_f encrypt, block128_f decrypt, + ocb128_f stream); +int CRYPTO_ocb128_copy_ctx(OCB128_CONTEXT *dest, OCB128_CONTEXT *src, + void *keyenc, void *keydec); +int CRYPTO_ocb128_setiv(OCB128_CONTEXT *ctx, const unsigned char *iv, + size_t len, size_t taglen); +int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad, + size_t len); +int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, const unsigned char *in, + unsigned char *out, size_t len); +int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, const unsigned char *in, + unsigned char *out, size_t len); +int CRYPTO_ocb128_finish(OCB128_CONTEXT *ctx, const unsigned char *tag, + size_t len); +int CRYPTO_ocb128_tag(OCB128_CONTEXT *ctx, unsigned char *tag, size_t len); +void CRYPTO_ocb128_cleanup(OCB128_CONTEXT *ctx); +#endif /* OPENSSL_NO_OCB */ + +#ifdef __cplusplus +} +#endif diff --git a/android/x86/include/openssl/obj_mac.h b/android/x86/include/openssl/obj_mac.h new file mode 100644 index 00000000..f97f3eaa --- /dev/null +++ b/android/x86/include/openssl/obj_mac.h @@ -0,0 +1,4577 @@ +/* + * WARNING: do not edit! + * Generated by crypto/objects/objects.pl + * + * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#define SN_undef "UNDEF" +#define LN_undef "undefined" +#define NID_undef 0 +#define OBJ_undef 0L + +#define SN_itu_t "ITU-T" +#define LN_itu_t "itu-t" +#define NID_itu_t 645 +#define OBJ_itu_t 0L + +#define NID_ccitt 404 +#define OBJ_ccitt OBJ_itu_t + +#define SN_iso "ISO" +#define LN_iso "iso" +#define NID_iso 181 +#define OBJ_iso 1L + +#define SN_joint_iso_itu_t "JOINT-ISO-ITU-T" +#define LN_joint_iso_itu_t "joint-iso-itu-t" +#define NID_joint_iso_itu_t 646 +#define OBJ_joint_iso_itu_t 2L + +#define NID_joint_iso_ccitt 393 +#define OBJ_joint_iso_ccitt OBJ_joint_iso_itu_t + +#define SN_member_body "member-body" +#define LN_member_body "ISO Member Body" +#define NID_member_body 182 +#define OBJ_member_body OBJ_iso,2L + +#define SN_identified_organization "identified-organization" +#define NID_identified_organization 676 +#define OBJ_identified_organization OBJ_iso,3L + +#define SN_hmac_md5 "HMAC-MD5" +#define LN_hmac_md5 "hmac-md5" +#define NID_hmac_md5 780 +#define OBJ_hmac_md5 OBJ_identified_organization,6L,1L,5L,5L,8L,1L,1L + +#define SN_hmac_sha1 "HMAC-SHA1" +#define LN_hmac_sha1 "hmac-sha1" +#define NID_hmac_sha1 781 +#define OBJ_hmac_sha1 OBJ_identified_organization,6L,1L,5L,5L,8L,1L,2L + +#define SN_certicom_arc "certicom-arc" +#define NID_certicom_arc 677 +#define OBJ_certicom_arc OBJ_identified_organization,132L + +#define SN_international_organizations "international-organizations" +#define LN_international_organizations "International Organizations" +#define NID_international_organizations 647 +#define OBJ_international_organizations OBJ_joint_iso_itu_t,23L + +#define SN_wap "wap" +#define NID_wap 678 +#define OBJ_wap OBJ_international_organizations,43L + +#define SN_wap_wsg "wap-wsg" +#define NID_wap_wsg 679 +#define OBJ_wap_wsg OBJ_wap,1L + +#define SN_selected_attribute_types "selected-attribute-types" +#define LN_selected_attribute_types "Selected Attribute Types" +#define NID_selected_attribute_types 394 +#define OBJ_selected_attribute_types OBJ_joint_iso_itu_t,5L,1L,5L + +#define SN_clearance "clearance" +#define NID_clearance 395 +#define OBJ_clearance OBJ_selected_attribute_types,55L + +#define SN_ISO_US "ISO-US" +#define LN_ISO_US "ISO US Member Body" +#define NID_ISO_US 183 +#define OBJ_ISO_US OBJ_member_body,840L + +#define SN_X9_57 "X9-57" +#define LN_X9_57 "X9.57" +#define NID_X9_57 184 +#define OBJ_X9_57 OBJ_ISO_US,10040L + +#define SN_X9cm "X9cm" +#define LN_X9cm "X9.57 CM ?" +#define NID_X9cm 185 +#define OBJ_X9cm OBJ_X9_57,4L + +#define SN_dsa "DSA" +#define LN_dsa "dsaEncryption" +#define NID_dsa 116 +#define OBJ_dsa OBJ_X9cm,1L + +#define SN_dsaWithSHA1 "DSA-SHA1" +#define LN_dsaWithSHA1 "dsaWithSHA1" +#define NID_dsaWithSHA1 113 +#define OBJ_dsaWithSHA1 OBJ_X9cm,3L + +#define SN_ansi_X9_62 "ansi-X9-62" +#define LN_ansi_X9_62 "ANSI X9.62" +#define NID_ansi_X9_62 405 +#define OBJ_ansi_X9_62 OBJ_ISO_US,10045L + +#define OBJ_X9_62_id_fieldType OBJ_ansi_X9_62,1L + +#define SN_X9_62_prime_field "prime-field" +#define NID_X9_62_prime_field 406 +#define OBJ_X9_62_prime_field OBJ_X9_62_id_fieldType,1L + +#define SN_X9_62_characteristic_two_field "characteristic-two-field" +#define NID_X9_62_characteristic_two_field 407 +#define OBJ_X9_62_characteristic_two_field OBJ_X9_62_id_fieldType,2L + +#define SN_X9_62_id_characteristic_two_basis "id-characteristic-two-basis" +#define NID_X9_62_id_characteristic_two_basis 680 +#define OBJ_X9_62_id_characteristic_two_basis OBJ_X9_62_characteristic_two_field,3L + +#define SN_X9_62_onBasis "onBasis" +#define NID_X9_62_onBasis 681 +#define OBJ_X9_62_onBasis OBJ_X9_62_id_characteristic_two_basis,1L + +#define SN_X9_62_tpBasis "tpBasis" +#define NID_X9_62_tpBasis 682 +#define OBJ_X9_62_tpBasis OBJ_X9_62_id_characteristic_two_basis,2L + +#define SN_X9_62_ppBasis "ppBasis" +#define NID_X9_62_ppBasis 683 +#define OBJ_X9_62_ppBasis OBJ_X9_62_id_characteristic_two_basis,3L + +#define OBJ_X9_62_id_publicKeyType OBJ_ansi_X9_62,2L + +#define SN_X9_62_id_ecPublicKey "id-ecPublicKey" +#define NID_X9_62_id_ecPublicKey 408 +#define OBJ_X9_62_id_ecPublicKey OBJ_X9_62_id_publicKeyType,1L + +#define OBJ_X9_62_ellipticCurve OBJ_ansi_X9_62,3L + +#define OBJ_X9_62_c_TwoCurve OBJ_X9_62_ellipticCurve,0L + +#define SN_X9_62_c2pnb163v1 "c2pnb163v1" +#define NID_X9_62_c2pnb163v1 684 +#define OBJ_X9_62_c2pnb163v1 OBJ_X9_62_c_TwoCurve,1L + +#define SN_X9_62_c2pnb163v2 "c2pnb163v2" +#define NID_X9_62_c2pnb163v2 685 +#define OBJ_X9_62_c2pnb163v2 OBJ_X9_62_c_TwoCurve,2L + +#define SN_X9_62_c2pnb163v3 "c2pnb163v3" +#define NID_X9_62_c2pnb163v3 686 +#define OBJ_X9_62_c2pnb163v3 OBJ_X9_62_c_TwoCurve,3L + +#define SN_X9_62_c2pnb176v1 "c2pnb176v1" +#define NID_X9_62_c2pnb176v1 687 +#define OBJ_X9_62_c2pnb176v1 OBJ_X9_62_c_TwoCurve,4L + +#define SN_X9_62_c2tnb191v1 "c2tnb191v1" +#define NID_X9_62_c2tnb191v1 688 +#define OBJ_X9_62_c2tnb191v1 OBJ_X9_62_c_TwoCurve,5L + +#define SN_X9_62_c2tnb191v2 "c2tnb191v2" +#define NID_X9_62_c2tnb191v2 689 +#define OBJ_X9_62_c2tnb191v2 OBJ_X9_62_c_TwoCurve,6L + +#define SN_X9_62_c2tnb191v3 "c2tnb191v3" +#define NID_X9_62_c2tnb191v3 690 +#define OBJ_X9_62_c2tnb191v3 OBJ_X9_62_c_TwoCurve,7L + +#define SN_X9_62_c2onb191v4 "c2onb191v4" +#define NID_X9_62_c2onb191v4 691 +#define OBJ_X9_62_c2onb191v4 OBJ_X9_62_c_TwoCurve,8L + +#define SN_X9_62_c2onb191v5 "c2onb191v5" +#define NID_X9_62_c2onb191v5 692 +#define OBJ_X9_62_c2onb191v5 OBJ_X9_62_c_TwoCurve,9L + +#define SN_X9_62_c2pnb208w1 "c2pnb208w1" +#define NID_X9_62_c2pnb208w1 693 +#define OBJ_X9_62_c2pnb208w1 OBJ_X9_62_c_TwoCurve,10L + +#define SN_X9_62_c2tnb239v1 "c2tnb239v1" +#define NID_X9_62_c2tnb239v1 694 +#define OBJ_X9_62_c2tnb239v1 OBJ_X9_62_c_TwoCurve,11L + +#define SN_X9_62_c2tnb239v2 "c2tnb239v2" +#define NID_X9_62_c2tnb239v2 695 +#define OBJ_X9_62_c2tnb239v2 OBJ_X9_62_c_TwoCurve,12L + +#define SN_X9_62_c2tnb239v3 "c2tnb239v3" +#define NID_X9_62_c2tnb239v3 696 +#define OBJ_X9_62_c2tnb239v3 OBJ_X9_62_c_TwoCurve,13L + +#define SN_X9_62_c2onb239v4 "c2onb239v4" +#define NID_X9_62_c2onb239v4 697 +#define OBJ_X9_62_c2onb239v4 OBJ_X9_62_c_TwoCurve,14L + +#define SN_X9_62_c2onb239v5 "c2onb239v5" +#define NID_X9_62_c2onb239v5 698 +#define OBJ_X9_62_c2onb239v5 OBJ_X9_62_c_TwoCurve,15L + +#define SN_X9_62_c2pnb272w1 "c2pnb272w1" +#define NID_X9_62_c2pnb272w1 699 +#define OBJ_X9_62_c2pnb272w1 OBJ_X9_62_c_TwoCurve,16L + +#define SN_X9_62_c2pnb304w1 "c2pnb304w1" +#define NID_X9_62_c2pnb304w1 700 +#define OBJ_X9_62_c2pnb304w1 OBJ_X9_62_c_TwoCurve,17L + +#define SN_X9_62_c2tnb359v1 "c2tnb359v1" +#define NID_X9_62_c2tnb359v1 701 +#define OBJ_X9_62_c2tnb359v1 OBJ_X9_62_c_TwoCurve,18L + +#define SN_X9_62_c2pnb368w1 "c2pnb368w1" +#define NID_X9_62_c2pnb368w1 702 +#define OBJ_X9_62_c2pnb368w1 OBJ_X9_62_c_TwoCurve,19L + +#define SN_X9_62_c2tnb431r1 "c2tnb431r1" +#define NID_X9_62_c2tnb431r1 703 +#define OBJ_X9_62_c2tnb431r1 OBJ_X9_62_c_TwoCurve,20L + +#define OBJ_X9_62_primeCurve OBJ_X9_62_ellipticCurve,1L + +#define SN_X9_62_prime192v1 "prime192v1" +#define NID_X9_62_prime192v1 409 +#define OBJ_X9_62_prime192v1 OBJ_X9_62_primeCurve,1L + +#define SN_X9_62_prime192v2 "prime192v2" +#define NID_X9_62_prime192v2 410 +#define OBJ_X9_62_prime192v2 OBJ_X9_62_primeCurve,2L + +#define SN_X9_62_prime192v3 "prime192v3" +#define NID_X9_62_prime192v3 411 +#define OBJ_X9_62_prime192v3 OBJ_X9_62_primeCurve,3L + +#define SN_X9_62_prime239v1 "prime239v1" +#define NID_X9_62_prime239v1 412 +#define OBJ_X9_62_prime239v1 OBJ_X9_62_primeCurve,4L + +#define SN_X9_62_prime239v2 "prime239v2" +#define NID_X9_62_prime239v2 413 +#define OBJ_X9_62_prime239v2 OBJ_X9_62_primeCurve,5L + +#define SN_X9_62_prime239v3 "prime239v3" +#define NID_X9_62_prime239v3 414 +#define OBJ_X9_62_prime239v3 OBJ_X9_62_primeCurve,6L + +#define SN_X9_62_prime256v1 "prime256v1" +#define NID_X9_62_prime256v1 415 +#define OBJ_X9_62_prime256v1 OBJ_X9_62_primeCurve,7L + +#define OBJ_X9_62_id_ecSigType OBJ_ansi_X9_62,4L + +#define SN_ecdsa_with_SHA1 "ecdsa-with-SHA1" +#define NID_ecdsa_with_SHA1 416 +#define OBJ_ecdsa_with_SHA1 OBJ_X9_62_id_ecSigType,1L + +#define SN_ecdsa_with_Recommended "ecdsa-with-Recommended" +#define NID_ecdsa_with_Recommended 791 +#define OBJ_ecdsa_with_Recommended OBJ_X9_62_id_ecSigType,2L + +#define SN_ecdsa_with_Specified "ecdsa-with-Specified" +#define NID_ecdsa_with_Specified 792 +#define OBJ_ecdsa_with_Specified OBJ_X9_62_id_ecSigType,3L + +#define SN_ecdsa_with_SHA224 "ecdsa-with-SHA224" +#define NID_ecdsa_with_SHA224 793 +#define OBJ_ecdsa_with_SHA224 OBJ_ecdsa_with_Specified,1L + +#define SN_ecdsa_with_SHA256 "ecdsa-with-SHA256" +#define NID_ecdsa_with_SHA256 794 +#define OBJ_ecdsa_with_SHA256 OBJ_ecdsa_with_Specified,2L + +#define SN_ecdsa_with_SHA384 "ecdsa-with-SHA384" +#define NID_ecdsa_with_SHA384 795 +#define OBJ_ecdsa_with_SHA384 OBJ_ecdsa_with_Specified,3L + +#define SN_ecdsa_with_SHA512 "ecdsa-with-SHA512" +#define NID_ecdsa_with_SHA512 796 +#define OBJ_ecdsa_with_SHA512 OBJ_ecdsa_with_Specified,4L + +#define OBJ_secg_ellipticCurve OBJ_certicom_arc,0L + +#define SN_secp112r1 "secp112r1" +#define NID_secp112r1 704 +#define OBJ_secp112r1 OBJ_secg_ellipticCurve,6L + +#define SN_secp112r2 "secp112r2" +#define NID_secp112r2 705 +#define OBJ_secp112r2 OBJ_secg_ellipticCurve,7L + +#define SN_secp128r1 "secp128r1" +#define NID_secp128r1 706 +#define OBJ_secp128r1 OBJ_secg_ellipticCurve,28L + +#define SN_secp128r2 "secp128r2" +#define NID_secp128r2 707 +#define OBJ_secp128r2 OBJ_secg_ellipticCurve,29L + +#define SN_secp160k1 "secp160k1" +#define NID_secp160k1 708 +#define OBJ_secp160k1 OBJ_secg_ellipticCurve,9L + +#define SN_secp160r1 "secp160r1" +#define NID_secp160r1 709 +#define OBJ_secp160r1 OBJ_secg_ellipticCurve,8L + +#define SN_secp160r2 "secp160r2" +#define NID_secp160r2 710 +#define OBJ_secp160r2 OBJ_secg_ellipticCurve,30L + +#define SN_secp192k1 "secp192k1" +#define NID_secp192k1 711 +#define OBJ_secp192k1 OBJ_secg_ellipticCurve,31L + +#define SN_secp224k1 "secp224k1" +#define NID_secp224k1 712 +#define OBJ_secp224k1 OBJ_secg_ellipticCurve,32L + +#define SN_secp224r1 "secp224r1" +#define NID_secp224r1 713 +#define OBJ_secp224r1 OBJ_secg_ellipticCurve,33L + +#define SN_secp256k1 "secp256k1" +#define NID_secp256k1 714 +#define OBJ_secp256k1 OBJ_secg_ellipticCurve,10L + +#define SN_secp384r1 "secp384r1" +#define NID_secp384r1 715 +#define OBJ_secp384r1 OBJ_secg_ellipticCurve,34L + +#define SN_secp521r1 "secp521r1" +#define NID_secp521r1 716 +#define OBJ_secp521r1 OBJ_secg_ellipticCurve,35L + +#define SN_sect113r1 "sect113r1" +#define NID_sect113r1 717 +#define OBJ_sect113r1 OBJ_secg_ellipticCurve,4L + +#define SN_sect113r2 "sect113r2" +#define NID_sect113r2 718 +#define OBJ_sect113r2 OBJ_secg_ellipticCurve,5L + +#define SN_sect131r1 "sect131r1" +#define NID_sect131r1 719 +#define OBJ_sect131r1 OBJ_secg_ellipticCurve,22L + +#define SN_sect131r2 "sect131r2" +#define NID_sect131r2 720 +#define OBJ_sect131r2 OBJ_secg_ellipticCurve,23L + +#define SN_sect163k1 "sect163k1" +#define NID_sect163k1 721 +#define OBJ_sect163k1 OBJ_secg_ellipticCurve,1L + +#define SN_sect163r1 "sect163r1" +#define NID_sect163r1 722 +#define OBJ_sect163r1 OBJ_secg_ellipticCurve,2L + +#define SN_sect163r2 "sect163r2" +#define NID_sect163r2 723 +#define OBJ_sect163r2 OBJ_secg_ellipticCurve,15L + +#define SN_sect193r1 "sect193r1" +#define NID_sect193r1 724 +#define OBJ_sect193r1 OBJ_secg_ellipticCurve,24L + +#define SN_sect193r2 "sect193r2" +#define NID_sect193r2 725 +#define OBJ_sect193r2 OBJ_secg_ellipticCurve,25L + +#define SN_sect233k1 "sect233k1" +#define NID_sect233k1 726 +#define OBJ_sect233k1 OBJ_secg_ellipticCurve,26L + +#define SN_sect233r1 "sect233r1" +#define NID_sect233r1 727 +#define OBJ_sect233r1 OBJ_secg_ellipticCurve,27L + +#define SN_sect239k1 "sect239k1" +#define NID_sect239k1 728 +#define OBJ_sect239k1 OBJ_secg_ellipticCurve,3L + +#define SN_sect283k1 "sect283k1" +#define NID_sect283k1 729 +#define OBJ_sect283k1 OBJ_secg_ellipticCurve,16L + +#define SN_sect283r1 "sect283r1" +#define NID_sect283r1 730 +#define OBJ_sect283r1 OBJ_secg_ellipticCurve,17L + +#define SN_sect409k1 "sect409k1" +#define NID_sect409k1 731 +#define OBJ_sect409k1 OBJ_secg_ellipticCurve,36L + +#define SN_sect409r1 "sect409r1" +#define NID_sect409r1 732 +#define OBJ_sect409r1 OBJ_secg_ellipticCurve,37L + +#define SN_sect571k1 "sect571k1" +#define NID_sect571k1 733 +#define OBJ_sect571k1 OBJ_secg_ellipticCurve,38L + +#define SN_sect571r1 "sect571r1" +#define NID_sect571r1 734 +#define OBJ_sect571r1 OBJ_secg_ellipticCurve,39L + +#define OBJ_wap_wsg_idm_ecid OBJ_wap_wsg,4L + +#define SN_wap_wsg_idm_ecid_wtls1 "wap-wsg-idm-ecid-wtls1" +#define NID_wap_wsg_idm_ecid_wtls1 735 +#define OBJ_wap_wsg_idm_ecid_wtls1 OBJ_wap_wsg_idm_ecid,1L + +#define SN_wap_wsg_idm_ecid_wtls3 "wap-wsg-idm-ecid-wtls3" +#define NID_wap_wsg_idm_ecid_wtls3 736 +#define OBJ_wap_wsg_idm_ecid_wtls3 OBJ_wap_wsg_idm_ecid,3L + +#define SN_wap_wsg_idm_ecid_wtls4 "wap-wsg-idm-ecid-wtls4" +#define NID_wap_wsg_idm_ecid_wtls4 737 +#define OBJ_wap_wsg_idm_ecid_wtls4 OBJ_wap_wsg_idm_ecid,4L + +#define SN_wap_wsg_idm_ecid_wtls5 "wap-wsg-idm-ecid-wtls5" +#define NID_wap_wsg_idm_ecid_wtls5 738 +#define OBJ_wap_wsg_idm_ecid_wtls5 OBJ_wap_wsg_idm_ecid,5L + +#define SN_wap_wsg_idm_ecid_wtls6 "wap-wsg-idm-ecid-wtls6" +#define NID_wap_wsg_idm_ecid_wtls6 739 +#define OBJ_wap_wsg_idm_ecid_wtls6 OBJ_wap_wsg_idm_ecid,6L + +#define SN_wap_wsg_idm_ecid_wtls7 "wap-wsg-idm-ecid-wtls7" +#define NID_wap_wsg_idm_ecid_wtls7 740 +#define OBJ_wap_wsg_idm_ecid_wtls7 OBJ_wap_wsg_idm_ecid,7L + +#define SN_wap_wsg_idm_ecid_wtls8 "wap-wsg-idm-ecid-wtls8" +#define NID_wap_wsg_idm_ecid_wtls8 741 +#define OBJ_wap_wsg_idm_ecid_wtls8 OBJ_wap_wsg_idm_ecid,8L + +#define SN_wap_wsg_idm_ecid_wtls9 "wap-wsg-idm-ecid-wtls9" +#define NID_wap_wsg_idm_ecid_wtls9 742 +#define OBJ_wap_wsg_idm_ecid_wtls9 OBJ_wap_wsg_idm_ecid,9L + +#define SN_wap_wsg_idm_ecid_wtls10 "wap-wsg-idm-ecid-wtls10" +#define NID_wap_wsg_idm_ecid_wtls10 743 +#define OBJ_wap_wsg_idm_ecid_wtls10 OBJ_wap_wsg_idm_ecid,10L + +#define SN_wap_wsg_idm_ecid_wtls11 "wap-wsg-idm-ecid-wtls11" +#define NID_wap_wsg_idm_ecid_wtls11 744 +#define OBJ_wap_wsg_idm_ecid_wtls11 OBJ_wap_wsg_idm_ecid,11L + +#define SN_wap_wsg_idm_ecid_wtls12 "wap-wsg-idm-ecid-wtls12" +#define NID_wap_wsg_idm_ecid_wtls12 745 +#define OBJ_wap_wsg_idm_ecid_wtls12 OBJ_wap_wsg_idm_ecid,12L + +#define SN_cast5_cbc "CAST5-CBC" +#define LN_cast5_cbc "cast5-cbc" +#define NID_cast5_cbc 108 +#define OBJ_cast5_cbc OBJ_ISO_US,113533L,7L,66L,10L + +#define SN_cast5_ecb "CAST5-ECB" +#define LN_cast5_ecb "cast5-ecb" +#define NID_cast5_ecb 109 + +#define SN_cast5_cfb64 "CAST5-CFB" +#define LN_cast5_cfb64 "cast5-cfb" +#define NID_cast5_cfb64 110 + +#define SN_cast5_ofb64 "CAST5-OFB" +#define LN_cast5_ofb64 "cast5-ofb" +#define NID_cast5_ofb64 111 + +#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC" +#define NID_pbeWithMD5AndCast5_CBC 112 +#define OBJ_pbeWithMD5AndCast5_CBC OBJ_ISO_US,113533L,7L,66L,12L + +#define SN_id_PasswordBasedMAC "id-PasswordBasedMAC" +#define LN_id_PasswordBasedMAC "password based MAC" +#define NID_id_PasswordBasedMAC 782 +#define OBJ_id_PasswordBasedMAC OBJ_ISO_US,113533L,7L,66L,13L + +#define SN_id_DHBasedMac "id-DHBasedMac" +#define LN_id_DHBasedMac "Diffie-Hellman based MAC" +#define NID_id_DHBasedMac 783 +#define OBJ_id_DHBasedMac OBJ_ISO_US,113533L,7L,66L,30L + +#define SN_rsadsi "rsadsi" +#define LN_rsadsi "RSA Data Security, Inc." +#define NID_rsadsi 1 +#define OBJ_rsadsi OBJ_ISO_US,113549L + +#define SN_pkcs "pkcs" +#define LN_pkcs "RSA Data Security, Inc. PKCS" +#define NID_pkcs 2 +#define OBJ_pkcs OBJ_rsadsi,1L + +#define SN_pkcs1 "pkcs1" +#define NID_pkcs1 186 +#define OBJ_pkcs1 OBJ_pkcs,1L + +#define LN_rsaEncryption "rsaEncryption" +#define NID_rsaEncryption 6 +#define OBJ_rsaEncryption OBJ_pkcs1,1L + +#define SN_md2WithRSAEncryption "RSA-MD2" +#define LN_md2WithRSAEncryption "md2WithRSAEncryption" +#define NID_md2WithRSAEncryption 7 +#define OBJ_md2WithRSAEncryption OBJ_pkcs1,2L + +#define SN_md4WithRSAEncryption "RSA-MD4" +#define LN_md4WithRSAEncryption "md4WithRSAEncryption" +#define NID_md4WithRSAEncryption 396 +#define OBJ_md4WithRSAEncryption OBJ_pkcs1,3L + +#define SN_md5WithRSAEncryption "RSA-MD5" +#define LN_md5WithRSAEncryption "md5WithRSAEncryption" +#define NID_md5WithRSAEncryption 8 +#define OBJ_md5WithRSAEncryption OBJ_pkcs1,4L + +#define SN_sha1WithRSAEncryption "RSA-SHA1" +#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption" +#define NID_sha1WithRSAEncryption 65 +#define OBJ_sha1WithRSAEncryption OBJ_pkcs1,5L + +#define SN_rsaesOaep "RSAES-OAEP" +#define LN_rsaesOaep "rsaesOaep" +#define NID_rsaesOaep 919 +#define OBJ_rsaesOaep OBJ_pkcs1,7L + +#define SN_mgf1 "MGF1" +#define LN_mgf1 "mgf1" +#define NID_mgf1 911 +#define OBJ_mgf1 OBJ_pkcs1,8L + +#define SN_pSpecified "PSPECIFIED" +#define LN_pSpecified "pSpecified" +#define NID_pSpecified 935 +#define OBJ_pSpecified OBJ_pkcs1,9L + +#define SN_rsassaPss "RSASSA-PSS" +#define LN_rsassaPss "rsassaPss" +#define NID_rsassaPss 912 +#define OBJ_rsassaPss OBJ_pkcs1,10L + +#define SN_sha256WithRSAEncryption "RSA-SHA256" +#define LN_sha256WithRSAEncryption "sha256WithRSAEncryption" +#define NID_sha256WithRSAEncryption 668 +#define OBJ_sha256WithRSAEncryption OBJ_pkcs1,11L + +#define SN_sha384WithRSAEncryption "RSA-SHA384" +#define LN_sha384WithRSAEncryption "sha384WithRSAEncryption" +#define NID_sha384WithRSAEncryption 669 +#define OBJ_sha384WithRSAEncryption OBJ_pkcs1,12L + +#define SN_sha512WithRSAEncryption "RSA-SHA512" +#define LN_sha512WithRSAEncryption "sha512WithRSAEncryption" +#define NID_sha512WithRSAEncryption 670 +#define OBJ_sha512WithRSAEncryption OBJ_pkcs1,13L + +#define SN_sha224WithRSAEncryption "RSA-SHA224" +#define LN_sha224WithRSAEncryption "sha224WithRSAEncryption" +#define NID_sha224WithRSAEncryption 671 +#define OBJ_sha224WithRSAEncryption OBJ_pkcs1,14L + +#define SN_pkcs3 "pkcs3" +#define NID_pkcs3 27 +#define OBJ_pkcs3 OBJ_pkcs,3L + +#define LN_dhKeyAgreement "dhKeyAgreement" +#define NID_dhKeyAgreement 28 +#define OBJ_dhKeyAgreement OBJ_pkcs3,1L + +#define SN_pkcs5 "pkcs5" +#define NID_pkcs5 187 +#define OBJ_pkcs5 OBJ_pkcs,5L + +#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES" +#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC" +#define NID_pbeWithMD2AndDES_CBC 9 +#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs5,1L + +#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES" +#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC" +#define NID_pbeWithMD5AndDES_CBC 10 +#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs5,3L + +#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64" +#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC" +#define NID_pbeWithMD2AndRC2_CBC 168 +#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs5,4L + +#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64" +#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC" +#define NID_pbeWithMD5AndRC2_CBC 169 +#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs5,6L + +#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES" +#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC" +#define NID_pbeWithSHA1AndDES_CBC 170 +#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs5,10L + +#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64" +#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC" +#define NID_pbeWithSHA1AndRC2_CBC 68 +#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs5,11L + +#define LN_id_pbkdf2 "PBKDF2" +#define NID_id_pbkdf2 69 +#define OBJ_id_pbkdf2 OBJ_pkcs5,12L + +#define LN_pbes2 "PBES2" +#define NID_pbes2 161 +#define OBJ_pbes2 OBJ_pkcs5,13L + +#define LN_pbmac1 "PBMAC1" +#define NID_pbmac1 162 +#define OBJ_pbmac1 OBJ_pkcs5,14L + +#define SN_pkcs7 "pkcs7" +#define NID_pkcs7 20 +#define OBJ_pkcs7 OBJ_pkcs,7L + +#define LN_pkcs7_data "pkcs7-data" +#define NID_pkcs7_data 21 +#define OBJ_pkcs7_data OBJ_pkcs7,1L + +#define LN_pkcs7_signed "pkcs7-signedData" +#define NID_pkcs7_signed 22 +#define OBJ_pkcs7_signed OBJ_pkcs7,2L + +#define LN_pkcs7_enveloped "pkcs7-envelopedData" +#define NID_pkcs7_enveloped 23 +#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L + +#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData" +#define NID_pkcs7_signedAndEnveloped 24 +#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L + +#define LN_pkcs7_digest "pkcs7-digestData" +#define NID_pkcs7_digest 25 +#define OBJ_pkcs7_digest OBJ_pkcs7,5L + +#define LN_pkcs7_encrypted "pkcs7-encryptedData" +#define NID_pkcs7_encrypted 26 +#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L + +#define SN_pkcs9 "pkcs9" +#define NID_pkcs9 47 +#define OBJ_pkcs9 OBJ_pkcs,9L + +#define LN_pkcs9_emailAddress "emailAddress" +#define NID_pkcs9_emailAddress 48 +#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L + +#define LN_pkcs9_unstructuredName "unstructuredName" +#define NID_pkcs9_unstructuredName 49 +#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L + +#define LN_pkcs9_contentType "contentType" +#define NID_pkcs9_contentType 50 +#define OBJ_pkcs9_contentType OBJ_pkcs9,3L + +#define LN_pkcs9_messageDigest "messageDigest" +#define NID_pkcs9_messageDigest 51 +#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L + +#define LN_pkcs9_signingTime "signingTime" +#define NID_pkcs9_signingTime 52 +#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L + +#define LN_pkcs9_countersignature "countersignature" +#define NID_pkcs9_countersignature 53 +#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L + +#define LN_pkcs9_challengePassword "challengePassword" +#define NID_pkcs9_challengePassword 54 +#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L + +#define LN_pkcs9_unstructuredAddress "unstructuredAddress" +#define NID_pkcs9_unstructuredAddress 55 +#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L + +#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes" +#define NID_pkcs9_extCertAttributes 56 +#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L + +#define SN_ext_req "extReq" +#define LN_ext_req "Extension Request" +#define NID_ext_req 172 +#define OBJ_ext_req OBJ_pkcs9,14L + +#define SN_SMIMECapabilities "SMIME-CAPS" +#define LN_SMIMECapabilities "S/MIME Capabilities" +#define NID_SMIMECapabilities 167 +#define OBJ_SMIMECapabilities OBJ_pkcs9,15L + +#define SN_SMIME "SMIME" +#define LN_SMIME "S/MIME" +#define NID_SMIME 188 +#define OBJ_SMIME OBJ_pkcs9,16L + +#define SN_id_smime_mod "id-smime-mod" +#define NID_id_smime_mod 189 +#define OBJ_id_smime_mod OBJ_SMIME,0L + +#define SN_id_smime_ct "id-smime-ct" +#define NID_id_smime_ct 190 +#define OBJ_id_smime_ct OBJ_SMIME,1L + +#define SN_id_smime_aa "id-smime-aa" +#define NID_id_smime_aa 191 +#define OBJ_id_smime_aa OBJ_SMIME,2L + +#define SN_id_smime_alg "id-smime-alg" +#define NID_id_smime_alg 192 +#define OBJ_id_smime_alg OBJ_SMIME,3L + +#define SN_id_smime_cd "id-smime-cd" +#define NID_id_smime_cd 193 +#define OBJ_id_smime_cd OBJ_SMIME,4L + +#define SN_id_smime_spq "id-smime-spq" +#define NID_id_smime_spq 194 +#define OBJ_id_smime_spq OBJ_SMIME,5L + +#define SN_id_smime_cti "id-smime-cti" +#define NID_id_smime_cti 195 +#define OBJ_id_smime_cti OBJ_SMIME,6L + +#define SN_id_smime_mod_cms "id-smime-mod-cms" +#define NID_id_smime_mod_cms 196 +#define OBJ_id_smime_mod_cms OBJ_id_smime_mod,1L + +#define SN_id_smime_mod_ess "id-smime-mod-ess" +#define NID_id_smime_mod_ess 197 +#define OBJ_id_smime_mod_ess OBJ_id_smime_mod,2L + +#define SN_id_smime_mod_oid "id-smime-mod-oid" +#define NID_id_smime_mod_oid 198 +#define OBJ_id_smime_mod_oid OBJ_id_smime_mod,3L + +#define SN_id_smime_mod_msg_v3 "id-smime-mod-msg-v3" +#define NID_id_smime_mod_msg_v3 199 +#define OBJ_id_smime_mod_msg_v3 OBJ_id_smime_mod,4L + +#define SN_id_smime_mod_ets_eSignature_88 "id-smime-mod-ets-eSignature-88" +#define NID_id_smime_mod_ets_eSignature_88 200 +#define OBJ_id_smime_mod_ets_eSignature_88 OBJ_id_smime_mod,5L + +#define SN_id_smime_mod_ets_eSignature_97 "id-smime-mod-ets-eSignature-97" +#define NID_id_smime_mod_ets_eSignature_97 201 +#define OBJ_id_smime_mod_ets_eSignature_97 OBJ_id_smime_mod,6L + +#define SN_id_smime_mod_ets_eSigPolicy_88 "id-smime-mod-ets-eSigPolicy-88" +#define NID_id_smime_mod_ets_eSigPolicy_88 202 +#define OBJ_id_smime_mod_ets_eSigPolicy_88 OBJ_id_smime_mod,7L + +#define SN_id_smime_mod_ets_eSigPolicy_97 "id-smime-mod-ets-eSigPolicy-97" +#define NID_id_smime_mod_ets_eSigPolicy_97 203 +#define OBJ_id_smime_mod_ets_eSigPolicy_97 OBJ_id_smime_mod,8L + +#define SN_id_smime_ct_receipt "id-smime-ct-receipt" +#define NID_id_smime_ct_receipt 204 +#define OBJ_id_smime_ct_receipt OBJ_id_smime_ct,1L + +#define SN_id_smime_ct_authData "id-smime-ct-authData" +#define NID_id_smime_ct_authData 205 +#define OBJ_id_smime_ct_authData OBJ_id_smime_ct,2L + +#define SN_id_smime_ct_publishCert "id-smime-ct-publishCert" +#define NID_id_smime_ct_publishCert 206 +#define OBJ_id_smime_ct_publishCert OBJ_id_smime_ct,3L + +#define SN_id_smime_ct_TSTInfo "id-smime-ct-TSTInfo" +#define NID_id_smime_ct_TSTInfo 207 +#define OBJ_id_smime_ct_TSTInfo OBJ_id_smime_ct,4L + +#define SN_id_smime_ct_TDTInfo "id-smime-ct-TDTInfo" +#define NID_id_smime_ct_TDTInfo 208 +#define OBJ_id_smime_ct_TDTInfo OBJ_id_smime_ct,5L + +#define SN_id_smime_ct_contentInfo "id-smime-ct-contentInfo" +#define NID_id_smime_ct_contentInfo 209 +#define OBJ_id_smime_ct_contentInfo OBJ_id_smime_ct,6L + +#define SN_id_smime_ct_DVCSRequestData "id-smime-ct-DVCSRequestData" +#define NID_id_smime_ct_DVCSRequestData 210 +#define OBJ_id_smime_ct_DVCSRequestData OBJ_id_smime_ct,7L + +#define SN_id_smime_ct_DVCSResponseData "id-smime-ct-DVCSResponseData" +#define NID_id_smime_ct_DVCSResponseData 211 +#define OBJ_id_smime_ct_DVCSResponseData OBJ_id_smime_ct,8L + +#define SN_id_smime_ct_compressedData "id-smime-ct-compressedData" +#define NID_id_smime_ct_compressedData 786 +#define OBJ_id_smime_ct_compressedData OBJ_id_smime_ct,9L + +#define SN_id_smime_ct_contentCollection "id-smime-ct-contentCollection" +#define NID_id_smime_ct_contentCollection 1058 +#define OBJ_id_smime_ct_contentCollection OBJ_id_smime_ct,19L + +#define SN_id_smime_ct_authEnvelopedData "id-smime-ct-authEnvelopedData" +#define NID_id_smime_ct_authEnvelopedData 1059 +#define OBJ_id_smime_ct_authEnvelopedData OBJ_id_smime_ct,23L + +#define SN_id_ct_asciiTextWithCRLF "id-ct-asciiTextWithCRLF" +#define NID_id_ct_asciiTextWithCRLF 787 +#define OBJ_id_ct_asciiTextWithCRLF OBJ_id_smime_ct,27L + +#define SN_id_ct_xml "id-ct-xml" +#define NID_id_ct_xml 1060 +#define OBJ_id_ct_xml OBJ_id_smime_ct,28L + +#define SN_id_smime_aa_receiptRequest "id-smime-aa-receiptRequest" +#define NID_id_smime_aa_receiptRequest 212 +#define OBJ_id_smime_aa_receiptRequest OBJ_id_smime_aa,1L + +#define SN_id_smime_aa_securityLabel "id-smime-aa-securityLabel" +#define NID_id_smime_aa_securityLabel 213 +#define OBJ_id_smime_aa_securityLabel OBJ_id_smime_aa,2L + +#define SN_id_smime_aa_mlExpandHistory "id-smime-aa-mlExpandHistory" +#define NID_id_smime_aa_mlExpandHistory 214 +#define OBJ_id_smime_aa_mlExpandHistory OBJ_id_smime_aa,3L + +#define SN_id_smime_aa_contentHint "id-smime-aa-contentHint" +#define NID_id_smime_aa_contentHint 215 +#define OBJ_id_smime_aa_contentHint OBJ_id_smime_aa,4L + +#define SN_id_smime_aa_msgSigDigest "id-smime-aa-msgSigDigest" +#define NID_id_smime_aa_msgSigDigest 216 +#define OBJ_id_smime_aa_msgSigDigest OBJ_id_smime_aa,5L + +#define SN_id_smime_aa_encapContentType "id-smime-aa-encapContentType" +#define NID_id_smime_aa_encapContentType 217 +#define OBJ_id_smime_aa_encapContentType OBJ_id_smime_aa,6L + +#define SN_id_smime_aa_contentIdentifier "id-smime-aa-contentIdentifier" +#define NID_id_smime_aa_contentIdentifier 218 +#define OBJ_id_smime_aa_contentIdentifier OBJ_id_smime_aa,7L + +#define SN_id_smime_aa_macValue "id-smime-aa-macValue" +#define NID_id_smime_aa_macValue 219 +#define OBJ_id_smime_aa_macValue OBJ_id_smime_aa,8L + +#define SN_id_smime_aa_equivalentLabels "id-smime-aa-equivalentLabels" +#define NID_id_smime_aa_equivalentLabels 220 +#define OBJ_id_smime_aa_equivalentLabels OBJ_id_smime_aa,9L + +#define SN_id_smime_aa_contentReference "id-smime-aa-contentReference" +#define NID_id_smime_aa_contentReference 221 +#define OBJ_id_smime_aa_contentReference OBJ_id_smime_aa,10L + +#define SN_id_smime_aa_encrypKeyPref "id-smime-aa-encrypKeyPref" +#define NID_id_smime_aa_encrypKeyPref 222 +#define OBJ_id_smime_aa_encrypKeyPref OBJ_id_smime_aa,11L + +#define SN_id_smime_aa_signingCertificate "id-smime-aa-signingCertificate" +#define NID_id_smime_aa_signingCertificate 223 +#define OBJ_id_smime_aa_signingCertificate OBJ_id_smime_aa,12L + +#define SN_id_smime_aa_smimeEncryptCerts "id-smime-aa-smimeEncryptCerts" +#define NID_id_smime_aa_smimeEncryptCerts 224 +#define OBJ_id_smime_aa_smimeEncryptCerts OBJ_id_smime_aa,13L + +#define SN_id_smime_aa_timeStampToken "id-smime-aa-timeStampToken" +#define NID_id_smime_aa_timeStampToken 225 +#define OBJ_id_smime_aa_timeStampToken OBJ_id_smime_aa,14L + +#define SN_id_smime_aa_ets_sigPolicyId "id-smime-aa-ets-sigPolicyId" +#define NID_id_smime_aa_ets_sigPolicyId 226 +#define OBJ_id_smime_aa_ets_sigPolicyId OBJ_id_smime_aa,15L + +#define SN_id_smime_aa_ets_commitmentType "id-smime-aa-ets-commitmentType" +#define NID_id_smime_aa_ets_commitmentType 227 +#define OBJ_id_smime_aa_ets_commitmentType OBJ_id_smime_aa,16L + +#define SN_id_smime_aa_ets_signerLocation "id-smime-aa-ets-signerLocation" +#define NID_id_smime_aa_ets_signerLocation 228 +#define OBJ_id_smime_aa_ets_signerLocation OBJ_id_smime_aa,17L + +#define SN_id_smime_aa_ets_signerAttr "id-smime-aa-ets-signerAttr" +#define NID_id_smime_aa_ets_signerAttr 229 +#define OBJ_id_smime_aa_ets_signerAttr OBJ_id_smime_aa,18L + +#define SN_id_smime_aa_ets_otherSigCert "id-smime-aa-ets-otherSigCert" +#define NID_id_smime_aa_ets_otherSigCert 230 +#define OBJ_id_smime_aa_ets_otherSigCert OBJ_id_smime_aa,19L + +#define SN_id_smime_aa_ets_contentTimestamp "id-smime-aa-ets-contentTimestamp" +#define NID_id_smime_aa_ets_contentTimestamp 231 +#define OBJ_id_smime_aa_ets_contentTimestamp OBJ_id_smime_aa,20L + +#define SN_id_smime_aa_ets_CertificateRefs "id-smime-aa-ets-CertificateRefs" +#define NID_id_smime_aa_ets_CertificateRefs 232 +#define OBJ_id_smime_aa_ets_CertificateRefs OBJ_id_smime_aa,21L + +#define SN_id_smime_aa_ets_RevocationRefs "id-smime-aa-ets-RevocationRefs" +#define NID_id_smime_aa_ets_RevocationRefs 233 +#define OBJ_id_smime_aa_ets_RevocationRefs OBJ_id_smime_aa,22L + +#define SN_id_smime_aa_ets_certValues "id-smime-aa-ets-certValues" +#define NID_id_smime_aa_ets_certValues 234 +#define OBJ_id_smime_aa_ets_certValues OBJ_id_smime_aa,23L + +#define SN_id_smime_aa_ets_revocationValues "id-smime-aa-ets-revocationValues" +#define NID_id_smime_aa_ets_revocationValues 235 +#define OBJ_id_smime_aa_ets_revocationValues OBJ_id_smime_aa,24L + +#define SN_id_smime_aa_ets_escTimeStamp "id-smime-aa-ets-escTimeStamp" +#define NID_id_smime_aa_ets_escTimeStamp 236 +#define OBJ_id_smime_aa_ets_escTimeStamp OBJ_id_smime_aa,25L + +#define SN_id_smime_aa_ets_certCRLTimestamp "id-smime-aa-ets-certCRLTimestamp" +#define NID_id_smime_aa_ets_certCRLTimestamp 237 +#define OBJ_id_smime_aa_ets_certCRLTimestamp OBJ_id_smime_aa,26L + +#define SN_id_smime_aa_ets_archiveTimeStamp "id-smime-aa-ets-archiveTimeStamp" +#define NID_id_smime_aa_ets_archiveTimeStamp 238 +#define OBJ_id_smime_aa_ets_archiveTimeStamp OBJ_id_smime_aa,27L + +#define SN_id_smime_aa_signatureType "id-smime-aa-signatureType" +#define NID_id_smime_aa_signatureType 239 +#define OBJ_id_smime_aa_signatureType OBJ_id_smime_aa,28L + +#define SN_id_smime_aa_dvcs_dvc "id-smime-aa-dvcs-dvc" +#define NID_id_smime_aa_dvcs_dvc 240 +#define OBJ_id_smime_aa_dvcs_dvc OBJ_id_smime_aa,29L + +#define SN_id_smime_alg_ESDHwith3DES "id-smime-alg-ESDHwith3DES" +#define NID_id_smime_alg_ESDHwith3DES 241 +#define OBJ_id_smime_alg_ESDHwith3DES OBJ_id_smime_alg,1L + +#define SN_id_smime_alg_ESDHwithRC2 "id-smime-alg-ESDHwithRC2" +#define NID_id_smime_alg_ESDHwithRC2 242 +#define OBJ_id_smime_alg_ESDHwithRC2 OBJ_id_smime_alg,2L + +#define SN_id_smime_alg_3DESwrap "id-smime-alg-3DESwrap" +#define NID_id_smime_alg_3DESwrap 243 +#define OBJ_id_smime_alg_3DESwrap OBJ_id_smime_alg,3L + +#define SN_id_smime_alg_RC2wrap "id-smime-alg-RC2wrap" +#define NID_id_smime_alg_RC2wrap 244 +#define OBJ_id_smime_alg_RC2wrap OBJ_id_smime_alg,4L + +#define SN_id_smime_alg_ESDH "id-smime-alg-ESDH" +#define NID_id_smime_alg_ESDH 245 +#define OBJ_id_smime_alg_ESDH OBJ_id_smime_alg,5L + +#define SN_id_smime_alg_CMS3DESwrap "id-smime-alg-CMS3DESwrap" +#define NID_id_smime_alg_CMS3DESwrap 246 +#define OBJ_id_smime_alg_CMS3DESwrap OBJ_id_smime_alg,6L + +#define SN_id_smime_alg_CMSRC2wrap "id-smime-alg-CMSRC2wrap" +#define NID_id_smime_alg_CMSRC2wrap 247 +#define OBJ_id_smime_alg_CMSRC2wrap OBJ_id_smime_alg,7L + +#define SN_id_alg_PWRI_KEK "id-alg-PWRI-KEK" +#define NID_id_alg_PWRI_KEK 893 +#define OBJ_id_alg_PWRI_KEK OBJ_id_smime_alg,9L + +#define SN_id_smime_cd_ldap "id-smime-cd-ldap" +#define NID_id_smime_cd_ldap 248 +#define OBJ_id_smime_cd_ldap OBJ_id_smime_cd,1L + +#define SN_id_smime_spq_ets_sqt_uri "id-smime-spq-ets-sqt-uri" +#define NID_id_smime_spq_ets_sqt_uri 249 +#define OBJ_id_smime_spq_ets_sqt_uri OBJ_id_smime_spq,1L + +#define SN_id_smime_spq_ets_sqt_unotice "id-smime-spq-ets-sqt-unotice" +#define NID_id_smime_spq_ets_sqt_unotice 250 +#define OBJ_id_smime_spq_ets_sqt_unotice OBJ_id_smime_spq,2L + +#define SN_id_smime_cti_ets_proofOfOrigin "id-smime-cti-ets-proofOfOrigin" +#define NID_id_smime_cti_ets_proofOfOrigin 251 +#define OBJ_id_smime_cti_ets_proofOfOrigin OBJ_id_smime_cti,1L + +#define SN_id_smime_cti_ets_proofOfReceipt "id-smime-cti-ets-proofOfReceipt" +#define NID_id_smime_cti_ets_proofOfReceipt 252 +#define OBJ_id_smime_cti_ets_proofOfReceipt OBJ_id_smime_cti,2L + +#define SN_id_smime_cti_ets_proofOfDelivery "id-smime-cti-ets-proofOfDelivery" +#define NID_id_smime_cti_ets_proofOfDelivery 253 +#define OBJ_id_smime_cti_ets_proofOfDelivery OBJ_id_smime_cti,3L + +#define SN_id_smime_cti_ets_proofOfSender "id-smime-cti-ets-proofOfSender" +#define NID_id_smime_cti_ets_proofOfSender 254 +#define OBJ_id_smime_cti_ets_proofOfSender OBJ_id_smime_cti,4L + +#define SN_id_smime_cti_ets_proofOfApproval "id-smime-cti-ets-proofOfApproval" +#define NID_id_smime_cti_ets_proofOfApproval 255 +#define OBJ_id_smime_cti_ets_proofOfApproval OBJ_id_smime_cti,5L + +#define SN_id_smime_cti_ets_proofOfCreation "id-smime-cti-ets-proofOfCreation" +#define NID_id_smime_cti_ets_proofOfCreation 256 +#define OBJ_id_smime_cti_ets_proofOfCreation OBJ_id_smime_cti,6L + +#define LN_friendlyName "friendlyName" +#define NID_friendlyName 156 +#define OBJ_friendlyName OBJ_pkcs9,20L + +#define LN_localKeyID "localKeyID" +#define NID_localKeyID 157 +#define OBJ_localKeyID OBJ_pkcs9,21L + +#define SN_ms_csp_name "CSPName" +#define LN_ms_csp_name "Microsoft CSP Name" +#define NID_ms_csp_name 417 +#define OBJ_ms_csp_name 1L,3L,6L,1L,4L,1L,311L,17L,1L + +#define SN_LocalKeySet "LocalKeySet" +#define LN_LocalKeySet "Microsoft Local Key set" +#define NID_LocalKeySet 856 +#define OBJ_LocalKeySet 1L,3L,6L,1L,4L,1L,311L,17L,2L + +#define OBJ_certTypes OBJ_pkcs9,22L + +#define LN_x509Certificate "x509Certificate" +#define NID_x509Certificate 158 +#define OBJ_x509Certificate OBJ_certTypes,1L + +#define LN_sdsiCertificate "sdsiCertificate" +#define NID_sdsiCertificate 159 +#define OBJ_sdsiCertificate OBJ_certTypes,2L + +#define OBJ_crlTypes OBJ_pkcs9,23L + +#define LN_x509Crl "x509Crl" +#define NID_x509Crl 160 +#define OBJ_x509Crl OBJ_crlTypes,1L + +#define OBJ_pkcs12 OBJ_pkcs,12L + +#define OBJ_pkcs12_pbeids OBJ_pkcs12,1L + +#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128" +#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4" +#define NID_pbe_WithSHA1And128BitRC4 144 +#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids,1L + +#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40" +#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4" +#define NID_pbe_WithSHA1And40BitRC4 145 +#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids,2L + +#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES" +#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146 +#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids,3L + +#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES" +#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147 +#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids,4L + +#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128" +#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC" +#define NID_pbe_WithSHA1And128BitRC2_CBC 148 +#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids,5L + +#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40" +#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC" +#define NID_pbe_WithSHA1And40BitRC2_CBC 149 +#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids,6L + +#define OBJ_pkcs12_Version1 OBJ_pkcs12,10L + +#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1,1L + +#define LN_keyBag "keyBag" +#define NID_keyBag 150 +#define OBJ_keyBag OBJ_pkcs12_BagIds,1L + +#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag" +#define NID_pkcs8ShroudedKeyBag 151 +#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds,2L + +#define LN_certBag "certBag" +#define NID_certBag 152 +#define OBJ_certBag OBJ_pkcs12_BagIds,3L + +#define LN_crlBag "crlBag" +#define NID_crlBag 153 +#define OBJ_crlBag OBJ_pkcs12_BagIds,4L + +#define LN_secretBag "secretBag" +#define NID_secretBag 154 +#define OBJ_secretBag OBJ_pkcs12_BagIds,5L + +#define LN_safeContentsBag "safeContentsBag" +#define NID_safeContentsBag 155 +#define OBJ_safeContentsBag OBJ_pkcs12_BagIds,6L + +#define SN_md2 "MD2" +#define LN_md2 "md2" +#define NID_md2 3 +#define OBJ_md2 OBJ_rsadsi,2L,2L + +#define SN_md4 "MD4" +#define LN_md4 "md4" +#define NID_md4 257 +#define OBJ_md4 OBJ_rsadsi,2L,4L + +#define SN_md5 "MD5" +#define LN_md5 "md5" +#define NID_md5 4 +#define OBJ_md5 OBJ_rsadsi,2L,5L + +#define SN_md5_sha1 "MD5-SHA1" +#define LN_md5_sha1 "md5-sha1" +#define NID_md5_sha1 114 + +#define LN_hmacWithMD5 "hmacWithMD5" +#define NID_hmacWithMD5 797 +#define OBJ_hmacWithMD5 OBJ_rsadsi,2L,6L + +#define LN_hmacWithSHA1 "hmacWithSHA1" +#define NID_hmacWithSHA1 163 +#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L + +#define LN_hmacWithSHA224 "hmacWithSHA224" +#define NID_hmacWithSHA224 798 +#define OBJ_hmacWithSHA224 OBJ_rsadsi,2L,8L + +#define LN_hmacWithSHA256 "hmacWithSHA256" +#define NID_hmacWithSHA256 799 +#define OBJ_hmacWithSHA256 OBJ_rsadsi,2L,9L + +#define LN_hmacWithSHA384 "hmacWithSHA384" +#define NID_hmacWithSHA384 800 +#define OBJ_hmacWithSHA384 OBJ_rsadsi,2L,10L + +#define LN_hmacWithSHA512 "hmacWithSHA512" +#define NID_hmacWithSHA512 801 +#define OBJ_hmacWithSHA512 OBJ_rsadsi,2L,11L + +#define SN_rc2_cbc "RC2-CBC" +#define LN_rc2_cbc "rc2-cbc" +#define NID_rc2_cbc 37 +#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L + +#define SN_rc2_ecb "RC2-ECB" +#define LN_rc2_ecb "rc2-ecb" +#define NID_rc2_ecb 38 + +#define SN_rc2_cfb64 "RC2-CFB" +#define LN_rc2_cfb64 "rc2-cfb" +#define NID_rc2_cfb64 39 + +#define SN_rc2_ofb64 "RC2-OFB" +#define LN_rc2_ofb64 "rc2-ofb" +#define NID_rc2_ofb64 40 + +#define SN_rc2_40_cbc "RC2-40-CBC" +#define LN_rc2_40_cbc "rc2-40-cbc" +#define NID_rc2_40_cbc 98 + +#define SN_rc2_64_cbc "RC2-64-CBC" +#define LN_rc2_64_cbc "rc2-64-cbc" +#define NID_rc2_64_cbc 166 + +#define SN_rc4 "RC4" +#define LN_rc4 "rc4" +#define NID_rc4 5 +#define OBJ_rc4 OBJ_rsadsi,3L,4L + +#define SN_rc4_40 "RC4-40" +#define LN_rc4_40 "rc4-40" +#define NID_rc4_40 97 + +#define SN_des_ede3_cbc "DES-EDE3-CBC" +#define LN_des_ede3_cbc "des-ede3-cbc" +#define NID_des_ede3_cbc 44 +#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L + +#define SN_rc5_cbc "RC5-CBC" +#define LN_rc5_cbc "rc5-cbc" +#define NID_rc5_cbc 120 +#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L + +#define SN_rc5_ecb "RC5-ECB" +#define LN_rc5_ecb "rc5-ecb" +#define NID_rc5_ecb 121 + +#define SN_rc5_cfb64 "RC5-CFB" +#define LN_rc5_cfb64 "rc5-cfb" +#define NID_rc5_cfb64 122 + +#define SN_rc5_ofb64 "RC5-OFB" +#define LN_rc5_ofb64 "rc5-ofb" +#define NID_rc5_ofb64 123 + +#define SN_ms_ext_req "msExtReq" +#define LN_ms_ext_req "Microsoft Extension Request" +#define NID_ms_ext_req 171 +#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L + +#define SN_ms_code_ind "msCodeInd" +#define LN_ms_code_ind "Microsoft Individual Code Signing" +#define NID_ms_code_ind 134 +#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L + +#define SN_ms_code_com "msCodeCom" +#define LN_ms_code_com "Microsoft Commercial Code Signing" +#define NID_ms_code_com 135 +#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L + +#define SN_ms_ctl_sign "msCTLSign" +#define LN_ms_ctl_sign "Microsoft Trust List Signing" +#define NID_ms_ctl_sign 136 +#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L + +#define SN_ms_sgc "msSGC" +#define LN_ms_sgc "Microsoft Server Gated Crypto" +#define NID_ms_sgc 137 +#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L + +#define SN_ms_efs "msEFS" +#define LN_ms_efs "Microsoft Encrypted File System" +#define NID_ms_efs 138 +#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L + +#define SN_ms_smartcard_login "msSmartcardLogin" +#define LN_ms_smartcard_login "Microsoft Smartcardlogin" +#define NID_ms_smartcard_login 648 +#define OBJ_ms_smartcard_login 1L,3L,6L,1L,4L,1L,311L,20L,2L,2L + +#define SN_ms_upn "msUPN" +#define LN_ms_upn "Microsoft Universal Principal Name" +#define NID_ms_upn 649 +#define OBJ_ms_upn 1L,3L,6L,1L,4L,1L,311L,20L,2L,3L + +#define SN_idea_cbc "IDEA-CBC" +#define LN_idea_cbc "idea-cbc" +#define NID_idea_cbc 34 +#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L + +#define SN_idea_ecb "IDEA-ECB" +#define LN_idea_ecb "idea-ecb" +#define NID_idea_ecb 36 + +#define SN_idea_cfb64 "IDEA-CFB" +#define LN_idea_cfb64 "idea-cfb" +#define NID_idea_cfb64 35 + +#define SN_idea_ofb64 "IDEA-OFB" +#define LN_idea_ofb64 "idea-ofb" +#define NID_idea_ofb64 46 + +#define SN_bf_cbc "BF-CBC" +#define LN_bf_cbc "bf-cbc" +#define NID_bf_cbc 91 +#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L + +#define SN_bf_ecb "BF-ECB" +#define LN_bf_ecb "bf-ecb" +#define NID_bf_ecb 92 + +#define SN_bf_cfb64 "BF-CFB" +#define LN_bf_cfb64 "bf-cfb" +#define NID_bf_cfb64 93 + +#define SN_bf_ofb64 "BF-OFB" +#define LN_bf_ofb64 "bf-ofb" +#define NID_bf_ofb64 94 + +#define SN_id_pkix "PKIX" +#define NID_id_pkix 127 +#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L + +#define SN_id_pkix_mod "id-pkix-mod" +#define NID_id_pkix_mod 258 +#define OBJ_id_pkix_mod OBJ_id_pkix,0L + +#define SN_id_pe "id-pe" +#define NID_id_pe 175 +#define OBJ_id_pe OBJ_id_pkix,1L + +#define SN_id_qt "id-qt" +#define NID_id_qt 259 +#define OBJ_id_qt OBJ_id_pkix,2L + +#define SN_id_kp "id-kp" +#define NID_id_kp 128 +#define OBJ_id_kp OBJ_id_pkix,3L + +#define SN_id_it "id-it" +#define NID_id_it 260 +#define OBJ_id_it OBJ_id_pkix,4L + +#define SN_id_pkip "id-pkip" +#define NID_id_pkip 261 +#define OBJ_id_pkip OBJ_id_pkix,5L + +#define SN_id_alg "id-alg" +#define NID_id_alg 262 +#define OBJ_id_alg OBJ_id_pkix,6L + +#define SN_id_cmc "id-cmc" +#define NID_id_cmc 263 +#define OBJ_id_cmc OBJ_id_pkix,7L + +#define SN_id_on "id-on" +#define NID_id_on 264 +#define OBJ_id_on OBJ_id_pkix,8L + +#define SN_id_pda "id-pda" +#define NID_id_pda 265 +#define OBJ_id_pda OBJ_id_pkix,9L + +#define SN_id_aca "id-aca" +#define NID_id_aca 266 +#define OBJ_id_aca OBJ_id_pkix,10L + +#define SN_id_qcs "id-qcs" +#define NID_id_qcs 267 +#define OBJ_id_qcs OBJ_id_pkix,11L + +#define SN_id_cct "id-cct" +#define NID_id_cct 268 +#define OBJ_id_cct OBJ_id_pkix,12L + +#define SN_id_ppl "id-ppl" +#define NID_id_ppl 662 +#define OBJ_id_ppl OBJ_id_pkix,21L + +#define SN_id_ad "id-ad" +#define NID_id_ad 176 +#define OBJ_id_ad OBJ_id_pkix,48L + +#define SN_id_pkix1_explicit_88 "id-pkix1-explicit-88" +#define NID_id_pkix1_explicit_88 269 +#define OBJ_id_pkix1_explicit_88 OBJ_id_pkix_mod,1L + +#define SN_id_pkix1_implicit_88 "id-pkix1-implicit-88" +#define NID_id_pkix1_implicit_88 270 +#define OBJ_id_pkix1_implicit_88 OBJ_id_pkix_mod,2L + +#define SN_id_pkix1_explicit_93 "id-pkix1-explicit-93" +#define NID_id_pkix1_explicit_93 271 +#define OBJ_id_pkix1_explicit_93 OBJ_id_pkix_mod,3L + +#define SN_id_pkix1_implicit_93 "id-pkix1-implicit-93" +#define NID_id_pkix1_implicit_93 272 +#define OBJ_id_pkix1_implicit_93 OBJ_id_pkix_mod,4L + +#define SN_id_mod_crmf "id-mod-crmf" +#define NID_id_mod_crmf 273 +#define OBJ_id_mod_crmf OBJ_id_pkix_mod,5L + +#define SN_id_mod_cmc "id-mod-cmc" +#define NID_id_mod_cmc 274 +#define OBJ_id_mod_cmc OBJ_id_pkix_mod,6L + +#define SN_id_mod_kea_profile_88 "id-mod-kea-profile-88" +#define NID_id_mod_kea_profile_88 275 +#define OBJ_id_mod_kea_profile_88 OBJ_id_pkix_mod,7L + +#define SN_id_mod_kea_profile_93 "id-mod-kea-profile-93" +#define NID_id_mod_kea_profile_93 276 +#define OBJ_id_mod_kea_profile_93 OBJ_id_pkix_mod,8L + +#define SN_id_mod_cmp "id-mod-cmp" +#define NID_id_mod_cmp 277 +#define OBJ_id_mod_cmp OBJ_id_pkix_mod,9L + +#define SN_id_mod_qualified_cert_88 "id-mod-qualified-cert-88" +#define NID_id_mod_qualified_cert_88 278 +#define OBJ_id_mod_qualified_cert_88 OBJ_id_pkix_mod,10L + +#define SN_id_mod_qualified_cert_93 "id-mod-qualified-cert-93" +#define NID_id_mod_qualified_cert_93 279 +#define OBJ_id_mod_qualified_cert_93 OBJ_id_pkix_mod,11L + +#define SN_id_mod_attribute_cert "id-mod-attribute-cert" +#define NID_id_mod_attribute_cert 280 +#define OBJ_id_mod_attribute_cert OBJ_id_pkix_mod,12L + +#define SN_id_mod_timestamp_protocol "id-mod-timestamp-protocol" +#define NID_id_mod_timestamp_protocol 281 +#define OBJ_id_mod_timestamp_protocol OBJ_id_pkix_mod,13L + +#define SN_id_mod_ocsp "id-mod-ocsp" +#define NID_id_mod_ocsp 282 +#define OBJ_id_mod_ocsp OBJ_id_pkix_mod,14L + +#define SN_id_mod_dvcs "id-mod-dvcs" +#define NID_id_mod_dvcs 283 +#define OBJ_id_mod_dvcs OBJ_id_pkix_mod,15L + +#define SN_id_mod_cmp2000 "id-mod-cmp2000" +#define NID_id_mod_cmp2000 284 +#define OBJ_id_mod_cmp2000 OBJ_id_pkix_mod,16L + +#define SN_info_access "authorityInfoAccess" +#define LN_info_access "Authority Information Access" +#define NID_info_access 177 +#define OBJ_info_access OBJ_id_pe,1L + +#define SN_biometricInfo "biometricInfo" +#define LN_biometricInfo "Biometric Info" +#define NID_biometricInfo 285 +#define OBJ_biometricInfo OBJ_id_pe,2L + +#define SN_qcStatements "qcStatements" +#define NID_qcStatements 286 +#define OBJ_qcStatements OBJ_id_pe,3L + +#define SN_ac_auditEntity "ac-auditEntity" +#define NID_ac_auditEntity 287 +#define OBJ_ac_auditEntity OBJ_id_pe,4L + +#define SN_ac_targeting "ac-targeting" +#define NID_ac_targeting 288 +#define OBJ_ac_targeting OBJ_id_pe,5L + +#define SN_aaControls "aaControls" +#define NID_aaControls 289 +#define OBJ_aaControls OBJ_id_pe,6L + +#define SN_sbgp_ipAddrBlock "sbgp-ipAddrBlock" +#define NID_sbgp_ipAddrBlock 290 +#define OBJ_sbgp_ipAddrBlock OBJ_id_pe,7L + +#define SN_sbgp_autonomousSysNum "sbgp-autonomousSysNum" +#define NID_sbgp_autonomousSysNum 291 +#define OBJ_sbgp_autonomousSysNum OBJ_id_pe,8L + +#define SN_sbgp_routerIdentifier "sbgp-routerIdentifier" +#define NID_sbgp_routerIdentifier 292 +#define OBJ_sbgp_routerIdentifier OBJ_id_pe,9L + +#define SN_ac_proxying "ac-proxying" +#define NID_ac_proxying 397 +#define OBJ_ac_proxying OBJ_id_pe,10L + +#define SN_sinfo_access "subjectInfoAccess" +#define LN_sinfo_access "Subject Information Access" +#define NID_sinfo_access 398 +#define OBJ_sinfo_access OBJ_id_pe,11L + +#define SN_proxyCertInfo "proxyCertInfo" +#define LN_proxyCertInfo "Proxy Certificate Information" +#define NID_proxyCertInfo 663 +#define OBJ_proxyCertInfo OBJ_id_pe,14L + +#define SN_tlsfeature "tlsfeature" +#define LN_tlsfeature "TLS Feature" +#define NID_tlsfeature 1020 +#define OBJ_tlsfeature OBJ_id_pe,24L + +#define SN_id_qt_cps "id-qt-cps" +#define LN_id_qt_cps "Policy Qualifier CPS" +#define NID_id_qt_cps 164 +#define OBJ_id_qt_cps OBJ_id_qt,1L + +#define SN_id_qt_unotice "id-qt-unotice" +#define LN_id_qt_unotice "Policy Qualifier User Notice" +#define NID_id_qt_unotice 165 +#define OBJ_id_qt_unotice OBJ_id_qt,2L + +#define SN_textNotice "textNotice" +#define NID_textNotice 293 +#define OBJ_textNotice OBJ_id_qt,3L + +#define SN_server_auth "serverAuth" +#define LN_server_auth "TLS Web Server Authentication" +#define NID_server_auth 129 +#define OBJ_server_auth OBJ_id_kp,1L + +#define SN_client_auth "clientAuth" +#define LN_client_auth "TLS Web Client Authentication" +#define NID_client_auth 130 +#define OBJ_client_auth OBJ_id_kp,2L + +#define SN_code_sign "codeSigning" +#define LN_code_sign "Code Signing" +#define NID_code_sign 131 +#define OBJ_code_sign OBJ_id_kp,3L + +#define SN_email_protect "emailProtection" +#define LN_email_protect "E-mail Protection" +#define NID_email_protect 132 +#define OBJ_email_protect OBJ_id_kp,4L + +#define SN_ipsecEndSystem "ipsecEndSystem" +#define LN_ipsecEndSystem "IPSec End System" +#define NID_ipsecEndSystem 294 +#define OBJ_ipsecEndSystem OBJ_id_kp,5L + +#define SN_ipsecTunnel "ipsecTunnel" +#define LN_ipsecTunnel "IPSec Tunnel" +#define NID_ipsecTunnel 295 +#define OBJ_ipsecTunnel OBJ_id_kp,6L + +#define SN_ipsecUser "ipsecUser" +#define LN_ipsecUser "IPSec User" +#define NID_ipsecUser 296 +#define OBJ_ipsecUser OBJ_id_kp,7L + +#define SN_time_stamp "timeStamping" +#define LN_time_stamp "Time Stamping" +#define NID_time_stamp 133 +#define OBJ_time_stamp OBJ_id_kp,8L + +#define SN_OCSP_sign "OCSPSigning" +#define LN_OCSP_sign "OCSP Signing" +#define NID_OCSP_sign 180 +#define OBJ_OCSP_sign OBJ_id_kp,9L + +#define SN_dvcs "DVCS" +#define LN_dvcs "dvcs" +#define NID_dvcs 297 +#define OBJ_dvcs OBJ_id_kp,10L + +#define SN_ipsec_IKE "ipsecIKE" +#define LN_ipsec_IKE "ipsec Internet Key Exchange" +#define NID_ipsec_IKE 1022 +#define OBJ_ipsec_IKE OBJ_id_kp,17L + +#define SN_capwapAC "capwapAC" +#define LN_capwapAC "Ctrl/provision WAP Access" +#define NID_capwapAC 1023 +#define OBJ_capwapAC OBJ_id_kp,18L + +#define SN_capwapWTP "capwapWTP" +#define LN_capwapWTP "Ctrl/Provision WAP Termination" +#define NID_capwapWTP 1024 +#define OBJ_capwapWTP OBJ_id_kp,19L + +#define SN_sshClient "secureShellClient" +#define LN_sshClient "SSH Client" +#define NID_sshClient 1025 +#define OBJ_sshClient OBJ_id_kp,21L + +#define SN_sshServer "secureShellServer" +#define LN_sshServer "SSH Server" +#define NID_sshServer 1026 +#define OBJ_sshServer OBJ_id_kp,22L + +#define SN_sendRouter "sendRouter" +#define LN_sendRouter "Send Router" +#define NID_sendRouter 1027 +#define OBJ_sendRouter OBJ_id_kp,23L + +#define SN_sendProxiedRouter "sendProxiedRouter" +#define LN_sendProxiedRouter "Send Proxied Router" +#define NID_sendProxiedRouter 1028 +#define OBJ_sendProxiedRouter OBJ_id_kp,24L + +#define SN_sendOwner "sendOwner" +#define LN_sendOwner "Send Owner" +#define NID_sendOwner 1029 +#define OBJ_sendOwner OBJ_id_kp,25L + +#define SN_sendProxiedOwner "sendProxiedOwner" +#define LN_sendProxiedOwner "Send Proxied Owner" +#define NID_sendProxiedOwner 1030 +#define OBJ_sendProxiedOwner OBJ_id_kp,26L + +#define SN_id_it_caProtEncCert "id-it-caProtEncCert" +#define NID_id_it_caProtEncCert 298 +#define OBJ_id_it_caProtEncCert OBJ_id_it,1L + +#define SN_id_it_signKeyPairTypes "id-it-signKeyPairTypes" +#define NID_id_it_signKeyPairTypes 299 +#define OBJ_id_it_signKeyPairTypes OBJ_id_it,2L + +#define SN_id_it_encKeyPairTypes "id-it-encKeyPairTypes" +#define NID_id_it_encKeyPairTypes 300 +#define OBJ_id_it_encKeyPairTypes OBJ_id_it,3L + +#define SN_id_it_preferredSymmAlg "id-it-preferredSymmAlg" +#define NID_id_it_preferredSymmAlg 301 +#define OBJ_id_it_preferredSymmAlg OBJ_id_it,4L + +#define SN_id_it_caKeyUpdateInfo "id-it-caKeyUpdateInfo" +#define NID_id_it_caKeyUpdateInfo 302 +#define OBJ_id_it_caKeyUpdateInfo OBJ_id_it,5L + +#define SN_id_it_currentCRL "id-it-currentCRL" +#define NID_id_it_currentCRL 303 +#define OBJ_id_it_currentCRL OBJ_id_it,6L + +#define SN_id_it_unsupportedOIDs "id-it-unsupportedOIDs" +#define NID_id_it_unsupportedOIDs 304 +#define OBJ_id_it_unsupportedOIDs OBJ_id_it,7L + +#define SN_id_it_subscriptionRequest "id-it-subscriptionRequest" +#define NID_id_it_subscriptionRequest 305 +#define OBJ_id_it_subscriptionRequest OBJ_id_it,8L + +#define SN_id_it_subscriptionResponse "id-it-subscriptionResponse" +#define NID_id_it_subscriptionResponse 306 +#define OBJ_id_it_subscriptionResponse OBJ_id_it,9L + +#define SN_id_it_keyPairParamReq "id-it-keyPairParamReq" +#define NID_id_it_keyPairParamReq 307 +#define OBJ_id_it_keyPairParamReq OBJ_id_it,10L + +#define SN_id_it_keyPairParamRep "id-it-keyPairParamRep" +#define NID_id_it_keyPairParamRep 308 +#define OBJ_id_it_keyPairParamRep OBJ_id_it,11L + +#define SN_id_it_revPassphrase "id-it-revPassphrase" +#define NID_id_it_revPassphrase 309 +#define OBJ_id_it_revPassphrase OBJ_id_it,12L + +#define SN_id_it_implicitConfirm "id-it-implicitConfirm" +#define NID_id_it_implicitConfirm 310 +#define OBJ_id_it_implicitConfirm OBJ_id_it,13L + +#define SN_id_it_confirmWaitTime "id-it-confirmWaitTime" +#define NID_id_it_confirmWaitTime 311 +#define OBJ_id_it_confirmWaitTime OBJ_id_it,14L + +#define SN_id_it_origPKIMessage "id-it-origPKIMessage" +#define NID_id_it_origPKIMessage 312 +#define OBJ_id_it_origPKIMessage OBJ_id_it,15L + +#define SN_id_it_suppLangTags "id-it-suppLangTags" +#define NID_id_it_suppLangTags 784 +#define OBJ_id_it_suppLangTags OBJ_id_it,16L + +#define SN_id_regCtrl "id-regCtrl" +#define NID_id_regCtrl 313 +#define OBJ_id_regCtrl OBJ_id_pkip,1L + +#define SN_id_regInfo "id-regInfo" +#define NID_id_regInfo 314 +#define OBJ_id_regInfo OBJ_id_pkip,2L + +#define SN_id_regCtrl_regToken "id-regCtrl-regToken" +#define NID_id_regCtrl_regToken 315 +#define OBJ_id_regCtrl_regToken OBJ_id_regCtrl,1L + +#define SN_id_regCtrl_authenticator "id-regCtrl-authenticator" +#define NID_id_regCtrl_authenticator 316 +#define OBJ_id_regCtrl_authenticator OBJ_id_regCtrl,2L + +#define SN_id_regCtrl_pkiPublicationInfo "id-regCtrl-pkiPublicationInfo" +#define NID_id_regCtrl_pkiPublicationInfo 317 +#define OBJ_id_regCtrl_pkiPublicationInfo OBJ_id_regCtrl,3L + +#define SN_id_regCtrl_pkiArchiveOptions "id-regCtrl-pkiArchiveOptions" +#define NID_id_regCtrl_pkiArchiveOptions 318 +#define OBJ_id_regCtrl_pkiArchiveOptions OBJ_id_regCtrl,4L + +#define SN_id_regCtrl_oldCertID "id-regCtrl-oldCertID" +#define NID_id_regCtrl_oldCertID 319 +#define OBJ_id_regCtrl_oldCertID OBJ_id_regCtrl,5L + +#define SN_id_regCtrl_protocolEncrKey "id-regCtrl-protocolEncrKey" +#define NID_id_regCtrl_protocolEncrKey 320 +#define OBJ_id_regCtrl_protocolEncrKey OBJ_id_regCtrl,6L + +#define SN_id_regInfo_utf8Pairs "id-regInfo-utf8Pairs" +#define NID_id_regInfo_utf8Pairs 321 +#define OBJ_id_regInfo_utf8Pairs OBJ_id_regInfo,1L + +#define SN_id_regInfo_certReq "id-regInfo-certReq" +#define NID_id_regInfo_certReq 322 +#define OBJ_id_regInfo_certReq OBJ_id_regInfo,2L + +#define SN_id_alg_des40 "id-alg-des40" +#define NID_id_alg_des40 323 +#define OBJ_id_alg_des40 OBJ_id_alg,1L + +#define SN_id_alg_noSignature "id-alg-noSignature" +#define NID_id_alg_noSignature 324 +#define OBJ_id_alg_noSignature OBJ_id_alg,2L + +#define SN_id_alg_dh_sig_hmac_sha1 "id-alg-dh-sig-hmac-sha1" +#define NID_id_alg_dh_sig_hmac_sha1 325 +#define OBJ_id_alg_dh_sig_hmac_sha1 OBJ_id_alg,3L + +#define SN_id_alg_dh_pop "id-alg-dh-pop" +#define NID_id_alg_dh_pop 326 +#define OBJ_id_alg_dh_pop OBJ_id_alg,4L + +#define SN_id_cmc_statusInfo "id-cmc-statusInfo" +#define NID_id_cmc_statusInfo 327 +#define OBJ_id_cmc_statusInfo OBJ_id_cmc,1L + +#define SN_id_cmc_identification "id-cmc-identification" +#define NID_id_cmc_identification 328 +#define OBJ_id_cmc_identification OBJ_id_cmc,2L + +#define SN_id_cmc_identityProof "id-cmc-identityProof" +#define NID_id_cmc_identityProof 329 +#define OBJ_id_cmc_identityProof OBJ_id_cmc,3L + +#define SN_id_cmc_dataReturn "id-cmc-dataReturn" +#define NID_id_cmc_dataReturn 330 +#define OBJ_id_cmc_dataReturn OBJ_id_cmc,4L + +#define SN_id_cmc_transactionId "id-cmc-transactionId" +#define NID_id_cmc_transactionId 331 +#define OBJ_id_cmc_transactionId OBJ_id_cmc,5L + +#define SN_id_cmc_senderNonce "id-cmc-senderNonce" +#define NID_id_cmc_senderNonce 332 +#define OBJ_id_cmc_senderNonce OBJ_id_cmc,6L + +#define SN_id_cmc_recipientNonce "id-cmc-recipientNonce" +#define NID_id_cmc_recipientNonce 333 +#define OBJ_id_cmc_recipientNonce OBJ_id_cmc,7L + +#define SN_id_cmc_addExtensions "id-cmc-addExtensions" +#define NID_id_cmc_addExtensions 334 +#define OBJ_id_cmc_addExtensions OBJ_id_cmc,8L + +#define SN_id_cmc_encryptedPOP "id-cmc-encryptedPOP" +#define NID_id_cmc_encryptedPOP 335 +#define OBJ_id_cmc_encryptedPOP OBJ_id_cmc,9L + +#define SN_id_cmc_decryptedPOP "id-cmc-decryptedPOP" +#define NID_id_cmc_decryptedPOP 336 +#define OBJ_id_cmc_decryptedPOP OBJ_id_cmc,10L + +#define SN_id_cmc_lraPOPWitness "id-cmc-lraPOPWitness" +#define NID_id_cmc_lraPOPWitness 337 +#define OBJ_id_cmc_lraPOPWitness OBJ_id_cmc,11L + +#define SN_id_cmc_getCert "id-cmc-getCert" +#define NID_id_cmc_getCert 338 +#define OBJ_id_cmc_getCert OBJ_id_cmc,15L + +#define SN_id_cmc_getCRL "id-cmc-getCRL" +#define NID_id_cmc_getCRL 339 +#define OBJ_id_cmc_getCRL OBJ_id_cmc,16L + +#define SN_id_cmc_revokeRequest "id-cmc-revokeRequest" +#define NID_id_cmc_revokeRequest 340 +#define OBJ_id_cmc_revokeRequest OBJ_id_cmc,17L + +#define SN_id_cmc_regInfo "id-cmc-regInfo" +#define NID_id_cmc_regInfo 341 +#define OBJ_id_cmc_regInfo OBJ_id_cmc,18L + +#define SN_id_cmc_responseInfo "id-cmc-responseInfo" +#define NID_id_cmc_responseInfo 342 +#define OBJ_id_cmc_responseInfo OBJ_id_cmc,19L + +#define SN_id_cmc_queryPending "id-cmc-queryPending" +#define NID_id_cmc_queryPending 343 +#define OBJ_id_cmc_queryPending OBJ_id_cmc,21L + +#define SN_id_cmc_popLinkRandom "id-cmc-popLinkRandom" +#define NID_id_cmc_popLinkRandom 344 +#define OBJ_id_cmc_popLinkRandom OBJ_id_cmc,22L + +#define SN_id_cmc_popLinkWitness "id-cmc-popLinkWitness" +#define NID_id_cmc_popLinkWitness 345 +#define OBJ_id_cmc_popLinkWitness OBJ_id_cmc,23L + +#define SN_id_cmc_confirmCertAcceptance "id-cmc-confirmCertAcceptance" +#define NID_id_cmc_confirmCertAcceptance 346 +#define OBJ_id_cmc_confirmCertAcceptance OBJ_id_cmc,24L + +#define SN_id_on_personalData "id-on-personalData" +#define NID_id_on_personalData 347 +#define OBJ_id_on_personalData OBJ_id_on,1L + +#define SN_id_on_permanentIdentifier "id-on-permanentIdentifier" +#define LN_id_on_permanentIdentifier "Permanent Identifier" +#define NID_id_on_permanentIdentifier 858 +#define OBJ_id_on_permanentIdentifier OBJ_id_on,3L + +#define SN_id_pda_dateOfBirth "id-pda-dateOfBirth" +#define NID_id_pda_dateOfBirth 348 +#define OBJ_id_pda_dateOfBirth OBJ_id_pda,1L + +#define SN_id_pda_placeOfBirth "id-pda-placeOfBirth" +#define NID_id_pda_placeOfBirth 349 +#define OBJ_id_pda_placeOfBirth OBJ_id_pda,2L + +#define SN_id_pda_gender "id-pda-gender" +#define NID_id_pda_gender 351 +#define OBJ_id_pda_gender OBJ_id_pda,3L + +#define SN_id_pda_countryOfCitizenship "id-pda-countryOfCitizenship" +#define NID_id_pda_countryOfCitizenship 352 +#define OBJ_id_pda_countryOfCitizenship OBJ_id_pda,4L + +#define SN_id_pda_countryOfResidence "id-pda-countryOfResidence" +#define NID_id_pda_countryOfResidence 353 +#define OBJ_id_pda_countryOfResidence OBJ_id_pda,5L + +#define SN_id_aca_authenticationInfo "id-aca-authenticationInfo" +#define NID_id_aca_authenticationInfo 354 +#define OBJ_id_aca_authenticationInfo OBJ_id_aca,1L + +#define SN_id_aca_accessIdentity "id-aca-accessIdentity" +#define NID_id_aca_accessIdentity 355 +#define OBJ_id_aca_accessIdentity OBJ_id_aca,2L + +#define SN_id_aca_chargingIdentity "id-aca-chargingIdentity" +#define NID_id_aca_chargingIdentity 356 +#define OBJ_id_aca_chargingIdentity OBJ_id_aca,3L + +#define SN_id_aca_group "id-aca-group" +#define NID_id_aca_group 357 +#define OBJ_id_aca_group OBJ_id_aca,4L + +#define SN_id_aca_role "id-aca-role" +#define NID_id_aca_role 358 +#define OBJ_id_aca_role OBJ_id_aca,5L + +#define SN_id_aca_encAttrs "id-aca-encAttrs" +#define NID_id_aca_encAttrs 399 +#define OBJ_id_aca_encAttrs OBJ_id_aca,6L + +#define SN_id_qcs_pkixQCSyntax_v1 "id-qcs-pkixQCSyntax-v1" +#define NID_id_qcs_pkixQCSyntax_v1 359 +#define OBJ_id_qcs_pkixQCSyntax_v1 OBJ_id_qcs,1L + +#define SN_id_cct_crs "id-cct-crs" +#define NID_id_cct_crs 360 +#define OBJ_id_cct_crs OBJ_id_cct,1L + +#define SN_id_cct_PKIData "id-cct-PKIData" +#define NID_id_cct_PKIData 361 +#define OBJ_id_cct_PKIData OBJ_id_cct,2L + +#define SN_id_cct_PKIResponse "id-cct-PKIResponse" +#define NID_id_cct_PKIResponse 362 +#define OBJ_id_cct_PKIResponse OBJ_id_cct,3L + +#define SN_id_ppl_anyLanguage "id-ppl-anyLanguage" +#define LN_id_ppl_anyLanguage "Any language" +#define NID_id_ppl_anyLanguage 664 +#define OBJ_id_ppl_anyLanguage OBJ_id_ppl,0L + +#define SN_id_ppl_inheritAll "id-ppl-inheritAll" +#define LN_id_ppl_inheritAll "Inherit all" +#define NID_id_ppl_inheritAll 665 +#define OBJ_id_ppl_inheritAll OBJ_id_ppl,1L + +#define SN_Independent "id-ppl-independent" +#define LN_Independent "Independent" +#define NID_Independent 667 +#define OBJ_Independent OBJ_id_ppl,2L + +#define SN_ad_OCSP "OCSP" +#define LN_ad_OCSP "OCSP" +#define NID_ad_OCSP 178 +#define OBJ_ad_OCSP OBJ_id_ad,1L + +#define SN_ad_ca_issuers "caIssuers" +#define LN_ad_ca_issuers "CA Issuers" +#define NID_ad_ca_issuers 179 +#define OBJ_ad_ca_issuers OBJ_id_ad,2L + +#define SN_ad_timeStamping "ad_timestamping" +#define LN_ad_timeStamping "AD Time Stamping" +#define NID_ad_timeStamping 363 +#define OBJ_ad_timeStamping OBJ_id_ad,3L + +#define SN_ad_dvcs "AD_DVCS" +#define LN_ad_dvcs "ad dvcs" +#define NID_ad_dvcs 364 +#define OBJ_ad_dvcs OBJ_id_ad,4L + +#define SN_caRepository "caRepository" +#define LN_caRepository "CA Repository" +#define NID_caRepository 785 +#define OBJ_caRepository OBJ_id_ad,5L + +#define OBJ_id_pkix_OCSP OBJ_ad_OCSP + +#define SN_id_pkix_OCSP_basic "basicOCSPResponse" +#define LN_id_pkix_OCSP_basic "Basic OCSP Response" +#define NID_id_pkix_OCSP_basic 365 +#define OBJ_id_pkix_OCSP_basic OBJ_id_pkix_OCSP,1L + +#define SN_id_pkix_OCSP_Nonce "Nonce" +#define LN_id_pkix_OCSP_Nonce "OCSP Nonce" +#define NID_id_pkix_OCSP_Nonce 366 +#define OBJ_id_pkix_OCSP_Nonce OBJ_id_pkix_OCSP,2L + +#define SN_id_pkix_OCSP_CrlID "CrlID" +#define LN_id_pkix_OCSP_CrlID "OCSP CRL ID" +#define NID_id_pkix_OCSP_CrlID 367 +#define OBJ_id_pkix_OCSP_CrlID OBJ_id_pkix_OCSP,3L + +#define SN_id_pkix_OCSP_acceptableResponses "acceptableResponses" +#define LN_id_pkix_OCSP_acceptableResponses "Acceptable OCSP Responses" +#define NID_id_pkix_OCSP_acceptableResponses 368 +#define OBJ_id_pkix_OCSP_acceptableResponses OBJ_id_pkix_OCSP,4L + +#define SN_id_pkix_OCSP_noCheck "noCheck" +#define LN_id_pkix_OCSP_noCheck "OCSP No Check" +#define NID_id_pkix_OCSP_noCheck 369 +#define OBJ_id_pkix_OCSP_noCheck OBJ_id_pkix_OCSP,5L + +#define SN_id_pkix_OCSP_archiveCutoff "archiveCutoff" +#define LN_id_pkix_OCSP_archiveCutoff "OCSP Archive Cutoff" +#define NID_id_pkix_OCSP_archiveCutoff 370 +#define OBJ_id_pkix_OCSP_archiveCutoff OBJ_id_pkix_OCSP,6L + +#define SN_id_pkix_OCSP_serviceLocator "serviceLocator" +#define LN_id_pkix_OCSP_serviceLocator "OCSP Service Locator" +#define NID_id_pkix_OCSP_serviceLocator 371 +#define OBJ_id_pkix_OCSP_serviceLocator OBJ_id_pkix_OCSP,7L + +#define SN_id_pkix_OCSP_extendedStatus "extendedStatus" +#define LN_id_pkix_OCSP_extendedStatus "Extended OCSP Status" +#define NID_id_pkix_OCSP_extendedStatus 372 +#define OBJ_id_pkix_OCSP_extendedStatus OBJ_id_pkix_OCSP,8L + +#define SN_id_pkix_OCSP_valid "valid" +#define NID_id_pkix_OCSP_valid 373 +#define OBJ_id_pkix_OCSP_valid OBJ_id_pkix_OCSP,9L + +#define SN_id_pkix_OCSP_path "path" +#define NID_id_pkix_OCSP_path 374 +#define OBJ_id_pkix_OCSP_path OBJ_id_pkix_OCSP,10L + +#define SN_id_pkix_OCSP_trustRoot "trustRoot" +#define LN_id_pkix_OCSP_trustRoot "Trust Root" +#define NID_id_pkix_OCSP_trustRoot 375 +#define OBJ_id_pkix_OCSP_trustRoot OBJ_id_pkix_OCSP,11L + +#define SN_algorithm "algorithm" +#define LN_algorithm "algorithm" +#define NID_algorithm 376 +#define OBJ_algorithm 1L,3L,14L,3L,2L + +#define SN_md5WithRSA "RSA-NP-MD5" +#define LN_md5WithRSA "md5WithRSA" +#define NID_md5WithRSA 104 +#define OBJ_md5WithRSA OBJ_algorithm,3L + +#define SN_des_ecb "DES-ECB" +#define LN_des_ecb "des-ecb" +#define NID_des_ecb 29 +#define OBJ_des_ecb OBJ_algorithm,6L + +#define SN_des_cbc "DES-CBC" +#define LN_des_cbc "des-cbc" +#define NID_des_cbc 31 +#define OBJ_des_cbc OBJ_algorithm,7L + +#define SN_des_ofb64 "DES-OFB" +#define LN_des_ofb64 "des-ofb" +#define NID_des_ofb64 45 +#define OBJ_des_ofb64 OBJ_algorithm,8L + +#define SN_des_cfb64 "DES-CFB" +#define LN_des_cfb64 "des-cfb" +#define NID_des_cfb64 30 +#define OBJ_des_cfb64 OBJ_algorithm,9L + +#define SN_rsaSignature "rsaSignature" +#define NID_rsaSignature 377 +#define OBJ_rsaSignature OBJ_algorithm,11L + +#define SN_dsa_2 "DSA-old" +#define LN_dsa_2 "dsaEncryption-old" +#define NID_dsa_2 67 +#define OBJ_dsa_2 OBJ_algorithm,12L + +#define SN_dsaWithSHA "DSA-SHA" +#define LN_dsaWithSHA "dsaWithSHA" +#define NID_dsaWithSHA 66 +#define OBJ_dsaWithSHA OBJ_algorithm,13L + +#define SN_shaWithRSAEncryption "RSA-SHA" +#define LN_shaWithRSAEncryption "shaWithRSAEncryption" +#define NID_shaWithRSAEncryption 42 +#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L + +#define SN_des_ede_ecb "DES-EDE" +#define LN_des_ede_ecb "des-ede" +#define NID_des_ede_ecb 32 +#define OBJ_des_ede_ecb OBJ_algorithm,17L + +#define SN_des_ede3_ecb "DES-EDE3" +#define LN_des_ede3_ecb "des-ede3" +#define NID_des_ede3_ecb 33 + +#define SN_des_ede_cbc "DES-EDE-CBC" +#define LN_des_ede_cbc "des-ede-cbc" +#define NID_des_ede_cbc 43 + +#define SN_des_ede_cfb64 "DES-EDE-CFB" +#define LN_des_ede_cfb64 "des-ede-cfb" +#define NID_des_ede_cfb64 60 + +#define SN_des_ede3_cfb64 "DES-EDE3-CFB" +#define LN_des_ede3_cfb64 "des-ede3-cfb" +#define NID_des_ede3_cfb64 61 + +#define SN_des_ede_ofb64 "DES-EDE-OFB" +#define LN_des_ede_ofb64 "des-ede-ofb" +#define NID_des_ede_ofb64 62 + +#define SN_des_ede3_ofb64 "DES-EDE3-OFB" +#define LN_des_ede3_ofb64 "des-ede3-ofb" +#define NID_des_ede3_ofb64 63 + +#define SN_desx_cbc "DESX-CBC" +#define LN_desx_cbc "desx-cbc" +#define NID_desx_cbc 80 + +#define SN_sha "SHA" +#define LN_sha "sha" +#define NID_sha 41 +#define OBJ_sha OBJ_algorithm,18L + +#define SN_sha1 "SHA1" +#define LN_sha1 "sha1" +#define NID_sha1 64 +#define OBJ_sha1 OBJ_algorithm,26L + +#define SN_dsaWithSHA1_2 "DSA-SHA1-old" +#define LN_dsaWithSHA1_2 "dsaWithSHA1-old" +#define NID_dsaWithSHA1_2 70 +#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L + +#define SN_sha1WithRSA "RSA-SHA1-2" +#define LN_sha1WithRSA "sha1WithRSA" +#define NID_sha1WithRSA 115 +#define OBJ_sha1WithRSA OBJ_algorithm,29L + +#define SN_ripemd160 "RIPEMD160" +#define LN_ripemd160 "ripemd160" +#define NID_ripemd160 117 +#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L + +#define SN_ripemd160WithRSA "RSA-RIPEMD160" +#define LN_ripemd160WithRSA "ripemd160WithRSA" +#define NID_ripemd160WithRSA 119 +#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L + +#define SN_blake2b512 "BLAKE2b512" +#define LN_blake2b512 "blake2b512" +#define NID_blake2b512 1056 +#define OBJ_blake2b512 1L,3L,6L,1L,4L,1L,1722L,12L,2L,1L,16L + +#define SN_blake2s256 "BLAKE2s256" +#define LN_blake2s256 "blake2s256" +#define NID_blake2s256 1057 +#define OBJ_blake2s256 1L,3L,6L,1L,4L,1L,1722L,12L,2L,2L,8L + +#define SN_sxnet "SXNetID" +#define LN_sxnet "Strong Extranet ID" +#define NID_sxnet 143 +#define OBJ_sxnet 1L,3L,101L,1L,4L,1L + +#define SN_X500 "X500" +#define LN_X500 "directory services (X.500)" +#define NID_X500 11 +#define OBJ_X500 2L,5L + +#define SN_X509 "X509" +#define NID_X509 12 +#define OBJ_X509 OBJ_X500,4L + +#define SN_commonName "CN" +#define LN_commonName "commonName" +#define NID_commonName 13 +#define OBJ_commonName OBJ_X509,3L + +#define SN_surname "SN" +#define LN_surname "surname" +#define NID_surname 100 +#define OBJ_surname OBJ_X509,4L + +#define LN_serialNumber "serialNumber" +#define NID_serialNumber 105 +#define OBJ_serialNumber OBJ_X509,5L + +#define SN_countryName "C" +#define LN_countryName "countryName" +#define NID_countryName 14 +#define OBJ_countryName OBJ_X509,6L + +#define SN_localityName "L" +#define LN_localityName "localityName" +#define NID_localityName 15 +#define OBJ_localityName OBJ_X509,7L + +#define SN_stateOrProvinceName "ST" +#define LN_stateOrProvinceName "stateOrProvinceName" +#define NID_stateOrProvinceName 16 +#define OBJ_stateOrProvinceName OBJ_X509,8L + +#define SN_streetAddress "street" +#define LN_streetAddress "streetAddress" +#define NID_streetAddress 660 +#define OBJ_streetAddress OBJ_X509,9L + +#define SN_organizationName "O" +#define LN_organizationName "organizationName" +#define NID_organizationName 17 +#define OBJ_organizationName OBJ_X509,10L + +#define SN_organizationalUnitName "OU" +#define LN_organizationalUnitName "organizationalUnitName" +#define NID_organizationalUnitName 18 +#define OBJ_organizationalUnitName OBJ_X509,11L + +#define SN_title "title" +#define LN_title "title" +#define NID_title 106 +#define OBJ_title OBJ_X509,12L + +#define LN_description "description" +#define NID_description 107 +#define OBJ_description OBJ_X509,13L + +#define LN_searchGuide "searchGuide" +#define NID_searchGuide 859 +#define OBJ_searchGuide OBJ_X509,14L + +#define LN_businessCategory "businessCategory" +#define NID_businessCategory 860 +#define OBJ_businessCategory OBJ_X509,15L + +#define LN_postalAddress "postalAddress" +#define NID_postalAddress 861 +#define OBJ_postalAddress OBJ_X509,16L + +#define LN_postalCode "postalCode" +#define NID_postalCode 661 +#define OBJ_postalCode OBJ_X509,17L + +#define LN_postOfficeBox "postOfficeBox" +#define NID_postOfficeBox 862 +#define OBJ_postOfficeBox OBJ_X509,18L + +#define LN_physicalDeliveryOfficeName "physicalDeliveryOfficeName" +#define NID_physicalDeliveryOfficeName 863 +#define OBJ_physicalDeliveryOfficeName OBJ_X509,19L + +#define LN_telephoneNumber "telephoneNumber" +#define NID_telephoneNumber 864 +#define OBJ_telephoneNumber OBJ_X509,20L + +#define LN_telexNumber "telexNumber" +#define NID_telexNumber 865 +#define OBJ_telexNumber OBJ_X509,21L + +#define LN_teletexTerminalIdentifier "teletexTerminalIdentifier" +#define NID_teletexTerminalIdentifier 866 +#define OBJ_teletexTerminalIdentifier OBJ_X509,22L + +#define LN_facsimileTelephoneNumber "facsimileTelephoneNumber" +#define NID_facsimileTelephoneNumber 867 +#define OBJ_facsimileTelephoneNumber OBJ_X509,23L + +#define LN_x121Address "x121Address" +#define NID_x121Address 868 +#define OBJ_x121Address OBJ_X509,24L + +#define LN_internationaliSDNNumber "internationaliSDNNumber" +#define NID_internationaliSDNNumber 869 +#define OBJ_internationaliSDNNumber OBJ_X509,25L + +#define LN_registeredAddress "registeredAddress" +#define NID_registeredAddress 870 +#define OBJ_registeredAddress OBJ_X509,26L + +#define LN_destinationIndicator "destinationIndicator" +#define NID_destinationIndicator 871 +#define OBJ_destinationIndicator OBJ_X509,27L + +#define LN_preferredDeliveryMethod "preferredDeliveryMethod" +#define NID_preferredDeliveryMethod 872 +#define OBJ_preferredDeliveryMethod OBJ_X509,28L + +#define LN_presentationAddress "presentationAddress" +#define NID_presentationAddress 873 +#define OBJ_presentationAddress OBJ_X509,29L + +#define LN_supportedApplicationContext "supportedApplicationContext" +#define NID_supportedApplicationContext 874 +#define OBJ_supportedApplicationContext OBJ_X509,30L + +#define SN_member "member" +#define NID_member 875 +#define OBJ_member OBJ_X509,31L + +#define SN_owner "owner" +#define NID_owner 876 +#define OBJ_owner OBJ_X509,32L + +#define LN_roleOccupant "roleOccupant" +#define NID_roleOccupant 877 +#define OBJ_roleOccupant OBJ_X509,33L + +#define SN_seeAlso "seeAlso" +#define NID_seeAlso 878 +#define OBJ_seeAlso OBJ_X509,34L + +#define LN_userPassword "userPassword" +#define NID_userPassword 879 +#define OBJ_userPassword OBJ_X509,35L + +#define LN_userCertificate "userCertificate" +#define NID_userCertificate 880 +#define OBJ_userCertificate OBJ_X509,36L + +#define LN_cACertificate "cACertificate" +#define NID_cACertificate 881 +#define OBJ_cACertificate OBJ_X509,37L + +#define LN_authorityRevocationList "authorityRevocationList" +#define NID_authorityRevocationList 882 +#define OBJ_authorityRevocationList OBJ_X509,38L + +#define LN_certificateRevocationList "certificateRevocationList" +#define NID_certificateRevocationList 883 +#define OBJ_certificateRevocationList OBJ_X509,39L + +#define LN_crossCertificatePair "crossCertificatePair" +#define NID_crossCertificatePair 884 +#define OBJ_crossCertificatePair OBJ_X509,40L + +#define SN_name "name" +#define LN_name "name" +#define NID_name 173 +#define OBJ_name OBJ_X509,41L + +#define SN_givenName "GN" +#define LN_givenName "givenName" +#define NID_givenName 99 +#define OBJ_givenName OBJ_X509,42L + +#define SN_initials "initials" +#define LN_initials "initials" +#define NID_initials 101 +#define OBJ_initials OBJ_X509,43L + +#define LN_generationQualifier "generationQualifier" +#define NID_generationQualifier 509 +#define OBJ_generationQualifier OBJ_X509,44L + +#define LN_x500UniqueIdentifier "x500UniqueIdentifier" +#define NID_x500UniqueIdentifier 503 +#define OBJ_x500UniqueIdentifier OBJ_X509,45L + +#define SN_dnQualifier "dnQualifier" +#define LN_dnQualifier "dnQualifier" +#define NID_dnQualifier 174 +#define OBJ_dnQualifier OBJ_X509,46L + +#define LN_enhancedSearchGuide "enhancedSearchGuide" +#define NID_enhancedSearchGuide 885 +#define OBJ_enhancedSearchGuide OBJ_X509,47L + +#define LN_protocolInformation "protocolInformation" +#define NID_protocolInformation 886 +#define OBJ_protocolInformation OBJ_X509,48L + +#define LN_distinguishedName "distinguishedName" +#define NID_distinguishedName 887 +#define OBJ_distinguishedName OBJ_X509,49L + +#define LN_uniqueMember "uniqueMember" +#define NID_uniqueMember 888 +#define OBJ_uniqueMember OBJ_X509,50L + +#define LN_houseIdentifier "houseIdentifier" +#define NID_houseIdentifier 889 +#define OBJ_houseIdentifier OBJ_X509,51L + +#define LN_supportedAlgorithms "supportedAlgorithms" +#define NID_supportedAlgorithms 890 +#define OBJ_supportedAlgorithms OBJ_X509,52L + +#define LN_deltaRevocationList "deltaRevocationList" +#define NID_deltaRevocationList 891 +#define OBJ_deltaRevocationList OBJ_X509,53L + +#define SN_dmdName "dmdName" +#define NID_dmdName 892 +#define OBJ_dmdName OBJ_X509,54L + +#define LN_pseudonym "pseudonym" +#define NID_pseudonym 510 +#define OBJ_pseudonym OBJ_X509,65L + +#define SN_role "role" +#define LN_role "role" +#define NID_role 400 +#define OBJ_role OBJ_X509,72L + +#define SN_X500algorithms "X500algorithms" +#define LN_X500algorithms "directory services - algorithms" +#define NID_X500algorithms 378 +#define OBJ_X500algorithms OBJ_X500,8L + +#define SN_rsa "RSA" +#define LN_rsa "rsa" +#define NID_rsa 19 +#define OBJ_rsa OBJ_X500algorithms,1L,1L + +#define SN_mdc2WithRSA "RSA-MDC2" +#define LN_mdc2WithRSA "mdc2WithRSA" +#define NID_mdc2WithRSA 96 +#define OBJ_mdc2WithRSA OBJ_X500algorithms,3L,100L + +#define SN_mdc2 "MDC2" +#define LN_mdc2 "mdc2" +#define NID_mdc2 95 +#define OBJ_mdc2 OBJ_X500algorithms,3L,101L + +#define SN_id_ce "id-ce" +#define NID_id_ce 81 +#define OBJ_id_ce OBJ_X500,29L + +#define SN_subject_directory_attributes "subjectDirectoryAttributes" +#define LN_subject_directory_attributes "X509v3 Subject Directory Attributes" +#define NID_subject_directory_attributes 769 +#define OBJ_subject_directory_attributes OBJ_id_ce,9L + +#define SN_subject_key_identifier "subjectKeyIdentifier" +#define LN_subject_key_identifier "X509v3 Subject Key Identifier" +#define NID_subject_key_identifier 82 +#define OBJ_subject_key_identifier OBJ_id_ce,14L + +#define SN_key_usage "keyUsage" +#define LN_key_usage "X509v3 Key Usage" +#define NID_key_usage 83 +#define OBJ_key_usage OBJ_id_ce,15L + +#define SN_private_key_usage_period "privateKeyUsagePeriod" +#define LN_private_key_usage_period "X509v3 Private Key Usage Period" +#define NID_private_key_usage_period 84 +#define OBJ_private_key_usage_period OBJ_id_ce,16L + +#define SN_subject_alt_name "subjectAltName" +#define LN_subject_alt_name "X509v3 Subject Alternative Name" +#define NID_subject_alt_name 85 +#define OBJ_subject_alt_name OBJ_id_ce,17L + +#define SN_issuer_alt_name "issuerAltName" +#define LN_issuer_alt_name "X509v3 Issuer Alternative Name" +#define NID_issuer_alt_name 86 +#define OBJ_issuer_alt_name OBJ_id_ce,18L + +#define SN_basic_constraints "basicConstraints" +#define LN_basic_constraints "X509v3 Basic Constraints" +#define NID_basic_constraints 87 +#define OBJ_basic_constraints OBJ_id_ce,19L + +#define SN_crl_number "crlNumber" +#define LN_crl_number "X509v3 CRL Number" +#define NID_crl_number 88 +#define OBJ_crl_number OBJ_id_ce,20L + +#define SN_crl_reason "CRLReason" +#define LN_crl_reason "X509v3 CRL Reason Code" +#define NID_crl_reason 141 +#define OBJ_crl_reason OBJ_id_ce,21L + +#define SN_invalidity_date "invalidityDate" +#define LN_invalidity_date "Invalidity Date" +#define NID_invalidity_date 142 +#define OBJ_invalidity_date OBJ_id_ce,24L + +#define SN_delta_crl "deltaCRL" +#define LN_delta_crl "X509v3 Delta CRL Indicator" +#define NID_delta_crl 140 +#define OBJ_delta_crl OBJ_id_ce,27L + +#define SN_issuing_distribution_point "issuingDistributionPoint" +#define LN_issuing_distribution_point "X509v3 Issuing Distribution Point" +#define NID_issuing_distribution_point 770 +#define OBJ_issuing_distribution_point OBJ_id_ce,28L + +#define SN_certificate_issuer "certificateIssuer" +#define LN_certificate_issuer "X509v3 Certificate Issuer" +#define NID_certificate_issuer 771 +#define OBJ_certificate_issuer OBJ_id_ce,29L + +#define SN_name_constraints "nameConstraints" +#define LN_name_constraints "X509v3 Name Constraints" +#define NID_name_constraints 666 +#define OBJ_name_constraints OBJ_id_ce,30L + +#define SN_crl_distribution_points "crlDistributionPoints" +#define LN_crl_distribution_points "X509v3 CRL Distribution Points" +#define NID_crl_distribution_points 103 +#define OBJ_crl_distribution_points OBJ_id_ce,31L + +#define SN_certificate_policies "certificatePolicies" +#define LN_certificate_policies "X509v3 Certificate Policies" +#define NID_certificate_policies 89 +#define OBJ_certificate_policies OBJ_id_ce,32L + +#define SN_any_policy "anyPolicy" +#define LN_any_policy "X509v3 Any Policy" +#define NID_any_policy 746 +#define OBJ_any_policy OBJ_certificate_policies,0L + +#define SN_policy_mappings "policyMappings" +#define LN_policy_mappings "X509v3 Policy Mappings" +#define NID_policy_mappings 747 +#define OBJ_policy_mappings OBJ_id_ce,33L + +#define SN_authority_key_identifier "authorityKeyIdentifier" +#define LN_authority_key_identifier "X509v3 Authority Key Identifier" +#define NID_authority_key_identifier 90 +#define OBJ_authority_key_identifier OBJ_id_ce,35L + +#define SN_policy_constraints "policyConstraints" +#define LN_policy_constraints "X509v3 Policy Constraints" +#define NID_policy_constraints 401 +#define OBJ_policy_constraints OBJ_id_ce,36L + +#define SN_ext_key_usage "extendedKeyUsage" +#define LN_ext_key_usage "X509v3 Extended Key Usage" +#define NID_ext_key_usage 126 +#define OBJ_ext_key_usage OBJ_id_ce,37L + +#define SN_freshest_crl "freshestCRL" +#define LN_freshest_crl "X509v3 Freshest CRL" +#define NID_freshest_crl 857 +#define OBJ_freshest_crl OBJ_id_ce,46L + +#define SN_inhibit_any_policy "inhibitAnyPolicy" +#define LN_inhibit_any_policy "X509v3 Inhibit Any Policy" +#define NID_inhibit_any_policy 748 +#define OBJ_inhibit_any_policy OBJ_id_ce,54L + +#define SN_target_information "targetInformation" +#define LN_target_information "X509v3 AC Targeting" +#define NID_target_information 402 +#define OBJ_target_information OBJ_id_ce,55L + +#define SN_no_rev_avail "noRevAvail" +#define LN_no_rev_avail "X509v3 No Revocation Available" +#define NID_no_rev_avail 403 +#define OBJ_no_rev_avail OBJ_id_ce,56L + +#define SN_anyExtendedKeyUsage "anyExtendedKeyUsage" +#define LN_anyExtendedKeyUsage "Any Extended Key Usage" +#define NID_anyExtendedKeyUsage 910 +#define OBJ_anyExtendedKeyUsage OBJ_ext_key_usage,0L + +#define SN_netscape "Netscape" +#define LN_netscape "Netscape Communications Corp." +#define NID_netscape 57 +#define OBJ_netscape 2L,16L,840L,1L,113730L + +#define SN_netscape_cert_extension "nsCertExt" +#define LN_netscape_cert_extension "Netscape Certificate Extension" +#define NID_netscape_cert_extension 58 +#define OBJ_netscape_cert_extension OBJ_netscape,1L + +#define SN_netscape_data_type "nsDataType" +#define LN_netscape_data_type "Netscape Data Type" +#define NID_netscape_data_type 59 +#define OBJ_netscape_data_type OBJ_netscape,2L + +#define SN_netscape_cert_type "nsCertType" +#define LN_netscape_cert_type "Netscape Cert Type" +#define NID_netscape_cert_type 71 +#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L + +#define SN_netscape_base_url "nsBaseUrl" +#define LN_netscape_base_url "Netscape Base Url" +#define NID_netscape_base_url 72 +#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L + +#define SN_netscape_revocation_url "nsRevocationUrl" +#define LN_netscape_revocation_url "Netscape Revocation Url" +#define NID_netscape_revocation_url 73 +#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L + +#define SN_netscape_ca_revocation_url "nsCaRevocationUrl" +#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url" +#define NID_netscape_ca_revocation_url 74 +#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L + +#define SN_netscape_renewal_url "nsRenewalUrl" +#define LN_netscape_renewal_url "Netscape Renewal Url" +#define NID_netscape_renewal_url 75 +#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L + +#define SN_netscape_ca_policy_url "nsCaPolicyUrl" +#define LN_netscape_ca_policy_url "Netscape CA Policy Url" +#define NID_netscape_ca_policy_url 76 +#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L + +#define SN_netscape_ssl_server_name "nsSslServerName" +#define LN_netscape_ssl_server_name "Netscape SSL Server Name" +#define NID_netscape_ssl_server_name 77 +#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L + +#define SN_netscape_comment "nsComment" +#define LN_netscape_comment "Netscape Comment" +#define NID_netscape_comment 78 +#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L + +#define SN_netscape_cert_sequence "nsCertSequence" +#define LN_netscape_cert_sequence "Netscape Certificate Sequence" +#define NID_netscape_cert_sequence 79 +#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L + +#define SN_ns_sgc "nsSGC" +#define LN_ns_sgc "Netscape Server Gated Crypto" +#define NID_ns_sgc 139 +#define OBJ_ns_sgc OBJ_netscape,4L,1L + +#define SN_org "ORG" +#define LN_org "org" +#define NID_org 379 +#define OBJ_org OBJ_iso,3L + +#define SN_dod "DOD" +#define LN_dod "dod" +#define NID_dod 380 +#define OBJ_dod OBJ_org,6L + +#define SN_iana "IANA" +#define LN_iana "iana" +#define NID_iana 381 +#define OBJ_iana OBJ_dod,1L + +#define OBJ_internet OBJ_iana + +#define SN_Directory "directory" +#define LN_Directory "Directory" +#define NID_Directory 382 +#define OBJ_Directory OBJ_internet,1L + +#define SN_Management "mgmt" +#define LN_Management "Management" +#define NID_Management 383 +#define OBJ_Management OBJ_internet,2L + +#define SN_Experimental "experimental" +#define LN_Experimental "Experimental" +#define NID_Experimental 384 +#define OBJ_Experimental OBJ_internet,3L + +#define SN_Private "private" +#define LN_Private "Private" +#define NID_Private 385 +#define OBJ_Private OBJ_internet,4L + +#define SN_Security "security" +#define LN_Security "Security" +#define NID_Security 386 +#define OBJ_Security OBJ_internet,5L + +#define SN_SNMPv2 "snmpv2" +#define LN_SNMPv2 "SNMPv2" +#define NID_SNMPv2 387 +#define OBJ_SNMPv2 OBJ_internet,6L + +#define LN_Mail "Mail" +#define NID_Mail 388 +#define OBJ_Mail OBJ_internet,7L + +#define SN_Enterprises "enterprises" +#define LN_Enterprises "Enterprises" +#define NID_Enterprises 389 +#define OBJ_Enterprises OBJ_Private,1L + +#define SN_dcObject "dcobject" +#define LN_dcObject "dcObject" +#define NID_dcObject 390 +#define OBJ_dcObject OBJ_Enterprises,1466L,344L + +#define SN_mime_mhs "mime-mhs" +#define LN_mime_mhs "MIME MHS" +#define NID_mime_mhs 504 +#define OBJ_mime_mhs OBJ_Mail,1L + +#define SN_mime_mhs_headings "mime-mhs-headings" +#define LN_mime_mhs_headings "mime-mhs-headings" +#define NID_mime_mhs_headings 505 +#define OBJ_mime_mhs_headings OBJ_mime_mhs,1L + +#define SN_mime_mhs_bodies "mime-mhs-bodies" +#define LN_mime_mhs_bodies "mime-mhs-bodies" +#define NID_mime_mhs_bodies 506 +#define OBJ_mime_mhs_bodies OBJ_mime_mhs,2L + +#define SN_id_hex_partial_message "id-hex-partial-message" +#define LN_id_hex_partial_message "id-hex-partial-message" +#define NID_id_hex_partial_message 507 +#define OBJ_id_hex_partial_message OBJ_mime_mhs_headings,1L + +#define SN_id_hex_multipart_message "id-hex-multipart-message" +#define LN_id_hex_multipart_message "id-hex-multipart-message" +#define NID_id_hex_multipart_message 508 +#define OBJ_id_hex_multipart_message OBJ_mime_mhs_headings,2L + +#define SN_zlib_compression "ZLIB" +#define LN_zlib_compression "zlib compression" +#define NID_zlib_compression 125 +#define OBJ_zlib_compression OBJ_id_smime_alg,8L + +#define OBJ_csor 2L,16L,840L,1L,101L,3L + +#define OBJ_nistAlgorithms OBJ_csor,4L + +#define OBJ_aes OBJ_nistAlgorithms,1L + +#define SN_aes_128_ecb "AES-128-ECB" +#define LN_aes_128_ecb "aes-128-ecb" +#define NID_aes_128_ecb 418 +#define OBJ_aes_128_ecb OBJ_aes,1L + +#define SN_aes_128_cbc "AES-128-CBC" +#define LN_aes_128_cbc "aes-128-cbc" +#define NID_aes_128_cbc 419 +#define OBJ_aes_128_cbc OBJ_aes,2L + +#define SN_aes_128_ofb128 "AES-128-OFB" +#define LN_aes_128_ofb128 "aes-128-ofb" +#define NID_aes_128_ofb128 420 +#define OBJ_aes_128_ofb128 OBJ_aes,3L + +#define SN_aes_128_cfb128 "AES-128-CFB" +#define LN_aes_128_cfb128 "aes-128-cfb" +#define NID_aes_128_cfb128 421 +#define OBJ_aes_128_cfb128 OBJ_aes,4L + +#define SN_id_aes128_wrap "id-aes128-wrap" +#define NID_id_aes128_wrap 788 +#define OBJ_id_aes128_wrap OBJ_aes,5L + +#define SN_aes_128_gcm "id-aes128-GCM" +#define LN_aes_128_gcm "aes-128-gcm" +#define NID_aes_128_gcm 895 +#define OBJ_aes_128_gcm OBJ_aes,6L + +#define SN_aes_128_ccm "id-aes128-CCM" +#define LN_aes_128_ccm "aes-128-ccm" +#define NID_aes_128_ccm 896 +#define OBJ_aes_128_ccm OBJ_aes,7L + +#define SN_id_aes128_wrap_pad "id-aes128-wrap-pad" +#define NID_id_aes128_wrap_pad 897 +#define OBJ_id_aes128_wrap_pad OBJ_aes,8L + +#define SN_aes_192_ecb "AES-192-ECB" +#define LN_aes_192_ecb "aes-192-ecb" +#define NID_aes_192_ecb 422 +#define OBJ_aes_192_ecb OBJ_aes,21L + +#define SN_aes_192_cbc "AES-192-CBC" +#define LN_aes_192_cbc "aes-192-cbc" +#define NID_aes_192_cbc 423 +#define OBJ_aes_192_cbc OBJ_aes,22L + +#define SN_aes_192_ofb128 "AES-192-OFB" +#define LN_aes_192_ofb128 "aes-192-ofb" +#define NID_aes_192_ofb128 424 +#define OBJ_aes_192_ofb128 OBJ_aes,23L + +#define SN_aes_192_cfb128 "AES-192-CFB" +#define LN_aes_192_cfb128 "aes-192-cfb" +#define NID_aes_192_cfb128 425 +#define OBJ_aes_192_cfb128 OBJ_aes,24L + +#define SN_id_aes192_wrap "id-aes192-wrap" +#define NID_id_aes192_wrap 789 +#define OBJ_id_aes192_wrap OBJ_aes,25L + +#define SN_aes_192_gcm "id-aes192-GCM" +#define LN_aes_192_gcm "aes-192-gcm" +#define NID_aes_192_gcm 898 +#define OBJ_aes_192_gcm OBJ_aes,26L + +#define SN_aes_192_ccm "id-aes192-CCM" +#define LN_aes_192_ccm "aes-192-ccm" +#define NID_aes_192_ccm 899 +#define OBJ_aes_192_ccm OBJ_aes,27L + +#define SN_id_aes192_wrap_pad "id-aes192-wrap-pad" +#define NID_id_aes192_wrap_pad 900 +#define OBJ_id_aes192_wrap_pad OBJ_aes,28L + +#define SN_aes_256_ecb "AES-256-ECB" +#define LN_aes_256_ecb "aes-256-ecb" +#define NID_aes_256_ecb 426 +#define OBJ_aes_256_ecb OBJ_aes,41L + +#define SN_aes_256_cbc "AES-256-CBC" +#define LN_aes_256_cbc "aes-256-cbc" +#define NID_aes_256_cbc 427 +#define OBJ_aes_256_cbc OBJ_aes,42L + +#define SN_aes_256_ofb128 "AES-256-OFB" +#define LN_aes_256_ofb128 "aes-256-ofb" +#define NID_aes_256_ofb128 428 +#define OBJ_aes_256_ofb128 OBJ_aes,43L + +#define SN_aes_256_cfb128 "AES-256-CFB" +#define LN_aes_256_cfb128 "aes-256-cfb" +#define NID_aes_256_cfb128 429 +#define OBJ_aes_256_cfb128 OBJ_aes,44L + +#define SN_id_aes256_wrap "id-aes256-wrap" +#define NID_id_aes256_wrap 790 +#define OBJ_id_aes256_wrap OBJ_aes,45L + +#define SN_aes_256_gcm "id-aes256-GCM" +#define LN_aes_256_gcm "aes-256-gcm" +#define NID_aes_256_gcm 901 +#define OBJ_aes_256_gcm OBJ_aes,46L + +#define SN_aes_256_ccm "id-aes256-CCM" +#define LN_aes_256_ccm "aes-256-ccm" +#define NID_aes_256_ccm 902 +#define OBJ_aes_256_ccm OBJ_aes,47L + +#define SN_id_aes256_wrap_pad "id-aes256-wrap-pad" +#define NID_id_aes256_wrap_pad 903 +#define OBJ_id_aes256_wrap_pad OBJ_aes,48L + +#define SN_aes_128_cfb1 "AES-128-CFB1" +#define LN_aes_128_cfb1 "aes-128-cfb1" +#define NID_aes_128_cfb1 650 + +#define SN_aes_192_cfb1 "AES-192-CFB1" +#define LN_aes_192_cfb1 "aes-192-cfb1" +#define NID_aes_192_cfb1 651 + +#define SN_aes_256_cfb1 "AES-256-CFB1" +#define LN_aes_256_cfb1 "aes-256-cfb1" +#define NID_aes_256_cfb1 652 + +#define SN_aes_128_cfb8 "AES-128-CFB8" +#define LN_aes_128_cfb8 "aes-128-cfb8" +#define NID_aes_128_cfb8 653 + +#define SN_aes_192_cfb8 "AES-192-CFB8" +#define LN_aes_192_cfb8 "aes-192-cfb8" +#define NID_aes_192_cfb8 654 + +#define SN_aes_256_cfb8 "AES-256-CFB8" +#define LN_aes_256_cfb8 "aes-256-cfb8" +#define NID_aes_256_cfb8 655 + +#define SN_aes_128_ctr "AES-128-CTR" +#define LN_aes_128_ctr "aes-128-ctr" +#define NID_aes_128_ctr 904 + +#define SN_aes_192_ctr "AES-192-CTR" +#define LN_aes_192_ctr "aes-192-ctr" +#define NID_aes_192_ctr 905 + +#define SN_aes_256_ctr "AES-256-CTR" +#define LN_aes_256_ctr "aes-256-ctr" +#define NID_aes_256_ctr 906 + +#define SN_aes_128_ocb "AES-128-OCB" +#define LN_aes_128_ocb "aes-128-ocb" +#define NID_aes_128_ocb 958 + +#define SN_aes_192_ocb "AES-192-OCB" +#define LN_aes_192_ocb "aes-192-ocb" +#define NID_aes_192_ocb 959 + +#define SN_aes_256_ocb "AES-256-OCB" +#define LN_aes_256_ocb "aes-256-ocb" +#define NID_aes_256_ocb 960 + +#define SN_aes_128_xts "AES-128-XTS" +#define LN_aes_128_xts "aes-128-xts" +#define NID_aes_128_xts 913 + +#define SN_aes_256_xts "AES-256-XTS" +#define LN_aes_256_xts "aes-256-xts" +#define NID_aes_256_xts 914 + +#define SN_des_cfb1 "DES-CFB1" +#define LN_des_cfb1 "des-cfb1" +#define NID_des_cfb1 656 + +#define SN_des_cfb8 "DES-CFB8" +#define LN_des_cfb8 "des-cfb8" +#define NID_des_cfb8 657 + +#define SN_des_ede3_cfb1 "DES-EDE3-CFB1" +#define LN_des_ede3_cfb1 "des-ede3-cfb1" +#define NID_des_ede3_cfb1 658 + +#define SN_des_ede3_cfb8 "DES-EDE3-CFB8" +#define LN_des_ede3_cfb8 "des-ede3-cfb8" +#define NID_des_ede3_cfb8 659 + +#define OBJ_nist_hashalgs OBJ_nistAlgorithms,2L + +#define SN_sha256 "SHA256" +#define LN_sha256 "sha256" +#define NID_sha256 672 +#define OBJ_sha256 OBJ_nist_hashalgs,1L + +#define SN_sha384 "SHA384" +#define LN_sha384 "sha384" +#define NID_sha384 673 +#define OBJ_sha384 OBJ_nist_hashalgs,2L + +#define SN_sha512 "SHA512" +#define LN_sha512 "sha512" +#define NID_sha512 674 +#define OBJ_sha512 OBJ_nist_hashalgs,3L + +#define SN_sha224 "SHA224" +#define LN_sha224 "sha224" +#define NID_sha224 675 +#define OBJ_sha224 OBJ_nist_hashalgs,4L + +#define OBJ_dsa_with_sha2 OBJ_nistAlgorithms,3L + +#define SN_dsa_with_SHA224 "dsa_with_SHA224" +#define NID_dsa_with_SHA224 802 +#define OBJ_dsa_with_SHA224 OBJ_dsa_with_sha2,1L + +#define SN_dsa_with_SHA256 "dsa_with_SHA256" +#define NID_dsa_with_SHA256 803 +#define OBJ_dsa_with_SHA256 OBJ_dsa_with_sha2,2L + +#define SN_hold_instruction_code "holdInstructionCode" +#define LN_hold_instruction_code "Hold Instruction Code" +#define NID_hold_instruction_code 430 +#define OBJ_hold_instruction_code OBJ_id_ce,23L + +#define OBJ_holdInstruction OBJ_X9_57,2L + +#define SN_hold_instruction_none "holdInstructionNone" +#define LN_hold_instruction_none "Hold Instruction None" +#define NID_hold_instruction_none 431 +#define OBJ_hold_instruction_none OBJ_holdInstruction,1L + +#define SN_hold_instruction_call_issuer "holdInstructionCallIssuer" +#define LN_hold_instruction_call_issuer "Hold Instruction Call Issuer" +#define NID_hold_instruction_call_issuer 432 +#define OBJ_hold_instruction_call_issuer OBJ_holdInstruction,2L + +#define SN_hold_instruction_reject "holdInstructionReject" +#define LN_hold_instruction_reject "Hold Instruction Reject" +#define NID_hold_instruction_reject 433 +#define OBJ_hold_instruction_reject OBJ_holdInstruction,3L + +#define SN_data "data" +#define NID_data 434 +#define OBJ_data OBJ_itu_t,9L + +#define SN_pss "pss" +#define NID_pss 435 +#define OBJ_pss OBJ_data,2342L + +#define SN_ucl "ucl" +#define NID_ucl 436 +#define OBJ_ucl OBJ_pss,19200300L + +#define SN_pilot "pilot" +#define NID_pilot 437 +#define OBJ_pilot OBJ_ucl,100L + +#define LN_pilotAttributeType "pilotAttributeType" +#define NID_pilotAttributeType 438 +#define OBJ_pilotAttributeType OBJ_pilot,1L + +#define LN_pilotAttributeSyntax "pilotAttributeSyntax" +#define NID_pilotAttributeSyntax 439 +#define OBJ_pilotAttributeSyntax OBJ_pilot,3L + +#define LN_pilotObjectClass "pilotObjectClass" +#define NID_pilotObjectClass 440 +#define OBJ_pilotObjectClass OBJ_pilot,4L + +#define LN_pilotGroups "pilotGroups" +#define NID_pilotGroups 441 +#define OBJ_pilotGroups OBJ_pilot,10L + +#define LN_iA5StringSyntax "iA5StringSyntax" +#define NID_iA5StringSyntax 442 +#define OBJ_iA5StringSyntax OBJ_pilotAttributeSyntax,4L + +#define LN_caseIgnoreIA5StringSyntax "caseIgnoreIA5StringSyntax" +#define NID_caseIgnoreIA5StringSyntax 443 +#define OBJ_caseIgnoreIA5StringSyntax OBJ_pilotAttributeSyntax,5L + +#define LN_pilotObject "pilotObject" +#define NID_pilotObject 444 +#define OBJ_pilotObject OBJ_pilotObjectClass,3L + +#define LN_pilotPerson "pilotPerson" +#define NID_pilotPerson 445 +#define OBJ_pilotPerson OBJ_pilotObjectClass,4L + +#define SN_account "account" +#define NID_account 446 +#define OBJ_account OBJ_pilotObjectClass,5L + +#define SN_document "document" +#define NID_document 447 +#define OBJ_document OBJ_pilotObjectClass,6L + +#define SN_room "room" +#define NID_room 448 +#define OBJ_room OBJ_pilotObjectClass,7L + +#define LN_documentSeries "documentSeries" +#define NID_documentSeries 449 +#define OBJ_documentSeries OBJ_pilotObjectClass,9L + +#define SN_Domain "domain" +#define LN_Domain "Domain" +#define NID_Domain 392 +#define OBJ_Domain OBJ_pilotObjectClass,13L + +#define LN_rFC822localPart "rFC822localPart" +#define NID_rFC822localPart 450 +#define OBJ_rFC822localPart OBJ_pilotObjectClass,14L + +#define LN_dNSDomain "dNSDomain" +#define NID_dNSDomain 451 +#define OBJ_dNSDomain OBJ_pilotObjectClass,15L + +#define LN_domainRelatedObject "domainRelatedObject" +#define NID_domainRelatedObject 452 +#define OBJ_domainRelatedObject OBJ_pilotObjectClass,17L + +#define LN_friendlyCountry "friendlyCountry" +#define NID_friendlyCountry 453 +#define OBJ_friendlyCountry OBJ_pilotObjectClass,18L + +#define LN_simpleSecurityObject "simpleSecurityObject" +#define NID_simpleSecurityObject 454 +#define OBJ_simpleSecurityObject OBJ_pilotObjectClass,19L + +#define LN_pilotOrganization "pilotOrganization" +#define NID_pilotOrganization 455 +#define OBJ_pilotOrganization OBJ_pilotObjectClass,20L + +#define LN_pilotDSA "pilotDSA" +#define NID_pilotDSA 456 +#define OBJ_pilotDSA OBJ_pilotObjectClass,21L + +#define LN_qualityLabelledData "qualityLabelledData" +#define NID_qualityLabelledData 457 +#define OBJ_qualityLabelledData OBJ_pilotObjectClass,22L + +#define SN_userId "UID" +#define LN_userId "userId" +#define NID_userId 458 +#define OBJ_userId OBJ_pilotAttributeType,1L + +#define LN_textEncodedORAddress "textEncodedORAddress" +#define NID_textEncodedORAddress 459 +#define OBJ_textEncodedORAddress OBJ_pilotAttributeType,2L + +#define SN_rfc822Mailbox "mail" +#define LN_rfc822Mailbox "rfc822Mailbox" +#define NID_rfc822Mailbox 460 +#define OBJ_rfc822Mailbox OBJ_pilotAttributeType,3L + +#define SN_info "info" +#define NID_info 461 +#define OBJ_info OBJ_pilotAttributeType,4L + +#define LN_favouriteDrink "favouriteDrink" +#define NID_favouriteDrink 462 +#define OBJ_favouriteDrink OBJ_pilotAttributeType,5L + +#define LN_roomNumber "roomNumber" +#define NID_roomNumber 463 +#define OBJ_roomNumber OBJ_pilotAttributeType,6L + +#define SN_photo "photo" +#define NID_photo 464 +#define OBJ_photo OBJ_pilotAttributeType,7L + +#define LN_userClass "userClass" +#define NID_userClass 465 +#define OBJ_userClass OBJ_pilotAttributeType,8L + +#define SN_host "host" +#define NID_host 466 +#define OBJ_host OBJ_pilotAttributeType,9L + +#define SN_manager "manager" +#define NID_manager 467 +#define OBJ_manager OBJ_pilotAttributeType,10L + +#define LN_documentIdentifier "documentIdentifier" +#define NID_documentIdentifier 468 +#define OBJ_documentIdentifier OBJ_pilotAttributeType,11L + +#define LN_documentTitle "documentTitle" +#define NID_documentTitle 469 +#define OBJ_documentTitle OBJ_pilotAttributeType,12L + +#define LN_documentVersion "documentVersion" +#define NID_documentVersion 470 +#define OBJ_documentVersion OBJ_pilotAttributeType,13L + +#define LN_documentAuthor "documentAuthor" +#define NID_documentAuthor 471 +#define OBJ_documentAuthor OBJ_pilotAttributeType,14L + +#define LN_documentLocation "documentLocation" +#define NID_documentLocation 472 +#define OBJ_documentLocation OBJ_pilotAttributeType,15L + +#define LN_homeTelephoneNumber "homeTelephoneNumber" +#define NID_homeTelephoneNumber 473 +#define OBJ_homeTelephoneNumber OBJ_pilotAttributeType,20L + +#define SN_secretary "secretary" +#define NID_secretary 474 +#define OBJ_secretary OBJ_pilotAttributeType,21L + +#define LN_otherMailbox "otherMailbox" +#define NID_otherMailbox 475 +#define OBJ_otherMailbox OBJ_pilotAttributeType,22L + +#define LN_lastModifiedTime "lastModifiedTime" +#define NID_lastModifiedTime 476 +#define OBJ_lastModifiedTime OBJ_pilotAttributeType,23L + +#define LN_lastModifiedBy "lastModifiedBy" +#define NID_lastModifiedBy 477 +#define OBJ_lastModifiedBy OBJ_pilotAttributeType,24L + +#define SN_domainComponent "DC" +#define LN_domainComponent "domainComponent" +#define NID_domainComponent 391 +#define OBJ_domainComponent OBJ_pilotAttributeType,25L + +#define LN_aRecord "aRecord" +#define NID_aRecord 478 +#define OBJ_aRecord OBJ_pilotAttributeType,26L + +#define LN_pilotAttributeType27 "pilotAttributeType27" +#define NID_pilotAttributeType27 479 +#define OBJ_pilotAttributeType27 OBJ_pilotAttributeType,27L + +#define LN_mXRecord "mXRecord" +#define NID_mXRecord 480 +#define OBJ_mXRecord OBJ_pilotAttributeType,28L + +#define LN_nSRecord "nSRecord" +#define NID_nSRecord 481 +#define OBJ_nSRecord OBJ_pilotAttributeType,29L + +#define LN_sOARecord "sOARecord" +#define NID_sOARecord 482 +#define OBJ_sOARecord OBJ_pilotAttributeType,30L + +#define LN_cNAMERecord "cNAMERecord" +#define NID_cNAMERecord 483 +#define OBJ_cNAMERecord OBJ_pilotAttributeType,31L + +#define LN_associatedDomain "associatedDomain" +#define NID_associatedDomain 484 +#define OBJ_associatedDomain OBJ_pilotAttributeType,37L + +#define LN_associatedName "associatedName" +#define NID_associatedName 485 +#define OBJ_associatedName OBJ_pilotAttributeType,38L + +#define LN_homePostalAddress "homePostalAddress" +#define NID_homePostalAddress 486 +#define OBJ_homePostalAddress OBJ_pilotAttributeType,39L + +#define LN_personalTitle "personalTitle" +#define NID_personalTitle 487 +#define OBJ_personalTitle OBJ_pilotAttributeType,40L + +#define LN_mobileTelephoneNumber "mobileTelephoneNumber" +#define NID_mobileTelephoneNumber 488 +#define OBJ_mobileTelephoneNumber OBJ_pilotAttributeType,41L + +#define LN_pagerTelephoneNumber "pagerTelephoneNumber" +#define NID_pagerTelephoneNumber 489 +#define OBJ_pagerTelephoneNumber OBJ_pilotAttributeType,42L + +#define LN_friendlyCountryName "friendlyCountryName" +#define NID_friendlyCountryName 490 +#define OBJ_friendlyCountryName OBJ_pilotAttributeType,43L + +#define SN_uniqueIdentifier "uid" +#define LN_uniqueIdentifier "uniqueIdentifier" +#define NID_uniqueIdentifier 102 +#define OBJ_uniqueIdentifier OBJ_pilotAttributeType,44L + +#define LN_organizationalStatus "organizationalStatus" +#define NID_organizationalStatus 491 +#define OBJ_organizationalStatus OBJ_pilotAttributeType,45L + +#define LN_janetMailbox "janetMailbox" +#define NID_janetMailbox 492 +#define OBJ_janetMailbox OBJ_pilotAttributeType,46L + +#define LN_mailPreferenceOption "mailPreferenceOption" +#define NID_mailPreferenceOption 493 +#define OBJ_mailPreferenceOption OBJ_pilotAttributeType,47L + +#define LN_buildingName "buildingName" +#define NID_buildingName 494 +#define OBJ_buildingName OBJ_pilotAttributeType,48L + +#define LN_dSAQuality "dSAQuality" +#define NID_dSAQuality 495 +#define OBJ_dSAQuality OBJ_pilotAttributeType,49L + +#define LN_singleLevelQuality "singleLevelQuality" +#define NID_singleLevelQuality 496 +#define OBJ_singleLevelQuality OBJ_pilotAttributeType,50L + +#define LN_subtreeMinimumQuality "subtreeMinimumQuality" +#define NID_subtreeMinimumQuality 497 +#define OBJ_subtreeMinimumQuality OBJ_pilotAttributeType,51L + +#define LN_subtreeMaximumQuality "subtreeMaximumQuality" +#define NID_subtreeMaximumQuality 498 +#define OBJ_subtreeMaximumQuality OBJ_pilotAttributeType,52L + +#define LN_personalSignature "personalSignature" +#define NID_personalSignature 499 +#define OBJ_personalSignature OBJ_pilotAttributeType,53L + +#define LN_dITRedirect "dITRedirect" +#define NID_dITRedirect 500 +#define OBJ_dITRedirect OBJ_pilotAttributeType,54L + +#define SN_audio "audio" +#define NID_audio 501 +#define OBJ_audio OBJ_pilotAttributeType,55L + +#define LN_documentPublisher "documentPublisher" +#define NID_documentPublisher 502 +#define OBJ_documentPublisher OBJ_pilotAttributeType,56L + +#define SN_id_set "id-set" +#define LN_id_set "Secure Electronic Transactions" +#define NID_id_set 512 +#define OBJ_id_set OBJ_international_organizations,42L + +#define SN_set_ctype "set-ctype" +#define LN_set_ctype "content types" +#define NID_set_ctype 513 +#define OBJ_set_ctype OBJ_id_set,0L + +#define SN_set_msgExt "set-msgExt" +#define LN_set_msgExt "message extensions" +#define NID_set_msgExt 514 +#define OBJ_set_msgExt OBJ_id_set,1L + +#define SN_set_attr "set-attr" +#define NID_set_attr 515 +#define OBJ_set_attr OBJ_id_set,3L + +#define SN_set_policy "set-policy" +#define NID_set_policy 516 +#define OBJ_set_policy OBJ_id_set,5L + +#define SN_set_certExt "set-certExt" +#define LN_set_certExt "certificate extensions" +#define NID_set_certExt 517 +#define OBJ_set_certExt OBJ_id_set,7L + +#define SN_set_brand "set-brand" +#define NID_set_brand 518 +#define OBJ_set_brand OBJ_id_set,8L + +#define SN_setct_PANData "setct-PANData" +#define NID_setct_PANData 519 +#define OBJ_setct_PANData OBJ_set_ctype,0L + +#define SN_setct_PANToken "setct-PANToken" +#define NID_setct_PANToken 520 +#define OBJ_setct_PANToken OBJ_set_ctype,1L + +#define SN_setct_PANOnly "setct-PANOnly" +#define NID_setct_PANOnly 521 +#define OBJ_setct_PANOnly OBJ_set_ctype,2L + +#define SN_setct_OIData "setct-OIData" +#define NID_setct_OIData 522 +#define OBJ_setct_OIData OBJ_set_ctype,3L + +#define SN_setct_PI "setct-PI" +#define NID_setct_PI 523 +#define OBJ_setct_PI OBJ_set_ctype,4L + +#define SN_setct_PIData "setct-PIData" +#define NID_setct_PIData 524 +#define OBJ_setct_PIData OBJ_set_ctype,5L + +#define SN_setct_PIDataUnsigned "setct-PIDataUnsigned" +#define NID_setct_PIDataUnsigned 525 +#define OBJ_setct_PIDataUnsigned OBJ_set_ctype,6L + +#define SN_setct_HODInput "setct-HODInput" +#define NID_setct_HODInput 526 +#define OBJ_setct_HODInput OBJ_set_ctype,7L + +#define SN_setct_AuthResBaggage "setct-AuthResBaggage" +#define NID_setct_AuthResBaggage 527 +#define OBJ_setct_AuthResBaggage OBJ_set_ctype,8L + +#define SN_setct_AuthRevReqBaggage "setct-AuthRevReqBaggage" +#define NID_setct_AuthRevReqBaggage 528 +#define OBJ_setct_AuthRevReqBaggage OBJ_set_ctype,9L + +#define SN_setct_AuthRevResBaggage "setct-AuthRevResBaggage" +#define NID_setct_AuthRevResBaggage 529 +#define OBJ_setct_AuthRevResBaggage OBJ_set_ctype,10L + +#define SN_setct_CapTokenSeq "setct-CapTokenSeq" +#define NID_setct_CapTokenSeq 530 +#define OBJ_setct_CapTokenSeq OBJ_set_ctype,11L + +#define SN_setct_PInitResData "setct-PInitResData" +#define NID_setct_PInitResData 531 +#define OBJ_setct_PInitResData OBJ_set_ctype,12L + +#define SN_setct_PI_TBS "setct-PI-TBS" +#define NID_setct_PI_TBS 532 +#define OBJ_setct_PI_TBS OBJ_set_ctype,13L + +#define SN_setct_PResData "setct-PResData" +#define NID_setct_PResData 533 +#define OBJ_setct_PResData OBJ_set_ctype,14L + +#define SN_setct_AuthReqTBS "setct-AuthReqTBS" +#define NID_setct_AuthReqTBS 534 +#define OBJ_setct_AuthReqTBS OBJ_set_ctype,16L + +#define SN_setct_AuthResTBS "setct-AuthResTBS" +#define NID_setct_AuthResTBS 535 +#define OBJ_setct_AuthResTBS OBJ_set_ctype,17L + +#define SN_setct_AuthResTBSX "setct-AuthResTBSX" +#define NID_setct_AuthResTBSX 536 +#define OBJ_setct_AuthResTBSX OBJ_set_ctype,18L + +#define SN_setct_AuthTokenTBS "setct-AuthTokenTBS" +#define NID_setct_AuthTokenTBS 537 +#define OBJ_setct_AuthTokenTBS OBJ_set_ctype,19L + +#define SN_setct_CapTokenData "setct-CapTokenData" +#define NID_setct_CapTokenData 538 +#define OBJ_setct_CapTokenData OBJ_set_ctype,20L + +#define SN_setct_CapTokenTBS "setct-CapTokenTBS" +#define NID_setct_CapTokenTBS 539 +#define OBJ_setct_CapTokenTBS OBJ_set_ctype,21L + +#define SN_setct_AcqCardCodeMsg "setct-AcqCardCodeMsg" +#define NID_setct_AcqCardCodeMsg 540 +#define OBJ_setct_AcqCardCodeMsg OBJ_set_ctype,22L + +#define SN_setct_AuthRevReqTBS "setct-AuthRevReqTBS" +#define NID_setct_AuthRevReqTBS 541 +#define OBJ_setct_AuthRevReqTBS OBJ_set_ctype,23L + +#define SN_setct_AuthRevResData "setct-AuthRevResData" +#define NID_setct_AuthRevResData 542 +#define OBJ_setct_AuthRevResData OBJ_set_ctype,24L + +#define SN_setct_AuthRevResTBS "setct-AuthRevResTBS" +#define NID_setct_AuthRevResTBS 543 +#define OBJ_setct_AuthRevResTBS OBJ_set_ctype,25L + +#define SN_setct_CapReqTBS "setct-CapReqTBS" +#define NID_setct_CapReqTBS 544 +#define OBJ_setct_CapReqTBS OBJ_set_ctype,26L + +#define SN_setct_CapReqTBSX "setct-CapReqTBSX" +#define NID_setct_CapReqTBSX 545 +#define OBJ_setct_CapReqTBSX OBJ_set_ctype,27L + +#define SN_setct_CapResData "setct-CapResData" +#define NID_setct_CapResData 546 +#define OBJ_setct_CapResData OBJ_set_ctype,28L + +#define SN_setct_CapRevReqTBS "setct-CapRevReqTBS" +#define NID_setct_CapRevReqTBS 547 +#define OBJ_setct_CapRevReqTBS OBJ_set_ctype,29L + +#define SN_setct_CapRevReqTBSX "setct-CapRevReqTBSX" +#define NID_setct_CapRevReqTBSX 548 +#define OBJ_setct_CapRevReqTBSX OBJ_set_ctype,30L + +#define SN_setct_CapRevResData "setct-CapRevResData" +#define NID_setct_CapRevResData 549 +#define OBJ_setct_CapRevResData OBJ_set_ctype,31L + +#define SN_setct_CredReqTBS "setct-CredReqTBS" +#define NID_setct_CredReqTBS 550 +#define OBJ_setct_CredReqTBS OBJ_set_ctype,32L + +#define SN_setct_CredReqTBSX "setct-CredReqTBSX" +#define NID_setct_CredReqTBSX 551 +#define OBJ_setct_CredReqTBSX OBJ_set_ctype,33L + +#define SN_setct_CredResData "setct-CredResData" +#define NID_setct_CredResData 552 +#define OBJ_setct_CredResData OBJ_set_ctype,34L + +#define SN_setct_CredRevReqTBS "setct-CredRevReqTBS" +#define NID_setct_CredRevReqTBS 553 +#define OBJ_setct_CredRevReqTBS OBJ_set_ctype,35L + +#define SN_setct_CredRevReqTBSX "setct-CredRevReqTBSX" +#define NID_setct_CredRevReqTBSX 554 +#define OBJ_setct_CredRevReqTBSX OBJ_set_ctype,36L + +#define SN_setct_CredRevResData "setct-CredRevResData" +#define NID_setct_CredRevResData 555 +#define OBJ_setct_CredRevResData OBJ_set_ctype,37L + +#define SN_setct_PCertReqData "setct-PCertReqData" +#define NID_setct_PCertReqData 556 +#define OBJ_setct_PCertReqData OBJ_set_ctype,38L + +#define SN_setct_PCertResTBS "setct-PCertResTBS" +#define NID_setct_PCertResTBS 557 +#define OBJ_setct_PCertResTBS OBJ_set_ctype,39L + +#define SN_setct_BatchAdminReqData "setct-BatchAdminReqData" +#define NID_setct_BatchAdminReqData 558 +#define OBJ_setct_BatchAdminReqData OBJ_set_ctype,40L + +#define SN_setct_BatchAdminResData "setct-BatchAdminResData" +#define NID_setct_BatchAdminResData 559 +#define OBJ_setct_BatchAdminResData OBJ_set_ctype,41L + +#define SN_setct_CardCInitResTBS "setct-CardCInitResTBS" +#define NID_setct_CardCInitResTBS 560 +#define OBJ_setct_CardCInitResTBS OBJ_set_ctype,42L + +#define SN_setct_MeAqCInitResTBS "setct-MeAqCInitResTBS" +#define NID_setct_MeAqCInitResTBS 561 +#define OBJ_setct_MeAqCInitResTBS OBJ_set_ctype,43L + +#define SN_setct_RegFormResTBS "setct-RegFormResTBS" +#define NID_setct_RegFormResTBS 562 +#define OBJ_setct_RegFormResTBS OBJ_set_ctype,44L + +#define SN_setct_CertReqData "setct-CertReqData" +#define NID_setct_CertReqData 563 +#define OBJ_setct_CertReqData OBJ_set_ctype,45L + +#define SN_setct_CertReqTBS "setct-CertReqTBS" +#define NID_setct_CertReqTBS 564 +#define OBJ_setct_CertReqTBS OBJ_set_ctype,46L + +#define SN_setct_CertResData "setct-CertResData" +#define NID_setct_CertResData 565 +#define OBJ_setct_CertResData OBJ_set_ctype,47L + +#define SN_setct_CertInqReqTBS "setct-CertInqReqTBS" +#define NID_setct_CertInqReqTBS 566 +#define OBJ_setct_CertInqReqTBS OBJ_set_ctype,48L + +#define SN_setct_ErrorTBS "setct-ErrorTBS" +#define NID_setct_ErrorTBS 567 +#define OBJ_setct_ErrorTBS OBJ_set_ctype,49L + +#define SN_setct_PIDualSignedTBE "setct-PIDualSignedTBE" +#define NID_setct_PIDualSignedTBE 568 +#define OBJ_setct_PIDualSignedTBE OBJ_set_ctype,50L + +#define SN_setct_PIUnsignedTBE "setct-PIUnsignedTBE" +#define NID_setct_PIUnsignedTBE 569 +#define OBJ_setct_PIUnsignedTBE OBJ_set_ctype,51L + +#define SN_setct_AuthReqTBE "setct-AuthReqTBE" +#define NID_setct_AuthReqTBE 570 +#define OBJ_setct_AuthReqTBE OBJ_set_ctype,52L + +#define SN_setct_AuthResTBE "setct-AuthResTBE" +#define NID_setct_AuthResTBE 571 +#define OBJ_setct_AuthResTBE OBJ_set_ctype,53L + +#define SN_setct_AuthResTBEX "setct-AuthResTBEX" +#define NID_setct_AuthResTBEX 572 +#define OBJ_setct_AuthResTBEX OBJ_set_ctype,54L + +#define SN_setct_AuthTokenTBE "setct-AuthTokenTBE" +#define NID_setct_AuthTokenTBE 573 +#define OBJ_setct_AuthTokenTBE OBJ_set_ctype,55L + +#define SN_setct_CapTokenTBE "setct-CapTokenTBE" +#define NID_setct_CapTokenTBE 574 +#define OBJ_setct_CapTokenTBE OBJ_set_ctype,56L + +#define SN_setct_CapTokenTBEX "setct-CapTokenTBEX" +#define NID_setct_CapTokenTBEX 575 +#define OBJ_setct_CapTokenTBEX OBJ_set_ctype,57L + +#define SN_setct_AcqCardCodeMsgTBE "setct-AcqCardCodeMsgTBE" +#define NID_setct_AcqCardCodeMsgTBE 576 +#define OBJ_setct_AcqCardCodeMsgTBE OBJ_set_ctype,58L + +#define SN_setct_AuthRevReqTBE "setct-AuthRevReqTBE" +#define NID_setct_AuthRevReqTBE 577 +#define OBJ_setct_AuthRevReqTBE OBJ_set_ctype,59L + +#define SN_setct_AuthRevResTBE "setct-AuthRevResTBE" +#define NID_setct_AuthRevResTBE 578 +#define OBJ_setct_AuthRevResTBE OBJ_set_ctype,60L + +#define SN_setct_AuthRevResTBEB "setct-AuthRevResTBEB" +#define NID_setct_AuthRevResTBEB 579 +#define OBJ_setct_AuthRevResTBEB OBJ_set_ctype,61L + +#define SN_setct_CapReqTBE "setct-CapReqTBE" +#define NID_setct_CapReqTBE 580 +#define OBJ_setct_CapReqTBE OBJ_set_ctype,62L + +#define SN_setct_CapReqTBEX "setct-CapReqTBEX" +#define NID_setct_CapReqTBEX 581 +#define OBJ_setct_CapReqTBEX OBJ_set_ctype,63L + +#define SN_setct_CapResTBE "setct-CapResTBE" +#define NID_setct_CapResTBE 582 +#define OBJ_setct_CapResTBE OBJ_set_ctype,64L + +#define SN_setct_CapRevReqTBE "setct-CapRevReqTBE" +#define NID_setct_CapRevReqTBE 583 +#define OBJ_setct_CapRevReqTBE OBJ_set_ctype,65L + +#define SN_setct_CapRevReqTBEX "setct-CapRevReqTBEX" +#define NID_setct_CapRevReqTBEX 584 +#define OBJ_setct_CapRevReqTBEX OBJ_set_ctype,66L + +#define SN_setct_CapRevResTBE "setct-CapRevResTBE" +#define NID_setct_CapRevResTBE 585 +#define OBJ_setct_CapRevResTBE OBJ_set_ctype,67L + +#define SN_setct_CredReqTBE "setct-CredReqTBE" +#define NID_setct_CredReqTBE 586 +#define OBJ_setct_CredReqTBE OBJ_set_ctype,68L + +#define SN_setct_CredReqTBEX "setct-CredReqTBEX" +#define NID_setct_CredReqTBEX 587 +#define OBJ_setct_CredReqTBEX OBJ_set_ctype,69L + +#define SN_setct_CredResTBE "setct-CredResTBE" +#define NID_setct_CredResTBE 588 +#define OBJ_setct_CredResTBE OBJ_set_ctype,70L + +#define SN_setct_CredRevReqTBE "setct-CredRevReqTBE" +#define NID_setct_CredRevReqTBE 589 +#define OBJ_setct_CredRevReqTBE OBJ_set_ctype,71L + +#define SN_setct_CredRevReqTBEX "setct-CredRevReqTBEX" +#define NID_setct_CredRevReqTBEX 590 +#define OBJ_setct_CredRevReqTBEX OBJ_set_ctype,72L + +#define SN_setct_CredRevResTBE "setct-CredRevResTBE" +#define NID_setct_CredRevResTBE 591 +#define OBJ_setct_CredRevResTBE OBJ_set_ctype,73L + +#define SN_setct_BatchAdminReqTBE "setct-BatchAdminReqTBE" +#define NID_setct_BatchAdminReqTBE 592 +#define OBJ_setct_BatchAdminReqTBE OBJ_set_ctype,74L + +#define SN_setct_BatchAdminResTBE "setct-BatchAdminResTBE" +#define NID_setct_BatchAdminResTBE 593 +#define OBJ_setct_BatchAdminResTBE OBJ_set_ctype,75L + +#define SN_setct_RegFormReqTBE "setct-RegFormReqTBE" +#define NID_setct_RegFormReqTBE 594 +#define OBJ_setct_RegFormReqTBE OBJ_set_ctype,76L + +#define SN_setct_CertReqTBE "setct-CertReqTBE" +#define NID_setct_CertReqTBE 595 +#define OBJ_setct_CertReqTBE OBJ_set_ctype,77L + +#define SN_setct_CertReqTBEX "setct-CertReqTBEX" +#define NID_setct_CertReqTBEX 596 +#define OBJ_setct_CertReqTBEX OBJ_set_ctype,78L + +#define SN_setct_CertResTBE "setct-CertResTBE" +#define NID_setct_CertResTBE 597 +#define OBJ_setct_CertResTBE OBJ_set_ctype,79L + +#define SN_setct_CRLNotificationTBS "setct-CRLNotificationTBS" +#define NID_setct_CRLNotificationTBS 598 +#define OBJ_setct_CRLNotificationTBS OBJ_set_ctype,80L + +#define SN_setct_CRLNotificationResTBS "setct-CRLNotificationResTBS" +#define NID_setct_CRLNotificationResTBS 599 +#define OBJ_setct_CRLNotificationResTBS OBJ_set_ctype,81L + +#define SN_setct_BCIDistributionTBS "setct-BCIDistributionTBS" +#define NID_setct_BCIDistributionTBS 600 +#define OBJ_setct_BCIDistributionTBS OBJ_set_ctype,82L + +#define SN_setext_genCrypt "setext-genCrypt" +#define LN_setext_genCrypt "generic cryptogram" +#define NID_setext_genCrypt 601 +#define OBJ_setext_genCrypt OBJ_set_msgExt,1L + +#define SN_setext_miAuth "setext-miAuth" +#define LN_setext_miAuth "merchant initiated auth" +#define NID_setext_miAuth 602 +#define OBJ_setext_miAuth OBJ_set_msgExt,3L + +#define SN_setext_pinSecure "setext-pinSecure" +#define NID_setext_pinSecure 603 +#define OBJ_setext_pinSecure OBJ_set_msgExt,4L + +#define SN_setext_pinAny "setext-pinAny" +#define NID_setext_pinAny 604 +#define OBJ_setext_pinAny OBJ_set_msgExt,5L + +#define SN_setext_track2 "setext-track2" +#define NID_setext_track2 605 +#define OBJ_setext_track2 OBJ_set_msgExt,7L + +#define SN_setext_cv "setext-cv" +#define LN_setext_cv "additional verification" +#define NID_setext_cv 606 +#define OBJ_setext_cv OBJ_set_msgExt,8L + +#define SN_set_policy_root "set-policy-root" +#define NID_set_policy_root 607 +#define OBJ_set_policy_root OBJ_set_policy,0L + +#define SN_setCext_hashedRoot "setCext-hashedRoot" +#define NID_setCext_hashedRoot 608 +#define OBJ_setCext_hashedRoot OBJ_set_certExt,0L + +#define SN_setCext_certType "setCext-certType" +#define NID_setCext_certType 609 +#define OBJ_setCext_certType OBJ_set_certExt,1L + +#define SN_setCext_merchData "setCext-merchData" +#define NID_setCext_merchData 610 +#define OBJ_setCext_merchData OBJ_set_certExt,2L + +#define SN_setCext_cCertRequired "setCext-cCertRequired" +#define NID_setCext_cCertRequired 611 +#define OBJ_setCext_cCertRequired OBJ_set_certExt,3L + +#define SN_setCext_tunneling "setCext-tunneling" +#define NID_setCext_tunneling 612 +#define OBJ_setCext_tunneling OBJ_set_certExt,4L + +#define SN_setCext_setExt "setCext-setExt" +#define NID_setCext_setExt 613 +#define OBJ_setCext_setExt OBJ_set_certExt,5L + +#define SN_setCext_setQualf "setCext-setQualf" +#define NID_setCext_setQualf 614 +#define OBJ_setCext_setQualf OBJ_set_certExt,6L + +#define SN_setCext_PGWYcapabilities "setCext-PGWYcapabilities" +#define NID_setCext_PGWYcapabilities 615 +#define OBJ_setCext_PGWYcapabilities OBJ_set_certExt,7L + +#define SN_setCext_TokenIdentifier "setCext-TokenIdentifier" +#define NID_setCext_TokenIdentifier 616 +#define OBJ_setCext_TokenIdentifier OBJ_set_certExt,8L + +#define SN_setCext_Track2Data "setCext-Track2Data" +#define NID_setCext_Track2Data 617 +#define OBJ_setCext_Track2Data OBJ_set_certExt,9L + +#define SN_setCext_TokenType "setCext-TokenType" +#define NID_setCext_TokenType 618 +#define OBJ_setCext_TokenType OBJ_set_certExt,10L + +#define SN_setCext_IssuerCapabilities "setCext-IssuerCapabilities" +#define NID_setCext_IssuerCapabilities 619 +#define OBJ_setCext_IssuerCapabilities OBJ_set_certExt,11L + +#define SN_setAttr_Cert "setAttr-Cert" +#define NID_setAttr_Cert 620 +#define OBJ_setAttr_Cert OBJ_set_attr,0L + +#define SN_setAttr_PGWYcap "setAttr-PGWYcap" +#define LN_setAttr_PGWYcap "payment gateway capabilities" +#define NID_setAttr_PGWYcap 621 +#define OBJ_setAttr_PGWYcap OBJ_set_attr,1L + +#define SN_setAttr_TokenType "setAttr-TokenType" +#define NID_setAttr_TokenType 622 +#define OBJ_setAttr_TokenType OBJ_set_attr,2L + +#define SN_setAttr_IssCap "setAttr-IssCap" +#define LN_setAttr_IssCap "issuer capabilities" +#define NID_setAttr_IssCap 623 +#define OBJ_setAttr_IssCap OBJ_set_attr,3L + +#define SN_set_rootKeyThumb "set-rootKeyThumb" +#define NID_set_rootKeyThumb 624 +#define OBJ_set_rootKeyThumb OBJ_setAttr_Cert,0L + +#define SN_set_addPolicy "set-addPolicy" +#define NID_set_addPolicy 625 +#define OBJ_set_addPolicy OBJ_setAttr_Cert,1L + +#define SN_setAttr_Token_EMV "setAttr-Token-EMV" +#define NID_setAttr_Token_EMV 626 +#define OBJ_setAttr_Token_EMV OBJ_setAttr_TokenType,1L + +#define SN_setAttr_Token_B0Prime "setAttr-Token-B0Prime" +#define NID_setAttr_Token_B0Prime 627 +#define OBJ_setAttr_Token_B0Prime OBJ_setAttr_TokenType,2L + +#define SN_setAttr_IssCap_CVM "setAttr-IssCap-CVM" +#define NID_setAttr_IssCap_CVM 628 +#define OBJ_setAttr_IssCap_CVM OBJ_setAttr_IssCap,3L + +#define SN_setAttr_IssCap_T2 "setAttr-IssCap-T2" +#define NID_setAttr_IssCap_T2 629 +#define OBJ_setAttr_IssCap_T2 OBJ_setAttr_IssCap,4L + +#define SN_setAttr_IssCap_Sig "setAttr-IssCap-Sig" +#define NID_setAttr_IssCap_Sig 630 +#define OBJ_setAttr_IssCap_Sig OBJ_setAttr_IssCap,5L + +#define SN_setAttr_GenCryptgrm "setAttr-GenCryptgrm" +#define LN_setAttr_GenCryptgrm "generate cryptogram" +#define NID_setAttr_GenCryptgrm 631 +#define OBJ_setAttr_GenCryptgrm OBJ_setAttr_IssCap_CVM,1L + +#define SN_setAttr_T2Enc "setAttr-T2Enc" +#define LN_setAttr_T2Enc "encrypted track 2" +#define NID_setAttr_T2Enc 632 +#define OBJ_setAttr_T2Enc OBJ_setAttr_IssCap_T2,1L + +#define SN_setAttr_T2cleartxt "setAttr-T2cleartxt" +#define LN_setAttr_T2cleartxt "cleartext track 2" +#define NID_setAttr_T2cleartxt 633 +#define OBJ_setAttr_T2cleartxt OBJ_setAttr_IssCap_T2,2L + +#define SN_setAttr_TokICCsig "setAttr-TokICCsig" +#define LN_setAttr_TokICCsig "ICC or token signature" +#define NID_setAttr_TokICCsig 634 +#define OBJ_setAttr_TokICCsig OBJ_setAttr_IssCap_Sig,1L + +#define SN_setAttr_SecDevSig "setAttr-SecDevSig" +#define LN_setAttr_SecDevSig "secure device signature" +#define NID_setAttr_SecDevSig 635 +#define OBJ_setAttr_SecDevSig OBJ_setAttr_IssCap_Sig,2L + +#define SN_set_brand_IATA_ATA "set-brand-IATA-ATA" +#define NID_set_brand_IATA_ATA 636 +#define OBJ_set_brand_IATA_ATA OBJ_set_brand,1L + +#define SN_set_brand_Diners "set-brand-Diners" +#define NID_set_brand_Diners 637 +#define OBJ_set_brand_Diners OBJ_set_brand,30L + +#define SN_set_brand_AmericanExpress "set-brand-AmericanExpress" +#define NID_set_brand_AmericanExpress 638 +#define OBJ_set_brand_AmericanExpress OBJ_set_brand,34L + +#define SN_set_brand_JCB "set-brand-JCB" +#define NID_set_brand_JCB 639 +#define OBJ_set_brand_JCB OBJ_set_brand,35L + +#define SN_set_brand_Visa "set-brand-Visa" +#define NID_set_brand_Visa 640 +#define OBJ_set_brand_Visa OBJ_set_brand,4L + +#define SN_set_brand_MasterCard "set-brand-MasterCard" +#define NID_set_brand_MasterCard 641 +#define OBJ_set_brand_MasterCard OBJ_set_brand,5L + +#define SN_set_brand_Novus "set-brand-Novus" +#define NID_set_brand_Novus 642 +#define OBJ_set_brand_Novus OBJ_set_brand,6011L + +#define SN_des_cdmf "DES-CDMF" +#define LN_des_cdmf "des-cdmf" +#define NID_des_cdmf 643 +#define OBJ_des_cdmf OBJ_rsadsi,3L,10L + +#define SN_rsaOAEPEncryptionSET "rsaOAEPEncryptionSET" +#define NID_rsaOAEPEncryptionSET 644 +#define OBJ_rsaOAEPEncryptionSET OBJ_rsadsi,1L,1L,6L + +#define SN_ipsec3 "Oakley-EC2N-3" +#define LN_ipsec3 "ipsec3" +#define NID_ipsec3 749 + +#define SN_ipsec4 "Oakley-EC2N-4" +#define LN_ipsec4 "ipsec4" +#define NID_ipsec4 750 + +#define SN_whirlpool "whirlpool" +#define NID_whirlpool 804 +#define OBJ_whirlpool OBJ_iso,0L,10118L,3L,0L,55L + +#define SN_cryptopro "cryptopro" +#define NID_cryptopro 805 +#define OBJ_cryptopro OBJ_member_body,643L,2L,2L + +#define SN_cryptocom "cryptocom" +#define NID_cryptocom 806 +#define OBJ_cryptocom OBJ_member_body,643L,2L,9L + +#define SN_id_tc26 "id-tc26" +#define NID_id_tc26 974 +#define OBJ_id_tc26 OBJ_member_body,643L,7L,1L + +#define SN_id_GostR3411_94_with_GostR3410_2001 "id-GostR3411-94-with-GostR3410-2001" +#define LN_id_GostR3411_94_with_GostR3410_2001 "GOST R 34.11-94 with GOST R 34.10-2001" +#define NID_id_GostR3411_94_with_GostR3410_2001 807 +#define OBJ_id_GostR3411_94_with_GostR3410_2001 OBJ_cryptopro,3L + +#define SN_id_GostR3411_94_with_GostR3410_94 "id-GostR3411-94-with-GostR3410-94" +#define LN_id_GostR3411_94_with_GostR3410_94 "GOST R 34.11-94 with GOST R 34.10-94" +#define NID_id_GostR3411_94_with_GostR3410_94 808 +#define OBJ_id_GostR3411_94_with_GostR3410_94 OBJ_cryptopro,4L + +#define SN_id_GostR3411_94 "md_gost94" +#define LN_id_GostR3411_94 "GOST R 34.11-94" +#define NID_id_GostR3411_94 809 +#define OBJ_id_GostR3411_94 OBJ_cryptopro,9L + +#define SN_id_HMACGostR3411_94 "id-HMACGostR3411-94" +#define LN_id_HMACGostR3411_94 "HMAC GOST 34.11-94" +#define NID_id_HMACGostR3411_94 810 +#define OBJ_id_HMACGostR3411_94 OBJ_cryptopro,10L + +#define SN_id_GostR3410_2001 "gost2001" +#define LN_id_GostR3410_2001 "GOST R 34.10-2001" +#define NID_id_GostR3410_2001 811 +#define OBJ_id_GostR3410_2001 OBJ_cryptopro,19L + +#define SN_id_GostR3410_94 "gost94" +#define LN_id_GostR3410_94 "GOST R 34.10-94" +#define NID_id_GostR3410_94 812 +#define OBJ_id_GostR3410_94 OBJ_cryptopro,20L + +#define SN_id_Gost28147_89 "gost89" +#define LN_id_Gost28147_89 "GOST 28147-89" +#define NID_id_Gost28147_89 813 +#define OBJ_id_Gost28147_89 OBJ_cryptopro,21L + +#define SN_gost89_cnt "gost89-cnt" +#define NID_gost89_cnt 814 + +#define SN_gost89_cnt_12 "gost89-cnt-12" +#define NID_gost89_cnt_12 975 + +#define SN_gost89_cbc "gost89-cbc" +#define NID_gost89_cbc 1009 + +#define SN_gost89_ecb "gost89-ecb" +#define NID_gost89_ecb 1010 + +#define SN_gost89_ctr "gost89-ctr" +#define NID_gost89_ctr 1011 + +#define SN_id_Gost28147_89_MAC "gost-mac" +#define LN_id_Gost28147_89_MAC "GOST 28147-89 MAC" +#define NID_id_Gost28147_89_MAC 815 +#define OBJ_id_Gost28147_89_MAC OBJ_cryptopro,22L + +#define SN_gost_mac_12 "gost-mac-12" +#define NID_gost_mac_12 976 + +#define SN_id_GostR3411_94_prf "prf-gostr3411-94" +#define LN_id_GostR3411_94_prf "GOST R 34.11-94 PRF" +#define NID_id_GostR3411_94_prf 816 +#define OBJ_id_GostR3411_94_prf OBJ_cryptopro,23L + +#define SN_id_GostR3410_2001DH "id-GostR3410-2001DH" +#define LN_id_GostR3410_2001DH "GOST R 34.10-2001 DH" +#define NID_id_GostR3410_2001DH 817 +#define OBJ_id_GostR3410_2001DH OBJ_cryptopro,98L + +#define SN_id_GostR3410_94DH "id-GostR3410-94DH" +#define LN_id_GostR3410_94DH "GOST R 34.10-94 DH" +#define NID_id_GostR3410_94DH 818 +#define OBJ_id_GostR3410_94DH OBJ_cryptopro,99L + +#define SN_id_Gost28147_89_CryptoPro_KeyMeshing "id-Gost28147-89-CryptoPro-KeyMeshing" +#define NID_id_Gost28147_89_CryptoPro_KeyMeshing 819 +#define OBJ_id_Gost28147_89_CryptoPro_KeyMeshing OBJ_cryptopro,14L,1L + +#define SN_id_Gost28147_89_None_KeyMeshing "id-Gost28147-89-None-KeyMeshing" +#define NID_id_Gost28147_89_None_KeyMeshing 820 +#define OBJ_id_Gost28147_89_None_KeyMeshing OBJ_cryptopro,14L,0L + +#define SN_id_GostR3411_94_TestParamSet "id-GostR3411-94-TestParamSet" +#define NID_id_GostR3411_94_TestParamSet 821 +#define OBJ_id_GostR3411_94_TestParamSet OBJ_cryptopro,30L,0L + +#define SN_id_GostR3411_94_CryptoProParamSet "id-GostR3411-94-CryptoProParamSet" +#define NID_id_GostR3411_94_CryptoProParamSet 822 +#define OBJ_id_GostR3411_94_CryptoProParamSet OBJ_cryptopro,30L,1L + +#define SN_id_Gost28147_89_TestParamSet "id-Gost28147-89-TestParamSet" +#define NID_id_Gost28147_89_TestParamSet 823 +#define OBJ_id_Gost28147_89_TestParamSet OBJ_cryptopro,31L,0L + +#define SN_id_Gost28147_89_CryptoPro_A_ParamSet "id-Gost28147-89-CryptoPro-A-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_A_ParamSet 824 +#define OBJ_id_Gost28147_89_CryptoPro_A_ParamSet OBJ_cryptopro,31L,1L + +#define SN_id_Gost28147_89_CryptoPro_B_ParamSet "id-Gost28147-89-CryptoPro-B-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_B_ParamSet 825 +#define OBJ_id_Gost28147_89_CryptoPro_B_ParamSet OBJ_cryptopro,31L,2L + +#define SN_id_Gost28147_89_CryptoPro_C_ParamSet "id-Gost28147-89-CryptoPro-C-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_C_ParamSet 826 +#define OBJ_id_Gost28147_89_CryptoPro_C_ParamSet OBJ_cryptopro,31L,3L + +#define SN_id_Gost28147_89_CryptoPro_D_ParamSet "id-Gost28147-89-CryptoPro-D-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_D_ParamSet 827 +#define OBJ_id_Gost28147_89_CryptoPro_D_ParamSet OBJ_cryptopro,31L,4L + +#define SN_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet "id-Gost28147-89-CryptoPro-Oscar-1-1-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet 828 +#define OBJ_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet OBJ_cryptopro,31L,5L + +#define SN_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet "id-Gost28147-89-CryptoPro-Oscar-1-0-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet 829 +#define OBJ_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet OBJ_cryptopro,31L,6L + +#define SN_id_Gost28147_89_CryptoPro_RIC_1_ParamSet "id-Gost28147-89-CryptoPro-RIC-1-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_RIC_1_ParamSet 830 +#define OBJ_id_Gost28147_89_CryptoPro_RIC_1_ParamSet OBJ_cryptopro,31L,7L + +#define SN_id_GostR3410_94_TestParamSet "id-GostR3410-94-TestParamSet" +#define NID_id_GostR3410_94_TestParamSet 831 +#define OBJ_id_GostR3410_94_TestParamSet OBJ_cryptopro,32L,0L + +#define SN_id_GostR3410_94_CryptoPro_A_ParamSet "id-GostR3410-94-CryptoPro-A-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_A_ParamSet 832 +#define OBJ_id_GostR3410_94_CryptoPro_A_ParamSet OBJ_cryptopro,32L,2L + +#define SN_id_GostR3410_94_CryptoPro_B_ParamSet "id-GostR3410-94-CryptoPro-B-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_B_ParamSet 833 +#define OBJ_id_GostR3410_94_CryptoPro_B_ParamSet OBJ_cryptopro,32L,3L + +#define SN_id_GostR3410_94_CryptoPro_C_ParamSet "id-GostR3410-94-CryptoPro-C-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_C_ParamSet 834 +#define OBJ_id_GostR3410_94_CryptoPro_C_ParamSet OBJ_cryptopro,32L,4L + +#define SN_id_GostR3410_94_CryptoPro_D_ParamSet "id-GostR3410-94-CryptoPro-D-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_D_ParamSet 835 +#define OBJ_id_GostR3410_94_CryptoPro_D_ParamSet OBJ_cryptopro,32L,5L + +#define SN_id_GostR3410_94_CryptoPro_XchA_ParamSet "id-GostR3410-94-CryptoPro-XchA-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_XchA_ParamSet 836 +#define OBJ_id_GostR3410_94_CryptoPro_XchA_ParamSet OBJ_cryptopro,33L,1L + +#define SN_id_GostR3410_94_CryptoPro_XchB_ParamSet "id-GostR3410-94-CryptoPro-XchB-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_XchB_ParamSet 837 +#define OBJ_id_GostR3410_94_CryptoPro_XchB_ParamSet OBJ_cryptopro,33L,2L + +#define SN_id_GostR3410_94_CryptoPro_XchC_ParamSet "id-GostR3410-94-CryptoPro-XchC-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_XchC_ParamSet 838 +#define OBJ_id_GostR3410_94_CryptoPro_XchC_ParamSet OBJ_cryptopro,33L,3L + +#define SN_id_GostR3410_2001_TestParamSet "id-GostR3410-2001-TestParamSet" +#define NID_id_GostR3410_2001_TestParamSet 839 +#define OBJ_id_GostR3410_2001_TestParamSet OBJ_cryptopro,35L,0L + +#define SN_id_GostR3410_2001_CryptoPro_A_ParamSet "id-GostR3410-2001-CryptoPro-A-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_A_ParamSet 840 +#define OBJ_id_GostR3410_2001_CryptoPro_A_ParamSet OBJ_cryptopro,35L,1L + +#define SN_id_GostR3410_2001_CryptoPro_B_ParamSet "id-GostR3410-2001-CryptoPro-B-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_B_ParamSet 841 +#define OBJ_id_GostR3410_2001_CryptoPro_B_ParamSet OBJ_cryptopro,35L,2L + +#define SN_id_GostR3410_2001_CryptoPro_C_ParamSet "id-GostR3410-2001-CryptoPro-C-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_C_ParamSet 842 +#define OBJ_id_GostR3410_2001_CryptoPro_C_ParamSet OBJ_cryptopro,35L,3L + +#define SN_id_GostR3410_2001_CryptoPro_XchA_ParamSet "id-GostR3410-2001-CryptoPro-XchA-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet 843 +#define OBJ_id_GostR3410_2001_CryptoPro_XchA_ParamSet OBJ_cryptopro,36L,0L + +#define SN_id_GostR3410_2001_CryptoPro_XchB_ParamSet "id-GostR3410-2001-CryptoPro-XchB-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet 844 +#define OBJ_id_GostR3410_2001_CryptoPro_XchB_ParamSet OBJ_cryptopro,36L,1L + +#define SN_id_GostR3410_94_a "id-GostR3410-94-a" +#define NID_id_GostR3410_94_a 845 +#define OBJ_id_GostR3410_94_a OBJ_id_GostR3410_94,1L + +#define SN_id_GostR3410_94_aBis "id-GostR3410-94-aBis" +#define NID_id_GostR3410_94_aBis 846 +#define OBJ_id_GostR3410_94_aBis OBJ_id_GostR3410_94,2L + +#define SN_id_GostR3410_94_b "id-GostR3410-94-b" +#define NID_id_GostR3410_94_b 847 +#define OBJ_id_GostR3410_94_b OBJ_id_GostR3410_94,3L + +#define SN_id_GostR3410_94_bBis "id-GostR3410-94-bBis" +#define NID_id_GostR3410_94_bBis 848 +#define OBJ_id_GostR3410_94_bBis OBJ_id_GostR3410_94,4L + +#define SN_id_Gost28147_89_cc "id-Gost28147-89-cc" +#define LN_id_Gost28147_89_cc "GOST 28147-89 Cryptocom ParamSet" +#define NID_id_Gost28147_89_cc 849 +#define OBJ_id_Gost28147_89_cc OBJ_cryptocom,1L,6L,1L + +#define SN_id_GostR3410_94_cc "gost94cc" +#define LN_id_GostR3410_94_cc "GOST 34.10-94 Cryptocom" +#define NID_id_GostR3410_94_cc 850 +#define OBJ_id_GostR3410_94_cc OBJ_cryptocom,1L,5L,3L + +#define SN_id_GostR3410_2001_cc "gost2001cc" +#define LN_id_GostR3410_2001_cc "GOST 34.10-2001 Cryptocom" +#define NID_id_GostR3410_2001_cc 851 +#define OBJ_id_GostR3410_2001_cc OBJ_cryptocom,1L,5L,4L + +#define SN_id_GostR3411_94_with_GostR3410_94_cc "id-GostR3411-94-with-GostR3410-94-cc" +#define LN_id_GostR3411_94_with_GostR3410_94_cc "GOST R 34.11-94 with GOST R 34.10-94 Cryptocom" +#define NID_id_GostR3411_94_with_GostR3410_94_cc 852 +#define OBJ_id_GostR3411_94_with_GostR3410_94_cc OBJ_cryptocom,1L,3L,3L + +#define SN_id_GostR3411_94_with_GostR3410_2001_cc "id-GostR3411-94-with-GostR3410-2001-cc" +#define LN_id_GostR3411_94_with_GostR3410_2001_cc "GOST R 34.11-94 with GOST R 34.10-2001 Cryptocom" +#define NID_id_GostR3411_94_with_GostR3410_2001_cc 853 +#define OBJ_id_GostR3411_94_with_GostR3410_2001_cc OBJ_cryptocom,1L,3L,4L + +#define SN_id_GostR3410_2001_ParamSet_cc "id-GostR3410-2001-ParamSet-cc" +#define LN_id_GostR3410_2001_ParamSet_cc "GOST R 3410-2001 Parameter Set Cryptocom" +#define NID_id_GostR3410_2001_ParamSet_cc 854 +#define OBJ_id_GostR3410_2001_ParamSet_cc OBJ_cryptocom,1L,8L,1L + +#define SN_id_tc26_algorithms "id-tc26-algorithms" +#define NID_id_tc26_algorithms 977 +#define OBJ_id_tc26_algorithms OBJ_id_tc26,1L + +#define SN_id_tc26_sign "id-tc26-sign" +#define NID_id_tc26_sign 978 +#define OBJ_id_tc26_sign OBJ_id_tc26_algorithms,1L + +#define SN_id_GostR3410_2012_256 "gost2012_256" +#define LN_id_GostR3410_2012_256 "GOST R 34.10-2012 with 256 bit modulus" +#define NID_id_GostR3410_2012_256 979 +#define OBJ_id_GostR3410_2012_256 OBJ_id_tc26_sign,1L + +#define SN_id_GostR3410_2012_512 "gost2012_512" +#define LN_id_GostR3410_2012_512 "GOST R 34.10-2012 with 512 bit modulus" +#define NID_id_GostR3410_2012_512 980 +#define OBJ_id_GostR3410_2012_512 OBJ_id_tc26_sign,2L + +#define SN_id_tc26_digest "id-tc26-digest" +#define NID_id_tc26_digest 981 +#define OBJ_id_tc26_digest OBJ_id_tc26_algorithms,2L + +#define SN_id_GostR3411_2012_256 "md_gost12_256" +#define LN_id_GostR3411_2012_256 "GOST R 34.11-2012 with 256 bit hash" +#define NID_id_GostR3411_2012_256 982 +#define OBJ_id_GostR3411_2012_256 OBJ_id_tc26_digest,2L + +#define SN_id_GostR3411_2012_512 "md_gost12_512" +#define LN_id_GostR3411_2012_512 "GOST R 34.11-2012 with 512 bit hash" +#define NID_id_GostR3411_2012_512 983 +#define OBJ_id_GostR3411_2012_512 OBJ_id_tc26_digest,3L + +#define SN_id_tc26_signwithdigest "id-tc26-signwithdigest" +#define NID_id_tc26_signwithdigest 984 +#define OBJ_id_tc26_signwithdigest OBJ_id_tc26_algorithms,3L + +#define SN_id_tc26_signwithdigest_gost3410_2012_256 "id-tc26-signwithdigest-gost3410-2012-256" +#define LN_id_tc26_signwithdigest_gost3410_2012_256 "GOST R 34.10-2012 with GOST R 34.11-2012 (256 bit)" +#define NID_id_tc26_signwithdigest_gost3410_2012_256 985 +#define OBJ_id_tc26_signwithdigest_gost3410_2012_256 OBJ_id_tc26_signwithdigest,2L + +#define SN_id_tc26_signwithdigest_gost3410_2012_512 "id-tc26-signwithdigest-gost3410-2012-512" +#define LN_id_tc26_signwithdigest_gost3410_2012_512 "GOST R 34.10-2012 with GOST R 34.11-2012 (512 bit)" +#define NID_id_tc26_signwithdigest_gost3410_2012_512 986 +#define OBJ_id_tc26_signwithdigest_gost3410_2012_512 OBJ_id_tc26_signwithdigest,3L + +#define SN_id_tc26_mac "id-tc26-mac" +#define NID_id_tc26_mac 987 +#define OBJ_id_tc26_mac OBJ_id_tc26_algorithms,4L + +#define SN_id_tc26_hmac_gost_3411_2012_256 "id-tc26-hmac-gost-3411-2012-256" +#define LN_id_tc26_hmac_gost_3411_2012_256 "HMAC GOST 34.11-2012 256 bit" +#define NID_id_tc26_hmac_gost_3411_2012_256 988 +#define OBJ_id_tc26_hmac_gost_3411_2012_256 OBJ_id_tc26_mac,1L + +#define SN_id_tc26_hmac_gost_3411_2012_512 "id-tc26-hmac-gost-3411-2012-512" +#define LN_id_tc26_hmac_gost_3411_2012_512 "HMAC GOST 34.11-2012 512 bit" +#define NID_id_tc26_hmac_gost_3411_2012_512 989 +#define OBJ_id_tc26_hmac_gost_3411_2012_512 OBJ_id_tc26_mac,2L + +#define SN_id_tc26_cipher "id-tc26-cipher" +#define NID_id_tc26_cipher 990 +#define OBJ_id_tc26_cipher OBJ_id_tc26_algorithms,5L + +#define SN_id_tc26_agreement "id-tc26-agreement" +#define NID_id_tc26_agreement 991 +#define OBJ_id_tc26_agreement OBJ_id_tc26_algorithms,6L + +#define SN_id_tc26_agreement_gost_3410_2012_256 "id-tc26-agreement-gost-3410-2012-256" +#define NID_id_tc26_agreement_gost_3410_2012_256 992 +#define OBJ_id_tc26_agreement_gost_3410_2012_256 OBJ_id_tc26_agreement,1L + +#define SN_id_tc26_agreement_gost_3410_2012_512 "id-tc26-agreement-gost-3410-2012-512" +#define NID_id_tc26_agreement_gost_3410_2012_512 993 +#define OBJ_id_tc26_agreement_gost_3410_2012_512 OBJ_id_tc26_agreement,2L + +#define SN_id_tc26_constants "id-tc26-constants" +#define NID_id_tc26_constants 994 +#define OBJ_id_tc26_constants OBJ_id_tc26,2L + +#define SN_id_tc26_sign_constants "id-tc26-sign-constants" +#define NID_id_tc26_sign_constants 995 +#define OBJ_id_tc26_sign_constants OBJ_id_tc26_constants,1L + +#define SN_id_tc26_gost_3410_2012_512_constants "id-tc26-gost-3410-2012-512-constants" +#define NID_id_tc26_gost_3410_2012_512_constants 996 +#define OBJ_id_tc26_gost_3410_2012_512_constants OBJ_id_tc26_sign_constants,2L + +#define SN_id_tc26_gost_3410_2012_512_paramSetTest "id-tc26-gost-3410-2012-512-paramSetTest" +#define LN_id_tc26_gost_3410_2012_512_paramSetTest "GOST R 34.10-2012 (512 bit) testing parameter set" +#define NID_id_tc26_gost_3410_2012_512_paramSetTest 997 +#define OBJ_id_tc26_gost_3410_2012_512_paramSetTest OBJ_id_tc26_gost_3410_2012_512_constants,0L + +#define SN_id_tc26_gost_3410_2012_512_paramSetA "id-tc26-gost-3410-2012-512-paramSetA" +#define LN_id_tc26_gost_3410_2012_512_paramSetA "GOST R 34.10-2012 (512 bit) ParamSet A" +#define NID_id_tc26_gost_3410_2012_512_paramSetA 998 +#define OBJ_id_tc26_gost_3410_2012_512_paramSetA OBJ_id_tc26_gost_3410_2012_512_constants,1L + +#define SN_id_tc26_gost_3410_2012_512_paramSetB "id-tc26-gost-3410-2012-512-paramSetB" +#define LN_id_tc26_gost_3410_2012_512_paramSetB "GOST R 34.10-2012 (512 bit) ParamSet B" +#define NID_id_tc26_gost_3410_2012_512_paramSetB 999 +#define OBJ_id_tc26_gost_3410_2012_512_paramSetB OBJ_id_tc26_gost_3410_2012_512_constants,2L + +#define SN_id_tc26_digest_constants "id-tc26-digest-constants" +#define NID_id_tc26_digest_constants 1000 +#define OBJ_id_tc26_digest_constants OBJ_id_tc26_constants,2L + +#define SN_id_tc26_cipher_constants "id-tc26-cipher-constants" +#define NID_id_tc26_cipher_constants 1001 +#define OBJ_id_tc26_cipher_constants OBJ_id_tc26_constants,5L + +#define SN_id_tc26_gost_28147_constants "id-tc26-gost-28147-constants" +#define NID_id_tc26_gost_28147_constants 1002 +#define OBJ_id_tc26_gost_28147_constants OBJ_id_tc26_cipher_constants,1L + +#define SN_id_tc26_gost_28147_param_Z "id-tc26-gost-28147-param-Z" +#define LN_id_tc26_gost_28147_param_Z "GOST 28147-89 TC26 parameter set" +#define NID_id_tc26_gost_28147_param_Z 1003 +#define OBJ_id_tc26_gost_28147_param_Z OBJ_id_tc26_gost_28147_constants,1L + +#define SN_INN "INN" +#define LN_INN "INN" +#define NID_INN 1004 +#define OBJ_INN OBJ_member_body,643L,3L,131L,1L,1L + +#define SN_OGRN "OGRN" +#define LN_OGRN "OGRN" +#define NID_OGRN 1005 +#define OBJ_OGRN OBJ_member_body,643L,100L,1L + +#define SN_SNILS "SNILS" +#define LN_SNILS "SNILS" +#define NID_SNILS 1006 +#define OBJ_SNILS OBJ_member_body,643L,100L,3L + +#define SN_subjectSignTool "subjectSignTool" +#define LN_subjectSignTool "Signing Tool of Subject" +#define NID_subjectSignTool 1007 +#define OBJ_subjectSignTool OBJ_member_body,643L,100L,111L + +#define SN_issuerSignTool "issuerSignTool" +#define LN_issuerSignTool "Signing Tool of Issuer" +#define NID_issuerSignTool 1008 +#define OBJ_issuerSignTool OBJ_member_body,643L,100L,112L + +#define SN_grasshopper_ecb "grasshopper-ecb" +#define NID_grasshopper_ecb 1012 + +#define SN_grasshopper_ctr "grasshopper-ctr" +#define NID_grasshopper_ctr 1013 + +#define SN_grasshopper_ofb "grasshopper-ofb" +#define NID_grasshopper_ofb 1014 + +#define SN_grasshopper_cbc "grasshopper-cbc" +#define NID_grasshopper_cbc 1015 + +#define SN_grasshopper_cfb "grasshopper-cfb" +#define NID_grasshopper_cfb 1016 + +#define SN_grasshopper_mac "grasshopper-mac" +#define NID_grasshopper_mac 1017 + +#define SN_camellia_128_cbc "CAMELLIA-128-CBC" +#define LN_camellia_128_cbc "camellia-128-cbc" +#define NID_camellia_128_cbc 751 +#define OBJ_camellia_128_cbc 1L,2L,392L,200011L,61L,1L,1L,1L,2L + +#define SN_camellia_192_cbc "CAMELLIA-192-CBC" +#define LN_camellia_192_cbc "camellia-192-cbc" +#define NID_camellia_192_cbc 752 +#define OBJ_camellia_192_cbc 1L,2L,392L,200011L,61L,1L,1L,1L,3L + +#define SN_camellia_256_cbc "CAMELLIA-256-CBC" +#define LN_camellia_256_cbc "camellia-256-cbc" +#define NID_camellia_256_cbc 753 +#define OBJ_camellia_256_cbc 1L,2L,392L,200011L,61L,1L,1L,1L,4L + +#define SN_id_camellia128_wrap "id-camellia128-wrap" +#define NID_id_camellia128_wrap 907 +#define OBJ_id_camellia128_wrap 1L,2L,392L,200011L,61L,1L,1L,3L,2L + +#define SN_id_camellia192_wrap "id-camellia192-wrap" +#define NID_id_camellia192_wrap 908 +#define OBJ_id_camellia192_wrap 1L,2L,392L,200011L,61L,1L,1L,3L,3L + +#define SN_id_camellia256_wrap "id-camellia256-wrap" +#define NID_id_camellia256_wrap 909 +#define OBJ_id_camellia256_wrap 1L,2L,392L,200011L,61L,1L,1L,3L,4L + +#define OBJ_ntt_ds 0L,3L,4401L,5L + +#define OBJ_camellia OBJ_ntt_ds,3L,1L,9L + +#define SN_camellia_128_ecb "CAMELLIA-128-ECB" +#define LN_camellia_128_ecb "camellia-128-ecb" +#define NID_camellia_128_ecb 754 +#define OBJ_camellia_128_ecb OBJ_camellia,1L + +#define SN_camellia_128_ofb128 "CAMELLIA-128-OFB" +#define LN_camellia_128_ofb128 "camellia-128-ofb" +#define NID_camellia_128_ofb128 766 +#define OBJ_camellia_128_ofb128 OBJ_camellia,3L + +#define SN_camellia_128_cfb128 "CAMELLIA-128-CFB" +#define LN_camellia_128_cfb128 "camellia-128-cfb" +#define NID_camellia_128_cfb128 757 +#define OBJ_camellia_128_cfb128 OBJ_camellia,4L + +#define SN_camellia_128_gcm "CAMELLIA-128-GCM" +#define LN_camellia_128_gcm "camellia-128-gcm" +#define NID_camellia_128_gcm 961 +#define OBJ_camellia_128_gcm OBJ_camellia,6L + +#define SN_camellia_128_ccm "CAMELLIA-128-CCM" +#define LN_camellia_128_ccm "camellia-128-ccm" +#define NID_camellia_128_ccm 962 +#define OBJ_camellia_128_ccm OBJ_camellia,7L + +#define SN_camellia_128_ctr "CAMELLIA-128-CTR" +#define LN_camellia_128_ctr "camellia-128-ctr" +#define NID_camellia_128_ctr 963 +#define OBJ_camellia_128_ctr OBJ_camellia,9L + +#define SN_camellia_128_cmac "CAMELLIA-128-CMAC" +#define LN_camellia_128_cmac "camellia-128-cmac" +#define NID_camellia_128_cmac 964 +#define OBJ_camellia_128_cmac OBJ_camellia,10L + +#define SN_camellia_192_ecb "CAMELLIA-192-ECB" +#define LN_camellia_192_ecb "camellia-192-ecb" +#define NID_camellia_192_ecb 755 +#define OBJ_camellia_192_ecb OBJ_camellia,21L + +#define SN_camellia_192_ofb128 "CAMELLIA-192-OFB" +#define LN_camellia_192_ofb128 "camellia-192-ofb" +#define NID_camellia_192_ofb128 767 +#define OBJ_camellia_192_ofb128 OBJ_camellia,23L + +#define SN_camellia_192_cfb128 "CAMELLIA-192-CFB" +#define LN_camellia_192_cfb128 "camellia-192-cfb" +#define NID_camellia_192_cfb128 758 +#define OBJ_camellia_192_cfb128 OBJ_camellia,24L + +#define SN_camellia_192_gcm "CAMELLIA-192-GCM" +#define LN_camellia_192_gcm "camellia-192-gcm" +#define NID_camellia_192_gcm 965 +#define OBJ_camellia_192_gcm OBJ_camellia,26L + +#define SN_camellia_192_ccm "CAMELLIA-192-CCM" +#define LN_camellia_192_ccm "camellia-192-ccm" +#define NID_camellia_192_ccm 966 +#define OBJ_camellia_192_ccm OBJ_camellia,27L + +#define SN_camellia_192_ctr "CAMELLIA-192-CTR" +#define LN_camellia_192_ctr "camellia-192-ctr" +#define NID_camellia_192_ctr 967 +#define OBJ_camellia_192_ctr OBJ_camellia,29L + +#define SN_camellia_192_cmac "CAMELLIA-192-CMAC" +#define LN_camellia_192_cmac "camellia-192-cmac" +#define NID_camellia_192_cmac 968 +#define OBJ_camellia_192_cmac OBJ_camellia,30L + +#define SN_camellia_256_ecb "CAMELLIA-256-ECB" +#define LN_camellia_256_ecb "camellia-256-ecb" +#define NID_camellia_256_ecb 756 +#define OBJ_camellia_256_ecb OBJ_camellia,41L + +#define SN_camellia_256_ofb128 "CAMELLIA-256-OFB" +#define LN_camellia_256_ofb128 "camellia-256-ofb" +#define NID_camellia_256_ofb128 768 +#define OBJ_camellia_256_ofb128 OBJ_camellia,43L + +#define SN_camellia_256_cfb128 "CAMELLIA-256-CFB" +#define LN_camellia_256_cfb128 "camellia-256-cfb" +#define NID_camellia_256_cfb128 759 +#define OBJ_camellia_256_cfb128 OBJ_camellia,44L + +#define SN_camellia_256_gcm "CAMELLIA-256-GCM" +#define LN_camellia_256_gcm "camellia-256-gcm" +#define NID_camellia_256_gcm 969 +#define OBJ_camellia_256_gcm OBJ_camellia,46L + +#define SN_camellia_256_ccm "CAMELLIA-256-CCM" +#define LN_camellia_256_ccm "camellia-256-ccm" +#define NID_camellia_256_ccm 970 +#define OBJ_camellia_256_ccm OBJ_camellia,47L + +#define SN_camellia_256_ctr "CAMELLIA-256-CTR" +#define LN_camellia_256_ctr "camellia-256-ctr" +#define NID_camellia_256_ctr 971 +#define OBJ_camellia_256_ctr OBJ_camellia,49L + +#define SN_camellia_256_cmac "CAMELLIA-256-CMAC" +#define LN_camellia_256_cmac "camellia-256-cmac" +#define NID_camellia_256_cmac 972 +#define OBJ_camellia_256_cmac OBJ_camellia,50L + +#define SN_camellia_128_cfb1 "CAMELLIA-128-CFB1" +#define LN_camellia_128_cfb1 "camellia-128-cfb1" +#define NID_camellia_128_cfb1 760 + +#define SN_camellia_192_cfb1 "CAMELLIA-192-CFB1" +#define LN_camellia_192_cfb1 "camellia-192-cfb1" +#define NID_camellia_192_cfb1 761 + +#define SN_camellia_256_cfb1 "CAMELLIA-256-CFB1" +#define LN_camellia_256_cfb1 "camellia-256-cfb1" +#define NID_camellia_256_cfb1 762 + +#define SN_camellia_128_cfb8 "CAMELLIA-128-CFB8" +#define LN_camellia_128_cfb8 "camellia-128-cfb8" +#define NID_camellia_128_cfb8 763 + +#define SN_camellia_192_cfb8 "CAMELLIA-192-CFB8" +#define LN_camellia_192_cfb8 "camellia-192-cfb8" +#define NID_camellia_192_cfb8 764 + +#define SN_camellia_256_cfb8 "CAMELLIA-256-CFB8" +#define LN_camellia_256_cfb8 "camellia-256-cfb8" +#define NID_camellia_256_cfb8 765 + +#define SN_kisa "KISA" +#define LN_kisa "kisa" +#define NID_kisa 773 +#define OBJ_kisa OBJ_member_body,410L,200004L + +#define SN_seed_ecb "SEED-ECB" +#define LN_seed_ecb "seed-ecb" +#define NID_seed_ecb 776 +#define OBJ_seed_ecb OBJ_kisa,1L,3L + +#define SN_seed_cbc "SEED-CBC" +#define LN_seed_cbc "seed-cbc" +#define NID_seed_cbc 777 +#define OBJ_seed_cbc OBJ_kisa,1L,4L + +#define SN_seed_cfb128 "SEED-CFB" +#define LN_seed_cfb128 "seed-cfb" +#define NID_seed_cfb128 779 +#define OBJ_seed_cfb128 OBJ_kisa,1L,5L + +#define SN_seed_ofb128 "SEED-OFB" +#define LN_seed_ofb128 "seed-ofb" +#define NID_seed_ofb128 778 +#define OBJ_seed_ofb128 OBJ_kisa,1L,6L + +#define SN_hmac "HMAC" +#define LN_hmac "hmac" +#define NID_hmac 855 + +#define SN_cmac "CMAC" +#define LN_cmac "cmac" +#define NID_cmac 894 + +#define SN_rc4_hmac_md5 "RC4-HMAC-MD5" +#define LN_rc4_hmac_md5 "rc4-hmac-md5" +#define NID_rc4_hmac_md5 915 + +#define SN_aes_128_cbc_hmac_sha1 "AES-128-CBC-HMAC-SHA1" +#define LN_aes_128_cbc_hmac_sha1 "aes-128-cbc-hmac-sha1" +#define NID_aes_128_cbc_hmac_sha1 916 + +#define SN_aes_192_cbc_hmac_sha1 "AES-192-CBC-HMAC-SHA1" +#define LN_aes_192_cbc_hmac_sha1 "aes-192-cbc-hmac-sha1" +#define NID_aes_192_cbc_hmac_sha1 917 + +#define SN_aes_256_cbc_hmac_sha1 "AES-256-CBC-HMAC-SHA1" +#define LN_aes_256_cbc_hmac_sha1 "aes-256-cbc-hmac-sha1" +#define NID_aes_256_cbc_hmac_sha1 918 + +#define SN_aes_128_cbc_hmac_sha256 "AES-128-CBC-HMAC-SHA256" +#define LN_aes_128_cbc_hmac_sha256 "aes-128-cbc-hmac-sha256" +#define NID_aes_128_cbc_hmac_sha256 948 + +#define SN_aes_192_cbc_hmac_sha256 "AES-192-CBC-HMAC-SHA256" +#define LN_aes_192_cbc_hmac_sha256 "aes-192-cbc-hmac-sha256" +#define NID_aes_192_cbc_hmac_sha256 949 + +#define SN_aes_256_cbc_hmac_sha256 "AES-256-CBC-HMAC-SHA256" +#define LN_aes_256_cbc_hmac_sha256 "aes-256-cbc-hmac-sha256" +#define NID_aes_256_cbc_hmac_sha256 950 + +#define SN_chacha20_poly1305 "ChaCha20-Poly1305" +#define LN_chacha20_poly1305 "chacha20-poly1305" +#define NID_chacha20_poly1305 1018 + +#define SN_chacha20 "ChaCha20" +#define LN_chacha20 "chacha20" +#define NID_chacha20 1019 + +#define SN_dhpublicnumber "dhpublicnumber" +#define LN_dhpublicnumber "X9.42 DH" +#define NID_dhpublicnumber 920 +#define OBJ_dhpublicnumber OBJ_ISO_US,10046L,2L,1L + +#define SN_brainpoolP160r1 "brainpoolP160r1" +#define NID_brainpoolP160r1 921 +#define OBJ_brainpoolP160r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,1L + +#define SN_brainpoolP160t1 "brainpoolP160t1" +#define NID_brainpoolP160t1 922 +#define OBJ_brainpoolP160t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,2L + +#define SN_brainpoolP192r1 "brainpoolP192r1" +#define NID_brainpoolP192r1 923 +#define OBJ_brainpoolP192r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,3L + +#define SN_brainpoolP192t1 "brainpoolP192t1" +#define NID_brainpoolP192t1 924 +#define OBJ_brainpoolP192t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,4L + +#define SN_brainpoolP224r1 "brainpoolP224r1" +#define NID_brainpoolP224r1 925 +#define OBJ_brainpoolP224r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,5L + +#define SN_brainpoolP224t1 "brainpoolP224t1" +#define NID_brainpoolP224t1 926 +#define OBJ_brainpoolP224t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,6L + +#define SN_brainpoolP256r1 "brainpoolP256r1" +#define NID_brainpoolP256r1 927 +#define OBJ_brainpoolP256r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,7L + +#define SN_brainpoolP256t1 "brainpoolP256t1" +#define NID_brainpoolP256t1 928 +#define OBJ_brainpoolP256t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,8L + +#define SN_brainpoolP320r1 "brainpoolP320r1" +#define NID_brainpoolP320r1 929 +#define OBJ_brainpoolP320r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,9L + +#define SN_brainpoolP320t1 "brainpoolP320t1" +#define NID_brainpoolP320t1 930 +#define OBJ_brainpoolP320t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,10L + +#define SN_brainpoolP384r1 "brainpoolP384r1" +#define NID_brainpoolP384r1 931 +#define OBJ_brainpoolP384r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,11L + +#define SN_brainpoolP384t1 "brainpoolP384t1" +#define NID_brainpoolP384t1 932 +#define OBJ_brainpoolP384t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,12L + +#define SN_brainpoolP512r1 "brainpoolP512r1" +#define NID_brainpoolP512r1 933 +#define OBJ_brainpoolP512r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,13L + +#define SN_brainpoolP512t1 "brainpoolP512t1" +#define NID_brainpoolP512t1 934 +#define OBJ_brainpoolP512t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,14L + +#define OBJ_x9_63_scheme 1L,3L,133L,16L,840L,63L,0L + +#define OBJ_secg_scheme OBJ_certicom_arc,1L + +#define SN_dhSinglePass_stdDH_sha1kdf_scheme "dhSinglePass-stdDH-sha1kdf-scheme" +#define NID_dhSinglePass_stdDH_sha1kdf_scheme 936 +#define OBJ_dhSinglePass_stdDH_sha1kdf_scheme OBJ_x9_63_scheme,2L + +#define SN_dhSinglePass_stdDH_sha224kdf_scheme "dhSinglePass-stdDH-sha224kdf-scheme" +#define NID_dhSinglePass_stdDH_sha224kdf_scheme 937 +#define OBJ_dhSinglePass_stdDH_sha224kdf_scheme OBJ_secg_scheme,11L,0L + +#define SN_dhSinglePass_stdDH_sha256kdf_scheme "dhSinglePass-stdDH-sha256kdf-scheme" +#define NID_dhSinglePass_stdDH_sha256kdf_scheme 938 +#define OBJ_dhSinglePass_stdDH_sha256kdf_scheme OBJ_secg_scheme,11L,1L + +#define SN_dhSinglePass_stdDH_sha384kdf_scheme "dhSinglePass-stdDH-sha384kdf-scheme" +#define NID_dhSinglePass_stdDH_sha384kdf_scheme 939 +#define OBJ_dhSinglePass_stdDH_sha384kdf_scheme OBJ_secg_scheme,11L,2L + +#define SN_dhSinglePass_stdDH_sha512kdf_scheme "dhSinglePass-stdDH-sha512kdf-scheme" +#define NID_dhSinglePass_stdDH_sha512kdf_scheme 940 +#define OBJ_dhSinglePass_stdDH_sha512kdf_scheme OBJ_secg_scheme,11L,3L + +#define SN_dhSinglePass_cofactorDH_sha1kdf_scheme "dhSinglePass-cofactorDH-sha1kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha1kdf_scheme 941 +#define OBJ_dhSinglePass_cofactorDH_sha1kdf_scheme OBJ_x9_63_scheme,3L + +#define SN_dhSinglePass_cofactorDH_sha224kdf_scheme "dhSinglePass-cofactorDH-sha224kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha224kdf_scheme 942 +#define OBJ_dhSinglePass_cofactorDH_sha224kdf_scheme OBJ_secg_scheme,14L,0L + +#define SN_dhSinglePass_cofactorDH_sha256kdf_scheme "dhSinglePass-cofactorDH-sha256kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha256kdf_scheme 943 +#define OBJ_dhSinglePass_cofactorDH_sha256kdf_scheme OBJ_secg_scheme,14L,1L + +#define SN_dhSinglePass_cofactorDH_sha384kdf_scheme "dhSinglePass-cofactorDH-sha384kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha384kdf_scheme 944 +#define OBJ_dhSinglePass_cofactorDH_sha384kdf_scheme OBJ_secg_scheme,14L,2L + +#define SN_dhSinglePass_cofactorDH_sha512kdf_scheme "dhSinglePass-cofactorDH-sha512kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha512kdf_scheme 945 +#define OBJ_dhSinglePass_cofactorDH_sha512kdf_scheme OBJ_secg_scheme,14L,3L + +#define SN_dh_std_kdf "dh-std-kdf" +#define NID_dh_std_kdf 946 + +#define SN_dh_cofactor_kdf "dh-cofactor-kdf" +#define NID_dh_cofactor_kdf 947 + +#define SN_ct_precert_scts "ct_precert_scts" +#define LN_ct_precert_scts "CT Precertificate SCTs" +#define NID_ct_precert_scts 951 +#define OBJ_ct_precert_scts 1L,3L,6L,1L,4L,1L,11129L,2L,4L,2L + +#define SN_ct_precert_poison "ct_precert_poison" +#define LN_ct_precert_poison "CT Precertificate Poison" +#define NID_ct_precert_poison 952 +#define OBJ_ct_precert_poison 1L,3L,6L,1L,4L,1L,11129L,2L,4L,3L + +#define SN_ct_precert_signer "ct_precert_signer" +#define LN_ct_precert_signer "CT Precertificate Signer" +#define NID_ct_precert_signer 953 +#define OBJ_ct_precert_signer 1L,3L,6L,1L,4L,1L,11129L,2L,4L,4L + +#define SN_ct_cert_scts "ct_cert_scts" +#define LN_ct_cert_scts "CT Certificate SCTs" +#define NID_ct_cert_scts 954 +#define OBJ_ct_cert_scts 1L,3L,6L,1L,4L,1L,11129L,2L,4L,5L + +#define SN_jurisdictionLocalityName "jurisdictionL" +#define LN_jurisdictionLocalityName "jurisdictionLocalityName" +#define NID_jurisdictionLocalityName 955 +#define OBJ_jurisdictionLocalityName 1L,3L,6L,1L,4L,1L,311L,60L,2L,1L,1L + +#define SN_jurisdictionStateOrProvinceName "jurisdictionST" +#define LN_jurisdictionStateOrProvinceName "jurisdictionStateOrProvinceName" +#define NID_jurisdictionStateOrProvinceName 956 +#define OBJ_jurisdictionStateOrProvinceName 1L,3L,6L,1L,4L,1L,311L,60L,2L,1L,2L + +#define SN_jurisdictionCountryName "jurisdictionC" +#define LN_jurisdictionCountryName "jurisdictionCountryName" +#define NID_jurisdictionCountryName 957 +#define OBJ_jurisdictionCountryName 1L,3L,6L,1L,4L,1L,311L,60L,2L,1L,3L + +#define SN_id_scrypt "id-scrypt" +#define NID_id_scrypt 973 +#define OBJ_id_scrypt 1L,3L,6L,1L,4L,1L,11591L,4L,11L + +#define SN_tls1_prf "TLS1-PRF" +#define LN_tls1_prf "tls1-prf" +#define NID_tls1_prf 1021 + +#define SN_hkdf "HKDF" +#define LN_hkdf "hkdf" +#define NID_hkdf 1036 + +#define SN_id_pkinit "id-pkinit" +#define NID_id_pkinit 1031 +#define OBJ_id_pkinit 1L,3L,6L,1L,5L,2L,3L + +#define SN_pkInitClientAuth "pkInitClientAuth" +#define LN_pkInitClientAuth "PKINIT Client Auth" +#define NID_pkInitClientAuth 1032 +#define OBJ_pkInitClientAuth OBJ_id_pkinit,4L + +#define SN_pkInitKDC "pkInitKDC" +#define LN_pkInitKDC "Signing KDC Response" +#define NID_pkInitKDC 1033 +#define OBJ_pkInitKDC OBJ_id_pkinit,5L + +#define SN_X25519 "X25519" +#define NID_X25519 1034 +#define OBJ_X25519 1L,3L,101L,110L + +#define SN_X448 "X448" +#define NID_X448 1035 +#define OBJ_X448 1L,3L,101L,111L + +#define SN_kx_rsa "KxRSA" +#define LN_kx_rsa "kx-rsa" +#define NID_kx_rsa 1037 + +#define SN_kx_ecdhe "KxECDHE" +#define LN_kx_ecdhe "kx-ecdhe" +#define NID_kx_ecdhe 1038 + +#define SN_kx_dhe "KxDHE" +#define LN_kx_dhe "kx-dhe" +#define NID_kx_dhe 1039 + +#define SN_kx_ecdhe_psk "KxECDHE-PSK" +#define LN_kx_ecdhe_psk "kx-ecdhe-psk" +#define NID_kx_ecdhe_psk 1040 + +#define SN_kx_dhe_psk "KxDHE-PSK" +#define LN_kx_dhe_psk "kx-dhe-psk" +#define NID_kx_dhe_psk 1041 + +#define SN_kx_rsa_psk "KxRSA_PSK" +#define LN_kx_rsa_psk "kx-rsa-psk" +#define NID_kx_rsa_psk 1042 + +#define SN_kx_psk "KxPSK" +#define LN_kx_psk "kx-psk" +#define NID_kx_psk 1043 + +#define SN_kx_srp "KxSRP" +#define LN_kx_srp "kx-srp" +#define NID_kx_srp 1044 + +#define SN_kx_gost "KxGOST" +#define LN_kx_gost "kx-gost" +#define NID_kx_gost 1045 + +#define SN_auth_rsa "AuthRSA" +#define LN_auth_rsa "auth-rsa" +#define NID_auth_rsa 1046 + +#define SN_auth_ecdsa "AuthECDSA" +#define LN_auth_ecdsa "auth-ecdsa" +#define NID_auth_ecdsa 1047 + +#define SN_auth_psk "AuthPSK" +#define LN_auth_psk "auth-psk" +#define NID_auth_psk 1048 + +#define SN_auth_dss "AuthDSS" +#define LN_auth_dss "auth-dss" +#define NID_auth_dss 1049 + +#define SN_auth_gost01 "AuthGOST01" +#define LN_auth_gost01 "auth-gost01" +#define NID_auth_gost01 1050 + +#define SN_auth_gost12 "AuthGOST12" +#define LN_auth_gost12 "auth-gost12" +#define NID_auth_gost12 1051 + +#define SN_auth_srp "AuthSRP" +#define LN_auth_srp "auth-srp" +#define NID_auth_srp 1052 + +#define SN_auth_null "AuthNULL" +#define LN_auth_null "auth-null" +#define NID_auth_null 1053 diff --git a/android/x86/include/openssl/objects.h b/android/x86/include/openssl/objects.h new file mode 100644 index 00000000..09d614ff --- /dev/null +++ b/android/x86/include/openssl/objects.h @@ -0,0 +1,1097 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OBJECTS_H +# define HEADER_OBJECTS_H + +# define USE_OBJ_MAC + +# ifdef USE_OBJ_MAC +# include <openssl/obj_mac.h> +# else +# define SN_undef "UNDEF" +# define LN_undef "undefined" +# define NID_undef 0 +# define OBJ_undef 0L + +# define SN_Algorithm "Algorithm" +# define LN_algorithm "algorithm" +# define NID_algorithm 38 +# define OBJ_algorithm 1L,3L,14L,3L,2L + +# define LN_rsadsi "rsadsi" +# define NID_rsadsi 1 +# define OBJ_rsadsi 1L,2L,840L,113549L + +# define LN_pkcs "pkcs" +# define NID_pkcs 2 +# define OBJ_pkcs OBJ_rsadsi,1L + +# define SN_md2 "MD2" +# define LN_md2 "md2" +# define NID_md2 3 +# define OBJ_md2 OBJ_rsadsi,2L,2L + +# define SN_md5 "MD5" +# define LN_md5 "md5" +# define NID_md5 4 +# define OBJ_md5 OBJ_rsadsi,2L,5L + +# define SN_rc4 "RC4" +# define LN_rc4 "rc4" +# define NID_rc4 5 +# define OBJ_rc4 OBJ_rsadsi,3L,4L + +# define LN_rsaEncryption "rsaEncryption" +# define NID_rsaEncryption 6 +# define OBJ_rsaEncryption OBJ_pkcs,1L,1L + +# define SN_md2WithRSAEncryption "RSA-MD2" +# define LN_md2WithRSAEncryption "md2WithRSAEncryption" +# define NID_md2WithRSAEncryption 7 +# define OBJ_md2WithRSAEncryption OBJ_pkcs,1L,2L + +# define SN_md5WithRSAEncryption "RSA-MD5" +# define LN_md5WithRSAEncryption "md5WithRSAEncryption" +# define NID_md5WithRSAEncryption 8 +# define OBJ_md5WithRSAEncryption OBJ_pkcs,1L,4L + +# define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES" +# define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC" +# define NID_pbeWithMD2AndDES_CBC 9 +# define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L + +# define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES" +# define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC" +# define NID_pbeWithMD5AndDES_CBC 10 +# define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L + +# define LN_X500 "X500" +# define NID_X500 11 +# define OBJ_X500 2L,5L + +# define LN_X509 "X509" +# define NID_X509 12 +# define OBJ_X509 OBJ_X500,4L + +# define SN_commonName "CN" +# define LN_commonName "commonName" +# define NID_commonName 13 +# define OBJ_commonName OBJ_X509,3L + +# define SN_countryName "C" +# define LN_countryName "countryName" +# define NID_countryName 14 +# define OBJ_countryName OBJ_X509,6L + +# define SN_localityName "L" +# define LN_localityName "localityName" +# define NID_localityName 15 +# define OBJ_localityName OBJ_X509,7L + +/* Postal Address? PA */ + +/* should be "ST" (rfc1327) but MS uses 'S' */ +# define SN_stateOrProvinceName "ST" +# define LN_stateOrProvinceName "stateOrProvinceName" +# define NID_stateOrProvinceName 16 +# define OBJ_stateOrProvinceName OBJ_X509,8L + +# define SN_organizationName "O" +# define LN_organizationName "organizationName" +# define NID_organizationName 17 +# define OBJ_organizationName OBJ_X509,10L + +# define SN_organizationalUnitName "OU" +# define LN_organizationalUnitName "organizationalUnitName" +# define NID_organizationalUnitName 18 +# define OBJ_organizationalUnitName OBJ_X509,11L + +# define SN_rsa "RSA" +# define LN_rsa "rsa" +# define NID_rsa 19 +# define OBJ_rsa OBJ_X500,8L,1L,1L + +# define LN_pkcs7 "pkcs7" +# define NID_pkcs7 20 +# define OBJ_pkcs7 OBJ_pkcs,7L + +# define LN_pkcs7_data "pkcs7-data" +# define NID_pkcs7_data 21 +# define OBJ_pkcs7_data OBJ_pkcs7,1L + +# define LN_pkcs7_signed "pkcs7-signedData" +# define NID_pkcs7_signed 22 +# define OBJ_pkcs7_signed OBJ_pkcs7,2L + +# define LN_pkcs7_enveloped "pkcs7-envelopedData" +# define NID_pkcs7_enveloped 23 +# define OBJ_pkcs7_enveloped OBJ_pkcs7,3L + +# define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData" +# define NID_pkcs7_signedAndEnveloped 24 +# define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L + +# define LN_pkcs7_digest "pkcs7-digestData" +# define NID_pkcs7_digest 25 +# define OBJ_pkcs7_digest OBJ_pkcs7,5L + +# define LN_pkcs7_encrypted "pkcs7-encryptedData" +# define NID_pkcs7_encrypted 26 +# define OBJ_pkcs7_encrypted OBJ_pkcs7,6L + +# define LN_pkcs3 "pkcs3" +# define NID_pkcs3 27 +# define OBJ_pkcs3 OBJ_pkcs,3L + +# define LN_dhKeyAgreement "dhKeyAgreement" +# define NID_dhKeyAgreement 28 +# define OBJ_dhKeyAgreement OBJ_pkcs3,1L + +# define SN_des_ecb "DES-ECB" +# define LN_des_ecb "des-ecb" +# define NID_des_ecb 29 +# define OBJ_des_ecb OBJ_algorithm,6L + +# define SN_des_cfb64 "DES-CFB" +# define LN_des_cfb64 "des-cfb" +# define NID_des_cfb64 30 +/* IV + num */ +# define OBJ_des_cfb64 OBJ_algorithm,9L + +# define SN_des_cbc "DES-CBC" +# define LN_des_cbc "des-cbc" +# define NID_des_cbc 31 +/* IV */ +# define OBJ_des_cbc OBJ_algorithm,7L + +# define SN_des_ede "DES-EDE" +# define LN_des_ede "des-ede" +# define NID_des_ede 32 +/* ?? */ +# define OBJ_des_ede OBJ_algorithm,17L + +# define SN_des_ede3 "DES-EDE3" +# define LN_des_ede3 "des-ede3" +# define NID_des_ede3 33 + +# define SN_idea_cbc "IDEA-CBC" +# define LN_idea_cbc "idea-cbc" +# define NID_idea_cbc 34 +# define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L + +# define SN_idea_cfb64 "IDEA-CFB" +# define LN_idea_cfb64 "idea-cfb" +# define NID_idea_cfb64 35 + +# define SN_idea_ecb "IDEA-ECB" +# define LN_idea_ecb "idea-ecb" +# define NID_idea_ecb 36 + +# define SN_rc2_cbc "RC2-CBC" +# define LN_rc2_cbc "rc2-cbc" +# define NID_rc2_cbc 37 +# define OBJ_rc2_cbc OBJ_rsadsi,3L,2L + +# define SN_rc2_ecb "RC2-ECB" +# define LN_rc2_ecb "rc2-ecb" +# define NID_rc2_ecb 38 + +# define SN_rc2_cfb64 "RC2-CFB" +# define LN_rc2_cfb64 "rc2-cfb" +# define NID_rc2_cfb64 39 + +# define SN_rc2_ofb64 "RC2-OFB" +# define LN_rc2_ofb64 "rc2-ofb" +# define NID_rc2_ofb64 40 + +# define SN_sha "SHA" +# define LN_sha "sha" +# define NID_sha 41 +# define OBJ_sha OBJ_algorithm,18L + +# define SN_shaWithRSAEncryption "RSA-SHA" +# define LN_shaWithRSAEncryption "shaWithRSAEncryption" +# define NID_shaWithRSAEncryption 42 +# define OBJ_shaWithRSAEncryption OBJ_algorithm,15L + +# define SN_des_ede_cbc "DES-EDE-CBC" +# define LN_des_ede_cbc "des-ede-cbc" +# define NID_des_ede_cbc 43 + +# define SN_des_ede3_cbc "DES-EDE3-CBC" +# define LN_des_ede3_cbc "des-ede3-cbc" +# define NID_des_ede3_cbc 44 +# define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L + +# define SN_des_ofb64 "DES-OFB" +# define LN_des_ofb64 "des-ofb" +# define NID_des_ofb64 45 +# define OBJ_des_ofb64 OBJ_algorithm,8L + +# define SN_idea_ofb64 "IDEA-OFB" +# define LN_idea_ofb64 "idea-ofb" +# define NID_idea_ofb64 46 + +# define LN_pkcs9 "pkcs9" +# define NID_pkcs9 47 +# define OBJ_pkcs9 OBJ_pkcs,9L + +# define SN_pkcs9_emailAddress "Email" +# define LN_pkcs9_emailAddress "emailAddress" +# define NID_pkcs9_emailAddress 48 +# define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L + +# define LN_pkcs9_unstructuredName "unstructuredName" +# define NID_pkcs9_unstructuredName 49 +# define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L + +# define LN_pkcs9_contentType "contentType" +# define NID_pkcs9_contentType 50 +# define OBJ_pkcs9_contentType OBJ_pkcs9,3L + +# define LN_pkcs9_messageDigest "messageDigest" +# define NID_pkcs9_messageDigest 51 +# define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L + +# define LN_pkcs9_signingTime "signingTime" +# define NID_pkcs9_signingTime 52 +# define OBJ_pkcs9_signingTime OBJ_pkcs9,5L + +# define LN_pkcs9_countersignature "countersignature" +# define NID_pkcs9_countersignature 53 +# define OBJ_pkcs9_countersignature OBJ_pkcs9,6L + +# define LN_pkcs9_challengePassword "challengePassword" +# define NID_pkcs9_challengePassword 54 +# define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L + +# define LN_pkcs9_unstructuredAddress "unstructuredAddress" +# define NID_pkcs9_unstructuredAddress 55 +# define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L + +# define LN_pkcs9_extCertAttributes "extendedCertificateAttributes" +# define NID_pkcs9_extCertAttributes 56 +# define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L + +# define SN_netscape "Netscape" +# define LN_netscape "Netscape Communications Corp." +# define NID_netscape 57 +# define OBJ_netscape 2L,16L,840L,1L,113730L + +# define SN_netscape_cert_extension "nsCertExt" +# define LN_netscape_cert_extension "Netscape Certificate Extension" +# define NID_netscape_cert_extension 58 +# define OBJ_netscape_cert_extension OBJ_netscape,1L + +# define SN_netscape_data_type "nsDataType" +# define LN_netscape_data_type "Netscape Data Type" +# define NID_netscape_data_type 59 +# define OBJ_netscape_data_type OBJ_netscape,2L + +# define SN_des_ede_cfb64 "DES-EDE-CFB" +# define LN_des_ede_cfb64 "des-ede-cfb" +# define NID_des_ede_cfb64 60 + +# define SN_des_ede3_cfb64 "DES-EDE3-CFB" +# define LN_des_ede3_cfb64 "des-ede3-cfb" +# define NID_des_ede3_cfb64 61 + +# define SN_des_ede_ofb64 "DES-EDE-OFB" +# define LN_des_ede_ofb64 "des-ede-ofb" +# define NID_des_ede_ofb64 62 + +# define SN_des_ede3_ofb64 "DES-EDE3-OFB" +# define LN_des_ede3_ofb64 "des-ede3-ofb" +# define NID_des_ede3_ofb64 63 + +/* I'm not sure about the object ID */ +# define SN_sha1 "SHA1" +# define LN_sha1 "sha1" +# define NID_sha1 64 +# define OBJ_sha1 OBJ_algorithm,26L +/* 28 Jun 1996 - eay */ +/* #define OBJ_sha1 1L,3L,14L,2L,26L,05L <- wrong */ + +# define SN_sha1WithRSAEncryption "RSA-SHA1" +# define LN_sha1WithRSAEncryption "sha1WithRSAEncryption" +# define NID_sha1WithRSAEncryption 65 +# define OBJ_sha1WithRSAEncryption OBJ_pkcs,1L,5L + +# define SN_dsaWithSHA "DSA-SHA" +# define LN_dsaWithSHA "dsaWithSHA" +# define NID_dsaWithSHA 66 +# define OBJ_dsaWithSHA OBJ_algorithm,13L + +# define SN_dsa_2 "DSA-old" +# define LN_dsa_2 "dsaEncryption-old" +# define NID_dsa_2 67 +# define OBJ_dsa_2 OBJ_algorithm,12L + +/* proposed by microsoft to RSA */ +# define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64" +# define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC" +# define NID_pbeWithSHA1AndRC2_CBC 68 +# define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L + +/* + * proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now defined + * explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something completely + * different. + */ +# define LN_id_pbkdf2 "PBKDF2" +# define NID_id_pbkdf2 69 +# define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L + +# define SN_dsaWithSHA1_2 "DSA-SHA1-old" +# define LN_dsaWithSHA1_2 "dsaWithSHA1-old" +# define NID_dsaWithSHA1_2 70 +/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */ +# define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L + +# define SN_netscape_cert_type "nsCertType" +# define LN_netscape_cert_type "Netscape Cert Type" +# define NID_netscape_cert_type 71 +# define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L + +# define SN_netscape_base_url "nsBaseUrl" +# define LN_netscape_base_url "Netscape Base Url" +# define NID_netscape_base_url 72 +# define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L + +# define SN_netscape_revocation_url "nsRevocationUrl" +# define LN_netscape_revocation_url "Netscape Revocation Url" +# define NID_netscape_revocation_url 73 +# define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L + +# define SN_netscape_ca_revocation_url "nsCaRevocationUrl" +# define LN_netscape_ca_revocation_url "Netscape CA Revocation Url" +# define NID_netscape_ca_revocation_url 74 +# define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L + +# define SN_netscape_renewal_url "nsRenewalUrl" +# define LN_netscape_renewal_url "Netscape Renewal Url" +# define NID_netscape_renewal_url 75 +# define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L + +# define SN_netscape_ca_policy_url "nsCaPolicyUrl" +# define LN_netscape_ca_policy_url "Netscape CA Policy Url" +# define NID_netscape_ca_policy_url 76 +# define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L + +# define SN_netscape_ssl_server_name "nsSslServerName" +# define LN_netscape_ssl_server_name "Netscape SSL Server Name" +# define NID_netscape_ssl_server_name 77 +# define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L + +# define SN_netscape_comment "nsComment" +# define LN_netscape_comment "Netscape Comment" +# define NID_netscape_comment 78 +# define OBJ_netscape_comment OBJ_netscape_cert_extension,13L + +# define SN_netscape_cert_sequence "nsCertSequence" +# define LN_netscape_cert_sequence "Netscape Certificate Sequence" +# define NID_netscape_cert_sequence 79 +# define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L + +# define SN_desx_cbc "DESX-CBC" +# define LN_desx_cbc "desx-cbc" +# define NID_desx_cbc 80 + +# define SN_id_ce "id-ce" +# define NID_id_ce 81 +# define OBJ_id_ce 2L,5L,29L + +# define SN_subject_key_identifier "subjectKeyIdentifier" +# define LN_subject_key_identifier "X509v3 Subject Key Identifier" +# define NID_subject_key_identifier 82 +# define OBJ_subject_key_identifier OBJ_id_ce,14L + +# define SN_key_usage "keyUsage" +# define LN_key_usage "X509v3 Key Usage" +# define NID_key_usage 83 +# define OBJ_key_usage OBJ_id_ce,15L + +# define SN_private_key_usage_period "privateKeyUsagePeriod" +# define LN_private_key_usage_period "X509v3 Private Key Usage Period" +# define NID_private_key_usage_period 84 +# define OBJ_private_key_usage_period OBJ_id_ce,16L + +# define SN_subject_alt_name "subjectAltName" +# define LN_subject_alt_name "X509v3 Subject Alternative Name" +# define NID_subject_alt_name 85 +# define OBJ_subject_alt_name OBJ_id_ce,17L + +# define SN_issuer_alt_name "issuerAltName" +# define LN_issuer_alt_name "X509v3 Issuer Alternative Name" +# define NID_issuer_alt_name 86 +# define OBJ_issuer_alt_name OBJ_id_ce,18L + +# define SN_basic_constraints "basicConstraints" +# define LN_basic_constraints "X509v3 Basic Constraints" +# define NID_basic_constraints 87 +# define OBJ_basic_constraints OBJ_id_ce,19L + +# define SN_crl_number "crlNumber" +# define LN_crl_number "X509v3 CRL Number" +# define NID_crl_number 88 +# define OBJ_crl_number OBJ_id_ce,20L + +# define SN_certificate_policies "certificatePolicies" +# define LN_certificate_policies "X509v3 Certificate Policies" +# define NID_certificate_policies 89 +# define OBJ_certificate_policies OBJ_id_ce,32L + +# define SN_authority_key_identifier "authorityKeyIdentifier" +# define LN_authority_key_identifier "X509v3 Authority Key Identifier" +# define NID_authority_key_identifier 90 +# define OBJ_authority_key_identifier OBJ_id_ce,35L + +# define SN_bf_cbc "BF-CBC" +# define LN_bf_cbc "bf-cbc" +# define NID_bf_cbc 91 +# define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L + +# define SN_bf_ecb "BF-ECB" +# define LN_bf_ecb "bf-ecb" +# define NID_bf_ecb 92 + +# define SN_bf_cfb64 "BF-CFB" +# define LN_bf_cfb64 "bf-cfb" +# define NID_bf_cfb64 93 + +# define SN_bf_ofb64 "BF-OFB" +# define LN_bf_ofb64 "bf-ofb" +# define NID_bf_ofb64 94 + +# define SN_mdc2 "MDC2" +# define LN_mdc2 "mdc2" +# define NID_mdc2 95 +# define OBJ_mdc2 2L,5L,8L,3L,101L +/* An alternative? 1L,3L,14L,3L,2L,19L */ + +# define SN_mdc2WithRSA "RSA-MDC2" +# define LN_mdc2WithRSA "mdc2withRSA" +# define NID_mdc2WithRSA 96 +# define OBJ_mdc2WithRSA 2L,5L,8L,3L,100L + +# define SN_rc4_40 "RC4-40" +# define LN_rc4_40 "rc4-40" +# define NID_rc4_40 97 + +# define SN_rc2_40_cbc "RC2-40-CBC" +# define LN_rc2_40_cbc "rc2-40-cbc" +# define NID_rc2_40_cbc 98 + +# define SN_givenName "G" +# define LN_givenName "givenName" +# define NID_givenName 99 +# define OBJ_givenName OBJ_X509,42L + +# define SN_surname "S" +# define LN_surname "surname" +# define NID_surname 100 +# define OBJ_surname OBJ_X509,4L + +# define SN_initials "I" +# define LN_initials "initials" +# define NID_initials 101 +# define OBJ_initials OBJ_X509,43L + +# define SN_uniqueIdentifier "UID" +# define LN_uniqueIdentifier "uniqueIdentifier" +# define NID_uniqueIdentifier 102 +# define OBJ_uniqueIdentifier OBJ_X509,45L + +# define SN_crl_distribution_points "crlDistributionPoints" +# define LN_crl_distribution_points "X509v3 CRL Distribution Points" +# define NID_crl_distribution_points 103 +# define OBJ_crl_distribution_points OBJ_id_ce,31L + +# define SN_md5WithRSA "RSA-NP-MD5" +# define LN_md5WithRSA "md5WithRSA" +# define NID_md5WithRSA 104 +# define OBJ_md5WithRSA OBJ_algorithm,3L + +# define SN_serialNumber "SN" +# define LN_serialNumber "serialNumber" +# define NID_serialNumber 105 +# define OBJ_serialNumber OBJ_X509,5L + +# define SN_title "T" +# define LN_title "title" +# define NID_title 106 +# define OBJ_title OBJ_X509,12L + +# define SN_description "D" +# define LN_description "description" +# define NID_description 107 +# define OBJ_description OBJ_X509,13L + +/* CAST5 is CAST-128, I'm just sticking with the documentation */ +# define SN_cast5_cbc "CAST5-CBC" +# define LN_cast5_cbc "cast5-cbc" +# define NID_cast5_cbc 108 +# define OBJ_cast5_cbc 1L,2L,840L,113533L,7L,66L,10L + +# define SN_cast5_ecb "CAST5-ECB" +# define LN_cast5_ecb "cast5-ecb" +# define NID_cast5_ecb 109 + +# define SN_cast5_cfb64 "CAST5-CFB" +# define LN_cast5_cfb64 "cast5-cfb" +# define NID_cast5_cfb64 110 + +# define SN_cast5_ofb64 "CAST5-OFB" +# define LN_cast5_ofb64 "cast5-ofb" +# define NID_cast5_ofb64 111 + +# define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC" +# define NID_pbeWithMD5AndCast5_CBC 112 +# define OBJ_pbeWithMD5AndCast5_CBC 1L,2L,840L,113533L,7L,66L,12L + +/*- + * This is one sun will soon be using :-( + * id-dsa-with-sha1 ID ::= { + * iso(1) member-body(2) us(840) x9-57 (10040) x9cm(4) 3 } + */ +# define SN_dsaWithSHA1 "DSA-SHA1" +# define LN_dsaWithSHA1 "dsaWithSHA1" +# define NID_dsaWithSHA1 113 +# define OBJ_dsaWithSHA1 1L,2L,840L,10040L,4L,3L + +# define NID_md5_sha1 114 +# define SN_md5_sha1 "MD5-SHA1" +# define LN_md5_sha1 "md5-sha1" + +# define SN_sha1WithRSA "RSA-SHA1-2" +# define LN_sha1WithRSA "sha1WithRSA" +# define NID_sha1WithRSA 115 +# define OBJ_sha1WithRSA OBJ_algorithm,29L + +# define SN_dsa "DSA" +# define LN_dsa "dsaEncryption" +# define NID_dsa 116 +# define OBJ_dsa 1L,2L,840L,10040L,4L,1L + +# define SN_ripemd160 "RIPEMD160" +# define LN_ripemd160 "ripemd160" +# define NID_ripemd160 117 +# define OBJ_ripemd160 1L,3L,36L,3L,2L,1L + +/* + * The name should actually be rsaSignatureWithripemd160, but I'm going to + * continue using the convention I'm using with the other ciphers + */ +# define SN_ripemd160WithRSA "RSA-RIPEMD160" +# define LN_ripemd160WithRSA "ripemd160WithRSA" +# define NID_ripemd160WithRSA 119 +# define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L + +/*- + * Taken from rfc2040 + * RC5_CBC_Parameters ::= SEQUENCE { + * version INTEGER (v1_0(16)), + * rounds INTEGER (8..127), + * blockSizeInBits INTEGER (64, 128), + * iv OCTET STRING OPTIONAL + * } + */ +# define SN_rc5_cbc "RC5-CBC" +# define LN_rc5_cbc "rc5-cbc" +# define NID_rc5_cbc 120 +# define OBJ_rc5_cbc OBJ_rsadsi,3L,8L + +# define SN_rc5_ecb "RC5-ECB" +# define LN_rc5_ecb "rc5-ecb" +# define NID_rc5_ecb 121 + +# define SN_rc5_cfb64 "RC5-CFB" +# define LN_rc5_cfb64 "rc5-cfb" +# define NID_rc5_cfb64 122 + +# define SN_rc5_ofb64 "RC5-OFB" +# define LN_rc5_ofb64 "rc5-ofb" +# define NID_rc5_ofb64 123 + +# define SN_rle_compression "RLE" +# define LN_rle_compression "run length compression" +# define NID_rle_compression 124 +# define OBJ_rle_compression 1L,1L,1L,1L,666L,1L + +# define SN_zlib_compression "ZLIB" +# define LN_zlib_compression "zlib compression" +# define NID_zlib_compression 125 +# define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L + +# define SN_ext_key_usage "extendedKeyUsage" +# define LN_ext_key_usage "X509v3 Extended Key Usage" +# define NID_ext_key_usage 126 +# define OBJ_ext_key_usage OBJ_id_ce,37 + +# define SN_id_pkix "PKIX" +# define NID_id_pkix 127 +# define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L + +# define SN_id_kp "id-kp" +# define NID_id_kp 128 +# define OBJ_id_kp OBJ_id_pkix,3L + +/* PKIX extended key usage OIDs */ + +# define SN_server_auth "serverAuth" +# define LN_server_auth "TLS Web Server Authentication" +# define NID_server_auth 129 +# define OBJ_server_auth OBJ_id_kp,1L + +# define SN_client_auth "clientAuth" +# define LN_client_auth "TLS Web Client Authentication" +# define NID_client_auth 130 +# define OBJ_client_auth OBJ_id_kp,2L + +# define SN_code_sign "codeSigning" +# define LN_code_sign "Code Signing" +# define NID_code_sign 131 +# define OBJ_code_sign OBJ_id_kp,3L + +# define SN_email_protect "emailProtection" +# define LN_email_protect "E-mail Protection" +# define NID_email_protect 132 +# define OBJ_email_protect OBJ_id_kp,4L + +# define SN_time_stamp "timeStamping" +# define LN_time_stamp "Time Stamping" +# define NID_time_stamp 133 +# define OBJ_time_stamp OBJ_id_kp,8L + +/* Additional extended key usage OIDs: Microsoft */ + +# define SN_ms_code_ind "msCodeInd" +# define LN_ms_code_ind "Microsoft Individual Code Signing" +# define NID_ms_code_ind 134 +# define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L + +# define SN_ms_code_com "msCodeCom" +# define LN_ms_code_com "Microsoft Commercial Code Signing" +# define NID_ms_code_com 135 +# define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L + +# define SN_ms_ctl_sign "msCTLSign" +# define LN_ms_ctl_sign "Microsoft Trust List Signing" +# define NID_ms_ctl_sign 136 +# define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L + +# define SN_ms_sgc "msSGC" +# define LN_ms_sgc "Microsoft Server Gated Crypto" +# define NID_ms_sgc 137 +# define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L + +# define SN_ms_efs "msEFS" +# define LN_ms_efs "Microsoft Encrypted File System" +# define NID_ms_efs 138 +# define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L + +/* Additional usage: Netscape */ + +# define SN_ns_sgc "nsSGC" +# define LN_ns_sgc "Netscape Server Gated Crypto" +# define NID_ns_sgc 139 +# define OBJ_ns_sgc OBJ_netscape,4L,1L + +# define SN_delta_crl "deltaCRL" +# define LN_delta_crl "X509v3 Delta CRL Indicator" +# define NID_delta_crl 140 +# define OBJ_delta_crl OBJ_id_ce,27L + +# define SN_crl_reason "CRLReason" +# define LN_crl_reason "CRL Reason Code" +# define NID_crl_reason 141 +# define OBJ_crl_reason OBJ_id_ce,21L + +# define SN_invalidity_date "invalidityDate" +# define LN_invalidity_date "Invalidity Date" +# define NID_invalidity_date 142 +# define OBJ_invalidity_date OBJ_id_ce,24L + +# define SN_sxnet "SXNetID" +# define LN_sxnet "Strong Extranet ID" +# define NID_sxnet 143 +# define OBJ_sxnet 1L,3L,101L,1L,4L,1L + +/* PKCS12 and related OBJECT IDENTIFIERS */ + +# define OBJ_pkcs12 OBJ_pkcs,12L +# define OBJ_pkcs12_pbeids OBJ_pkcs12, 1 + +# define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128" +# define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4" +# define NID_pbe_WithSHA1And128BitRC4 144 +# define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L + +# define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40" +# define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4" +# define NID_pbe_WithSHA1And40BitRC4 145 +# define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L + +# define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES" +# define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC" +# define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146 +# define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L + +# define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES" +# define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC" +# define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147 +# define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L + +# define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128" +# define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC" +# define NID_pbe_WithSHA1And128BitRC2_CBC 148 +# define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L + +# define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40" +# define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC" +# define NID_pbe_WithSHA1And40BitRC2_CBC 149 +# define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L + +# define OBJ_pkcs12_Version1 OBJ_pkcs12, 10L + +# define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1, 1L + +# define LN_keyBag "keyBag" +# define NID_keyBag 150 +# define OBJ_keyBag OBJ_pkcs12_BagIds, 1L + +# define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag" +# define NID_pkcs8ShroudedKeyBag 151 +# define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds, 2L + +# define LN_certBag "certBag" +# define NID_certBag 152 +# define OBJ_certBag OBJ_pkcs12_BagIds, 3L + +# define LN_crlBag "crlBag" +# define NID_crlBag 153 +# define OBJ_crlBag OBJ_pkcs12_BagIds, 4L + +# define LN_secretBag "secretBag" +# define NID_secretBag 154 +# define OBJ_secretBag OBJ_pkcs12_BagIds, 5L + +# define LN_safeContentsBag "safeContentsBag" +# define NID_safeContentsBag 155 +# define OBJ_safeContentsBag OBJ_pkcs12_BagIds, 6L + +# define LN_friendlyName "friendlyName" +# define NID_friendlyName 156 +# define OBJ_friendlyName OBJ_pkcs9, 20L + +# define LN_localKeyID "localKeyID" +# define NID_localKeyID 157 +# define OBJ_localKeyID OBJ_pkcs9, 21L + +# define OBJ_certTypes OBJ_pkcs9, 22L + +# define LN_x509Certificate "x509Certificate" +# define NID_x509Certificate 158 +# define OBJ_x509Certificate OBJ_certTypes, 1L + +# define LN_sdsiCertificate "sdsiCertificate" +# define NID_sdsiCertificate 159 +# define OBJ_sdsiCertificate OBJ_certTypes, 2L + +# define OBJ_crlTypes OBJ_pkcs9, 23L + +# define LN_x509Crl "x509Crl" +# define NID_x509Crl 160 +# define OBJ_x509Crl OBJ_crlTypes, 1L + +/* PKCS#5 v2 OIDs */ + +# define LN_pbes2 "PBES2" +# define NID_pbes2 161 +# define OBJ_pbes2 OBJ_pkcs,5L,13L + +# define LN_pbmac1 "PBMAC1" +# define NID_pbmac1 162 +# define OBJ_pbmac1 OBJ_pkcs,5L,14L + +# define LN_hmacWithSHA1 "hmacWithSHA1" +# define NID_hmacWithSHA1 163 +# define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L + +/* Policy Qualifier Ids */ + +# define LN_id_qt_cps "Policy Qualifier CPS" +# define SN_id_qt_cps "id-qt-cps" +# define NID_id_qt_cps 164 +# define OBJ_id_qt_cps OBJ_id_pkix,2L,1L + +# define LN_id_qt_unotice "Policy Qualifier User Notice" +# define SN_id_qt_unotice "id-qt-unotice" +# define NID_id_qt_unotice 165 +# define OBJ_id_qt_unotice OBJ_id_pkix,2L,2L + +# define SN_rc2_64_cbc "RC2-64-CBC" +# define LN_rc2_64_cbc "rc2-64-cbc" +# define NID_rc2_64_cbc 166 + +# define SN_SMIMECapabilities "SMIME-CAPS" +# define LN_SMIMECapabilities "S/MIME Capabilities" +# define NID_SMIMECapabilities 167 +# define OBJ_SMIMECapabilities OBJ_pkcs9,15L + +# define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64" +# define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC" +# define NID_pbeWithMD2AndRC2_CBC 168 +# define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L + +# define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64" +# define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC" +# define NID_pbeWithMD5AndRC2_CBC 169 +# define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L + +# define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES" +# define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC" +# define NID_pbeWithSHA1AndDES_CBC 170 +# define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L + +/* Extension request OIDs */ + +# define LN_ms_ext_req "Microsoft Extension Request" +# define SN_ms_ext_req "msExtReq" +# define NID_ms_ext_req 171 +# define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L + +# define LN_ext_req "Extension Request" +# define SN_ext_req "extReq" +# define NID_ext_req 172 +# define OBJ_ext_req OBJ_pkcs9,14L + +# define SN_name "name" +# define LN_name "name" +# define NID_name 173 +# define OBJ_name OBJ_X509,41L + +# define SN_dnQualifier "dnQualifier" +# define LN_dnQualifier "dnQualifier" +# define NID_dnQualifier 174 +# define OBJ_dnQualifier OBJ_X509,46L + +# define SN_id_pe "id-pe" +# define NID_id_pe 175 +# define OBJ_id_pe OBJ_id_pkix,1L + +# define SN_id_ad "id-ad" +# define NID_id_ad 176 +# define OBJ_id_ad OBJ_id_pkix,48L + +# define SN_info_access "authorityInfoAccess" +# define LN_info_access "Authority Information Access" +# define NID_info_access 177 +# define OBJ_info_access OBJ_id_pe,1L + +# define SN_ad_OCSP "OCSP" +# define LN_ad_OCSP "OCSP" +# define NID_ad_OCSP 178 +# define OBJ_ad_OCSP OBJ_id_ad,1L + +# define SN_ad_ca_issuers "caIssuers" +# define LN_ad_ca_issuers "CA Issuers" +# define NID_ad_ca_issuers 179 +# define OBJ_ad_ca_issuers OBJ_id_ad,2L + +# define SN_OCSP_sign "OCSPSigning" +# define LN_OCSP_sign "OCSP Signing" +# define NID_OCSP_sign 180 +# define OBJ_OCSP_sign OBJ_id_kp,9L +# endif /* USE_OBJ_MAC */ + +# include <openssl/bio.h> +# include <openssl/asn1.h> + +# define OBJ_NAME_TYPE_UNDEF 0x00 +# define OBJ_NAME_TYPE_MD_METH 0x01 +# define OBJ_NAME_TYPE_CIPHER_METH 0x02 +# define OBJ_NAME_TYPE_PKEY_METH 0x03 +# define OBJ_NAME_TYPE_COMP_METH 0x04 +# define OBJ_NAME_TYPE_NUM 0x05 + +# define OBJ_NAME_ALIAS 0x8000 + +# define OBJ_BSEARCH_VALUE_ON_NOMATCH 0x01 +# define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH 0x02 + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct obj_name_st { + int type; + int alias; + const char *name; + const char *data; +} OBJ_NAME; + +# define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) + +int OBJ_NAME_init(void); +int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), + int (*cmp_func) (const char *, const char *), + void (*free_func) (const char *, int, const char *)); +const char *OBJ_NAME_get(const char *name, int type); +int OBJ_NAME_add(const char *name, int type, const char *data); +int OBJ_NAME_remove(const char *name, int type); +void OBJ_NAME_cleanup(int type); /* -1 for everything */ +void OBJ_NAME_do_all(int type, void (*fn) (const OBJ_NAME *, void *arg), + void *arg); +void OBJ_NAME_do_all_sorted(int type, + void (*fn) (const OBJ_NAME *, void *arg), + void *arg); + +ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o); +ASN1_OBJECT *OBJ_nid2obj(int n); +const char *OBJ_nid2ln(int n); +const char *OBJ_nid2sn(int n); +int OBJ_obj2nid(const ASN1_OBJECT *o); +ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name); +int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name); +int OBJ_txt2nid(const char *s); +int OBJ_ln2nid(const char *s); +int OBJ_sn2nid(const char *s); +int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b); +const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, + int (*cmp) (const void *, const void *)); +const void *OBJ_bsearch_ex_(const void *key, const void *base, int num, + int size, + int (*cmp) (const void *, const void *), + int flags); + +# define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \ + static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \ + static int nm##_cmp(type1 const *, type2 const *); \ + scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) + +# define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \ + _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp) +# define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ + type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) + +/*- + * Unsolved problem: if a type is actually a pointer type, like + * nid_triple is, then its impossible to get a const where you need + * it. Consider: + * + * typedef int nid_triple[3]; + * const void *a_; + * const nid_triple const *a = a_; + * + * The assignement discards a const because what you really want is: + * + * const int const * const *a = a_; + * + * But if you do that, you lose the fact that a is an array of 3 ints, + * which breaks comparison functions. + * + * Thus we end up having to cast, sadly, or unpack the + * declarations. Or, as I finally did in this case, delcare nid_triple + * to be a struct, which it should have been in the first place. + * + * Ben, August 2008. + * + * Also, strictly speaking not all types need be const, but handling + * the non-constness means a lot of complication, and in practice + * comparison routines do always not touch their arguments. + */ + +# define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm) \ + static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ + { \ + type1 const *a = a_; \ + type2 const *b = b_; \ + return nm##_cmp(a,b); \ + } \ + static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ + { \ + return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ + nm##_cmp_BSEARCH_CMP_FN); \ + } \ + extern void dummy_prototype(void) + +# define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ + static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ + { \ + type1 const *a = a_; \ + type2 const *b = b_; \ + return nm##_cmp(a,b); \ + } \ + type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ + { \ + return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ + nm##_cmp_BSEARCH_CMP_FN); \ + } \ + extern void dummy_prototype(void) + +# define OBJ_bsearch(type1,key,type2,base,num,cmp) \ + ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ + num,sizeof(type2), \ + ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ + (void)CHECKED_PTR_OF(type2,cmp##_type_2), \ + cmp##_BSEARCH_CMP_FN))) + +# define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags) \ + ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ + num,sizeof(type2), \ + ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ + (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \ + cmp##_BSEARCH_CMP_FN)),flags) + +int OBJ_new_nid(int num); +int OBJ_add_object(const ASN1_OBJECT *obj); +int OBJ_create(const char *oid, const char *sn, const char *ln); +#if OPENSSL_API_COMPAT < 0x10100000L +# define OBJ_cleanup() while(0) continue +#endif +int OBJ_create_objects(BIO *in); + +size_t OBJ_length(const ASN1_OBJECT *obj); +const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj); + +int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid); +int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid); +int OBJ_add_sigid(int signid, int dig_id, int pkey_id); +void OBJ_sigid_free(void); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_OBJ_strings(void); + +/* Error codes for the OBJ functions. */ + +/* Function codes. */ +# define OBJ_F_OBJ_ADD_OBJECT 105 +# define OBJ_F_OBJ_CREATE 100 +# define OBJ_F_OBJ_DUP 101 +# define OBJ_F_OBJ_NAME_NEW_INDEX 106 +# define OBJ_F_OBJ_NID2LN 102 +# define OBJ_F_OBJ_NID2OBJ 103 +# define OBJ_F_OBJ_NID2SN 104 + +/* Reason codes. */ +# define OBJ_R_OID_EXISTS 102 +# define OBJ_R_UNKNOWN_NID 101 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/ocsp.h b/android/x86/include/openssl/ocsp.h new file mode 100644 index 00000000..08debc5b --- /dev/null +++ b/android/x86/include/openssl/ocsp.h @@ -0,0 +1,412 @@ +/* + * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OCSP_H +# define HEADER_OCSP_H + +#include <openssl/opensslconf.h> + +/* + * These definitions are outside the OPENSSL_NO_OCSP guard because although for + * historical reasons they have OCSP_* names, they can actually be used + * independently of OCSP. E.g. see RFC5280 + */ +/*- + * CRLReason ::= ENUMERATED { + * unspecified (0), + * keyCompromise (1), + * cACompromise (2), + * affiliationChanged (3), + * superseded (4), + * cessationOfOperation (5), + * certificateHold (6), + * removeFromCRL (8) } + */ +# define OCSP_REVOKED_STATUS_NOSTATUS -1 +# define OCSP_REVOKED_STATUS_UNSPECIFIED 0 +# define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1 +# define OCSP_REVOKED_STATUS_CACOMPROMISE 2 +# define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3 +# define OCSP_REVOKED_STATUS_SUPERSEDED 4 +# define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5 +# define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6 +# define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8 + + +# ifndef OPENSSL_NO_OCSP + +# include <openssl/ossl_typ.h> +# include <openssl/x509.h> +# include <openssl/x509v3.h> +# include <openssl/safestack.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Various flags and values */ + +# define OCSP_DEFAULT_NONCE_LENGTH 16 + +# define OCSP_NOCERTS 0x1 +# define OCSP_NOINTERN 0x2 +# define OCSP_NOSIGS 0x4 +# define OCSP_NOCHAIN 0x8 +# define OCSP_NOVERIFY 0x10 +# define OCSP_NOEXPLICIT 0x20 +# define OCSP_NOCASIGN 0x40 +# define OCSP_NODELEGATED 0x80 +# define OCSP_NOCHECKS 0x100 +# define OCSP_TRUSTOTHER 0x200 +# define OCSP_RESPID_KEY 0x400 +# define OCSP_NOTIME 0x800 + +typedef struct ocsp_cert_id_st OCSP_CERTID; + +DEFINE_STACK_OF(OCSP_CERTID) + +typedef struct ocsp_one_request_st OCSP_ONEREQ; + +DEFINE_STACK_OF(OCSP_ONEREQ) + +typedef struct ocsp_req_info_st OCSP_REQINFO; +typedef struct ocsp_signature_st OCSP_SIGNATURE; +typedef struct ocsp_request_st OCSP_REQUEST; + +# define OCSP_RESPONSE_STATUS_SUCCESSFUL 0 +# define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1 +# define OCSP_RESPONSE_STATUS_INTERNALERROR 2 +# define OCSP_RESPONSE_STATUS_TRYLATER 3 +# define OCSP_RESPONSE_STATUS_SIGREQUIRED 5 +# define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6 + +typedef struct ocsp_resp_bytes_st OCSP_RESPBYTES; + +# define V_OCSP_RESPID_NAME 0 +# define V_OCSP_RESPID_KEY 1 + +DEFINE_STACK_OF(OCSP_RESPID) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPID) + +typedef struct ocsp_revoked_info_st OCSP_REVOKEDINFO; + +# define V_OCSP_CERTSTATUS_GOOD 0 +# define V_OCSP_CERTSTATUS_REVOKED 1 +# define V_OCSP_CERTSTATUS_UNKNOWN 2 + +typedef struct ocsp_cert_status_st OCSP_CERTSTATUS; +typedef struct ocsp_single_response_st OCSP_SINGLERESP; + +DEFINE_STACK_OF(OCSP_SINGLERESP) + +typedef struct ocsp_response_data_st OCSP_RESPDATA; + +typedef struct ocsp_basic_response_st OCSP_BASICRESP; + +typedef struct ocsp_crl_id_st OCSP_CRLID; +typedef struct ocsp_service_locator_st OCSP_SERVICELOC; + +# define PEM_STRING_OCSP_REQUEST "OCSP REQUEST" +# define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE" + +# define d2i_OCSP_REQUEST_bio(bp,p) ASN1_d2i_bio_of(OCSP_REQUEST,OCSP_REQUEST_new,d2i_OCSP_REQUEST,bp,p) + +# define d2i_OCSP_RESPONSE_bio(bp,p) ASN1_d2i_bio_of(OCSP_RESPONSE,OCSP_RESPONSE_new,d2i_OCSP_RESPONSE,bp,p) + +# define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL) + +# define PEM_read_bio_OCSP_RESPONSE(bp,x,cb)(OCSP_RESPONSE *)PEM_ASN1_read_bio(\ + (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,bp,(char **)x,cb,NULL) + +# define PEM_write_bio_OCSP_REQUEST(bp,o) \ + PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\ + bp,(char *)o, NULL,NULL,0,NULL,NULL) + +# define PEM_write_bio_OCSP_RESPONSE(bp,o) \ + PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\ + bp,(char *)o, NULL,NULL,0,NULL,NULL) + +# define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio_of(OCSP_RESPONSE,i2d_OCSP_RESPONSE,bp,o) + +# define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio_of(OCSP_REQUEST,i2d_OCSP_REQUEST,bp,o) + +# define OCSP_REQUEST_sign(o,pkey,md) \ + ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO),\ + &o->optionalSignature->signatureAlgorithm,NULL,\ + o->optionalSignature->signature,&o->tbsRequest,pkey,md) + +# define OCSP_BASICRESP_sign(o,pkey,md,d) \ + ASN1_item_sign(ASN1_ITEM_rptr(OCSP_RESPDATA),&o->signatureAlgorithm,NULL,\ + o->signature,&o->tbsResponseData,pkey,md) + +# define OCSP_REQUEST_verify(a,r) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_REQINFO),\ + &a->optionalSignature->signatureAlgorithm,\ + a->optionalSignature->signature,&a->tbsRequest,r) + +# define OCSP_BASICRESP_verify(a,r,d) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_RESPDATA),\ + &a->signatureAlgorithm,a->signature,&a->tbsResponseData,r) + +# define ASN1_BIT_STRING_digest(data,type,md,len) \ + ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len) + +# define OCSP_CERTSTATUS_dup(cs)\ + (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\ + (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs)) + +OCSP_CERTID *OCSP_CERTID_dup(OCSP_CERTID *id); + +OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req); +OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, OCSP_REQUEST *req, + int maxline); +int OCSP_REQ_CTX_nbio(OCSP_REQ_CTX *rctx); +int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx); +OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline); +void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx); +void OCSP_set_max_response_length(OCSP_REQ_CTX *rctx, unsigned long len); +int OCSP_REQ_CTX_i2d(OCSP_REQ_CTX *rctx, const ASN1_ITEM *it, + ASN1_VALUE *val); +int OCSP_REQ_CTX_nbio_d2i(OCSP_REQ_CTX *rctx, ASN1_VALUE **pval, + const ASN1_ITEM *it); +BIO *OCSP_REQ_CTX_get0_mem_bio(OCSP_REQ_CTX *rctx); +int OCSP_REQ_CTX_i2d(OCSP_REQ_CTX *rctx, const ASN1_ITEM *it, + ASN1_VALUE *val); +int OCSP_REQ_CTX_http(OCSP_REQ_CTX *rctx, const char *op, const char *path); +int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, OCSP_REQUEST *req); +int OCSP_REQ_CTX_add1_header(OCSP_REQ_CTX *rctx, + const char *name, const char *value); + +OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, const X509 *subject, + const X509 *issuer); + +OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, + const X509_NAME *issuerName, + const ASN1_BIT_STRING *issuerKey, + const ASN1_INTEGER *serialNumber); + +OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid); + +int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len); +int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len); +int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs); +int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req); + +int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm); +int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert); + +int OCSP_request_sign(OCSP_REQUEST *req, + X509 *signer, + EVP_PKEY *key, + const EVP_MD *dgst, + STACK_OF(X509) *certs, unsigned long flags); + +int OCSP_response_status(OCSP_RESPONSE *resp); +OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp); + +const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *bs); + +int OCSP_resp_count(OCSP_BASICRESP *bs); +OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx); +const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(const OCSP_BASICRESP* bs); +const STACK_OF(X509) *OCSP_resp_get0_certs(const OCSP_BASICRESP *bs); +int OCSP_resp_get0_id(const OCSP_BASICRESP *bs, + const ASN1_OCTET_STRING **pid, + const X509_NAME **pname); + +int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last); +int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason, + ASN1_GENERALIZEDTIME **revtime, + ASN1_GENERALIZEDTIME **thisupd, + ASN1_GENERALIZEDTIME **nextupd); +int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status, + int *reason, + ASN1_GENERALIZEDTIME **revtime, + ASN1_GENERALIZEDTIME **thisupd, + ASN1_GENERALIZEDTIME **nextupd); +int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, + ASN1_GENERALIZEDTIME *nextupd, long sec, long maxsec); + +int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, + X509_STORE *store, unsigned long flags); + +int OCSP_parse_url(const char *url, char **phost, char **pport, char **ppath, + int *pssl); + +int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b); +int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b); + +int OCSP_request_onereq_count(OCSP_REQUEST *req); +OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i); +OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one); +int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd, + ASN1_OCTET_STRING **pikeyHash, + ASN1_INTEGER **pserial, OCSP_CERTID *cid); +int OCSP_request_is_signed(OCSP_REQUEST *req); +OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs); +OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp, + OCSP_CERTID *cid, + int status, int reason, + ASN1_TIME *revtime, + ASN1_TIME *thisupd, + ASN1_TIME *nextupd); +int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert); +int OCSP_basic_sign(OCSP_BASICRESP *brsp, + X509 *signer, EVP_PKEY *key, const EVP_MD *dgst, + STACK_OF(X509) *certs, unsigned long flags); +int OCSP_RESPID_set_by_name(OCSP_RESPID *respid, X509 *cert); +int OCSP_RESPID_set_by_key(OCSP_RESPID *respid, X509 *cert); +int OCSP_RESPID_match(OCSP_RESPID *respid, X509 *cert); + +X509_EXTENSION *OCSP_crlID_new(const char *url, long *n, char *tim); + +X509_EXTENSION *OCSP_accept_responses_new(char **oids); + +X509_EXTENSION *OCSP_archive_cutoff_new(char *tim); + +X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME *issuer, const char **urls); + +int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x); +int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos); +int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, const ASN1_OBJECT *obj, + int lastpos); +int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos); +X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc); +X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc); +void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, + int *idx); +int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit, + unsigned long flags); +int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc); + +int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x); +int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos); +int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, const ASN1_OBJECT *obj, int lastpos); +int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos); +X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc); +X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc); +void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx); +int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit, + unsigned long flags); +int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc); + +int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x); +int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos); +int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, const ASN1_OBJECT *obj, + int lastpos); +int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, + int lastpos); +X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc); +X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc); +void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, + int *idx); +int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, + int crit, unsigned long flags); +int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc); + +int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x); +int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos); +int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, const ASN1_OBJECT *obj, + int lastpos); +int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, + int lastpos); +X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc); +X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc); +void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, + int *idx); +int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, + int crit, unsigned long flags); +int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc); +const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *x); + +DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP) +DECLARE_ASN1_FUNCTIONS(OCSP_CERTSTATUS) +DECLARE_ASN1_FUNCTIONS(OCSP_REVOKEDINFO) +DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPDATA) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPID) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPBYTES) +DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ) +DECLARE_ASN1_FUNCTIONS(OCSP_CERTID) +DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST) +DECLARE_ASN1_FUNCTIONS(OCSP_SIGNATURE) +DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO) +DECLARE_ASN1_FUNCTIONS(OCSP_CRLID) +DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC) + +const char *OCSP_response_status_str(long s); +const char *OCSP_cert_status_str(long s); +const char *OCSP_crl_reason_str(long s); + +int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST *a, unsigned long flags); +int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE *o, unsigned long flags); + +int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, + X509_STORE *st, unsigned long flags); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_OCSP_strings(void); + +/* Error codes for the OCSP functions. */ + +/* Function codes. */ +# define OCSP_F_D2I_OCSP_NONCE 102 +# define OCSP_F_OCSP_BASIC_ADD1_STATUS 103 +# define OCSP_F_OCSP_BASIC_SIGN 104 +# define OCSP_F_OCSP_BASIC_VERIFY 105 +# define OCSP_F_OCSP_CERT_ID_NEW 101 +# define OCSP_F_OCSP_CHECK_DELEGATED 106 +# define OCSP_F_OCSP_CHECK_IDS 107 +# define OCSP_F_OCSP_CHECK_ISSUER 108 +# define OCSP_F_OCSP_CHECK_VALIDITY 115 +# define OCSP_F_OCSP_MATCH_ISSUERID 109 +# define OCSP_F_OCSP_PARSE_URL 114 +# define OCSP_F_OCSP_REQUEST_SIGN 110 +# define OCSP_F_OCSP_REQUEST_VERIFY 116 +# define OCSP_F_OCSP_RESPONSE_GET1_BASIC 111 +# define OCSP_F_PARSE_HTTP_LINE1 118 + +/* Reason codes. */ +# define OCSP_R_CERTIFICATE_VERIFY_ERROR 101 +# define OCSP_R_DIGEST_ERR 102 +# define OCSP_R_ERROR_IN_NEXTUPDATE_FIELD 122 +# define OCSP_R_ERROR_IN_THISUPDATE_FIELD 123 +# define OCSP_R_ERROR_PARSING_URL 121 +# define OCSP_R_MISSING_OCSPSIGNING_USAGE 103 +# define OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE 124 +# define OCSP_R_NOT_BASIC_RESPONSE 104 +# define OCSP_R_NO_CERTIFICATES_IN_CHAIN 105 +# define OCSP_R_NO_RESPONSE_DATA 108 +# define OCSP_R_NO_REVOKED_TIME 109 +# define OCSP_R_NO_SIGNER_KEY 130 +# define OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 110 +# define OCSP_R_REQUEST_NOT_SIGNED 128 +# define OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA 111 +# define OCSP_R_ROOT_CA_NOT_TRUSTED 112 +# define OCSP_R_SERVER_RESPONSE_ERROR 114 +# define OCSP_R_SERVER_RESPONSE_PARSE_ERROR 115 +# define OCSP_R_SIGNATURE_FAILURE 117 +# define OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND 118 +# define OCSP_R_STATUS_EXPIRED 125 +# define OCSP_R_STATUS_NOT_YET_VALID 126 +# define OCSP_R_STATUS_TOO_OLD 127 +# define OCSP_R_UNKNOWN_MESSAGE_DIGEST 119 +# define OCSP_R_UNKNOWN_NID 120 +# define OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE 129 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/opensslconf-arm32.h b/android/x86/include/openssl/opensslconf-arm32.h new file mode 100644 index 00000000..527f4d5b --- /dev/null +++ b/android/x86/include/openssl/opensslconf-arm32.h @@ -0,0 +1,169 @@ +/* + * WARNING: do not edit! + * Generated by Makefile from include/openssl/opensslconf.h.in + * + * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_ALGORITHM_DEFINES +# error OPENSSL_ALGORITHM_DEFINES no longer supported +#endif + +/* + * OpenSSL was configured with the following options: + */ + +#ifndef OPENSSL_NO_MD2 +# define OPENSSL_NO_MD2 +#endif +#ifndef OPENSSL_NO_RC5 +# define OPENSSL_NO_RC5 +#endif +#ifndef OPENSSL_THREADS +# define OPENSSL_THREADS +#endif +#ifndef OPENSSL_NO_ASAN +# define OPENSSL_NO_ASAN +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG +# define OPENSSL_NO_CRYPTO_MDEBUG +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +# define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +#endif +#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 +# define OPENSSL_NO_EC_NISTP_64_GCC_128 +#endif +#ifndef OPENSSL_NO_EGD +# define OPENSSL_NO_EGD +#endif +#ifndef OPENSSL_NO_FUZZ_AFL +# define OPENSSL_NO_FUZZ_AFL +#endif +#ifndef OPENSSL_NO_FUZZ_LIBFUZZER +# define OPENSSL_NO_FUZZ_LIBFUZZER +#endif +#ifndef OPENSSL_NO_HEARTBEATS +# define OPENSSL_NO_HEARTBEATS +#endif +#ifndef OPENSSL_NO_MSAN +# define OPENSSL_NO_MSAN +#endif +#ifndef OPENSSL_NO_SCTP +# define OPENSSL_NO_SCTP +#endif +#ifndef OPENSSL_NO_SSL_TRACE +# define OPENSSL_NO_SSL_TRACE +#endif +#ifndef OPENSSL_NO_SSL3 +# define OPENSSL_NO_SSL3 +#endif +#ifndef OPENSSL_NO_SSL3_METHOD +# define OPENSSL_NO_SSL3_METHOD +#endif +#ifndef OPENSSL_NO_UBSAN +# define OPENSSL_NO_UBSAN +#endif +#ifndef OPENSSL_NO_UNIT_TEST +# define OPENSSL_NO_UNIT_TEST +#endif +#ifndef OPENSSL_NO_WEAK_SSL_CIPHERS +# define OPENSSL_NO_WEAK_SSL_CIPHERS +#endif +#ifndef OPENSSL_NO_AFALGENG +# define OPENSSL_NO_AFALGENG +#endif + + +/* + * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers + * don't like that. This will hopefully silence them. + */ +#define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy; + +/* + * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the + * declarations of functions deprecated in or before <version>. Otherwise, they + * still won't see them if the library has been built to disable deprecated + * functions. + */ +#if defined(OPENSSL_NO_DEPRECATED) +# define DECLARE_DEPRECATED(f) +#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) +# define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated)); +#else +# define DECLARE_DEPRECATED(f) f; +#endif + +#ifndef OPENSSL_FILE +# ifdef OPENSSL_NO_FILENAMES +# define OPENSSL_FILE "" +# define OPENSSL_LINE 0 +# else +# define OPENSSL_FILE __FILE__ +# define OPENSSL_LINE __LINE__ +# endif +#endif + +#ifndef OPENSSL_MIN_API +# define OPENSSL_MIN_API 0 +#endif + +#if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < OPENSSL_MIN_API +# undef OPENSSL_API_COMPAT +# define OPENSSL_API_COMPAT OPENSSL_MIN_API +#endif + +#if OPENSSL_API_COMPAT < 0x10100000L +# define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_1_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x10000000L +# define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_0_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x00908000L +# define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_0_9_8(f) +#endif + +#define OPENSSL_CPUID_OBJ + +/* Generate 80386 code? */ +#undef I386_ONLY + +#undef OPENSSL_UNISTD +#define OPENSSL_UNISTD <unistd.h> + +#undef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* + * The following are cipher-specific, but are part of the public API. + */ +#if !defined(OPENSSL_SYS_UEFI) +# define BN_LLONG +/* Only one for the following should be defined */ +# undef SIXTY_FOUR_BIT_LONG +# undef SIXTY_FOUR_BIT +# define THIRTY_TWO_BIT +#endif + +#define RC4_INT unsigned char + +#ifdef __cplusplus +} +#endif diff --git a/android/x86/include/openssl/opensslconf-arm64.h b/android/x86/include/openssl/opensslconf-arm64.h new file mode 100644 index 00000000..f3d83b5c --- /dev/null +++ b/android/x86/include/openssl/opensslconf-arm64.h @@ -0,0 +1,169 @@ +/* + * WARNING: do not edit! + * Generated by Makefile from include/openssl/opensslconf.h.in + * + * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_ALGORITHM_DEFINES +# error OPENSSL_ALGORITHM_DEFINES no longer supported +#endif + +/* + * OpenSSL was configured with the following options: + */ + +#ifndef OPENSSL_NO_MD2 +# define OPENSSL_NO_MD2 +#endif +#ifndef OPENSSL_NO_RC5 +# define OPENSSL_NO_RC5 +#endif +#ifndef OPENSSL_THREADS +# define OPENSSL_THREADS +#endif +#ifndef OPENSSL_NO_ASAN +# define OPENSSL_NO_ASAN +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG +# define OPENSSL_NO_CRYPTO_MDEBUG +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +# define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +#endif +#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 +# define OPENSSL_NO_EC_NISTP_64_GCC_128 +#endif +#ifndef OPENSSL_NO_EGD +# define OPENSSL_NO_EGD +#endif +#ifndef OPENSSL_NO_FUZZ_AFL +# define OPENSSL_NO_FUZZ_AFL +#endif +#ifndef OPENSSL_NO_FUZZ_LIBFUZZER +# define OPENSSL_NO_FUZZ_LIBFUZZER +#endif +#ifndef OPENSSL_NO_HEARTBEATS +# define OPENSSL_NO_HEARTBEATS +#endif +#ifndef OPENSSL_NO_MSAN +# define OPENSSL_NO_MSAN +#endif +#ifndef OPENSSL_NO_SCTP +# define OPENSSL_NO_SCTP +#endif +#ifndef OPENSSL_NO_SSL_TRACE +# define OPENSSL_NO_SSL_TRACE +#endif +#ifndef OPENSSL_NO_SSL3 +# define OPENSSL_NO_SSL3 +#endif +#ifndef OPENSSL_NO_SSL3_METHOD +# define OPENSSL_NO_SSL3_METHOD +#endif +#ifndef OPENSSL_NO_UBSAN +# define OPENSSL_NO_UBSAN +#endif +#ifndef OPENSSL_NO_UNIT_TEST +# define OPENSSL_NO_UNIT_TEST +#endif +#ifndef OPENSSL_NO_WEAK_SSL_CIPHERS +# define OPENSSL_NO_WEAK_SSL_CIPHERS +#endif +#ifndef OPENSSL_NO_AFALGENG +# define OPENSSL_NO_AFALGENG +#endif + + +/* + * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers + * don't like that. This will hopefully silence them. + */ +#define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy; + +/* + * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the + * declarations of functions deprecated in or before <version>. Otherwise, they + * still won't see them if the library has been built to disable deprecated + * functions. + */ +#if defined(OPENSSL_NO_DEPRECATED) +# define DECLARE_DEPRECATED(f) +#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) +# define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated)); +#else +# define DECLARE_DEPRECATED(f) f; +#endif + +#ifndef OPENSSL_FILE +# ifdef OPENSSL_NO_FILENAMES +# define OPENSSL_FILE "" +# define OPENSSL_LINE 0 +# else +# define OPENSSL_FILE __FILE__ +# define OPENSSL_LINE __LINE__ +# endif +#endif + +#ifndef OPENSSL_MIN_API +# define OPENSSL_MIN_API 0 +#endif + +#if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < OPENSSL_MIN_API +# undef OPENSSL_API_COMPAT +# define OPENSSL_API_COMPAT OPENSSL_MIN_API +#endif + +#if OPENSSL_API_COMPAT < 0x10100000L +# define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_1_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x10000000L +# define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_0_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x00908000L +# define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_0_9_8(f) +#endif + +#define OPENSSL_CPUID_OBJ + +/* Generate 80386 code? */ +#undef I386_ONLY + +#undef OPENSSL_UNISTD +#define OPENSSL_UNISTD <unistd.h> + +#undef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* + * The following are cipher-specific, but are part of the public API. + */ +#if !defined(OPENSSL_SYS_UEFI) +# undef BN_LLONG +/* Only one for the following should be defined */ +# define SIXTY_FOUR_BIT_LONG +# undef SIXTY_FOUR_BIT +# undef THIRTY_TWO_BIT +#endif + +#define RC4_INT unsigned char + +#ifdef __cplusplus +} +#endif diff --git a/android/x86/include/openssl/opensslconf-x86.h b/android/x86/include/openssl/opensslconf-x86.h new file mode 100644 index 00000000..9891b5d8 --- /dev/null +++ b/android/x86/include/openssl/opensslconf-x86.h @@ -0,0 +1,169 @@ +/* + * WARNING: do not edit! + * Generated by Makefile from include/openssl/opensslconf.h.in + * + * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_ALGORITHM_DEFINES +# error OPENSSL_ALGORITHM_DEFINES no longer supported +#endif + +/* + * OpenSSL was configured with the following options: + */ + +#ifndef OPENSSL_NO_MD2 +# define OPENSSL_NO_MD2 +#endif +#ifndef OPENSSL_NO_RC5 +# define OPENSSL_NO_RC5 +#endif +#ifndef OPENSSL_THREADS +# define OPENSSL_THREADS +#endif +#ifndef OPENSSL_NO_ASAN +# define OPENSSL_NO_ASAN +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG +# define OPENSSL_NO_CRYPTO_MDEBUG +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +# define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +#endif +#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 +# define OPENSSL_NO_EC_NISTP_64_GCC_128 +#endif +#ifndef OPENSSL_NO_EGD +# define OPENSSL_NO_EGD +#endif +#ifndef OPENSSL_NO_FUZZ_AFL +# define OPENSSL_NO_FUZZ_AFL +#endif +#ifndef OPENSSL_NO_FUZZ_LIBFUZZER +# define OPENSSL_NO_FUZZ_LIBFUZZER +#endif +#ifndef OPENSSL_NO_HEARTBEATS +# define OPENSSL_NO_HEARTBEATS +#endif +#ifndef OPENSSL_NO_MSAN +# define OPENSSL_NO_MSAN +#endif +#ifndef OPENSSL_NO_SCTP +# define OPENSSL_NO_SCTP +#endif +#ifndef OPENSSL_NO_SSL_TRACE +# define OPENSSL_NO_SSL_TRACE +#endif +#ifndef OPENSSL_NO_SSL3 +# define OPENSSL_NO_SSL3 +#endif +#ifndef OPENSSL_NO_SSL3_METHOD +# define OPENSSL_NO_SSL3_METHOD +#endif +#ifndef OPENSSL_NO_UBSAN +# define OPENSSL_NO_UBSAN +#endif +#ifndef OPENSSL_NO_UNIT_TEST +# define OPENSSL_NO_UNIT_TEST +#endif +#ifndef OPENSSL_NO_WEAK_SSL_CIPHERS +# define OPENSSL_NO_WEAK_SSL_CIPHERS +#endif +#ifndef OPENSSL_NO_AFALGENG +# define OPENSSL_NO_AFALGENG +#endif + + +/* + * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers + * don't like that. This will hopefully silence them. + */ +#define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy; + +/* + * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the + * declarations of functions deprecated in or before <version>. Otherwise, they + * still won't see them if the library has been built to disable deprecated + * functions. + */ +#if defined(OPENSSL_NO_DEPRECATED) +# define DECLARE_DEPRECATED(f) +#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) +# define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated)); +#else +# define DECLARE_DEPRECATED(f) f; +#endif + +#ifndef OPENSSL_FILE +# ifdef OPENSSL_NO_FILENAMES +# define OPENSSL_FILE "" +# define OPENSSL_LINE 0 +# else +# define OPENSSL_FILE __FILE__ +# define OPENSSL_LINE __LINE__ +# endif +#endif + +#ifndef OPENSSL_MIN_API +# define OPENSSL_MIN_API 0 +#endif + +#if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < OPENSSL_MIN_API +# undef OPENSSL_API_COMPAT +# define OPENSSL_API_COMPAT OPENSSL_MIN_API +#endif + +#if OPENSSL_API_COMPAT < 0x10100000L +# define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_1_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x10000000L +# define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_0_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x00908000L +# define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_0_9_8(f) +#endif + +#define OPENSSL_CPUID_OBJ + +/* Generate 80386 code? */ +#undef I386_ONLY + +#undef OPENSSL_UNISTD +#define OPENSSL_UNISTD <unistd.h> + +#undef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* + * The following are cipher-specific, but are part of the public API. + */ +#if !defined(OPENSSL_SYS_UEFI) +# define BN_LLONG +/* Only one for the following should be defined */ +# undef SIXTY_FOUR_BIT_LONG +# undef SIXTY_FOUR_BIT +# define THIRTY_TWO_BIT +#endif + +#define RC4_INT unsigned int + +#ifdef __cplusplus +} +#endif diff --git a/android/x86/include/openssl/opensslconf.h b/android/x86/include/openssl/opensslconf.h new file mode 100644 index 00000000..94174f30 --- /dev/null +++ b/android/x86/include/openssl/opensslconf.h @@ -0,0 +1,9 @@ +#ifdef __aarch64__ +#include "opensslconf-arm64.h" +#elif __arm__ +#include "opensslconf-arm32.h" +#elif __i386__ +#include "opensslconf-x86.h" +#else +#error "Unsupported architecture!" +#endif diff --git a/android/x86/include/openssl/opensslv.h b/android/x86/include/openssl/opensslv.h new file mode 100644 index 00000000..2d54b69b --- /dev/null +++ b/android/x86/include/openssl/opensslv.h @@ -0,0 +1,105 @@ +/* + * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OPENSSLV_H +# define HEADER_OPENSSLV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*- + * Numeric release version identifier: + * MNNFFPPS: major minor fix patch status + * The status nibble has one of the values 0 for development, 1 to e for betas + * 1 to 14, and f for release. The patch level is exactly that. + * For example: + * 0.9.3-dev 0x00903000 + * 0.9.3-beta1 0x00903001 + * 0.9.3-beta2-dev 0x00903002 + * 0.9.3-beta2 0x00903002 (same as ...beta2-dev) + * 0.9.3 0x0090300f + * 0.9.3a 0x0090301f + * 0.9.4 0x0090400f + * 1.2.3z 0x102031af + * + * For continuity reasons (because 0.9.5 is already out, and is coded + * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level + * part is slightly different, by setting the highest bit. This means + * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start + * with 0x0090600S... + * + * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.) + * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for + * major minor fix final patch/beta) + */ +# define OPENSSL_VERSION_NUMBER 0x1010003fL +# ifdef OPENSSL_FIPS +# define OPENSSL_VERSION_TEXT "OpenSSL 1.1.0c-fips 10 Nov 2016" +# else +# define OPENSSL_VERSION_TEXT "OpenSSL 1.1.0c 10 Nov 2016" +# endif + +/*- + * The macros below are to be used for shared library (.so, .dll, ...) + * versioning. That kind of versioning works a bit differently between + * operating systems. The most usual scheme is to set a major and a minor + * number, and have the runtime loader check that the major number is equal + * to what it was at application link time, while the minor number has to + * be greater or equal to what it was at application link time. With this + * scheme, the version number is usually part of the file name, like this: + * + * libcrypto.so.0.9 + * + * Some unixen also make a softlink with the major version number only: + * + * libcrypto.so.0 + * + * On Tru64 and IRIX 6.x it works a little bit differently. There, the + * shared library version is stored in the file, and is actually a series + * of versions, separated by colons. The rightmost version present in the + * library when linking an application is stored in the application to be + * matched at run time. When the application is run, a check is done to + * see if the library version stored in the application matches any of the + * versions in the version string of the library itself. + * This version string can be constructed in any way, depending on what + * kind of matching is desired. However, to implement the same scheme as + * the one used in the other unixen, all compatible versions, from lowest + * to highest, should be part of the string. Consecutive builds would + * give the following versions strings: + * + * 3.0 + * 3.0:3.1 + * 3.0:3.1:3.2 + * 4.0 + * 4.0:4.1 + * + * Notice how version 4 is completely incompatible with version, and + * therefore give the breach you can see. + * + * There may be other schemes as well that I haven't yet discovered. + * + * So, here's the way it works here: first of all, the library version + * number doesn't need at all to match the overall OpenSSL version. + * However, it's nice and more understandable if it actually does. + * The current library version is stored in the macro SHLIB_VERSION_NUMBER, + * which is just a piece of text in the format "M.m.e" (Major, minor, edit). + * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways, + * we need to keep a history of version numbers, which is done in the + * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and + * should only keep the versions that are binary compatible with the current. + */ +# define SHLIB_VERSION_HISTORY "" +# define SHLIB_VERSION_NUMBER "1.1" + + +#ifdef __cplusplus +} +#endif +#endif /* HEADER_OPENSSLV_H */ diff --git a/android/x86/include/openssl/ossl_typ.h b/android/x86/include/openssl/ossl_typ.h new file mode 100644 index 00000000..129a67f0 --- /dev/null +++ b/android/x86/include/openssl/ossl_typ.h @@ -0,0 +1,190 @@ +/* + * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OPENSSL_TYPES_H +# define HEADER_OPENSSL_TYPES_H + +#include <limits.h> + +#ifdef __cplusplus +extern "C" { +#endif + +# include <openssl/e_os2.h> + +# ifdef NO_ASN1_TYPEDEFS +# define ASN1_INTEGER ASN1_STRING +# define ASN1_ENUMERATED ASN1_STRING +# define ASN1_BIT_STRING ASN1_STRING +# define ASN1_OCTET_STRING ASN1_STRING +# define ASN1_PRINTABLESTRING ASN1_STRING +# define ASN1_T61STRING ASN1_STRING +# define ASN1_IA5STRING ASN1_STRING +# define ASN1_UTCTIME ASN1_STRING +# define ASN1_GENERALIZEDTIME ASN1_STRING +# define ASN1_TIME ASN1_STRING +# define ASN1_GENERALSTRING ASN1_STRING +# define ASN1_UNIVERSALSTRING ASN1_STRING +# define ASN1_BMPSTRING ASN1_STRING +# define ASN1_VISIBLESTRING ASN1_STRING +# define ASN1_UTF8STRING ASN1_STRING +# define ASN1_BOOLEAN int +# define ASN1_NULL int +# else +typedef struct asn1_string_st ASN1_INTEGER; +typedef struct asn1_string_st ASN1_ENUMERATED; +typedef struct asn1_string_st ASN1_BIT_STRING; +typedef struct asn1_string_st ASN1_OCTET_STRING; +typedef struct asn1_string_st ASN1_PRINTABLESTRING; +typedef struct asn1_string_st ASN1_T61STRING; +typedef struct asn1_string_st ASN1_IA5STRING; +typedef struct asn1_string_st ASN1_GENERALSTRING; +typedef struct asn1_string_st ASN1_UNIVERSALSTRING; +typedef struct asn1_string_st ASN1_BMPSTRING; +typedef struct asn1_string_st ASN1_UTCTIME; +typedef struct asn1_string_st ASN1_TIME; +typedef struct asn1_string_st ASN1_GENERALIZEDTIME; +typedef struct asn1_string_st ASN1_VISIBLESTRING; +typedef struct asn1_string_st ASN1_UTF8STRING; +typedef struct asn1_string_st ASN1_STRING; +typedef int ASN1_BOOLEAN; +typedef int ASN1_NULL; +# endif + +typedef struct asn1_object_st ASN1_OBJECT; + +typedef struct ASN1_ITEM_st ASN1_ITEM; +typedef struct asn1_pctx_st ASN1_PCTX; +typedef struct asn1_sctx_st ASN1_SCTX; + +# ifdef _WIN32 +# undef X509_NAME +# undef X509_EXTENSIONS +# undef PKCS7_ISSUER_AND_SERIAL +# undef PKCS7_SIGNER_INFO +# undef OCSP_REQUEST +# undef OCSP_RESPONSE +# endif + +# ifdef BIGNUM +# undef BIGNUM +# endif +struct dane_st; +typedef struct bio_st BIO; +typedef struct bignum_st BIGNUM; +typedef struct bignum_ctx BN_CTX; +typedef struct bn_blinding_st BN_BLINDING; +typedef struct bn_mont_ctx_st BN_MONT_CTX; +typedef struct bn_recp_ctx_st BN_RECP_CTX; +typedef struct bn_gencb_st BN_GENCB; + +typedef struct buf_mem_st BUF_MEM; + +typedef struct evp_cipher_st EVP_CIPHER; +typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; +typedef struct evp_md_st EVP_MD; +typedef struct evp_md_ctx_st EVP_MD_CTX; +typedef struct evp_pkey_st EVP_PKEY; + +typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD; + +typedef struct evp_pkey_method_st EVP_PKEY_METHOD; +typedef struct evp_pkey_ctx_st EVP_PKEY_CTX; + +typedef struct evp_Encode_Ctx_st EVP_ENCODE_CTX; + +typedef struct hmac_ctx_st HMAC_CTX; + +typedef struct dh_st DH; +typedef struct dh_method DH_METHOD; + +typedef struct dsa_st DSA; +typedef struct dsa_method DSA_METHOD; + +typedef struct rsa_st RSA; +typedef struct rsa_meth_st RSA_METHOD; + +typedef struct ec_key_st EC_KEY; +typedef struct ec_key_method_st EC_KEY_METHOD; + +typedef struct rand_meth_st RAND_METHOD; + +typedef struct ssl_dane_st SSL_DANE; +typedef struct x509_st X509; +typedef struct X509_algor_st X509_ALGOR; +typedef struct X509_crl_st X509_CRL; +typedef struct x509_crl_method_st X509_CRL_METHOD; +typedef struct x509_revoked_st X509_REVOKED; +typedef struct X509_name_st X509_NAME; +typedef struct X509_pubkey_st X509_PUBKEY; +typedef struct x509_store_st X509_STORE; +typedef struct x509_store_ctx_st X509_STORE_CTX; + +typedef struct x509_object_st X509_OBJECT; +typedef struct x509_lookup_st X509_LOOKUP; +typedef struct x509_lookup_method_st X509_LOOKUP_METHOD; +typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM; + +typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO; + +typedef struct v3_ext_ctx X509V3_CTX; +typedef struct conf_st CONF; +typedef struct ossl_init_settings_st OPENSSL_INIT_SETTINGS; + +typedef struct ui_st UI; +typedef struct ui_method_st UI_METHOD; + +typedef struct engine_st ENGINE; +typedef struct ssl_st SSL; +typedef struct ssl_ctx_st SSL_CTX; + +typedef struct comp_ctx_st COMP_CTX; +typedef struct comp_method_st COMP_METHOD; + +typedef struct X509_POLICY_NODE_st X509_POLICY_NODE; +typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL; +typedef struct X509_POLICY_TREE_st X509_POLICY_TREE; +typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE; + +typedef struct AUTHORITY_KEYID_st AUTHORITY_KEYID; +typedef struct DIST_POINT_st DIST_POINT; +typedef struct ISSUING_DIST_POINT_st ISSUING_DIST_POINT; +typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS; + +typedef struct crypto_ex_data_st CRYPTO_EX_DATA; + +typedef struct ocsp_req_ctx_st OCSP_REQ_CTX; +typedef struct ocsp_response_st OCSP_RESPONSE; +typedef struct ocsp_responder_id_st OCSP_RESPID; + +typedef struct sct_st SCT; +typedef struct sct_ctx_st SCT_CTX; +typedef struct ctlog_st CTLOG; +typedef struct ctlog_store_st CTLOG_STORE; +typedef struct ct_policy_eval_ctx_st CT_POLICY_EVAL_CTX; + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \ + defined(INTMAX_MAX) && defined(UINTMAX_MAX) +typedef intmax_t ossl_intmax_t; +typedef uintmax_t ossl_uintmax_t; +#else +/* + * Not long long, because the C-library can only be expected to provide + * strtoll(), strtoull() at the same time as intmax_t and strtoimax(), + * strtoumax(). Since we use these for parsing arguments, we need the + * conversion functions, not just the sizes. + */ +typedef long ossl_intmax_t; +typedef unsigned long ossl_uintmax_t; +#endif + +#ifdef __cplusplus +} +#endif +#endif /* def HEADER_OPENSSL_TYPES_H */ diff --git a/android/x86/include/openssl/pem.h b/android/x86/include/openssl/pem.h new file mode 100644 index 00000000..2375d635 --- /dev/null +++ b/android/x86/include/openssl/pem.h @@ -0,0 +1,501 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PEM_H +# define HEADER_PEM_H + +# include <openssl/e_os2.h> +# include <openssl/bio.h> +# include <openssl/stack.h> +# include <openssl/evp.h> +# include <openssl/x509.h> +# include <openssl/pem2.h> + +#ifdef __cplusplus +extern "C" { +#endif + +# define PEM_BUFSIZE 1024 + +# define PEM_STRING_X509_OLD "X509 CERTIFICATE" +# define PEM_STRING_X509 "CERTIFICATE" +# define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" +# define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" +# define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" +# define PEM_STRING_X509_CRL "X509 CRL" +# define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" +# define PEM_STRING_PUBLIC "PUBLIC KEY" +# define PEM_STRING_RSA "RSA PRIVATE KEY" +# define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" +# define PEM_STRING_DSA "DSA PRIVATE KEY" +# define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" +# define PEM_STRING_PKCS7 "PKCS7" +# define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA" +# define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" +# define PEM_STRING_PKCS8INF "PRIVATE KEY" +# define PEM_STRING_DHPARAMS "DH PARAMETERS" +# define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS" +# define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" +# define PEM_STRING_DSAPARAMS "DSA PARAMETERS" +# define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" +# define PEM_STRING_ECPARAMETERS "EC PARAMETERS" +# define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" +# define PEM_STRING_PARAMETERS "PARAMETERS" +# define PEM_STRING_CMS "CMS" + +# define PEM_TYPE_ENCRYPTED 10 +# define PEM_TYPE_MIC_ONLY 20 +# define PEM_TYPE_MIC_CLEAR 30 +# define PEM_TYPE_CLEAR 40 + +typedef struct pem_recip_st { + char *name; + X509_NAME *dn; + int cipher; + int key_enc; + /* char iv[8]; unused and wrong size */ +} PEM_USER; + +typedef struct pem_ctx_st { + int type; /* what type of object */ + struct { + int version; + int mode; + } proc_type; + + char *domain; + + struct { + int cipher; + /*- + unused, and wrong size + unsigned char iv[8]; */ + } DEK_info; + + PEM_USER *originator; + + int num_recipient; + PEM_USER **recipient; + +/*- + XXX(ben): don#t think this is used! + STACK *x509_chain; / * certificate chain */ + EVP_MD *md; /* signature type */ + + int md_enc; /* is the md encrypted or not? */ + int md_len; /* length of md_data */ + char *md_data; /* message digest, could be pkey encrypted */ + + EVP_CIPHER *dec; /* date encryption cipher */ + int key_len; /* key length */ + unsigned char *key; /* key */ + /*- + unused, and wrong size + unsigned char iv[8]; */ + + int data_enc; /* is the data encrypted */ + int data_len; + unsigned char *data; +} PEM_CTX; + +/* + * These macros make the PEM_read/PEM_write functions easier to maintain and + * write. Now they are all implemented with either: IMPLEMENT_PEM_rw(...) or + * IMPLEMENT_PEM_rw_cb(...) + */ + +# ifdef OPENSSL_NO_STDIO + +# define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ +# define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ +# define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/ +# define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ +# define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/ +# else + +# define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ +type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ +{ \ +return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \ +} + +# define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x) \ +{ \ +return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \ +} + +# define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, const type *x) \ +{ \ +return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \ +} + +# define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, \ + void *u) \ + { \ + return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ + } + +# define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, \ + void *u) \ + { \ + return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ + } + +# endif + +# define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ +type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ +{ \ +return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \ +} + +# define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x) \ +{ \ +return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \ +} + +# define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, const type *x) \ +{ \ +return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \ +} + +# define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ + { \ + return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \ + } + +# define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ + { \ + return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \ + } + +# define IMPLEMENT_PEM_write(name, type, str, asn1) \ + IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_write_fp(name, type, str, asn1) + +# define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) + +# define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) + +# define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) + +# define IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_read_fp(name, type, str, asn1) + +# define IMPLEMENT_PEM_rw(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write(name, type, str, asn1) + +# define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write_const(name, type, str, asn1) + +# define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb(name, type, str, asn1) + +/* These are the same except they are for the declarations */ + +# if defined(OPENSSL_NO_STDIO) + +# define DECLARE_PEM_read_fp(name, type) /**/ +# define DECLARE_PEM_write_fp(name, type) /**/ +# define DECLARE_PEM_write_fp_const(name, type) /**/ +# define DECLARE_PEM_write_cb_fp(name, type) /**/ +# else + +# define DECLARE_PEM_read_fp(name, type) \ + type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); + +# define DECLARE_PEM_write_fp(name, type) \ + int PEM_write_##name(FILE *fp, type *x); + +# define DECLARE_PEM_write_fp_const(name, type) \ + int PEM_write_##name(FILE *fp, const type *x); + +# define DECLARE_PEM_write_cb_fp(name, type) \ + int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u); + +# endif + +# define DECLARE_PEM_read_bio(name, type) \ + type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); + +# define DECLARE_PEM_write_bio(name, type) \ + int PEM_write_bio_##name(BIO *bp, type *x); + +# define DECLARE_PEM_write_bio_const(name, type) \ + int PEM_write_bio_##name(BIO *bp, const type *x); + +# define DECLARE_PEM_write_cb_bio(name, type) \ + int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u); + +# define DECLARE_PEM_write(name, type) \ + DECLARE_PEM_write_bio(name, type) \ + DECLARE_PEM_write_fp(name, type) +# define DECLARE_PEM_write_const(name, type) \ + DECLARE_PEM_write_bio_const(name, type) \ + DECLARE_PEM_write_fp_const(name, type) +# define DECLARE_PEM_write_cb(name, type) \ + DECLARE_PEM_write_cb_bio(name, type) \ + DECLARE_PEM_write_cb_fp(name, type) +# define DECLARE_PEM_read(name, type) \ + DECLARE_PEM_read_bio(name, type) \ + DECLARE_PEM_read_fp(name, type) +# define DECLARE_PEM_rw(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write(name, type) +# define DECLARE_PEM_rw_const(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write_const(name, type) +# define DECLARE_PEM_rw_cb(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write_cb(name, type) +typedef int pem_password_cb (char *buf, int size, int rwflag, void *userdata); + +int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); +int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *len, + pem_password_cb *callback, void *u); + +int PEM_read_bio(BIO *bp, char **name, char **header, + unsigned char **data, long *len); +int PEM_write_bio(BIO *bp, const char *name, const char *hdr, + const unsigned char *data, long len); +int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, + const char *name, BIO *bp, pem_password_cb *cb, + void *u); +void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, + pem_password_cb *cb, void *u); +int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, + const EVP_CIPHER *enc, unsigned char *kstr, int klen, + pem_password_cb *cb, void *u); + +STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, + pem_password_cb *cb, void *u); +int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, + unsigned char *kstr, int klen, + pem_password_cb *cd, void *u); + +#ifndef OPENSSL_NO_STDIO +int PEM_read(FILE *fp, char **name, char **header, + unsigned char **data, long *len); +int PEM_write(FILE *fp, const char *name, const char *hdr, + const unsigned char *data, long len); +void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, + pem_password_cb *cb, void *u); +int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, + void *x, const EVP_CIPHER *enc, unsigned char *kstr, + int klen, pem_password_cb *callback, void *u); +STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, + pem_password_cb *cb, void *u); +#endif + +int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); +int PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *d, unsigned int cnt); +int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, + unsigned int *siglen, EVP_PKEY *pkey); + +int PEM_def_callback(char *buf, int num, int w, void *key); +void PEM_proc_type(char *buf, int type); +void PEM_dek_info(char *buf, const char *type, int len, char *str); + +# include <openssl/symhacks.h> + +DECLARE_PEM_rw(X509, X509) +DECLARE_PEM_rw(X509_AUX, X509) +DECLARE_PEM_rw(X509_REQ, X509_REQ) +DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) +DECLARE_PEM_rw(X509_CRL, X509_CRL) +DECLARE_PEM_rw(PKCS7, PKCS7) +DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) +DECLARE_PEM_rw(PKCS8, X509_SIG) +DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) +# ifndef OPENSSL_NO_RSA +DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) +DECLARE_PEM_rw_const(RSAPublicKey, RSA) +DECLARE_PEM_rw(RSA_PUBKEY, RSA) +# endif +# ifndef OPENSSL_NO_DSA +DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) +DECLARE_PEM_rw(DSA_PUBKEY, DSA) +DECLARE_PEM_rw_const(DSAparams, DSA) +# endif +# ifndef OPENSSL_NO_EC +DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP) +DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY) +DECLARE_PEM_rw(EC_PUBKEY, EC_KEY) +# endif +# ifndef OPENSSL_NO_DH +DECLARE_PEM_rw_const(DHparams, DH) +DECLARE_PEM_write_const(DHxparams, DH) +# endif +DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) +DECLARE_PEM_rw(PUBKEY, EVP_PKEY) + +int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x, + const EVP_CIPHER *enc, + unsigned char *kstr, int klen, + pem_password_cb *cb, void *u); + +int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, + char *, int, pem_password_cb *, void *); +int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); +EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, + void *u); + +# ifndef OPENSSL_NO_STDIO +int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); + +EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, + void *u); + +int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, pem_password_cb *cd, + void *u); +# endif +EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x); +int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x); + +# ifndef OPENSSL_NO_DSA +EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length); +EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length); +EVP_PKEY *b2i_PrivateKey_bio(BIO *in); +EVP_PKEY *b2i_PublicKey_bio(BIO *in); +int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk); +int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk); +# ifndef OPENSSL_NO_RC4 +EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u); +int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, + pem_password_cb *cb, void *u); +# endif +# endif + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_PEM_strings(void); + +/* Error codes for the PEM functions. */ + +/* Function codes. */ +# define PEM_F_B2I_DSS 127 +# define PEM_F_B2I_PVK_BIO 128 +# define PEM_F_B2I_RSA 129 +# define PEM_F_CHECK_BITLEN_DSA 130 +# define PEM_F_CHECK_BITLEN_RSA 131 +# define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 +# define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 +# define PEM_F_DO_B2I 132 +# define PEM_F_DO_B2I_BIO 133 +# define PEM_F_DO_BLOB_HEADER 134 +# define PEM_F_DO_PK8PKEY 126 +# define PEM_F_DO_PK8PKEY_FP 125 +# define PEM_F_DO_PVK_BODY 135 +# define PEM_F_DO_PVK_HEADER 136 +# define PEM_F_I2B_PVK 137 +# define PEM_F_I2B_PVK_BIO 138 +# define PEM_F_LOAD_IV 101 +# define PEM_F_PEM_ASN1_READ 102 +# define PEM_F_PEM_ASN1_READ_BIO 103 +# define PEM_F_PEM_ASN1_WRITE 104 +# define PEM_F_PEM_ASN1_WRITE_BIO 105 +# define PEM_F_PEM_DEF_CALLBACK 100 +# define PEM_F_PEM_DO_HEADER 106 +# define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 +# define PEM_F_PEM_READ 108 +# define PEM_F_PEM_READ_BIO 109 +# define PEM_F_PEM_READ_BIO_DHPARAMS 141 +# define PEM_F_PEM_READ_BIO_PARAMETERS 140 +# define PEM_F_PEM_READ_BIO_PRIVATEKEY 123 +# define PEM_F_PEM_READ_DHPARAMS 142 +# define PEM_F_PEM_READ_PRIVATEKEY 124 +# define PEM_F_PEM_SIGNFINAL 112 +# define PEM_F_PEM_WRITE 113 +# define PEM_F_PEM_WRITE_BIO 114 +# define PEM_F_PEM_WRITE_PRIVATEKEY 139 +# define PEM_F_PEM_X509_INFO_READ 115 +# define PEM_F_PEM_X509_INFO_READ_BIO 116 +# define PEM_F_PEM_X509_INFO_WRITE_BIO 117 + +/* Reason codes. */ +# define PEM_R_BAD_BASE64_DECODE 100 +# define PEM_R_BAD_DECRYPT 101 +# define PEM_R_BAD_END_LINE 102 +# define PEM_R_BAD_IV_CHARS 103 +# define PEM_R_BAD_MAGIC_NUMBER 116 +# define PEM_R_BAD_PASSWORD_READ 104 +# define PEM_R_BAD_VERSION_NUMBER 117 +# define PEM_R_BIO_WRITE_FAILURE 118 +# define PEM_R_CIPHER_IS_NULL 127 +# define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 +# define PEM_R_EXPECTING_PRIVATE_KEY_BLOB 119 +# define PEM_R_EXPECTING_PUBLIC_KEY_BLOB 120 +# define PEM_R_HEADER_TOO_LONG 128 +# define PEM_R_INCONSISTENT_HEADER 121 +# define PEM_R_KEYBLOB_HEADER_PARSE_ERROR 122 +# define PEM_R_KEYBLOB_TOO_SHORT 123 +# define PEM_R_MISSING_DEK_IV 129 +# define PEM_R_NOT_DEK_INFO 105 +# define PEM_R_NOT_ENCRYPTED 106 +# define PEM_R_NOT_PROC_TYPE 107 +# define PEM_R_NO_START_LINE 108 +# define PEM_R_PROBLEMS_GETTING_PASSWORD 109 +# define PEM_R_PVK_DATA_TOO_SHORT 124 +# define PEM_R_PVK_TOO_SHORT 125 +# define PEM_R_READ_KEY 111 +# define PEM_R_SHORT_HEADER 112 +# define PEM_R_UNEXPECTED_DEK_IV 130 +# define PEM_R_UNSUPPORTED_CIPHER 113 +# define PEM_R_UNSUPPORTED_ENCRYPTION 114 +# define PEM_R_UNSUPPORTED_KEY_COMPONENTS 126 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/pem2.h b/android/x86/include/openssl/pem2.h new file mode 100644 index 00000000..cfe73f13 --- /dev/null +++ b/android/x86/include/openssl/pem2.h @@ -0,0 +1,20 @@ +/* + * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef HEADER_PEM_H +int ERR_load_PEM_strings(void); +#endif + +#ifdef __cplusplus +} +#endif diff --git a/android/x86/include/openssl/pkcs12.h b/android/x86/include/openssl/pkcs12.h new file mode 100644 index 00000000..deaded9d --- /dev/null +++ b/android/x86/include/openssl/pkcs12.h @@ -0,0 +1,282 @@ +/* + * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PKCS12_H +# define HEADER_PKCS12_H + +# include <openssl/bio.h> +# include <openssl/x509.h> + +#ifdef __cplusplus +extern "C" { +#endif + +# define PKCS12_KEY_ID 1 +# define PKCS12_IV_ID 2 +# define PKCS12_MAC_ID 3 + +/* Default iteration count */ +# ifndef PKCS12_DEFAULT_ITER +# define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER +# endif + +# define PKCS12_MAC_KEY_LENGTH 20 + +# define PKCS12_SALT_LEN 8 + +/* It's not clear if these are actually needed... */ +# define PKCS12_key_gen PKCS12_key_gen_utf8 +# define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8 + +/* MS key usage constants */ + +# define KEY_EX 0x10 +# define KEY_SIG 0x80 + +typedef struct PKCS12_MAC_DATA_st PKCS12_MAC_DATA; + +typedef struct PKCS12_st PKCS12; + +typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG; + +DEFINE_STACK_OF(PKCS12_SAFEBAG) + +typedef struct pkcs12_bag_st PKCS12_BAGS; + +# define PKCS12_ERROR 0 +# define PKCS12_OK 1 + +/* Compatibility macros */ + +#if OPENSSL_API_COMPAT < 0x10100000L + +# define M_PKCS12_bag_type PKCS12_bag_type +# define M_PKCS12_cert_bag_type PKCS12_cert_bag_type +# define M_PKCS12_crl_bag_type PKCS12_cert_bag_type + +# define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert +# define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl +# define PKCS12_bag_type PKCS12_SAFEBAG_get_nid +# define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid +# define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert +# define PKCS12_x509crl2certbag PKCS12_SAFEBAG_create_crl +# define PKCS12_MAKE_KEYBAG PKCS12_SAFEBAG_create0_p8inf +# define PKCS12_MAKE_SHKEYBAG PKCS12_SAFEBAG_create_pkcs8_encrypt + +#endif + +DEPRECATEDIN_1_1_0(ASN1_TYPE *PKCS12_get_attr(const PKCS12_SAFEBAG *bag, int attr_nid)) + +ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid); +int PKCS12_mac_present(const PKCS12 *p12); +void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac, + const X509_ALGOR **pmacalg, + const ASN1_OCTET_STRING **psalt, + const ASN1_INTEGER **piter, + const PKCS12 *p12); + +const ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag, + int attr_nid); +const ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag); +int PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag); +int PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag); + +X509 *PKCS12_SAFEBAG_get1_cert(const PKCS12_SAFEBAG *bag); +X509_CRL *PKCS12_SAFEBAG_get1_crl(const PKCS12_SAFEBAG *bag); +const STACK_OF(PKCS12_SAFEBAG) * +PKCS12_SAFEBAG_get0_safes(const PKCS12_SAFEBAG *bag); +const PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(const PKCS12_SAFEBAG *bag); +const X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(const PKCS12_SAFEBAG *bag); + +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_cert(X509 *x509); +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_crl(X509_CRL *crl); +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8); +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8); +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid, + const char *pass, + int passlen, + unsigned char *salt, + int saltlen, int iter, + PKCS8_PRIV_KEY_INFO *p8inf); + +PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, + int nid1, int nid2); +PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass, + int passlen); +PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(const PKCS12_SAFEBAG *bag, + const char *pass, int passlen); +X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, + const char *pass, int passlen, unsigned char *salt, + int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8); +X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen, + PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe); +PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk); +STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7); +PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, + unsigned char *salt, int saltlen, int iter, + STACK_OF(PKCS12_SAFEBAG) *bags); +STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, + int passlen); + +int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes); +STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12); + +int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, + int namelen); +int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, + int namelen); +int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name, + int namelen); +int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, + int namelen); +int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, + const unsigned char *name, int namelen); +int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage); +ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs, + int attr_nid); +char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag); +const STACK_OF(X509_ATTRIBUTE) * +PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag); +unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor, + const char *pass, int passlen, + const unsigned char *in, int inlen, + unsigned char **data, int *datalen, + int en_de); +void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it, + const char *pass, int passlen, + const ASN1_OCTET_STRING *oct, int zbuf); +ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, + const ASN1_ITEM *it, + const char *pass, int passlen, + void *obj, int zbuf); +PKCS12 *PKCS12_init(int mode); +int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); +int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); +int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt, + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); +int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, + const EVP_MD *md_type, int en_de); +int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, + unsigned char *mac, unsigned int *maclen); +int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen); +int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, + unsigned char *salt, int saltlen, int iter, + const EVP_MD *md_type); +int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, + int saltlen, const EVP_MD *md_type); +unsigned char *OPENSSL_asc2uni(const char *asc, int asclen, + unsigned char **uni, int *unilen); +char *OPENSSL_uni2asc(const unsigned char *uni, int unilen); +unsigned char *OPENSSL_utf82uni(const char *asc, int asclen, + unsigned char **uni, int *unilen); +char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen); + +DECLARE_ASN1_FUNCTIONS(PKCS12) +DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA) +DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG) +DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS) + +DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS) +DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES) + +void PKCS12_PBE_add(void); +int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, + STACK_OF(X509) **ca); +PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey, + X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, + int iter, int mac_iter, int keytype); + +PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert); +PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, + EVP_PKEY *key, int key_usage, int iter, + int key_nid, const char *pass); +int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags, + int safe_nid, int iter, const char *pass); +PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid); + +int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12); +# ifndef OPENSSL_NO_STDIO +int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12); +# endif +PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12); +# ifndef OPENSSL_NO_STDIO +PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12); +# endif +int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_PKCS12_strings(void); + +/* Error codes for the PKCS12 functions. */ + +/* Function codes. */ +# define PKCS12_F_PKCS12_CREATE 105 +# define PKCS12_F_PKCS12_GEN_MAC 107 +# define PKCS12_F_PKCS12_INIT 109 +# define PKCS12_F_PKCS12_ITEM_DECRYPT_D2I 106 +# define PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT 108 +# define PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG 117 +# define PKCS12_F_PKCS12_KEY_GEN_ASC 110 +# define PKCS12_F_PKCS12_KEY_GEN_UNI 111 +# define PKCS12_F_PKCS12_KEY_GEN_UTF8 116 +# define PKCS12_F_PKCS12_NEWPASS 128 +# define PKCS12_F_PKCS12_PACK_P7DATA 114 +# define PKCS12_F_PKCS12_PACK_P7ENCDATA 115 +# define PKCS12_F_PKCS12_PARSE 118 +# define PKCS12_F_PKCS12_PBE_CRYPT 119 +# define PKCS12_F_PKCS12_PBE_KEYIVGEN 120 +# define PKCS12_F_PKCS12_SAFEBAG_CREATE0_P8INF 112 +# define PKCS12_F_PKCS12_SAFEBAG_CREATE0_PKCS8 113 +# define PKCS12_F_PKCS12_SAFEBAG_CREATE_PKCS8_ENCRYPT 133 +# define PKCS12_F_PKCS12_SETUP_MAC 122 +# define PKCS12_F_PKCS12_SET_MAC 123 +# define PKCS12_F_PKCS12_UNPACK_AUTHSAFES 130 +# define PKCS12_F_PKCS12_UNPACK_P7DATA 131 +# define PKCS12_F_PKCS12_VERIFY_MAC 126 +# define PKCS12_F_PKCS8_ENCRYPT 125 +# define PKCS12_F_PKCS8_SET0_PBE 132 + +/* Reason codes. */ +# define PKCS12_R_CANT_PACK_STRUCTURE 100 +# define PKCS12_R_CONTENT_TYPE_NOT_DATA 121 +# define PKCS12_R_DECODE_ERROR 101 +# define PKCS12_R_ENCODE_ERROR 102 +# define PKCS12_R_ENCRYPT_ERROR 103 +# define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120 +# define PKCS12_R_INVALID_NULL_ARGUMENT 104 +# define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105 +# define PKCS12_R_IV_GEN_ERROR 106 +# define PKCS12_R_KEY_GEN_ERROR 107 +# define PKCS12_R_MAC_ABSENT 108 +# define PKCS12_R_MAC_GENERATION_ERROR 109 +# define PKCS12_R_MAC_SETUP_ERROR 110 +# define PKCS12_R_MAC_STRING_SET_ERROR 111 +# define PKCS12_R_MAC_VERIFY_FAILURE 113 +# define PKCS12_R_PARSE_ERROR 114 +# define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115 +# define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116 +# define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117 +# define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118 +# define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/pkcs7.h b/android/x86/include/openssl/pkcs7.h new file mode 100644 index 00000000..691f7220 --- /dev/null +++ b/android/x86/include/openssl/pkcs7.h @@ -0,0 +1,404 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PKCS7_H +# define HEADER_PKCS7_H + +# include <openssl/asn1.h> +# include <openssl/bio.h> +# include <openssl/e_os2.h> + +# include <openssl/symhacks.h> +# include <openssl/ossl_typ.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/*- +Encryption_ID DES-CBC +Digest_ID MD5 +Digest_Encryption_ID rsaEncryption +Key_Encryption_ID rsaEncryption +*/ + +typedef struct pkcs7_issuer_and_serial_st { + X509_NAME *issuer; + ASN1_INTEGER *serial; +} PKCS7_ISSUER_AND_SERIAL; + +typedef struct pkcs7_signer_info_st { + ASN1_INTEGER *version; /* version 1 */ + PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; + X509_ALGOR *digest_alg; + STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */ + X509_ALGOR *digest_enc_alg; + ASN1_OCTET_STRING *enc_digest; + STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */ + /* The private key to sign with */ + EVP_PKEY *pkey; +} PKCS7_SIGNER_INFO; + +DEFINE_STACK_OF(PKCS7_SIGNER_INFO) + +typedef struct pkcs7_recip_info_st { + ASN1_INTEGER *version; /* version 0 */ + PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; + X509_ALGOR *key_enc_algor; + ASN1_OCTET_STRING *enc_key; + X509 *cert; /* get the pub-key from this */ +} PKCS7_RECIP_INFO; + +DEFINE_STACK_OF(PKCS7_RECIP_INFO) + +typedef struct pkcs7_signed_st { + ASN1_INTEGER *version; /* version 1 */ + STACK_OF(X509_ALGOR) *md_algs; /* md used */ + STACK_OF(X509) *cert; /* [ 0 ] */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ + STACK_OF(PKCS7_SIGNER_INFO) *signer_info; + struct pkcs7_st *contents; +} PKCS7_SIGNED; +/* + * The above structure is very very similar to PKCS7_SIGN_ENVELOPE. How about + * merging the two + */ + +typedef struct pkcs7_enc_content_st { + ASN1_OBJECT *content_type; + X509_ALGOR *algorithm; + ASN1_OCTET_STRING *enc_data; /* [ 0 ] */ + const EVP_CIPHER *cipher; +} PKCS7_ENC_CONTENT; + +typedef struct pkcs7_enveloped_st { + ASN1_INTEGER *version; /* version 0 */ + STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; + PKCS7_ENC_CONTENT *enc_data; +} PKCS7_ENVELOPE; + +typedef struct pkcs7_signedandenveloped_st { + ASN1_INTEGER *version; /* version 1 */ + STACK_OF(X509_ALGOR) *md_algs; /* md used */ + STACK_OF(X509) *cert; /* [ 0 ] */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ + STACK_OF(PKCS7_SIGNER_INFO) *signer_info; + PKCS7_ENC_CONTENT *enc_data; + STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; +} PKCS7_SIGN_ENVELOPE; + +typedef struct pkcs7_digest_st { + ASN1_INTEGER *version; /* version 0 */ + X509_ALGOR *md; /* md used */ + struct pkcs7_st *contents; + ASN1_OCTET_STRING *digest; +} PKCS7_DIGEST; + +typedef struct pkcs7_encrypted_st { + ASN1_INTEGER *version; /* version 0 */ + PKCS7_ENC_CONTENT *enc_data; +} PKCS7_ENCRYPT; + +typedef struct pkcs7_st { + /* + * The following is non NULL if it contains ASN1 encoding of this + * structure + */ + unsigned char *asn1; + long length; +# define PKCS7_S_HEADER 0 +# define PKCS7_S_BODY 1 +# define PKCS7_S_TAIL 2 + int state; /* used during processing */ + int detached; + ASN1_OBJECT *type; + /* content as defined by the type */ + /* + * all encryption/message digests are applied to the 'contents', leaving + * out the 'type' field. + */ + union { + char *ptr; + /* NID_pkcs7_data */ + ASN1_OCTET_STRING *data; + /* NID_pkcs7_signed */ + PKCS7_SIGNED *sign; + /* NID_pkcs7_enveloped */ + PKCS7_ENVELOPE *enveloped; + /* NID_pkcs7_signedAndEnveloped */ + PKCS7_SIGN_ENVELOPE *signed_and_enveloped; + /* NID_pkcs7_digest */ + PKCS7_DIGEST *digest; + /* NID_pkcs7_encrypted */ + PKCS7_ENCRYPT *encrypted; + /* Anything else */ + ASN1_TYPE *other; + } d; +} PKCS7; + +DEFINE_STACK_OF(PKCS7) + +# define PKCS7_OP_SET_DETACHED_SIGNATURE 1 +# define PKCS7_OP_GET_DETACHED_SIGNATURE 2 + +# define PKCS7_get_signed_attributes(si) ((si)->auth_attr) +# define PKCS7_get_attributes(si) ((si)->unauth_attr) + +# define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) +# define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted) +# define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped) +# define PKCS7_type_is_signedAndEnveloped(a) \ + (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) +# define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) +# define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest) + +# define PKCS7_set_detached(p,v) \ + PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL) +# define PKCS7_get_detached(p) \ + PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL) + +# define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7)) + +/* S/MIME related flags */ + +# define PKCS7_TEXT 0x1 +# define PKCS7_NOCERTS 0x2 +# define PKCS7_NOSIGS 0x4 +# define PKCS7_NOCHAIN 0x8 +# define PKCS7_NOINTERN 0x10 +# define PKCS7_NOVERIFY 0x20 +# define PKCS7_DETACHED 0x40 +# define PKCS7_BINARY 0x80 +# define PKCS7_NOATTR 0x100 +# define PKCS7_NOSMIMECAP 0x200 +# define PKCS7_NOOLDMIMETYPE 0x400 +# define PKCS7_CRLFEOL 0x800 +# define PKCS7_STREAM 0x1000 +# define PKCS7_NOCRL 0x2000 +# define PKCS7_PARTIAL 0x4000 +# define PKCS7_REUSE_DIGEST 0x8000 +# define PKCS7_NO_DUAL_CONTENT 0x10000 + +/* Flags: for compatibility with older code */ + +# define SMIME_TEXT PKCS7_TEXT +# define SMIME_NOCERTS PKCS7_NOCERTS +# define SMIME_NOSIGS PKCS7_NOSIGS +# define SMIME_NOCHAIN PKCS7_NOCHAIN +# define SMIME_NOINTERN PKCS7_NOINTERN +# define SMIME_NOVERIFY PKCS7_NOVERIFY +# define SMIME_DETACHED PKCS7_DETACHED +# define SMIME_BINARY PKCS7_BINARY +# define SMIME_NOATTR PKCS7_NOATTR + +/* CRLF ASCII canonicalisation */ +# define SMIME_ASCIICRLF 0x80000 + +DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL) + +int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, + const EVP_MD *type, unsigned char *md, + unsigned int *len); +# ifndef OPENSSL_NO_STDIO +PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7); +int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7); +# endif +PKCS7 *PKCS7_dup(PKCS7 *p7); +PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7); +int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7); +int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags); +int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *in, int flags); + +DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO) +DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO) +DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED) +DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT) +DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE) +DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE) +DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST) +DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT) +DECLARE_ASN1_FUNCTIONS(PKCS7) + +DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN) +DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY) + +DECLARE_ASN1_NDEF_FUNCTION(PKCS7) +DECLARE_ASN1_PRINT_FUNCTION(PKCS7) + +long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg); + +int PKCS7_set_type(PKCS7 *p7, int type); +int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other); +int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data); +int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, + const EVP_MD *dgst); +int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si); +int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i); +int PKCS7_add_certificate(PKCS7 *p7, X509 *x509); +int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509); +int PKCS7_content_new(PKCS7 *p7, int nid); +int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, + BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); +int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, + X509 *x509); + +BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio); +int PKCS7_dataFinal(PKCS7 *p7, BIO *bio); +BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert); + +PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, + EVP_PKEY *pkey, const EVP_MD *dgst); +X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); +int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md); +STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7); + +PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); +void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk, + X509_ALGOR **pdig, X509_ALGOR **psig); +void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc); +int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri); +int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509); +int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher); +int PKCS7_stream(unsigned char ***boundary, PKCS7 *p7); + +PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx); +ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk); +int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int type, + void *data); +int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, + void *value); +ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid); +ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid); +int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, + STACK_OF(X509_ATTRIBUTE) *sk); +int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, + STACK_OF(X509_ATTRIBUTE) *sk); + +PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, + BIO *data, int flags); + +PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, + X509 *signcert, EVP_PKEY *pkey, + const EVP_MD *md, int flags); + +int PKCS7_final(PKCS7 *p7, BIO *data, int flags); +int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, + BIO *indata, BIO *out, int flags); +STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, + int flags); +PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, + int flags); +int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, + int flags); + +int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, + STACK_OF(X509_ALGOR) *cap); +STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si); +int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg); + +int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid); +int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t); +int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, + const unsigned char *md, int mdlen); + +int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags); +PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont); + +BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_PKCS7_strings(void); + +/* Error codes for the PKCS7 functions. */ + +/* Function codes. */ +# define PKCS7_F_DO_PKCS7_SIGNED_ATTRIB 136 +# define PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME 135 +# define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118 +# define PKCS7_F_PKCS7_ADD_CERTIFICATE 100 +# define PKCS7_F_PKCS7_ADD_CRL 101 +# define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 +# define PKCS7_F_PKCS7_ADD_SIGNATURE 131 +# define PKCS7_F_PKCS7_ADD_SIGNER 103 +# define PKCS7_F_PKCS7_BIO_ADD_DIGEST 125 +# define PKCS7_F_PKCS7_COPY_EXISTING_DIGEST 138 +# define PKCS7_F_PKCS7_CTRL 104 +# define PKCS7_F_PKCS7_DATADECODE 112 +# define PKCS7_F_PKCS7_DATAFINAL 128 +# define PKCS7_F_PKCS7_DATAINIT 105 +# define PKCS7_F_PKCS7_DATAVERIFY 107 +# define PKCS7_F_PKCS7_DECRYPT 114 +# define PKCS7_F_PKCS7_DECRYPT_RINFO 133 +# define PKCS7_F_PKCS7_ENCODE_RINFO 132 +# define PKCS7_F_PKCS7_ENCRYPT 115 +# define PKCS7_F_PKCS7_FINAL 134 +# define PKCS7_F_PKCS7_FIND_DIGEST 127 +# define PKCS7_F_PKCS7_GET0_SIGNERS 124 +# define PKCS7_F_PKCS7_RECIP_INFO_SET 130 +# define PKCS7_F_PKCS7_SET_CIPHER 108 +# define PKCS7_F_PKCS7_SET_CONTENT 109 +# define PKCS7_F_PKCS7_SET_DIGEST 126 +# define PKCS7_F_PKCS7_SET_TYPE 110 +# define PKCS7_F_PKCS7_SIGN 116 +# define PKCS7_F_PKCS7_SIGNATUREVERIFY 113 +# define PKCS7_F_PKCS7_SIGNER_INFO_SET 129 +# define PKCS7_F_PKCS7_SIGNER_INFO_SIGN 139 +# define PKCS7_F_PKCS7_SIGN_ADD_SIGNER 137 +# define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119 +# define PKCS7_F_PKCS7_VERIFY 117 + +/* Reason codes. */ +# define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117 +# define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144 +# define PKCS7_R_CIPHER_NOT_INITIALIZED 116 +# define PKCS7_R_CONTENT_AND_DATA_PRESENT 118 +# define PKCS7_R_CTRL_ERROR 152 +# define PKCS7_R_DECRYPT_ERROR 119 +# define PKCS7_R_DIGEST_FAILURE 101 +# define PKCS7_R_ENCRYPTION_CTRL_FAILURE 149 +# define PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 150 +# define PKCS7_R_ERROR_ADDING_RECIPIENT 120 +# define PKCS7_R_ERROR_SETTING_CIPHER 121 +# define PKCS7_R_INVALID_NULL_POINTER 143 +# define PKCS7_R_INVALID_SIGNED_DATA_TYPE 155 +# define PKCS7_R_NO_CONTENT 122 +# define PKCS7_R_NO_DEFAULT_DIGEST 151 +# define PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND 154 +# define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115 +# define PKCS7_R_NO_SIGNATURES_ON_DATA 123 +# define PKCS7_R_NO_SIGNERS 142 +# define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104 +# define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124 +# define PKCS7_R_PKCS7_ADD_SIGNER_ERROR 153 +# define PKCS7_R_PKCS7_DATASIGN 145 +# define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127 +# define PKCS7_R_SIGNATURE_FAILURE 105 +# define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128 +# define PKCS7_R_SIGNING_CTRL_FAILURE 147 +# define PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 148 +# define PKCS7_R_SMIME_TEXT_ERROR 129 +# define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106 +# define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107 +# define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108 +# define PKCS7_R_UNKNOWN_DIGEST_TYPE 109 +# define PKCS7_R_UNKNOWN_OPERATION 110 +# define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111 +# define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112 +# define PKCS7_R_WRONG_CONTENT_TYPE 113 +# define PKCS7_R_WRONG_PKCS7_TYPE 114 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/rand.h b/android/x86/include/openssl/rand.h new file mode 100644 index 00000000..d521ae19 --- /dev/null +++ b/android/x86/include/openssl/rand.h @@ -0,0 +1,89 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RAND_H +# define HEADER_RAND_H + +# include <stdlib.h> +# include <openssl/ossl_typ.h> +# include <openssl/e_os2.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Already defined in ossl_typ.h */ +/* typedef struct rand_meth_st RAND_METHOD; */ + +struct rand_meth_st { + int (*seed) (const void *buf, int num); + int (*bytes) (unsigned char *buf, int num); + void (*cleanup) (void); + int (*add) (const void *buf, int num, double entropy); + int (*pseudorand) (unsigned char *buf, int num); + int (*status) (void); +}; + +# ifdef BN_DEBUG +extern int rand_predictable; +# endif + +int RAND_set_rand_method(const RAND_METHOD *meth); +const RAND_METHOD *RAND_get_rand_method(void); +# ifndef OPENSSL_NO_ENGINE +int RAND_set_rand_engine(ENGINE *engine); +# endif +RAND_METHOD *RAND_OpenSSL(void); +#if OPENSSL_API_COMPAT < 0x10100000L +# define RAND_cleanup() while(0) continue +#endif +int RAND_bytes(unsigned char *buf, int num); +DEPRECATEDIN_1_1_0(int RAND_pseudo_bytes(unsigned char *buf, int num)) +void RAND_seed(const void *buf, int num); +#if defined(__ANDROID__) && defined(__NDK_FPABI__) +__NDK_FPABI__ /* __attribute__((pcs("aapcs"))) on ARM */ +#endif +void RAND_add(const void *buf, int num, double entropy); +int RAND_load_file(const char *file, long max_bytes); +int RAND_write_file(const char *file); +const char *RAND_file_name(char *file, size_t num); +int RAND_status(void); +# ifndef OPENSSL_NO_EGD +int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes); +int RAND_egd(const char *path); +int RAND_egd_bytes(const char *path, int bytes); +# endif +int RAND_poll(void); + +#if defined(_WIN32) && (defined(BASETYPES) || defined(_WINDEF_H)) +/* application has to include <windows.h> in order to use these */ +DEPRECATEDIN_1_1_0(void RAND_screen(void)) +DEPRECATEDIN_1_1_0(int RAND_event(UINT, WPARAM, LPARAM)) +#endif + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_RAND_strings(void); + +/* Error codes for the RAND functions. */ + +/* Function codes. */ +# define RAND_F_RAND_BYTES 100 + +/* Reason codes. */ +# define RAND_R_PRNG_NOT_SEEDED 100 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/rc2.h b/android/x86/include/openssl/rc2.h new file mode 100644 index 00000000..585f9e4c --- /dev/null +++ b/android/x86/include/openssl/rc2.h @@ -0,0 +1,51 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RC2_H +# define HEADER_RC2_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_RC2 +# ifdef __cplusplus +extern "C" { +# endif + +typedef unsigned int RC2_INT; + +# define RC2_ENCRYPT 1 +# define RC2_DECRYPT 0 + +# define RC2_BLOCK 8 +# define RC2_KEY_LENGTH 16 + +typedef struct rc2_key_st { + RC2_INT data[64]; +} RC2_KEY; + +void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits); +void RC2_ecb_encrypt(const unsigned char *in, unsigned char *out, + RC2_KEY *key, int enc); +void RC2_encrypt(unsigned long *data, RC2_KEY *key); +void RC2_decrypt(unsigned long *data, RC2_KEY *key); +void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + RC2_KEY *ks, unsigned char *iv, int enc); +void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC2_KEY *schedule, unsigned char *ivec, + int *num, int enc); +void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC2_KEY *schedule, unsigned char *ivec, + int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/rc4.h b/android/x86/include/openssl/rc4.h new file mode 100644 index 00000000..86803b37 --- /dev/null +++ b/android/x86/include/openssl/rc4.h @@ -0,0 +1,36 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RC4_H +# define HEADER_RC4_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_RC4 +# include <stddef.h> +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rc4_key_st { + RC4_INT x, y; + RC4_INT data[256]; +} RC4_KEY; + +const char *RC4_options(void); +void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); +void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, + unsigned char *outdata); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/rc5.h b/android/x86/include/openssl/rc5.h new file mode 100644 index 00000000..793f88e4 --- /dev/null +++ b/android/x86/include/openssl/rc5.h @@ -0,0 +1,63 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RC5_H +# define HEADER_RC5_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_RC5 +# ifdef __cplusplus +extern "C" { +# endif + +# define RC5_ENCRYPT 1 +# define RC5_DECRYPT 0 + +# define RC5_32_INT unsigned int + +# define RC5_32_BLOCK 8 +# define RC5_32_KEY_LENGTH 16/* This is a default, max is 255 */ + +/* + * This are the only values supported. Tweak the code if you want more The + * most supported modes will be RC5-32/12/16 RC5-32/16/8 + */ +# define RC5_8_ROUNDS 8 +# define RC5_12_ROUNDS 12 +# define RC5_16_ROUNDS 16 + +typedef struct rc5_key_st { + /* Number of rounds */ + int rounds; + RC5_32_INT data[2 * (RC5_16_ROUNDS + 1)]; +} RC5_32_KEY; + +void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data, + int rounds); +void RC5_32_ecb_encrypt(const unsigned char *in, unsigned char *out, + RC5_32_KEY *key, int enc); +void RC5_32_encrypt(unsigned long *data, RC5_32_KEY *key); +void RC5_32_decrypt(unsigned long *data, RC5_32_KEY *key); +void RC5_32_cbc_encrypt(const unsigned char *in, unsigned char *out, + long length, RC5_32_KEY *ks, unsigned char *iv, + int enc); +void RC5_32_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC5_32_KEY *schedule, + unsigned char *ivec, int *num, int enc); +void RC5_32_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC5_32_KEY *schedule, + unsigned char *ivec, int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/ripemd.h b/android/x86/include/openssl/ripemd.h new file mode 100644 index 00000000..c42026aa --- /dev/null +++ b/android/x86/include/openssl/ripemd.h @@ -0,0 +1,47 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RIPEMD_H +# define HEADER_RIPEMD_H + +# include <openssl/opensslconf.h> + +#ifndef OPENSSL_NO_RMD160 +# include <openssl/e_os2.h> +# include <stddef.h> +# ifdef __cplusplus +extern "C" { +# endif + +# define RIPEMD160_LONG unsigned int + +# define RIPEMD160_CBLOCK 64 +# define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4) +# define RIPEMD160_DIGEST_LENGTH 20 + +typedef struct RIPEMD160state_st { + RIPEMD160_LONG A, B, C, D, E; + RIPEMD160_LONG Nl, Nh; + RIPEMD160_LONG data[RIPEMD160_LBLOCK]; + unsigned int num; +} RIPEMD160_CTX; + +int RIPEMD160_Init(RIPEMD160_CTX *c); +int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len); +int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); +unsigned char *RIPEMD160(const unsigned char *d, size_t n, unsigned char *md); +void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b); + +# ifdef __cplusplus +} +# endif +# endif + + +#endif diff --git a/android/x86/include/openssl/rsa.h b/android/x86/include/openssl/rsa.h new file mode 100644 index 00000000..4d6e9cc9 --- /dev/null +++ b/android/x86/include/openssl/rsa.h @@ -0,0 +1,589 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RSA_H +# define HEADER_RSA_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_RSA +# include <openssl/asn1.h> +# include <openssl/bio.h> +# include <openssl/crypto.h> +# include <openssl/ossl_typ.h> +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/bn.h> +# endif +# ifdef __cplusplus +extern "C" { +# endif + +/* The types RSA and RSA_METHOD are defined in ossl_typ.h */ + +# ifndef OPENSSL_RSA_MAX_MODULUS_BITS +# define OPENSSL_RSA_MAX_MODULUS_BITS 16384 +# endif + +# define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024 + +# ifndef OPENSSL_RSA_SMALL_MODULUS_BITS +# define OPENSSL_RSA_SMALL_MODULUS_BITS 3072 +# endif +# ifndef OPENSSL_RSA_MAX_PUBEXP_BITS + +/* exponent limit enforced for "large" modulus only */ +# define OPENSSL_RSA_MAX_PUBEXP_BITS 64 +# endif + +# define RSA_3 0x3L +# define RSA_F4 0x10001L + +# define RSA_METHOD_FLAG_NO_CHECK 0x0001/* don't check pub/private + * match */ + +# define RSA_FLAG_CACHE_PUBLIC 0x0002 +# define RSA_FLAG_CACHE_PRIVATE 0x0004 +# define RSA_FLAG_BLINDING 0x0008 +# define RSA_FLAG_THREAD_SAFE 0x0010 +/* + * This flag means the private key operations will be handled by rsa_mod_exp + * and that they do not depend on the private key components being present: + * for example a key stored in external hardware. Without this flag + * bn_mod_exp gets called when private key components are absent. + */ +# define RSA_FLAG_EXT_PKEY 0x0020 + +/* + * new with 0.9.6j and 0.9.7b; the built-in + * RSA implementation now uses blinding by + * default (ignoring RSA_FLAG_BLINDING), + * but other engines might not need it + */ +# define RSA_FLAG_NO_BLINDING 0x0080 +# if OPENSSL_API_COMPAT < 0x10100000L +/* + * Does nothing. Previously this switched off constant time behaviour. + */ +# define RSA_FLAG_NO_CONSTTIME 0x0000 +# endif +# if OPENSSL_API_COMPAT < 0x00908000L +/* deprecated name for the flag*/ +/* + * new with 0.9.7h; the built-in RSA + * implementation now uses constant time + * modular exponentiation for secret exponents + * by default. This flag causes the + * faster variable sliding window method to + * be used for all exponents. + */ +# define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME +# endif + +# define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, EVP_PKEY_CTRL_RSA_PADDING, \ + pad, NULL) + +# define EVP_PKEY_CTX_get_rsa_padding(ctx, ppad) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, \ + EVP_PKEY_CTRL_GET_RSA_PADDING, 0, ppad) + +# define EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \ + (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \ + EVP_PKEY_CTRL_RSA_PSS_SALTLEN, \ + len, NULL) + +# define EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, plen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \ + (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \ + EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, \ + 0, plen) + +# define EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL) + +# define EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp) + +# define EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \ + EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)md) + +# define EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_RSA_OAEP_MD, 0, (void *)md) + +# define EVP_PKEY_CTX_get_rsa_mgf1_md(ctx, pmd) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \ + EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_GET_RSA_MGF1_MD, 0, (void *)pmd) + +# define EVP_PKEY_CTX_get_rsa_oaep_md(ctx, pmd) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_GET_RSA_OAEP_MD, 0, (void *)pmd) + +# define EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, l, llen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_RSA_OAEP_LABEL, llen, (void *)l) + +# define EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, l) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, (void *)l) + +# define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 2) + +# define EVP_PKEY_CTRL_RSA_KEYGEN_BITS (EVP_PKEY_ALG_CTRL + 3) +# define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4) +# define EVP_PKEY_CTRL_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 5) + +# define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 6) +# define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 7) +# define EVP_PKEY_CTRL_GET_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 8) + +# define EVP_PKEY_CTRL_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 9) +# define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 10) + +# define EVP_PKEY_CTRL_GET_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 11) +# define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12) + +# define RSA_PKCS1_PADDING 1 +# define RSA_SSLV23_PADDING 2 +# define RSA_NO_PADDING 3 +# define RSA_PKCS1_OAEP_PADDING 4 +# define RSA_X931_PADDING 5 +/* EVP_PKEY_ only */ +# define RSA_PKCS1_PSS_PADDING 6 + +# define RSA_PKCS1_PADDING_SIZE 11 + +# define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg) +# define RSA_get_app_data(s) RSA_get_ex_data(s,0) + +RSA *RSA_new(void); +RSA *RSA_new_method(ENGINE *engine); +int RSA_bits(const RSA *rsa); +int RSA_size(const RSA *rsa); +int RSA_security_bits(const RSA *rsa); + +int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d); +int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q); +int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp); +void RSA_get0_key(const RSA *r, + const BIGNUM **n, const BIGNUM **e, const BIGNUM **d); +void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q); +void RSA_get0_crt_params(const RSA *r, + const BIGNUM **dmp1, const BIGNUM **dmq1, + const BIGNUM **iqmp); +void RSA_clear_flags(RSA *r, int flags); +int RSA_test_flags(const RSA *r, int flags); +void RSA_set_flags(RSA *r, int flags); +ENGINE *RSA_get0_engine(const RSA *r); + +/* Deprecated version */ +DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void + (*callback) (int, int, void *), + void *cb_arg)) + +/* New version */ +int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); + +int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, + BIGNUM *q2, const BIGNUM *Xp1, const BIGNUM *Xp2, + const BIGNUM *Xp, const BIGNUM *Xq1, const BIGNUM *Xq2, + const BIGNUM *Xq, const BIGNUM *e, BN_GENCB *cb); +int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, + BN_GENCB *cb); + +int RSA_check_key(const RSA *); +int RSA_check_key_ex(const RSA *, BN_GENCB *cb); + /* next 4 return -1 on error */ +int RSA_public_encrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_private_encrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_public_decrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_private_decrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +void RSA_free(RSA *r); +/* "up" the RSA object's reference count */ +int RSA_up_ref(RSA *r); + +int RSA_flags(const RSA *r); + +void RSA_set_default_method(const RSA_METHOD *meth); +const RSA_METHOD *RSA_get_default_method(void); +const RSA_METHOD *RSA_get_method(const RSA *rsa); +int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); + +/* these are the actual RSA functions */ +const RSA_METHOD *RSA_PKCS1_OpenSSL(void); + +const RSA_METHOD *RSA_null_method(void); + +DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey) +DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey) + +typedef struct rsa_pss_params_st { + X509_ALGOR *hashAlgorithm; + X509_ALGOR *maskGenAlgorithm; + ASN1_INTEGER *saltLength; + ASN1_INTEGER *trailerField; +} RSA_PSS_PARAMS; + +DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS) + +typedef struct rsa_oaep_params_st { + X509_ALGOR *hashFunc; + X509_ALGOR *maskGenFunc; + X509_ALGOR *pSourceFunc; +} RSA_OAEP_PARAMS; + +DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS) + +# ifndef OPENSSL_NO_STDIO +int RSA_print_fp(FILE *fp, const RSA *r, int offset); +# endif + +int RSA_print(BIO *bp, const RSA *r, int offset); + +/* + * The following 2 functions sign and verify a X509_SIG ASN1 object inside + * PKCS#1 padded RSA encryption + */ +int RSA_sign(int type, const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, RSA *rsa); +int RSA_verify(int type, const unsigned char *m, unsigned int m_length, + const unsigned char *sigbuf, unsigned int siglen, RSA *rsa); + +/* + * The following 2 function sign and verify a ASN1_OCTET_STRING object inside + * PKCS#1 padded RSA encryption + */ +int RSA_sign_ASN1_OCTET_STRING(int type, + const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, + RSA *rsa); +int RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char *m, + unsigned int m_length, unsigned char *sigbuf, + unsigned int siglen, RSA *rsa); + +int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); +void RSA_blinding_off(RSA *rsa); +BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx); + +int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, + const unsigned char *f, int fl); +int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, + const unsigned char *f, int fl, + int rsa_len); +int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, + const unsigned char *f, int fl); +int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, + const unsigned char *f, int fl, + int rsa_len); +int PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed, + long seedlen, const EVP_MD *dgst); +int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, + const unsigned char *f, int fl, + const unsigned char *p, int pl); +int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen, + const unsigned char *f, int fl, int rsa_len, + const unsigned char *p, int pl); +int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, + const unsigned char *from, int flen, + const unsigned char *param, int plen, + const EVP_MD *md, const EVP_MD *mgf1md); +int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, + const unsigned char *from, int flen, + int num, const unsigned char *param, + int plen, const EVP_MD *md, + const EVP_MD *mgf1md); +int RSA_padding_add_SSLv23(unsigned char *to, int tlen, + const unsigned char *f, int fl); +int RSA_padding_check_SSLv23(unsigned char *to, int tlen, + const unsigned char *f, int fl, int rsa_len); +int RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *f, + int fl); +int RSA_padding_check_none(unsigned char *to, int tlen, + const unsigned char *f, int fl, int rsa_len); +int RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *f, + int fl); +int RSA_padding_check_X931(unsigned char *to, int tlen, + const unsigned char *f, int fl, int rsa_len); +int RSA_X931_hash_id(int nid); + +int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash, + const EVP_MD *Hash, const unsigned char *EM, + int sLen); +int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM, + const unsigned char *mHash, const EVP_MD *Hash, + int sLen); + +int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash, + const EVP_MD *Hash, const EVP_MD *mgf1Hash, + const unsigned char *EM, int sLen); + +int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, + const unsigned char *mHash, + const EVP_MD *Hash, const EVP_MD *mgf1Hash, + int sLen); + +#define RSA_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef) +int RSA_set_ex_data(RSA *r, int idx, void *arg); +void *RSA_get_ex_data(const RSA *r, int idx); + +RSA *RSAPublicKey_dup(RSA *rsa); +RSA *RSAPrivateKey_dup(RSA *rsa); + +/* + * If this flag is set the RSA method is FIPS compliant and can be used in + * FIPS mode. This is set in the validated module method. If an application + * sets this flag in its own methods it is its responsibility to ensure the + * result is compliant. + */ + +# define RSA_FLAG_FIPS_METHOD 0x0400 + +/* + * If this flag is set the operations normally disabled in FIPS mode are + * permitted it is then the applications responsibility to ensure that the + * usage is compliant. + */ + +# define RSA_FLAG_NON_FIPS_ALLOW 0x0400 +/* + * Application has decided PRNG is good enough to generate a key: don't + * check. + */ +# define RSA_FLAG_CHECKED 0x0800 + +RSA_METHOD *RSA_meth_new(const char *name, int flags); +void RSA_meth_free(RSA_METHOD *meth); +RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth); +const char *RSA_meth_get0_name(const RSA_METHOD *meth); +int RSA_meth_set1_name(RSA_METHOD *meth, const char *name); +int RSA_meth_get_flags(RSA_METHOD *meth); +int RSA_meth_set_flags(RSA_METHOD *meth, int flags); +void *RSA_meth_get0_app_data(const RSA_METHOD *meth); +int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data); +int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth)) + (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_meth_set_pub_enc(RSA_METHOD *rsa, + int (*pub_enc) (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, + int padding)); +int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth)) + (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_meth_set_pub_dec(RSA_METHOD *rsa, + int (*pub_dec) (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, + int padding)); +int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth)) + (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_meth_set_priv_enc(RSA_METHOD *rsa, + int (*priv_enc) (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, + int padding)); +int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth)) + (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_meth_set_priv_dec(RSA_METHOD *rsa, + int (*priv_dec) (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, + int padding)); +int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth)) + (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx); +int RSA_meth_set_mod_exp(RSA_METHOD *rsa, + int (*mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa, + BN_CTX *ctx)); +int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth)) + (BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa, + int (*bn_mod_exp) (BIGNUM *r, + const BIGNUM *a, + const BIGNUM *p, + const BIGNUM *m, + BN_CTX *ctx, + BN_MONT_CTX *m_ctx)); +int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa); +int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa)); +int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa); +int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa)); +int (*RSA_meth_get_sign(const RSA_METHOD *meth)) + (int type, + const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, + const RSA *rsa); +int RSA_meth_set_sign(RSA_METHOD *rsa, + int (*sign) (int type, const unsigned char *m, + unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, + const RSA *rsa)); +int (*RSA_meth_get_verify(const RSA_METHOD *meth)) + (int dtype, const unsigned char *m, + unsigned int m_length, const unsigned char *sigbuf, + unsigned int siglen, const RSA *rsa); +int RSA_meth_set_verify(RSA_METHOD *rsa, + int (*verify) (int dtype, const unsigned char *m, + unsigned int m_length, + const unsigned char *sigbuf, + unsigned int siglen, const RSA *rsa)); +int (*RSA_meth_get_keygen(const RSA_METHOD *meth)) + (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); +int RSA_meth_set_keygen(RSA_METHOD *rsa, + int (*keygen) (RSA *rsa, int bits, BIGNUM *e, + BN_GENCB *cb)); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_RSA_strings(void); + +/* Error codes for the RSA functions. */ + +/* Function codes. */ +# define RSA_F_CHECK_PADDING_MD 140 +# define RSA_F_ENCODE_PKCS1 146 +# define RSA_F_INT_RSA_VERIFY 145 +# define RSA_F_OLD_RSA_PRIV_DECODE 147 +# define RSA_F_PKEY_RSA_CTRL 143 +# define RSA_F_PKEY_RSA_CTRL_STR 144 +# define RSA_F_PKEY_RSA_SIGN 142 +# define RSA_F_PKEY_RSA_VERIFYRECOVER 141 +# define RSA_F_RSA_ALGOR_TO_MD 156 +# define RSA_F_RSA_BUILTIN_KEYGEN 129 +# define RSA_F_RSA_CHECK_KEY 123 +# define RSA_F_RSA_CHECK_KEY_EX 160 +# define RSA_F_RSA_CMS_DECRYPT 159 +# define RSA_F_RSA_ITEM_VERIFY 148 +# define RSA_F_RSA_METH_DUP 161 +# define RSA_F_RSA_METH_NEW 162 +# define RSA_F_RSA_METH_SET1_NAME 163 +# define RSA_F_RSA_MGF1_TO_MD 157 +# define RSA_F_RSA_NEW_METHOD 106 +# define RSA_F_RSA_NULL 124 +# define RSA_F_RSA_NULL_PRIVATE_DECRYPT 132 +# define RSA_F_RSA_NULL_PRIVATE_ENCRYPT 133 +# define RSA_F_RSA_NULL_PUBLIC_DECRYPT 134 +# define RSA_F_RSA_NULL_PUBLIC_ENCRYPT 135 +# define RSA_F_RSA_OSSL_PRIVATE_DECRYPT 101 +# define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT 102 +# define RSA_F_RSA_OSSL_PUBLIC_DECRYPT 103 +# define RSA_F_RSA_OSSL_PUBLIC_ENCRYPT 104 +# define RSA_F_RSA_PADDING_ADD_NONE 107 +# define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 +# define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP_MGF1 154 +# define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125 +# define RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1 152 +# define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 +# define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 +# define RSA_F_RSA_PADDING_ADD_SSLV23 110 +# define RSA_F_RSA_PADDING_ADD_X931 127 +# define RSA_F_RSA_PADDING_CHECK_NONE 111 +# define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 +# define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1 153 +# define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 +# define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 +# define RSA_F_RSA_PADDING_CHECK_SSLV23 114 +# define RSA_F_RSA_PADDING_CHECK_X931 128 +# define RSA_F_RSA_PRINT 115 +# define RSA_F_RSA_PRINT_FP 116 +# define RSA_F_RSA_PRIV_ENCODE 138 +# define RSA_F_RSA_PSS_TO_CTX 155 +# define RSA_F_RSA_PUB_DECODE 139 +# define RSA_F_RSA_SETUP_BLINDING 136 +# define RSA_F_RSA_SIGN 117 +# define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 +# define RSA_F_RSA_VERIFY 119 +# define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 +# define RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1 126 + +/* Reason codes. */ +# define RSA_R_ALGORITHM_MISMATCH 100 +# define RSA_R_BAD_E_VALUE 101 +# define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 +# define RSA_R_BAD_PAD_BYTE_COUNT 103 +# define RSA_R_BAD_SIGNATURE 104 +# define RSA_R_BLOCK_TYPE_IS_NOT_01 106 +# define RSA_R_BLOCK_TYPE_IS_NOT_02 107 +# define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 +# define RSA_R_DATA_TOO_LARGE 109 +# define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 +# define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132 +# define RSA_R_DATA_TOO_SMALL 111 +# define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122 +# define RSA_R_DIGEST_DOES_NOT_MATCH 158 +# define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 +# define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 +# define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 +# define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 +# define RSA_R_FIRST_OCTET_INVALID 133 +# define RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE 144 +# define RSA_R_INVALID_DIGEST 157 +# define RSA_R_INVALID_DIGEST_LENGTH 143 +# define RSA_R_INVALID_HEADER 137 +# define RSA_R_INVALID_LABEL 160 +# define RSA_R_INVALID_MESSAGE_LENGTH 131 +# define RSA_R_INVALID_MGF1_MD 156 +# define RSA_R_INVALID_OAEP_PARAMETERS 161 +# define RSA_R_INVALID_PADDING 138 +# define RSA_R_INVALID_PADDING_MODE 141 +# define RSA_R_INVALID_PSS_PARAMETERS 149 +# define RSA_R_INVALID_PSS_SALTLEN 146 +# define RSA_R_INVALID_SALT_LENGTH 150 +# define RSA_R_INVALID_TRAILER 139 +# define RSA_R_INVALID_X931_DIGEST 142 +# define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 +# define RSA_R_KEY_SIZE_TOO_SMALL 120 +# define RSA_R_LAST_OCTET_INVALID 134 +# define RSA_R_MODULUS_TOO_LARGE 105 +# define RSA_R_NO_PUBLIC_EXPONENT 140 +# define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 +# define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 +# define RSA_R_OAEP_DECODING_ERROR 121 +# define RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 148 +# define RSA_R_PADDING_CHECK_FAILED 114 +# define RSA_R_PKCS_DECODING_ERROR 159 +# define RSA_R_P_NOT_PRIME 128 +# define RSA_R_Q_NOT_PRIME 129 +# define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130 +# define RSA_R_SLEN_CHECK_FAILED 136 +# define RSA_R_SLEN_RECOVERY_FAILED 135 +# define RSA_R_SSLV3_ROLLBACK_ATTACK 115 +# define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 +# define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 +# define RSA_R_UNKNOWN_DIGEST 166 +# define RSA_R_UNKNOWN_MASK_DIGEST 151 +# define RSA_R_UNKNOWN_PADDING_TYPE 118 +# define RSA_R_UNSUPPORTED_ENCRYPTION_TYPE 162 +# define RSA_R_UNSUPPORTED_LABEL_SOURCE 163 +# define RSA_R_UNSUPPORTED_MASK_ALGORITHM 153 +# define RSA_R_UNSUPPORTED_MASK_PARAMETER 154 +# define RSA_R_UNSUPPORTED_SIGNATURE_TYPE 155 +# define RSA_R_VALUE_MISSING 147 +# define RSA_R_WRONG_SIGNATURE_LENGTH 119 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/safestack.h b/android/x86/include/openssl/safestack.h new file mode 100644 index 00000000..9fe733c2 --- /dev/null +++ b/android/x86/include/openssl/safestack.h @@ -0,0 +1,164 @@ +/* + * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SAFESTACK_H +# define HEADER_SAFESTACK_H + +# include <openssl/stack.h> +# include <openssl/e_os2.h> + +#ifdef __cplusplus +extern "C" { +#endif + +# define STACK_OF(type) struct stack_st_##type + +# define SKM_DEFINE_STACK_OF(t1, t2, t3) \ + STACK_OF(t1); \ + typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \ + typedef void (*sk_##t1##_freefunc)(t3 *a); \ + typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \ + static ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \ + { \ + return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \ + } \ + static ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \ + { \ + return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \ + } \ + static ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \ + } \ + static ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \ + } \ + static ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \ + { \ + OPENSSL_sk_free((OPENSSL_STACK *)sk); \ + } \ + static ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \ + { \ + OPENSSL_sk_zero((OPENSSL_STACK *)sk); \ + } \ + static ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \ + { \ + return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \ + } \ + static ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, \ + (const void *)ptr); \ + } \ + static ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \ + { \ + return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \ + } \ + static ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \ + { \ + return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \ + } \ + static ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \ + { \ + OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \ + } \ + static ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \ + { \ + return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \ + } \ + static ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \ + { \ + return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \ + } \ + static ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \ + { \ + OPENSSL_sk_sort((OPENSSL_STACK *)sk); \ + } \ + static ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \ + { \ + return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \ + } \ + static ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \ + } \ + static ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \ + sk_##t1##_copyfunc copyfunc, \ + sk_##t1##_freefunc freefunc) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((const OPENSSL_STACK *)sk, \ + (OPENSSL_sk_copyfunc)copyfunc, \ + (OPENSSL_sk_freefunc)freefunc); \ + } \ + static ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \ + { \ + return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \ + } + +# define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2) +# define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t) +# define DEFINE_SPECIAL_STACK_OF_CONST(t1, t2) \ + SKM_DEFINE_STACK_OF(t1, const t2, t2) +# define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t) + +/*- + * Strings are special: normally an lhash entry will point to a single + * (somewhat) mutable object. In the case of strings: + * + * a) Instead of a single char, there is an array of chars, NUL-terminated. + * b) The string may have be immutable. + * + * So, they need their own declarations. Especially important for + * type-checking tools, such as Deputy. + * + * In practice, however, it appears to be hard to have a const + * string. For now, I'm settling for dealing with the fact it is a + * string at all. + */ +typedef char *OPENSSL_STRING; +typedef const char *OPENSSL_CSTRING; + +/*- + * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but + * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned + * above, instead of a single char each entry is a NUL-terminated array of + * chars. So, we have to implement STRING specially for STACK_OF. This is + * dealt with in the autogenerated macros below. + */ +DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char) +DEFINE_SPECIAL_STACK_OF_CONST(OPENSSL_CSTRING, char) + +/* + * Similarly, we sometimes use a block of characters, NOT nul-terminated. + * These should also be distinguished from "normal" stacks. + */ +typedef void *OPENSSL_BLOCK; +DEFINE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void) + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/seed.h b/android/x86/include/openssl/seed.h new file mode 100644 index 00000000..bb97131d --- /dev/null +++ b/android/x86/include/openssl/seed.h @@ -0,0 +1,98 @@ +/* + * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * Copyright (c) 2007 KISA(Korea Information Security Agency). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Neither the name of author nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef HEADER_SEED_H +# define HEADER_SEED_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_SEED +# include <openssl/e_os2.h> +# include <openssl/crypto.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* look whether we need 'long' to get 32 bits */ +# ifdef AES_LONG +# ifndef SEED_LONG +# define SEED_LONG 1 +# endif +# endif + +# if !defined(NO_SYS_TYPES_H) +# include <sys/types.h> +# endif + +# define SEED_BLOCK_SIZE 16 +# define SEED_KEY_LENGTH 16 + +typedef struct seed_key_st { +# ifdef SEED_LONG + unsigned long data[32]; +# else + unsigned int data[32]; +# endif +} SEED_KEY_SCHEDULE; + +void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], + SEED_KEY_SCHEDULE *ks); + +void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], + unsigned char d[SEED_BLOCK_SIZE], + const SEED_KEY_SCHEDULE *ks); +void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE], + unsigned char d[SEED_BLOCK_SIZE], + const SEED_KEY_SCHEDULE *ks); + +void SEED_ecb_encrypt(const unsigned char *in, unsigned char *out, + const SEED_KEY_SCHEDULE *ks, int enc); +void SEED_cbc_encrypt(const unsigned char *in, unsigned char *out, size_t len, + const SEED_KEY_SCHEDULE *ks, + unsigned char ivec[SEED_BLOCK_SIZE], int enc); +void SEED_cfb128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const SEED_KEY_SCHEDULE *ks, + unsigned char ivec[SEED_BLOCK_SIZE], int *num, + int enc); +void SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const SEED_KEY_SCHEDULE *ks, + unsigned char ivec[SEED_BLOCK_SIZE], int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/sha.h b/android/x86/include/openssl/sha.h new file mode 100644 index 00000000..6a1eb0de --- /dev/null +++ b/android/x86/include/openssl/sha.h @@ -0,0 +1,119 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SHA_H +# define HEADER_SHA_H + +# include <openssl/e_os2.h> +# include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/*- + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! SHA_LONG has to be at least 32 bits wide. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +# define SHA_LONG unsigned int + +# define SHA_LBLOCK 16 +# define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a + * contiguous array of 32 bit wide + * big-endian values. */ +# define SHA_LAST_BLOCK (SHA_CBLOCK-8) +# define SHA_DIGEST_LENGTH 20 + +typedef struct SHAstate_st { + SHA_LONG h0, h1, h2, h3, h4; + SHA_LONG Nl, Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num; +} SHA_CTX; + +int SHA1_Init(SHA_CTX *c); +int SHA1_Update(SHA_CTX *c, const void *data, size_t len); +int SHA1_Final(unsigned char *md, SHA_CTX *c); +unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); +void SHA1_Transform(SHA_CTX *c, const unsigned char *data); + +# define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a + * contiguous array of 32 bit wide + * big-endian values. */ + +typedef struct SHA256state_st { + SHA_LONG h[8]; + SHA_LONG Nl, Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num, md_len; +} SHA256_CTX; + +int SHA224_Init(SHA256_CTX *c); +int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); +int SHA224_Final(unsigned char *md, SHA256_CTX *c); +unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md); +int SHA256_Init(SHA256_CTX *c); +int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); +int SHA256_Final(unsigned char *md, SHA256_CTX *c); +unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); +void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); + +# define SHA224_DIGEST_LENGTH 28 +# define SHA256_DIGEST_LENGTH 32 +# define SHA384_DIGEST_LENGTH 48 +# define SHA512_DIGEST_LENGTH 64 + +/* + * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 + * being exactly 64-bit wide. See Implementation Notes in sha512.c + * for further details. + */ +/* + * SHA-512 treats input data as a + * contiguous array of 64 bit + * wide big-endian values. + */ +# define SHA512_CBLOCK (SHA_LBLOCK*8) +# if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) +# define SHA_LONG64 unsigned __int64 +# define U64(C) C##UI64 +# elif defined(__arch64__) +# define SHA_LONG64 unsigned long +# define U64(C) C##UL +# else +# define SHA_LONG64 unsigned long long +# define U64(C) C##ULL +# endif + +typedef struct SHA512state_st { + SHA_LONG64 h[8]; + SHA_LONG64 Nl, Nh; + union { + SHA_LONG64 d[SHA_LBLOCK]; + unsigned char p[SHA512_CBLOCK]; + } u; + unsigned int num, md_len; +} SHA512_CTX; + +int SHA384_Init(SHA512_CTX *c); +int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); +int SHA384_Final(unsigned char *md, SHA512_CTX *c); +unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md); +int SHA512_Init(SHA512_CTX *c); +int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); +int SHA512_Final(unsigned char *md, SHA512_CTX *c); +unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md); +void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/android/x86/include/openssl/srp.h b/android/x86/include/openssl/srp.h new file mode 100644 index 00000000..f2b6ec75 --- /dev/null +++ b/android/x86/include/openssl/srp.h @@ -0,0 +1,131 @@ +/* + * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SRP_H +# define HEADER_SRP_H + +#include <openssl/opensslconf.h> + +#ifndef OPENSSL_NO_SRP +# include <stdio.h> +# include <string.h> +# include <openssl/safestack.h> +# include <openssl/bn.h> +# include <openssl/crypto.h> + +# ifdef __cplusplus +extern "C" { +# endif + +typedef struct SRP_gN_cache_st { + char *b64_bn; + BIGNUM *bn; +} SRP_gN_cache; + + +DEFINE_STACK_OF(SRP_gN_cache) + +typedef struct SRP_user_pwd_st { + /* Owned by us. */ + char *id; + BIGNUM *s; + BIGNUM *v; + /* Not owned by us. */ + const BIGNUM *g; + const BIGNUM *N; + /* Owned by us. */ + char *info; +} SRP_user_pwd; + +void SRP_user_pwd_free(SRP_user_pwd *user_pwd); + +DEFINE_STACK_OF(SRP_user_pwd) + +typedef struct SRP_VBASE_st { + STACK_OF(SRP_user_pwd) *users_pwd; + STACK_OF(SRP_gN_cache) *gN_cache; +/* to simulate a user */ + char *seed_key; + const BIGNUM *default_g; + const BIGNUM *default_N; +} SRP_VBASE; + +/* + * Internal structure storing N and g pair + */ +typedef struct SRP_gN_st { + char *id; + const BIGNUM *g; + const BIGNUM *N; +} SRP_gN; + +DEFINE_STACK_OF(SRP_gN) + +SRP_VBASE *SRP_VBASE_new(char *seed_key); +void SRP_VBASE_free(SRP_VBASE *vb); +int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file); + +/* This method ignores the configured seed and fails for an unknown user. */ +DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)) +/* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/ +SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username); + +char *SRP_create_verifier(const char *user, const char *pass, char **salt, + char **verifier, const char *N, const char *g); +int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, + BIGNUM **verifier, const BIGNUM *N, + const BIGNUM *g); + +# define SRP_NO_ERROR 0 +# define SRP_ERR_VBASE_INCOMPLETE_FILE 1 +# define SRP_ERR_VBASE_BN_LIB 2 +# define SRP_ERR_OPEN_FILE 3 +# define SRP_ERR_MEMORY 4 + +# define DB_srptype 0 +# define DB_srpverifier 1 +# define DB_srpsalt 2 +# define DB_srpid 3 +# define DB_srpgN 4 +# define DB_srpinfo 5 +# undef DB_NUMBER +# define DB_NUMBER 6 + +# define DB_SRP_INDEX 'I' +# define DB_SRP_VALID 'V' +# define DB_SRP_REVOKED 'R' +# define DB_SRP_MODIF 'v' + +/* see srp.c */ +char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N); +SRP_gN *SRP_get_default_gN(const char *id); + +/* server side .... */ +BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u, + const BIGNUM *b, const BIGNUM *N); +BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g, + const BIGNUM *v); +int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N); +BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N); + +/* client side .... */ +BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass); +BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g); +BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g, + const BIGNUM *x, const BIGNUM *a, const BIGNUM *u); +int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N); + +# define SRP_MINIMAL_N 1024 + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/srtp.h b/android/x86/include/openssl/srtp.h new file mode 100644 index 00000000..5ddfa46d --- /dev/null +++ b/android/x86/include/openssl/srtp.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * DTLS code by Eric Rescorla <ekr@rtfm.com> + * + * Copyright (C) 2006, Network Resonance, Inc. Copyright (C) 2011, RTFM, Inc. + */ + +#ifndef HEADER_D1_SRTP_H +# define HEADER_D1_SRTP_H + +# include <openssl/ssl.h> + +#ifdef __cplusplus +extern "C" { +#endif + +# define SRTP_AES128_CM_SHA1_80 0x0001 +# define SRTP_AES128_CM_SHA1_32 0x0002 +# define SRTP_AES128_F8_SHA1_80 0x0003 +# define SRTP_AES128_F8_SHA1_32 0x0004 +# define SRTP_NULL_SHA1_80 0x0005 +# define SRTP_NULL_SHA1_32 0x0006 + +/* AEAD SRTP protection profiles from RFC 7714 */ +# define SRTP_AEAD_AES_128_GCM 0x0007 +# define SRTP_AEAD_AES_256_GCM 0x0008 + +# ifndef OPENSSL_NO_SRTP + +__owur int SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx, const char *profiles); +__owur int SSL_set_tlsext_use_srtp(SSL *ctx, const char *profiles); + +__owur STACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(SSL *ssl); +__owur SRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(SSL *s); + +# endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/android/x86/include/openssl/ssl.h b/android/x86/include/openssl/ssl.h new file mode 100644 index 00000000..86ab9125 --- /dev/null +++ b/android/x86/include/openssl/ssl.h @@ -0,0 +1,2529 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECC cipher suite support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ +/* ==================================================================== + * Copyright 2005 Nokia. All rights reserved. + * + * The portions of the attached software ("Contribution") is developed by + * Nokia Corporation and is licensed pursuant to the OpenSSL open source + * license. + * + * The Contribution, originally written by Mika Kousa and Pasi Eronen of + * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites + * support (see RFC 4279) to OpenSSL. + * + * No patent licenses or other rights except those expressly stated in + * the OpenSSL open source license shall be deemed granted or received + * expressly, by implication, estoppel, or otherwise. + * + * No assurances are provided by Nokia that the Contribution does not + * infringe the patent or other intellectual property rights of any third + * party or that the license provides you with all the necessary rights + * to make use of the Contribution. + * + * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN + * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA + * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY + * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR + * OTHERWISE. + */ + +#ifndef HEADER_SSL_H +# define HEADER_SSL_H + +# include <openssl/e_os2.h> +# include <openssl/opensslconf.h> +# include <openssl/comp.h> +# include <openssl/bio.h> +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/x509.h> +# include <openssl/crypto.h> +# include <openssl/lhash.h> +# include <openssl/buffer.h> +# endif +# include <openssl/pem.h> +# include <openssl/hmac.h> +# include <openssl/async.h> + +# include <openssl/safestack.h> +# include <openssl/symhacks.h> +# include <openssl/ct.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* OpenSSL version number for ASN.1 encoding of the session information */ +/*- + * Version 0 - initial version + * Version 1 - added the optional peer certificate + */ +# define SSL_SESSION_ASN1_VERSION 0x0001 + +# define SSL_MAX_SSL_SESSION_ID_LENGTH 32 +# define SSL_MAX_SID_CTX_LENGTH 32 + +# define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8) +# define SSL_MAX_KEY_ARG_LENGTH 8 +# define SSL_MAX_MASTER_KEY_LENGTH 48 + +/* The maximum number of encrypt/decrypt pipelines we can support */ +# define SSL_MAX_PIPELINES 32 + +/* text strings for the ciphers */ + +/* These are used to specify which ciphers to use and not to use */ + +# define SSL_TXT_LOW "LOW" +# define SSL_TXT_MEDIUM "MEDIUM" +# define SSL_TXT_HIGH "HIGH" +# define SSL_TXT_FIPS "FIPS" + +# define SSL_TXT_aNULL "aNULL" +# define SSL_TXT_eNULL "eNULL" +# define SSL_TXT_NULL "NULL" + +# define SSL_TXT_kRSA "kRSA" +# define SSL_TXT_kDHr "kDHr" +# define SSL_TXT_kDHd "kDHd" +# define SSL_TXT_kDH "kDH" +# define SSL_TXT_kEDH "kEDH"/* alias for kDHE */ +# define SSL_TXT_kDHE "kDHE" +# define SSL_TXT_kECDHr "kECDHr" +# define SSL_TXT_kECDHe "kECDHe" +# define SSL_TXT_kECDH "kECDH" +# define SSL_TXT_kEECDH "kEECDH"/* alias for kECDHE */ +# define SSL_TXT_kECDHE "kECDHE" +# define SSL_TXT_kPSK "kPSK" +# define SSL_TXT_kRSAPSK "kRSAPSK" +# define SSL_TXT_kECDHEPSK "kECDHEPSK" +# define SSL_TXT_kDHEPSK "kDHEPSK" +# define SSL_TXT_kGOST "kGOST" +# define SSL_TXT_kSRP "kSRP" + +# define SSL_TXT_aRSA "aRSA" +# define SSL_TXT_aDSS "aDSS" +# define SSL_TXT_aDH "aDH" +# define SSL_TXT_aECDH "aECDH" +# define SSL_TXT_aECDSA "aECDSA" +# define SSL_TXT_aPSK "aPSK" +# define SSL_TXT_aGOST94 "aGOST94" +# define SSL_TXT_aGOST01 "aGOST01" +# define SSL_TXT_aGOST12 "aGOST12" +# define SSL_TXT_aGOST "aGOST" +# define SSL_TXT_aSRP "aSRP" + +# define SSL_TXT_DSS "DSS" +# define SSL_TXT_DH "DH" +# define SSL_TXT_DHE "DHE"/* same as "kDHE:-ADH" */ +# define SSL_TXT_EDH "EDH"/* alias for DHE */ +# define SSL_TXT_ADH "ADH" +# define SSL_TXT_RSA "RSA" +# define SSL_TXT_ECDH "ECDH" +# define SSL_TXT_EECDH "EECDH"/* alias for ECDHE" */ +# define SSL_TXT_ECDHE "ECDHE"/* same as "kECDHE:-AECDH" */ +# define SSL_TXT_AECDH "AECDH" +# define SSL_TXT_ECDSA "ECDSA" +# define SSL_TXT_PSK "PSK" +# define SSL_TXT_SRP "SRP" + +# define SSL_TXT_DES "DES" +# define SSL_TXT_3DES "3DES" +# define SSL_TXT_RC4 "RC4" +# define SSL_TXT_RC2 "RC2" +# define SSL_TXT_IDEA "IDEA" +# define SSL_TXT_SEED "SEED" +# define SSL_TXT_AES128 "AES128" +# define SSL_TXT_AES256 "AES256" +# define SSL_TXT_AES "AES" +# define SSL_TXT_AES_GCM "AESGCM" +# define SSL_TXT_AES_CCM "AESCCM" +# define SSL_TXT_AES_CCM_8 "AESCCM8" +# define SSL_TXT_CAMELLIA128 "CAMELLIA128" +# define SSL_TXT_CAMELLIA256 "CAMELLIA256" +# define SSL_TXT_CAMELLIA "CAMELLIA" +# define SSL_TXT_CHACHA20 "CHACHA20" +# define SSL_TXT_GOST "GOST89" + +# define SSL_TXT_MD5 "MD5" +# define SSL_TXT_SHA1 "SHA1" +# define SSL_TXT_SHA "SHA"/* same as "SHA1" */ +# define SSL_TXT_GOST94 "GOST94" +# define SSL_TXT_GOST89MAC "GOST89MAC" +# define SSL_TXT_GOST12 "GOST12" +# define SSL_TXT_GOST89MAC12 "GOST89MAC12" +# define SSL_TXT_SHA256 "SHA256" +# define SSL_TXT_SHA384 "SHA384" + +# define SSL_TXT_SSLV3 "SSLv3" +# define SSL_TXT_TLSV1 "TLSv1" +# define SSL_TXT_TLSV1_1 "TLSv1.1" +# define SSL_TXT_TLSV1_2 "TLSv1.2" + +# define SSL_TXT_ALL "ALL" + +/*- + * COMPLEMENTOF* definitions. These identifiers are used to (de-select) + * ciphers normally not being used. + * Example: "RC4" will activate all ciphers using RC4 including ciphers + * without authentication, which would normally disabled by DEFAULT (due + * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT" + * will make sure that it is also disabled in the specific selection. + * COMPLEMENTOF* identifiers are portable between version, as adjustments + * to the default cipher setup will also be included here. + * + * COMPLEMENTOFDEFAULT does not experience the same special treatment that + * DEFAULT gets, as only selection is being done and no sorting as needed + * for DEFAULT. + */ +# define SSL_TXT_CMPALL "COMPLEMENTOFALL" +# define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT" + +/* + * The following cipher list is used by default. It also is substituted when + * an application-defined cipher list string starts with 'DEFAULT'. + */ +# define SSL_DEFAULT_CIPHER_LIST "ALL:!COMPLEMENTOFDEFAULT:!eNULL" +/* + * As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always + * starts with a reasonable order, and all we have to do for DEFAULT is + * throwing out anonymous and unencrypted ciphersuites! (The latter are not + * actually enabled by ALL, but "ALL:RSA" would enable some of them.) + */ + +/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ +# define SSL_SENT_SHUTDOWN 1 +# define SSL_RECEIVED_SHUTDOWN 2 + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +# define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 +# define SSL_FILETYPE_PEM X509_FILETYPE_PEM + +/* + * This is needed to stop compilers complaining about the 'struct ssl_st *' + * function parameters used to prototype callbacks in SSL_CTX. + */ +typedef struct ssl_st *ssl_crock_st; +typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT; +typedef struct ssl_method_st SSL_METHOD; +typedef struct ssl_cipher_st SSL_CIPHER; +typedef struct ssl_session_st SSL_SESSION; +typedef struct tls_sigalgs_st TLS_SIGALGS; +typedef struct ssl_conf_ctx_st SSL_CONF_CTX; +typedef struct ssl_comp_st SSL_COMP; + +STACK_OF(SSL_CIPHER); +STACK_OF(SSL_COMP); + +/* SRTP protection profiles for use with the use_srtp extension (RFC 5764)*/ +typedef struct srtp_protection_profile_st { + const char *name; + unsigned long id; +} SRTP_PROTECTION_PROFILE; + +DEFINE_STACK_OF(SRTP_PROTECTION_PROFILE) + +typedef int (*tls_session_ticket_ext_cb_fn) (SSL *s, + const unsigned char *data, + int len, void *arg); +typedef int (*tls_session_secret_cb_fn) (SSL *s, void *secret, + int *secret_len, + STACK_OF(SSL_CIPHER) *peer_ciphers, + const SSL_CIPHER **cipher, void *arg); + +/* Typedefs for handling custom extensions */ + +typedef int (*custom_ext_add_cb) (SSL *s, unsigned int ext_type, + const unsigned char **out, + size_t *outlen, int *al, void *add_arg); + +typedef void (*custom_ext_free_cb) (SSL *s, unsigned int ext_type, + const unsigned char *out, void *add_arg); + +typedef int (*custom_ext_parse_cb) (SSL *s, unsigned int ext_type, + const unsigned char *in, + size_t inlen, int *al, void *parse_arg); + +/* Allow initial connection to servers that don't support RI */ +# define SSL_OP_LEGACY_SERVER_CONNECT 0x00000004U +/* Removed from OpenSSL 0.9.8q and 1.0.0c */ +/* Dead forever, see CVE-2010-4180. */ +# define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x0U +# define SSL_OP_TLSEXT_PADDING 0x00000010U +# define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x0U +# define SSL_OP_SAFARI_ECDHE_ECDSA_BUG 0x00000040U +/* Ancient SSLeay version, retained for compatibility */ +# define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x0 +# define SSL_OP_TLS_D5_BUG 0x0U +/* Removed from OpenSSL 1.1.0 */ +# define SSL_OP_TLS_BLOCK_PADDING_BUG 0x0U + +/* Hasn't done anything since OpenSSL 0.9.7h, retained for compatibility */ +# define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x0 +/* Refers to ancient SSLREF and SSLv2, retained for compatibility */ +# define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x0 +/* Related to removed SSLv2 */ +# define SSL_OP_MICROSOFT_SESS_ID_BUG 0x0 +# define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x0 + +/* + * Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added in + * OpenSSL 0.9.6d. Usually (depending on the application protocol) the + * workaround is not needed. Unfortunately some broken SSL/TLS + * implementations cannot handle it at all, which is why we include it in + * SSL_OP_ALL. + */ +/* added in 0.9.6e */ +# define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x00000800U + +/* + * SSL_OP_ALL: various bug workarounds that should be rather harmless. This + * used to be 0x000FFFFFL before 0.9.7. + */ +# define SSL_OP_ALL 0x80000BFFU + +/* DTLS options */ +# define SSL_OP_NO_QUERY_MTU 0x00001000U +/* Turn on Cookie Exchange (on relevant for servers) */ +# define SSL_OP_COOKIE_EXCHANGE 0x00002000U +/* Don't use RFC4507 ticket extension */ +# define SSL_OP_NO_TICKET 0x00004000U +# ifndef OPENSSL_NO_DTLS1_METHOD +/* Use Cisco's "speshul" version of DTLS_BAD_VER + * (only with deprecated DTLSv1_client_method()) */ +# define SSL_OP_CISCO_ANYCONNECT 0x00008000U +# endif + +/* As server, disallow session resumption on renegotiation */ +# define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000U +/* Don't use compression even if supported */ +# define SSL_OP_NO_COMPRESSION 0x00020000U +/* Permit unsafe legacy renegotiation */ +# define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION 0x00040000U +/* Does nothing: retained for compatibility */ +# define SSL_OP_SINGLE_ECDH_USE 0x0 +/* Does nothing: retained for compatibility */ +# define SSL_OP_SINGLE_DH_USE 0x0 +/* Does nothing: retained for compatibility */ +# define SSL_OP_EPHEMERAL_RSA 0x0 +/* + * Set on servers to choose the cipher according to the server's preferences + */ +# define SSL_OP_CIPHER_SERVER_PREFERENCE 0x00400000U +/* + * If set, a server will allow a client to issue a SSLv3.0 version number as + * latest version supported in the premaster secret, even when TLSv1.0 + * (version 3.1) was announced in the client hello. Normally this is + * forbidden to prevent version rollback attacks. + */ +# define SSL_OP_TLS_ROLLBACK_BUG 0x00800000U + +# define SSL_OP_NO_SSLv2 0x00000000U +# define SSL_OP_NO_SSLv3 0x02000000U +# define SSL_OP_NO_TLSv1 0x04000000U +# define SSL_OP_NO_TLSv1_2 0x08000000U +# define SSL_OP_NO_TLSv1_1 0x10000000U + +# define SSL_OP_NO_DTLSv1 0x04000000U +# define SSL_OP_NO_DTLSv1_2 0x08000000U + +# define SSL_OP_NO_SSL_MASK (SSL_OP_NO_SSLv3|\ + SSL_OP_NO_TLSv1|SSL_OP_NO_TLSv1_1|SSL_OP_NO_TLSv1_2) +# define SSL_OP_NO_DTLS_MASK (SSL_OP_NO_DTLSv1|SSL_OP_NO_DTLSv1_2) + + +/* Removed from previous versions */ +# define SSL_OP_PKCS1_CHECK_1 0x0 +# define SSL_OP_PKCS1_CHECK_2 0x0 +# define SSL_OP_NETSCAPE_CA_DN_BUG 0x0 +# define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x0U +/* + * Make server add server-hello extension from early version of cryptopro + * draft, when GOST ciphersuite is negotiated. Required for interoperability + * with CryptoPro CSP 3.x + */ +# define SSL_OP_CRYPTOPRO_TLSEXT_BUG 0x80000000U + +/* + * Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success + * when just a single record has been written): + */ +# define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001U +/* + * Make it possible to retry SSL_write() with changed buffer location (buffer + * contents must stay the same!); this is not the default to avoid the + * misconception that non-blocking SSL_write() behaves like non-blocking + * write(): + */ +# define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002U +/* + * Never bother the application with retries if the transport is blocking: + */ +# define SSL_MODE_AUTO_RETRY 0x00000004U +/* Don't attempt to automatically build certificate chain */ +# define SSL_MODE_NO_AUTO_CHAIN 0x00000008U +/* + * Save RAM by releasing read and write buffers when they're empty. (SSL3 and + * TLS only.) "Released" buffers are put onto a free-list in the context or + * just freed (depending on the context's setting for freelist_max_len). + */ +# define SSL_MODE_RELEASE_BUFFERS 0x00000010U +/* + * Send the current time in the Random fields of the ClientHello and + * ServerHello records for compatibility with hypothetical implementations + * that require it. + */ +# define SSL_MODE_SEND_CLIENTHELLO_TIME 0x00000020U +# define SSL_MODE_SEND_SERVERHELLO_TIME 0x00000040U +/* + * Send TLS_FALLBACK_SCSV in the ClientHello. To be set only by applications + * that reconnect with a downgraded protocol version; see + * draft-ietf-tls-downgrade-scsv-00 for details. DO NOT ENABLE THIS if your + * application attempts a normal handshake. Only use this in explicit + * fallback retries, following the guidance in + * draft-ietf-tls-downgrade-scsv-00. + */ +# define SSL_MODE_SEND_FALLBACK_SCSV 0x00000080U +/* + * Support Asynchronous operation + */ +# define SSL_MODE_ASYNC 0x00000100U + +/* Cert related flags */ +/* + * Many implementations ignore some aspects of the TLS standards such as + * enforcing certificate chain algorithms. When this is set we enforce them. + */ +# define SSL_CERT_FLAG_TLS_STRICT 0x00000001U + +/* Suite B modes, takes same values as certificate verify flags */ +# define SSL_CERT_FLAG_SUITEB_128_LOS_ONLY 0x10000 +/* Suite B 192 bit only mode */ +# define SSL_CERT_FLAG_SUITEB_192_LOS 0x20000 +/* Suite B 128 bit mode allowing 192 bit algorithms */ +# define SSL_CERT_FLAG_SUITEB_128_LOS 0x30000 + +/* Perform all sorts of protocol violations for testing purposes */ +# define SSL_CERT_FLAG_BROKEN_PROTOCOL 0x10000000 + +/* Flags for building certificate chains */ +/* Treat any existing certificates as untrusted CAs */ +# define SSL_BUILD_CHAIN_FLAG_UNTRUSTED 0x1 +/* Don't include root CA in chain */ +# define SSL_BUILD_CHAIN_FLAG_NO_ROOT 0x2 +/* Just check certificates already there */ +# define SSL_BUILD_CHAIN_FLAG_CHECK 0x4 +/* Ignore verification errors */ +# define SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR 0x8 +/* Clear verification errors from queue */ +# define SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR 0x10 + +/* Flags returned by SSL_check_chain */ +/* Certificate can be used with this session */ +# define CERT_PKEY_VALID 0x1 +/* Certificate can also be used for signing */ +# define CERT_PKEY_SIGN 0x2 +/* EE certificate signing algorithm OK */ +# define CERT_PKEY_EE_SIGNATURE 0x10 +/* CA signature algorithms OK */ +# define CERT_PKEY_CA_SIGNATURE 0x20 +/* EE certificate parameters OK */ +# define CERT_PKEY_EE_PARAM 0x40 +/* CA certificate parameters OK */ +# define CERT_PKEY_CA_PARAM 0x80 +/* Signing explicitly allowed as opposed to SHA1 fallback */ +# define CERT_PKEY_EXPLICIT_SIGN 0x100 +/* Client CA issuer names match (always set for server cert) */ +# define CERT_PKEY_ISSUER_NAME 0x200 +/* Cert type matches client types (always set for server cert) */ +# define CERT_PKEY_CERT_TYPE 0x400 +/* Cert chain suitable to Suite B */ +# define CERT_PKEY_SUITEB 0x800 + +# define SSL_CONF_FLAG_CMDLINE 0x1 +# define SSL_CONF_FLAG_FILE 0x2 +# define SSL_CONF_FLAG_CLIENT 0x4 +# define SSL_CONF_FLAG_SERVER 0x8 +# define SSL_CONF_FLAG_SHOW_ERRORS 0x10 +# define SSL_CONF_FLAG_CERTIFICATE 0x20 +# define SSL_CONF_FLAG_REQUIRE_PRIVATE 0x40 +/* Configuration value types */ +# define SSL_CONF_TYPE_UNKNOWN 0x0 +# define SSL_CONF_TYPE_STRING 0x1 +# define SSL_CONF_TYPE_FILE 0x2 +# define SSL_CONF_TYPE_DIR 0x3 +# define SSL_CONF_TYPE_NONE 0x4 + +/* + * Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, they + * cannot be used to clear bits. + */ + +unsigned long SSL_CTX_get_options(const SSL_CTX *ctx); +unsigned long SSL_get_options(const SSL* s); +unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op); +unsigned long SSL_clear_options(SSL *s, unsigned long op); +unsigned long SSL_CTX_set_options(SSL_CTX *ctx, unsigned long op); +unsigned long SSL_set_options(SSL *s, unsigned long op); + +# define SSL_CTX_set_mode(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL) +# define SSL_CTX_clear_mode(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_MODE,(op),NULL) +# define SSL_CTX_get_mode(ctx) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL) +# define SSL_clear_mode(ssl,op) \ + SSL_ctrl((ssl),SSL_CTRL_CLEAR_MODE,(op),NULL) +# define SSL_set_mode(ssl,op) \ + SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL) +# define SSL_get_mode(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL) +# define SSL_set_mtu(ssl, mtu) \ + SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL) +# define DTLS_set_link_mtu(ssl, mtu) \ + SSL_ctrl((ssl),DTLS_CTRL_SET_LINK_MTU,(mtu),NULL) +# define DTLS_get_link_min_mtu(ssl) \ + SSL_ctrl((ssl),DTLS_CTRL_GET_LINK_MIN_MTU,0,NULL) + +# define SSL_get_secure_renegotiation_support(ssl) \ + SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL) + +# ifndef OPENSSL_NO_HEARTBEATS +# define SSL_heartbeat(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT,0,NULL) +# endif + +# define SSL_CTX_set_cert_flags(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_CERT_FLAGS,(op),NULL) +# define SSL_set_cert_flags(s,op) \ + SSL_ctrl((s),SSL_CTRL_CERT_FLAGS,(op),NULL) +# define SSL_CTX_clear_cert_flags(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL) +# define SSL_clear_cert_flags(s,op) \ + SSL_ctrl((s),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL) + +void SSL_CTX_set_msg_callback(SSL_CTX *ctx, + void (*cb) (int write_p, int version, + int content_type, const void *buf, + size_t len, SSL *ssl, void *arg)); +void SSL_set_msg_callback(SSL *ssl, + void (*cb) (int write_p, int version, + int content_type, const void *buf, + size_t len, SSL *ssl, void *arg)); +# define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) +# define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) + +# define SSL_get_extms_support(s) \ + SSL_ctrl((s),SSL_CTRL_GET_EXTMS_SUPPORT,0,NULL) + +# ifndef OPENSSL_NO_SRP + +/* see tls_srp.c */ +__owur int SSL_SRP_CTX_init(SSL *s); +__owur int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx); +int SSL_SRP_CTX_free(SSL *ctx); +int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx); +__owur int SSL_srp_server_param_with_username(SSL *s, int *ad); +__owur int SRP_Calc_A_param(SSL *s); + +# endif + +/* 100k max cert list */ +# define SSL_MAX_CERT_LIST_DEFAULT 1024*100 + +# define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20) + +/* + * This callback type is used inside SSL_CTX, SSL, and in the functions that + * set them. It is used to override the generation of SSL/TLS session IDs in + * a server. Return value should be zero on an error, non-zero to proceed. + * Also, callbacks should themselves check if the id they generate is unique + * otherwise the SSL handshake will fail with an error - callbacks can do + * this using the 'ssl' value they're passed by; + * SSL_has_matching_session_id(ssl, id, *id_len) The length value passed in + * is set at the maximum size the session ID can be. In SSLv3/TLSv1 it is 32 + * bytes. The callback can alter this length to be less if desired. It is + * also an error for the callback to set the size to zero. + */ +typedef int (*GEN_SESSION_CB) (const SSL *ssl, unsigned char *id, + unsigned int *id_len); + +# define SSL_SESS_CACHE_OFF 0x0000 +# define SSL_SESS_CACHE_CLIENT 0x0001 +# define SSL_SESS_CACHE_SERVER 0x0002 +# define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER) +# define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 +/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */ +# define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 +# define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200 +# define SSL_SESS_CACHE_NO_INTERNAL \ + (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE) + +LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx); +# define SSL_CTX_sess_number(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL) +# define SSL_CTX_sess_connect(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL) +# define SSL_CTX_sess_connect_good(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL) +# define SSL_CTX_sess_connect_renegotiate(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL) +# define SSL_CTX_sess_accept(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL) +# define SSL_CTX_sess_accept_renegotiate(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL) +# define SSL_CTX_sess_accept_good(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL) +# define SSL_CTX_sess_hits(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL) +# define SSL_CTX_sess_cb_hits(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL) +# define SSL_CTX_sess_misses(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL) +# define SSL_CTX_sess_timeouts(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL) +# define SSL_CTX_sess_cache_full(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL) + +void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx, + int (*new_session_cb) (struct ssl_st *ssl, + SSL_SESSION *sess)); +int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (struct ssl_st *ssl, + SSL_SESSION *sess); +void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx, + void (*remove_session_cb) (struct ssl_ctx_st + *ctx, + SSL_SESSION + *sess)); +void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (struct ssl_ctx_st *ctx, + SSL_SESSION *sess); +void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, + SSL_SESSION *(*get_session_cb) (struct ssl_st + *ssl, + const unsigned char + *data, int len, + int *copy)); +SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (struct ssl_st *ssl, + const unsigned char *data, + int len, int *copy); +void SSL_CTX_set_info_callback(SSL_CTX *ctx, + void (*cb) (const SSL *ssl, int type, + int val)); +void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type, + int val); +void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, + int (*client_cert_cb) (SSL *ssl, X509 **x509, + EVP_PKEY **pkey)); +int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509, + EVP_PKEY **pkey); +# ifndef OPENSSL_NO_ENGINE +__owur int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e); +# endif +void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, + int (*app_gen_cookie_cb) (SSL *ssl, + unsigned char + *cookie, + unsigned int + *cookie_len)); +void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, + int (*app_verify_cookie_cb) (SSL *ssl, + const unsigned char + *cookie, + unsigned int + cookie_len)); +# ifndef OPENSSL_NO_NEXTPROTONEG +void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s, + int (*cb) (SSL *ssl, + const unsigned char + **out, + unsigned int *outlen, + void *arg), void *arg); +void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s, + int (*cb) (SSL *ssl, + unsigned char **out, + unsigned char *outlen, + const unsigned char *in, + unsigned int inlen, + void *arg), void *arg); +void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, + unsigned *len); +# endif + +__owur int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, + const unsigned char *in, unsigned int inlen, + const unsigned char *client, + unsigned int client_len); + +# define OPENSSL_NPN_UNSUPPORTED 0 +# define OPENSSL_NPN_NEGOTIATED 1 +# define OPENSSL_NPN_NO_OVERLAP 2 + +__owur int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos, + unsigned int protos_len); +__owur int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos, + unsigned int protos_len); +void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, + int (*cb) (SSL *ssl, + const unsigned char **out, + unsigned char *outlen, + const unsigned char *in, + unsigned int inlen, + void *arg), void *arg); +void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data, + unsigned int *len); + +# ifndef OPENSSL_NO_PSK +/* + * the maximum length of the buffer given to callbacks containing the + * resulting identity/psk + */ +# define PSK_MAX_IDENTITY_LEN 128 +# define PSK_MAX_PSK_LEN 256 +void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, + unsigned int (*psk_client_callback) (SSL + *ssl, + const + char + *hint, + char + *identity, + unsigned + int + max_identity_len, + unsigned + char + *psk, + unsigned + int + max_psk_len)); +void SSL_set_psk_client_callback(SSL *ssl, + unsigned int (*psk_client_callback) (SSL + *ssl, + const + char + *hint, + char + *identity, + unsigned + int + max_identity_len, + unsigned + char + *psk, + unsigned + int + max_psk_len)); +void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, + unsigned int (*psk_server_callback) (SSL + *ssl, + const + char + *identity, + unsigned + char + *psk, + unsigned + int + max_psk_len)); +void SSL_set_psk_server_callback(SSL *ssl, + unsigned int (*psk_server_callback) (SSL + *ssl, + const + char + *identity, + unsigned + char + *psk, + unsigned + int + max_psk_len)); +__owur int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint); +__owur int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint); +const char *SSL_get_psk_identity_hint(const SSL *s); +const char *SSL_get_psk_identity(const SSL *s); +# endif + +/* Register callbacks to handle custom TLS Extensions for client or server. */ + +__owur int SSL_CTX_has_client_custom_ext(const SSL_CTX *ctx, + unsigned int ext_type); + +__owur int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx, unsigned int ext_type, + custom_ext_add_cb add_cb, + custom_ext_free_cb free_cb, + void *add_arg, + custom_ext_parse_cb parse_cb, + void *parse_arg); + +__owur int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx, unsigned int ext_type, + custom_ext_add_cb add_cb, + custom_ext_free_cb free_cb, + void *add_arg, + custom_ext_parse_cb parse_cb, + void *parse_arg); + +__owur int SSL_extension_supported(unsigned int ext_type); + +# define SSL_NOTHING 1 +# define SSL_WRITING 2 +# define SSL_READING 3 +# define SSL_X509_LOOKUP 4 +# define SSL_ASYNC_PAUSED 5 +# define SSL_ASYNC_NO_JOBS 6 + +/* These will only be used when doing non-blocking IO */ +# define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING) +# define SSL_want_read(s) (SSL_want(s) == SSL_READING) +# define SSL_want_write(s) (SSL_want(s) == SSL_WRITING) +# define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP) +# define SSL_want_async(s) (SSL_want(s) == SSL_ASYNC_PAUSED) +# define SSL_want_async_job(s) (SSL_want(s) == SSL_ASYNC_NO_JOBS) + +# define SSL_MAC_FLAG_READ_MAC_STREAM 1 +# define SSL_MAC_FLAG_WRITE_MAC_STREAM 2 + +#ifdef __cplusplus +} +#endif + +# include <openssl/ssl2.h> +# include <openssl/ssl3.h> +# include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */ +# include <openssl/dtls1.h> /* Datagram TLS */ +# include <openssl/srtp.h> /* Support for the use_srtp extension */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * These need to be after the above set of includes due to a compiler bug + * in VisualStudio 2015 + */ +DEFINE_STACK_OF_CONST(SSL_CIPHER) +DEFINE_STACK_OF(SSL_COMP) + +/* compatibility */ +# define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg)) +# define SSL_get_app_data(s) (SSL_get_ex_data(s,0)) +# define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a)) +# define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0)) +# define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0)) +# define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg)) +DEPRECATEDIN_1_1_0(void SSL_set_debug(SSL *s, int debug)) + + +/* + * The valid handshake states (one for each type message sent and one for each + * type of message received). There are also two "special" states: + * TLS = TLS or DTLS state + * DTLS = DTLS specific state + * CR/SR = Client Read/Server Read + * CW/SW = Client Write/Server Write + * + * The "special" states are: + * TLS_ST_BEFORE = No handshake has been initiated yet + * TLS_ST_OK = A handshake has been successfully completed + */ +typedef enum { + TLS_ST_BEFORE, + TLS_ST_OK, + DTLS_ST_CR_HELLO_VERIFY_REQUEST, + TLS_ST_CR_SRVR_HELLO, + TLS_ST_CR_CERT, + TLS_ST_CR_CERT_STATUS, + TLS_ST_CR_KEY_EXCH, + TLS_ST_CR_CERT_REQ, + TLS_ST_CR_SRVR_DONE, + TLS_ST_CR_SESSION_TICKET, + TLS_ST_CR_CHANGE, + TLS_ST_CR_FINISHED, + TLS_ST_CW_CLNT_HELLO, + TLS_ST_CW_CERT, + TLS_ST_CW_KEY_EXCH, + TLS_ST_CW_CERT_VRFY, + TLS_ST_CW_CHANGE, + TLS_ST_CW_NEXT_PROTO, + TLS_ST_CW_FINISHED, + TLS_ST_SW_HELLO_REQ, + TLS_ST_SR_CLNT_HELLO, + DTLS_ST_SW_HELLO_VERIFY_REQUEST, + TLS_ST_SW_SRVR_HELLO, + TLS_ST_SW_CERT, + TLS_ST_SW_KEY_EXCH, + TLS_ST_SW_CERT_REQ, + TLS_ST_SW_SRVR_DONE, + TLS_ST_SR_CERT, + TLS_ST_SR_KEY_EXCH, + TLS_ST_SR_CERT_VRFY, + TLS_ST_SR_NEXT_PROTO, + TLS_ST_SR_CHANGE, + TLS_ST_SR_FINISHED, + TLS_ST_SW_SESSION_TICKET, + TLS_ST_SW_CERT_STATUS, + TLS_ST_SW_CHANGE, + TLS_ST_SW_FINISHED +} OSSL_HANDSHAKE_STATE; + +/* + * Most of the following state values are no longer used and are defined to be + * the closest equivalent value in the current state machine code. Not all + * defines have an equivalent and are set to a dummy value (-1). SSL_ST_CONNECT + * and SSL_ST_ACCEPT are still in use in the definition of SSL_CB_ACCEPT_LOOP, + * SSL_CB_ACCEPT_EXIT, SSL_CB_CONNECT_LOOP and SSL_CB_CONNECT_EXIT. + */ + +# define SSL_ST_CONNECT 0x1000 +# define SSL_ST_ACCEPT 0x2000 + +# define SSL_ST_MASK 0x0FFF + +# define SSL_CB_LOOP 0x01 +# define SSL_CB_EXIT 0x02 +# define SSL_CB_READ 0x04 +# define SSL_CB_WRITE 0x08 +# define SSL_CB_ALERT 0x4000/* used in callback */ +# define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ) +# define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE) +# define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP) +# define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT) +# define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP) +# define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT) +# define SSL_CB_HANDSHAKE_START 0x10 +# define SSL_CB_HANDSHAKE_DONE 0x20 + +/* Is the SSL_connection established? */ +# define SSL_in_connect_init(a) (SSL_in_init(a) && !SSL_is_server(a)) +# define SSL_in_accept_init(a) (SSL_in_init(a) && SSL_is_server(a)) +int SSL_in_init(SSL *s); +int SSL_in_before(SSL *s); +int SSL_is_init_finished(SSL *s); + +/* + * The following 3 states are kept in ssl->rlayer.rstate when reads fail, you + * should not need these + */ +# define SSL_ST_READ_HEADER 0xF0 +# define SSL_ST_READ_BODY 0xF1 +# define SSL_ST_READ_DONE 0xF2 + +/*- + * Obtain latest Finished message + * -- that we sent (SSL_get_finished) + * -- that we expected from peer (SSL_get_peer_finished). + * Returns length (0 == no Finished so far), copies up to 'count' bytes. + */ +size_t SSL_get_finished(const SSL *s, void *buf, size_t count); +size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); + +/* + * use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options are + * 'ored' with SSL_VERIFY_PEER if they are desired + */ +# define SSL_VERIFY_NONE 0x00 +# define SSL_VERIFY_PEER 0x01 +# define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 +# define SSL_VERIFY_CLIENT_ONCE 0x04 + +# define OpenSSL_add_ssl_algorithms() SSL_library_init() +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSLeay_add_ssl_algorithms() SSL_library_init() +# endif + +/* More backward compatibility */ +# define SSL_get_cipher(s) \ + SSL_CIPHER_get_name(SSL_get_current_cipher(s)) +# define SSL_get_cipher_bits(s,np) \ + SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np) +# define SSL_get_cipher_version(s) \ + SSL_CIPHER_get_version(SSL_get_current_cipher(s)) +# define SSL_get_cipher_name(s) \ + SSL_CIPHER_get_name(SSL_get_current_cipher(s)) +# define SSL_get_time(a) SSL_SESSION_get_time(a) +# define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b)) +# define SSL_get_timeout(a) SSL_SESSION_get_timeout(a) +# define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b)) + +# define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id) +# define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id) + +DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION) +# define SSL_AD_REASON_OFFSET 1000/* offset to get SSL_R_... value + * from SSL_AD_... */ +/* These alert types are for SSLv3 and TLSv1 */ +# define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY +/* fatal */ +# define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE +/* fatal */ +# define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC +# define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED +# define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW +/* fatal */ +# define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE +/* fatal */ +# define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE +/* Not for TLS */ +# define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE +# define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE +# define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE +# define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED +# define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED +# define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN +/* fatal */ +# define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER +/* fatal */ +# define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA +/* fatal */ +# define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED +/* fatal */ +# define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR +# define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR +/* fatal */ +# define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION +/* fatal */ +# define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION +/* fatal */ +# define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY +/* fatal */ +# define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR +# define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED +# define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION +# define SSL_AD_UNSUPPORTED_EXTENSION TLS1_AD_UNSUPPORTED_EXTENSION +# define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE +# define SSL_AD_UNRECOGNIZED_NAME TLS1_AD_UNRECOGNIZED_NAME +# define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE +# define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE +/* fatal */ +# define SSL_AD_UNKNOWN_PSK_IDENTITY TLS1_AD_UNKNOWN_PSK_IDENTITY +/* fatal */ +# define SSL_AD_INAPPROPRIATE_FALLBACK TLS1_AD_INAPPROPRIATE_FALLBACK +# define SSL_AD_NO_APPLICATION_PROTOCOL TLS1_AD_NO_APPLICATION_PROTOCOL +# define SSL_ERROR_NONE 0 +# define SSL_ERROR_SSL 1 +# define SSL_ERROR_WANT_READ 2 +# define SSL_ERROR_WANT_WRITE 3 +# define SSL_ERROR_WANT_X509_LOOKUP 4 +# define SSL_ERROR_SYSCALL 5/* look at error stack/return + * value/errno */ +# define SSL_ERROR_ZERO_RETURN 6 +# define SSL_ERROR_WANT_CONNECT 7 +# define SSL_ERROR_WANT_ACCEPT 8 +# define SSL_ERROR_WANT_ASYNC 9 +# define SSL_ERROR_WANT_ASYNC_JOB 10 +# define SSL_CTRL_SET_TMP_DH 3 +# define SSL_CTRL_SET_TMP_ECDH 4 +# define SSL_CTRL_SET_TMP_DH_CB 6 +# define SSL_CTRL_GET_CLIENT_CERT_REQUEST 9 +# define SSL_CTRL_GET_NUM_RENEGOTIATIONS 10 +# define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 11 +# define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 12 +# define SSL_CTRL_GET_FLAGS 13 +# define SSL_CTRL_EXTRA_CHAIN_CERT 14 +# define SSL_CTRL_SET_MSG_CALLBACK 15 +# define SSL_CTRL_SET_MSG_CALLBACK_ARG 16 +/* only applies to datagram connections */ +# define SSL_CTRL_SET_MTU 17 +/* Stats */ +# define SSL_CTRL_SESS_NUMBER 20 +# define SSL_CTRL_SESS_CONNECT 21 +# define SSL_CTRL_SESS_CONNECT_GOOD 22 +# define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23 +# define SSL_CTRL_SESS_ACCEPT 24 +# define SSL_CTRL_SESS_ACCEPT_GOOD 25 +# define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26 +# define SSL_CTRL_SESS_HIT 27 +# define SSL_CTRL_SESS_CB_HIT 28 +# define SSL_CTRL_SESS_MISSES 29 +# define SSL_CTRL_SESS_TIMEOUTS 30 +# define SSL_CTRL_SESS_CACHE_FULL 31 +# define SSL_CTRL_MODE 33 +# define SSL_CTRL_GET_READ_AHEAD 40 +# define SSL_CTRL_SET_READ_AHEAD 41 +# define SSL_CTRL_SET_SESS_CACHE_SIZE 42 +# define SSL_CTRL_GET_SESS_CACHE_SIZE 43 +# define SSL_CTRL_SET_SESS_CACHE_MODE 44 +# define SSL_CTRL_GET_SESS_CACHE_MODE 45 +# define SSL_CTRL_GET_MAX_CERT_LIST 50 +# define SSL_CTRL_SET_MAX_CERT_LIST 51 +# define SSL_CTRL_SET_MAX_SEND_FRAGMENT 52 +/* see tls1.h for macros based on these */ +# define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53 +# define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54 +# define SSL_CTRL_SET_TLSEXT_HOSTNAME 55 +# define SSL_CTRL_SET_TLSEXT_DEBUG_CB 56 +# define SSL_CTRL_SET_TLSEXT_DEBUG_ARG 57 +# define SSL_CTRL_GET_TLSEXT_TICKET_KEYS 58 +# define SSL_CTRL_SET_TLSEXT_TICKET_KEYS 59 +/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT 60 */ +/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB 61 */ +/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG 62 */ +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB 63 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG 64 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE 65 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS 66 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS 67 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS 68 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS 69 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP 70 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP 71 +# define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB 72 +# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB 75 +# define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB 76 +# define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB 77 +# define SSL_CTRL_SET_SRP_ARG 78 +# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME 79 +# define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH 80 +# define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD 81 +# ifndef OPENSSL_NO_HEARTBEATS +# define SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT 85 +# define SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING 86 +# define SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS 87 +# endif +# define DTLS_CTRL_GET_TIMEOUT 73 +# define DTLS_CTRL_HANDLE_TIMEOUT 74 +# define SSL_CTRL_GET_RI_SUPPORT 76 +# define SSL_CTRL_CLEAR_MODE 78 +# define SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB 79 +# define SSL_CTRL_GET_EXTRA_CHAIN_CERTS 82 +# define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS 83 +# define SSL_CTRL_CHAIN 88 +# define SSL_CTRL_CHAIN_CERT 89 +# define SSL_CTRL_GET_CURVES 90 +# define SSL_CTRL_SET_CURVES 91 +# define SSL_CTRL_SET_CURVES_LIST 92 +# define SSL_CTRL_GET_SHARED_CURVE 93 +# define SSL_CTRL_SET_SIGALGS 97 +# define SSL_CTRL_SET_SIGALGS_LIST 98 +# define SSL_CTRL_CERT_FLAGS 99 +# define SSL_CTRL_CLEAR_CERT_FLAGS 100 +# define SSL_CTRL_SET_CLIENT_SIGALGS 101 +# define SSL_CTRL_SET_CLIENT_SIGALGS_LIST 102 +# define SSL_CTRL_GET_CLIENT_CERT_TYPES 103 +# define SSL_CTRL_SET_CLIENT_CERT_TYPES 104 +# define SSL_CTRL_BUILD_CERT_CHAIN 105 +# define SSL_CTRL_SET_VERIFY_CERT_STORE 106 +# define SSL_CTRL_SET_CHAIN_CERT_STORE 107 +# define SSL_CTRL_GET_PEER_SIGNATURE_NID 108 +# define SSL_CTRL_GET_SERVER_TMP_KEY 109 +# define SSL_CTRL_GET_RAW_CIPHERLIST 110 +# define SSL_CTRL_GET_EC_POINT_FORMATS 111 +# define SSL_CTRL_GET_CHAIN_CERTS 115 +# define SSL_CTRL_SELECT_CURRENT_CERT 116 +# define SSL_CTRL_SET_CURRENT_CERT 117 +# define SSL_CTRL_SET_DH_AUTO 118 +# define DTLS_CTRL_SET_LINK_MTU 120 +# define DTLS_CTRL_GET_LINK_MIN_MTU 121 +# define SSL_CTRL_GET_EXTMS_SUPPORT 122 +# define SSL_CTRL_SET_MIN_PROTO_VERSION 123 +# define SSL_CTRL_SET_MAX_PROTO_VERSION 124 +# define SSL_CTRL_SET_SPLIT_SEND_FRAGMENT 125 +# define SSL_CTRL_SET_MAX_PIPELINES 126 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE 127 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB 128 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG 129 +# define SSL_CERT_SET_FIRST 1 +# define SSL_CERT_SET_NEXT 2 +# define SSL_CERT_SET_SERVER 3 +# define DTLSv1_get_timeout(ssl, arg) \ + SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)arg) +# define DTLSv1_handle_timeout(ssl) \ + SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL) +# define SSL_num_renegotiations(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL) +# define SSL_clear_num_renegotiations(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL) +# define SSL_total_renegotiations(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL) +# define SSL_CTX_set_tmp_dh(ctx,dh) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh) +# define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh) +# define SSL_CTX_set_dh_auto(ctx, onoff) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_DH_AUTO,onoff,NULL) +# define SSL_set_dh_auto(s, onoff) \ + SSL_ctrl(s,SSL_CTRL_SET_DH_AUTO,onoff,NULL) +# define SSL_set_tmp_dh(ssl,dh) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh) +# define SSL_set_tmp_ecdh(ssl,ecdh) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh) +# define SSL_CTX_add_extra_chain_cert(ctx,x509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509) +# define SSL_CTX_get_extra_chain_certs(ctx,px509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,0,px509) +# define SSL_CTX_get_extra_chain_certs_only(ctx,px509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,1,px509) +# define SSL_CTX_clear_extra_chain_certs(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS,0,NULL) +# define SSL_CTX_set0_chain(ctx,sk) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,0,(char *)sk) +# define SSL_CTX_set1_chain(ctx,sk) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,1,(char *)sk) +# define SSL_CTX_add0_chain_cert(ctx,x509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,0,(char *)x509) +# define SSL_CTX_add1_chain_cert(ctx,x509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,1,(char *)x509) +# define SSL_CTX_get0_chain_certs(ctx,px509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERTS,0,px509) +# define SSL_CTX_clear_chain_certs(ctx) \ + SSL_CTX_set0_chain(ctx,NULL) +# define SSL_CTX_build_cert_chain(ctx, flags) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL) +# define SSL_CTX_select_current_cert(ctx,x509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)x509) +# define SSL_CTX_set_current_cert(ctx, op) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CURRENT_CERT, op, NULL) +# define SSL_CTX_set0_verify_cert_store(ctx,st) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)st) +# define SSL_CTX_set1_verify_cert_store(ctx,st) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)st) +# define SSL_CTX_set0_chain_cert_store(ctx,st) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)st) +# define SSL_CTX_set1_chain_cert_store(ctx,st) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)st) +# define SSL_set0_chain(ctx,sk) \ + SSL_ctrl(ctx,SSL_CTRL_CHAIN,0,(char *)sk) +# define SSL_set1_chain(ctx,sk) \ + SSL_ctrl(ctx,SSL_CTRL_CHAIN,1,(char *)sk) +# define SSL_add0_chain_cert(ctx,x509) \ + SSL_ctrl(ctx,SSL_CTRL_CHAIN_CERT,0,(char *)x509) +# define SSL_add1_chain_cert(ctx,x509) \ + SSL_ctrl(ctx,SSL_CTRL_CHAIN_CERT,1,(char *)x509) +# define SSL_get0_chain_certs(ctx,px509) \ + SSL_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERTS,0,px509) +# define SSL_clear_chain_certs(ctx) \ + SSL_set0_chain(ctx,NULL) +# define SSL_build_cert_chain(s, flags) \ + SSL_ctrl(s,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL) +# define SSL_select_current_cert(ctx,x509) \ + SSL_ctrl(ctx,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)x509) +# define SSL_set_current_cert(ctx,op) \ + SSL_ctrl(ctx,SSL_CTRL_SET_CURRENT_CERT, op, NULL) +# define SSL_set0_verify_cert_store(s,st) \ + SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)st) +# define SSL_set1_verify_cert_store(s,st) \ + SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)st) +# define SSL_set0_chain_cert_store(s,st) \ + SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)st) +# define SSL_set1_chain_cert_store(s,st) \ + SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)st) +# define SSL_get1_curves(ctx, s) \ + SSL_ctrl(ctx,SSL_CTRL_GET_CURVES,0,(char *)s) +# define SSL_CTX_set1_curves(ctx, clist, clistlen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CURVES,clistlen,(char *)clist) +# define SSL_CTX_set1_curves_list(ctx, s) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CURVES_LIST,0,(char *)s) +# define SSL_set1_curves(ctx, clist, clistlen) \ + SSL_ctrl(ctx,SSL_CTRL_SET_CURVES,clistlen,(char *)clist) +# define SSL_set1_curves_list(ctx, s) \ + SSL_ctrl(ctx,SSL_CTRL_SET_CURVES_LIST,0,(char *)s) +# define SSL_get_shared_curve(s, n) \ + SSL_ctrl(s,SSL_CTRL_GET_SHARED_CURVE,n,NULL) +# define SSL_CTX_set1_sigalgs(ctx, slist, slistlen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS,slistlen,(int *)slist) +# define SSL_CTX_set1_sigalgs_list(ctx, s) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)s) +# define SSL_set1_sigalgs(ctx, slist, slistlen) \ + SSL_ctrl(ctx,SSL_CTRL_SET_SIGALGS,clistlen,(int *)slist) +# define SSL_set1_sigalgs_list(ctx, s) \ + SSL_ctrl(ctx,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)s) +# define SSL_CTX_set1_client_sigalgs(ctx, slist, slistlen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)slist) +# define SSL_CTX_set1_client_sigalgs_list(ctx, s) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)s) +# define SSL_set1_client_sigalgs(ctx, slist, slistlen) \ + SSL_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS,clistlen,(int *)slist) +# define SSL_set1_client_sigalgs_list(ctx, s) \ + SSL_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)s) +# define SSL_get0_certificate_types(s, clist) \ + SSL_ctrl(s, SSL_CTRL_GET_CLIENT_CERT_TYPES, 0, (char *)clist) +# define SSL_CTX_set1_client_certificate_types(ctx, clist, clistlen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen,(char *)clist) +# define SSL_set1_client_certificate_types(s, clist, clistlen) \ + SSL_ctrl(s,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen,(char *)clist) +# define SSL_get_peer_signature_nid(s, pn) \ + SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NID,0,pn) +# define SSL_get_server_tmp_key(s, pk) \ + SSL_ctrl(s,SSL_CTRL_GET_SERVER_TMP_KEY,0,pk) +# define SSL_get0_raw_cipherlist(s, plst) \ + SSL_ctrl(s,SSL_CTRL_GET_RAW_CIPHERLIST,0,plst) +# define SSL_get0_ec_point_formats(s, plst) \ + SSL_ctrl(s,SSL_CTRL_GET_EC_POINT_FORMATS,0,plst) +#define SSL_CTX_set_min_proto_version(ctx, version) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL) +#define SSL_CTX_set_max_proto_version(ctx, version) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL) +#define SSL_set_min_proto_version(s, version) \ + SSL_ctrl(s, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL) +#define SSL_set_max_proto_version(s, version) \ + SSL_ctrl(s, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL) + +#if OPENSSL_API_COMPAT < 0x10100000L +/* Provide some compatibility macros for removed functionality. */ +# define SSL_CTX_need_tmp_RSA(ctx) 0 +# define SSL_CTX_set_tmp_rsa(ctx,rsa) 1 +# define SSL_need_tmp_RSA(ssl) 0 +# define SSL_set_tmp_rsa(ssl,rsa) 1 +# define SSL_CTX_set_ecdh_auto(dummy, onoff) ((onoff) != 0) +# define SSL_set_ecdh_auto(dummy, onoff) ((onoff) != 0) +/* + * We "pretend" to call the callback to avoid warnings about unused static + * functions. + */ +# define SSL_CTX_set_tmp_rsa_callback(ctx, cb) while(0) (cb)(NULL, 0, 0) +# define SSL_set_tmp_rsa_callback(ssl, cb) while(0) (cb)(NULL, 0, 0) +#endif + +__owur const BIO_METHOD *BIO_f_ssl(void); +__owur BIO *BIO_new_ssl(SSL_CTX *ctx, int client); +__owur BIO *BIO_new_ssl_connect(SSL_CTX *ctx); +__owur BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx); +__owur int BIO_ssl_copy_session_id(BIO *to, BIO *from); +void BIO_ssl_shutdown(BIO *ssl_bio); + +__owur int SSL_CTX_set_cipher_list(SSL_CTX *, const char *str); +__owur SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth); +int SSL_CTX_up_ref(SSL_CTX *ctx); +void SSL_CTX_free(SSL_CTX *); +__owur long SSL_CTX_set_timeout(SSL_CTX *ctx, long t); +__owur long SSL_CTX_get_timeout(const SSL_CTX *ctx); +__owur X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *); +void SSL_CTX_set_cert_store(SSL_CTX *, X509_STORE *); +__owur int SSL_want(const SSL *s); +__owur int SSL_clear(SSL *s); + +void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm); + +__owur const SSL_CIPHER *SSL_get_current_cipher(const SSL *s); +__owur int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits); +__owur const char *SSL_CIPHER_get_version(const SSL_CIPHER *c); +__owur const char *SSL_CIPHER_get_name(const SSL_CIPHER *c); +__owur uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *c); +__owur int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *c); +__owur int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *c); +__owur int SSL_CIPHER_is_aead(const SSL_CIPHER *c); + +__owur int SSL_get_fd(const SSL *s); +__owur int SSL_get_rfd(const SSL *s); +__owur int SSL_get_wfd(const SSL *s); +__owur const char *SSL_get_cipher_list(const SSL *s, int n); +__owur char *SSL_get_shared_ciphers(const SSL *s, char *buf, int len); +__owur int SSL_get_read_ahead(const SSL *s); +__owur int SSL_pending(const SSL *s); +__owur int SSL_has_pending(const SSL *s); +# ifndef OPENSSL_NO_SOCK +__owur int SSL_set_fd(SSL *s, int fd); +__owur int SSL_set_rfd(SSL *s, int fd); +__owur int SSL_set_wfd(SSL *s, int fd); +# endif +void SSL_set0_rbio(SSL *s, BIO *rbio); +void SSL_set0_wbio(SSL *s, BIO *wbio); +void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio); +__owur BIO *SSL_get_rbio(const SSL *s); +__owur BIO *SSL_get_wbio(const SSL *s); +__owur int SSL_set_cipher_list(SSL *s, const char *str); +void SSL_set_read_ahead(SSL *s, int yes); +__owur int SSL_get_verify_mode(const SSL *s); +__owur int SSL_get_verify_depth(const SSL *s); +__owur int (*SSL_get_verify_callback(const SSL *s)) (int, X509_STORE_CTX *); +void SSL_set_verify(SSL *s, int mode, + int (*callback) (int ok, X509_STORE_CTX *ctx)); +void SSL_set_verify_depth(SSL *s, int depth); +void SSL_set_cert_cb(SSL *s, int (*cb) (SSL *ssl, void *arg), void *arg); +# ifndef OPENSSL_NO_RSA +__owur int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa); +__owur int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, const unsigned char *d, long len); +# endif +__owur int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); +__owur int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d, + long len); +__owur int SSL_use_certificate(SSL *ssl, X509 *x); +__owur int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len); + +/* Set serverinfo data for the current active cert. */ +__owur int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo, + size_t serverinfo_length); +__owur int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file); + +#ifndef OPENSSL_NO_RSA +__owur int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type); +#endif + +__owur int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type); +__owur int SSL_use_certificate_file(SSL *ssl, const char *file, int type); + +#ifndef OPENSSL_NO_RSA +__owur int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type); +#endif +__owur int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type); +__owur int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type); +/* PEM type */ +__owur int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); +__owur int SSL_use_certificate_chain_file(SSL *ssl, const char *file); +__owur STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file); +__owur int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, + const char *file); +int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, + const char *dir); + +#if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_load_error_strings() \ + OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS \ + | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL) +#endif + +__owur const char *SSL_state_string(const SSL *s); +__owur const char *SSL_rstate_string(const SSL *s); +__owur const char *SSL_state_string_long(const SSL *s); +__owur const char *SSL_rstate_string_long(const SSL *s); +__owur long SSL_SESSION_get_time(const SSL_SESSION *s); +__owur long SSL_SESSION_set_time(SSL_SESSION *s, long t); +__owur long SSL_SESSION_get_timeout(const SSL_SESSION *s); +__owur long SSL_SESSION_set_timeout(SSL_SESSION *s, long t); +__owur int SSL_SESSION_get_protocol_version(const SSL_SESSION *s); +__owur const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s); +__owur const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s); +__owur int SSL_SESSION_has_ticket(const SSL_SESSION *s); +__owur unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s); +void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick, + size_t *len); +__owur int SSL_copy_session_id(SSL *to, const SSL *from); +__owur X509 *SSL_SESSION_get0_peer(SSL_SESSION *s); +__owur int SSL_SESSION_set1_id_context(SSL_SESSION *s, const unsigned char *sid_ctx, + unsigned int sid_ctx_len); +__owur int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid, + unsigned int sid_len); + +__owur SSL_SESSION *SSL_SESSION_new(void); +const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, + unsigned int *len); +const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s, + unsigned int *len); +__owur unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s); +# ifndef OPENSSL_NO_STDIO +int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *ses); +# endif +int SSL_SESSION_print(BIO *fp, const SSL_SESSION *ses); +int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x); +int SSL_SESSION_up_ref(SSL_SESSION *ses); +void SSL_SESSION_free(SSL_SESSION *ses); +__owur int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp); +__owur int SSL_set_session(SSL *to, SSL_SESSION *session); +__owur int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c); +int SSL_CTX_remove_session(SSL_CTX *, SSL_SESSION *c); +__owur int SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB); +__owur int SSL_set_generate_session_id(SSL *, GEN_SESSION_CB); +__owur int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, + unsigned int id_len); +SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, + long length); + +# ifdef HEADER_X509_H +__owur X509 *SSL_get_peer_certificate(const SSL *s); +# endif + +__owur STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s); + +__owur int SSL_CTX_get_verify_mode(const SSL_CTX *ctx); +__owur int SSL_CTX_get_verify_depth(const SSL_CTX *ctx); +__owur int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx)) (int, + X509_STORE_CTX *); +void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, + int (*callback) (int, X509_STORE_CTX *)); +void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth); +void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, + int (*cb) (X509_STORE_CTX *, void *), + void *arg); +void SSL_CTX_set_cert_cb(SSL_CTX *c, int (*cb) (SSL *ssl, void *arg), + void *arg); +# ifndef OPENSSL_NO_RSA +__owur int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); +__owur int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, + long len); +# endif +__owur int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); +__owur int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, + const unsigned char *d, long len); +__owur int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); +__owur int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, + const unsigned char *d); + +void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); +void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); +pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx); +void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx); +void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb); +void SSL_set_default_passwd_cb_userdata(SSL *s, void *u); +pem_password_cb *SSL_get_default_passwd_cb(SSL *s); +void *SSL_get_default_passwd_cb_userdata(SSL *s); + +__owur int SSL_CTX_check_private_key(const SSL_CTX *ctx); +__owur int SSL_check_private_key(const SSL *ctx); + +__owur int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx, + unsigned int sid_ctx_len); + +SSL *SSL_new(SSL_CTX *ctx); +int SSL_up_ref(SSL *s); +int SSL_is_dtls(const SSL *s); +__owur int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx, + unsigned int sid_ctx_len); + +__owur int SSL_CTX_set_purpose(SSL_CTX *s, int purpose); +__owur int SSL_set_purpose(SSL *s, int purpose); +__owur int SSL_CTX_set_trust(SSL_CTX *s, int trust); +__owur int SSL_set_trust(SSL *s, int trust); + +__owur int SSL_set1_host(SSL *s, const char *hostname); +__owur int SSL_add1_host(SSL *s, const char *hostname); +__owur const char *SSL_get0_peername(SSL *s); +void SSL_set_hostflags(SSL *s, unsigned int flags); + +__owur int SSL_CTX_dane_enable(SSL_CTX *ctx); +__owur int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md, + uint8_t mtype, uint8_t ord); +__owur int SSL_dane_enable(SSL *s, const char *basedomain); +__owur int SSL_dane_tlsa_add(SSL *s, uint8_t usage, uint8_t selector, + uint8_t mtype, unsigned char *data, size_t dlen); +__owur int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki); +__owur int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector, + uint8_t *mtype, unsigned const char **data, + size_t *dlen); +/* + * Bridge opacity barrier between libcrypt and libssl, also needed to support + * offline testing in test/danetest.c + */ +SSL_DANE *SSL_get0_dane(SSL *ssl); +/* + * DANE flags + */ +unsigned long SSL_CTX_dane_set_flags(SSL_CTX *ctx, unsigned long flags); +unsigned long SSL_CTX_dane_clear_flags(SSL_CTX *ctx, unsigned long flags); +unsigned long SSL_dane_set_flags(SSL *ssl, unsigned long flags); +unsigned long SSL_dane_clear_flags(SSL *ssl, unsigned long flags); + +__owur int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm); +__owur int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm); + +__owur X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx); +__owur X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl); + +# ifndef OPENSSL_NO_SRP +int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name); +int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password); +int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength); +int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx, + char *(*cb) (SSL *, void *)); +int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx, + int (*cb) (SSL *, void *)); +int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx, + int (*cb) (SSL *, int *, void *)); +int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg); + +int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g, + BIGNUM *sa, BIGNUM *v, char *info); +int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass, + const char *grp); + +__owur BIGNUM *SSL_get_srp_g(SSL *s); +__owur BIGNUM *SSL_get_srp_N(SSL *s); + +__owur char *SSL_get_srp_username(SSL *s); +__owur char *SSL_get_srp_userinfo(SSL *s); +# endif + +void SSL_certs_clear(SSL *s); +void SSL_free(SSL *ssl); +# ifdef OSSL_ASYNC_FD +/* + * Windows application developer has to include windows.h to use these. + */ +__owur int SSL_waiting_for_async(SSL *s); +__owur int SSL_get_all_async_fds(SSL *s, OSSL_ASYNC_FD *fds, size_t *numfds); +__owur int SSL_get_changed_async_fds(SSL *s, OSSL_ASYNC_FD *addfd, + size_t *numaddfds, OSSL_ASYNC_FD *delfd, + size_t *numdelfds); +# endif +__owur int SSL_accept(SSL *ssl); +__owur int SSL_connect(SSL *ssl); +__owur int SSL_read(SSL *ssl, void *buf, int num); +__owur int SSL_peek(SSL *ssl, void *buf, int num); +__owur int SSL_write(SSL *ssl, const void *buf, int num); +long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg); +long SSL_callback_ctrl(SSL *, int, void (*)(void)); +long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg); +long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void)); + +__owur int SSL_get_error(const SSL *s, int ret_code); +__owur const char *SSL_get_version(const SSL *s); + +/* This sets the 'default' SSL version that SSL_new() will create */ +__owur int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth); + +# ifndef OPENSSL_NO_SSL3_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *SSLv3_method(void)) /* SSLv3 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *SSLv3_server_method(void)) /* SSLv3 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *SSLv3_client_method(void)) /* SSLv3 */ +# endif + +#define SSLv23_method TLS_method +#define SSLv23_server_method TLS_server_method +#define SSLv23_client_method TLS_client_method + +/* Negotiate highest available SSL/TLS version */ +__owur const SSL_METHOD *TLS_method(void); +__owur const SSL_METHOD *TLS_server_method(void); +__owur const SSL_METHOD *TLS_client_method(void); + +# ifndef OPENSSL_NO_TLS1_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_method(void)) /* TLSv1.0 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_server_method(void)) /* TLSv1.0 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_client_method(void)) /* TLSv1.0 */ +# endif + +# ifndef OPENSSL_NO_TLS1_1_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_1_method(void)) /* TLSv1.1 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_1_server_method(void)) /* TLSv1.1 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_1_client_method(void)) /* TLSv1.1 */ +# endif + +# ifndef OPENSSL_NO_TLS1_2_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_method(void)) /* TLSv1.2 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_server_method(void)) /* TLSv1.2 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_client_method(void)) /* TLSv1.2 */ +# endif + +# ifndef OPENSSL_NO_DTLS1_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_method(void)) /* DTLSv1.0 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_server_method(void)) /* DTLSv1.0 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_client_method(void)) /* DTLSv1.0 */ +# endif + +# ifndef OPENSSL_NO_DTLS1_2_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_2_method(void)) /* DTLSv1.2 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_2_server_method(void)) /* DTLSv1.2 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_2_client_method(void)) /* DTLSv1.2 */ +#endif + +__owur const SSL_METHOD *DTLS_method(void); /* DTLS 1.0 and 1.2 */ +__owur const SSL_METHOD *DTLS_server_method(void); /* DTLS 1.0 and 1.2 */ +__owur const SSL_METHOD *DTLS_client_method(void); /* DTLS 1.0 and 1.2 */ + +__owur STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s); +__owur STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx); +__owur STACK_OF(SSL_CIPHER) *SSL_get_client_ciphers(const SSL *s); +__owur STACK_OF(SSL_CIPHER) *SSL_get1_supported_ciphers(SSL *s); + +__owur int SSL_do_handshake(SSL *s); +int SSL_renegotiate(SSL *s); +__owur int SSL_renegotiate_abbreviated(SSL *s); +__owur int SSL_renegotiate_pending(SSL *s); +int SSL_shutdown(SSL *s); + +__owur const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx); +__owur const SSL_METHOD *SSL_get_ssl_method(SSL *s); +__owur int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method); +__owur const char *SSL_alert_type_string_long(int value); +__owur const char *SSL_alert_type_string(int value); +__owur const char *SSL_alert_desc_string_long(int value); +__owur const char *SSL_alert_desc_string(int value); + +void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list); +void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list); +__owur STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s); +__owur STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s); +__owur int SSL_add_client_CA(SSL *ssl, X509 *x); +__owur int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x); + +void SSL_set_connect_state(SSL *s); +void SSL_set_accept_state(SSL *s); + +__owur long SSL_get_default_timeout(const SSL *s); + +#if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_library_init() OPENSSL_init_ssl(0, NULL) +#endif + +__owur char *SSL_CIPHER_description(const SSL_CIPHER *, char *buf, int size); +__owur STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk); + +__owur SSL *SSL_dup(SSL *ssl); + +__owur X509 *SSL_get_certificate(const SSL *ssl); +/* + * EVP_PKEY + */ struct evp_pkey_st *SSL_get_privatekey(const SSL *ssl); + +__owur X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx); +__owur EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx); + +void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode); +__owur int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx); +void SSL_set_quiet_shutdown(SSL *ssl, int mode); +__owur int SSL_get_quiet_shutdown(const SSL *ssl); +void SSL_set_shutdown(SSL *ssl, int mode); +__owur int SSL_get_shutdown(const SSL *ssl); +__owur int SSL_version(const SSL *ssl); +__owur int SSL_client_version(const SSL *s); +__owur int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx); +__owur int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx); +__owur int SSL_CTX_set_default_verify_file(SSL_CTX *ctx); +__owur int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, + const char *CApath); +# define SSL_get0_session SSL_get_session/* just peek at pointer */ +__owur SSL_SESSION *SSL_get_session(const SSL *ssl); +__owur SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */ +__owur SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl); +SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx); +void SSL_set_info_callback(SSL *ssl, + void (*cb) (const SSL *ssl, int type, int val)); +void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type, + int val); +__owur OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl); + +void SSL_set_verify_result(SSL *ssl, long v); +__owur long SSL_get_verify_result(const SSL *ssl); +__owur STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s); + +__owur size_t SSL_get_client_random(const SSL *ssl, unsigned char *out, + size_t outlen); +__owur size_t SSL_get_server_random(const SSL *ssl, unsigned char *out, + size_t outlen); +__owur size_t SSL_SESSION_get_master_key(const SSL_SESSION *ssl, + unsigned char *out, size_t outlen); + +#define SSL_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, l, p, newf, dupf, freef) +__owur int SSL_set_ex_data(SSL *ssl, int idx, void *data); +void *SSL_get_ex_data(const SSL *ssl, int idx); +#define SSL_SESSION_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, l, p, newf, dupf, freef) +__owur int SSL_SESSION_set_ex_data(SSL_SESSION *ss, int idx, void *data); +void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss, int idx); +#define SSL_CTX_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, l, p, newf, dupf, freef) +__owur int SSL_CTX_set_ex_data(SSL_CTX *ssl, int idx, void *data); +void *SSL_CTX_get_ex_data(const SSL_CTX *ssl, int idx); + +__owur int SSL_get_ex_data_X509_STORE_CTX_idx(void); + +# define SSL_CTX_sess_set_cache_size(ctx,t) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL) +# define SSL_CTX_sess_get_cache_size(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL) +# define SSL_CTX_set_session_cache_mode(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL) +# define SSL_CTX_get_session_cache_mode(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL) + +# define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx) +# define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m) +# define SSL_CTX_get_read_ahead(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL) +# define SSL_CTX_set_read_ahead(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL) +# define SSL_CTX_get_max_cert_list(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) +# define SSL_CTX_set_max_cert_list(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) +# define SSL_get_max_cert_list(ssl) \ + SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) +# define SSL_set_max_cert_list(ssl,m) \ + SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) + +# define SSL_CTX_set_max_send_fragment(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL) +# define SSL_set_max_send_fragment(ssl,m) \ + SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL) +# define SSL_CTX_set_split_send_fragment(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL) +# define SSL_set_split_send_fragment(ssl,m) \ + SSL_ctrl(ssl,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL) +# define SSL_CTX_set_max_pipelines(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_PIPELINES,m,NULL) +# define SSL_set_max_pipelines(ssl,m) \ + SSL_ctrl(ssl,SSL_CTRL_SET_MAX_PIPELINES,m,NULL) + +void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len); +void SSL_set_default_read_buffer_len(SSL *s, size_t len); + +# ifndef OPENSSL_NO_DH +/* NB: the |keylength| is only applicable when is_export is true */ +void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, + DH *(*dh) (SSL *ssl, int is_export, + int keylength)); +void SSL_set_tmp_dh_callback(SSL *ssl, + DH *(*dh) (SSL *ssl, int is_export, + int keylength)); +# endif + +__owur const COMP_METHOD *SSL_get_current_compression(SSL *s); +__owur const COMP_METHOD *SSL_get_current_expansion(SSL *s); +__owur const char *SSL_COMP_get_name(const COMP_METHOD *comp); +STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void); +__owur STACK_OF(SSL_COMP) *SSL_COMP_set0_compression_methods(STACK_OF(SSL_COMP) + *meths); +#if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_COMP_free_compression_methods() while(0) continue +#endif +__owur int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm); + +const SSL_CIPHER *SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr); +int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c); +int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c); + +/* TLS extensions functions */ +__owur int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len); + +__owur int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb, + void *arg); + +/* Pre-shared secret session resumption functions */ +__owur int SSL_set_session_secret_cb(SSL *s, + tls_session_secret_cb_fn tls_session_secret_cb, + void *arg); + +void SSL_CTX_set_not_resumable_session_callback(SSL_CTX *ctx, + int (*cb) (SSL *ssl, + int + is_forward_secure)); + +void SSL_set_not_resumable_session_callback(SSL *ssl, + int (*cb) (SSL *ssl, + int + is_forward_secure)); +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_cache_hit(s) SSL_session_reused(s) +# endif + +__owur int SSL_session_reused(SSL *s); +__owur int SSL_is_server(SSL *s); + +__owur __owur SSL_CONF_CTX *SSL_CONF_CTX_new(void); +int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx); +void SSL_CONF_CTX_free(SSL_CONF_CTX *cctx); +unsigned int SSL_CONF_CTX_set_flags(SSL_CONF_CTX *cctx, unsigned int flags); +__owur unsigned int SSL_CONF_CTX_clear_flags(SSL_CONF_CTX *cctx, unsigned int flags); +__owur int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre); + +void SSL_CONF_CTX_set_ssl(SSL_CONF_CTX *cctx, SSL *ssl); +void SSL_CONF_CTX_set_ssl_ctx(SSL_CONF_CTX *cctx, SSL_CTX *ctx); + +__owur int SSL_CONF_cmd(SSL_CONF_CTX *cctx, const char *cmd, const char *value); +__owur int SSL_CONF_cmd_argv(SSL_CONF_CTX *cctx, int *pargc, char ***pargv); +__owur int SSL_CONF_cmd_value_type(SSL_CONF_CTX *cctx, const char *cmd); + +void SSL_add_ssl_module(void); +int SSL_config(SSL *s, const char *name); +int SSL_CTX_config(SSL_CTX *ctx, const char *name); + +# ifndef OPENSSL_NO_SSL_TRACE +void SSL_trace(int write_p, int version, int content_type, + const void *buf, size_t len, SSL *ssl, void *arg); +__owur const char *SSL_CIPHER_standard_name(const SSL_CIPHER *c); +# endif + +# ifndef OPENSSL_NO_SOCK +int DTLSv1_listen(SSL *s, BIO_ADDR *client); +# endif + +# ifndef OPENSSL_NO_CT + +/* + * A callback for verifying that the received SCTs are sufficient. + * Expected to return 1 if they are sufficient, otherwise 0. + * May return a negative integer if an error occurs. + * A connection should be aborted if the SCTs are deemed insufficient. + */ +typedef int(*ssl_ct_validation_cb)(const CT_POLICY_EVAL_CTX *ctx, + const STACK_OF(SCT) *scts, void *arg); + +/* + * Sets a |callback| that is invoked upon receipt of ServerHelloDone to validate + * the received SCTs. + * If the callback returns a non-positive result, the connection is terminated. + * Call this function before beginning a handshake. + * If a NULL |callback| is provided, SCT validation is disabled. + * |arg| is arbitrary userdata that will be passed to the callback whenever it + * is invoked. Ownership of |arg| remains with the caller. + * + * NOTE: A side-effect of setting a CT callback is that an OCSP stapled response + * will be requested. + */ +int SSL_set_ct_validation_callback(SSL *s, ssl_ct_validation_cb callback, + void *arg); +int SSL_CTX_set_ct_validation_callback(SSL_CTX *ctx, + ssl_ct_validation_cb callback, + void *arg); +#define SSL_disable_ct(s) \ + ((void) SSL_set_validation_callback((s), NULL, NULL)) +#define SSL_CTX_disable_ct(ctx) \ + ((void) SSL_CTX_set_validation_callback((ctx), NULL, NULL)) + +/* + * The validation type enumerates the available behaviours of the built-in SSL + * CT validation callback selected via SSL_enable_ct() and SSL_CTX_enable_ct(). + * The underlying callback is a static function in libssl. + */ +enum { + SSL_CT_VALIDATION_PERMISSIVE = 0, + SSL_CT_VALIDATION_STRICT +}; + +/* + * Enable CT by setting up a callback that implements one of the built-in + * validation variants. The SSL_CT_VALIDATION_PERMISSIVE variant always + * continues the handshake, the application can make appropriate decisions at + * handshake completion. The SSL_CT_VALIDATION_STRICT variant requires at + * least one valid SCT, or else handshake termination will be requested. The + * handshake may continue anyway if SSL_VERIFY_NONE is in effect. + */ +int SSL_enable_ct(SSL *s, int validation_mode); +int SSL_CTX_enable_ct(SSL_CTX *ctx, int validation_mode); + +/* + * Report whether a non-NULL callback is enabled. + */ +int SSL_ct_is_enabled(const SSL *s); +int SSL_CTX_ct_is_enabled(const SSL_CTX *ctx); + +/* Gets the SCTs received from a connection */ +const STACK_OF(SCT) *SSL_get0_peer_scts(SSL *s); + +/* + * Loads the CT log list from the default location. + * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store, + * the log information loaded from this file will be appended to the + * CTLOG_STORE. + * Returns 1 on success, 0 otherwise. + */ +int SSL_CTX_set_default_ctlog_list_file(SSL_CTX *ctx); + +/* + * Loads the CT log list from the specified file path. + * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store, + * the log information loaded from this file will be appended to the + * CTLOG_STORE. + * Returns 1 on success, 0 otherwise. + */ +int SSL_CTX_set_ctlog_list_file(SSL_CTX *ctx, const char *path); + +/* + * Sets the CT log list used by all SSL connections created from this SSL_CTX. + * Ownership of the CTLOG_STORE is transferred to the SSL_CTX. + */ +void SSL_CTX_set0_ctlog_store(SSL_CTX *ctx, CTLOG_STORE *logs); + +/* + * Gets the CT log list used by all SSL connections created from this SSL_CTX. + * This will be NULL unless one of the following functions has been called: + * - SSL_CTX_set_default_ctlog_list_file + * - SSL_CTX_set_ctlog_list_file + * - SSL_CTX_set_ctlog_store + */ +const CTLOG_STORE *SSL_CTX_get0_ctlog_store(const SSL_CTX *ctx); + +# endif /* OPENSSL_NO_CT */ + +/* What the "other" parameter contains in security callback */ +/* Mask for type */ +# define SSL_SECOP_OTHER_TYPE 0xffff0000 +# define SSL_SECOP_OTHER_NONE 0 +# define SSL_SECOP_OTHER_CIPHER (1 << 16) +# define SSL_SECOP_OTHER_CURVE (2 << 16) +# define SSL_SECOP_OTHER_DH (3 << 16) +# define SSL_SECOP_OTHER_PKEY (4 << 16) +# define SSL_SECOP_OTHER_SIGALG (5 << 16) +# define SSL_SECOP_OTHER_CERT (6 << 16) + +/* Indicated operation refers to peer key or certificate */ +# define SSL_SECOP_PEER 0x1000 + +/* Values for "op" parameter in security callback */ + +/* Called to filter ciphers */ +/* Ciphers client supports */ +# define SSL_SECOP_CIPHER_SUPPORTED (1 | SSL_SECOP_OTHER_CIPHER) +/* Cipher shared by client/server */ +# define SSL_SECOP_CIPHER_SHARED (2 | SSL_SECOP_OTHER_CIPHER) +/* Sanity check of cipher server selects */ +# define SSL_SECOP_CIPHER_CHECK (3 | SSL_SECOP_OTHER_CIPHER) +/* Curves supported by client */ +# define SSL_SECOP_CURVE_SUPPORTED (4 | SSL_SECOP_OTHER_CURVE) +/* Curves shared by client/server */ +# define SSL_SECOP_CURVE_SHARED (5 | SSL_SECOP_OTHER_CURVE) +/* Sanity check of curve server selects */ +# define SSL_SECOP_CURVE_CHECK (6 | SSL_SECOP_OTHER_CURVE) +/* Temporary DH key */ +# define SSL_SECOP_TMP_DH (7 | SSL_SECOP_OTHER_PKEY) +/* SSL/TLS version */ +# define SSL_SECOP_VERSION (9 | SSL_SECOP_OTHER_NONE) +/* Session tickets */ +# define SSL_SECOP_TICKET (10 | SSL_SECOP_OTHER_NONE) +/* Supported signature algorithms sent to peer */ +# define SSL_SECOP_SIGALG_SUPPORTED (11 | SSL_SECOP_OTHER_SIGALG) +/* Shared signature algorithm */ +# define SSL_SECOP_SIGALG_SHARED (12 | SSL_SECOP_OTHER_SIGALG) +/* Sanity check signature algorithm allowed */ +# define SSL_SECOP_SIGALG_CHECK (13 | SSL_SECOP_OTHER_SIGALG) +/* Used to get mask of supported public key signature algorithms */ +# define SSL_SECOP_SIGALG_MASK (14 | SSL_SECOP_OTHER_SIGALG) +/* Use to see if compression is allowed */ +# define SSL_SECOP_COMPRESSION (15 | SSL_SECOP_OTHER_NONE) +/* EE key in certificate */ +# define SSL_SECOP_EE_KEY (16 | SSL_SECOP_OTHER_CERT) +/* CA key in certificate */ +# define SSL_SECOP_CA_KEY (17 | SSL_SECOP_OTHER_CERT) +/* CA digest algorithm in certificate */ +# define SSL_SECOP_CA_MD (18 | SSL_SECOP_OTHER_CERT) +/* Peer EE key in certificate */ +# define SSL_SECOP_PEER_EE_KEY (SSL_SECOP_EE_KEY | SSL_SECOP_PEER) +/* Peer CA key in certificate */ +# define SSL_SECOP_PEER_CA_KEY (SSL_SECOP_CA_KEY | SSL_SECOP_PEER) +/* Peer CA digest algorithm in certificate */ +# define SSL_SECOP_PEER_CA_MD (SSL_SECOP_CA_MD | SSL_SECOP_PEER) + +void SSL_set_security_level(SSL *s, int level); +__owur int SSL_get_security_level(const SSL *s); +void SSL_set_security_callback(SSL *s, + int (*cb) (const SSL *s, const SSL_CTX *ctx, int op, + int bits, int nid, void *other, + void *ex)); +int (*SSL_get_security_callback(const SSL *s)) (const SSL *s, const SSL_CTX *ctx, int op, + int bits, int nid, + void *other, void *ex); +void SSL_set0_security_ex_data(SSL *s, void *ex); +__owur void *SSL_get0_security_ex_data(const SSL *s); + +void SSL_CTX_set_security_level(SSL_CTX *ctx, int level); +__owur int SSL_CTX_get_security_level(const SSL_CTX *ctx); +void SSL_CTX_set_security_callback(SSL_CTX *ctx, + int (*cb) (const SSL *s, const SSL_CTX *ctx, int op, + int bits, int nid, void *other, + void *ex)); +int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx)) (const SSL *s, + const SSL_CTX *ctx, + int op, int bits, + int nid, + void *other, + void *ex); +void SSL_CTX_set0_security_ex_data(SSL_CTX *ctx, void *ex); +__owur void *SSL_CTX_get0_security_ex_data(const SSL_CTX *ctx); + +/* OPENSSL_INIT flag 0x010000 reserved for internal use */ +#define OPENSSL_INIT_NO_LOAD_SSL_STRINGS 0x00100000L +#define OPENSSL_INIT_LOAD_SSL_STRINGS 0x00200000L + +#define OPENSSL_INIT_SSL_DEFAULT \ + (OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS) + +int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings); + +# ifndef OPENSSL_NO_UNIT_TEST +__owur const struct openssl_ssl_test_functions *SSL_test_functions(void); +# endif + +extern const char SSL_version_str[]; + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_SSL_strings(void); + +/* Error codes for the SSL functions. */ + +/* Function codes. */ +# define SSL_F_CHECK_SUITEB_CIPHER_LIST 331 +# define SSL_F_CT_MOVE_SCTS 345 +# define SSL_F_CT_STRICT 349 +# define SSL_F_D2I_SSL_SESSION 103 +# define SSL_F_DANE_CTX_ENABLE 347 +# define SSL_F_DANE_MTYPE_SET 393 +# define SSL_F_DANE_TLSA_ADD 394 +# define SSL_F_DO_DTLS1_WRITE 245 +# define SSL_F_DO_SSL3_WRITE 104 +# define SSL_F_DTLS1_BUFFER_RECORD 247 +# define SSL_F_DTLS1_CHECK_TIMEOUT_NUM 318 +# define SSL_F_DTLS1_HEARTBEAT 305 +# define SSL_F_DTLS1_PREPROCESS_FRAGMENT 288 +# define SSL_F_DTLS1_PROCESS_BUFFERED_RECORDS 424 +# define SSL_F_DTLS1_PROCESS_RECORD 257 +# define SSL_F_DTLS1_READ_BYTES 258 +# define SSL_F_DTLS1_READ_FAILED 339 +# define SSL_F_DTLS1_RETRANSMIT_MESSAGE 390 +# define SSL_F_DTLS1_WRITE_APP_DATA_BYTES 268 +# define SSL_F_DTLSV1_LISTEN 350 +# define SSL_F_DTLS_CONSTRUCT_CHANGE_CIPHER_SPEC 371 +# define SSL_F_DTLS_CONSTRUCT_HELLO_VERIFY_REQUEST 385 +# define SSL_F_DTLS_GET_REASSEMBLED_MESSAGE 370 +# define SSL_F_DTLS_PROCESS_HELLO_VERIFY 386 +# define SSL_F_OPENSSL_INIT_SSL 342 +# define SSL_F_OSSL_STATEM_CLIENT_READ_TRANSITION 417 +# define SSL_F_OSSL_STATEM_SERVER_READ_TRANSITION 418 +# define SSL_F_READ_STATE_MACHINE 352 +# define SSL_F_SSL3_CHANGE_CIPHER_STATE 129 +# define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130 +# define SSL_F_SSL3_CTRL 213 +# define SSL_F_SSL3_CTX_CTRL 133 +# define SSL_F_SSL3_DIGEST_CACHED_RECORDS 293 +# define SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC 292 +# define SSL_F_SSL3_FINAL_FINISH_MAC 285 +# define SSL_F_SSL3_GENERATE_KEY_BLOCK 238 +# define SSL_F_SSL3_GENERATE_MASTER_SECRET 388 +# define SSL_F_SSL3_GET_RECORD 143 +# define SSL_F_SSL3_INIT_FINISHED_MAC 397 +# define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147 +# define SSL_F_SSL3_READ_BYTES 148 +# define SSL_F_SSL3_READ_N 149 +# define SSL_F_SSL3_SETUP_KEY_BLOCK 157 +# define SSL_F_SSL3_SETUP_READ_BUFFER 156 +# define SSL_F_SSL3_SETUP_WRITE_BUFFER 291 +# define SSL_F_SSL3_WRITE_BYTES 158 +# define SSL_F_SSL3_WRITE_PENDING 159 +# define SSL_F_SSL_ADD_CERT_CHAIN 316 +# define SSL_F_SSL_ADD_CERT_TO_BUF 319 +# define SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT 298 +# define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT 277 +# define SSL_F_SSL_ADD_CLIENTHELLO_USE_SRTP_EXT 307 +# define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215 +# define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216 +# define SSL_F_SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT 299 +# define SSL_F_SSL_ADD_SERVERHELLO_TLSEXT 278 +# define SSL_F_SSL_ADD_SERVERHELLO_USE_SRTP_EXT 308 +# define SSL_F_SSL_BAD_METHOD 160 +# define SSL_F_SSL_BUILD_CERT_CHAIN 332 +# define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161 +# define SSL_F_SSL_CERT_ADD0_CHAIN_CERT 346 +# define SSL_F_SSL_CERT_DUP 221 +# define SSL_F_SSL_CERT_NEW 162 +# define SSL_F_SSL_CERT_SET0_CHAIN 340 +# define SSL_F_SSL_CHECK_PRIVATE_KEY 163 +# define SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT 280 +# define SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG 279 +# define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230 +# define SSL_F_SSL_CIPHER_STRENGTH_SORT 231 +# define SSL_F_SSL_CLEAR 164 +# define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165 +# define SSL_F_SSL_CONF_CMD 334 +# define SSL_F_SSL_CREATE_CIPHER_LIST 166 +# define SSL_F_SSL_CTRL 232 +# define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168 +# define SSL_F_SSL_CTX_ENABLE_CT 398 +# define SSL_F_SSL_CTX_MAKE_PROFILES 309 +# define SSL_F_SSL_CTX_NEW 169 +# define SSL_F_SSL_CTX_SET_ALPN_PROTOS 343 +# define SSL_F_SSL_CTX_SET_CIPHER_LIST 269 +# define SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE 290 +# define SSL_F_SSL_CTX_SET_CT_VALIDATION_CALLBACK 396 +# define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219 +# define SSL_F_SSL_CTX_SET_SSL_VERSION 170 +# define SSL_F_SSL_CTX_USE_CERTIFICATE 171 +# define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172 +# define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173 +# define SSL_F_SSL_CTX_USE_PRIVATEKEY 174 +# define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175 +# define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176 +# define SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT 272 +# define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177 +# define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178 +# define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179 +# define SSL_F_SSL_CTX_USE_SERVERINFO 336 +# define SSL_F_SSL_CTX_USE_SERVERINFO_FILE 337 +# define SSL_F_SSL_DANE_DUP 403 +# define SSL_F_SSL_DANE_ENABLE 395 +# define SSL_F_SSL_DO_CONFIG 391 +# define SSL_F_SSL_DO_HANDSHAKE 180 +# define SSL_F_SSL_DUP_CA_LIST 408 +# define SSL_F_SSL_ENABLE_CT 402 +# define SSL_F_SSL_GET_NEW_SESSION 181 +# define SSL_F_SSL_GET_PREV_SESSION 217 +# define SSL_F_SSL_GET_SERVER_CERT_INDEX 322 +# define SSL_F_SSL_GET_SIGN_PKEY 183 +# define SSL_F_SSL_INIT_WBIO_BUFFER 184 +# define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185 +# define SSL_F_SSL_MODULE_INIT 392 +# define SSL_F_SSL_NEW 186 +# define SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT 300 +# define SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT 302 +# define SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT 310 +# define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT 301 +# define SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT 303 +# define SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT 311 +# define SSL_F_SSL_PEEK 270 +# define SSL_F_SSL_READ 223 +# define SSL_F_SSL_SCAN_CLIENTHELLO_TLSEXT 320 +# define SSL_F_SSL_SCAN_SERVERHELLO_TLSEXT 321 +# define SSL_F_SSL_SESSION_DUP 348 +# define SSL_F_SSL_SESSION_NEW 189 +# define SSL_F_SSL_SESSION_PRINT_FP 190 +# define SSL_F_SSL_SESSION_SET1_ID 423 +# define SSL_F_SSL_SESSION_SET1_ID_CONTEXT 312 +# define SSL_F_SSL_SET_ALPN_PROTOS 344 +# define SSL_F_SSL_SET_CERT 191 +# define SSL_F_SSL_SET_CIPHER_LIST 271 +# define SSL_F_SSL_SET_CT_VALIDATION_CALLBACK 399 +# define SSL_F_SSL_SET_FD 192 +# define SSL_F_SSL_SET_PKEY 193 +# define SSL_F_SSL_SET_RFD 194 +# define SSL_F_SSL_SET_SESSION 195 +# define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218 +# define SSL_F_SSL_SET_SESSION_TICKET_EXT 294 +# define SSL_F_SSL_SET_WFD 196 +# define SSL_F_SSL_SHUTDOWN 224 +# define SSL_F_SSL_SRP_CTX_INIT 313 +# define SSL_F_SSL_START_ASYNC_JOB 389 +# define SSL_F_SSL_UNDEFINED_FUNCTION 197 +# define SSL_F_SSL_UNDEFINED_VOID_FUNCTION 244 +# define SSL_F_SSL_USE_CERTIFICATE 198 +# define SSL_F_SSL_USE_CERTIFICATE_ASN1 199 +# define SSL_F_SSL_USE_CERTIFICATE_FILE 200 +# define SSL_F_SSL_USE_PRIVATEKEY 201 +# define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202 +# define SSL_F_SSL_USE_PRIVATEKEY_FILE 203 +# define SSL_F_SSL_USE_PSK_IDENTITY_HINT 273 +# define SSL_F_SSL_USE_RSAPRIVATEKEY 204 +# define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205 +# define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206 +# define SSL_F_SSL_VALIDATE_CT 400 +# define SSL_F_SSL_VERIFY_CERT_CHAIN 207 +# define SSL_F_SSL_WRITE 208 +# define SSL_F_STATE_MACHINE 353 +# define SSL_F_TLS12_CHECK_PEER_SIGALG 333 +# define SSL_F_TLS1_CHANGE_CIPHER_STATE 209 +# define SSL_F_TLS1_CHECK_DUPLICATE_EXTENSIONS 341 +# define SSL_F_TLS1_ENC 401 +# define SSL_F_TLS1_EXPORT_KEYING_MATERIAL 314 +# define SSL_F_TLS1_GET_CURVELIST 338 +# define SSL_F_TLS1_PRF 284 +# define SSL_F_TLS1_SETUP_KEY_BLOCK 211 +# define SSL_F_TLS1_SET_SERVER_SIGALGS 335 +# define SSL_F_TLS_CLIENT_KEY_EXCHANGE_POST_WORK 354 +# define SSL_F_TLS_CONSTRUCT_CERTIFICATE_REQUEST 372 +# define SSL_F_TLS_CONSTRUCT_CKE_DHE 404 +# define SSL_F_TLS_CONSTRUCT_CKE_ECDHE 405 +# define SSL_F_TLS_CONSTRUCT_CKE_GOST 406 +# define SSL_F_TLS_CONSTRUCT_CKE_PSK_PREAMBLE 407 +# define SSL_F_TLS_CONSTRUCT_CKE_RSA 409 +# define SSL_F_TLS_CONSTRUCT_CKE_SRP 410 +# define SSL_F_TLS_CONSTRUCT_CLIENT_CERTIFICATE 355 +# define SSL_F_TLS_CONSTRUCT_CLIENT_HELLO 356 +# define SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE 357 +# define SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY 358 +# define SSL_F_TLS_CONSTRUCT_FINISHED 359 +# define SSL_F_TLS_CONSTRUCT_HELLO_REQUEST 373 +# define SSL_F_TLS_CONSTRUCT_NEW_SESSION_TICKET 428 +# define SSL_F_TLS_CONSTRUCT_SERVER_CERTIFICATE 374 +# define SSL_F_TLS_CONSTRUCT_SERVER_DONE 375 +# define SSL_F_TLS_CONSTRUCT_SERVER_HELLO 376 +# define SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE 377 +# define SSL_F_TLS_GET_MESSAGE_BODY 351 +# define SSL_F_TLS_GET_MESSAGE_HEADER 387 +# define SSL_F_TLS_POST_PROCESS_CLIENT_HELLO 378 +# define SSL_F_TLS_POST_PROCESS_CLIENT_KEY_EXCHANGE 384 +# define SSL_F_TLS_PREPARE_CLIENT_CERTIFICATE 360 +# define SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST 361 +# define SSL_F_TLS_PROCESS_CERT_STATUS 362 +# define SSL_F_TLS_PROCESS_CERT_VERIFY 379 +# define SSL_F_TLS_PROCESS_CHANGE_CIPHER_SPEC 363 +# define SSL_F_TLS_PROCESS_CKE_DHE 411 +# define SSL_F_TLS_PROCESS_CKE_ECDHE 412 +# define SSL_F_TLS_PROCESS_CKE_GOST 413 +# define SSL_F_TLS_PROCESS_CKE_PSK_PREAMBLE 414 +# define SSL_F_TLS_PROCESS_CKE_RSA 415 +# define SSL_F_TLS_PROCESS_CKE_SRP 416 +# define SSL_F_TLS_PROCESS_CLIENT_CERTIFICATE 380 +# define SSL_F_TLS_PROCESS_CLIENT_HELLO 381 +# define SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE 382 +# define SSL_F_TLS_PROCESS_FINISHED 364 +# define SSL_F_TLS_PROCESS_KEY_EXCHANGE 365 +# define SSL_F_TLS_PROCESS_NEW_SESSION_TICKET 366 +# define SSL_F_TLS_PROCESS_NEXT_PROTO 383 +# define SSL_F_TLS_PROCESS_SERVER_CERTIFICATE 367 +# define SSL_F_TLS_PROCESS_SERVER_DONE 368 +# define SSL_F_TLS_PROCESS_SERVER_HELLO 369 +# define SSL_F_TLS_PROCESS_SKE_DHE 419 +# define SSL_F_TLS_PROCESS_SKE_ECDHE 420 +# define SSL_F_TLS_PROCESS_SKE_PSK_PREAMBLE 421 +# define SSL_F_TLS_PROCESS_SKE_SRP 422 +# define SSL_F_USE_CERTIFICATE_CHAIN_FILE 220 + +/* Reason codes. */ +# define SSL_R_APP_DATA_IN_HANDSHAKE 100 +# define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272 +# define SSL_R_AT_LEAST_TLS_1_0_NEEDED_IN_FIPS_MODE 143 +# define SSL_R_AT_LEAST_TLS_1_2_NEEDED_IN_SUITEB_MODE 158 +# define SSL_R_BAD_CHANGE_CIPHER_SPEC 103 +# define SSL_R_BAD_DATA 390 +# define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106 +# define SSL_R_BAD_DECOMPRESSION 107 +# define SSL_R_BAD_DH_VALUE 102 +# define SSL_R_BAD_DIGEST_LENGTH 111 +# define SSL_R_BAD_ECC_CERT 304 +# define SSL_R_BAD_ECPOINT 306 +# define SSL_R_BAD_HANDSHAKE_LENGTH 332 +# define SSL_R_BAD_HELLO_REQUEST 105 +# define SSL_R_BAD_LENGTH 271 +# define SSL_R_BAD_PACKET_LENGTH 115 +# define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116 +# define SSL_R_BAD_RSA_ENCRYPT 119 +# define SSL_R_BAD_SIGNATURE 123 +# define SSL_R_BAD_SRP_A_LENGTH 347 +# define SSL_R_BAD_SRP_PARAMETERS 371 +# define SSL_R_BAD_SRTP_MKI_VALUE 352 +# define SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST 353 +# define SSL_R_BAD_SSL_FILETYPE 124 +# define SSL_R_BAD_VALUE 384 +# define SSL_R_BAD_WRITE_RETRY 127 +# define SSL_R_BIO_NOT_SET 128 +# define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129 +# define SSL_R_BN_LIB 130 +# define SSL_R_CA_DN_LENGTH_MISMATCH 131 +# define SSL_R_CA_KEY_TOO_SMALL 397 +# define SSL_R_CA_MD_TOO_WEAK 398 +# define SSL_R_CCS_RECEIVED_EARLY 133 +# define SSL_R_CERTIFICATE_VERIFY_FAILED 134 +# define SSL_R_CERT_CB_ERROR 377 +# define SSL_R_CERT_LENGTH_MISMATCH 135 +# define SSL_R_CIPHER_CODE_WRONG_LENGTH 137 +# define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138 +# define SSL_R_CLIENTHELLO_TLSEXT 226 +# define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140 +# define SSL_R_COMPRESSION_DISABLED 343 +# define SSL_R_COMPRESSION_FAILURE 141 +# define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE 307 +# define SSL_R_COMPRESSION_LIBRARY_ERROR 142 +# define SSL_R_CONNECTION_TYPE_NOT_SET 144 +# define SSL_R_CONTEXT_NOT_DANE_ENABLED 167 +# define SSL_R_COOKIE_GEN_CALLBACK_FAILURE 400 +# define SSL_R_COOKIE_MISMATCH 308 +# define SSL_R_CUSTOM_EXT_HANDLER_ALREADY_INSTALLED 206 +# define SSL_R_DANE_ALREADY_ENABLED 172 +# define SSL_R_DANE_CANNOT_OVERRIDE_MTYPE_FULL 173 +# define SSL_R_DANE_NOT_ENABLED 175 +# define SSL_R_DANE_TLSA_BAD_CERTIFICATE 180 +# define SSL_R_DANE_TLSA_BAD_CERTIFICATE_USAGE 184 +# define SSL_R_DANE_TLSA_BAD_DATA_LENGTH 189 +# define SSL_R_DANE_TLSA_BAD_DIGEST_LENGTH 192 +# define SSL_R_DANE_TLSA_BAD_MATCHING_TYPE 200 +# define SSL_R_DANE_TLSA_BAD_PUBLIC_KEY 201 +# define SSL_R_DANE_TLSA_BAD_SELECTOR 202 +# define SSL_R_DANE_TLSA_NULL_DATA 203 +# define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145 +# define SSL_R_DATA_LENGTH_TOO_LONG 146 +# define SSL_R_DECRYPTION_FAILED 147 +# define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281 +# define SSL_R_DH_KEY_TOO_SMALL 394 +# define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148 +# define SSL_R_DIGEST_CHECK_FAILED 149 +# define SSL_R_DTLS_MESSAGE_TOO_BIG 334 +# define SSL_R_DUPLICATE_COMPRESSION_ID 309 +# define SSL_R_ECC_CERT_NOT_FOR_SIGNING 318 +# define SSL_R_ECDH_REQUIRED_FOR_SUITEB_MODE 374 +# define SSL_R_EE_KEY_TOO_SMALL 399 +# define SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST 354 +# define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150 +# define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151 +# define SSL_R_ERROR_SETTING_TLSA_BASE_DOMAIN 204 +# define SSL_R_EXCESSIVE_MESSAGE_SIZE 152 +# define SSL_R_EXTRA_DATA_IN_MESSAGE 153 +# define SSL_R_FAILED_TO_INIT_ASYNC 405 +# define SSL_R_FRAGMENTED_CLIENT_HELLO 401 +# define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154 +# define SSL_R_HTTPS_PROXY_REQUEST 155 +# define SSL_R_HTTP_REQUEST 156 +# define SSL_R_ILLEGAL_SUITEB_DIGEST 380 +# define SSL_R_INAPPROPRIATE_FALLBACK 373 +# define SSL_R_INCONSISTENT_COMPRESSION 340 +# define SSL_R_INCONSISTENT_EXTMS 104 +# define SSL_R_INVALID_COMMAND 280 +# define SSL_R_INVALID_COMPRESSION_ALGORITHM 341 +# define SSL_R_INVALID_CONFIGURATION_NAME 113 +# define SSL_R_INVALID_CT_VALIDATION_TYPE 212 +# define SSL_R_INVALID_NULL_CMD_NAME 385 +# define SSL_R_INVALID_SEQUENCE_NUMBER 402 +# define SSL_R_INVALID_SERVERINFO_DATA 388 +# define SSL_R_INVALID_SRP_USERNAME 357 +# define SSL_R_INVALID_STATUS_RESPONSE 328 +# define SSL_R_INVALID_TICKET_KEYS_LENGTH 325 +# define SSL_R_LENGTH_MISMATCH 159 +# define SSL_R_LENGTH_TOO_LONG 404 +# define SSL_R_LENGTH_TOO_SHORT 160 +# define SSL_R_LIBRARY_BUG 274 +# define SSL_R_LIBRARY_HAS_NO_CIPHERS 161 +# define SSL_R_MISSING_DSA_SIGNING_CERT 165 +# define SSL_R_MISSING_ECDSA_SIGNING_CERT 381 +# define SSL_R_MISSING_RSA_CERTIFICATE 168 +# define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169 +# define SSL_R_MISSING_RSA_SIGNING_CERT 170 +# define SSL_R_MISSING_SRP_PARAM 358 +# define SSL_R_MISSING_TMP_DH_KEY 171 +# define SSL_R_MISSING_TMP_ECDH_KEY 311 +# define SSL_R_NO_CERTIFICATES_RETURNED 176 +# define SSL_R_NO_CERTIFICATE_ASSIGNED 177 +# define SSL_R_NO_CERTIFICATE_SET 179 +# define SSL_R_NO_CIPHERS_AVAILABLE 181 +# define SSL_R_NO_CIPHERS_SPECIFIED 183 +# define SSL_R_NO_CIPHER_MATCH 185 +# define SSL_R_NO_CLIENT_CERT_METHOD 331 +# define SSL_R_NO_COMPRESSION_SPECIFIED 187 +# define SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER 330 +# define SSL_R_NO_METHOD_SPECIFIED 188 +# define SSL_R_NO_PEM_EXTENSIONS 389 +# define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190 +# define SSL_R_NO_PROTOCOLS_AVAILABLE 191 +# define SSL_R_NO_RENEGOTIATION 339 +# define SSL_R_NO_REQUIRED_DIGEST 324 +# define SSL_R_NO_SHARED_CIPHER 193 +# define SSL_R_NO_SHARED_SIGNATURE_ALGORITHMS 376 +# define SSL_R_NO_SRTP_PROFILES 359 +# define SSL_R_NO_VALID_SCTS 216 +# define SSL_R_NO_VERIFY_COOKIE_CALLBACK 403 +# define SSL_R_NULL_SSL_CTX 195 +# define SSL_R_NULL_SSL_METHOD_PASSED 196 +# define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197 +# define SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED 344 +# define SSL_R_PACKET_LENGTH_TOO_LONG 198 +# define SSL_R_PARSE_TLSEXT 227 +# define SSL_R_PATH_TOO_LONG 270 +# define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199 +# define SSL_R_PEM_NAME_BAD_PREFIX 391 +# define SSL_R_PEM_NAME_TOO_SHORT 392 +# define SSL_R_PIPELINE_FAILURE 406 +# define SSL_R_PROTOCOL_IS_SHUTDOWN 207 +# define SSL_R_PSK_IDENTITY_NOT_FOUND 223 +# define SSL_R_PSK_NO_CLIENT_CB 224 +# define SSL_R_PSK_NO_SERVER_CB 225 +# define SSL_R_READ_BIO_NOT_SET 211 +# define SSL_R_READ_TIMEOUT_EXPIRED 312 +# define SSL_R_RECORD_LENGTH_MISMATCH 213 +# define SSL_R_RECORD_TOO_SMALL 298 +# define SSL_R_RENEGOTIATE_EXT_TOO_LONG 335 +# define SSL_R_RENEGOTIATION_ENCODING_ERR 336 +# define SSL_R_RENEGOTIATION_MISMATCH 337 +# define SSL_R_REQUIRED_CIPHER_MISSING 215 +# define SSL_R_REQUIRED_COMPRESSION_ALGORITHM_MISSING 342 +# define SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING 345 +# define SSL_R_SCT_VERIFICATION_FAILED 208 +# define SSL_R_SERVERHELLO_TLSEXT 275 +# define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277 +# define SSL_R_SHUTDOWN_WHILE_IN_INIT 407 +# define SSL_R_SIGNATURE_ALGORITHMS_ERROR 360 +# define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220 +# define SSL_R_SRP_A_CALC 361 +# define SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES 362 +# define SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG 363 +# define SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE 364 +# define SSL_R_SSL3_EXT_INVALID_SERVERNAME 319 +# define SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE 320 +# define SSL_R_SSL3_SESSION_ID_TOO_LONG 300 +# define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 +# define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020 +# define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045 +# define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044 +# define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046 +# define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030 +# define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040 +# define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047 +# define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041 +# define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010 +# define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043 +# define SSL_R_SSL_COMMAND_SECTION_EMPTY 117 +# define SSL_R_SSL_COMMAND_SECTION_NOT_FOUND 125 +# define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228 +# define SSL_R_SSL_HANDSHAKE_FAILURE 229 +# define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230 +# define SSL_R_SSL_NEGATIVE_LENGTH 372 +# define SSL_R_SSL_SECTION_EMPTY 126 +# define SSL_R_SSL_SECTION_NOT_FOUND 136 +# define SSL_R_SSL_SESSION_ID_CALLBACK_FAILED 301 +# define SSL_R_SSL_SESSION_ID_CONFLICT 302 +# define SSL_R_SSL_SESSION_ID_TOO_LONG 408 +# define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273 +# define SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH 303 +# define SSL_R_SSL_SESSION_VERSION_MISMATCH 210 +# define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049 +# define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050 +# define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021 +# define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051 +# define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060 +# define SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK 1086 +# define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071 +# define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080 +# define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100 +# define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070 +# define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022 +# define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048 +# define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090 +# define SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE 1114 +# define SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE 1113 +# define SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE 1111 +# define SSL_R_TLSV1_UNRECOGNIZED_NAME 1112 +# define SSL_R_TLSV1_UNSUPPORTED_EXTENSION 1110 +# define SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT 365 +# define SSL_R_TLS_HEARTBEAT_PENDING 366 +# define SSL_R_TLS_ILLEGAL_EXPORTER_LABEL 367 +# define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST 157 +# define SSL_R_TOO_MANY_WARN_ALERTS 409 +# define SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS 314 +# define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239 +# define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242 +# define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243 +# define SSL_R_UNEXPECTED_MESSAGE 244 +# define SSL_R_UNEXPECTED_RECORD 245 +# define SSL_R_UNINITIALIZED 276 +# define SSL_R_UNKNOWN_ALERT_TYPE 246 +# define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247 +# define SSL_R_UNKNOWN_CIPHER_RETURNED 248 +# define SSL_R_UNKNOWN_CIPHER_TYPE 249 +# define SSL_R_UNKNOWN_CMD_NAME 386 +# define SSL_R_UNKNOWN_COMMAND 139 +# define SSL_R_UNKNOWN_DIGEST 368 +# define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250 +# define SSL_R_UNKNOWN_PKEY_TYPE 251 +# define SSL_R_UNKNOWN_PROTOCOL 252 +# define SSL_R_UNKNOWN_SSL_VERSION 254 +# define SSL_R_UNKNOWN_STATE 255 +# define SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED 338 +# define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257 +# define SSL_R_UNSUPPORTED_ELLIPTIC_CURVE 315 +# define SSL_R_UNSUPPORTED_PROTOCOL 258 +# define SSL_R_UNSUPPORTED_SSL_VERSION 259 +# define SSL_R_UNSUPPORTED_STATUS_TYPE 329 +# define SSL_R_USE_SRTP_NOT_NEGOTIATED 369 +# define SSL_R_VERSION_TOO_HIGH 166 +# define SSL_R_VERSION_TOO_LOW 396 +# define SSL_R_WRONG_CERTIFICATE_TYPE 383 +# define SSL_R_WRONG_CIPHER_RETURNED 261 +# define SSL_R_WRONG_CURVE 378 +# define SSL_R_WRONG_SIGNATURE_LENGTH 264 +# define SSL_R_WRONG_SIGNATURE_SIZE 265 +# define SSL_R_WRONG_SIGNATURE_TYPE 370 +# define SSL_R_WRONG_SSL_VERSION 266 +# define SSL_R_WRONG_VERSION_NUMBER 267 +# define SSL_R_X509_LIB 268 +# define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/ssl2.h b/android/x86/include/openssl/ssl2.h new file mode 100644 index 00000000..5321bd27 --- /dev/null +++ b/android/x86/include/openssl/ssl2.h @@ -0,0 +1,24 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SSL2_H +# define HEADER_SSL2_H + +#ifdef __cplusplus +extern "C" { +#endif + +# define SSL2_VERSION 0x0002 + +# define SSL2_MT_CLIENT_HELLO 1 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/x86/include/openssl/ssl3.h b/android/x86/include/openssl/ssl3.h new file mode 100644 index 00000000..aca19223 --- /dev/null +++ b/android/x86/include/openssl/ssl3.h @@ -0,0 +1,307 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECC cipher suite support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ + +#ifndef HEADER_SSL3_H +# define HEADER_SSL3_H + +# include <openssl/comp.h> +# include <openssl/buffer.h> +# include <openssl/evp.h> +# include <openssl/ssl.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Signalling cipher suite value from RFC 5746 + * (TLS_EMPTY_RENEGOTIATION_INFO_SCSV) + */ +# define SSL3_CK_SCSV 0x030000FF + +/* + * Signalling cipher suite value from draft-ietf-tls-downgrade-scsv-00 + * (TLS_FALLBACK_SCSV) + */ +# define SSL3_CK_FALLBACK_SCSV 0x03005600 + +# define SSL3_CK_RSA_NULL_MD5 0x03000001 +# define SSL3_CK_RSA_NULL_SHA 0x03000002 +# define SSL3_CK_RSA_RC4_40_MD5 0x03000003 +# define SSL3_CK_RSA_RC4_128_MD5 0x03000004 +# define SSL3_CK_RSA_RC4_128_SHA 0x03000005 +# define SSL3_CK_RSA_RC2_40_MD5 0x03000006 +# define SSL3_CK_RSA_IDEA_128_SHA 0x03000007 +# define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008 +# define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009 +# define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A + +# define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B +# define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C +# define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D +# define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E +# define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F +# define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010 + +# define SSL3_CK_DHE_DSS_DES_40_CBC_SHA 0x03000011 +# define SSL3_CK_EDH_DSS_DES_40_CBC_SHA SSL3_CK_DHE_DSS_DES_40_CBC_SHA +# define SSL3_CK_DHE_DSS_DES_64_CBC_SHA 0x03000012 +# define SSL3_CK_EDH_DSS_DES_64_CBC_SHA SSL3_CK_DHE_DSS_DES_64_CBC_SHA +# define SSL3_CK_DHE_DSS_DES_192_CBC3_SHA 0x03000013 +# define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA SSL3_CK_DHE_DSS_DES_192_CBC3_SHA +# define SSL3_CK_DHE_RSA_DES_40_CBC_SHA 0x03000014 +# define SSL3_CK_EDH_RSA_DES_40_CBC_SHA SSL3_CK_DHE_RSA_DES_40_CBC_SHA +# define SSL3_CK_DHE_RSA_DES_64_CBC_SHA 0x03000015 +# define SSL3_CK_EDH_RSA_DES_64_CBC_SHA SSL3_CK_DHE_RSA_DES_64_CBC_SHA +# define SSL3_CK_DHE_RSA_DES_192_CBC3_SHA 0x03000016 +# define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA SSL3_CK_DHE_RSA_DES_192_CBC3_SHA + +# define SSL3_CK_ADH_RC4_40_MD5 0x03000017 +# define SSL3_CK_ADH_RC4_128_MD5 0x03000018 +# define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019 +# define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A +# define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B + +# define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5" +# define SSL3_TXT_RSA_NULL_SHA "NULL-SHA" +# define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5" +# define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5" +# define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA" +# define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5" +# define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA" +# define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA" +# define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA" +# define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA" + +# define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA" +# define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA" +# define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA" +# define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA" +# define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA" +# define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA" + +# define SSL3_TXT_DHE_DSS_DES_40_CBC_SHA "EXP-DHE-DSS-DES-CBC-SHA" +# define SSL3_TXT_DHE_DSS_DES_64_CBC_SHA "DHE-DSS-DES-CBC-SHA" +# define SSL3_TXT_DHE_DSS_DES_192_CBC3_SHA "DHE-DSS-DES-CBC3-SHA" +# define SSL3_TXT_DHE_RSA_DES_40_CBC_SHA "EXP-DHE-RSA-DES-CBC-SHA" +# define SSL3_TXT_DHE_RSA_DES_64_CBC_SHA "DHE-RSA-DES-CBC-SHA" +# define SSL3_TXT_DHE_RSA_DES_192_CBC3_SHA "DHE-RSA-DES-CBC3-SHA" + +/* + * This next block of six "EDH" labels is for backward compatibility with + * older versions of OpenSSL. New code should use the six "DHE" labels above + * instead: + */ +# define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA" +# define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA" +# define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA" +# define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA" +# define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA" +# define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA" + +# define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5" +# define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5" +# define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA" +# define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA" +# define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA" + +# define SSL3_SSL_SESSION_ID_LENGTH 32 +# define SSL3_MAX_SSL_SESSION_ID_LENGTH 32 + +# define SSL3_MASTER_SECRET_SIZE 48 +# define SSL3_RANDOM_SIZE 32 +# define SSL3_SESSION_ID_SIZE 32 +# define SSL3_RT_HEADER_LENGTH 5 + +# define SSL3_HM_HEADER_LENGTH 4 + +# ifndef SSL3_ALIGN_PAYLOAD + /* + * Some will argue that this increases memory footprint, but it's not + * actually true. Point is that malloc has to return at least 64-bit aligned + * pointers, meaning that allocating 5 bytes wastes 3 bytes in either case. + * Suggested pre-gaping simply moves these wasted bytes from the end of + * allocated region to its front, but makes data payload aligned, which + * improves performance:-) + */ +# define SSL3_ALIGN_PAYLOAD 8 +# else +# if (SSL3_ALIGN_PAYLOAD&(SSL3_ALIGN_PAYLOAD-1))!=0 +# error "insane SSL3_ALIGN_PAYLOAD" +# undef SSL3_ALIGN_PAYLOAD +# endif +# endif + +/* + * This is the maximum MAC (digest) size used by the SSL library. Currently + * maximum of 20 is used by SHA1, but we reserve for future extension for + * 512-bit hashes. + */ + +# define SSL3_RT_MAX_MD_SIZE 64 + +/* + * Maximum block size used in all ciphersuites. Currently 16 for AES. + */ + +# define SSL_RT_MAX_CIPHER_BLOCK_SIZE 16 + +# define SSL3_RT_MAX_EXTRA (16384) + +/* Maximum plaintext length: defined by SSL/TLS standards */ +# define SSL3_RT_MAX_PLAIN_LENGTH 16384 +/* Maximum compression overhead: defined by SSL/TLS standards */ +# define SSL3_RT_MAX_COMPRESSED_OVERHEAD 1024 + +/* + * The standards give a maximum encryption overhead of 1024 bytes. In + * practice the value is lower than this. The overhead is the maximum number + * of padding bytes (256) plus the mac size. + */ +# define SSL3_RT_MAX_ENCRYPTED_OVERHEAD (256 + SSL3_RT_MAX_MD_SIZE) + +/* + * OpenSSL currently only uses a padding length of at most one block so the + * send overhead is smaller. + */ + +# define SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD \ + (SSL_RT_MAX_CIPHER_BLOCK_SIZE + SSL3_RT_MAX_MD_SIZE) + +/* If compression isn't used don't include the compression overhead */ + +# ifdef OPENSSL_NO_COMP +# define SSL3_RT_MAX_COMPRESSED_LENGTH SSL3_RT_MAX_PLAIN_LENGTH +# else +# define SSL3_RT_MAX_COMPRESSED_LENGTH \ + (SSL3_RT_MAX_PLAIN_LENGTH+SSL3_RT_MAX_COMPRESSED_OVERHEAD) +# endif +# define SSL3_RT_MAX_ENCRYPTED_LENGTH \ + (SSL3_RT_MAX_ENCRYPTED_OVERHEAD+SSL3_RT_MAX_COMPRESSED_LENGTH) +# define SSL3_RT_MAX_PACKET_SIZE \ + (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH) + +# define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54" +# define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52" + +# define SSL3_VERSION 0x0300 +# define SSL3_VERSION_MAJOR 0x03 +# define SSL3_VERSION_MINOR 0x00 + +# define SSL3_RT_CHANGE_CIPHER_SPEC 20 +# define SSL3_RT_ALERT 21 +# define SSL3_RT_HANDSHAKE 22 +# define SSL3_RT_APPLICATION_DATA 23 +# define DTLS1_RT_HEARTBEAT 24 + +/* Pseudo content types to indicate additional parameters */ +# define TLS1_RT_CRYPTO 0x1000 +# define TLS1_RT_CRYPTO_PREMASTER (TLS1_RT_CRYPTO | 0x1) +# define TLS1_RT_CRYPTO_CLIENT_RANDOM (TLS1_RT_CRYPTO | 0x2) +# define TLS1_RT_CRYPTO_SERVER_RANDOM (TLS1_RT_CRYPTO | 0x3) +# define TLS1_RT_CRYPTO_MASTER (TLS1_RT_CRYPTO | 0x4) + +# define TLS1_RT_CRYPTO_READ 0x0000 +# define TLS1_RT_CRYPTO_WRITE 0x0100 +# define TLS1_RT_CRYPTO_MAC (TLS1_RT_CRYPTO | 0x5) +# define TLS1_RT_CRYPTO_KEY (TLS1_RT_CRYPTO | 0x6) +# define TLS1_RT_CRYPTO_IV (TLS1_RT_CRYPTO | 0x7) +# define TLS1_RT_CRYPTO_FIXED_IV (TLS1_RT_CRYPTO | 0x8) + +/* Pseudo content type for SSL/TLS header info */ +# define SSL3_RT_HEADER 0x100 + +# define SSL3_AL_WARNING 1 +# define SSL3_AL_FATAL 2 + +# define SSL3_AD_CLOSE_NOTIFY 0 +# define SSL3_AD_UNEXPECTED_MESSAGE 10/* fatal */ +# define SSL3_AD_BAD_RECORD_MAC 20/* fatal */ +# define SSL3_AD_DECOMPRESSION_FAILURE 30/* fatal */ +# define SSL3_AD_HANDSHAKE_FAILURE 40/* fatal */ +# define SSL3_AD_NO_CERTIFICATE 41 +# define SSL3_AD_BAD_CERTIFICATE 42 +# define SSL3_AD_UNSUPPORTED_CERTIFICATE 43 +# define SSL3_AD_CERTIFICATE_REVOKED 44 +# define SSL3_AD_CERTIFICATE_EXPIRED 45 +# define SSL3_AD_CERTIFICATE_UNKNOWN 46 +# define SSL3_AD_ILLEGAL_PARAMETER 47/* fatal */ + +# define TLS1_HB_REQUEST 1 +# define TLS1_HB_RESPONSE 2 + + +# define SSL3_CT_RSA_SIGN 1 +# define SSL3_CT_DSS_SIGN 2 +# define SSL3_CT_RSA_FIXED_DH 3 +# define SSL3_CT_DSS_FIXED_DH 4 +# define SSL3_CT_RSA_EPHEMERAL_DH 5 +# define SSL3_CT_DSS_EPHEMERAL_DH 6 +# define SSL3_CT_FORTEZZA_DMS 20 +/* + * SSL3_CT_NUMBER is used to size arrays and it must be large enough to + * contain all of the cert types defined either for SSLv3 and TLSv1. + */ +# define SSL3_CT_NUMBER 9 + +# define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 + +/* Removed from OpenSSL 1.1.0 */ +# define TLS1_FLAGS_TLS_PADDING_BUG 0x0 + +# define TLS1_FLAGS_SKIP_CERT_VERIFY 0x0010 + +/* Set if we encrypt then mac instead of usual mac then encrypt */ +# define TLS1_FLAGS_ENCRYPT_THEN_MAC 0x0100 + +/* Set if extended master secret extension received from peer */ +# define TLS1_FLAGS_RECEIVED_EXTMS 0x0200 + +# define SSL3_MT_HELLO_REQUEST 0 +# define SSL3_MT_CLIENT_HELLO 1 +# define SSL3_MT_SERVER_HELLO 2 +# define SSL3_MT_NEWSESSION_TICKET 4 +# define SSL3_MT_CERTIFICATE 11 +# define SSL3_MT_SERVER_KEY_EXCHANGE 12 +# define SSL3_MT_CERTIFICATE_REQUEST 13 +# define SSL3_MT_SERVER_DONE 14 +# define SSL3_MT_CERTIFICATE_VERIFY 15 +# define SSL3_MT_CLIENT_KEY_EXCHANGE 16 +# define SSL3_MT_FINISHED 20 +# define SSL3_MT_CERTIFICATE_STATUS 22 +# ifndef OPENSSL_NO_NEXTPROTONEG +# define SSL3_MT_NEXT_PROTO 67 +# endif +# define DTLS1_MT_HELLO_VERIFY_REQUEST 3 + +/* Dummy message type for handling CCS like a normal handshake message */ +# define SSL3_MT_CHANGE_CIPHER_SPEC 0x0101 + +# define SSL3_MT_CCS 1 + +/* These are used when changing over to a new cipher */ +# define SSL3_CC_READ 0x01 +# define SSL3_CC_WRITE 0x02 +# define SSL3_CC_CLIENT 0x10 +# define SSL3_CC_SERVER 0x20 +# define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE) +# define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ) +# define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ) +# define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE) + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/x86/include/openssl/stack.h b/android/x86/include/openssl/stack.h new file mode 100644 index 00000000..23ad3b89 --- /dev/null +++ b/android/x86/include/openssl/stack.h @@ -0,0 +1,78 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_STACK_H +# define HEADER_STACK_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct stack_st OPENSSL_STACK; /* Use STACK_OF(...) instead */ + +typedef int (*OPENSSL_sk_compfunc)(const void *, const void *); +typedef void (*OPENSSL_sk_freefunc)(void *); +typedef void *(*OPENSSL_sk_copyfunc)(const void *); + +int OPENSSL_sk_num(const OPENSSL_STACK *); +void *OPENSSL_sk_value(const OPENSSL_STACK *, int); + +void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data); + +OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc cmp); +OPENSSL_STACK *OPENSSL_sk_new_null(void); +void OPENSSL_sk_free(OPENSSL_STACK *); +void OPENSSL_sk_pop_free(OPENSSL_STACK *st, void (*func) (void *)); +OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *, OPENSSL_sk_copyfunc c, OPENSSL_sk_freefunc f); +int OPENSSL_sk_insert(OPENSSL_STACK *sk, const void *data, int where); +void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc); +void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p); +int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data); +int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data); +int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data); +int OPENSSL_sk_unshift(OPENSSL_STACK *st, const void *data); +void *OPENSSL_sk_shift(OPENSSL_STACK *st); +void *OPENSSL_sk_pop(OPENSSL_STACK *st); +void OPENSSL_sk_zero(OPENSSL_STACK *st); +OPENSSL_sk_compfunc OPENSSL_sk_set_cmp_func(OPENSSL_STACK *sk, OPENSSL_sk_compfunc cmp); +OPENSSL_STACK *OPENSSL_sk_dup(const OPENSSL_STACK *st); +void OPENSSL_sk_sort(OPENSSL_STACK *st); +int OPENSSL_sk_is_sorted(const OPENSSL_STACK *st); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define _STACK OPENSSL_STACK +# define sk_num OPENSSL_sk_num +# define sk_value OPENSSL_sk_value +# define sk_set OPENSSL_sk_set +# define sk_new OPENSSL_sk_new +# define sk_new_null OPENSSL_sk_new_null +# define sk_free OPENSSL_sk_free +# define sk_pop_free OPENSSL_sk_pop_free +# define sk_deep_copy OPENSSL_sk_deep_copy +# define sk_insert OPENSSL_sk_insert +# define sk_delete OPENSSL_sk_delete +# define sk_delete_ptr OPENSSL_sk_delete_ptr +# define sk_find OPENSSL_sk_find +# define sk_find_ex OPENSSL_sk_find_ex +# define sk_push OPENSSL_sk_push +# define sk_unshift OPENSSL_sk_unshift +# define sk_shift OPENSSL_sk_shift +# define sk_pop OPENSSL_sk_pop +# define sk_zero OPENSSL_sk_zero +# define sk_set_cmp_func OPENSSL_sk_set_cmp_func +# define sk_dup OPENSSL_sk_dup +# define sk_sort OPENSSL_sk_sort +# define sk_is_sorted OPENSSL_sk_is_sorted +# endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/android/x86/include/openssl/symhacks.h b/android/x86/include/openssl/symhacks.h new file mode 100644 index 00000000..caf1f1a7 --- /dev/null +++ b/android/x86/include/openssl/symhacks.h @@ -0,0 +1,52 @@ +/* + * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SYMHACKS_H +# define HEADER_SYMHACKS_H + +# include <openssl/e_os2.h> + +/* Case insensitive linking causes problems.... */ +# if defined(OPENSSL_SYS_VMS) +# undef ERR_load_CRYPTO_strings +# define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings +# undef OCSP_crlID_new +# define OCSP_crlID_new OCSP_crlID2_new + +# undef d2i_ECPARAMETERS +# define d2i_ECPARAMETERS d2i_UC_ECPARAMETERS +# undef i2d_ECPARAMETERS +# define i2d_ECPARAMETERS i2d_UC_ECPARAMETERS +# undef d2i_ECPKPARAMETERS +# define d2i_ECPKPARAMETERS d2i_UC_ECPKPARAMETERS +# undef i2d_ECPKPARAMETERS +# define i2d_ECPKPARAMETERS i2d_UC_ECPKPARAMETERS + +/* + * These functions do not seem to exist! However, I'm paranoid... Original + * command in x509v3.h: These functions are being redefined in another + * directory, and clash when the linker is case-insensitive, so let's hide + * them a little, by giving them an extra 'o' at the beginning of the name... + */ +# undef X509v3_cleanup_extensions +# define X509v3_cleanup_extensions oX509v3_cleanup_extensions +# undef X509v3_add_extension +# define X509v3_add_extension oX509v3_add_extension +# undef X509v3_add_netscape_extensions +# define X509v3_add_netscape_extensions oX509v3_add_netscape_extensions +# undef X509v3_add_standard_extensions +# define X509v3_add_standard_extensions oX509v3_add_standard_extensions + +/* This one clashes with CMS_data_create */ +# undef cms_Data_create +# define cms_Data_create priv_cms_Data_create + +# endif + +#endif /* ! defined HEADER_VMS_IDHACKS_H */ diff --git a/android/x86/include/openssl/tls1.h b/android/x86/include/openssl/tls1.h new file mode 100644 index 00000000..23e382cd --- /dev/null +++ b/android/x86/include/openssl/tls1.h @@ -0,0 +1,972 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * + * Portions of the attached software ("Contribution") are developed by + * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. + * + * The Contribution is licensed pursuant to the OpenSSL open source + * license provided above. + * + * ECC cipher suite support in OpenSSL originally written by + * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories. + * + */ +/* ==================================================================== + * Copyright 2005 Nokia. All rights reserved. + * + * The portions of the attached software ("Contribution") is developed by + * Nokia Corporation and is licensed pursuant to the OpenSSL open source + * license. + * + * The Contribution, originally written by Mika Kousa and Pasi Eronen of + * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites + * support (see RFC 4279) to OpenSSL. + * + * No patent licenses or other rights except those expressly stated in + * the OpenSSL open source license shall be deemed granted or received + * expressly, by implication, estoppel, or otherwise. + * + * No assurances are provided by Nokia that the Contribution does not + * infringe the patent or other intellectual property rights of any third + * party or that the license provides you with all the necessary rights + * to make use of the Contribution. + * + * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN + * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA + * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY + * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR + * OTHERWISE. + */ + +#ifndef HEADER_TLS1_H +# define HEADER_TLS1_H + +# include <openssl/buffer.h> +# include <openssl/x509.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Default security level if not overridden at config time */ +# ifndef OPENSSL_TLS_SECURITY_LEVEL +# define OPENSSL_TLS_SECURITY_LEVEL 1 +# endif + +# define TLS1_VERSION 0x0301 +# define TLS1_1_VERSION 0x0302 +# define TLS1_2_VERSION 0x0303 +# define TLS_MAX_VERSION TLS1_2_VERSION + +/* Special value for method supporting multiple versions */ +# define TLS_ANY_VERSION 0x10000 + +# define TLS1_VERSION_MAJOR 0x03 +# define TLS1_VERSION_MINOR 0x01 + +# define TLS1_1_VERSION_MAJOR 0x03 +# define TLS1_1_VERSION_MINOR 0x02 + +# define TLS1_2_VERSION_MAJOR 0x03 +# define TLS1_2_VERSION_MINOR 0x03 + +# define TLS1_get_version(s) \ + ((SSL_version(s) >> 8) == TLS1_VERSION_MAJOR ? SSL_version(s) : 0) + +# define TLS1_get_client_version(s) \ + ((SSL_client_version(s) >> 8) == TLS1_VERSION_MAJOR ? SSL_client_version(s) : 0) + +# define TLS1_AD_DECRYPTION_FAILED 21 +# define TLS1_AD_RECORD_OVERFLOW 22 +# define TLS1_AD_UNKNOWN_CA 48/* fatal */ +# define TLS1_AD_ACCESS_DENIED 49/* fatal */ +# define TLS1_AD_DECODE_ERROR 50/* fatal */ +# define TLS1_AD_DECRYPT_ERROR 51 +# define TLS1_AD_EXPORT_RESTRICTION 60/* fatal */ +# define TLS1_AD_PROTOCOL_VERSION 70/* fatal */ +# define TLS1_AD_INSUFFICIENT_SECURITY 71/* fatal */ +# define TLS1_AD_INTERNAL_ERROR 80/* fatal */ +# define TLS1_AD_INAPPROPRIATE_FALLBACK 86/* fatal */ +# define TLS1_AD_USER_CANCELLED 90 +# define TLS1_AD_NO_RENEGOTIATION 100 +/* codes 110-114 are from RFC3546 */ +# define TLS1_AD_UNSUPPORTED_EXTENSION 110 +# define TLS1_AD_CERTIFICATE_UNOBTAINABLE 111 +# define TLS1_AD_UNRECOGNIZED_NAME 112 +# define TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE 113 +# define TLS1_AD_BAD_CERTIFICATE_HASH_VALUE 114 +# define TLS1_AD_UNKNOWN_PSK_IDENTITY 115/* fatal */ +# define TLS1_AD_NO_APPLICATION_PROTOCOL 120 /* fatal */ + +/* ExtensionType values from RFC3546 / RFC4366 / RFC6066 */ +# define TLSEXT_TYPE_server_name 0 +# define TLSEXT_TYPE_max_fragment_length 1 +# define TLSEXT_TYPE_client_certificate_url 2 +# define TLSEXT_TYPE_trusted_ca_keys 3 +# define TLSEXT_TYPE_truncated_hmac 4 +# define TLSEXT_TYPE_status_request 5 +/* ExtensionType values from RFC4681 */ +# define TLSEXT_TYPE_user_mapping 6 +/* ExtensionType values from RFC5878 */ +# define TLSEXT_TYPE_client_authz 7 +# define TLSEXT_TYPE_server_authz 8 +/* ExtensionType values from RFC6091 */ +# define TLSEXT_TYPE_cert_type 9 + +/* ExtensionType values from RFC4492 */ +# define TLSEXT_TYPE_elliptic_curves 10 +# define TLSEXT_TYPE_ec_point_formats 11 + +/* ExtensionType value from RFC5054 */ +# define TLSEXT_TYPE_srp 12 + +/* ExtensionType values from RFC5246 */ +# define TLSEXT_TYPE_signature_algorithms 13 + +/* ExtensionType value from RFC5764 */ +# define TLSEXT_TYPE_use_srtp 14 + +/* ExtensionType value from RFC5620 */ +# define TLSEXT_TYPE_heartbeat 15 + +/* ExtensionType value from RFC7301 */ +# define TLSEXT_TYPE_application_layer_protocol_negotiation 16 + +/* + * Extension type for Certificate Transparency + * https://tools.ietf.org/html/rfc6962#section-3.3.1 + */ +# define TLSEXT_TYPE_signed_certificate_timestamp 18 + +/* + * ExtensionType value for TLS padding extension. + * http://tools.ietf.org/html/draft-agl-tls-padding + */ +# define TLSEXT_TYPE_padding 21 + +/* ExtensionType value from RFC7366 */ +# define TLSEXT_TYPE_encrypt_then_mac 22 + +/* ExtensionType value from RFC7627 */ +# define TLSEXT_TYPE_extended_master_secret 23 + +/* ExtensionType value from RFC4507 */ +# define TLSEXT_TYPE_session_ticket 35 + +/* Temporary extension type */ +# define TLSEXT_TYPE_renegotiate 0xff01 + +# ifndef OPENSSL_NO_NEXTPROTONEG +/* This is not an IANA defined extension number */ +# define TLSEXT_TYPE_next_proto_neg 13172 +# endif + +/* NameType value from RFC3546 */ +# define TLSEXT_NAMETYPE_host_name 0 +/* status request value from RFC3546 */ +# define TLSEXT_STATUSTYPE_ocsp 1 + +/* ECPointFormat values from RFC4492 */ +# define TLSEXT_ECPOINTFORMAT_first 0 +# define TLSEXT_ECPOINTFORMAT_uncompressed 0 +# define TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime 1 +# define TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2 2 +# define TLSEXT_ECPOINTFORMAT_last 2 + +/* Signature and hash algorithms from RFC5246 */ +# define TLSEXT_signature_anonymous 0 +# define TLSEXT_signature_rsa 1 +# define TLSEXT_signature_dsa 2 +# define TLSEXT_signature_ecdsa 3 +# define TLSEXT_signature_gostr34102001 237 +# define TLSEXT_signature_gostr34102012_256 238 +# define TLSEXT_signature_gostr34102012_512 239 + +/* Total number of different signature algorithms */ +# define TLSEXT_signature_num 7 + +# define TLSEXT_hash_none 0 +# define TLSEXT_hash_md5 1 +# define TLSEXT_hash_sha1 2 +# define TLSEXT_hash_sha224 3 +# define TLSEXT_hash_sha256 4 +# define TLSEXT_hash_sha384 5 +# define TLSEXT_hash_sha512 6 +# define TLSEXT_hash_gostr3411 237 +# define TLSEXT_hash_gostr34112012_256 238 +# define TLSEXT_hash_gostr34112012_512 239 + +/* Total number of different digest algorithms */ + +# define TLSEXT_hash_num 10 + +/* Flag set for unrecognised algorithms */ +# define TLSEXT_nid_unknown 0x1000000 + +/* ECC curves */ + +# define TLSEXT_curve_P_256 23 +# define TLSEXT_curve_P_384 24 + +# define TLSEXT_MAXLEN_host_name 255 + +__owur const char *SSL_get_servername(const SSL *s, const int type); +__owur int SSL_get_servername_type(const SSL *s); +/* + * SSL_export_keying_material exports a value derived from the master secret, + * as specified in RFC 5705. It writes |olen| bytes to |out| given a label and + * optional context. (Since a zero length context is allowed, the |use_context| + * flag controls whether a context is included.) It returns 1 on success and + * zero otherwise. + */ +__owur int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen, + const char *label, size_t llen, + const unsigned char *p, size_t plen, + int use_context); + +int SSL_get_sigalgs(SSL *s, int idx, + int *psign, int *phash, int *psignandhash, + unsigned char *rsig, unsigned char *rhash); + +int SSL_get_shared_sigalgs(SSL *s, int idx, + int *psign, int *phash, int *psignandhash, + unsigned char *rsig, unsigned char *rhash); + +__owur int SSL_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain); + +# define SSL_set_tlsext_host_name(s,name) \ +SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,(char *)name) + +# define SSL_set_tlsext_debug_callback(ssl, cb) \ +SSL_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_CB,(void (*)(void))cb) + +# define SSL_set_tlsext_debug_arg(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_ARG,0, (void *)arg) + +# define SSL_get_tlsext_status_type(ssl) \ +SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE,0, NULL) + +# define SSL_set_tlsext_status_type(ssl, type) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE,type, NULL) + +# define SSL_get_tlsext_status_exts(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS,0, (void *)arg) + +# define SSL_set_tlsext_status_exts(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS,0, (void *)arg) + +# define SSL_get_tlsext_status_ids(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS,0, (void *)arg) + +# define SSL_set_tlsext_status_ids(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS,0, (void *)arg) + +# define SSL_get_tlsext_status_ocsp_resp(ssl, arg) \ +SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP,0, (void *)arg) + +# define SSL_set_tlsext_status_ocsp_resp(ssl, arg, arglen) \ +SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP,arglen, (void *)arg) + +# define SSL_CTX_set_tlsext_servername_callback(ctx, cb) \ +SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_CB,(void (*)(void))cb) + +# define SSL_TLSEXT_ERR_OK 0 +# define SSL_TLSEXT_ERR_ALERT_WARNING 1 +# define SSL_TLSEXT_ERR_ALERT_FATAL 2 +# define SSL_TLSEXT_ERR_NOACK 3 + +# define SSL_CTX_set_tlsext_servername_arg(ctx, arg) \ +SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG,0, (void *)arg) + +# define SSL_CTX_get_tlsext_ticket_keys(ctx, keys, keylen) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_GET_TLSEXT_TICKET_KEYS,(keylen),(keys)) +# define SSL_CTX_set_tlsext_ticket_keys(ctx, keys, keylen) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_SET_TLSEXT_TICKET_KEYS,(keylen),(keys)) + +# define SSL_CTX_get_tlsext_status_cb(ssl, cb) \ +SSL_CTX_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB,0, (void (**)(void))cb) +# define SSL_CTX_set_tlsext_status_cb(ssl, cb) \ +SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB,(void (*)(void))cb) + +# define SSL_CTX_get_tlsext_status_arg(ssl, arg) \ +SSL_CTX_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG,0, (void *)arg +# define SSL_CTX_set_tlsext_status_arg(ssl, arg) \ +SSL_CTX_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG,0, (void *)arg) + +#define SSL_CTX_set_tlsext_status_type(ssl, type) \ + SSL_CTX_ctrl(ssl, SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE, type, NULL) + +#define SSL_CTX_get_tlsext_status_type(ssl) \ + SSL_CTX_ctrl(ssl, SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE, 0, NULL) + +# define SSL_CTX_set_tlsext_ticket_key_cb(ssl, cb) \ +SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb) + +# ifndef OPENSSL_NO_HEARTBEATS +# define SSL_DTLSEXT_HB_ENABLED 0x01 +# define SSL_DTLSEXT_HB_DONT_SEND_REQUESTS 0x02 +# define SSL_DTLSEXT_HB_DONT_RECV_REQUESTS 0x04 +# define SSL_get_dtlsext_heartbeat_pending(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING,0,NULL) +# define SSL_set_dtlsext_heartbeat_no_requests(ssl, arg) \ + SSL_ctrl((ssl),SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS,arg,NULL) + +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_CTRL_TLS_EXT_SEND_HEARTBEAT \ + SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT +# define SSL_CTRL_GET_TLS_EXT_HEARTBEAT_PENDING \ + SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING +# define SSL_CTRL_SET_TLS_EXT_HEARTBEAT_NO_REQUESTS \ + SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS +# define SSL_TLSEXT_HB_ENABLED \ + SSL_DTLSEXT_HB_ENABLED +# define SSL_TLSEXT_HB_DONT_SEND_REQUESTS \ + SSL_DTLSEXT_HB_DONT_SEND_REQUESTS +# define SSL_TLSEXT_HB_DONT_RECV_REQUESTS \ + SSL_DTLSEXT_HB_DONT_RECV_REQUESTS +# define SSL_get_tlsext_heartbeat_pending(ssl) \ + SSL_get_dtlsext_heartbeat_pending(ssl) +# define SSL_set_tlsext_heartbeat_no_requests(ssl, arg) \ + SSL_set_dtlsext_heartbeat_no_requests(ssl, arg) +# endif +# endif + +/* PSK ciphersuites from 4279 */ +# define TLS1_CK_PSK_WITH_RC4_128_SHA 0x0300008A +# define TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA 0x0300008B +# define TLS1_CK_PSK_WITH_AES_128_CBC_SHA 0x0300008C +# define TLS1_CK_PSK_WITH_AES_256_CBC_SHA 0x0300008D + +# define TLS1_CK_DHE_PSK_WITH_RC4_128_SHA 0x0300008E +# define TLS1_CK_DHE_PSK_WITH_3DES_EDE_CBC_SHA 0x0300008F +# define TLS1_CK_DHE_PSK_WITH_AES_128_CBC_SHA 0x03000090 +# define TLS1_CK_DHE_PSK_WITH_AES_256_CBC_SHA 0x03000091 + +# define TLS1_CK_RSA_PSK_WITH_RC4_128_SHA 0x03000092 +# define TLS1_CK_RSA_PSK_WITH_3DES_EDE_CBC_SHA 0x03000093 +# define TLS1_CK_RSA_PSK_WITH_AES_128_CBC_SHA 0x03000094 +# define TLS1_CK_RSA_PSK_WITH_AES_256_CBC_SHA 0x03000095 + +/* PSK ciphersuites from 5487 */ +# define TLS1_CK_PSK_WITH_AES_128_GCM_SHA256 0x030000A8 +# define TLS1_CK_PSK_WITH_AES_256_GCM_SHA384 0x030000A9 +# define TLS1_CK_DHE_PSK_WITH_AES_128_GCM_SHA256 0x030000AA +# define TLS1_CK_DHE_PSK_WITH_AES_256_GCM_SHA384 0x030000AB +# define TLS1_CK_RSA_PSK_WITH_AES_128_GCM_SHA256 0x030000AC +# define TLS1_CK_RSA_PSK_WITH_AES_256_GCM_SHA384 0x030000AD + +# define TLS1_CK_PSK_WITH_AES_128_CBC_SHA256 0x030000AE +# define TLS1_CK_PSK_WITH_AES_256_CBC_SHA384 0x030000AF +# define TLS1_CK_PSK_WITH_NULL_SHA256 0x030000B0 +# define TLS1_CK_PSK_WITH_NULL_SHA384 0x030000B1 + +# define TLS1_CK_DHE_PSK_WITH_AES_128_CBC_SHA256 0x030000B2 +# define TLS1_CK_DHE_PSK_WITH_AES_256_CBC_SHA384 0x030000B3 +# define TLS1_CK_DHE_PSK_WITH_NULL_SHA256 0x030000B4 +# define TLS1_CK_DHE_PSK_WITH_NULL_SHA384 0x030000B5 + +# define TLS1_CK_RSA_PSK_WITH_AES_128_CBC_SHA256 0x030000B6 +# define TLS1_CK_RSA_PSK_WITH_AES_256_CBC_SHA384 0x030000B7 +# define TLS1_CK_RSA_PSK_WITH_NULL_SHA256 0x030000B8 +# define TLS1_CK_RSA_PSK_WITH_NULL_SHA384 0x030000B9 + +/* NULL PSK ciphersuites from RFC4785 */ +# define TLS1_CK_PSK_WITH_NULL_SHA 0x0300002C +# define TLS1_CK_DHE_PSK_WITH_NULL_SHA 0x0300002D +# define TLS1_CK_RSA_PSK_WITH_NULL_SHA 0x0300002E + +/* AES ciphersuites from RFC3268 */ +# define TLS1_CK_RSA_WITH_AES_128_SHA 0x0300002F +# define TLS1_CK_DH_DSS_WITH_AES_128_SHA 0x03000030 +# define TLS1_CK_DH_RSA_WITH_AES_128_SHA 0x03000031 +# define TLS1_CK_DHE_DSS_WITH_AES_128_SHA 0x03000032 +# define TLS1_CK_DHE_RSA_WITH_AES_128_SHA 0x03000033 +# define TLS1_CK_ADH_WITH_AES_128_SHA 0x03000034 + +# define TLS1_CK_RSA_WITH_AES_256_SHA 0x03000035 +# define TLS1_CK_DH_DSS_WITH_AES_256_SHA 0x03000036 +# define TLS1_CK_DH_RSA_WITH_AES_256_SHA 0x03000037 +# define TLS1_CK_DHE_DSS_WITH_AES_256_SHA 0x03000038 +# define TLS1_CK_DHE_RSA_WITH_AES_256_SHA 0x03000039 +# define TLS1_CK_ADH_WITH_AES_256_SHA 0x0300003A + +/* TLS v1.2 ciphersuites */ +# define TLS1_CK_RSA_WITH_NULL_SHA256 0x0300003B +# define TLS1_CK_RSA_WITH_AES_128_SHA256 0x0300003C +# define TLS1_CK_RSA_WITH_AES_256_SHA256 0x0300003D +# define TLS1_CK_DH_DSS_WITH_AES_128_SHA256 0x0300003E +# define TLS1_CK_DH_RSA_WITH_AES_128_SHA256 0x0300003F +# define TLS1_CK_DHE_DSS_WITH_AES_128_SHA256 0x03000040 + +/* Camellia ciphersuites from RFC4132 */ +# define TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000041 +# define TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000042 +# define TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000043 +# define TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000044 +# define TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000045 +# define TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA 0x03000046 + +/* TLS v1.2 ciphersuites */ +# define TLS1_CK_DHE_RSA_WITH_AES_128_SHA256 0x03000067 +# define TLS1_CK_DH_DSS_WITH_AES_256_SHA256 0x03000068 +# define TLS1_CK_DH_RSA_WITH_AES_256_SHA256 0x03000069 +# define TLS1_CK_DHE_DSS_WITH_AES_256_SHA256 0x0300006A +# define TLS1_CK_DHE_RSA_WITH_AES_256_SHA256 0x0300006B +# define TLS1_CK_ADH_WITH_AES_128_SHA256 0x0300006C +# define TLS1_CK_ADH_WITH_AES_256_SHA256 0x0300006D + +/* Camellia ciphersuites from RFC4132 */ +# define TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000084 +# define TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000085 +# define TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000086 +# define TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000087 +# define TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000088 +# define TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA 0x03000089 + +/* SEED ciphersuites from RFC4162 */ +# define TLS1_CK_RSA_WITH_SEED_SHA 0x03000096 +# define TLS1_CK_DH_DSS_WITH_SEED_SHA 0x03000097 +# define TLS1_CK_DH_RSA_WITH_SEED_SHA 0x03000098 +# define TLS1_CK_DHE_DSS_WITH_SEED_SHA 0x03000099 +# define TLS1_CK_DHE_RSA_WITH_SEED_SHA 0x0300009A +# define TLS1_CK_ADH_WITH_SEED_SHA 0x0300009B + +/* TLS v1.2 GCM ciphersuites from RFC5288 */ +# define TLS1_CK_RSA_WITH_AES_128_GCM_SHA256 0x0300009C +# define TLS1_CK_RSA_WITH_AES_256_GCM_SHA384 0x0300009D +# define TLS1_CK_DHE_RSA_WITH_AES_128_GCM_SHA256 0x0300009E +# define TLS1_CK_DHE_RSA_WITH_AES_256_GCM_SHA384 0x0300009F +# define TLS1_CK_DH_RSA_WITH_AES_128_GCM_SHA256 0x030000A0 +# define TLS1_CK_DH_RSA_WITH_AES_256_GCM_SHA384 0x030000A1 +# define TLS1_CK_DHE_DSS_WITH_AES_128_GCM_SHA256 0x030000A2 +# define TLS1_CK_DHE_DSS_WITH_AES_256_GCM_SHA384 0x030000A3 +# define TLS1_CK_DH_DSS_WITH_AES_128_GCM_SHA256 0x030000A4 +# define TLS1_CK_DH_DSS_WITH_AES_256_GCM_SHA384 0x030000A5 +# define TLS1_CK_ADH_WITH_AES_128_GCM_SHA256 0x030000A6 +# define TLS1_CK_ADH_WITH_AES_256_GCM_SHA384 0x030000A7 + +/* CCM ciphersuites from RFC6655 */ +# define TLS1_CK_RSA_WITH_AES_128_CCM 0x0300C09C +# define TLS1_CK_RSA_WITH_AES_256_CCM 0x0300C09D +# define TLS1_CK_DHE_RSA_WITH_AES_128_CCM 0x0300C09E +# define TLS1_CK_DHE_RSA_WITH_AES_256_CCM 0x0300C09F +# define TLS1_CK_RSA_WITH_AES_128_CCM_8 0x0300C0A0 +# define TLS1_CK_RSA_WITH_AES_256_CCM_8 0x0300C0A1 +# define TLS1_CK_DHE_RSA_WITH_AES_128_CCM_8 0x0300C0A2 +# define TLS1_CK_DHE_RSA_WITH_AES_256_CCM_8 0x0300C0A3 +# define TLS1_CK_PSK_WITH_AES_128_CCM 0x0300C0A4 +# define TLS1_CK_PSK_WITH_AES_256_CCM 0x0300C0A5 +# define TLS1_CK_DHE_PSK_WITH_AES_128_CCM 0x0300C0A6 +# define TLS1_CK_DHE_PSK_WITH_AES_256_CCM 0x0300C0A7 +# define TLS1_CK_PSK_WITH_AES_128_CCM_8 0x0300C0A8 +# define TLS1_CK_PSK_WITH_AES_256_CCM_8 0x0300C0A9 +# define TLS1_CK_DHE_PSK_WITH_AES_128_CCM_8 0x0300C0AA +# define TLS1_CK_DHE_PSK_WITH_AES_256_CCM_8 0x0300C0AB + +/* CCM ciphersuites from RFC7251 */ +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CCM 0x0300C0AC +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CCM 0x0300C0AD +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CCM_8 0x0300C0AE +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CCM_8 0x0300C0AF + +/* TLS 1.2 Camellia SHA-256 ciphersuites from RFC5932 */ +# define TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x030000BA +# define TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 0x030000BB +# define TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x030000BC +# define TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 0x030000BD +# define TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x030000BE +# define TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA256 0x030000BF + +# define TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x030000C0 +# define TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 0x030000C1 +# define TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x030000C2 +# define TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 0x030000C3 +# define TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x030000C4 +# define TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA256 0x030000C5 + +/* ECC ciphersuites from RFC4492 */ +# define TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA 0x0300C001 +# define TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA 0x0300C002 +# define TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C003 +# define TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0x0300C004 +# define TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0x0300C005 + +# define TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA 0x0300C006 +# define TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA 0x0300C007 +# define TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C008 +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0x0300C009 +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0x0300C00A + +# define TLS1_CK_ECDH_RSA_WITH_NULL_SHA 0x0300C00B +# define TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA 0x0300C00C +# define TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA 0x0300C00D +# define TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA 0x0300C00E +# define TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA 0x0300C00F + +# define TLS1_CK_ECDHE_RSA_WITH_NULL_SHA 0x0300C010 +# define TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA 0x0300C011 +# define TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA 0x0300C012 +# define TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA 0x0300C013 +# define TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA 0x0300C014 + +# define TLS1_CK_ECDH_anon_WITH_NULL_SHA 0x0300C015 +# define TLS1_CK_ECDH_anon_WITH_RC4_128_SHA 0x0300C016 +# define TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA 0x0300C017 +# define TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA 0x0300C018 +# define TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA 0x0300C019 + +/* SRP ciphersuites from RFC 5054 */ +# define TLS1_CK_SRP_SHA_WITH_3DES_EDE_CBC_SHA 0x0300C01A +# define TLS1_CK_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA 0x0300C01B +# define TLS1_CK_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA 0x0300C01C +# define TLS1_CK_SRP_SHA_WITH_AES_128_CBC_SHA 0x0300C01D +# define TLS1_CK_SRP_SHA_RSA_WITH_AES_128_CBC_SHA 0x0300C01E +# define TLS1_CK_SRP_SHA_DSS_WITH_AES_128_CBC_SHA 0x0300C01F +# define TLS1_CK_SRP_SHA_WITH_AES_256_CBC_SHA 0x0300C020 +# define TLS1_CK_SRP_SHA_RSA_WITH_AES_256_CBC_SHA 0x0300C021 +# define TLS1_CK_SRP_SHA_DSS_WITH_AES_256_CBC_SHA 0x0300C022 + +/* ECDH HMAC based ciphersuites from RFC5289 */ + +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_SHA256 0x0300C023 +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_SHA384 0x0300C024 +# define TLS1_CK_ECDH_ECDSA_WITH_AES_128_SHA256 0x0300C025 +# define TLS1_CK_ECDH_ECDSA_WITH_AES_256_SHA384 0x0300C026 +# define TLS1_CK_ECDHE_RSA_WITH_AES_128_SHA256 0x0300C027 +# define TLS1_CK_ECDHE_RSA_WITH_AES_256_SHA384 0x0300C028 +# define TLS1_CK_ECDH_RSA_WITH_AES_128_SHA256 0x0300C029 +# define TLS1_CK_ECDH_RSA_WITH_AES_256_SHA384 0x0300C02A + +/* ECDH GCM based ciphersuites from RFC5289 */ +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0x0300C02B +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0x0300C02C +# define TLS1_CK_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 0x0300C02D +# define TLS1_CK_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 0x0300C02E +# define TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0x0300C02F +# define TLS1_CK_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0x0300C030 +# define TLS1_CK_ECDH_RSA_WITH_AES_128_GCM_SHA256 0x0300C031 +# define TLS1_CK_ECDH_RSA_WITH_AES_256_GCM_SHA384 0x0300C032 + +/* ECDHE PSK ciphersuites from RFC5489 */ +# define TLS1_CK_ECDHE_PSK_WITH_RC4_128_SHA 0x0300C033 +# define TLS1_CK_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA 0x0300C034 +# define TLS1_CK_ECDHE_PSK_WITH_AES_128_CBC_SHA 0x0300C035 +# define TLS1_CK_ECDHE_PSK_WITH_AES_256_CBC_SHA 0x0300C036 + +# define TLS1_CK_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0x0300C037 +# define TLS1_CK_ECDHE_PSK_WITH_AES_256_CBC_SHA384 0x0300C038 + +/* NULL PSK ciphersuites from RFC4785 */ + +# define TLS1_CK_ECDHE_PSK_WITH_NULL_SHA 0x0300C039 +# define TLS1_CK_ECDHE_PSK_WITH_NULL_SHA256 0x0300C03A +# define TLS1_CK_ECDHE_PSK_WITH_NULL_SHA384 0x0300C03B + +/* Camellia-CBC ciphersuites from RFC6367 */ +# define TLS1_CK_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0x0300C072 +# define TLS1_CK_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0x0300C073 +# define TLS1_CK_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0x0300C074 +# define TLS1_CK_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0x0300C075 +# define TLS1_CK_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x0300C076 +# define TLS1_CK_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 0x0300C077 +# define TLS1_CK_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x0300C078 +# define TLS1_CK_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 0x0300C079 + +# define TLS1_CK_PSK_WITH_CAMELLIA_128_CBC_SHA256 0x0300C094 +# define TLS1_CK_PSK_WITH_CAMELLIA_256_CBC_SHA384 0x0300C095 +# define TLS1_CK_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0x0300C096 +# define TLS1_CK_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0x0300C097 +# define TLS1_CK_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 0x0300C098 +# define TLS1_CK_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 0x0300C099 +# define TLS1_CK_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0x0300C09A +# define TLS1_CK_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0x0300C09B + +/* draft-ietf-tls-chacha20-poly1305-03 */ +# define TLS1_CK_ECDHE_RSA_WITH_CHACHA20_POLY1305 0x0300CCA8 +# define TLS1_CK_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 0x0300CCA9 +# define TLS1_CK_DHE_RSA_WITH_CHACHA20_POLY1305 0x0300CCAA +# define TLS1_CK_PSK_WITH_CHACHA20_POLY1305 0x0300CCAB +# define TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305 0x0300CCAC +# define TLS1_CK_DHE_PSK_WITH_CHACHA20_POLY1305 0x0300CCAD +# define TLS1_CK_RSA_PSK_WITH_CHACHA20_POLY1305 0x0300CCAE + +/* + * XXX Backward compatibility alert: Older versions of OpenSSL gave some DHE + * ciphers names with "EDH" instead of "DHE". Going forward, we should be + * using DHE everywhere, though we may indefinitely maintain aliases for + * users or configurations that used "EDH" + */ +# define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA "DHE-DSS-RC4-SHA" + +# define TLS1_TXT_PSK_WITH_NULL_SHA "PSK-NULL-SHA" +# define TLS1_TXT_DHE_PSK_WITH_NULL_SHA "DHE-PSK-NULL-SHA" +# define TLS1_TXT_RSA_PSK_WITH_NULL_SHA "RSA-PSK-NULL-SHA" + +/* AES ciphersuites from RFC3268 */ +# define TLS1_TXT_RSA_WITH_AES_128_SHA "AES128-SHA" +# define TLS1_TXT_DH_DSS_WITH_AES_128_SHA "DH-DSS-AES128-SHA" +# define TLS1_TXT_DH_RSA_WITH_AES_128_SHA "DH-RSA-AES128-SHA" +# define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA "DHE-DSS-AES128-SHA" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA "DHE-RSA-AES128-SHA" +# define TLS1_TXT_ADH_WITH_AES_128_SHA "ADH-AES128-SHA" + +# define TLS1_TXT_RSA_WITH_AES_256_SHA "AES256-SHA" +# define TLS1_TXT_DH_DSS_WITH_AES_256_SHA "DH-DSS-AES256-SHA" +# define TLS1_TXT_DH_RSA_WITH_AES_256_SHA "DH-RSA-AES256-SHA" +# define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA "DHE-DSS-AES256-SHA" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA "DHE-RSA-AES256-SHA" +# define TLS1_TXT_ADH_WITH_AES_256_SHA "ADH-AES256-SHA" + +/* ECC ciphersuites from RFC4492 */ +# define TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA "ECDH-ECDSA-NULL-SHA" +# define TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA "ECDH-ECDSA-RC4-SHA" +# define TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA "ECDH-ECDSA-DES-CBC3-SHA" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA "ECDH-ECDSA-AES128-SHA" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA "ECDH-ECDSA-AES256-SHA" + +# define TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA "ECDHE-ECDSA-NULL-SHA" +# define TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA "ECDHE-ECDSA-RC4-SHA" +# define TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA "ECDHE-ECDSA-DES-CBC3-SHA" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA "ECDHE-ECDSA-AES128-SHA" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA "ECDHE-ECDSA-AES256-SHA" + +# define TLS1_TXT_ECDH_RSA_WITH_NULL_SHA "ECDH-RSA-NULL-SHA" +# define TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA "ECDH-RSA-RC4-SHA" +# define TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA "ECDH-RSA-DES-CBC3-SHA" +# define TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA "ECDH-RSA-AES128-SHA" +# define TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA "ECDH-RSA-AES256-SHA" + +# define TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA "ECDHE-RSA-NULL-SHA" +# define TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA "ECDHE-RSA-RC4-SHA" +# define TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA "ECDHE-RSA-DES-CBC3-SHA" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA "ECDHE-RSA-AES128-SHA" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA "ECDHE-RSA-AES256-SHA" + +# define TLS1_TXT_ECDH_anon_WITH_NULL_SHA "AECDH-NULL-SHA" +# define TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA "AECDH-RC4-SHA" +# define TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA "AECDH-DES-CBC3-SHA" +# define TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA "AECDH-AES128-SHA" +# define TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA "AECDH-AES256-SHA" + +/* PSK ciphersuites from RFC 4279 */ +# define TLS1_TXT_PSK_WITH_RC4_128_SHA "PSK-RC4-SHA" +# define TLS1_TXT_PSK_WITH_3DES_EDE_CBC_SHA "PSK-3DES-EDE-CBC-SHA" +# define TLS1_TXT_PSK_WITH_AES_128_CBC_SHA "PSK-AES128-CBC-SHA" +# define TLS1_TXT_PSK_WITH_AES_256_CBC_SHA "PSK-AES256-CBC-SHA" + +# define TLS1_TXT_DHE_PSK_WITH_RC4_128_SHA "DHE-PSK-RC4-SHA" +# define TLS1_TXT_DHE_PSK_WITH_3DES_EDE_CBC_SHA "DHE-PSK-3DES-EDE-CBC-SHA" +# define TLS1_TXT_DHE_PSK_WITH_AES_128_CBC_SHA "DHE-PSK-AES128-CBC-SHA" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_CBC_SHA "DHE-PSK-AES256-CBC-SHA" +# define TLS1_TXT_RSA_PSK_WITH_RC4_128_SHA "RSA-PSK-RC4-SHA" +# define TLS1_TXT_RSA_PSK_WITH_3DES_EDE_CBC_SHA "RSA-PSK-3DES-EDE-CBC-SHA" +# define TLS1_TXT_RSA_PSK_WITH_AES_128_CBC_SHA "RSA-PSK-AES128-CBC-SHA" +# define TLS1_TXT_RSA_PSK_WITH_AES_256_CBC_SHA "RSA-PSK-AES256-CBC-SHA" + +/* PSK ciphersuites from RFC 5487 */ +# define TLS1_TXT_PSK_WITH_AES_128_GCM_SHA256 "PSK-AES128-GCM-SHA256" +# define TLS1_TXT_PSK_WITH_AES_256_GCM_SHA384 "PSK-AES256-GCM-SHA384" +# define TLS1_TXT_DHE_PSK_WITH_AES_128_GCM_SHA256 "DHE-PSK-AES128-GCM-SHA256" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_GCM_SHA384 "DHE-PSK-AES256-GCM-SHA384" +# define TLS1_TXT_RSA_PSK_WITH_AES_128_GCM_SHA256 "RSA-PSK-AES128-GCM-SHA256" +# define TLS1_TXT_RSA_PSK_WITH_AES_256_GCM_SHA384 "RSA-PSK-AES256-GCM-SHA384" + +# define TLS1_TXT_PSK_WITH_AES_128_CBC_SHA256 "PSK-AES128-CBC-SHA256" +# define TLS1_TXT_PSK_WITH_AES_256_CBC_SHA384 "PSK-AES256-CBC-SHA384" +# define TLS1_TXT_PSK_WITH_NULL_SHA256 "PSK-NULL-SHA256" +# define TLS1_TXT_PSK_WITH_NULL_SHA384 "PSK-NULL-SHA384" + +# define TLS1_TXT_DHE_PSK_WITH_AES_128_CBC_SHA256 "DHE-PSK-AES128-CBC-SHA256" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_CBC_SHA384 "DHE-PSK-AES256-CBC-SHA384" +# define TLS1_TXT_DHE_PSK_WITH_NULL_SHA256 "DHE-PSK-NULL-SHA256" +# define TLS1_TXT_DHE_PSK_WITH_NULL_SHA384 "DHE-PSK-NULL-SHA384" + +# define TLS1_TXT_RSA_PSK_WITH_AES_128_CBC_SHA256 "RSA-PSK-AES128-CBC-SHA256" +# define TLS1_TXT_RSA_PSK_WITH_AES_256_CBC_SHA384 "RSA-PSK-AES256-CBC-SHA384" +# define TLS1_TXT_RSA_PSK_WITH_NULL_SHA256 "RSA-PSK-NULL-SHA256" +# define TLS1_TXT_RSA_PSK_WITH_NULL_SHA384 "RSA-PSK-NULL-SHA384" + +/* SRP ciphersuite from RFC 5054 */ +# define TLS1_TXT_SRP_SHA_WITH_3DES_EDE_CBC_SHA "SRP-3DES-EDE-CBC-SHA" +# define TLS1_TXT_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA "SRP-RSA-3DES-EDE-CBC-SHA" +# define TLS1_TXT_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA "SRP-DSS-3DES-EDE-CBC-SHA" +# define TLS1_TXT_SRP_SHA_WITH_AES_128_CBC_SHA "SRP-AES-128-CBC-SHA" +# define TLS1_TXT_SRP_SHA_RSA_WITH_AES_128_CBC_SHA "SRP-RSA-AES-128-CBC-SHA" +# define TLS1_TXT_SRP_SHA_DSS_WITH_AES_128_CBC_SHA "SRP-DSS-AES-128-CBC-SHA" +# define TLS1_TXT_SRP_SHA_WITH_AES_256_CBC_SHA "SRP-AES-256-CBC-SHA" +# define TLS1_TXT_SRP_SHA_RSA_WITH_AES_256_CBC_SHA "SRP-RSA-AES-256-CBC-SHA" +# define TLS1_TXT_SRP_SHA_DSS_WITH_AES_256_CBC_SHA "SRP-DSS-AES-256-CBC-SHA" + +/* Camellia ciphersuites from RFC4132 */ +# define TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA "CAMELLIA128-SHA" +# define TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA "DH-DSS-CAMELLIA128-SHA" +# define TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA "DH-RSA-CAMELLIA128-SHA" +# define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA "DHE-DSS-CAMELLIA128-SHA" +# define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA "DHE-RSA-CAMELLIA128-SHA" +# define TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA "ADH-CAMELLIA128-SHA" + +# define TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA "CAMELLIA256-SHA" +# define TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA "DH-DSS-CAMELLIA256-SHA" +# define TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA "DH-RSA-CAMELLIA256-SHA" +# define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA "DHE-DSS-CAMELLIA256-SHA" +# define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA "DHE-RSA-CAMELLIA256-SHA" +# define TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA "ADH-CAMELLIA256-SHA" + +/* TLS 1.2 Camellia SHA-256 ciphersuites from RFC5932 */ +# define TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA256 "CAMELLIA128-SHA256" +# define TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 "DH-DSS-CAMELLIA128-SHA256" +# define TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 "DH-RSA-CAMELLIA128-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 "DHE-DSS-CAMELLIA128-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 "DHE-RSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA256 "ADH-CAMELLIA128-SHA256" + +# define TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA256 "CAMELLIA256-SHA256" +# define TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 "DH-DSS-CAMELLIA256-SHA256" +# define TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 "DH-RSA-CAMELLIA256-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 "DHE-DSS-CAMELLIA256-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 "DHE-RSA-CAMELLIA256-SHA256" +# define TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA256 "ADH-CAMELLIA256-SHA256" + +# define TLS1_TXT_PSK_WITH_CAMELLIA_128_CBC_SHA256 "PSK-CAMELLIA128-SHA256" +# define TLS1_TXT_PSK_WITH_CAMELLIA_256_CBC_SHA384 "PSK-CAMELLIA256-SHA384" +# define TLS1_TXT_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 "DHE-PSK-CAMELLIA128-SHA256" +# define TLS1_TXT_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 "DHE-PSK-CAMELLIA256-SHA384" +# define TLS1_TXT_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 "RSA-PSK-CAMELLIA128-SHA256" +# define TLS1_TXT_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 "RSA-PSK-CAMELLIA256-SHA384" +# define TLS1_TXT_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 "ECDHE-PSK-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 "ECDHE-PSK-CAMELLIA256-SHA384" + +/* SEED ciphersuites from RFC4162 */ +# define TLS1_TXT_RSA_WITH_SEED_SHA "SEED-SHA" +# define TLS1_TXT_DH_DSS_WITH_SEED_SHA "DH-DSS-SEED-SHA" +# define TLS1_TXT_DH_RSA_WITH_SEED_SHA "DH-RSA-SEED-SHA" +# define TLS1_TXT_DHE_DSS_WITH_SEED_SHA "DHE-DSS-SEED-SHA" +# define TLS1_TXT_DHE_RSA_WITH_SEED_SHA "DHE-RSA-SEED-SHA" +# define TLS1_TXT_ADH_WITH_SEED_SHA "ADH-SEED-SHA" + +/* TLS v1.2 ciphersuites */ +# define TLS1_TXT_RSA_WITH_NULL_SHA256 "NULL-SHA256" +# define TLS1_TXT_RSA_WITH_AES_128_SHA256 "AES128-SHA256" +# define TLS1_TXT_RSA_WITH_AES_256_SHA256 "AES256-SHA256" +# define TLS1_TXT_DH_DSS_WITH_AES_128_SHA256 "DH-DSS-AES128-SHA256" +# define TLS1_TXT_DH_RSA_WITH_AES_128_SHA256 "DH-RSA-AES128-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA256 "DHE-DSS-AES128-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA256 "DHE-RSA-AES128-SHA256" +# define TLS1_TXT_DH_DSS_WITH_AES_256_SHA256 "DH-DSS-AES256-SHA256" +# define TLS1_TXT_DH_RSA_WITH_AES_256_SHA256 "DH-RSA-AES256-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA256 "DHE-DSS-AES256-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA256 "DHE-RSA-AES256-SHA256" +# define TLS1_TXT_ADH_WITH_AES_128_SHA256 "ADH-AES128-SHA256" +# define TLS1_TXT_ADH_WITH_AES_256_SHA256 "ADH-AES256-SHA256" + +/* TLS v1.2 GCM ciphersuites from RFC5288 */ +# define TLS1_TXT_RSA_WITH_AES_128_GCM_SHA256 "AES128-GCM-SHA256" +# define TLS1_TXT_RSA_WITH_AES_256_GCM_SHA384 "AES256-GCM-SHA384" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_GCM_SHA256 "DHE-RSA-AES128-GCM-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_GCM_SHA384 "DHE-RSA-AES256-GCM-SHA384" +# define TLS1_TXT_DH_RSA_WITH_AES_128_GCM_SHA256 "DH-RSA-AES128-GCM-SHA256" +# define TLS1_TXT_DH_RSA_WITH_AES_256_GCM_SHA384 "DH-RSA-AES256-GCM-SHA384" +# define TLS1_TXT_DHE_DSS_WITH_AES_128_GCM_SHA256 "DHE-DSS-AES128-GCM-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_AES_256_GCM_SHA384 "DHE-DSS-AES256-GCM-SHA384" +# define TLS1_TXT_DH_DSS_WITH_AES_128_GCM_SHA256 "DH-DSS-AES128-GCM-SHA256" +# define TLS1_TXT_DH_DSS_WITH_AES_256_GCM_SHA384 "DH-DSS-AES256-GCM-SHA384" +# define TLS1_TXT_ADH_WITH_AES_128_GCM_SHA256 "ADH-AES128-GCM-SHA256" +# define TLS1_TXT_ADH_WITH_AES_256_GCM_SHA384 "ADH-AES256-GCM-SHA384" + +/* CCM ciphersuites from RFC6655 */ + +# define TLS1_TXT_RSA_WITH_AES_128_CCM "AES128-CCM" +# define TLS1_TXT_RSA_WITH_AES_256_CCM "AES256-CCM" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_CCM "DHE-RSA-AES128-CCM" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_CCM "DHE-RSA-AES256-CCM" + +# define TLS1_TXT_RSA_WITH_AES_128_CCM_8 "AES128-CCM8" +# define TLS1_TXT_RSA_WITH_AES_256_CCM_8 "AES256-CCM8" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_CCM_8 "DHE-RSA-AES128-CCM8" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_CCM_8 "DHE-RSA-AES256-CCM8" + +# define TLS1_TXT_PSK_WITH_AES_128_CCM "PSK-AES128-CCM" +# define TLS1_TXT_PSK_WITH_AES_256_CCM "PSK-AES256-CCM" +# define TLS1_TXT_DHE_PSK_WITH_AES_128_CCM "DHE-PSK-AES128-CCM" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_CCM "DHE-PSK-AES256-CCM" + +# define TLS1_TXT_PSK_WITH_AES_128_CCM_8 "PSK-AES128-CCM8" +# define TLS1_TXT_PSK_WITH_AES_256_CCM_8 "PSK-AES256-CCM8" +# define TLS1_TXT_DHE_PSK_WITH_AES_128_CCM_8 "DHE-PSK-AES128-CCM8" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_CCM_8 "DHE-PSK-AES256-CCM8" + +/* CCM ciphersuites from RFC7251 */ + +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CCM "ECDHE-ECDSA-AES128-CCM" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CCM "ECDHE-ECDSA-AES256-CCM" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CCM_8 "ECDHE-ECDSA-AES128-CCM8" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CCM_8 "ECDHE-ECDSA-AES256-CCM8" + +/* ECDH HMAC based ciphersuites from RFC5289 */ + +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_SHA256 "ECDHE-ECDSA-AES128-SHA256" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_SHA384 "ECDHE-ECDSA-AES256-SHA384" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_SHA256 "ECDH-ECDSA-AES128-SHA256" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_SHA384 "ECDH-ECDSA-AES256-SHA384" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_128_SHA256 "ECDHE-RSA-AES128-SHA256" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_256_SHA384 "ECDHE-RSA-AES256-SHA384" +# define TLS1_TXT_ECDH_RSA_WITH_AES_128_SHA256 "ECDH-RSA-AES128-SHA256" +# define TLS1_TXT_ECDH_RSA_WITH_AES_256_SHA384 "ECDH-RSA-AES256-SHA384" + +/* ECDH GCM based ciphersuites from RFC5289 */ +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 "ECDHE-ECDSA-AES128-GCM-SHA256" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 "ECDHE-ECDSA-AES256-GCM-SHA384" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 "ECDH-ECDSA-AES128-GCM-SHA256" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 "ECDH-ECDSA-AES256-GCM-SHA384" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_128_GCM_SHA256 "ECDHE-RSA-AES128-GCM-SHA256" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_256_GCM_SHA384 "ECDHE-RSA-AES256-GCM-SHA384" +# define TLS1_TXT_ECDH_RSA_WITH_AES_128_GCM_SHA256 "ECDH-RSA-AES128-GCM-SHA256" +# define TLS1_TXT_ECDH_RSA_WITH_AES_256_GCM_SHA384 "ECDH-RSA-AES256-GCM-SHA384" + +/* TLS v1.2 PSK GCM ciphersuites from RFC5487 */ +# define TLS1_TXT_PSK_WITH_AES_128_GCM_SHA256 "PSK-AES128-GCM-SHA256" +# define TLS1_TXT_PSK_WITH_AES_256_GCM_SHA384 "PSK-AES256-GCM-SHA384" + +/* ECDHE PSK ciphersuites from RFC 5489 */ +# define TLS1_TXT_ECDHE_PSK_WITH_RC4_128_SHA "ECDHE-PSK-RC4-SHA" +# define TLS1_TXT_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA "ECDHE-PSK-3DES-EDE-CBC-SHA" +# define TLS1_TXT_ECDHE_PSK_WITH_AES_128_CBC_SHA "ECDHE-PSK-AES128-CBC-SHA" +# define TLS1_TXT_ECDHE_PSK_WITH_AES_256_CBC_SHA "ECDHE-PSK-AES256-CBC-SHA" + +# define TLS1_TXT_ECDHE_PSK_WITH_AES_128_CBC_SHA256 "ECDHE-PSK-AES128-CBC-SHA256" +# define TLS1_TXT_ECDHE_PSK_WITH_AES_256_CBC_SHA384 "ECDHE-PSK-AES256-CBC-SHA384" + +# define TLS1_TXT_ECDHE_PSK_WITH_NULL_SHA "ECDHE-PSK-NULL-SHA" +# define TLS1_TXT_ECDHE_PSK_WITH_NULL_SHA256 "ECDHE-PSK-NULL-SHA256" +# define TLS1_TXT_ECDHE_PSK_WITH_NULL_SHA384 "ECDHE-PSK-NULL-SHA384" + +/* Camellia-CBC ciphersuites from RFC6367 */ +# define TLS1_TXT_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 "ECDHE-ECDSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 "ECDHE-ECDSA-CAMELLIA256-SHA384" +# define TLS1_TXT_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 "ECDH-ECDSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 "ECDH-ECDSA-CAMELLIA256-SHA384" +# define TLS1_TXT_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 "ECDHE-RSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 "ECDHE-RSA-CAMELLIA256-SHA384" +# define TLS1_TXT_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 "ECDH-RSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 "ECDH-RSA-CAMELLIA256-SHA384" + +/* draft-ietf-tls-chacha20-poly1305-03 */ +# define TLS1_TXT_ECDHE_RSA_WITH_CHACHA20_POLY1305 "ECDHE-RSA-CHACHA20-POLY1305" +# define TLS1_TXT_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 "ECDHE-ECDSA-CHACHA20-POLY1305" +# define TLS1_TXT_DHE_RSA_WITH_CHACHA20_POLY1305 "DHE-RSA-CHACHA20-POLY1305" +# define TLS1_TXT_PSK_WITH_CHACHA20_POLY1305 "PSK-CHACHA20-POLY1305" +# define TLS1_TXT_ECDHE_PSK_WITH_CHACHA20_POLY1305 "ECDHE-PSK-CHACHA20-POLY1305" +# define TLS1_TXT_DHE_PSK_WITH_CHACHA20_POLY1305 "DHE-PSK-CHACHA20-POLY1305" +# define TLS1_TXT_RSA_PSK_WITH_CHACHA20_POLY1305 "RSA-PSK-CHACHA20-POLY1305" + +# define TLS_CT_RSA_SIGN 1 +# define TLS_CT_DSS_SIGN 2 +# define TLS_CT_RSA_FIXED_DH 3 +# define TLS_CT_DSS_FIXED_DH 4 +# define TLS_CT_ECDSA_SIGN 64 +# define TLS_CT_RSA_FIXED_ECDH 65 +# define TLS_CT_ECDSA_FIXED_ECDH 66 +# define TLS_CT_GOST01_SIGN 22 +# define TLS_CT_GOST12_SIGN 238 +# define TLS_CT_GOST12_512_SIGN 239 + +/* + * when correcting this number, correct also SSL3_CT_NUMBER in ssl3.h (see + * comment there) + */ +# define TLS_CT_NUMBER 9 + +# define TLS1_FINISH_MAC_LENGTH 12 + +# define TLS_MD_MAX_CONST_SIZE 22 +# define TLS_MD_CLIENT_FINISH_CONST "client finished" +# define TLS_MD_CLIENT_FINISH_CONST_SIZE 15 +# define TLS_MD_SERVER_FINISH_CONST "server finished" +# define TLS_MD_SERVER_FINISH_CONST_SIZE 15 +# define TLS_MD_KEY_EXPANSION_CONST "key expansion" +# define TLS_MD_KEY_EXPANSION_CONST_SIZE 13 +# define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key" +# define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16 +# define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" +# define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 +# define TLS_MD_IV_BLOCK_CONST "IV block" +# define TLS_MD_IV_BLOCK_CONST_SIZE 8 +# define TLS_MD_MASTER_SECRET_CONST "master secret" +# define TLS_MD_MASTER_SECRET_CONST_SIZE 13 +# define TLS_MD_EXTENDED_MASTER_SECRET_CONST "extended master secret" +# define TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE 22 + +# ifdef CHARSET_EBCDIC +# undef TLS_MD_CLIENT_FINISH_CONST +/* + * client finished + */ +# define TLS_MD_CLIENT_FINISH_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64" + +# undef TLS_MD_SERVER_FINISH_CONST +/* + * server finished + */ +# define TLS_MD_SERVER_FINISH_CONST "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64" + +# undef TLS_MD_SERVER_WRITE_KEY_CONST +/* + * server write key + */ +# define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" + +# undef TLS_MD_KEY_EXPANSION_CONST +/* + * key expansion + */ +# define TLS_MD_KEY_EXPANSION_CONST "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e" + +# undef TLS_MD_CLIENT_WRITE_KEY_CONST +/* + * client write key + */ +# define TLS_MD_CLIENT_WRITE_KEY_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" + +# undef TLS_MD_SERVER_WRITE_KEY_CONST +/* + * server write key + */ +# define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" + +# undef TLS_MD_IV_BLOCK_CONST +/* + * IV block + */ +# define TLS_MD_IV_BLOCK_CONST "\x49\x56\x20\x62\x6c\x6f\x63\x6b" + +# undef TLS_MD_MASTER_SECRET_CONST +/* + * master secret + */ +# define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" +# undef TLS_MD_EXTENDED_MASTER_SECRET_CONST +/* + * extended master secret + */ +# define TLS_MD_EXTENDED_MASTER_SECRET_CONST "\x65\x78\x74\x65\x63\x64\x65\x64\x20\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" +# endif + +/* TLS Session Ticket extension struct */ +struct tls_session_ticket_ext_st { + unsigned short length; + void *data; +}; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/x86/include/openssl/ts.h b/android/x86/include/openssl/ts.h new file mode 100644 index 00000000..a5659825 --- /dev/null +++ b/android/x86/include/openssl/ts.h @@ -0,0 +1,643 @@ +/* + * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_TS_H +# define HEADER_TS_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_TS +# include <openssl/symhacks.h> +# include <openssl/buffer.h> +# include <openssl/evp.h> +# include <openssl/bio.h> +# include <openssl/stack.h> +# include <openssl/asn1.h> +# include <openssl/safestack.h> +# include <openssl/rsa.h> +# include <openssl/dsa.h> +# include <openssl/dh.h> +# ifdef __cplusplus +extern "C" { +# endif + +# include <openssl/x509.h> +# include <openssl/x509v3.h> + +typedef struct TS_msg_imprint_st TS_MSG_IMPRINT; +typedef struct TS_req_st TS_REQ; +typedef struct TS_accuracy_st TS_ACCURACY; +typedef struct TS_tst_info_st TS_TST_INFO; + +/* Possible values for status. */ +# define TS_STATUS_GRANTED 0 +# define TS_STATUS_GRANTED_WITH_MODS 1 +# define TS_STATUS_REJECTION 2 +# define TS_STATUS_WAITING 3 +# define TS_STATUS_REVOCATION_WARNING 4 +# define TS_STATUS_REVOCATION_NOTIFICATION 5 + +/* Possible values for failure_info. */ +# define TS_INFO_BAD_ALG 0 +# define TS_INFO_BAD_REQUEST 2 +# define TS_INFO_BAD_DATA_FORMAT 5 +# define TS_INFO_TIME_NOT_AVAILABLE 14 +# define TS_INFO_UNACCEPTED_POLICY 15 +# define TS_INFO_UNACCEPTED_EXTENSION 16 +# define TS_INFO_ADD_INFO_NOT_AVAILABLE 17 +# define TS_INFO_SYSTEM_FAILURE 25 + + +typedef struct TS_status_info_st TS_STATUS_INFO; +typedef struct ESS_issuer_serial ESS_ISSUER_SERIAL; +typedef struct ESS_cert_id ESS_CERT_ID; +typedef struct ESS_signing_cert ESS_SIGNING_CERT; + +DEFINE_STACK_OF(ESS_CERT_ID) + +typedef struct TS_resp_st TS_RESP; + +TS_REQ *TS_REQ_new(void); +void TS_REQ_free(TS_REQ *a); +int i2d_TS_REQ(const TS_REQ *a, unsigned char **pp); +TS_REQ *d2i_TS_REQ(TS_REQ **a, const unsigned char **pp, long length); + +TS_REQ *TS_REQ_dup(TS_REQ *a); + +#ifndef OPENSSL_NO_STDIO +TS_REQ *d2i_TS_REQ_fp(FILE *fp, TS_REQ **a); +int i2d_TS_REQ_fp(FILE *fp, TS_REQ *a); +#endif +TS_REQ *d2i_TS_REQ_bio(BIO *fp, TS_REQ **a); +int i2d_TS_REQ_bio(BIO *fp, TS_REQ *a); + +TS_MSG_IMPRINT *TS_MSG_IMPRINT_new(void); +void TS_MSG_IMPRINT_free(TS_MSG_IMPRINT *a); +int i2d_TS_MSG_IMPRINT(const TS_MSG_IMPRINT *a, unsigned char **pp); +TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT(TS_MSG_IMPRINT **a, + const unsigned char **pp, long length); + +TS_MSG_IMPRINT *TS_MSG_IMPRINT_dup(TS_MSG_IMPRINT *a); + +#ifndef OPENSSL_NO_STDIO +TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a); +int i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a); +#endif +TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_bio(BIO *bio, TS_MSG_IMPRINT **a); +int i2d_TS_MSG_IMPRINT_bio(BIO *bio, TS_MSG_IMPRINT *a); + +TS_RESP *TS_RESP_new(void); +void TS_RESP_free(TS_RESP *a); +int i2d_TS_RESP(const TS_RESP *a, unsigned char **pp); +TS_RESP *d2i_TS_RESP(TS_RESP **a, const unsigned char **pp, long length); +TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token); +TS_RESP *TS_RESP_dup(TS_RESP *a); + +#ifndef OPENSSL_NO_STDIO +TS_RESP *d2i_TS_RESP_fp(FILE *fp, TS_RESP **a); +int i2d_TS_RESP_fp(FILE *fp, TS_RESP *a); +#endif +TS_RESP *d2i_TS_RESP_bio(BIO *bio, TS_RESP **a); +int i2d_TS_RESP_bio(BIO *bio, TS_RESP *a); + +TS_STATUS_INFO *TS_STATUS_INFO_new(void); +void TS_STATUS_INFO_free(TS_STATUS_INFO *a); +int i2d_TS_STATUS_INFO(const TS_STATUS_INFO *a, unsigned char **pp); +TS_STATUS_INFO *d2i_TS_STATUS_INFO(TS_STATUS_INFO **a, + const unsigned char **pp, long length); +TS_STATUS_INFO *TS_STATUS_INFO_dup(TS_STATUS_INFO *a); + +TS_TST_INFO *TS_TST_INFO_new(void); +void TS_TST_INFO_free(TS_TST_INFO *a); +int i2d_TS_TST_INFO(const TS_TST_INFO *a, unsigned char **pp); +TS_TST_INFO *d2i_TS_TST_INFO(TS_TST_INFO **a, const unsigned char **pp, + long length); +TS_TST_INFO *TS_TST_INFO_dup(TS_TST_INFO *a); + +#ifndef OPENSSL_NO_STDIO +TS_TST_INFO *d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a); +int i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a); +#endif +TS_TST_INFO *d2i_TS_TST_INFO_bio(BIO *bio, TS_TST_INFO **a); +int i2d_TS_TST_INFO_bio(BIO *bio, TS_TST_INFO *a); + +TS_ACCURACY *TS_ACCURACY_new(void); +void TS_ACCURACY_free(TS_ACCURACY *a); +int i2d_TS_ACCURACY(const TS_ACCURACY *a, unsigned char **pp); +TS_ACCURACY *d2i_TS_ACCURACY(TS_ACCURACY **a, const unsigned char **pp, + long length); +TS_ACCURACY *TS_ACCURACY_dup(TS_ACCURACY *a); + +ESS_ISSUER_SERIAL *ESS_ISSUER_SERIAL_new(void); +void ESS_ISSUER_SERIAL_free(ESS_ISSUER_SERIAL *a); +int i2d_ESS_ISSUER_SERIAL(const ESS_ISSUER_SERIAL *a, unsigned char **pp); +ESS_ISSUER_SERIAL *d2i_ESS_ISSUER_SERIAL(ESS_ISSUER_SERIAL **a, + const unsigned char **pp, + long length); +ESS_ISSUER_SERIAL *ESS_ISSUER_SERIAL_dup(ESS_ISSUER_SERIAL *a); + +ESS_CERT_ID *ESS_CERT_ID_new(void); +void ESS_CERT_ID_free(ESS_CERT_ID *a); +int i2d_ESS_CERT_ID(const ESS_CERT_ID *a, unsigned char **pp); +ESS_CERT_ID *d2i_ESS_CERT_ID(ESS_CERT_ID **a, const unsigned char **pp, + long length); +ESS_CERT_ID *ESS_CERT_ID_dup(ESS_CERT_ID *a); + +ESS_SIGNING_CERT *ESS_SIGNING_CERT_new(void); +void ESS_SIGNING_CERT_free(ESS_SIGNING_CERT *a); +int i2d_ESS_SIGNING_CERT(const ESS_SIGNING_CERT *a, unsigned char **pp); +ESS_SIGNING_CERT *d2i_ESS_SIGNING_CERT(ESS_SIGNING_CERT **a, + const unsigned char **pp, long length); +ESS_SIGNING_CERT *ESS_SIGNING_CERT_dup(ESS_SIGNING_CERT *a); + +int TS_REQ_set_version(TS_REQ *a, long version); +long TS_REQ_get_version(const TS_REQ *a); + +int TS_STATUS_INFO_set_status(TS_STATUS_INFO *a, int i); +const ASN1_INTEGER *TS_STATUS_INFO_get0_status(const TS_STATUS_INFO *a); + +const STACK_OF(ASN1_UTF8STRING) * +TS_STATUS_INFO_get0_text(const TS_STATUS_INFO *a); + +const ASN1_BIT_STRING * +TS_STATUS_INFO_get0_failure_info(const TS_STATUS_INFO *a); + +int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint); +TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a); + +int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg); +X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a); + +int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len); +ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a); + +int TS_REQ_set_policy_id(TS_REQ *a, const ASN1_OBJECT *policy); +ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a); + +int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce); +const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a); + +int TS_REQ_set_cert_req(TS_REQ *a, int cert_req); +int TS_REQ_get_cert_req(const TS_REQ *a); + +STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a); +void TS_REQ_ext_free(TS_REQ *a); +int TS_REQ_get_ext_count(TS_REQ *a); +int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos); +int TS_REQ_get_ext_by_OBJ(TS_REQ *a, const ASN1_OBJECT *obj, int lastpos); +int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos); +X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc); +X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc); +int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc); +void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx); + +/* Function declarations for TS_REQ defined in ts/ts_req_print.c */ + +int TS_REQ_print_bio(BIO *bio, TS_REQ *a); + +/* Function declarations for TS_RESP defined in ts/ts_resp_utils.c */ + +int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *info); +TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a); + +/* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */ +void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info); +PKCS7 *TS_RESP_get_token(TS_RESP *a); +TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a); + +int TS_TST_INFO_set_version(TS_TST_INFO *a, long version); +long TS_TST_INFO_get_version(const TS_TST_INFO *a); + +int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy_id); +ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a); + +int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint); +TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a); + +int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial); +const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a); + +int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime); +const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a); + +int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy); +TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a); + +int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds); +const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a); + +int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis); +const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a); + +int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros); +const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a); + +int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering); +int TS_TST_INFO_get_ordering(const TS_TST_INFO *a); + +int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce); +const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a); + +int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa); +GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a); + +STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a); +void TS_TST_INFO_ext_free(TS_TST_INFO *a); +int TS_TST_INFO_get_ext_count(TS_TST_INFO *a); +int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos); +int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, const ASN1_OBJECT *obj, + int lastpos); +int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos); +X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc); +X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc); +int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc); +void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx); + +/* + * Declarations related to response generation, defined in ts/ts_resp_sign.c. + */ + +/* Optional flags for response generation. */ + +/* Don't include the TSA name in response. */ +# define TS_TSA_NAME 0x01 + +/* Set ordering to true in response. */ +# define TS_ORDERING 0x02 + +/* + * Include the signer certificate and the other specified certificates in + * the ESS signing certificate attribute beside the PKCS7 signed data. + * Only the signer certificates is included by default. + */ +# define TS_ESS_CERT_ID_CHAIN 0x04 + +/* Forward declaration. */ +struct TS_resp_ctx; + +/* This must return a unique number less than 160 bits long. */ +typedef ASN1_INTEGER *(*TS_serial_cb) (struct TS_resp_ctx *, void *); + +/* + * This must return the seconds and microseconds since Jan 1, 1970 in the sec + * and usec variables allocated by the caller. Return non-zero for success + * and zero for failure. + */ +typedef int (*TS_time_cb) (struct TS_resp_ctx *, void *, long *sec, + long *usec); + +/* + * This must process the given extension. It can modify the TS_TST_INFO + * object of the context. Return values: !0 (processed), 0 (error, it must + * set the status info/failure info of the response). + */ +typedef int (*TS_extension_cb) (struct TS_resp_ctx *, X509_EXTENSION *, + void *); + +typedef struct TS_resp_ctx TS_RESP_CTX; + +DEFINE_STACK_OF_CONST(EVP_MD) + +/* Creates a response context that can be used for generating responses. */ +TS_RESP_CTX *TS_RESP_CTX_new(void); +void TS_RESP_CTX_free(TS_RESP_CTX *ctx); + +/* This parameter must be set. */ +int TS_RESP_CTX_set_signer_cert(TS_RESP_CTX *ctx, X509 *signer); + +/* This parameter must be set. */ +int TS_RESP_CTX_set_signer_key(TS_RESP_CTX *ctx, EVP_PKEY *key); + +int TS_RESP_CTX_set_signer_digest(TS_RESP_CTX *ctx, + const EVP_MD *signer_digest); + +/* This parameter must be set. */ +int TS_RESP_CTX_set_def_policy(TS_RESP_CTX *ctx, const ASN1_OBJECT *def_policy); + +/* No additional certs are included in the response by default. */ +int TS_RESP_CTX_set_certs(TS_RESP_CTX *ctx, STACK_OF(X509) *certs); + +/* + * Adds a new acceptable policy, only the default policy is accepted by + * default. + */ +int TS_RESP_CTX_add_policy(TS_RESP_CTX *ctx, const ASN1_OBJECT *policy); + +/* + * Adds a new acceptable message digest. Note that no message digests are + * accepted by default. The md argument is shared with the caller. + */ +int TS_RESP_CTX_add_md(TS_RESP_CTX *ctx, const EVP_MD *md); + +/* Accuracy is not included by default. */ +int TS_RESP_CTX_set_accuracy(TS_RESP_CTX *ctx, + int secs, int millis, int micros); + +/* + * Clock precision digits, i.e. the number of decimal digits: '0' means sec, + * '3' msec, '6' usec, and so on. Default is 0. + */ +int TS_RESP_CTX_set_clock_precision_digits(TS_RESP_CTX *ctx, + unsigned clock_precision_digits); +/* At most we accept usec precision. */ +# define TS_MAX_CLOCK_PRECISION_DIGITS 6 + +/* Maximum status message length */ +# define TS_MAX_STATUS_LENGTH (1024 * 1024) + +/* No flags are set by default. */ +void TS_RESP_CTX_add_flags(TS_RESP_CTX *ctx, int flags); + +/* Default callback always returns a constant. */ +void TS_RESP_CTX_set_serial_cb(TS_RESP_CTX *ctx, TS_serial_cb cb, void *data); + +/* Default callback uses the gettimeofday() and gmtime() system calls. */ +void TS_RESP_CTX_set_time_cb(TS_RESP_CTX *ctx, TS_time_cb cb, void *data); + +/* + * Default callback rejects all extensions. The extension callback is called + * when the TS_TST_INFO object is already set up and not signed yet. + */ +/* FIXME: extension handling is not tested yet. */ +void TS_RESP_CTX_set_extension_cb(TS_RESP_CTX *ctx, + TS_extension_cb cb, void *data); + +/* The following methods can be used in the callbacks. */ +int TS_RESP_CTX_set_status_info(TS_RESP_CTX *ctx, + int status, const char *text); + +/* Sets the status info only if it is still TS_STATUS_GRANTED. */ +int TS_RESP_CTX_set_status_info_cond(TS_RESP_CTX *ctx, + int status, const char *text); + +int TS_RESP_CTX_add_failure_info(TS_RESP_CTX *ctx, int failure); + +/* The get methods below can be used in the extension callback. */ +TS_REQ *TS_RESP_CTX_get_request(TS_RESP_CTX *ctx); + +TS_TST_INFO *TS_RESP_CTX_get_tst_info(TS_RESP_CTX *ctx); + +/* + * Creates the signed TS_TST_INFO and puts it in TS_RESP. + * In case of errors it sets the status info properly. + * Returns NULL only in case of memory allocation/fatal error. + */ +TS_RESP *TS_RESP_create_response(TS_RESP_CTX *ctx, BIO *req_bio); + +/* + * Declarations related to response verification, + * they are defined in ts/ts_resp_verify.c. + */ + +int TS_RESP_verify_signature(PKCS7 *token, STACK_OF(X509) *certs, + X509_STORE *store, X509 **signer_out); + +/* Context structure for the generic verify method. */ + +/* Verify the signer's certificate and the signature of the response. */ +# define TS_VFY_SIGNATURE (1u << 0) +/* Verify the version number of the response. */ +# define TS_VFY_VERSION (1u << 1) +/* Verify if the policy supplied by the user matches the policy of the TSA. */ +# define TS_VFY_POLICY (1u << 2) +/* + * Verify the message imprint provided by the user. This flag should not be + * specified with TS_VFY_DATA. + */ +# define TS_VFY_IMPRINT (1u << 3) +/* + * Verify the message imprint computed by the verify method from the user + * provided data and the MD algorithm of the response. This flag should not + * be specified with TS_VFY_IMPRINT. + */ +# define TS_VFY_DATA (1u << 4) +/* Verify the nonce value. */ +# define TS_VFY_NONCE (1u << 5) +/* Verify if the TSA name field matches the signer certificate. */ +# define TS_VFY_SIGNER (1u << 6) +/* Verify if the TSA name field equals to the user provided name. */ +# define TS_VFY_TSA_NAME (1u << 7) + +/* You can use the following convenience constants. */ +# define TS_VFY_ALL_IMPRINT (TS_VFY_SIGNATURE \ + | TS_VFY_VERSION \ + | TS_VFY_POLICY \ + | TS_VFY_IMPRINT \ + | TS_VFY_NONCE \ + | TS_VFY_SIGNER \ + | TS_VFY_TSA_NAME) +# define TS_VFY_ALL_DATA (TS_VFY_SIGNATURE \ + | TS_VFY_VERSION \ + | TS_VFY_POLICY \ + | TS_VFY_DATA \ + | TS_VFY_NONCE \ + | TS_VFY_SIGNER \ + | TS_VFY_TSA_NAME) + +typedef struct TS_verify_ctx TS_VERIFY_CTX; + +int TS_RESP_verify_response(TS_VERIFY_CTX *ctx, TS_RESP *response); +int TS_RESP_verify_token(TS_VERIFY_CTX *ctx, PKCS7 *token); + +/* + * Declarations related to response verification context, + */ +TS_VERIFY_CTX *TS_VERIFY_CTX_new(void); +void TS_VERIFY_CTX_init(TS_VERIFY_CTX *ctx); +void TS_VERIFY_CTX_free(TS_VERIFY_CTX *ctx); +void TS_VERIFY_CTX_cleanup(TS_VERIFY_CTX *ctx); +int TS_VERIFY_CTX_set_flags(TS_VERIFY_CTX *ctx, int f); +int TS_VERIFY_CTX_add_flags(TS_VERIFY_CTX *ctx, int f); +BIO *TS_VERIFY_CTX_set_data(TS_VERIFY_CTX *ctx, BIO *b); +unsigned char *TS_VERIFY_CTX_set_imprint(TS_VERIFY_CTX *ctx, + unsigned char *hexstr, long len); +X509_STORE *TS_VERIFY_CTX_set_store(TS_VERIFY_CTX *ctx, X509_STORE *s); +STACK_OF(X509) *TS_VERIFY_CTS_set_certs(TS_VERIFY_CTX *ctx, STACK_OF(X509) *certs); + +/*- + * If ctx is NULL, it allocates and returns a new object, otherwise + * it returns ctx. It initialises all the members as follows: + * flags = TS_VFY_ALL_IMPRINT & ~(TS_VFY_TSA_NAME | TS_VFY_SIGNATURE) + * certs = NULL + * store = NULL + * policy = policy from the request or NULL if absent (in this case + * TS_VFY_POLICY is cleared from flags as well) + * md_alg = MD algorithm from request + * imprint, imprint_len = imprint from request + * data = NULL + * nonce, nonce_len = nonce from the request or NULL if absent (in this case + * TS_VFY_NONCE is cleared from flags as well) + * tsa_name = NULL + * Important: after calling this method TS_VFY_SIGNATURE should be added! + */ +TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx); + +/* Function declarations for TS_RESP defined in ts/ts_resp_print.c */ + +int TS_RESP_print_bio(BIO *bio, TS_RESP *a); +int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a); +int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a); + +/* Common utility functions defined in ts/ts_lib.c */ + +int TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num); +int TS_OBJ_print_bio(BIO *bio, const ASN1_OBJECT *obj); +int TS_ext_print_bio(BIO *bio, const STACK_OF(X509_EXTENSION) *extensions); +int TS_X509_ALGOR_print_bio(BIO *bio, const X509_ALGOR *alg); +int TS_MSG_IMPRINT_print_bio(BIO *bio, TS_MSG_IMPRINT *msg); + +/* + * Function declarations for handling configuration options, defined in + * ts/ts_conf.c + */ + +X509 *TS_CONF_load_cert(const char *file); +STACK_OF(X509) *TS_CONF_load_certs(const char *file); +EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass); +const char *TS_CONF_get_tsa_section(CONF *conf, const char *section); +int TS_CONF_set_serial(CONF *conf, const char *section, TS_serial_cb cb, + TS_RESP_CTX *ctx); +#ifndef OPENSSL_NO_ENGINE +int TS_CONF_set_crypto_device(CONF *conf, const char *section, + const char *device); +int TS_CONF_set_default_engine(const char *name); +#endif +int TS_CONF_set_signer_cert(CONF *conf, const char *section, + const char *cert, TS_RESP_CTX *ctx); +int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs, + TS_RESP_CTX *ctx); +int TS_CONF_set_signer_key(CONF *conf, const char *section, + const char *key, const char *pass, + TS_RESP_CTX *ctx); +int TS_CONF_set_signer_digest(CONF *conf, const char *section, + const char *md, TS_RESP_CTX *ctx); +int TS_CONF_set_def_policy(CONF *conf, const char *section, + const char *policy, TS_RESP_CTX *ctx); +int TS_CONF_set_policies(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_digests(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_accuracy(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_clock_precision_digits(CONF *conf, const char *section, + TS_RESP_CTX *ctx); +int TS_CONF_set_ordering(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_tsa_name(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_ess_cert_id_chain(CONF *conf, const char *section, + TS_RESP_CTX *ctx); + +/* -------------------------------------------------- */ +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_TS_strings(void); + +/* Error codes for the TS functions. */ + +/* Function codes. */ +# define TS_F_DEF_SERIAL_CB 110 +# define TS_F_DEF_TIME_CB 111 +# define TS_F_ESS_ADD_SIGNING_CERT 112 +# define TS_F_ESS_CERT_ID_NEW_INIT 113 +# define TS_F_ESS_SIGNING_CERT_NEW_INIT 114 +# define TS_F_INT_TS_RESP_VERIFY_TOKEN 149 +# define TS_F_PKCS7_TO_TS_TST_INFO 148 +# define TS_F_TS_ACCURACY_SET_MICROS 115 +# define TS_F_TS_ACCURACY_SET_MILLIS 116 +# define TS_F_TS_ACCURACY_SET_SECONDS 117 +# define TS_F_TS_CHECK_IMPRINTS 100 +# define TS_F_TS_CHECK_NONCES 101 +# define TS_F_TS_CHECK_POLICY 102 +# define TS_F_TS_CHECK_SIGNING_CERTS 103 +# define TS_F_TS_CHECK_STATUS_INFO 104 +# define TS_F_TS_COMPUTE_IMPRINT 145 +# define TS_F_TS_CONF_INVALID 151 +# define TS_F_TS_CONF_LOAD_CERT 153 +# define TS_F_TS_CONF_LOAD_CERTS 154 +# define TS_F_TS_CONF_LOAD_KEY 155 +# define TS_F_TS_CONF_LOOKUP_FAIL 152 +# define TS_F_TS_CONF_SET_DEFAULT_ENGINE 146 +# define TS_F_TS_GET_STATUS_TEXT 105 +# define TS_F_TS_MSG_IMPRINT_SET_ALGO 118 +# define TS_F_TS_REQ_SET_MSG_IMPRINT 119 +# define TS_F_TS_REQ_SET_NONCE 120 +# define TS_F_TS_REQ_SET_POLICY_ID 121 +# define TS_F_TS_RESP_CREATE_RESPONSE 122 +# define TS_F_TS_RESP_CREATE_TST_INFO 123 +# define TS_F_TS_RESP_CTX_ADD_FAILURE_INFO 124 +# define TS_F_TS_RESP_CTX_ADD_MD 125 +# define TS_F_TS_RESP_CTX_ADD_POLICY 126 +# define TS_F_TS_RESP_CTX_NEW 127 +# define TS_F_TS_RESP_CTX_SET_ACCURACY 128 +# define TS_F_TS_RESP_CTX_SET_CERTS 129 +# define TS_F_TS_RESP_CTX_SET_DEF_POLICY 130 +# define TS_F_TS_RESP_CTX_SET_SIGNER_CERT 131 +# define TS_F_TS_RESP_CTX_SET_STATUS_INFO 132 +# define TS_F_TS_RESP_GET_POLICY 133 +# define TS_F_TS_RESP_SET_GENTIME_WITH_PRECISION 134 +# define TS_F_TS_RESP_SET_STATUS_INFO 135 +# define TS_F_TS_RESP_SET_TST_INFO 150 +# define TS_F_TS_RESP_SIGN 136 +# define TS_F_TS_RESP_VERIFY_SIGNATURE 106 +# define TS_F_TS_TST_INFO_SET_ACCURACY 137 +# define TS_F_TS_TST_INFO_SET_MSG_IMPRINT 138 +# define TS_F_TS_TST_INFO_SET_NONCE 139 +# define TS_F_TS_TST_INFO_SET_POLICY_ID 140 +# define TS_F_TS_TST_INFO_SET_SERIAL 141 +# define TS_F_TS_TST_INFO_SET_TIME 142 +# define TS_F_TS_TST_INFO_SET_TSA 143 +# define TS_F_TS_VERIFY 108 +# define TS_F_TS_VERIFY_CERT 109 +# define TS_F_TS_VERIFY_CTX_NEW 144 + +/* Reason codes. */ +# define TS_R_BAD_PKCS7_TYPE 132 +# define TS_R_BAD_TYPE 133 +# define TS_R_CANNOT_LOAD_CERT 137 +# define TS_R_CANNOT_LOAD_KEY 138 +# define TS_R_CERTIFICATE_VERIFY_ERROR 100 +# define TS_R_COULD_NOT_SET_ENGINE 127 +# define TS_R_COULD_NOT_SET_TIME 115 +# define TS_R_DETACHED_CONTENT 134 +# define TS_R_ESS_ADD_SIGNING_CERT_ERROR 116 +# define TS_R_ESS_SIGNING_CERTIFICATE_ERROR 101 +# define TS_R_INVALID_NULL_POINTER 102 +# define TS_R_INVALID_SIGNER_CERTIFICATE_PURPOSE 117 +# define TS_R_MESSAGE_IMPRINT_MISMATCH 103 +# define TS_R_NONCE_MISMATCH 104 +# define TS_R_NONCE_NOT_RETURNED 105 +# define TS_R_NO_CONTENT 106 +# define TS_R_NO_TIME_STAMP_TOKEN 107 +# define TS_R_PKCS7_ADD_SIGNATURE_ERROR 118 +# define TS_R_PKCS7_ADD_SIGNED_ATTR_ERROR 119 +# define TS_R_PKCS7_TO_TS_TST_INFO_FAILED 129 +# define TS_R_POLICY_MISMATCH 108 +# define TS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 120 +# define TS_R_RESPONSE_SETUP_ERROR 121 +# define TS_R_SIGNATURE_FAILURE 109 +# define TS_R_THERE_MUST_BE_ONE_SIGNER 110 +# define TS_R_TIME_SYSCALL_ERROR 122 +# define TS_R_TOKEN_NOT_PRESENT 130 +# define TS_R_TOKEN_PRESENT 131 +# define TS_R_TSA_NAME_MISMATCH 111 +# define TS_R_TSA_UNTRUSTED 112 +# define TS_R_TST_INFO_SETUP_ERROR 123 +# define TS_R_TS_DATASIGN 124 +# define TS_R_UNACCEPTABLE_POLICY 125 +# define TS_R_UNSUPPORTED_MD_ALGORITHM 126 +# define TS_R_UNSUPPORTED_VERSION 113 +# define TS_R_VAR_BAD_VALUE 135 +# define TS_R_VAR_LOOKUP_FAILURE 136 +# define TS_R_WRONG_CONTENT_TYPE 114 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/txt_db.h b/android/x86/include/openssl/txt_db.h new file mode 100644 index 00000000..0e6c943e --- /dev/null +++ b/android/x86/include/openssl/txt_db.h @@ -0,0 +1,57 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_TXT_DB_H +# define HEADER_TXT_DB_H + +# include <openssl/opensslconf.h> +# include <openssl/bio.h> +# include <openssl/stack.h> +# include <openssl/lhash.h> + +# define DB_ERROR_OK 0 +# define DB_ERROR_MALLOC 1 +# define DB_ERROR_INDEX_CLASH 2 +# define DB_ERROR_INDEX_OUT_OF_RANGE 3 +# define DB_ERROR_NO_INDEX 4 +# define DB_ERROR_INSERT_INDEX_CLASH 5 +# define DB_ERROR_WRONG_NUM_FIELDS 6 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef OPENSSL_STRING *OPENSSL_PSTRING; +DEFINE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING) + +typedef struct txt_db_st { + int num_fields; + STACK_OF(OPENSSL_PSTRING) *data; + LHASH_OF(OPENSSL_STRING) **index; + int (**qual) (OPENSSL_STRING *); + long error; + long arg1; + long arg2; + OPENSSL_STRING *arg_row; +} TXT_DB; + +TXT_DB *TXT_DB_read(BIO *in, int num); +long TXT_DB_write(BIO *out, TXT_DB *db); +int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *), + OPENSSL_LH_HASHFUNC hash, OPENSSL_LH_COMPFUNC cmp); +void TXT_DB_free(TXT_DB *db); +OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, + OPENSSL_STRING *value); +int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/android/x86/include/openssl/ui.h b/android/x86/include/openssl/ui.h new file mode 100644 index 00000000..26f4f044 --- /dev/null +++ b/android/x86/include/openssl/ui.h @@ -0,0 +1,368 @@ +/* + * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_UI_H +# define HEADER_UI_H + +# include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_UI + +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/crypto.h> +# endif +# include <openssl/safestack.h> +# include <openssl/ossl_typ.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * All the following functions return -1 or NULL on error and in some cases + * (UI_process()) -2 if interrupted or in some other way cancelled. When + * everything is fine, they return 0, a positive value or a non-NULL pointer, + * all depending on their purpose. + */ + +/* Creators and destructor. */ +UI *UI_new(void); +UI *UI_new_method(const UI_METHOD *method); +void UI_free(UI *ui); + +/*- + The following functions are used to add strings to be printed and prompt + strings to prompt for data. The names are UI_{add,dup}_<function>_string + and UI_{add,dup}_input_boolean. + + UI_{add,dup}_<function>_string have the following meanings: + add add a text or prompt string. The pointers given to these + functions are used verbatim, no copying is done. + dup make a copy of the text or prompt string, then add the copy + to the collection of strings in the user interface. + <function> + The function is a name for the functionality that the given + string shall be used for. It can be one of: + input use the string as data prompt. + verify use the string as verification prompt. This + is used to verify a previous input. + info use the string for informational output. + error use the string for error output. + Honestly, there's currently no difference between info and error for the + moment. + + UI_{add,dup}_input_boolean have the same semantics for "add" and "dup", + and are typically used when one wants to prompt for a yes/no response. + + All of the functions in this group take a UI and a prompt string. + The string input and verify addition functions also take a flag argument, + a buffer for the result to end up with, a minimum input size and a maximum + input size (the result buffer MUST be large enough to be able to contain + the maximum number of characters). Additionally, the verify addition + functions takes another buffer to compare the result against. + The boolean input functions take an action description string (which should + be safe to ignore if the expected user action is obvious, for example with + a dialog box with an OK button and a Cancel button), a string of acceptable + characters to mean OK and to mean Cancel. The two last strings are checked + to make sure they don't have common characters. Additionally, the same + flag argument as for the string input is taken, as well as a result buffer. + The result buffer is required to be at least one byte long. Depending on + the answer, the first character from the OK or the Cancel character strings + will be stored in the first byte of the result buffer. No NUL will be + added, so the result is *not* a string. + + On success, the all return an index of the added information. That index + is useful when retrieving results with UI_get0_result(). */ +int UI_add_input_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize); +int UI_dup_input_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize); +int UI_add_verify_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize, + const char *test_buf); +int UI_dup_verify_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize, + const char *test_buf); +int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, + const char *ok_chars, const char *cancel_chars, + int flags, char *result_buf); +int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, + const char *ok_chars, const char *cancel_chars, + int flags, char *result_buf); +int UI_add_info_string(UI *ui, const char *text); +int UI_dup_info_string(UI *ui, const char *text); +int UI_add_error_string(UI *ui, const char *text); +int UI_dup_error_string(UI *ui, const char *text); + +/* These are the possible flags. They can be or'ed together. */ +/* Use to have echoing of input */ +# define UI_INPUT_FLAG_ECHO 0x01 +/* + * Use a default password. Where that password is found is completely up to + * the application, it might for example be in the user data set with + * UI_add_user_data(). It is not recommended to have more than one input in + * each UI being marked with this flag, or the application might get + * confused. + */ +# define UI_INPUT_FLAG_DEFAULT_PWD 0x02 + +/*- + * The user of these routines may want to define flags of their own. The core + * UI won't look at those, but will pass them on to the method routines. They + * must use higher bits so they don't get confused with the UI bits above. + * UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good + * example of use is this: + * + * #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE) + * +*/ +# define UI_INPUT_FLAG_USER_BASE 16 + +/*- + * The following function helps construct a prompt. object_desc is a + * textual short description of the object, for example "pass phrase", + * and object_name is the name of the object (might be a card name or + * a file name. + * The returned string shall always be allocated on the heap with + * OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). + * + * If the ui_method doesn't contain a pointer to a user-defined prompt + * constructor, a default string is built, looking like this: + * + * "Enter {object_desc} for {object_name}:" + * + * So, if object_desc has the value "pass phrase" and object_name has + * the value "foo.key", the resulting string is: + * + * "Enter pass phrase for foo.key:" +*/ +char *UI_construct_prompt(UI *ui_method, + const char *object_desc, const char *object_name); + +/* + * The following function is used to store a pointer to user-specific data. + * Any previous such pointer will be returned and replaced. + * + * For callback purposes, this function makes a lot more sense than using + * ex_data, since the latter requires that different parts of OpenSSL or + * applications share the same ex_data index. + * + * Note that the UI_OpenSSL() method completely ignores the user data. Other + * methods may not, however. + */ +void *UI_add_user_data(UI *ui, void *user_data); +/* We need a user data retrieving function as well. */ +void *UI_get0_user_data(UI *ui); + +/* Return the result associated with a prompt given with the index i. */ +const char *UI_get0_result(UI *ui, int i); + +/* When all strings have been added, process the whole thing. */ +int UI_process(UI *ui); + +/* + * Give a user interface parametrised control commands. This can be used to + * send down an integer, a data pointer or a function pointer, as well as be + * used to get information from a UI. + */ +int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)); + +/* The commands */ +/* + * Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the + * OpenSSL error stack before printing any info or added error messages and + * before any prompting. + */ +# define UI_CTRL_PRINT_ERRORS 1 +/* + * Check if a UI_process() is possible to do again with the same instance of + * a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0 + * if not. + */ +# define UI_CTRL_IS_REDOABLE 2 + +/* Some methods may use extra data */ +# define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg) +# define UI_get_app_data(s) UI_get_ex_data(s,0) + +#define UI_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, l, p, newf, dupf, freef) +int UI_set_ex_data(UI *r, int idx, void *arg); +void *UI_get_ex_data(UI *r, int idx); + +/* Use specific methods instead of the built-in one */ +void UI_set_default_method(const UI_METHOD *meth); +const UI_METHOD *UI_get_default_method(void); +const UI_METHOD *UI_get_method(UI *ui); +const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth); + +/* The method with all the built-in thingies */ +UI_METHOD *UI_OpenSSL(void); + +/* ---------- For method writers ---------- */ +/*- + A method contains a number of functions that implement the low level + of the User Interface. The functions are: + + an opener This function starts a session, maybe by opening + a channel to a tty, or by opening a window. + a writer This function is called to write a given string, + maybe to the tty, maybe as a field label in a + window. + a flusher This function is called to flush everything that + has been output so far. It can be used to actually + display a dialog box after it has been built. + a reader This function is called to read a given prompt, + maybe from the tty, maybe from a field in a + window. Note that it's called with all string + structures, not only the prompt ones, so it must + check such things itself. + a closer This function closes the session, maybe by closing + the channel to the tty, or closing the window. + + All these functions are expected to return: + + 0 on error. + 1 on success. + -1 on out-of-band events, for example if some prompting has + been canceled (by pressing Ctrl-C, for example). This is + only checked when returned by the flusher or the reader. + + The way this is used, the opener is first called, then the writer for all + strings, then the flusher, then the reader for all strings and finally the + closer. Note that if you want to prompt from a terminal or other command + line interface, the best is to have the reader also write the prompts + instead of having the writer do it. If you want to prompt from a dialog + box, the writer can be used to build up the contents of the box, and the + flusher to actually display the box and run the event loop until all data + has been given, after which the reader only grabs the given data and puts + them back into the UI strings. + + All method functions take a UI as argument. Additionally, the writer and + the reader take a UI_STRING. +*/ + +/* + * The UI_STRING type is the data structure that contains all the needed info + * about a string or a prompt, including test data for a verification prompt. + */ +typedef struct ui_string_st UI_STRING; +DEFINE_STACK_OF(UI_STRING) + +/* + * The different types of strings that are currently supported. This is only + * needed by method authors. + */ +enum UI_string_types { + UIT_NONE = 0, + UIT_PROMPT, /* Prompt for a string */ + UIT_VERIFY, /* Prompt for a string and verify */ + UIT_BOOLEAN, /* Prompt for a yes/no response */ + UIT_INFO, /* Send info to the user */ + UIT_ERROR /* Send an error message to the user */ +}; + +/* Create and manipulate methods */ +UI_METHOD *UI_create_method(const char *name); +void UI_destroy_method(UI_METHOD *ui_method); +int UI_method_set_opener(UI_METHOD *method, int (*opener) (UI *ui)); +int UI_method_set_writer(UI_METHOD *method, + int (*writer) (UI *ui, UI_STRING *uis)); +int UI_method_set_flusher(UI_METHOD *method, int (*flusher) (UI *ui)); +int UI_method_set_reader(UI_METHOD *method, + int (*reader) (UI *ui, UI_STRING *uis)); +int UI_method_set_closer(UI_METHOD *method, int (*closer) (UI *ui)); +int UI_method_set_prompt_constructor(UI_METHOD *method, + char *(*prompt_constructor) (UI *ui, + const char + *object_desc, + const char + *object_name)); +int (*UI_method_get_opener(UI_METHOD *method)) (UI *); +int (*UI_method_get_writer(UI_METHOD *method)) (UI *, UI_STRING *); +int (*UI_method_get_flusher(UI_METHOD *method)) (UI *); +int (*UI_method_get_reader(UI_METHOD *method)) (UI *, UI_STRING *); +int (*UI_method_get_closer(UI_METHOD *method)) (UI *); +char *(*UI_method_get_prompt_constructor(UI_METHOD *method)) (UI *, + const char *, + const char *); + +/* + * The following functions are helpers for method writers to access relevant + * data from a UI_STRING. + */ + +/* Return type of the UI_STRING */ +enum UI_string_types UI_get_string_type(UI_STRING *uis); +/* Return input flags of the UI_STRING */ +int UI_get_input_flags(UI_STRING *uis); +/* Return the actual string to output (the prompt, info or error) */ +const char *UI_get0_output_string(UI_STRING *uis); +/* + * Return the optional action string to output (the boolean prompt + * instruction) + */ +const char *UI_get0_action_string(UI_STRING *uis); +/* Return the result of a prompt */ +const char *UI_get0_result_string(UI_STRING *uis); +/* + * Return the string to test the result against. Only useful with verifies. + */ +const char *UI_get0_test_string(UI_STRING *uis); +/* Return the required minimum size of the result */ +int UI_get_result_minsize(UI_STRING *uis); +/* Return the required maximum size of the result */ +int UI_get_result_maxsize(UI_STRING *uis); +/* Set the result of a UI_STRING. */ +int UI_set_result(UI *ui, UI_STRING *uis, const char *result); + +/* A couple of popular utility functions */ +int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, + int verify); +int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, + int verify); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_UI_strings(void); + +/* Error codes for the UI functions. */ + +/* Function codes. */ +# define UI_F_GENERAL_ALLOCATE_BOOLEAN 108 +# define UI_F_GENERAL_ALLOCATE_PROMPT 109 +# define UI_F_UI_CREATE_METHOD 112 +# define UI_F_UI_CTRL 111 +# define UI_F_UI_DUP_ERROR_STRING 101 +# define UI_F_UI_DUP_INFO_STRING 102 +# define UI_F_UI_DUP_INPUT_BOOLEAN 110 +# define UI_F_UI_DUP_INPUT_STRING 103 +# define UI_F_UI_DUP_VERIFY_STRING 106 +# define UI_F_UI_GET0_RESULT 107 +# define UI_F_UI_NEW_METHOD 104 +# define UI_F_UI_SET_RESULT 105 + +/* Reason codes. */ +# define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS 104 +# define UI_R_INDEX_TOO_LARGE 102 +# define UI_R_INDEX_TOO_SMALL 103 +# define UI_R_NO_RESULT_BUFFER 105 +# define UI_R_RESULT_TOO_LARGE 100 +# define UI_R_RESULT_TOO_SMALL 101 +# define UI_R_UNKNOWN_CONTROL_COMMAND 106 + +# ifdef __cplusplus +} +# endif +# endif +#endif diff --git a/android/x86/include/openssl/whrlpool.h b/android/x86/include/openssl/whrlpool.h new file mode 100644 index 00000000..20ea3503 --- /dev/null +++ b/android/x86/include/openssl/whrlpool.h @@ -0,0 +1,48 @@ +/* + * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_WHRLPOOL_H +# define HEADER_WHRLPOOL_H + +#include <openssl/opensslconf.h> + +# ifndef OPENSSL_NO_WHIRLPOOL +# include <openssl/e_os2.h> +# include <stddef.h> +# ifdef __cplusplus +extern "C" { +# endif + +# define WHIRLPOOL_DIGEST_LENGTH (512/8) +# define WHIRLPOOL_BBLOCK 512 +# define WHIRLPOOL_COUNTER (256/8) + +typedef struct { + union { + unsigned char c[WHIRLPOOL_DIGEST_LENGTH]; + /* double q is here to ensure 64-bit alignment */ + double q[WHIRLPOOL_DIGEST_LENGTH / sizeof(double)]; + } H; + unsigned char data[WHIRLPOOL_BBLOCK / 8]; + unsigned int bitoff; + size_t bitlen[WHIRLPOOL_COUNTER / sizeof(size_t)]; +} WHIRLPOOL_CTX; + +int WHIRLPOOL_Init(WHIRLPOOL_CTX *c); +int WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *inp, size_t bytes); +void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *inp, size_t bits); +int WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c); +unsigned char *WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff --git a/android/x86/include/openssl/x509.h b/android/x86/include/openssl/x509.h new file mode 100644 index 00000000..c8996f35 --- /dev/null +++ b/android/x86/include/openssl/x509.h @@ -0,0 +1,1123 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* ==================================================================== + * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. + * ECDH support in OpenSSL originally developed by + * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. + */ + +#ifndef HEADER_X509_H +# define HEADER_X509_H + +# include <openssl/e_os2.h> +# include <openssl/ossl_typ.h> +# include <openssl/symhacks.h> +# include <openssl/buffer.h> +# include <openssl/evp.h> +# include <openssl/bio.h> +# include <openssl/stack.h> +# include <openssl/asn1.h> +# include <openssl/safestack.h> +# include <openssl/ec.h> + +# if OPENSSL_API_COMPAT < 0x10100000L +# include <openssl/rsa.h> +# include <openssl/dsa.h> +# include <openssl/dh.h> +# endif + +# include <openssl/sha.h> + +#ifdef __cplusplus +extern "C" { +#endif + +# define X509_FILETYPE_PEM 1 +# define X509_FILETYPE_ASN1 2 +# define X509_FILETYPE_DEFAULT 3 + +# define X509v3_KU_DIGITAL_SIGNATURE 0x0080 +# define X509v3_KU_NON_REPUDIATION 0x0040 +# define X509v3_KU_KEY_ENCIPHERMENT 0x0020 +# define X509v3_KU_DATA_ENCIPHERMENT 0x0010 +# define X509v3_KU_KEY_AGREEMENT 0x0008 +# define X509v3_KU_KEY_CERT_SIGN 0x0004 +# define X509v3_KU_CRL_SIGN 0x0002 +# define X509v3_KU_ENCIPHER_ONLY 0x0001 +# define X509v3_KU_DECIPHER_ONLY 0x8000 +# define X509v3_KU_UNDEF 0xffff + +struct X509_algor_st { + ASN1_OBJECT *algorithm; + ASN1_TYPE *parameter; +} /* X509_ALGOR */ ; + +typedef STACK_OF(X509_ALGOR) X509_ALGORS; + +typedef struct X509_val_st { + ASN1_TIME *notBefore; + ASN1_TIME *notAfter; +} X509_VAL; + +typedef struct X509_sig_st X509_SIG; + +typedef struct X509_name_entry_st X509_NAME_ENTRY; + +DEFINE_STACK_OF(X509_NAME_ENTRY) + +DEFINE_STACK_OF(X509_NAME) + +# define X509_EX_V_NETSCAPE_HACK 0x8000 +# define X509_EX_V_INIT 0x0001 +typedef struct X509_extension_st X509_EXTENSION; + +typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; + +DEFINE_STACK_OF(X509_EXTENSION) + +typedef struct x509_attributes_st X509_ATTRIBUTE; + +DEFINE_STACK_OF(X509_ATTRIBUTE) + +typedef struct X509_req_info_st X509_REQ_INFO; + +typedef struct X509_req_st X509_REQ; + +typedef struct x509_cert_aux_st X509_CERT_AUX; + +typedef struct x509_cinf_st X509_CINF; + +DEFINE_STACK_OF(X509) + +/* This is used for a table of trust checking functions */ + +typedef struct x509_trust_st { + int trust; + int flags; + int (*check_trust) (struct x509_trust_st *, X509 *, int); + char *name; + int arg1; + void *arg2; +} X509_TRUST; + +DEFINE_STACK_OF(X509_TRUST) + +/* standard trust ids */ + +# define X509_TRUST_DEFAULT 0 /* Only valid in purpose settings */ + +# define X509_TRUST_COMPAT 1 +# define X509_TRUST_SSL_CLIENT 2 +# define X509_TRUST_SSL_SERVER 3 +# define X509_TRUST_EMAIL 4 +# define X509_TRUST_OBJECT_SIGN 5 +# define X509_TRUST_OCSP_SIGN 6 +# define X509_TRUST_OCSP_REQUEST 7 +# define X509_TRUST_TSA 8 + +/* Keep these up to date! */ +# define X509_TRUST_MIN 1 +# define X509_TRUST_MAX 8 + +/* trust_flags values */ +# define X509_TRUST_DYNAMIC (1U << 0) +# define X509_TRUST_DYNAMIC_NAME (1U << 1) +/* No compat trust if self-signed, preempts "DO_SS" */ +# define X509_TRUST_NO_SS_COMPAT (1U << 2) +/* Compat trust if no explicit accepted trust EKUs */ +# define X509_TRUST_DO_SS_COMPAT (1U << 3) +/* Accept "anyEKU" as a wildcard trust OID */ +# define X509_TRUST_OK_ANY_EKU (1U << 4) + +/* check_trust return codes */ + +# define X509_TRUST_TRUSTED 1 +# define X509_TRUST_REJECTED 2 +# define X509_TRUST_UNTRUSTED 3 + +/* Flags for X509_print_ex() */ + +# define X509_FLAG_COMPAT 0 +# define X509_FLAG_NO_HEADER 1L +# define X509_FLAG_NO_VERSION (1L << 1) +# define X509_FLAG_NO_SERIAL (1L << 2) +# define X509_FLAG_NO_SIGNAME (1L << 3) +# define X509_FLAG_NO_ISSUER (1L << 4) +# define X509_FLAG_NO_VALIDITY (1L << 5) +# define X509_FLAG_NO_SUBJECT (1L << 6) +# define X509_FLAG_NO_PUBKEY (1L << 7) +# define X509_FLAG_NO_EXTENSIONS (1L << 8) +# define X509_FLAG_NO_SIGDUMP (1L << 9) +# define X509_FLAG_NO_AUX (1L << 10) +# define X509_FLAG_NO_ATTRIBUTES (1L << 11) +# define X509_FLAG_NO_IDS (1L << 12) + +/* Flags specific to X509_NAME_print_ex() */ + +/* The field separator information */ + +# define XN_FLAG_SEP_MASK (0xf << 16) + +# define XN_FLAG_COMPAT 0/* Traditional; use old X509_NAME_print */ +# define XN_FLAG_SEP_COMMA_PLUS (1 << 16)/* RFC2253 ,+ */ +# define XN_FLAG_SEP_CPLUS_SPC (2 << 16)/* ,+ spaced: more readable */ +# define XN_FLAG_SEP_SPLUS_SPC (3 << 16)/* ;+ spaced */ +# define XN_FLAG_SEP_MULTILINE (4 << 16)/* One line per field */ + +# define XN_FLAG_DN_REV (1 << 20)/* Reverse DN order */ + +/* How the field name is shown */ + +# define XN_FLAG_FN_MASK (0x3 << 21) + +# define XN_FLAG_FN_SN 0/* Object short name */ +# define XN_FLAG_FN_LN (1 << 21)/* Object long name */ +# define XN_FLAG_FN_OID (2 << 21)/* Always use OIDs */ +# define XN_FLAG_FN_NONE (3 << 21)/* No field names */ + +# define XN_FLAG_SPC_EQ (1 << 23)/* Put spaces round '=' */ + +/* + * This determines if we dump fields we don't recognise: RFC2253 requires + * this. + */ + +# define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24) + +# define XN_FLAG_FN_ALIGN (1 << 25)/* Align field names to 20 + * characters */ + +/* Complete set of RFC2253 flags */ + +# define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \ + XN_FLAG_SEP_COMMA_PLUS | \ + XN_FLAG_DN_REV | \ + XN_FLAG_FN_SN | \ + XN_FLAG_DUMP_UNKNOWN_FIELDS) + +/* readable oneline form */ + +# define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \ + ASN1_STRFLGS_ESC_QUOTE | \ + XN_FLAG_SEP_CPLUS_SPC | \ + XN_FLAG_SPC_EQ | \ + XN_FLAG_FN_SN) + +/* readable multiline form */ + +# define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \ + ASN1_STRFLGS_ESC_MSB | \ + XN_FLAG_SEP_MULTILINE | \ + XN_FLAG_SPC_EQ | \ + XN_FLAG_FN_LN | \ + XN_FLAG_FN_ALIGN) + +DEFINE_STACK_OF(X509_REVOKED) + +typedef struct X509_crl_info_st X509_CRL_INFO; + +DEFINE_STACK_OF(X509_CRL) + +typedef struct private_key_st { + int version; + /* The PKCS#8 data types */ + X509_ALGOR *enc_algor; + ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */ + /* When decrypted, the following will not be NULL */ + EVP_PKEY *dec_pkey; + /* used to encrypt and decrypt */ + int key_length; + char *key_data; + int key_free; /* true if we should auto free key_data */ + /* expanded version of 'enc_algor' */ + EVP_CIPHER_INFO cipher; +} X509_PKEY; + +typedef struct X509_info_st { + X509 *x509; + X509_CRL *crl; + X509_PKEY *x_pkey; + EVP_CIPHER_INFO enc_cipher; + int enc_len; + char *enc_data; +} X509_INFO; + +DEFINE_STACK_OF(X509_INFO) + +/* + * The next 2 structures and their 8 routines were sent to me by Pat Richard + * <patr@x509.com> and are used to manipulate Netscapes spki structures - + * useful if you are writing a CA web page + */ +typedef struct Netscape_spkac_st { + X509_PUBKEY *pubkey; + ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */ +} NETSCAPE_SPKAC; + +typedef struct Netscape_spki_st { + NETSCAPE_SPKAC *spkac; /* signed public key and challenge */ + X509_ALGOR sig_algor; + ASN1_BIT_STRING *signature; +} NETSCAPE_SPKI; + +/* Netscape certificate sequence structure */ +typedef struct Netscape_certificate_sequence { + ASN1_OBJECT *type; + STACK_OF(X509) *certs; +} NETSCAPE_CERT_SEQUENCE; + +/*- Unused (and iv length is wrong) +typedef struct CBCParameter_st + { + unsigned char iv[8]; + } CBC_PARAM; +*/ + +/* Password based encryption structure */ + +typedef struct PBEPARAM_st { + ASN1_OCTET_STRING *salt; + ASN1_INTEGER *iter; +} PBEPARAM; + +/* Password based encryption V2 structures */ + +typedef struct PBE2PARAM_st { + X509_ALGOR *keyfunc; + X509_ALGOR *encryption; +} PBE2PARAM; + +typedef struct PBKDF2PARAM_st { +/* Usually OCTET STRING but could be anything */ + ASN1_TYPE *salt; + ASN1_INTEGER *iter; + ASN1_INTEGER *keylength; + X509_ALGOR *prf; +} PBKDF2PARAM; + +#ifdef __cplusplus +} +#endif + +# include <openssl/x509_vfy.h> +# include <openssl/pkcs7.h> + +#ifdef __cplusplus +extern "C" { +#endif + +# define X509_EXT_PACK_UNKNOWN 1 +# define X509_EXT_PACK_STRING 2 + +# define X509_extract_key(x) X509_get_pubkey(x)/*****/ +# define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) +# define X509_name_cmp(a,b) X509_NAME_cmp((a),(b)) + +void X509_CRL_set_default_method(const X509_CRL_METHOD *meth); +X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init) (X509_CRL *crl), + int (*crl_free) (X509_CRL *crl), + int (*crl_lookup) (X509_CRL *crl, + X509_REVOKED **ret, + ASN1_INTEGER *ser, + X509_NAME *issuer), + int (*crl_verify) (X509_CRL *crl, + EVP_PKEY *pk)); +void X509_CRL_METHOD_free(X509_CRL_METHOD *m); + +void X509_CRL_set_meth_data(X509_CRL *crl, void *dat); +void *X509_CRL_get_meth_data(X509_CRL *crl); + +const char *X509_verify_cert_error_string(long n); + +int X509_verify(X509 *a, EVP_PKEY *r); + +int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); +int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); +int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); + +NETSCAPE_SPKI *NETSCAPE_SPKI_b64_decode(const char *str, int len); +char *NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x); +EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x); +int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey); + +int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki); + +int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent); +int X509_signature_print(BIO *bp, const X509_ALGOR *alg, + const ASN1_STRING *sig); + +int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx); +# ifndef OPENSSL_NO_OCSP +int X509_http_nbio(OCSP_REQ_CTX *rctx, X509 **pcert); +# endif +int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx); +int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx); +# ifndef OPENSSL_NO_OCSP +int X509_CRL_http_nbio(OCSP_REQ_CTX *rctx, X509_CRL **pcrl); +# endif +int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md); + +int X509_pubkey_digest(const X509 *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_digest(const X509 *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); + +# ifndef OPENSSL_NO_STDIO +X509 *d2i_X509_fp(FILE *fp, X509 **x509); +int i2d_X509_fp(FILE *fp, X509 *x509); +X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl); +int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl); +X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req); +int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req); +# ifndef OPENSSL_NO_RSA +RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa); +int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa); +RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa); +int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa); +RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa); +int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa); +# endif +# ifndef OPENSSL_NO_DSA +DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); +int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa); +DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); +int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); +# endif +# ifndef OPENSSL_NO_EC +EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey); +int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey); +EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey); +int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey); +# endif +X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8); +int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8); +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, + PKCS8_PRIV_KEY_INFO **p8inf); +int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf); +int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key); +int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a); +int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); +# endif + +X509 *d2i_X509_bio(BIO *bp, X509 **x509); +int i2d_X509_bio(BIO *bp, X509 *x509); +X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl); +int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl); +X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req); +int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req); +# ifndef OPENSSL_NO_RSA +RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa); +int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa); +RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa); +int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa); +RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa); +int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa); +# endif +# ifndef OPENSSL_NO_DSA +DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa); +int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa); +DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); +int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); +# endif +# ifndef OPENSSL_NO_EC +EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey); +int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey); +EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey); +int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey); +# endif +X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8); +int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8); +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, + PKCS8_PRIV_KEY_INFO **p8inf); +int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf); +int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key); +int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); +int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); + +X509 *X509_dup(X509 *x509); +X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa); +X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex); +X509_CRL *X509_CRL_dup(X509_CRL *crl); +X509_REVOKED *X509_REVOKED_dup(X509_REVOKED *rev); +X509_REQ *X509_REQ_dup(X509_REQ *req); +X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn); +int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, + void *pval); +void X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype, + const void **ppval, const X509_ALGOR *algor); +void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md); +int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b); + +X509_NAME *X509_NAME_dup(X509_NAME *xn); +X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); + +int X509_cmp_time(const ASN1_TIME *s, time_t *t); +int X509_cmp_current_time(const ASN1_TIME *s); +ASN1_TIME *X509_time_adj(ASN1_TIME *s, long adj, time_t *t); +ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s, + int offset_day, long offset_sec, time_t *t); +ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long adj); + +const char *X509_get_default_cert_area(void); +const char *X509_get_default_cert_dir(void); +const char *X509_get_default_cert_file(void); +const char *X509_get_default_cert_dir_env(void); +const char *X509_get_default_cert_file_env(void); +const char *X509_get_default_private_dir(void); + +X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); +X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey); + +DECLARE_ASN1_FUNCTIONS(X509_ALGOR) +DECLARE_ASN1_ENCODE_FUNCTIONS(X509_ALGORS, X509_ALGORS, X509_ALGORS) +DECLARE_ASN1_FUNCTIONS(X509_VAL) + +DECLARE_ASN1_FUNCTIONS(X509_PUBKEY) + +int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); +EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key); +EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key); +int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain); +long X509_get_pathlen(X509 *x); +int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp); +EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length); +# ifndef OPENSSL_NO_RSA +int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp); +RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length); +# endif +# ifndef OPENSSL_NO_DSA +int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp); +DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length); +# endif +# ifndef OPENSSL_NO_EC +int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp); +EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length); +# endif + +DECLARE_ASN1_FUNCTIONS(X509_SIG) +void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **palg, + const ASN1_OCTET_STRING **pdigest); +void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **palg, + ASN1_OCTET_STRING **pdigest); + +DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO) +DECLARE_ASN1_FUNCTIONS(X509_REQ) + +DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE) +X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value); + +DECLARE_ASN1_FUNCTIONS(X509_EXTENSION) +DECLARE_ASN1_ENCODE_FUNCTIONS(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS) + +DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY) + +DECLARE_ASN1_FUNCTIONS(X509_NAME) + +int X509_NAME_set(X509_NAME **xn, X509_NAME *name); + +DECLARE_ASN1_FUNCTIONS(X509_CINF) + +DECLARE_ASN1_FUNCTIONS(X509) +DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX) + +#define X509_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, l, p, newf, dupf, freef) +int X509_set_ex_data(X509 *r, int idx, void *arg); +void *X509_get_ex_data(X509 *r, int idx); +int i2d_X509_AUX(X509 *a, unsigned char **pp); +X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length); + +int i2d_re_X509_tbs(X509 *x, unsigned char **pp); + +void X509_get0_signature(const ASN1_BIT_STRING **psig, + const X509_ALGOR **palg, const X509 *x); +int X509_get_signature_nid(const X509 *x); + +int X509_trusted(const X509 *x); +int X509_alias_set1(X509 *x, const unsigned char *name, int len); +int X509_keyid_set1(X509 *x, const unsigned char *id, int len); +unsigned char *X509_alias_get0(X509 *x, int *len); +unsigned char *X509_keyid_get0(X509 *x, int *len); +int (*X509_TRUST_set_default(int (*trust) (int, X509 *, int))) (int, X509 *, + int); +int X509_TRUST_set(int *t, int trust); +int X509_add1_trust_object(X509 *x, const ASN1_OBJECT *obj); +int X509_add1_reject_object(X509 *x, const ASN1_OBJECT *obj); +void X509_trust_clear(X509 *x); +void X509_reject_clear(X509 *x); + +STACK_OF(ASN1_OBJECT) *X509_get0_trust_objects(X509 *x); +STACK_OF(ASN1_OBJECT) *X509_get0_reject_objects(X509 *x); + +DECLARE_ASN1_FUNCTIONS(X509_REVOKED) +DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO) +DECLARE_ASN1_FUNCTIONS(X509_CRL) + +int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev); +int X509_CRL_get0_by_serial(X509_CRL *crl, + X509_REVOKED **ret, ASN1_INTEGER *serial); +int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x); + +X509_PKEY *X509_PKEY_new(void); +void X509_PKEY_free(X509_PKEY *a); + +DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI) +DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC) +DECLARE_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE) + +X509_INFO *X509_INFO_new(void); +void X509_INFO_free(X509_INFO *a); +char *X509_NAME_oneline(const X509_NAME *a, char *buf, int size); + +int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *algor1, + ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey); + +int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data, + unsigned char *md, unsigned int *len); + +int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, + X509_ALGOR *algor2, ASN1_BIT_STRING *signature, + char *data, EVP_PKEY *pkey, const EVP_MD *type); + +int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *data, + unsigned char *md, unsigned int *len); + +int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1, + ASN1_BIT_STRING *signature, void *data, EVP_PKEY *pkey); + +int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, + X509_ALGOR *algor2, ASN1_BIT_STRING *signature, void *data, + EVP_PKEY *pkey, const EVP_MD *type); +int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, + X509_ALGOR *algor2, ASN1_BIT_STRING *signature, + void *asn, EVP_MD_CTX *ctx); + +long X509_get_version(const X509 *x); +int X509_set_version(X509 *x, long version); +int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial); +ASN1_INTEGER *X509_get_serialNumber(X509 *x); +const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x); +int X509_set_issuer_name(X509 *x, X509_NAME *name); +X509_NAME *X509_get_issuer_name(const X509 *a); +int X509_set_subject_name(X509 *x, X509_NAME *name); +X509_NAME *X509_get_subject_name(const X509 *a); +const ASN1_TIME * X509_get0_notBefore(const X509 *x); +ASN1_TIME *X509_getm_notBefore(const X509 *x); +int X509_set1_notBefore(X509 *x, const ASN1_TIME *tm); +const ASN1_TIME *X509_get0_notAfter(const X509 *x); +ASN1_TIME *X509_getm_notAfter(const X509 *x); +int X509_set1_notAfter(X509 *x, const ASN1_TIME *tm); +int X509_set_pubkey(X509 *x, EVP_PKEY *pkey); +int X509_up_ref(X509 *x); +int X509_get_signature_type(const X509 *x); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define X509_get_notBefore X509_getm_notBefore +# define X509_get_notAfter X509_getm_notAfter +# define X509_set_notBefore X509_set1_notBefore +# define X509_set_notAfter X509_set1_notAfter +#endif + + +/* + * This one is only used so that a binary form can output, as in + * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) + */ +X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x); +const STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x); +void X509_get0_uids(const X509 *x, const ASN1_BIT_STRING **piuid, + const ASN1_BIT_STRING **psuid); +const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x); + +EVP_PKEY *X509_get0_pubkey(const X509 *x); +EVP_PKEY *X509_get_pubkey(X509 *x); +ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x); +int X509_certificate_type(const X509 *x, const EVP_PKEY *pubkey); + +long X509_REQ_get_version(const X509_REQ *req); +int X509_REQ_set_version(X509_REQ *x, long version); +X509_NAME *X509_REQ_get_subject_name(const X509_REQ *req); +int X509_REQ_set_subject_name(X509_REQ *req, X509_NAME *name); +void X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig, + const X509_ALGOR **palg); +int X509_REQ_get_signature_nid(const X509_REQ *req); +int i2d_re_X509_REQ_tbs(X509_REQ *req, unsigned char **pp); +int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey); +EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req); +EVP_PKEY *X509_REQ_get0_pubkey(X509_REQ *req); +X509_PUBKEY *X509_REQ_get_X509_PUBKEY(X509_REQ *req); +int X509_REQ_extension_nid(int nid); +int *X509_REQ_get_extension_nids(void); +void X509_REQ_set_extension_nids(int *nids); +STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req); +int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, + int nid); +int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts); +int X509_REQ_get_attr_count(const X509_REQ *req); +int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid, int lastpos); +int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, const ASN1_OBJECT *obj, + int lastpos); +X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc); +X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc); +int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr); +int X509_REQ_add1_attr_by_OBJ(X509_REQ *req, + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len); +int X509_REQ_add1_attr_by_NID(X509_REQ *req, + int nid, int type, + const unsigned char *bytes, int len); +int X509_REQ_add1_attr_by_txt(X509_REQ *req, + const char *attrname, int type, + const unsigned char *bytes, int len); + +int X509_CRL_set_version(X509_CRL *x, long version); +int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name); +int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm); +int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm); +int X509_CRL_sort(X509_CRL *crl); +int X509_CRL_up_ref(X509_CRL *crl); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate +# define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate +#endif + +long X509_CRL_get_version(const X509_CRL *crl); +const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl); +const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl); +DEPRECATEDIN_1_1_0(ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl)) +DEPRECATEDIN_1_1_0(ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl)) +X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl); +const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl); +STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl); +void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, + const X509_ALGOR **palg); +int X509_CRL_get_signature_nid(const X509_CRL *crl); +int i2d_re_X509_CRL_tbs(X509_CRL *req, unsigned char **pp); + +const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x); +int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial); +const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x); +int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm); +const STACK_OF(X509_EXTENSION) * +X509_REVOKED_get0_extensions(const X509_REVOKED *r); + +X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer, + EVP_PKEY *skey, const EVP_MD *md, unsigned int flags); + +int X509_REQ_check_private_key(X509_REQ *x509, EVP_PKEY *pkey); + +int X509_check_private_key(const X509 *x509, const EVP_PKEY *pkey); +int X509_chain_check_suiteb(int *perror_depth, + X509 *x, STACK_OF(X509) *chain, + unsigned long flags); +int X509_CRL_check_suiteb(X509_CRL *crl, EVP_PKEY *pk, unsigned long flags); +STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain); + +int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b); +unsigned long X509_issuer_and_serial_hash(X509 *a); + +int X509_issuer_name_cmp(const X509 *a, const X509 *b); +unsigned long X509_issuer_name_hash(X509 *a); + +int X509_subject_name_cmp(const X509 *a, const X509 *b); +unsigned long X509_subject_name_hash(X509 *x); + +# ifndef OPENSSL_NO_MD5 +unsigned long X509_issuer_name_hash_old(X509 *a); +unsigned long X509_subject_name_hash_old(X509 *x); +# endif + +int X509_cmp(const X509 *a, const X509 *b); +int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b); +unsigned long X509_NAME_hash(X509_NAME *x); +unsigned long X509_NAME_hash_old(X509_NAME *x); + +int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b); +int X509_CRL_match(const X509_CRL *a, const X509_CRL *b); +int X509_aux_print(BIO *out, X509 *x, int indent); +# ifndef OPENSSL_NO_STDIO +int X509_print_ex_fp(FILE *bp, X509 *x, unsigned long nmflag, + unsigned long cflag); +int X509_print_fp(FILE *bp, X509 *x); +int X509_CRL_print_fp(FILE *bp, X509_CRL *x); +int X509_REQ_print_fp(FILE *bp, X509_REQ *req); +int X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent, + unsigned long flags); +# endif + +int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase); +int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent, + unsigned long flags); +int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflag, + unsigned long cflag); +int X509_print(BIO *bp, X509 *x); +int X509_ocspid_print(BIO *bp, X509 *x); +int X509_CRL_print(BIO *bp, X509_CRL *x); +int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, + unsigned long cflag); +int X509_REQ_print(BIO *bp, X509_REQ *req); + +int X509_NAME_entry_count(const X509_NAME *name); +int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len); +int X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, + char *buf, int len); + +/* + * NOTE: you should be passing -1, not 0 as lastpos. The functions that use + * lastpos, search after that position on. + */ +int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos); +int X509_NAME_get_index_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, + int lastpos); +X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc); +X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); +int X509_NAME_add_entry(X509_NAME *name, const X509_NAME_ENTRY *ne, + int loc, int set); +int X509_NAME_add_entry_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len, int loc, + int set); +int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, + const unsigned char *bytes, int len, int loc, + int set); +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, + const char *field, int type, + const unsigned char *bytes, + int len); +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, + int type, + const unsigned char *bytes, + int len); +int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, + const unsigned char *bytes, int len, int loc, + int set); +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, + int len); +int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, const ASN1_OBJECT *obj); +int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, + const unsigned char *bytes, int len); +ASN1_OBJECT *X509_NAME_ENTRY_get_object(const X509_NAME_ENTRY *ne); +ASN1_STRING * X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne); +int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne); + +int X509_NAME_get0_der(X509_NAME *nm, const unsigned char **pder, + size_t *pderlen); + +int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); +int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, + int nid, int lastpos); +int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, + const ASN1_OBJECT *obj, int lastpos); +int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, + int crit, int lastpos); +X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc); +X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc); +STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, + X509_EXTENSION *ex, int loc); + +int X509_get_ext_count(const X509 *x); +int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos); +int X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj, int lastpos); +int X509_get_ext_by_critical(const X509 *x, int crit, int lastpos); +X509_EXTENSION *X509_get_ext(const X509 *x, int loc); +X509_EXTENSION *X509_delete_ext(X509 *x, int loc); +int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc); +void *X509_get_ext_d2i(const X509 *x, int nid, int *crit, int *idx); +int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, + unsigned long flags); + +int X509_CRL_get_ext_count(const X509_CRL *x); +int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid, int lastpos); +int X509_CRL_get_ext_by_OBJ(const X509_CRL *x, const ASN1_OBJECT *obj, + int lastpos); +int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit, int lastpos); +X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc); +X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); +int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc); +void *X509_CRL_get_ext_d2i(const X509_CRL *x, int nid, int *crit, int *idx); +int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit, + unsigned long flags); + +int X509_REVOKED_get_ext_count(const X509_REVOKED *x); +int X509_REVOKED_get_ext_by_NID(const X509_REVOKED *x, int nid, int lastpos); +int X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED *x, const ASN1_OBJECT *obj, + int lastpos); +int X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x, int crit, + int lastpos); +X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc); +X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc); +int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc); +void *X509_REVOKED_get_ext_d2i(const X509_REVOKED *x, int nid, int *crit, + int *idx); +int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit, + unsigned long flags); + +X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, + int nid, int crit, + ASN1_OCTET_STRING *data); +X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, + const ASN1_OBJECT *obj, int crit, + ASN1_OCTET_STRING *data); +int X509_EXTENSION_set_object(X509_EXTENSION *ex, const ASN1_OBJECT *obj); +int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); +int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data); +ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex); +ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); +int X509_EXTENSION_get_critical(const X509_EXTENSION *ex); + +int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x); +int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, + int lastpos); +int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, + const ASN1_OBJECT *obj, int lastpos); +X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc); +X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, + X509_ATTRIBUTE *attr); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) + **x, const ASN1_OBJECT *obj, + int type, + const unsigned char *bytes, + int len); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) + **x, int nid, int type, + const unsigned char *bytes, + int len); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) + **x, const char *attrname, + int type, + const unsigned char *bytes, + int len); +void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x, + const ASN1_OBJECT *obj, int lastpos, int type); +X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, + int atrtype, const void *data, + int len); +X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, + const ASN1_OBJECT *obj, + int atrtype, const void *data, + int len); +X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr, + const char *atrname, int type, + const unsigned char *bytes, + int len); +int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj); +int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, + const void *data, int len); +void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, int atrtype, + void *data); +int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr); +ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr); +ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx); + +int EVP_PKEY_get_attr_count(const EVP_PKEY *key); +int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid, int lastpos); +int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, const ASN1_OBJECT *obj, + int lastpos); +X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc); +X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc); +int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr); +int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key, + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len); +int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key, + int nid, int type, + const unsigned char *bytes, int len); +int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key, + const char *attrname, int type, + const unsigned char *bytes, int len); + +int X509_verify_cert(X509_STORE_CTX *ctx); + +/* lookup a cert from a X509 STACK */ +X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name, + ASN1_INTEGER *serial); +X509 *X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name); + +DECLARE_ASN1_FUNCTIONS(PBEPARAM) +DECLARE_ASN1_FUNCTIONS(PBE2PARAM) +DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM) + +int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, + const unsigned char *salt, int saltlen); + +X509_ALGOR *PKCS5_pbe_set(int alg, int iter, + const unsigned char *salt, int saltlen); +X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, + unsigned char *salt, int saltlen); +X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, + unsigned char *salt, int saltlen, + unsigned char *aiv, int prf_nid); + +#ifndef OPENSSL_NO_SCRYPT +X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher, + const unsigned char *salt, int saltlen, + unsigned char *aiv, uint64_t N, uint64_t r, + uint64_t p); +#endif + +X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, + int prf_nid, int keylen); + +/* PKCS#8 utilities */ + +DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) + +EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8); +PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey); + +int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, + int version, int ptype, void *pval, + unsigned char *penc, int penclen); +int PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, + const unsigned char **pk, int *ppklen, + const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8); + +const STACK_OF(X509_ATTRIBUTE) * +PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *p8); +int PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type, + const unsigned char *bytes, int len); + +int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, + int ptype, void *pval, + unsigned char *penc, int penclen); +int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, + const unsigned char **pk, int *ppklen, + X509_ALGOR **pa, X509_PUBKEY *pub); + +int X509_check_trust(X509 *x, int id, int flags); +int X509_TRUST_get_count(void); +X509_TRUST *X509_TRUST_get0(int idx); +int X509_TRUST_get_by_id(int id); +int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int), + const char *name, int arg1, void *arg2); +void X509_TRUST_cleanup(void); +int X509_TRUST_get_flags(const X509_TRUST *xp); +char *X509_TRUST_get0_name(const X509_TRUST *xp); +int X509_TRUST_get_trust(const X509_TRUST *xp); + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_X509_strings(void); + +/* Error codes for the X509 functions. */ + +/* Function codes. */ +# define X509_F_ADD_CERT_DIR 100 +# define X509_F_BUILD_CHAIN 106 +# define X509_F_BY_FILE_CTRL 101 +# define X509_F_CHECK_NAME_CONSTRAINTS 149 +# define X509_F_CHECK_POLICY 145 +# define X509_F_DANE_I2D 107 +# define X509_F_DIR_CTRL 102 +# define X509_F_GET_CERT_BY_SUBJECT 103 +# define X509_F_NETSCAPE_SPKI_B64_DECODE 129 +# define X509_F_NETSCAPE_SPKI_B64_ENCODE 130 +# define X509_F_X509AT_ADD1_ATTR 135 +# define X509_F_X509V3_ADD_EXT 104 +# define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136 +# define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137 +# define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140 +# define X509_F_X509_ATTRIBUTE_GET0_DATA 139 +# define X509_F_X509_ATTRIBUTE_SET1_DATA 138 +# define X509_F_X509_CHECK_PRIVATE_KEY 128 +# define X509_F_X509_CRL_DIFF 105 +# define X509_F_X509_CRL_PRINT_FP 147 +# define X509_F_X509_EXTENSION_CREATE_BY_NID 108 +# define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 +# define X509_F_X509_GET_PUBKEY_PARAMETERS 110 +# define X509_F_X509_LOAD_CERT_CRL_FILE 132 +# define X509_F_X509_LOAD_CERT_FILE 111 +# define X509_F_X509_LOAD_CRL_FILE 112 +# define X509_F_X509_NAME_ADD_ENTRY 113 +# define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114 +# define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131 +# define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 +# define X509_F_X509_NAME_ONELINE 116 +# define X509_F_X509_NAME_PRINT 117 +# define X509_F_X509_OBJECT_NEW 150 +# define X509_F_X509_PRINT_EX_FP 118 +# define X509_F_X509_PUBKEY_DECODE 148 +# define X509_F_X509_PUBKEY_GET0 119 +# define X509_F_X509_PUBKEY_SET 120 +# define X509_F_X509_REQ_CHECK_PRIVATE_KEY 144 +# define X509_F_X509_REQ_PRINT_EX 121 +# define X509_F_X509_REQ_PRINT_FP 122 +# define X509_F_X509_REQ_TO_X509 123 +# define X509_F_X509_STORE_ADD_CERT 124 +# define X509_F_X509_STORE_ADD_CRL 125 +# define X509_F_X509_STORE_CTX_GET1_ISSUER 146 +# define X509_F_X509_STORE_CTX_INIT 143 +# define X509_F_X509_STORE_CTX_NEW 142 +# define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134 +# define X509_F_X509_TO_X509_REQ 126 +# define X509_F_X509_TRUST_ADD 133 +# define X509_F_X509_TRUST_SET 141 +# define X509_F_X509_VERIFY_CERT 127 + +/* Reason codes. */ +# define X509_R_AKID_MISMATCH 110 +# define X509_R_BAD_SELECTOR 133 +# define X509_R_BAD_X509_FILETYPE 100 +# define X509_R_BASE64_DECODE_ERROR 118 +# define X509_R_CANT_CHECK_DH_KEY 114 +# define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 +# define X509_R_CRL_ALREADY_DELTA 127 +# define X509_R_CRL_VERIFY_FAILURE 131 +# define X509_R_IDP_MISMATCH 128 +# define X509_R_INVALID_DIRECTORY 113 +# define X509_R_INVALID_FIELD_NAME 119 +# define X509_R_INVALID_TRUST 123 +# define X509_R_ISSUER_MISMATCH 129 +# define X509_R_KEY_TYPE_MISMATCH 115 +# define X509_R_KEY_VALUES_MISMATCH 116 +# define X509_R_LOADING_CERT_DIR 103 +# define X509_R_LOADING_DEFAULTS 104 +# define X509_R_METHOD_NOT_SUPPORTED 124 +# define X509_R_NAME_TOO_LONG 134 +# define X509_R_NEWER_CRL_NOT_NEWER 132 +# define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 +# define X509_R_NO_CRL_NUMBER 130 +# define X509_R_PUBLIC_KEY_DECODE_ERROR 125 +# define X509_R_PUBLIC_KEY_ENCODE_ERROR 126 +# define X509_R_SHOULD_RETRY 106 +# define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 +# define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 +# define X509_R_UNKNOWN_KEY_TYPE 117 +# define X509_R_UNKNOWN_NID 109 +# define X509_R_UNKNOWN_PURPOSE_ID 121 +# define X509_R_UNKNOWN_TRUST_ID 120 +# define X509_R_UNSUPPORTED_ALGORITHM 111 +# define X509_R_WRONG_LOOKUP_TYPE 112 +# define X509_R_WRONG_TYPE 122 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/openssl/x509_vfy.h b/android/x86/include/openssl/x509_vfy.h new file mode 100644 index 00000000..cab8005e --- /dev/null +++ b/android/x86/include/openssl/x509_vfy.h @@ -0,0 +1,539 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_X509_VFY_H +# define HEADER_X509_VFY_H + +/* + * Protect against recursion, x509.h and x509_vfy.h each include the other. + */ +# ifndef HEADER_X509_H +# include <openssl/x509.h> +# endif + +# include <openssl/opensslconf.h> +# include <openssl/lhash.h> +# include <openssl/bio.h> +# include <openssl/crypto.h> +# include <openssl/symhacks.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/*- +SSL_CTX -> X509_STORE + -> X509_LOOKUP + ->X509_LOOKUP_METHOD + -> X509_LOOKUP + ->X509_LOOKUP_METHOD + +SSL -> X509_STORE_CTX + ->X509_STORE + +The X509_STORE holds the tables etc for verification stuff. +A X509_STORE_CTX is used while validating a single certificate. +The X509_STORE has X509_LOOKUPs for looking up certs. +The X509_STORE then calls a function to actually verify the +certificate chain. +*/ + +typedef enum { + X509_LU_NONE = 0, + X509_LU_X509, X509_LU_CRL +} X509_LOOKUP_TYPE; + +#if OPENSSL_API_COMPAT < 0x10100000L +#define X509_LU_RETRY -1 +#define X509_LU_FAIL 0 +#endif + +DEFINE_STACK_OF(X509_LOOKUP) +DEFINE_STACK_OF(X509_OBJECT) +DEFINE_STACK_OF(X509_VERIFY_PARAM) + +int X509_STORE_set_depth(X509_STORE *store, int depth); + +typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *); +typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *); +typedef int (*X509_STORE_CTX_get_issuer_fn)(X509 **issuer, + X509_STORE_CTX *ctx, X509 *x); +typedef int (*X509_STORE_CTX_check_issued_fn)(X509_STORE_CTX *ctx, + X509 *x, X509 *issuer); +typedef int (*X509_STORE_CTX_check_revocation_fn)(X509_STORE_CTX *ctx); +typedef int (*X509_STORE_CTX_get_crl_fn)(X509_STORE_CTX *ctx, + X509_CRL **crl, X509 *x); +typedef int (*X509_STORE_CTX_check_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl); +typedef int (*X509_STORE_CTX_cert_crl_fn)(X509_STORE_CTX *ctx, + X509_CRL *crl, X509 *x); +typedef int (*X509_STORE_CTX_check_policy_fn)(X509_STORE_CTX *ctx); +typedef STACK_OF(X509) *(*X509_STORE_CTX_lookup_certs_fn)(X509_STORE_CTX *ctx, + X509_NAME *nm); +typedef STACK_OF(X509_CRL) *(*X509_STORE_CTX_lookup_crls_fn)(X509_STORE_CTX *ctx, + X509_NAME *nm); +typedef int (*X509_STORE_CTX_cleanup_fn)(X509_STORE_CTX *ctx); + + +void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); + +# define X509_STORE_CTX_set_app_data(ctx,data) \ + X509_STORE_CTX_set_ex_data(ctx,0,data) +# define X509_STORE_CTX_get_app_data(ctx) \ + X509_STORE_CTX_get_ex_data(ctx,0) + +# define X509_L_FILE_LOAD 1 +# define X509_L_ADD_DIR 2 + +# define X509_LOOKUP_load_file(x,name,type) \ + X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) + +# define X509_LOOKUP_add_dir(x,name,type) \ + X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) + +# define X509_V_OK 0 +# define X509_V_ERR_UNSPECIFIED 1 +# define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 +# define X509_V_ERR_UNABLE_TO_GET_CRL 3 +# define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 +# define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 +# define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 +# define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 +# define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 +# define X509_V_ERR_CERT_NOT_YET_VALID 9 +# define X509_V_ERR_CERT_HAS_EXPIRED 10 +# define X509_V_ERR_CRL_NOT_YET_VALID 11 +# define X509_V_ERR_CRL_HAS_EXPIRED 12 +# define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 +# define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 +# define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 +# define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 +# define X509_V_ERR_OUT_OF_MEM 17 +# define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 +# define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 +# define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 +# define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 +# define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 +# define X509_V_ERR_CERT_REVOKED 23 +# define X509_V_ERR_INVALID_CA 24 +# define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 +# define X509_V_ERR_INVALID_PURPOSE 26 +# define X509_V_ERR_CERT_UNTRUSTED 27 +# define X509_V_ERR_CERT_REJECTED 28 +/* These are 'informational' when looking for issuer cert */ +# define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 +# define X509_V_ERR_AKID_SKID_MISMATCH 30 +# define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 +# define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 +# define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 +# define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 +# define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 +# define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 +# define X509_V_ERR_INVALID_NON_CA 37 +# define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 +# define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 +# define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 +# define X509_V_ERR_INVALID_EXTENSION 41 +# define X509_V_ERR_INVALID_POLICY_EXTENSION 42 +# define X509_V_ERR_NO_EXPLICIT_POLICY 43 +# define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 +# define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 +# define X509_V_ERR_UNNESTED_RESOURCE 46 +# define X509_V_ERR_PERMITTED_VIOLATION 47 +# define X509_V_ERR_EXCLUDED_VIOLATION 48 +# define X509_V_ERR_SUBTREE_MINMAX 49 +/* The application is not happy */ +# define X509_V_ERR_APPLICATION_VERIFICATION 50 +# define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 +# define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 +# define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 +# define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 +/* Another issuer check debug option */ +# define X509_V_ERR_PATH_LOOP 55 +/* Suite B mode algorithm violation */ +# define X509_V_ERR_SUITE_B_INVALID_VERSION 56 +# define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57 +# define X509_V_ERR_SUITE_B_INVALID_CURVE 58 +# define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59 +# define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60 +# define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61 +/* Host, email and IP check errors */ +# define X509_V_ERR_HOSTNAME_MISMATCH 62 +# define X509_V_ERR_EMAIL_MISMATCH 63 +# define X509_V_ERR_IP_ADDRESS_MISMATCH 64 +/* DANE TLSA errors */ +# define X509_V_ERR_DANE_NO_MATCH 65 +/* security level errors */ +# define X509_V_ERR_EE_KEY_TOO_SMALL 66 +# define X509_V_ERR_CA_KEY_TOO_SMALL 67 +# define X509_V_ERR_CA_MD_TOO_WEAK 68 +/* Caller error */ +# define X509_V_ERR_INVALID_CALL 69 +/* Issuer lookup error */ +# define X509_V_ERR_STORE_LOOKUP 70 +/* Certificate transparency */ +# define X509_V_ERR_NO_VALID_SCTS 71 + +# define X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION 72 + +/* Certificate verify flags */ + +# if OPENSSL_API_COMPAT < 0x10100000L +# define X509_V_FLAG_CB_ISSUER_CHECK 0x0 /* Deprecated */ +# endif +/* Use check time instead of current time */ +# define X509_V_FLAG_USE_CHECK_TIME 0x2 +/* Lookup CRLs */ +# define X509_V_FLAG_CRL_CHECK 0x4 +/* Lookup CRLs for whole chain */ +# define X509_V_FLAG_CRL_CHECK_ALL 0x8 +/* Ignore unhandled critical extensions */ +# define X509_V_FLAG_IGNORE_CRITICAL 0x10 +/* Disable workarounds for broken certificates */ +# define X509_V_FLAG_X509_STRICT 0x20 +/* Enable proxy certificate validation */ +# define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 +/* Enable policy checking */ +# define X509_V_FLAG_POLICY_CHECK 0x80 +/* Policy variable require-explicit-policy */ +# define X509_V_FLAG_EXPLICIT_POLICY 0x100 +/* Policy variable inhibit-any-policy */ +# define X509_V_FLAG_INHIBIT_ANY 0x200 +/* Policy variable inhibit-policy-mapping */ +# define X509_V_FLAG_INHIBIT_MAP 0x400 +/* Notify callback that policy is OK */ +# define X509_V_FLAG_NOTIFY_POLICY 0x800 +/* Extended CRL features such as indirect CRLs, alternate CRL signing keys */ +# define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 +/* Delta CRL support */ +# define X509_V_FLAG_USE_DELTAS 0x2000 +/* Check self-signed CA signature */ +# define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 +/* Use trusted store first */ +# define X509_V_FLAG_TRUSTED_FIRST 0x8000 +/* Suite B 128 bit only mode: not normally used */ +# define X509_V_FLAG_SUITEB_128_LOS_ONLY 0x10000 +/* Suite B 192 bit only mode */ +# define X509_V_FLAG_SUITEB_192_LOS 0x20000 +/* Suite B 128 bit mode allowing 192 bit algorithms */ +# define X509_V_FLAG_SUITEB_128_LOS 0x30000 +/* Allow partial chains if at least one certificate is in trusted store */ +# define X509_V_FLAG_PARTIAL_CHAIN 0x80000 +/* + * If the initial chain is not trusted, do not attempt to build an alternative + * chain. Alternate chain checking was introduced in 1.1.0. Setting this flag + * will force the behaviour to match that of previous versions. + */ +# define X509_V_FLAG_NO_ALT_CHAINS 0x100000 +/* Do not check certificate/CRL validity against current time */ +# define X509_V_FLAG_NO_CHECK_TIME 0x200000 + +# define X509_VP_FLAG_DEFAULT 0x1 +# define X509_VP_FLAG_OVERWRITE 0x2 +# define X509_VP_FLAG_RESET_FLAGS 0x4 +# define X509_VP_FLAG_LOCKED 0x8 +# define X509_VP_FLAG_ONCE 0x10 + +/* Internal use: mask of policy related options */ +# define X509_V_FLAG_POLICY_MASK (X509_V_FLAG_POLICY_CHECK \ + | X509_V_FLAG_EXPLICIT_POLICY \ + | X509_V_FLAG_INHIBIT_ANY \ + | X509_V_FLAG_INHIBIT_MAP) + +int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, X509_LOOKUP_TYPE type, + X509_NAME *name); +X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, + X509_LOOKUP_TYPE type, + X509_NAME *name); +X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, + X509_OBJECT *x); +int X509_OBJECT_up_ref_count(X509_OBJECT *a); +X509_OBJECT *X509_OBJECT_new(void); +void X509_OBJECT_free(X509_OBJECT *a); +X509_LOOKUP_TYPE X509_OBJECT_get_type(const X509_OBJECT *a); +X509 *X509_OBJECT_get0_X509(const X509_OBJECT *a); +X509_CRL *X509_OBJECT_get0_X509_CRL(X509_OBJECT *a); +X509_STORE *X509_STORE_new(void); +void X509_STORE_free(X509_STORE *v); +int X509_STORE_lock(X509_STORE *ctx); +int X509_STORE_unlock(X509_STORE *ctx); +int X509_STORE_up_ref(X509_STORE *v); +STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *v); + +STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *st, X509_NAME *nm); +STACK_OF(X509_CRL) *X509_STORE_CTX_get1_crls(X509_STORE_CTX *st, X509_NAME *nm); +int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags); +int X509_STORE_set_purpose(X509_STORE *ctx, int purpose); +int X509_STORE_set_trust(X509_STORE *ctx, int trust); +int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *pm); +X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *ctx); + +void X509_STORE_set_verify(X509_STORE *ctx, X509_STORE_CTX_verify_fn verify); +#define X509_STORE_set_verify_func(ctx, func) \ + X509_STORE_set_verify((ctx),(func)) +void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, + X509_STORE_CTX_verify_fn verify); +X509_STORE_CTX_verify_fn X509_STORE_get_verify(X509_STORE *ctx); +void X509_STORE_set_verify_cb(X509_STORE *ctx, + X509_STORE_CTX_verify_cb verify_cb); +# define X509_STORE_set_verify_cb_func(ctx,func) \ + X509_STORE_set_verify_cb((ctx),(func)) +X509_STORE_CTX_verify_cb X509_STORE_get_verify_cb(X509_STORE *ctx); +void X509_STORE_set_get_issuer(X509_STORE *ctx, + X509_STORE_CTX_get_issuer_fn get_issuer); +X509_STORE_CTX_get_issuer_fn X509_STORE_get_get_issuer(X509_STORE *ctx); +void X509_STORE_set_check_issued(X509_STORE *ctx, + X509_STORE_CTX_check_issued_fn check_issued); +X509_STORE_CTX_check_issued_fn X509_STORE_get_check_issued(X509_STORE *ctx); +void X509_STORE_set_check_revocation(X509_STORE *ctx, + X509_STORE_CTX_check_revocation_fn check_revocation); +X509_STORE_CTX_check_revocation_fn X509_STORE_get_check_revocation(X509_STORE *ctx); +void X509_STORE_set_get_crl(X509_STORE *ctx, + X509_STORE_CTX_get_crl_fn get_crl); +X509_STORE_CTX_get_crl_fn X509_STORE_get_get_crl(X509_STORE *ctx); +void X509_STORE_set_check_crl(X509_STORE *ctx, + X509_STORE_CTX_check_crl_fn check_crl); +X509_STORE_CTX_check_crl_fn X509_STORE_get_check_crl(X509_STORE *ctx); +void X509_STORE_set_cert_crl(X509_STORE *ctx, + X509_STORE_CTX_cert_crl_fn cert_crl); +X509_STORE_CTX_cert_crl_fn X509_STORE_get_cert_crl(X509_STORE *ctx); +void X509_STORE_set_check_policy(X509_STORE *ctx, + X509_STORE_CTX_check_policy_fn check_policy); +X509_STORE_CTX_check_policy_fn X509_STORE_get_check_policy(X509_STORE *ctx); +void X509_STORE_set_lookup_certs(X509_STORE *ctx, + X509_STORE_CTX_lookup_certs_fn lookup_certs); +X509_STORE_CTX_lookup_certs_fn X509_STORE_get_lookup_certs(X509_STORE *ctx); +void X509_STORE_set_lookup_crls(X509_STORE *ctx, + X509_STORE_CTX_lookup_crls_fn lookup_crls); +#define X509_STORE_set_lookup_crls_cb(ctx, func) \ + X509_STORE_set_lookup_crls((ctx), (func)) +X509_STORE_CTX_lookup_crls_fn X509_STORE_get_lookup_crls(X509_STORE *ctx); +void X509_STORE_set_cleanup(X509_STORE *ctx, + X509_STORE_CTX_cleanup_fn cleanup); +X509_STORE_CTX_cleanup_fn X509_STORE_get_cleanup(X509_STORE *ctx); + +#define X509_STORE_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE, l, p, newf, dupf, freef) +int X509_STORE_set_ex_data(X509_STORE *ctx, int idx, void *data); +void *X509_STORE_get_ex_data(X509_STORE *ctx, int idx); + +X509_STORE_CTX *X509_STORE_CTX_new(void); + +int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); + +void X509_STORE_CTX_free(X509_STORE_CTX *ctx); +int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, + X509 *x509, STACK_OF(X509) *chain); +void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk); +void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); + +X509_STORE *X509_STORE_CTX_get0_store(X509_STORE_CTX *ctx); +X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx); +STACK_OF(X509)* X509_STORE_CTX_get0_untrusted(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set0_untrusted(X509_STORE_CTX *ctx, STACK_OF(X509) *sk); +void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, + X509_STORE_CTX_verify_cb verify); +X509_STORE_CTX_verify_cb X509_STORE_CTX_get_verify_cb(X509_STORE_CTX *ctx); +X509_STORE_CTX_verify_fn X509_STORE_CTX_get_verify(X509_STORE_CTX *ctx); +X509_STORE_CTX_get_issuer_fn X509_STORE_CTX_get_get_issuer(X509_STORE_CTX *ctx); +X509_STORE_CTX_check_issued_fn X509_STORE_CTX_get_check_issued(X509_STORE_CTX *ctx); +X509_STORE_CTX_check_revocation_fn X509_STORE_CTX_get_check_revocation(X509_STORE_CTX *ctx); +X509_STORE_CTX_get_crl_fn X509_STORE_CTX_get_get_crl(X509_STORE_CTX *ctx); +X509_STORE_CTX_check_crl_fn X509_STORE_CTX_get_check_crl(X509_STORE_CTX *ctx); +X509_STORE_CTX_cert_crl_fn X509_STORE_CTX_get_cert_crl(X509_STORE_CTX *ctx); +X509_STORE_CTX_check_policy_fn X509_STORE_CTX_get_check_policy(X509_STORE_CTX *ctx); +X509_STORE_CTX_lookup_certs_fn X509_STORE_CTX_get_lookup_certs(X509_STORE_CTX *ctx); +X509_STORE_CTX_lookup_crls_fn X509_STORE_CTX_get_lookup_crls(X509_STORE_CTX *ctx); +X509_STORE_CTX_cleanup_fn X509_STORE_CTX_get_cleanup(X509_STORE_CTX *ctx); + +#if OPENSSL_API_COMPAT < 0x10100000L +# define X509_STORE_CTX_get_chain X509_STORE_CTX_get0_chain +# define X509_STORE_CTX_set_chain X509_STORE_CTX_set0_untrusted +# define X509_STORE_CTX_trusted_stack X509_STORE_CTX_set0_trusted_stack +# define X509_STORE_get_by_subject X509_STORE_CTX_get_by_subject +# define X509_STORE_get1_cert X509_STORE_CTX_get1_certs +# define X509_STORE_get1_crl X509_STORE_CTX_get1_crls +#endif + +X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); +X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); +X509_LOOKUP_METHOD *X509_LOOKUP_file(void); + +int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); +int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); + +int X509_STORE_CTX_get_by_subject(X509_STORE_CTX *vs, X509_LOOKUP_TYPE type, + X509_NAME *name, X509_OBJECT *ret); +X509_OBJECT *X509_STORE_CTX_get_obj_by_subject(X509_STORE_CTX *vs, + X509_LOOKUP_TYPE type, + X509_NAME *name); + +int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, + long argl, char **ret); + +int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type); +int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type); +int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type); + +X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); +void X509_LOOKUP_free(X509_LOOKUP *ctx); +int X509_LOOKUP_init(X509_LOOKUP *ctx); +int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, + X509_NAME *name, X509_OBJECT *ret); +int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, + X509_NAME *name, ASN1_INTEGER *serial, + X509_OBJECT *ret); +int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, + const unsigned char *bytes, int len, + X509_OBJECT *ret); +int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, + const char *str, int len, X509_OBJECT *ret); +int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); + +int X509_STORE_load_locations(X509_STORE *ctx, + const char *file, const char *dir); +int X509_STORE_set_default_paths(X509_STORE *ctx); + +#define X509_STORE_CTX_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE_CTX, l, p, newf, dupf, freef) +int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data); +void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx); +int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int s); +int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_error_depth(X509_STORE_CTX *ctx, int depth); +X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_current_cert(X509_STORE_CTX *ctx, X509 *x); +X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx); +X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx); +X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx); +STACK_OF(X509) *X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx); +STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_cert(X509_STORE_CTX *c, X509 *x); +void X509_STORE_CTX_set0_verified_chain(X509_STORE_CTX *c, STACK_OF(X509) *sk); +void X509_STORE_CTX_set0_crls(X509_STORE_CTX *c, STACK_OF(X509_CRL) *sk); +int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); +int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); +int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose, + int purpose, int trust); +void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags); +void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags, + time_t t); + +X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx); +int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx); +int X509_STORE_CTX_get_num_untrusted(X509_STORE_CTX *ctx); + +X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param); +int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name); + +/* + * Bridge opacity barrier between libcrypt and libssl, also needed to support + * offline testing in test/danetest.c + */ +void X509_STORE_CTX_set0_dane(X509_STORE_CTX *ctx, SSL_DANE *dane); +#define DANE_FLAG_NO_DANE_EE_NAMECHECKS (1L << 0) + +/* X509_VERIFY_PARAM functions */ + +X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); +void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); +int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); +int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name); +int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, + unsigned long flags); +int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, + unsigned long flags); +unsigned long X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose); +int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust); +void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth); +void X509_VERIFY_PARAM_set_auth_level(X509_VERIFY_PARAM *param, int auth_level); +void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t); +int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, + ASN1_OBJECT *policy); +int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param, + STACK_OF(ASN1_OBJECT) *policies); + +int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, + const char *name, size_t namelen); +int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, + const char *name, size_t namelen); +void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, + unsigned int flags); +char *X509_VERIFY_PARAM_get0_peername(X509_VERIFY_PARAM *); +void X509_VERIFY_PARAM_move_peername(X509_VERIFY_PARAM *, X509_VERIFY_PARAM *); +int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, + const char *email, size_t emaillen); +int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, + const unsigned char *ip, size_t iplen); +int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, + const char *ipasc); + +int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_get_auth_level(const X509_VERIFY_PARAM *param); +const char *X509_VERIFY_PARAM_get0_name(const X509_VERIFY_PARAM *param); + +int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_get_count(void); +const X509_VERIFY_PARAM *X509_VERIFY_PARAM_get0(int id); +const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name); +void X509_VERIFY_PARAM_table_cleanup(void); + +/* Non positive return values are errors */ +#define X509_PCY_TREE_FAILURE -2 /* Failure to satisfy explicit policy */ +#define X509_PCY_TREE_INVALID -1 /* Inconsistent or invalid extensions */ +#define X509_PCY_TREE_INTERNAL 0 /* Internal error, most likely malloc */ + +/* + * Positive return values form a bit mask, all but the first are internal to + * the library and don't appear in results from X509_policy_check(). + */ +#define X509_PCY_TREE_VALID 1 /* The policy tree is valid */ +#define X509_PCY_TREE_EMPTY 2 /* The policy tree is empty */ +#define X509_PCY_TREE_EXPLICIT 4 /* Explicit policy required */ + +int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, + STACK_OF(X509) *certs, + STACK_OF(ASN1_OBJECT) *policy_oids, unsigned int flags); + +void X509_policy_tree_free(X509_POLICY_TREE *tree); + +int X509_policy_tree_level_count(const X509_POLICY_TREE *tree); +X509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, + int i); + +STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(const + X509_POLICY_TREE + *tree); + +STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(const + X509_POLICY_TREE + *tree); + +int X509_policy_level_node_count(X509_POLICY_LEVEL *level); + +X509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, + int i); + +const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node); + +STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(const + X509_POLICY_NODE + *node); +const X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE + *node); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/x86/include/openssl/x509v3.h b/android/x86/include/openssl/x509v3.h new file mode 100644 index 00000000..f21ce7c1 --- /dev/null +++ b/android/x86/include/openssl/x509v3.h @@ -0,0 +1,1005 @@ +/* + * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_X509V3_H +# define HEADER_X509V3_H + +# include <openssl/bio.h> +# include <openssl/x509.h> +# include <openssl/conf.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Forward reference */ +struct v3_ext_method; +struct v3_ext_ctx; + +/* Useful typedefs */ + +typedef void *(*X509V3_EXT_NEW)(void); +typedef void (*X509V3_EXT_FREE) (void *); +typedef void *(*X509V3_EXT_D2I)(void *, const unsigned char **, long); +typedef int (*X509V3_EXT_I2D) (void *, unsigned char **); +typedef STACK_OF(CONF_VALUE) * + (*X509V3_EXT_I2V) (const struct v3_ext_method *method, void *ext, + STACK_OF(CONF_VALUE) *extlist); +typedef void *(*X509V3_EXT_V2I)(const struct v3_ext_method *method, + struct v3_ext_ctx *ctx, + STACK_OF(CONF_VALUE) *values); +typedef char *(*X509V3_EXT_I2S)(const struct v3_ext_method *method, + void *ext); +typedef void *(*X509V3_EXT_S2I)(const struct v3_ext_method *method, + struct v3_ext_ctx *ctx, const char *str); +typedef int (*X509V3_EXT_I2R) (const struct v3_ext_method *method, void *ext, + BIO *out, int indent); +typedef void *(*X509V3_EXT_R2I)(const struct v3_ext_method *method, + struct v3_ext_ctx *ctx, const char *str); + +/* V3 extension structure */ + +struct v3_ext_method { + int ext_nid; + int ext_flags; +/* If this is set the following four fields are ignored */ + ASN1_ITEM_EXP *it; +/* Old style ASN1 calls */ + X509V3_EXT_NEW ext_new; + X509V3_EXT_FREE ext_free; + X509V3_EXT_D2I d2i; + X509V3_EXT_I2D i2d; +/* The following pair is used for string extensions */ + X509V3_EXT_I2S i2s; + X509V3_EXT_S2I s2i; +/* The following pair is used for multi-valued extensions */ + X509V3_EXT_I2V i2v; + X509V3_EXT_V2I v2i; +/* The following are used for raw extensions */ + X509V3_EXT_I2R i2r; + X509V3_EXT_R2I r2i; + void *usr_data; /* Any extension specific data */ +}; + +typedef struct X509V3_CONF_METHOD_st { + char *(*get_string) (void *db, const char *section, const char *value); + STACK_OF(CONF_VALUE) *(*get_section) (void *db, const char *section); + void (*free_string) (void *db, char *string); + void (*free_section) (void *db, STACK_OF(CONF_VALUE) *section); +} X509V3_CONF_METHOD; + +/* Context specific info */ +struct v3_ext_ctx { +# define CTX_TEST 0x1 +# define X509V3_CTX_REPLACE 0x2 + int flags; + X509 *issuer_cert; + X509 *subject_cert; + X509_REQ *subject_req; + X509_CRL *crl; + X509V3_CONF_METHOD *db_meth; + void *db; +/* Maybe more here */ +}; + +typedef struct v3_ext_method X509V3_EXT_METHOD; + +DEFINE_STACK_OF(X509V3_EXT_METHOD) + +/* ext_flags values */ +# define X509V3_EXT_DYNAMIC 0x1 +# define X509V3_EXT_CTX_DEP 0x2 +# define X509V3_EXT_MULTILINE 0x4 + +typedef BIT_STRING_BITNAME ENUMERATED_NAMES; + +typedef struct BASIC_CONSTRAINTS_st { + int ca; + ASN1_INTEGER *pathlen; +} BASIC_CONSTRAINTS; + +typedef struct PKEY_USAGE_PERIOD_st { + ASN1_GENERALIZEDTIME *notBefore; + ASN1_GENERALIZEDTIME *notAfter; +} PKEY_USAGE_PERIOD; + +typedef struct otherName_st { + ASN1_OBJECT *type_id; + ASN1_TYPE *value; +} OTHERNAME; + +typedef struct EDIPartyName_st { + ASN1_STRING *nameAssigner; + ASN1_STRING *partyName; +} EDIPARTYNAME; + +typedef struct GENERAL_NAME_st { +# define GEN_OTHERNAME 0 +# define GEN_EMAIL 1 +# define GEN_DNS 2 +# define GEN_X400 3 +# define GEN_DIRNAME 4 +# define GEN_EDIPARTY 5 +# define GEN_URI 6 +# define GEN_IPADD 7 +# define GEN_RID 8 + int type; + union { + char *ptr; + OTHERNAME *otherName; /* otherName */ + ASN1_IA5STRING *rfc822Name; + ASN1_IA5STRING *dNSName; + ASN1_TYPE *x400Address; + X509_NAME *directoryName; + EDIPARTYNAME *ediPartyName; + ASN1_IA5STRING *uniformResourceIdentifier; + ASN1_OCTET_STRING *iPAddress; + ASN1_OBJECT *registeredID; + /* Old names */ + ASN1_OCTET_STRING *ip; /* iPAddress */ + X509_NAME *dirn; /* dirn */ + ASN1_IA5STRING *ia5; /* rfc822Name, dNSName, + * uniformResourceIdentifier */ + ASN1_OBJECT *rid; /* registeredID */ + ASN1_TYPE *other; /* x400Address */ + } d; +} GENERAL_NAME; + +typedef struct ACCESS_DESCRIPTION_st { + ASN1_OBJECT *method; + GENERAL_NAME *location; +} ACCESS_DESCRIPTION; + +typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS; + +typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE; + +typedef STACK_OF(ASN1_INTEGER) TLS_FEATURE; + +DEFINE_STACK_OF(GENERAL_NAME) +typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES; +DEFINE_STACK_OF(GENERAL_NAMES) + +DEFINE_STACK_OF(ACCESS_DESCRIPTION) + +typedef struct DIST_POINT_NAME_st { + int type; + union { + GENERAL_NAMES *fullname; + STACK_OF(X509_NAME_ENTRY) *relativename; + } name; +/* If relativename then this contains the full distribution point name */ + X509_NAME *dpname; +} DIST_POINT_NAME; +/* All existing reasons */ +# define CRLDP_ALL_REASONS 0x807f + +# define CRL_REASON_NONE -1 +# define CRL_REASON_UNSPECIFIED 0 +# define CRL_REASON_KEY_COMPROMISE 1 +# define CRL_REASON_CA_COMPROMISE 2 +# define CRL_REASON_AFFILIATION_CHANGED 3 +# define CRL_REASON_SUPERSEDED 4 +# define CRL_REASON_CESSATION_OF_OPERATION 5 +# define CRL_REASON_CERTIFICATE_HOLD 6 +# define CRL_REASON_REMOVE_FROM_CRL 8 +# define CRL_REASON_PRIVILEGE_WITHDRAWN 9 +# define CRL_REASON_AA_COMPROMISE 10 + +struct DIST_POINT_st { + DIST_POINT_NAME *distpoint; + ASN1_BIT_STRING *reasons; + GENERAL_NAMES *CRLissuer; + int dp_reasons; +}; + +typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; + +DEFINE_STACK_OF(DIST_POINT) + +struct AUTHORITY_KEYID_st { + ASN1_OCTET_STRING *keyid; + GENERAL_NAMES *issuer; + ASN1_INTEGER *serial; +}; + +/* Strong extranet structures */ + +typedef struct SXNET_ID_st { + ASN1_INTEGER *zone; + ASN1_OCTET_STRING *user; +} SXNETID; + +DEFINE_STACK_OF(SXNETID) + +typedef struct SXNET_st { + ASN1_INTEGER *version; + STACK_OF(SXNETID) *ids; +} SXNET; + +typedef struct NOTICEREF_st { + ASN1_STRING *organization; + STACK_OF(ASN1_INTEGER) *noticenos; +} NOTICEREF; + +typedef struct USERNOTICE_st { + NOTICEREF *noticeref; + ASN1_STRING *exptext; +} USERNOTICE; + +typedef struct POLICYQUALINFO_st { + ASN1_OBJECT *pqualid; + union { + ASN1_IA5STRING *cpsuri; + USERNOTICE *usernotice; + ASN1_TYPE *other; + } d; +} POLICYQUALINFO; + +DEFINE_STACK_OF(POLICYQUALINFO) + +typedef struct POLICYINFO_st { + ASN1_OBJECT *policyid; + STACK_OF(POLICYQUALINFO) *qualifiers; +} POLICYINFO; + +typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; + +DEFINE_STACK_OF(POLICYINFO) + +typedef struct POLICY_MAPPING_st { + ASN1_OBJECT *issuerDomainPolicy; + ASN1_OBJECT *subjectDomainPolicy; +} POLICY_MAPPING; + +DEFINE_STACK_OF(POLICY_MAPPING) + +typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS; + +typedef struct GENERAL_SUBTREE_st { + GENERAL_NAME *base; + ASN1_INTEGER *minimum; + ASN1_INTEGER *maximum; +} GENERAL_SUBTREE; + +DEFINE_STACK_OF(GENERAL_SUBTREE) + +struct NAME_CONSTRAINTS_st { + STACK_OF(GENERAL_SUBTREE) *permittedSubtrees; + STACK_OF(GENERAL_SUBTREE) *excludedSubtrees; +}; + +typedef struct POLICY_CONSTRAINTS_st { + ASN1_INTEGER *requireExplicitPolicy; + ASN1_INTEGER *inhibitPolicyMapping; +} POLICY_CONSTRAINTS; + +/* Proxy certificate structures, see RFC 3820 */ +typedef struct PROXY_POLICY_st { + ASN1_OBJECT *policyLanguage; + ASN1_OCTET_STRING *policy; +} PROXY_POLICY; + +typedef struct PROXY_CERT_INFO_EXTENSION_st { + ASN1_INTEGER *pcPathLengthConstraint; + PROXY_POLICY *proxyPolicy; +} PROXY_CERT_INFO_EXTENSION; + +DECLARE_ASN1_FUNCTIONS(PROXY_POLICY) +DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION) + +struct ISSUING_DIST_POINT_st { + DIST_POINT_NAME *distpoint; + int onlyuser; + int onlyCA; + ASN1_BIT_STRING *onlysomereasons; + int indirectCRL; + int onlyattr; +}; + +/* Values in idp_flags field */ +/* IDP present */ +# define IDP_PRESENT 0x1 +/* IDP values inconsistent */ +# define IDP_INVALID 0x2 +/* onlyuser true */ +# define IDP_ONLYUSER 0x4 +/* onlyCA true */ +# define IDP_ONLYCA 0x8 +/* onlyattr true */ +# define IDP_ONLYATTR 0x10 +/* indirectCRL true */ +# define IDP_INDIRECT 0x20 +/* onlysomereasons present */ +# define IDP_REASONS 0x40 + +# define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \ +",name:", val->name, ",value:", val->value); + +# define X509V3_set_ctx_test(ctx) \ + X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST) +# define X509V3_set_ctx_nodb(ctx) (ctx)->db = NULL; + +# define EXT_BITSTRING(nid, table) { nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), \ + 0,0,0,0, \ + 0,0, \ + (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \ + (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \ + NULL, NULL, \ + table} + +# define EXT_IA5STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), \ + 0,0,0,0, \ + (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \ + (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \ + 0,0,0,0, \ + NULL} + +# define EXT_END { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + +/* X509_PURPOSE stuff */ + +# define EXFLAG_BCONS 0x1 +# define EXFLAG_KUSAGE 0x2 +# define EXFLAG_XKUSAGE 0x4 +# define EXFLAG_NSCERT 0x8 + +# define EXFLAG_CA 0x10 +/* Really self issued not necessarily self signed */ +# define EXFLAG_SI 0x20 +# define EXFLAG_V1 0x40 +# define EXFLAG_INVALID 0x80 +# define EXFLAG_SET 0x100 +# define EXFLAG_CRITICAL 0x200 +# define EXFLAG_PROXY 0x400 + +# define EXFLAG_INVALID_POLICY 0x800 +# define EXFLAG_FRESHEST 0x1000 +/* Self signed */ +# define EXFLAG_SS 0x2000 + +# define KU_DIGITAL_SIGNATURE 0x0080 +# define KU_NON_REPUDIATION 0x0040 +# define KU_KEY_ENCIPHERMENT 0x0020 +# define KU_DATA_ENCIPHERMENT 0x0010 +# define KU_KEY_AGREEMENT 0x0008 +# define KU_KEY_CERT_SIGN 0x0004 +# define KU_CRL_SIGN 0x0002 +# define KU_ENCIPHER_ONLY 0x0001 +# define KU_DECIPHER_ONLY 0x8000 + +# define NS_SSL_CLIENT 0x80 +# define NS_SSL_SERVER 0x40 +# define NS_SMIME 0x20 +# define NS_OBJSIGN 0x10 +# define NS_SSL_CA 0x04 +# define NS_SMIME_CA 0x02 +# define NS_OBJSIGN_CA 0x01 +# define NS_ANY_CA (NS_SSL_CA|NS_SMIME_CA|NS_OBJSIGN_CA) + +# define XKU_SSL_SERVER 0x1 +# define XKU_SSL_CLIENT 0x2 +# define XKU_SMIME 0x4 +# define XKU_CODE_SIGN 0x8 +# define XKU_SGC 0x10 +# define XKU_OCSP_SIGN 0x20 +# define XKU_TIMESTAMP 0x40 +# define XKU_DVCS 0x80 +# define XKU_ANYEKU 0x100 + +# define X509_PURPOSE_DYNAMIC 0x1 +# define X509_PURPOSE_DYNAMIC_NAME 0x2 + +typedef struct x509_purpose_st { + int purpose; + int trust; /* Default trust ID */ + int flags; + int (*check_purpose) (const struct x509_purpose_st *, const X509 *, int); + char *name; + char *sname; + void *usr_data; +} X509_PURPOSE; + +# define X509_PURPOSE_SSL_CLIENT 1 +# define X509_PURPOSE_SSL_SERVER 2 +# define X509_PURPOSE_NS_SSL_SERVER 3 +# define X509_PURPOSE_SMIME_SIGN 4 +# define X509_PURPOSE_SMIME_ENCRYPT 5 +# define X509_PURPOSE_CRL_SIGN 6 +# define X509_PURPOSE_ANY 7 +# define X509_PURPOSE_OCSP_HELPER 8 +# define X509_PURPOSE_TIMESTAMP_SIGN 9 + +# define X509_PURPOSE_MIN 1 +# define X509_PURPOSE_MAX 9 + +/* Flags for X509V3_EXT_print() */ + +# define X509V3_EXT_UNKNOWN_MASK (0xfL << 16) +/* Return error for unknown extensions */ +# define X509V3_EXT_DEFAULT 0 +/* Print error for unknown extensions */ +# define X509V3_EXT_ERROR_UNKNOWN (1L << 16) +/* ASN1 parse unknown extensions */ +# define X509V3_EXT_PARSE_UNKNOWN (2L << 16) +/* BIO_dump unknown extensions */ +# define X509V3_EXT_DUMP_UNKNOWN (3L << 16) + +/* Flags for X509V3_add1_i2d */ + +# define X509V3_ADD_OP_MASK 0xfL +# define X509V3_ADD_DEFAULT 0L +# define X509V3_ADD_APPEND 1L +# define X509V3_ADD_REPLACE 2L +# define X509V3_ADD_REPLACE_EXISTING 3L +# define X509V3_ADD_KEEP_EXISTING 4L +# define X509V3_ADD_DELETE 5L +# define X509V3_ADD_SILENT 0x10 + +DEFINE_STACK_OF(X509_PURPOSE) + +DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) + +DECLARE_ASN1_FUNCTIONS(SXNET) +DECLARE_ASN1_FUNCTIONS(SXNETID) + +int SXNET_add_id_asc(SXNET **psx, const char *zone, const char *user, int userlen); +int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, const char *user, + int userlen); +int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, const char *user, + int userlen); + +ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, const char *zone); +ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone); +ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone); + +DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID) + +DECLARE_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD) + +DECLARE_ASN1_FUNCTIONS(GENERAL_NAME) +GENERAL_NAME *GENERAL_NAME_dup(GENERAL_NAME *a); +int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b); + +ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, + STACK_OF(CONF_VALUE) *nval); +STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + ASN1_BIT_STRING *bits, + STACK_OF(CONF_VALUE) *extlist); +char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5); +ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, const char *str); + +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, + GENERAL_NAME *gen, + STACK_OF(CONF_VALUE) *ret); +int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen); + +DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES) + +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, + GENERAL_NAMES *gen, + STACK_OF(CONF_VALUE) *extlist); +GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); + +DECLARE_ASN1_FUNCTIONS(OTHERNAME) +DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME) +int OTHERNAME_cmp(OTHERNAME *a, OTHERNAME *b); +void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value); +void *GENERAL_NAME_get0_value(GENERAL_NAME *a, int *ptype); +int GENERAL_NAME_set0_othername(GENERAL_NAME *gen, + ASN1_OBJECT *oid, ASN1_TYPE *value); +int GENERAL_NAME_get0_otherName(GENERAL_NAME *gen, + ASN1_OBJECT **poid, ASN1_TYPE **pvalue); + +char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, + const ASN1_OCTET_STRING *ia5); +ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, const char *str); + +DECLARE_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE) +int i2a_ACCESS_DESCRIPTION(BIO *bp, const ACCESS_DESCRIPTION *a); + +DECLARE_ASN1_ALLOC_FUNCTIONS(TLS_FEATURE) + +DECLARE_ASN1_FUNCTIONS(CERTIFICATEPOLICIES) +DECLARE_ASN1_FUNCTIONS(POLICYINFO) +DECLARE_ASN1_FUNCTIONS(POLICYQUALINFO) +DECLARE_ASN1_FUNCTIONS(USERNOTICE) +DECLARE_ASN1_FUNCTIONS(NOTICEREF) + +DECLARE_ASN1_FUNCTIONS(CRL_DIST_POINTS) +DECLARE_ASN1_FUNCTIONS(DIST_POINT) +DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME) +DECLARE_ASN1_FUNCTIONS(ISSUING_DIST_POINT) + +int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname); + +int NAME_CONSTRAINTS_check(X509 *x, NAME_CONSTRAINTS *nc); +int NAME_CONSTRAINTS_check_CN(X509 *x, NAME_CONSTRAINTS *nc); + +DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION) +DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS) + +DECLARE_ASN1_ITEM(POLICY_MAPPING) +DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING) +DECLARE_ASN1_ITEM(POLICY_MAPPINGS) + +DECLARE_ASN1_ITEM(GENERAL_SUBTREE) +DECLARE_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE) + +DECLARE_ASN1_ITEM(NAME_CONSTRAINTS) +DECLARE_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS) + +DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS) +DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS) + +GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out, + const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, int gen_type, + const char *value, int is_nc); + +# ifdef HEADER_CONF_H +GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, CONF_VALUE *cnf); +GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, + const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, CONF_VALUE *cnf, + int is_nc); +void X509V3_conf_free(CONF_VALUE *val); + +X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, + const char *value); +X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, const char *name, + const char *value); +int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, const char *section, + STACK_OF(X509_EXTENSION) **sk); +int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, + X509 *cert); +int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, + X509_REQ *req); +int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, + X509_CRL *crl); + +X509_EXTENSION *X509V3_EXT_conf_nid(LHASH_OF(CONF_VALUE) *conf, + X509V3_CTX *ctx, int ext_nid, + const char *value); +X509_EXTENSION *X509V3_EXT_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, + const char *name, const char *value); +int X509V3_EXT_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, + const char *section, X509 *cert); +int X509V3_EXT_REQ_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, + const char *section, X509_REQ *req); +int X509V3_EXT_CRL_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, + const char *section, X509_CRL *crl); + +int X509V3_add_value_bool_nf(const char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_get_value_bool(const CONF_VALUE *value, int *asn1_bool); +int X509V3_get_value_int(const CONF_VALUE *value, ASN1_INTEGER **aint); +void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf); +void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH_OF(CONF_VALUE) *lhash); +# endif + +char *X509V3_get_string(X509V3_CTX *ctx, const char *name, const char *section); +STACK_OF(CONF_VALUE) *X509V3_get_section(X509V3_CTX *ctx, const char *section); +void X509V3_string_free(X509V3_CTX *ctx, char *str); +void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section); +void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject, + X509_REQ *req, X509_CRL *crl, int flags); + +int X509V3_add_value(const char *name, const char *value, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_uchar(const char *name, const unsigned char *value, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_bool(const char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_int(const char *name, const ASN1_INTEGER *aint, + STACK_OF(CONF_VALUE) **extlist); +char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, const ASN1_INTEGER *aint); +ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, const char *value); +char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, const ASN1_ENUMERATED *aint); +char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, + const ASN1_ENUMERATED *aint); +int X509V3_EXT_add(X509V3_EXT_METHOD *ext); +int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist); +int X509V3_EXT_add_alias(int nid_to, int nid_from); +void X509V3_EXT_cleanup(void); + +const X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext); +const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid); +int X509V3_add_standard_extensions(void); +STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line); +void *X509V3_EXT_d2i(X509_EXTENSION *ext); +void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit, + int *idx); + +X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); +int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, + int crit, unsigned long flags); + +#if OPENSSL_API_COMPAT < 0x10100000L +/* The new declarations are in crypto.h, but the old ones were here. */ +# define hex_to_string OPENSSL_buf2hexstr +# define string_to_hex OPENSSL_hexstr2buf +#endif + +void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, + int ml); +int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, + int indent); +#ifndef OPENSSL_NO_STDIO +int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); +#endif +int X509V3_extensions_print(BIO *out, const char *title, + const STACK_OF(X509_EXTENSION) *exts, + unsigned long flag, int indent); + +int X509_check_ca(X509 *x); +int X509_check_purpose(X509 *x, int id, int ca); +int X509_supported_extension(X509_EXTENSION *ex); +int X509_PURPOSE_set(int *p, int purpose); +int X509_check_issued(X509 *issuer, X509 *subject); +int X509_check_akid(X509 *issuer, AUTHORITY_KEYID *akid); +void X509_set_proxy_flag(X509 *x); +void X509_set_proxy_pathlen(X509 *x, long l); +long X509_get_proxy_pathlen(X509 *x); + +uint32_t X509_get_extension_flags(X509 *x); +uint32_t X509_get_key_usage(X509 *x); +uint32_t X509_get_extended_key_usage(X509 *x); +const ASN1_OCTET_STRING *X509_get0_subject_key_id(X509 *x); + +int X509_PURPOSE_get_count(void); +X509_PURPOSE *X509_PURPOSE_get0(int idx); +int X509_PURPOSE_get_by_sname(const char *sname); +int X509_PURPOSE_get_by_id(int id); +int X509_PURPOSE_add(int id, int trust, int flags, + int (*ck) (const X509_PURPOSE *, const X509 *, int), + const char *name, const char *sname, void *arg); +char *X509_PURPOSE_get0_name(const X509_PURPOSE *xp); +char *X509_PURPOSE_get0_sname(const X509_PURPOSE *xp); +int X509_PURPOSE_get_trust(const X509_PURPOSE *xp); +void X509_PURPOSE_cleanup(void); +int X509_PURPOSE_get_id(const X509_PURPOSE *); + +STACK_OF(OPENSSL_STRING) *X509_get1_email(X509 *x); +STACK_OF(OPENSSL_STRING) *X509_REQ_get1_email(X509_REQ *x); +void X509_email_free(STACK_OF(OPENSSL_STRING) *sk); +STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x); +/* Flags for X509_check_* functions */ + +/* + * Always check subject name for host match even if subject alt names present + */ +# define X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT 0x1 +/* Disable wildcard matching for dnsName fields and common name. */ +# define X509_CHECK_FLAG_NO_WILDCARDS 0x2 +/* Wildcards must not match a partial label. */ +# define X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS 0x4 +/* Allow (non-partial) wildcards to match multiple labels. */ +# define X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS 0x8 +/* Constraint verifier subdomain patterns to match a single labels. */ +# define X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS 0x10 +/* Never check the subject CN */ +# define X509_CHECK_FLAG_NEVER_CHECK_SUBJECT 0x20 +/* + * Match reference identifiers starting with "." to any sub-domain. + * This is a non-public flag, turned on implicitly when the subject + * reference identity is a DNS name. + */ +# define _X509_CHECK_FLAG_DOT_SUBDOMAINS 0x8000 + +int X509_check_host(X509 *x, const char *chk, size_t chklen, + unsigned int flags, char **peername); +int X509_check_email(X509 *x, const char *chk, size_t chklen, + unsigned int flags); +int X509_check_ip(X509 *x, const unsigned char *chk, size_t chklen, + unsigned int flags); +int X509_check_ip_asc(X509 *x, const char *ipasc, unsigned int flags); + +ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc); +ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc); +int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk, + unsigned long chtype); + +void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent); +DEFINE_STACK_OF(X509_POLICY_NODE) + +#ifndef OPENSSL_NO_RFC3779 +typedef struct ASRange_st { + ASN1_INTEGER *min, *max; +} ASRange; + +# define ASIdOrRange_id 0 +# define ASIdOrRange_range 1 + +typedef struct ASIdOrRange_st { + int type; + union { + ASN1_INTEGER *id; + ASRange *range; + } u; +} ASIdOrRange; + +typedef STACK_OF(ASIdOrRange) ASIdOrRanges; +DEFINE_STACK_OF(ASIdOrRange) + +# define ASIdentifierChoice_inherit 0 +# define ASIdentifierChoice_asIdsOrRanges 1 + +typedef struct ASIdentifierChoice_st { + int type; + union { + ASN1_NULL *inherit; + ASIdOrRanges *asIdsOrRanges; + } u; +} ASIdentifierChoice; + +typedef struct ASIdentifiers_st { + ASIdentifierChoice *asnum, *rdi; +} ASIdentifiers; + +DECLARE_ASN1_FUNCTIONS(ASRange) +DECLARE_ASN1_FUNCTIONS(ASIdOrRange) +DECLARE_ASN1_FUNCTIONS(ASIdentifierChoice) +DECLARE_ASN1_FUNCTIONS(ASIdentifiers) + +typedef struct IPAddressRange_st { + ASN1_BIT_STRING *min, *max; +} IPAddressRange; + +# define IPAddressOrRange_addressPrefix 0 +# define IPAddressOrRange_addressRange 1 + +typedef struct IPAddressOrRange_st { + int type; + union { + ASN1_BIT_STRING *addressPrefix; + IPAddressRange *addressRange; + } u; +} IPAddressOrRange; + +typedef STACK_OF(IPAddressOrRange) IPAddressOrRanges; +DEFINE_STACK_OF(IPAddressOrRange) + +# define IPAddressChoice_inherit 0 +# define IPAddressChoice_addressesOrRanges 1 + +typedef struct IPAddressChoice_st { + int type; + union { + ASN1_NULL *inherit; + IPAddressOrRanges *addressesOrRanges; + } u; +} IPAddressChoice; + +typedef struct IPAddressFamily_st { + ASN1_OCTET_STRING *addressFamily; + IPAddressChoice *ipAddressChoice; +} IPAddressFamily; + +typedef STACK_OF(IPAddressFamily) IPAddrBlocks; +DEFINE_STACK_OF(IPAddressFamily) + +DECLARE_ASN1_FUNCTIONS(IPAddressRange) +DECLARE_ASN1_FUNCTIONS(IPAddressOrRange) +DECLARE_ASN1_FUNCTIONS(IPAddressChoice) +DECLARE_ASN1_FUNCTIONS(IPAddressFamily) + +/* + * API tag for elements of the ASIdentifer SEQUENCE. + */ +# define V3_ASID_ASNUM 0 +# define V3_ASID_RDI 1 + +/* + * AFI values, assigned by IANA. It'd be nice to make the AFI + * handling code totally generic, but there are too many little things + * that would need to be defined for other address families for it to + * be worth the trouble. + */ +# define IANA_AFI_IPV4 1 +# define IANA_AFI_IPV6 2 + +/* + * Utilities to construct and extract values from RFC3779 extensions, + * since some of the encodings (particularly for IP address prefixes + * and ranges) are a bit tedious to work with directly. + */ +int X509v3_asid_add_inherit(ASIdentifiers *asid, int which); +int X509v3_asid_add_id_or_range(ASIdentifiers *asid, int which, + ASN1_INTEGER *min, ASN1_INTEGER *max); +int X509v3_addr_add_inherit(IPAddrBlocks *addr, + const unsigned afi, const unsigned *safi); +int X509v3_addr_add_prefix(IPAddrBlocks *addr, + const unsigned afi, const unsigned *safi, + unsigned char *a, const int prefixlen); +int X509v3_addr_add_range(IPAddrBlocks *addr, + const unsigned afi, const unsigned *safi, + unsigned char *min, unsigned char *max); +unsigned X509v3_addr_get_afi(const IPAddressFamily *f); +int X509v3_addr_get_range(IPAddressOrRange *aor, const unsigned afi, + unsigned char *min, unsigned char *max, + const int length); + +/* + * Canonical forms. + */ +int X509v3_asid_is_canonical(ASIdentifiers *asid); +int X509v3_addr_is_canonical(IPAddrBlocks *addr); +int X509v3_asid_canonize(ASIdentifiers *asid); +int X509v3_addr_canonize(IPAddrBlocks *addr); + +/* + * Tests for inheritance and containment. + */ +int X509v3_asid_inherits(ASIdentifiers *asid); +int X509v3_addr_inherits(IPAddrBlocks *addr); +int X509v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b); +int X509v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b); + +/* + * Check whether RFC 3779 extensions nest properly in chains. + */ +int X509v3_asid_validate_path(X509_STORE_CTX *); +int X509v3_addr_validate_path(X509_STORE_CTX *); +int X509v3_asid_validate_resource_set(STACK_OF(X509) *chain, + ASIdentifiers *ext, + int allow_inheritance); +int X509v3_addr_validate_resource_set(STACK_OF(X509) *chain, + IPAddrBlocks *ext, int allow_inheritance); + +#endif /* OPENSSL_NO_RFC3779 */ + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +int ERR_load_X509V3_strings(void); + +/* Error codes for the X509V3 functions. */ + +/* Function codes. */ +# define X509V3_F_A2I_GENERAL_NAME 164 +# define X509V3_F_ADDR_VALIDATE_PATH_INTERNAL 166 +# define X509V3_F_ASIDENTIFIERCHOICE_CANONIZE 161 +# define X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL 162 +# define X509V3_F_COPY_EMAIL 122 +# define X509V3_F_COPY_ISSUER 123 +# define X509V3_F_DO_DIRNAME 144 +# define X509V3_F_DO_EXT_I2D 135 +# define X509V3_F_DO_EXT_NCONF 151 +# define X509V3_F_GNAMES_FROM_SECTNAME 156 +# define X509V3_F_I2S_ASN1_ENUMERATED 121 +# define X509V3_F_I2S_ASN1_IA5STRING 149 +# define X509V3_F_I2S_ASN1_INTEGER 120 +# define X509V3_F_I2V_AUTHORITY_INFO_ACCESS 138 +# define X509V3_F_NOTICE_SECTION 132 +# define X509V3_F_NREF_NOS 133 +# define X509V3_F_POLICY_SECTION 131 +# define X509V3_F_PROCESS_PCI_VALUE 150 +# define X509V3_F_R2I_CERTPOL 130 +# define X509V3_F_R2I_PCI 155 +# define X509V3_F_S2I_ASN1_IA5STRING 100 +# define X509V3_F_S2I_ASN1_INTEGER 108 +# define X509V3_F_S2I_ASN1_OCTET_STRING 112 +# define X509V3_F_S2I_SKEY_ID 115 +# define X509V3_F_SET_DIST_POINT_NAME 158 +# define X509V3_F_SXNET_ADD_ID_ASC 125 +# define X509V3_F_SXNET_ADD_ID_INTEGER 126 +# define X509V3_F_SXNET_ADD_ID_ULONG 127 +# define X509V3_F_SXNET_GET_ID_ASC 128 +# define X509V3_F_SXNET_GET_ID_ULONG 129 +# define X509V3_F_V2I_ASIDENTIFIERS 163 +# define X509V3_F_V2I_ASN1_BIT_STRING 101 +# define X509V3_F_V2I_AUTHORITY_INFO_ACCESS 139 +# define X509V3_F_V2I_AUTHORITY_KEYID 119 +# define X509V3_F_V2I_BASIC_CONSTRAINTS 102 +# define X509V3_F_V2I_CRLD 134 +# define X509V3_F_V2I_EXTENDED_KEY_USAGE 103 +# define X509V3_F_V2I_GENERAL_NAMES 118 +# define X509V3_F_V2I_GENERAL_NAME_EX 117 +# define X509V3_F_V2I_IDP 157 +# define X509V3_F_V2I_IPADDRBLOCKS 159 +# define X509V3_F_V2I_ISSUER_ALT 153 +# define X509V3_F_V2I_NAME_CONSTRAINTS 147 +# define X509V3_F_V2I_POLICY_CONSTRAINTS 146 +# define X509V3_F_V2I_POLICY_MAPPINGS 145 +# define X509V3_F_V2I_SUBJECT_ALT 154 +# define X509V3_F_V2I_TLS_FEATURE 165 +# define X509V3_F_V3_GENERIC_EXTENSION 116 +# define X509V3_F_X509V3_ADD1_I2D 140 +# define X509V3_F_X509V3_ADD_VALUE 105 +# define X509V3_F_X509V3_EXT_ADD 104 +# define X509V3_F_X509V3_EXT_ADD_ALIAS 106 +# define X509V3_F_X509V3_EXT_I2D 136 +# define X509V3_F_X509V3_EXT_NCONF 152 +# define X509V3_F_X509V3_GET_SECTION 142 +# define X509V3_F_X509V3_GET_STRING 143 +# define X509V3_F_X509V3_GET_VALUE_BOOL 110 +# define X509V3_F_X509V3_PARSE_LIST 109 +# define X509V3_F_X509_PURPOSE_ADD 137 +# define X509V3_F_X509_PURPOSE_SET 141 + +/* Reason codes. */ +# define X509V3_R_BAD_IP_ADDRESS 118 +# define X509V3_R_BAD_OBJECT 119 +# define X509V3_R_BN_DEC2BN_ERROR 100 +# define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101 +# define X509V3_R_DIRNAME_ERROR 149 +# define X509V3_R_DISTPOINT_ALREADY_SET 160 +# define X509V3_R_DUPLICATE_ZONE_ID 133 +# define X509V3_R_ERROR_CONVERTING_ZONE 131 +# define X509V3_R_ERROR_CREATING_EXTENSION 144 +# define X509V3_R_ERROR_IN_EXTENSION 128 +# define X509V3_R_EXPECTED_A_SECTION_NAME 137 +# define X509V3_R_EXTENSION_EXISTS 145 +# define X509V3_R_EXTENSION_NAME_ERROR 115 +# define X509V3_R_EXTENSION_NOT_FOUND 102 +# define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103 +# define X509V3_R_EXTENSION_VALUE_ERROR 116 +# define X509V3_R_ILLEGAL_EMPTY_EXTENSION 151 +# define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG 152 +# define X509V3_R_INVALID_ASNUMBER 162 +# define X509V3_R_INVALID_ASRANGE 163 +# define X509V3_R_INVALID_BOOLEAN_STRING 104 +# define X509V3_R_INVALID_EXTENSION_STRING 105 +# define X509V3_R_INVALID_INHERITANCE 165 +# define X509V3_R_INVALID_IPADDRESS 166 +# define X509V3_R_INVALID_MULTIPLE_RDNS 161 +# define X509V3_R_INVALID_NAME 106 +# define X509V3_R_INVALID_NULL_ARGUMENT 107 +# define X509V3_R_INVALID_NULL_NAME 108 +# define X509V3_R_INVALID_NULL_VALUE 109 +# define X509V3_R_INVALID_NUMBER 140 +# define X509V3_R_INVALID_NUMBERS 141 +# define X509V3_R_INVALID_OBJECT_IDENTIFIER 110 +# define X509V3_R_INVALID_OPTION 138 +# define X509V3_R_INVALID_POLICY_IDENTIFIER 134 +# define X509V3_R_INVALID_PROXY_POLICY_SETTING 153 +# define X509V3_R_INVALID_PURPOSE 146 +# define X509V3_R_INVALID_SAFI 164 +# define X509V3_R_INVALID_SECTION 135 +# define X509V3_R_INVALID_SYNTAX 143 +# define X509V3_R_ISSUER_DECODE_ERROR 126 +# define X509V3_R_MISSING_VALUE 124 +# define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142 +# define X509V3_R_NO_CONFIG_DATABASE 136 +# define X509V3_R_NO_ISSUER_CERTIFICATE 121 +# define X509V3_R_NO_ISSUER_DETAILS 127 +# define X509V3_R_NO_POLICY_IDENTIFIER 139 +# define X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED 154 +# define X509V3_R_NO_PUBLIC_KEY 114 +# define X509V3_R_NO_SUBJECT_DETAILS 125 +# define X509V3_R_OPERATION_NOT_DEFINED 148 +# define X509V3_R_OTHERNAME_ERROR 147 +# define X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED 155 +# define X509V3_R_POLICY_PATH_LENGTH 156 +# define X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED 157 +# define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY 159 +# define X509V3_R_SECTION_NOT_FOUND 150 +# define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122 +# define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123 +# define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111 +# define X509V3_R_UNKNOWN_EXTENSION 129 +# define X509V3_R_UNKNOWN_EXTENSION_NAME 130 +# define X509V3_R_UNKNOWN_OPTION 120 +# define X509V3_R_UNSUPPORTED_OPTION 117 +# define X509V3_R_UNSUPPORTED_TYPE 167 +# define X509V3_R_USER_TOO_LONG 132 + +# ifdef __cplusplus +} +# endif +#endif diff --git a/android/x86/include/png/png.h b/android/x86/include/png/png.h new file mode 100644 index 00000000..123201d3 --- /dev/null +++ b/android/x86/include/png/png.h @@ -0,0 +1,3130 @@ + +/* png.h - header file for PNG reference library + * + * libpng version 1.6.21, January 15, 2016 + * + * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license (See LICENSE, below) + * + * Authors and maintainers: + * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat + * libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger + * libpng versions 0.97, January 1998, through 1.6.21, January 15, 2016: + * Glenn Randers-Pehrson. + * See also "Contributing Authors", below. + */ + +/* + * COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: + * + * If you modify libpng you may insert additional notices immediately following + * this sentence. + * + * This code is released under the libpng license. + * + * libpng versions 1.0.7, July 1, 2000, through 1.6.21, January 15, 2016, are + * Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are + * derived from libpng-1.0.6, and are distributed according to the same + * disclaimer and license as libpng-1.0.6 with the following individuals + * added to the list of Contributing Authors: + * + * Simon-Pierre Cadieux + * Eric S. Raymond + * Mans Rullgard + * Cosmin Truta + * Gilles Vollant + * James Yu + * + * and with the following additions to the disclaimer: + * + * There is no warranty against interference with your enjoyment of the + * library or against infringement. There is no warranty that our + * efforts or the library will fulfill any of your particular purposes + * or needs. This library is provided with all faults, and the entire + * risk of satisfactory quality, performance, accuracy, and effort is with + * the user. + * + * libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are + * Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from + * libpng-0.96, and are distributed according to the same disclaimer and + * license as libpng-0.96, with the following individuals added to the list + * of Contributing Authors: + * + * Tom Lane + * Glenn Randers-Pehrson + * Willem van Schaik + * + * libpng versions 0.89, June 1996, through 0.96, May 1997, are + * Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88, + * and are distributed according to the same disclaimer and license as + * libpng-0.88, with the following individuals added to the list of + * Contributing Authors: + * + * John Bowler + * Kevin Bracey + * Sam Bushell + * Magnus Holmgren + * Greg Roelofs + * Tom Tanner + * + * libpng versions 0.5, May 1995, through 0.88, January 1996, are + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. + * + * For the purposes of this copyright and license, "Contributing Authors" + * is defined as the following set of individuals: + * + * Andreas Dilger + * Dave Martindale + * Guy Eric Schalnat + * Paul Schmidt + * Tim Wegner + * + * The PNG Reference Library is supplied "AS IS". The Contributing Authors + * and Group 42, Inc. disclaim all warranties, expressed or implied, + * including, without limitation, the warranties of merchantability and of + * fitness for any purpose. The Contributing Authors and Group 42, Inc. + * assume no liability for direct, indirect, incidental, special, exemplary, + * or consequential damages, which may result from the use of the PNG + * Reference Library, even if advised of the possibility of such damage. + * + * Permission is hereby granted to use, copy, modify, and distribute this + * source code, or portions hereof, for any purpose, without fee, subject + * to the following restrictions: + * + * 1. The origin of this source code must not be misrepresented. + * + * 2. Altered versions must be plainly marked as such and must not + * be misrepresented as being the original source. + * + * 3. This Copyright notice may not be removed or altered from any + * source or altered source distribution. + * + * The Contributing Authors and Group 42, Inc. specifically permit, without + * fee, and encourage the use of this source code as a component to + * supporting the PNG file format in commercial products. If you use this + * source code in a product, acknowledgment is not required but would be + * appreciated. + * + * END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE. + */ + +/* + * A "png_get_copyright" function is available, for convenient use in "about" + * boxes and the like: + * + * printf("%s", png_get_copyright(NULL)); + * + * Also, the PNG logo (in PNG format, of course) is supplied in the + * files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). + */ + +/* + * Libpng is OSI Certified Open Source Software. OSI Certified Open Source is + * a certification mark of the Open Source Initiative. OSI has not addressed + * the additional disclaimers inserted at version 1.0.7. + */ + +/* + * The contributing authors would like to thank all those who helped + * with testing, bug fixes, and patience. This wouldn't have been + * possible without all of you. + * + * Thanks to Frank J. T. Wojcik for helping with the documentation. + */ + +/* Note about libpng version numbers: + * + * Due to various miscommunications, unforeseen code incompatibilities + * and occasional factors outside the authors' control, version numbering + * on the library has not always been consistent and straightforward. + * The following table summarizes matters since version 0.89c, which was + * the first widely used release: + * + * source png.h png.h shared-lib + * version string int version + * ------- ------ ----- ---------- + * 0.89c "1.0 beta 3" 0.89 89 1.0.89 + * 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90] + * 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95] + * 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96] + * 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97] + * 0.97c 0.97 97 2.0.97 + * 0.98 0.98 98 2.0.98 + * 0.99 0.99 98 2.0.99 + * 0.99a-m 0.99 99 2.0.99 + * 1.00 1.00 100 2.1.0 [100 should be 10000] + * 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000] + * 1.0.1 png.h string is 10001 2.1.0 + * 1.0.1a-e identical to the 10002 from here on, the shared library + * 1.0.2 source version) 10002 is 2.V where V is the source code + * 1.0.2a-b 10003 version, except as noted. + * 1.0.3 10003 + * 1.0.3a-d 10004 + * 1.0.4 10004 + * 1.0.4a-f 10005 + * 1.0.5 (+ 2 patches) 10005 + * 1.0.5a-d 10006 + * 1.0.5e-r 10100 (not source compatible) + * 1.0.5s-v 10006 (not binary compatible) + * 1.0.6 (+ 3 patches) 10006 (still binary incompatible) + * 1.0.6d-f 10007 (still binary incompatible) + * 1.0.6g 10007 + * 1.0.6h 10007 10.6h (testing xy.z so-numbering) + * 1.0.6i 10007 10.6i + * 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0) + * 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible) + * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible) + * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible) + * 1.0.7 1 10007 (still compatible) + * ... + * 1.0.19 10 10019 10.so.0.19[.0] + * ... + * 1.2.53 13 10253 12.so.0.53[.0] + * ... + * 1.5.23 15 10523 15.so.15.23[.0] + * ... + * 1.6.21 16 10621 16.so.16.21[.0] + * + * Henceforth the source version will match the shared-library major + * and minor numbers; the shared-library major version number will be + * used for changes in backward compatibility, as it is intended. The + * PNG_LIBPNG_VER macro, which is not used within libpng but is available + * for applications, is an unsigned integer of the form xyyzz corresponding + * to the source version x.y.z (leading zeros in y and z). Beta versions + * were given the previous public release number plus a letter, until + * version 1.0.6j; from then on they were given the upcoming public + * release number plus "betaNN" or "rcNN". + * + * Binary incompatibility exists only when applications make direct access + * to the info_ptr or png_ptr members through png.h, and the compiled + * application is loaded with a different version of the library. + * + * DLLNUM will change each time there are forward or backward changes + * in binary compatibility (e.g., when a new feature is added). + * + * See libpng.txt or libpng.3 for more information. The PNG specification + * is available as a W3C Recommendation and as an ISO Specification, + * <http://www.w3.org/TR/2003/REC-PNG-20031110/ + */ + +/* + * Y2K compliance in libpng: + * ========================= + * + * January 15, 2016 + * + * Since the PNG Development group is an ad-hoc body, we can't make + * an official declaration. + * + * This is your unofficial assurance that libpng from version 0.71 and + * upward through 1.6.21 are Y2K compliant. It is my belief that + * earlier versions were also Y2K compliant. + * + * Libpng only has two year fields. One is a 2-byte unsigned integer + * that will hold years up to 65535. The other, which is deprecated, + * holds the date in text format, and will hold years up to 9999. + * + * The integer is + * "png_uint_16 year" in png_time_struct. + * + * The string is + * "char time_buffer[29]" in png_struct. This is no longer used + * in libpng-1.6.x and will be removed from libpng-1.7.0. + * + * There are seven time-related functions: + * png.c: png_convert_to_rfc_1123_buffer() in png.c + * (formerly png_convert_to_rfc_1123() prior to libpng-1.5.x and + * png_convert_to_rfc_1152() in error prior to libpng-0.98) + * png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c + * png_convert_from_time_t() in pngwrite.c + * png_get_tIME() in pngget.c + * png_handle_tIME() in pngrutil.c, called in pngread.c + * png_set_tIME() in pngset.c + * png_write_tIME() in pngwutil.c, called in pngwrite.c + * + * All handle dates properly in a Y2K environment. The + * png_convert_from_time_t() function calls gmtime() to convert from system + * clock time, which returns (year - 1900), which we properly convert to + * the full 4-digit year. There is a possibility that libpng applications + * are not passing 4-digit years into the png_convert_to_rfc_1123_buffer() + * function, or that they are incorrectly passing only a 2-digit year + * instead of "year - 1900" into the png_convert_from_struct_tm() function, + * but this is not under our control. The libpng documentation has always + * stated that it works with 4-digit years, and the APIs have been + * documented as such. + * + * The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned + * integer to hold the year, and can hold years as large as 65535. + * + * zlib, upon which libpng depends, is also Y2K compliant. It contains + * no date-related code. + * + * Glenn Randers-Pehrson + * libpng maintainer + * PNG Development Group + */ + +#ifndef PNG_H +#define PNG_H + +/* This is not the place to learn how to use libpng. The file libpng-manual.txt + * describes how to use libpng, and the file example.c summarizes it + * with some code on which to build. This file is useful for looking + * at the actual function definitions and structure components. If that + * file has been stripped from your copy of libpng, you can find it at + * <http://www.libpng.org/pub/png/libpng-manual.txt> + * + * If you just need to read a PNG file and don't want to read the documentation + * skip to the end of this file and read the section entitled 'simplified API'. + */ + +/* Version information for png.h - this should match the version in png.c */ +#define PNG_LIBPNG_VER_STRING "1.6.21" +#define PNG_HEADER_VERSION_STRING \ + " libpng version 1.6.21 - January 15, 2016\n" + +#define PNG_LIBPNG_VER_SONUM 16 +#define PNG_LIBPNG_VER_DLLNUM 16 + +/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ +#define PNG_LIBPNG_VER_MAJOR 1 +#define PNG_LIBPNG_VER_MINOR 6 +#define PNG_LIBPNG_VER_RELEASE 21 + +/* This should match the numeric part of the final component of + * PNG_LIBPNG_VER_STRING, omitting any leading zero: + */ + +#define PNG_LIBPNG_VER_BUILD 0 + +/* Release Status */ +#define PNG_LIBPNG_BUILD_ALPHA 1 +#define PNG_LIBPNG_BUILD_BETA 2 +#define PNG_LIBPNG_BUILD_RC 3 +#define PNG_LIBPNG_BUILD_STABLE 4 +#define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7 + +/* Release-Specific Flags */ +#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with + PNG_LIBPNG_BUILD_STABLE only */ +#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with + PNG_LIBPNG_BUILD_SPECIAL */ +#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with + PNG_LIBPNG_BUILD_PRIVATE */ + +#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE + +/* Careful here. At one time, Guy wanted to use 082, but that would be octal. + * We must not include leading zeros. + * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only + * version 1.0.0 was mis-numbered 100 instead of 10000). From + * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release + */ +#define PNG_LIBPNG_VER 10621 /* 1.6.21 */ + +/* Library configuration: these options cannot be changed after + * the library has been built. + */ +#ifndef PNGLCONF_H + /* If pnglibconf.h is missing, you can + * copy scripts/pnglibconf.h.prebuilt to pnglibconf.h + */ +# include "pnglibconf.h" +#endif + +#ifndef PNG_VERSION_INFO_ONLY + /* Machine specific configuration. */ +# include "pngconf.h" +#endif + +/* + * Added at libpng-1.2.8 + * + * Ref MSDN: Private as priority over Special + * VS_FF_PRIVATEBUILD File *was not* built using standard release + * procedures. If this value is given, the StringFileInfo block must + * contain a PrivateBuild string. + * + * VS_FF_SPECIALBUILD File *was* built by the original company using + * standard release procedures but is a variation of the standard + * file of the same version number. If this value is given, the + * StringFileInfo block must contain a SpecialBuild string. + */ + +#ifdef PNG_USER_PRIVATEBUILD /* From pnglibconf.h */ +# define PNG_LIBPNG_BUILD_TYPE \ + (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE) +#else +# ifdef PNG_LIBPNG_SPECIALBUILD +# define PNG_LIBPNG_BUILD_TYPE \ + (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL) +# else +# define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE) +# endif +#endif + +#ifndef PNG_VERSION_INFO_ONLY + +/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Version information for C files, stored in png.c. This had better match + * the version above. + */ +#define png_libpng_ver png_get_header_ver(NULL) + +/* This file is arranged in several sections: + * + * 1. [omitted] + * 2. Any configuration options that can be specified by for the application + * code when it is built. (Build time configuration is in pnglibconf.h) + * 3. Type definitions (base types are defined in pngconf.h), structure + * definitions. + * 4. Exported library functions. + * 5. Simplified API. + * 6. Implementation options. + * + * The library source code has additional files (principally pngpriv.h) that + * allow configuration of the library. + */ + +/* Section 1: [omitted] */ + +/* Section 2: run time configuration + * See pnglibconf.h for build time configuration + * + * Run time configuration allows the application to choose between + * implementations of certain arithmetic APIs. The default is set + * at build time and recorded in pnglibconf.h, but it is safe to + * override these (and only these) settings. Note that this won't + * change what the library does, only application code, and the + * settings can (and probably should) be made on a per-file basis + * by setting the #defines before including png.h + * + * Use macros to read integers from PNG data or use the exported + * functions? + * PNG_USE_READ_MACROS: use the macros (see below) Note that + * the macros evaluate their argument multiple times. + * PNG_NO_USE_READ_MACROS: call the relevant library function. + * + * Use the alternative algorithm for compositing alpha samples that + * does not use division? + * PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division' + * algorithm. + * PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm. + * + * How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is + * false? + * PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error + * APIs to png_warning. + * Otherwise the calls are mapped to png_error. + */ + +/* Section 3: type definitions, including structures and compile time + * constants. + * See pngconf.h for base types that vary by machine/system + */ + +/* This triggers a compiler error in png.c, if png.c and png.h + * do not agree upon the version number. + */ +typedef char* png_libpng_version_1_6_21; + +/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info. + * + * png_struct is the cache of information used while reading or writing a single + * PNG file. One of these is always required, although the simplified API + * (below) hides the creation and destruction of it. + */ +typedef struct png_struct_def png_struct; +typedef const png_struct * png_const_structp; +typedef png_struct * png_structp; +typedef png_struct * * png_structpp; + +/* png_info contains information read from or to be written to a PNG file. One + * or more of these must exist while reading or creating a PNG file. The + * information is not used by libpng during read but is used to control what + * gets written when a PNG file is created. "png_get_" function calls read + * information during read and "png_set_" functions calls write information + * when creating a PNG. + * been moved into a separate header file that is not accessible to + * applications. Read libpng-manual.txt or libpng.3 for more info. + */ +typedef struct png_info_def png_info; +typedef png_info * png_infop; +typedef const png_info * png_const_infop; +typedef png_info * * png_infopp; + +/* Types with names ending 'p' are pointer types. The corresponding types with + * names ending 'rp' are identical pointer types except that the pointer is + * marked 'restrict', which means that it is the only pointer to the object + * passed to the function. Applications should not use the 'restrict' types; + * it is always valid to pass 'p' to a pointer with a function argument of the + * corresponding 'rp' type. Different compilers have different rules with + * regard to type matching in the presence of 'restrict'. For backward + * compatibility libpng callbacks never have 'restrict' in their parameters and, + * consequentially, writing portable application code is extremely difficult if + * an attempt is made to use 'restrict'. + */ +typedef png_struct * PNG_RESTRICT png_structrp; +typedef const png_struct * PNG_RESTRICT png_const_structrp; +typedef png_info * PNG_RESTRICT png_inforp; +typedef const png_info * PNG_RESTRICT png_const_inforp; + +/* Three color definitions. The order of the red, green, and blue, (and the + * exact size) is not important, although the size of the fields need to + * be png_byte or png_uint_16 (as defined below). + */ +typedef struct png_color_struct +{ + png_byte red; + png_byte green; + png_byte blue; +} png_color; +typedef png_color * png_colorp; +typedef const png_color * png_const_colorp; +typedef png_color * * png_colorpp; + +typedef struct png_color_16_struct +{ + png_byte index; /* used for palette files */ + png_uint_16 red; /* for use in red green blue files */ + png_uint_16 green; + png_uint_16 blue; + png_uint_16 gray; /* for use in grayscale files */ +} png_color_16; +typedef png_color_16 * png_color_16p; +typedef const png_color_16 * png_const_color_16p; +typedef png_color_16 * * png_color_16pp; + +typedef struct png_color_8_struct +{ + png_byte red; /* for use in red green blue files */ + png_byte green; + png_byte blue; + png_byte gray; /* for use in grayscale files */ + png_byte alpha; /* for alpha channel files */ +} png_color_8; +typedef png_color_8 * png_color_8p; +typedef const png_color_8 * png_const_color_8p; +typedef png_color_8 * * png_color_8pp; + +/* + * The following two structures are used for the in-core representation + * of sPLT chunks. + */ +typedef struct png_sPLT_entry_struct +{ + png_uint_16 red; + png_uint_16 green; + png_uint_16 blue; + png_uint_16 alpha; + png_uint_16 frequency; +} png_sPLT_entry; +typedef png_sPLT_entry * png_sPLT_entryp; +typedef const png_sPLT_entry * png_const_sPLT_entryp; +typedef png_sPLT_entry * * png_sPLT_entrypp; + +/* When the depth of the sPLT palette is 8 bits, the color and alpha samples + * occupy the LSB of their respective members, and the MSB of each member + * is zero-filled. The frequency member always occupies the full 16 bits. + */ + +typedef struct png_sPLT_struct +{ + png_charp name; /* palette name */ + png_byte depth; /* depth of palette samples */ + png_sPLT_entryp entries; /* palette entries */ + png_int_32 nentries; /* number of palette entries */ +} png_sPLT_t; +typedef png_sPLT_t * png_sPLT_tp; +typedef const png_sPLT_t * png_const_sPLT_tp; +typedef png_sPLT_t * * png_sPLT_tpp; + +#ifdef PNG_TEXT_SUPPORTED +/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file, + * and whether that contents is compressed or not. The "key" field + * points to a regular zero-terminated C string. The "text" fields can be a + * regular C string, an empty string, or a NULL pointer. + * However, the structure returned by png_get_text() will always contain + * the "text" field as a regular zero-terminated C string (possibly + * empty), never a NULL pointer, so it can be safely used in printf() and + * other string-handling functions. Note that the "itxt_length", "lang", and + * "lang_key" members of the structure only exist when the library is built + * with iTXt chunk support. Prior to libpng-1.4.0 the library was built by + * default without iTXt support. Also note that when iTXt *is* supported, + * the "lang" and "lang_key" fields contain NULL pointers when the + * "compression" field contains * PNG_TEXT_COMPRESSION_NONE or + * PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the + * same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag" + * which is always 0 or 1, or its "compression method" which is always 0. + */ +typedef struct png_text_struct +{ + int compression; /* compression value: + -1: tEXt, none + 0: zTXt, deflate + 1: iTXt, none + 2: iTXt, deflate */ + png_charp key; /* keyword, 1-79 character description of "text" */ + png_charp text; /* comment, may be an empty string (ie "") + or a NULL pointer */ + png_size_t text_length; /* length of the text string */ + png_size_t itxt_length; /* length of the itxt string */ + png_charp lang; /* language code, 0-79 characters + or a NULL pointer */ + png_charp lang_key; /* keyword translated UTF-8 string, 0 or more + chars or a NULL pointer */ +} png_text; +typedef png_text * png_textp; +typedef const png_text * png_const_textp; +typedef png_text * * png_textpp; +#endif + +/* Supported compression types for text in PNG files (tEXt, and zTXt). + * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */ +#define PNG_TEXT_COMPRESSION_NONE_WR -3 +#define PNG_TEXT_COMPRESSION_zTXt_WR -2 +#define PNG_TEXT_COMPRESSION_NONE -1 +#define PNG_TEXT_COMPRESSION_zTXt 0 +#define PNG_ITXT_COMPRESSION_NONE 1 +#define PNG_ITXT_COMPRESSION_zTXt 2 +#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */ + +/* png_time is a way to hold the time in an machine independent way. + * Two conversions are provided, both from time_t and struct tm. There + * is no portable way to convert to either of these structures, as far + * as I know. If you know of a portable way, send it to me. As a side + * note - PNG has always been Year 2000 compliant! + */ +typedef struct png_time_struct +{ + png_uint_16 year; /* full year, as in, 1995 */ + png_byte month; /* month of year, 1 - 12 */ + png_byte day; /* day of month, 1 - 31 */ + png_byte hour; /* hour of day, 0 - 23 */ + png_byte minute; /* minute of hour, 0 - 59 */ + png_byte second; /* second of minute, 0 - 60 (for leap seconds) */ +} png_time; +typedef png_time * png_timep; +typedef const png_time * png_const_timep; +typedef png_time * * png_timepp; + +#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) ||\ + defined(PNG_USER_CHUNKS_SUPPORTED) +/* png_unknown_chunk is a structure to hold queued chunks for which there is + * no specific support. The idea is that we can use this to queue + * up private chunks for output even though the library doesn't actually + * know about their semantics. + * + * The data in the structure is set by libpng on read and used on write. + */ +typedef struct png_unknown_chunk_t +{ + png_byte name[5]; /* Textual chunk name with '\0' terminator */ + png_byte *data; /* Data, should not be modified on read! */ + png_size_t size; + + /* On write 'location' must be set using the flag values listed below. + * Notice that on read it is set by libpng however the values stored have + * more bits set than are listed below. Always treat the value as a + * bitmask. On write set only one bit - setting multiple bits may cause the + * chunk to be written in multiple places. + */ + png_byte location; /* mode of operation at read time */ +} +png_unknown_chunk; + +typedef png_unknown_chunk * png_unknown_chunkp; +typedef const png_unknown_chunk * png_const_unknown_chunkp; +typedef png_unknown_chunk * * png_unknown_chunkpp; +#endif + +/* Flag values for the unknown chunk location byte. */ +#define PNG_HAVE_IHDR 0x01 +#define PNG_HAVE_PLTE 0x02 +#define PNG_AFTER_IDAT 0x08 + +/* Maximum positive integer used in PNG is (2^31)-1 */ +#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) +#define PNG_UINT_32_MAX ((png_uint_32)(-1)) +#define PNG_SIZE_MAX ((png_size_t)(-1)) + +/* These are constants for fixed point values encoded in the + * PNG specification manner (x100000) + */ +#define PNG_FP_1 100000 +#define PNG_FP_HALF 50000 +#define PNG_FP_MAX ((png_fixed_point)0x7fffffffL) +#define PNG_FP_MIN (-PNG_FP_MAX) + +/* These describe the color_type field in png_info. */ +/* color type masks */ +#define PNG_COLOR_MASK_PALETTE 1 +#define PNG_COLOR_MASK_COLOR 2 +#define PNG_COLOR_MASK_ALPHA 4 + +/* color types. Note that not all combinations are legal */ +#define PNG_COLOR_TYPE_GRAY 0 +#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE) +#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR) +#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA) +#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA) +/* aliases */ +#define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA +#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA + +/* This is for compression type. PNG 1.0-1.2 only define the single type. */ +#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */ +#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE + +/* This is for filter type. PNG 1.0-1.2 only define the single type. */ +#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */ +#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */ +#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE + +/* These are for the interlacing type. These values should NOT be changed. */ +#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */ +#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */ +#define PNG_INTERLACE_LAST 2 /* Not a valid value */ + +/* These are for the oFFs chunk. These values should NOT be changed. */ +#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */ +#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */ +#define PNG_OFFSET_LAST 2 /* Not a valid value */ + +/* These are for the pCAL chunk. These values should NOT be changed. */ +#define PNG_EQUATION_LINEAR 0 /* Linear transformation */ +#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */ +#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */ +#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */ +#define PNG_EQUATION_LAST 4 /* Not a valid value */ + +/* These are for the sCAL chunk. These values should NOT be changed. */ +#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */ +#define PNG_SCALE_METER 1 /* meters per pixel */ +#define PNG_SCALE_RADIAN 2 /* radians per pixel */ +#define PNG_SCALE_LAST 3 /* Not a valid value */ + +/* These are for the pHYs chunk. These values should NOT be changed. */ +#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */ +#define PNG_RESOLUTION_METER 1 /* pixels/meter */ +#define PNG_RESOLUTION_LAST 2 /* Not a valid value */ + +/* These are for the sRGB chunk. These values should NOT be changed. */ +#define PNG_sRGB_INTENT_PERCEPTUAL 0 +#define PNG_sRGB_INTENT_RELATIVE 1 +#define PNG_sRGB_INTENT_SATURATION 2 +#define PNG_sRGB_INTENT_ABSOLUTE 3 +#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */ + +/* This is for text chunks */ +#define PNG_KEYWORD_MAX_LENGTH 79 + +/* Maximum number of entries in PLTE/sPLT/tRNS arrays */ +#define PNG_MAX_PALETTE_LENGTH 256 + +/* These determine if an ancillary chunk's data has been successfully read + * from the PNG header, or if the application has filled in the corresponding + * data in the info_struct to be written into the output file. The values + * of the PNG_INFO_<chunk> defines should NOT be changed. + */ +#define PNG_INFO_gAMA 0x0001 +#define PNG_INFO_sBIT 0x0002 +#define PNG_INFO_cHRM 0x0004 +#define PNG_INFO_PLTE 0x0008 +#define PNG_INFO_tRNS 0x0010 +#define PNG_INFO_bKGD 0x0020 +#define PNG_INFO_hIST 0x0040 +#define PNG_INFO_pHYs 0x0080 +#define PNG_INFO_oFFs 0x0100 +#define PNG_INFO_tIME 0x0200 +#define PNG_INFO_pCAL 0x0400 +#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */ +#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */ +#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */ +#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */ +#if INT_MAX >= 0x8000 /* else this might break */ +#define PNG_INFO_IDAT 0x8000 /* ESR, 1.0.6 */ +#endif + +/* This is used for the transformation routines, as some of them + * change these values for the row. It also should enable using + * the routines for other purposes. + */ +typedef struct png_row_info_struct +{ + png_uint_32 width; /* width of row */ + png_size_t rowbytes; /* number of bytes in row */ + png_byte color_type; /* color type of row */ + png_byte bit_depth; /* bit depth of row */ + png_byte channels; /* number of channels (1, 2, 3, or 4) */ + png_byte pixel_depth; /* bits per pixel (depth * channels) */ +} png_row_info; + +typedef png_row_info * png_row_infop; +typedef png_row_info * * png_row_infopp; + +/* These are the function types for the I/O functions and for the functions + * that allow the user to override the default I/O functions with his or her + * own. The png_error_ptr type should match that of user-supplied warning + * and error functions, while the png_rw_ptr type should match that of the + * user read/write data functions. Note that the 'write' function must not + * modify the buffer it is passed. The 'read' function, on the other hand, is + * expected to return the read data in the buffer. + */ +typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp)); +typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t)); +typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp)); +typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32, + int)); +typedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32, + int)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop)); +typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop)); + +/* The following callback receives png_uint_32 row_number, int pass for the + * png_bytep data of the row. When transforming an interlaced image the + * row number is the row number within the sub-image of the interlace pass, so + * the value will increase to the height of the sub-image (not the full image) + * then reset to 0 for the next pass. + * + * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to + * find the output pixel (x,y) given an interlaced sub-image pixel + * (row,col,pass). (See below for these macros.) + */ +typedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp, png_bytep, + png_uint_32, int)); +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +typedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop, + png_bytep)); +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp, + png_unknown_chunkp)); +#endif +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +/* not used anywhere */ +/* typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); */ +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* This must match the function definition in <setjmp.h>, and the application + * must include this before png.h to obtain the definition of jmp_buf. The + * function is required to be PNG_NORETURN, but this is not checked. If the + * function does return the application will crash via an abort() or similar + * system level call. + * + * If you get a warning here while building the library you may need to make + * changes to ensure that pnglibconf.h records the calling convention used by + * your compiler. This may be very difficult - try using a different compiler + * to build the library! + */ +PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef); +#endif + +/* Transform masks for the high-level interface */ +#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */ +#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */ +#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */ +#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */ +#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */ +#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */ +#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */ +#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */ +#define PNG_TRANSFORM_BGR 0x0080 /* read and write */ +#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */ +#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */ +#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */ +#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only */ +/* Added to libpng-1.2.34 */ +#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER +#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */ +/* Added to libpng-1.4.0 */ +#define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */ +/* Added to libpng-1.5.4 */ +#define PNG_TRANSFORM_EXPAND_16 0x4000 /* read only */ +#if INT_MAX >= 0x8000 /* else this might break */ +#define PNG_TRANSFORM_SCALE_16 0x8000 /* read only */ +#endif + +/* Flags for MNG supported features */ +#define PNG_FLAG_MNG_EMPTY_PLTE 0x01 +#define PNG_FLAG_MNG_FILTER_64 0x04 +#define PNG_ALL_MNG_FEATURES 0x05 + +/* NOTE: prior to 1.5 these functions had no 'API' style declaration, + * this allowed the zlib default functions to be used on Windows + * platforms. In 1.5 the zlib default malloc (which just calls malloc and + * ignores the first argument) should be completely compatible with the + * following. + */ +typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp, + png_alloc_size_t)); +typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp)); + +/* Section 4: exported functions + * Here are the function definitions most commonly used. This is not + * the place to find out how to use libpng. See libpng-manual.txt for the + * full explanation, see example.c for the summary. This just provides + * a simple one line description of the use of each function. + * + * The PNG_EXPORT() and PNG_EXPORTA() macros used below are defined in + * pngconf.h and in the *.dfn files in the scripts directory. + * + * PNG_EXPORT(ordinal, type, name, (args)); + * + * ordinal: ordinal that is used while building + * *.def files. The ordinal value is only + * relevant when preprocessing png.h with + * the *.dfn files for building symbol table + * entries, and are removed by pngconf.h. + * type: return type of the function + * name: function name + * args: function arguments, with types + * + * When we wish to append attributes to a function prototype we use + * the PNG_EXPORTA() macro instead. + * + * PNG_EXPORTA(ordinal, type, name, (args), attributes); + * + * ordinal, type, name, and args: same as in PNG_EXPORT(). + * attributes: function attributes + */ + +/* Returns the version number of the library */ +PNG_EXPORT(1, png_uint_32, png_access_version_number, (void)); + +/* Tell lib we have already handled the first <num_bytes> magic bytes. + * Handling more than 8 bytes from the beginning of the file is an error. + */ +PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes)); + +/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a + * PNG file. Returns zero if the supplied bytes match the 8-byte PNG + * signature, and non-zero otherwise. Having num_to_check == 0 or + * start > 7 will always fail (ie return non-zero). + */ +PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, png_size_t start, + png_size_t num_to_check)); + +/* Simple signature checking function. This is the same as calling + * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n). + */ +#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n)) + +/* Allocate and initialize png_ptr struct for reading, and any other memory. */ +PNG_EXPORTA(4, png_structp, png_create_read_struct, + (png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn), + PNG_ALLOCATED); + +/* Allocate and initialize png_ptr struct for writing, and any other memory */ +PNG_EXPORTA(5, png_structp, png_create_write_struct, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn), + PNG_ALLOCATED); + +PNG_EXPORT(6, png_size_t, png_get_compression_buffer_size, + (png_const_structrp png_ptr)); + +PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structrp png_ptr, + png_size_t size)); + +/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp + * match up. + */ +#ifdef PNG_SETJMP_SUPPORTED +/* This function returns the jmp_buf built in to *png_ptr. It must be + * supplied with an appropriate 'longjmp' function to use on that jmp_buf + * unless the default error function is overridden in which case NULL is + * acceptable. The size of the jmp_buf is checked against the actual size + * allocated by the library - the call will return NULL on a mismatch + * indicating an ABI mismatch. + */ +PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structrp png_ptr, + png_longjmp_ptr longjmp_fn, size_t jmp_buf_size)); +# define png_jmpbuf(png_ptr) \ + (*png_set_longjmp_fn((png_ptr), longjmp, (sizeof (jmp_buf)))) +#else +# define png_jmpbuf(png_ptr) \ + (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP) +#endif +/* This function should be used by libpng applications in place of + * longjmp(png_ptr->jmpbuf, val). If longjmp_fn() has been set, it + * will use it; otherwise it will call PNG_ABORT(). This function was + * added in libpng-1.5.0. + */ +PNG_EXPORTA(9, void, png_longjmp, (png_const_structrp png_ptr, int val), + PNG_NORETURN); + +#ifdef PNG_READ_SUPPORTED +/* Reset the compression stream */ +PNG_EXPORTA(10, int, png_reset_zstream, (png_structrp png_ptr), PNG_DEPRECATED); +#endif + +/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ +#ifdef PNG_USER_MEM_SUPPORTED +PNG_EXPORTA(11, png_structp, png_create_read_struct_2, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn, + png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn), + PNG_ALLOCATED); +PNG_EXPORTA(12, png_structp, png_create_write_struct_2, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn, + png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn), + PNG_ALLOCATED); +#endif + +/* Write the PNG file signature. */ +PNG_EXPORT(13, void, png_write_sig, (png_structrp png_ptr)); + +/* Write a PNG chunk - size, type, (optional) data, CRC. */ +PNG_EXPORT(14, void, png_write_chunk, (png_structrp png_ptr, png_const_bytep + chunk_name, png_const_bytep data, png_size_t length)); + +/* Write the start of a PNG chunk - length and chunk name. */ +PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr, + png_const_bytep chunk_name, png_uint_32 length)); + +/* Write the data of a PNG chunk started with png_write_chunk_start(). */ +PNG_EXPORT(16, void, png_write_chunk_data, (png_structrp png_ptr, + png_const_bytep data, png_size_t length)); + +/* Finish a chunk started with png_write_chunk_start() (includes CRC). */ +PNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr)); + +/* Allocate and initialize the info structure */ +PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structrp png_ptr), + PNG_ALLOCATED); + +/* DEPRECATED: this function allowed init structures to be created using the + * default allocation method (typically malloc). Use is deprecated in 1.6.0 and + * the API will be removed in the future. + */ +PNG_EXPORTA(19, void, png_info_init_3, (png_infopp info_ptr, + png_size_t png_info_struct_size), PNG_DEPRECATED); + +/* Writes all the PNG information before the image. */ +PNG_EXPORT(20, void, png_write_info_before_PLTE, + (png_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(21, void, png_write_info, + (png_structrp png_ptr, png_const_inforp info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the information before the actual image data. */ +PNG_EXPORT(22, void, png_read_info, + (png_structrp png_ptr, png_inforp info_ptr)); +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED + /* Convert to a US string format: there is no localization support in this + * routine. The original implementation used a 29 character buffer in + * png_struct, this will be removed in future versions. + */ +#if PNG_LIBPNG_VER < 10700 +/* To do: remove this from libpng17 (and from libpng17/png.c and pngstruct.h) */ +PNG_EXPORTA(23, png_const_charp, png_convert_to_rfc1123, (png_structrp png_ptr, + png_const_timep ptime),PNG_DEPRECATED); +#endif +PNG_EXPORT(241, int, png_convert_to_rfc1123_buffer, (char out[29], + png_const_timep ptime)); +#endif + +#ifdef PNG_CONVERT_tIME_SUPPORTED +/* Convert from a struct tm to png_time */ +PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime, + const struct tm * ttime)); + +/* Convert from time_t to png_time. Uses gmtime() */ +PNG_EXPORT(25, void, png_convert_from_time_t, (png_timep ptime, time_t ttime)); +#endif /* CONVERT_tIME */ + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ +PNG_EXPORT(26, void, png_set_expand, (png_structrp png_ptr)); +PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structrp png_ptr)); +PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structrp png_ptr)); +PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED +/* Expand to 16-bit channels, forces conversion of palette to RGB and expansion + * of a tRNS chunk if present. + */ +PNG_EXPORT(221, void, png_set_expand_16, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Use blue, green, red order for pixels. */ +PNG_EXPORT(30, void, png_set_bgr, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +/* Expand the grayscale to 24-bit RGB if necessary. */ +PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +/* Reduce RGB to grayscale. */ +#define PNG_ERROR_ACTION_NONE 1 +#define PNG_ERROR_ACTION_WARN 2 +#define PNG_ERROR_ACTION_ERROR 3 +#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/ + +PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structrp png_ptr, + int error_action, double red, double green)) +PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structrp png_ptr, + int error_action, png_fixed_point red, png_fixed_point green)) + +PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structrp + png_ptr)); +#endif + +#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth, + png_colorp palette)); +#endif + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED +/* How the alpha channel is interpreted - this affects how the color channels + * of a PNG file are returned to the calling application when an alpha channel, + * or a tRNS chunk in a palette file, is present. + * + * This has no effect on the way pixels are written into a PNG output + * datastream. The color samples in a PNG datastream are never premultiplied + * with the alpha samples. + * + * The default is to return data according to the PNG specification: the alpha + * channel is a linear measure of the contribution of the pixel to the + * corresponding composited pixel, and the color channels are unassociated + * (not premultiplied). The gamma encoded color channels must be scaled + * according to the contribution and to do this it is necessary to undo + * the encoding, scale the color values, perform the composition and reencode + * the values. This is the 'PNG' mode. + * + * The alternative is to 'associate' the alpha with the color information by + * storing color channel values that have been scaled by the alpha. + * image. These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes + * (the latter being the two common names for associated alpha color channels). + * + * For the 'OPTIMIZED' mode, a pixel is treated as opaque only if the alpha + * value is equal to the maximum value. + * + * The final choice is to gamma encode the alpha channel as well. This is + * broken because, in practice, no implementation that uses this choice + * correctly undoes the encoding before handling alpha composition. Use this + * choice only if other serious errors in the software or hardware you use + * mandate it; the typical serious error is for dark halos to appear around + * opaque areas of the composited PNG image because of arithmetic overflow. + * + * The API function png_set_alpha_mode specifies which of these choices to use + * with an enumerated 'mode' value and the gamma of the required output: + */ +#define PNG_ALPHA_PNG 0 /* according to the PNG standard */ +#define PNG_ALPHA_STANDARD 1 /* according to Porter/Duff */ +#define PNG_ALPHA_ASSOCIATED 1 /* as above; this is the normal practice */ +#define PNG_ALPHA_PREMULTIPLIED 1 /* as above */ +#define PNG_ALPHA_OPTIMIZED 2 /* 'PNG' for opaque pixels, else 'STANDARD' */ +#define PNG_ALPHA_BROKEN 3 /* the alpha channel is gamma encoded */ + +PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structrp png_ptr, int mode, + double output_gamma)) +PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr, + int mode, png_fixed_point output_gamma)) +#endif + +#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED) +/* The output_gamma value is a screen gamma in libpng terminology: it expresses + * how to decode the output values, not how they are encoded. + */ +#define PNG_DEFAULT_sRGB -1 /* sRGB gamma and color space */ +#define PNG_GAMMA_MAC_18 -2 /* Old Mac '1.8' gamma and color space */ +#define PNG_GAMMA_sRGB 220000 /* Television standards--matches sRGB gamma */ +#define PNG_GAMMA_LINEAR PNG_FP_1 /* Linear */ +#endif + +/* The following are examples of calls to png_set_alpha_mode to achieve the + * required overall gamma correction and, where necessary, alpha + * premultiplication. + * + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB); + * This is the default libpng handling of the alpha channel - it is not + * pre-multiplied into the color components. In addition the call states + * that the output is for a sRGB system and causes all PNG files without gAMA + * chunks to be assumed to be encoded using sRGB. + * + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC); + * In this case the output is assumed to be something like an sRGB conformant + * display preceeded by a power-law lookup table of power 1.45. This is how + * early Mac systems behaved. + * + * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR); + * This is the classic Jim Blinn approach and will work in academic + * environments where everything is done by the book. It has the shortcoming + * of assuming that input PNG data with no gamma information is linear - this + * is unlikely to be correct unless the PNG files where generated locally. + * Most of the time the output precision will be so low as to show + * significant banding in dark areas of the image. + * + * png_set_expand_16(pp); + * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB); + * This is a somewhat more realistic Jim Blinn inspired approach. PNG files + * are assumed to have the sRGB encoding if not marked with a gamma value and + * the output is always 16 bits per component. This permits accurate scaling + * and processing of the data. If you know that your input PNG files were + * generated locally you might need to replace PNG_DEFAULT_sRGB with the + * correct value for your system. + * + * png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB); + * If you just need to composite the PNG image onto an existing background + * and if you control the code that does this you can use the optimization + * setting. In this case you just copy completely opaque pixels to the + * output. For pixels that are not completely transparent (you just skip + * those) you do the composition math using png_composite or png_composite_16 + * below then encode the resultant 8-bit or 16-bit values to match the output + * encoding. + * + * Other cases + * If neither the PNG nor the standard linear encoding work for you because + * of the software or hardware you use then you have a big problem. The PNG + * case will probably result in halos around the image. The linear encoding + * will probably result in a washed out, too bright, image (it's actually too + * contrasty.) Try the ALPHA_OPTIMIZED mode above - this will probably + * substantially reduce the halos. Alternatively try: + * + * png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB); + * This option will also reduce the halos, but there will be slight dark + * halos round the opaque parts of the image where the background is light. + * In the OPTIMIZED mode the halos will be light halos where the background + * is dark. Take your pick - the halos are unavoidable unless you can get + * your hardware/software fixed! (The OPTIMIZED approach is slightly + * faster.) + * + * When the default gamma of PNG files doesn't match the output gamma. + * If you have PNG files with no gamma information png_set_alpha_mode allows + * you to provide a default gamma, but it also sets the ouput gamma to the + * matching value. If you know your PNG files have a gamma that doesn't + * match the output you can take advantage of the fact that + * png_set_alpha_mode always sets the output gamma but only sets the PNG + * default if it is not already set: + * + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB); + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC); + * The first call sets both the default and the output gamma values, the + * second call overrides the output gamma without changing the default. This + * is easier than achieving the same effect with png_set_gamma. You must use + * PNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will + * fire if more than one call to png_set_alpha_mode and png_set_background is + * made in the same read operation, however multiple calls with PNG_ALPHA_PNG + * are ignored. + */ + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED +PNG_EXPORT(36, void, png_set_strip_alpha, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +PNG_EXPORT(37, void, png_set_swap_alpha, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +PNG_EXPORT(38, void, png_set_invert_alpha, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +/* Add a filler byte to 8-bit or 16-bit Gray or 24-bit or 48-bit RGB images. */ +PNG_EXPORT(39, void, png_set_filler, (png_structrp png_ptr, png_uint_32 filler, + int flags)); +/* The values of the PNG_FILLER_ defines should NOT be changed */ +# define PNG_FILLER_BEFORE 0 +# define PNG_FILLER_AFTER 1 +/* Add an alpha byte to 8-bit or 16-bit Gray or 24-bit or 48-bit RGB images. */ +PNG_EXPORT(40, void, png_set_add_alpha, (png_structrp png_ptr, + png_uint_32 filler, int flags)); +#endif /* READ_FILLER || WRITE_FILLER */ + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Swap bytes in 16-bit depth files. */ +PNG_EXPORT(41, void, png_set_swap, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) +/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */ +PNG_EXPORT(42, void, png_set_packing, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ + defined(PNG_WRITE_PACKSWAP_SUPPORTED) +/* Swap packing order of pixels in bytes. */ +PNG_EXPORT(43, void, png_set_packswap, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) +/* Converts files to legal bit depths. */ +PNG_EXPORT(44, void, png_set_shift, (png_structrp png_ptr, png_const_color_8p + true_bits)); +#endif + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) +/* Have the code handle the interlacing. Returns the number of passes. + * MUST be called before png_read_update_info or png_start_read_image, + * otherwise it will not have the desired effect. Note that it is still + * necessary to call png_read_row or png_read_rows png_get_image_height + * times for each pass. +*/ +PNG_EXPORT(45, int, png_set_interlace_handling, (png_structrp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +/* Invert monochrome files */ +PNG_EXPORT(46, void, png_set_invert_mono, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED +/* Handle alpha and tRNS by replacing with a background color. Prior to + * libpng-1.5.4 this API must not be called before the PNG file header has been + * read. Doing so will result in unexpected behavior and possible warnings or + * errors if the PNG file contains a bKGD chunk. + */ +PNG_FP_EXPORT(47, void, png_set_background, (png_structrp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, double background_gamma)) +PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structrp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, png_fixed_point background_gamma)) +#endif +#ifdef PNG_READ_BACKGROUND_SUPPORTED +# define PNG_BACKGROUND_GAMMA_UNKNOWN 0 +# define PNG_BACKGROUND_GAMMA_SCREEN 1 +# define PNG_BACKGROUND_GAMMA_FILE 2 +# define PNG_BACKGROUND_GAMMA_UNIQUE 3 +#endif + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED +/* Scale a 16-bit depth file down to 8-bit, accurately. */ +PNG_EXPORT(229, void, png_set_scale_16, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED +#define PNG_READ_16_TO_8 SUPPORTED /* Name prior to 1.5.4 */ +/* Strip the second byte of information from a 16-bit depth file. */ +PNG_EXPORT(48, void, png_set_strip_16, (png_structrp png_ptr)); +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +/* Turn on quantizing, and reduce the palette to the number of colors + * available. + */ +PNG_EXPORT(49, void, png_set_quantize, (png_structrp png_ptr, + png_colorp palette, int num_palette, int maximum_colors, + png_const_uint_16p histogram, int full_quantize)); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* The threshold on gamma processing is configurable but hard-wired into the + * library. The following is the floating point variant. + */ +#define PNG_GAMMA_THRESHOLD (PNG_GAMMA_THRESHOLD_FIXED*.00001) + +/* Handle gamma correction. Screen_gamma=(display_exponent). + * NOTE: this API simply sets the screen and file gamma values. It will + * therefore override the value for gamma in a PNG file if it is called after + * the file header has been read - use with care - call before reading the PNG + * file for best results! + * + * These routines accept the same gamma values as png_set_alpha_mode (described + * above). The PNG_GAMMA_ defines and PNG_DEFAULT_sRGB can be passed to either + * API (floating point or fixed.) Notice, however, that the 'file_gamma' value + * is the inverse of a 'screen gamma' value. + */ +PNG_FP_EXPORT(50, void, png_set_gamma, (png_structrp png_ptr, + double screen_gamma, double override_file_gamma)) +PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structrp png_ptr, + png_fixed_point screen_gamma, png_fixed_point override_file_gamma)) +#endif + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +/* Set how many lines between output flushes - 0 for no flushing */ +PNG_EXPORT(51, void, png_set_flush, (png_structrp png_ptr, int nrows)); +/* Flush the current PNG output buffer */ +PNG_EXPORT(52, void, png_write_flush, (png_structrp png_ptr)); +#endif + +/* Optional update palette with requested transformations */ +PNG_EXPORT(53, void, png_start_read_image, (png_structrp png_ptr)); + +/* Optional call to update the users info structure */ +PNG_EXPORT(54, void, png_read_update_info, (png_structrp png_ptr, + png_inforp info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read one or more rows of image data. */ +PNG_EXPORT(55, void, png_read_rows, (png_structrp png_ptr, png_bytepp row, + png_bytepp display_row, png_uint_32 num_rows)); +#endif + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read a row of data. */ +PNG_EXPORT(56, void, png_read_row, (png_structrp png_ptr, png_bytep row, + png_bytep display_row)); +#endif + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the whole image into memory at once. */ +PNG_EXPORT(57, void, png_read_image, (png_structrp png_ptr, png_bytepp image)); +#endif + +/* Write a row of image data */ +PNG_EXPORT(58, void, png_write_row, (png_structrp png_ptr, + png_const_bytep row)); + +/* Write a few rows of image data: (*row) is not written; however, the type + * is declared as writeable to maintain compatibility with previous versions + * of libpng and to allow the 'display_row' array from read_rows to be passed + * unchanged to write_rows. + */ +PNG_EXPORT(59, void, png_write_rows, (png_structrp png_ptr, png_bytepp row, + png_uint_32 num_rows)); + +/* Write the image data */ +PNG_EXPORT(60, void, png_write_image, (png_structrp png_ptr, png_bytepp image)); + +/* Write the end of the PNG file. */ +PNG_EXPORT(61, void, png_write_end, (png_structrp png_ptr, + png_inforp info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the end of the PNG file. */ +PNG_EXPORT(62, void, png_read_end, (png_structrp png_ptr, png_inforp info_ptr)); +#endif + +/* Free any memory associated with the png_info_struct */ +PNG_EXPORT(63, void, png_destroy_info_struct, (png_const_structrp png_ptr, + png_infopp info_ptr_ptr)); + +/* Free any memory associated with the png_struct and the png_info_structs */ +PNG_EXPORT(64, void, png_destroy_read_struct, (png_structpp png_ptr_ptr, + png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)); + +/* Free any memory associated with the png_struct and the png_info_structs */ +PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr, + png_infopp info_ptr_ptr)); + +/* Set the libpng method of handling chunk CRC errors */ +PNG_EXPORT(66, void, png_set_crc_action, (png_structrp png_ptr, int crit_action, + int ancil_action)); + +/* Values for png_set_crc_action() say how to handle CRC errors in + * ancillary and critical chunks, and whether to use the data contained + * therein. Note that it is impossible to "discard" data in a critical + * chunk. For versions prior to 0.90, the action was always error/quit, + * whereas in version 0.90 and later, the action for CRC errors in ancillary + * chunks is warn/discard. These values should NOT be changed. + * + * value action:critical action:ancillary + */ +#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */ +#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */ +#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */ +#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */ +#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */ +#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */ + +#ifdef PNG_WRITE_SUPPORTED +/* These functions give the user control over the scan-line filtering in + * libpng and the compression methods used by zlib. These functions are + * mainly useful for testing, as the defaults should work with most users. + * Those users who are tight on memory or want faster performance at the + * expense of compression can modify them. See the compression library + * header file (zlib.h) for an explination of the compression functions. + */ + +/* Set the filtering method(s) used by libpng. Currently, the only valid + * value for "method" is 0. + */ +PNG_EXPORT(67, void, png_set_filter, (png_structrp png_ptr, int method, + int filters)); +#endif /* WRITE */ + +/* Flags for png_set_filter() to say which filters to use. The flags + * are chosen so that they don't conflict with real filter types + * below, in case they are supplied instead of the #defined constants. + * These values should NOT be changed. + */ +#define PNG_NO_FILTERS 0x00 +#define PNG_FILTER_NONE 0x08 +#define PNG_FILTER_SUB 0x10 +#define PNG_FILTER_UP 0x20 +#define PNG_FILTER_AVG 0x40 +#define PNG_FILTER_PAETH 0x80 +#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \ + PNG_FILTER_AVG | PNG_FILTER_PAETH) + +/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now. + * These defines should NOT be changed. + */ +#define PNG_FILTER_VALUE_NONE 0 +#define PNG_FILTER_VALUE_SUB 1 +#define PNG_FILTER_VALUE_UP 2 +#define PNG_FILTER_VALUE_AVG 3 +#define PNG_FILTER_VALUE_PAETH 4 +#define PNG_FILTER_VALUE_LAST 5 + +#ifdef PNG_WRITE_SUPPORTED +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */ +PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structrp png_ptr, + int heuristic_method, int num_weights, png_const_doublep filter_weights, + png_const_doublep filter_costs)) +PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed, + (png_structrp png_ptr, int heuristic_method, int num_weights, + png_const_fixed_point_p filter_weights, + png_const_fixed_point_p filter_costs)) +#endif /* WRITE_WEIGHTED_FILTER */ + +/* The following are no longer used and will be removed from libpng-1.7: */ +#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */ +#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */ +#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */ +#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */ + +/* Set the library compression level. Currently, valid values range from + * 0 - 9, corresponding directly to the zlib compression levels 0 - 9 + * (0 - no compression, 9 - "maximal" compression). Note that tests have + * shown that zlib compression levels 3-6 usually perform as well as level 9 + * for PNG images, and do considerably fewer caclulations. In the future, + * these values may not correspond directly to the zlib compression levels. + */ +#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED +PNG_EXPORT(69, void, png_set_compression_level, (png_structrp png_ptr, + int level)); + +PNG_EXPORT(70, void, png_set_compression_mem_level, (png_structrp png_ptr, + int mem_level)); + +PNG_EXPORT(71, void, png_set_compression_strategy, (png_structrp png_ptr, + int strategy)); + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +PNG_EXPORT(72, void, png_set_compression_window_bits, (png_structrp png_ptr, + int window_bits)); + +PNG_EXPORT(73, void, png_set_compression_method, (png_structrp png_ptr, + int method)); +#endif /* WRITE_CUSTOMIZE_COMPRESSION */ + +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED +/* Also set zlib parameters for compressing non-IDAT chunks */ +PNG_EXPORT(222, void, png_set_text_compression_level, (png_structrp png_ptr, + int level)); + +PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structrp png_ptr, + int mem_level)); + +PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structrp png_ptr, + int strategy)); + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +PNG_EXPORT(225, void, png_set_text_compression_window_bits, + (png_structrp png_ptr, int window_bits)); + +PNG_EXPORT(226, void, png_set_text_compression_method, (png_structrp png_ptr, + int method)); +#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */ +#endif /* WRITE */ + +/* These next functions are called for input/output, memory, and error + * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c, + * and call standard C I/O routines such as fread(), fwrite(), and + * fprintf(). These functions can be made to use other I/O routines + * at run time for those applications that need to handle I/O in a + * different manner by calling png_set_???_fn(). See libpng-manual.txt for + * more information. + */ + +#ifdef PNG_STDIO_SUPPORTED +/* Initialize the input/output for the PNG file to the default functions. */ +PNG_EXPORT(74, void, png_init_io, (png_structrp png_ptr, png_FILE_p fp)); +#endif + +/* Replace the (error and abort), and warning functions with user + * supplied functions. If no messages are to be printed you must still + * write and use replacement functions. The replacement error_fn should + * still do a longjmp to the last setjmp location if you are using this + * method of error handling. If error_fn or warning_fn is NULL, the + * default function will be used. + */ + +PNG_EXPORT(75, void, png_set_error_fn, (png_structrp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn)); + +/* Return the user pointer associated with the error functions */ +PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structrp png_ptr)); + +/* Replace the default data output functions with a user supplied one(s). + * If buffered output is not used, then output_flush_fn can be set to NULL. + * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time + * output_flush_fn will be ignored (and thus can be NULL). + * It is probably a mistake to use NULL for output_flush_fn if + * write_data_fn is not also NULL unless you have built libpng with + * PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's + * default flush function, which uses the standard *FILE structure, will + * be used. + */ +PNG_EXPORT(77, void, png_set_write_fn, (png_structrp png_ptr, png_voidp io_ptr, + png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)); + +/* Replace the default data input function with a user supplied one. */ +PNG_EXPORT(78, void, png_set_read_fn, (png_structrp png_ptr, png_voidp io_ptr, + png_rw_ptr read_data_fn)); + +/* Return the user pointer associated with the I/O functions */ +PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_const_structrp png_ptr)); + +PNG_EXPORT(80, void, png_set_read_status_fn, (png_structrp png_ptr, + png_read_status_ptr read_row_fn)); + +PNG_EXPORT(81, void, png_set_write_status_fn, (png_structrp png_ptr, + png_write_status_ptr write_row_fn)); + +#ifdef PNG_USER_MEM_SUPPORTED +/* Replace the default memory allocation functions with user supplied one(s). */ +PNG_EXPORT(82, void, png_set_mem_fn, (png_structrp png_ptr, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn)); +/* Return the user pointer associated with the memory functions */ +PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structrp png_ptr)); +#endif + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED +PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structrp png_ptr, + png_user_transform_ptr read_user_transform_fn)); +#endif + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structrp png_ptr, + png_user_transform_ptr write_user_transform_fn)); +#endif + +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +PNG_EXPORT(86, void, png_set_user_transform_info, (png_structrp png_ptr, + png_voidp user_transform_ptr, int user_transform_depth, + int user_transform_channels)); +/* Return the user pointer associated with the user transform functions */ +PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr, + (png_const_structrp png_ptr)); +#endif + +#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED +/* Return information about the row currently being processed. Note that these + * APIs do not fail but will return unexpected results if called outside a user + * transform callback. Also note that when transforming an interlaced image the + * row number is the row number within the sub-image of the interlace pass, so + * the value will increase to the height of the sub-image (not the full image) + * then reset to 0 for the next pass. + * + * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to + * find the output pixel (x,y) given an interlaced sub-image pixel + * (row,col,pass). (See below for these macros.) + */ +PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structrp)); +PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp)); +#endif + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED +/* This callback is called only for *unknown* chunks. If + * PNG_HANDLE_AS_UNKNOWN_SUPPORTED is set then it is possible to set known + * chunks to be treated as unknown, however in this case the callback must do + * any processing required by the chunk (e.g. by calling the appropriate + * png_set_ APIs.) + * + * There is no write support - on write, by default, all the chunks in the + * 'unknown' list are written in the specified position. + * + * The integer return from the callback function is interpreted thus: + * + * negative: An error occurred; png_chunk_error will be called. + * zero: The chunk was not handled, the chunk will be saved. A critical + * chunk will cause an error at this point unless it is to be saved. + * positive: The chunk was handled, libpng will ignore/discard it. + * + * See "INTERACTION WTIH USER CHUNK CALLBACKS" below for important notes about + * how this behavior will change in libpng 1.7 + */ +PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr, + png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structrp png_ptr)); +#endif + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +/* Sets the function callbacks for the push reader, and a pointer to a + * user-defined structure available to the callback functions. + */ +PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structrp png_ptr, + png_voidp progressive_ptr, png_progressive_info_ptr info_fn, + png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn)); + +/* Returns the user pointer associated with the push read functions */ +PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, + (png_const_structrp png_ptr)); + +/* Function to be called when data becomes available */ +PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr, + png_inforp info_ptr, png_bytep buffer, png_size_t buffer_size)); + +/* A function which may be called *only* within png_process_data to stop the + * processing of any more data. The function returns the number of bytes + * remaining, excluding any that libpng has cached internally. A subsequent + * call to png_process_data must supply these bytes again. If the argument + * 'save' is set to true the routine will first save all the pending data and + * will always return 0. + */ +PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structrp, int save)); + +/* A function which may be called *only* outside (after) a call to + * png_process_data. It returns the number of bytes of data to skip in the + * input. Normally it will return 0, but if it returns a non-zero value the + * application must skip than number of bytes of input data and pass the + * following data to the next call to png_process_data. + */ +PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structrp)); + +/* Function that combines rows. 'new_row' is a flag that should come from + * the callback and be non-NULL if anything needs to be done; the library + * stores its own version of the new data internally and ignores the passed + * in value. + */ +PNG_EXPORT(93, void, png_progressive_combine_row, (png_const_structrp png_ptr, + png_bytep old_row, png_const_bytep new_row)); +#endif /* PROGRESSIVE_READ */ + +PNG_EXPORTA(94, png_voidp, png_malloc, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); +/* Added at libpng version 1.4.0 */ +PNG_EXPORTA(95, png_voidp, png_calloc, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); + +/* Added at libpng version 1.2.4 */ +PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); + +/* Frees a pointer allocated by png_malloc() */ +PNG_EXPORT(97, void, png_free, (png_const_structrp png_ptr, png_voidp ptr)); + +/* Free data that was allocated internally */ +PNG_EXPORT(98, void, png_free_data, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 free_me, int num)); + +/* Reassign responsibility for freeing existing data, whether allocated + * by libpng or by the application; this works on the png_info structure passed + * in, it does not change the state for other png_info structures. + * + * It is unlikely that this function works correctly as of 1.6.0 and using it + * may result either in memory leaks or double free of allocated data. + */ +PNG_EXPORT(99, void, png_data_freer, (png_const_structrp png_ptr, + png_inforp info_ptr, int freer, png_uint_32 mask)); + +/* Assignments for png_data_freer */ +#define PNG_DESTROY_WILL_FREE_DATA 1 +#define PNG_SET_WILL_FREE_DATA 1 +#define PNG_USER_WILL_FREE_DATA 2 +/* Flags for png_ptr->free_me and info_ptr->free_me */ +#define PNG_FREE_HIST 0x0008 +#define PNG_FREE_ICCP 0x0010 +#define PNG_FREE_SPLT 0x0020 +#define PNG_FREE_ROWS 0x0040 +#define PNG_FREE_PCAL 0x0080 +#define PNG_FREE_SCAL 0x0100 +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +# define PNG_FREE_UNKN 0x0200 +#endif +/* PNG_FREE_LIST 0x0400 removed in 1.6.0 because it is ignored */ +#define PNG_FREE_PLTE 0x1000 +#define PNG_FREE_TRNS 0x2000 +#define PNG_FREE_TEXT 0x4000 +#define PNG_FREE_ALL 0x7fff +#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ + +#ifdef PNG_USER_MEM_SUPPORTED +PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_const_structrp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED PNG_DEPRECATED); +PNG_EXPORTA(101, void, png_free_default, (png_const_structrp png_ptr, + png_voidp ptr), PNG_DEPRECATED); +#endif + +#ifdef PNG_ERROR_TEXT_SUPPORTED +/* Fatal error in PNG image of libpng - can't continue */ +PNG_EXPORTA(102, void, png_error, (png_const_structrp png_ptr, + png_const_charp error_message), PNG_NORETURN); + +/* The same, but the chunk name is prepended to the error string. */ +PNG_EXPORTA(103, void, png_chunk_error, (png_const_structrp png_ptr, + png_const_charp error_message), PNG_NORETURN); + +#else +/* Fatal error in PNG image of libpng - can't continue */ +PNG_EXPORTA(104, void, png_err, (png_const_structrp png_ptr), PNG_NORETURN); +# define png_error(s1,s2) png_err(s1) +# define png_chunk_error(s1,s2) png_err(s1) +#endif + +#ifdef PNG_WARNINGS_SUPPORTED +/* Non-fatal error in libpng. Can continue, but may have a problem. */ +PNG_EXPORT(105, void, png_warning, (png_const_structrp png_ptr, + png_const_charp warning_message)); + +/* Non-fatal error in libpng, chunk name is prepended to message. */ +PNG_EXPORT(106, void, png_chunk_warning, (png_const_structrp png_ptr, + png_const_charp warning_message)); +#else +# define png_warning(s1,s2) ((void)(s1)) +# define png_chunk_warning(s1,s2) ((void)(s1)) +#endif + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +/* Benign error in libpng. Can continue, but may have a problem. + * User can choose whether to handle as a fatal error or as a warning. */ +PNG_EXPORT(107, void, png_benign_error, (png_const_structrp png_ptr, + png_const_charp warning_message)); + +#ifdef PNG_READ_SUPPORTED +/* Same, chunk name is prepended to message (only during read) */ +PNG_EXPORT(108, void, png_chunk_benign_error, (png_const_structrp png_ptr, + png_const_charp warning_message)); +#endif + +PNG_EXPORT(109, void, png_set_benign_errors, + (png_structrp png_ptr, int allowed)); +#else +# ifdef PNG_ALLOW_BENIGN_ERRORS +# define png_benign_error png_warning +# define png_chunk_benign_error png_chunk_warning +# else +# define png_benign_error png_error +# define png_chunk_benign_error png_chunk_error +# endif +#endif + +/* The png_set_<chunk> functions are for storing values in the png_info_struct. + * Similarly, the png_get_<chunk> calls are used to read values from the + * png_info_struct, either storing the parameters in the passed variables, or + * setting pointers into the png_info_struct where the data is stored. The + * png_get_<chunk> functions return a non-zero value if the data was available + * in info_ptr, or return zero and do not change any of the parameters if the + * data was not available. + * + * These functions should be used instead of directly accessing png_info + * to avoid problems with future changes in the size and internal layout of + * png_info_struct. + */ +/* Returns "flag" if chunk data is valid in info_ptr. */ +PNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 flag)); + +/* Returns number of bytes needed to hold a transformed row. */ +PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +#ifdef PNG_INFO_IMAGE_SUPPORTED +/* Returns row_pointers, which is an array of pointers to scanlines that was + * returned from png_read_png(). + */ +PNG_EXPORT(112, png_bytepp, png_get_rows, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Set row_pointers, which is an array of pointers to scanlines for use + * by png_write_png(). + */ +PNG_EXPORT(113, void, png_set_rows, (png_const_structrp png_ptr, + png_inforp info_ptr, png_bytepp row_pointers)); +#endif + +/* Returns number of color channels in image. */ +PNG_EXPORT(114, png_byte, png_get_channels, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +#ifdef PNG_EASY_ACCESS_SUPPORTED +/* Returns image width in pixels. */ +PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image height in pixels. */ +PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image bit_depth. */ +PNG_EXPORT(117, png_byte, png_get_bit_depth, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image color_type. */ +PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image filter_type. */ +PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image interlace_type. */ +PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image compression_type. */ +PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); + +/* Returns image resolution in pixels per meter, from pHYs chunk data. */ +PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +/* Returns pixel aspect ratio, computed from pHYs chunk data. */ +PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) +PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) + +/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ +PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(128, png_int_32, png_get_x_offset_microns, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); +PNG_EXPORT(129, png_int_32, png_get_y_offset_microns, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +#endif /* EASY_ACCESS */ + +#ifdef PNG_READ_SUPPORTED +/* Returns pointer to signature string read from PNG header */ +PNG_EXPORT(130, png_const_bytep, png_get_signature, (png_const_structrp png_ptr, + png_const_inforp info_ptr)); +#endif + +#ifdef PNG_bKGD_SUPPORTED +PNG_EXPORT(131, png_uint_32, png_get_bKGD, (png_const_structrp png_ptr, + png_inforp info_ptr, png_color_16p *background)); +#endif + +#ifdef PNG_bKGD_SUPPORTED +PNG_EXPORT(132, void, png_set_bKGD, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_color_16p background)); +#endif + +#ifdef PNG_cHRM_SUPPORTED +PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structrp png_ptr, + png_const_inforp info_ptr, double *white_x, double *white_y, double *red_x, + double *red_y, double *green_x, double *green_y, double *blue_x, + double *blue_y)) +PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_const_structrp png_ptr, + png_const_inforp info_ptr, double *red_X, double *red_Y, double *red_Z, + double *green_X, double *green_Y, double *green_Z, double *blue_X, + double *blue_Y, double *blue_Z)) +PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_white_x, png_fixed_point *int_white_y, + png_fixed_point *int_red_x, png_fixed_point *int_red_y, + png_fixed_point *int_green_x, png_fixed_point *int_green_y, + png_fixed_point *int_blue_x, png_fixed_point *int_blue_y)) +PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_red_X, png_fixed_point *int_red_Y, + png_fixed_point *int_red_Z, png_fixed_point *int_green_X, + png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, + png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, + png_fixed_point *int_blue_Z)) +#endif + +#ifdef PNG_cHRM_SUPPORTED +PNG_FP_EXPORT(135, void, png_set_cHRM, (png_const_structrp png_ptr, + png_inforp info_ptr, + double white_x, double white_y, double red_x, double red_y, double green_x, + double green_y, double blue_x, double blue_y)) +PNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_const_structrp png_ptr, + png_inforp info_ptr, double red_X, double red_Y, double red_Z, + double green_X, double green_Y, double green_Z, double blue_X, + double blue_Y, double blue_Z)) +PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, png_fixed_point int_white_x, + png_fixed_point int_white_y, png_fixed_point int_red_x, + png_fixed_point int_red_y, png_fixed_point int_green_x, + png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)) +PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y, + png_fixed_point int_red_Z, png_fixed_point int_green_X, + png_fixed_point int_green_Y, png_fixed_point int_green_Z, + png_fixed_point int_blue_X, png_fixed_point int_blue_Y, + png_fixed_point int_blue_Z)) +#endif + +#ifdef PNG_gAMA_SUPPORTED +PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structrp png_ptr, + png_const_inforp info_ptr, double *file_gamma)) +PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr, + png_fixed_point *int_file_gamma)) +#endif + +#ifdef PNG_gAMA_SUPPORTED +PNG_FP_EXPORT(139, void, png_set_gAMA, (png_const_structrp png_ptr, + png_inforp info_ptr, double file_gamma)) +PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, png_fixed_point int_file_gamma)) +#endif + +#ifdef PNG_hIST_SUPPORTED +PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_16p *hist)); +#endif + +#ifdef PNG_hIST_SUPPORTED +PNG_EXPORT(142, void, png_set_hIST, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_uint_16p hist)); +#endif + +PNG_EXPORT(143, png_uint_32, png_get_IHDR, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *width, png_uint_32 *height, + int *bit_depth, int *color_type, int *interlace_method, + int *compression_method, int *filter_method)); + +PNG_EXPORT(144, void, png_set_IHDR, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_method, int compression_method, + int filter_method)); + +#ifdef PNG_oFFs_SUPPORTED +PNG_EXPORT(145, png_uint_32, png_get_oFFs, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, + int *unit_type)); +#endif + +#ifdef PNG_oFFs_SUPPORTED +PNG_EXPORT(146, void, png_set_oFFs, (png_const_structrp png_ptr, + png_inforp info_ptr, png_int_32 offset_x, png_int_32 offset_y, + int unit_type)); +#endif + +#ifdef PNG_pCAL_SUPPORTED +PNG_EXPORT(147, png_uint_32, png_get_pCAL, (png_const_structrp png_ptr, + png_inforp info_ptr, png_charp *purpose, png_int_32 *X0, + png_int_32 *X1, int *type, int *nparams, png_charp *units, + png_charpp *params)); +#endif + +#ifdef PNG_pCAL_SUPPORTED +PNG_EXPORT(148, void, png_set_pCAL, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1, + int type, int nparams, png_const_charp units, png_charpp params)); +#endif + +#ifdef PNG_pHYs_SUPPORTED +PNG_EXPORT(149, png_uint_32, png_get_pHYs, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, + int *unit_type)); +#endif + +#ifdef PNG_pHYs_SUPPORTED +PNG_EXPORT(150, void, png_set_pHYs, (png_const_structrp png_ptr, + png_inforp info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)); +#endif + +PNG_EXPORT(151, png_uint_32, png_get_PLTE, (png_const_structrp png_ptr, + png_inforp info_ptr, png_colorp *palette, int *num_palette)); + +PNG_EXPORT(152, void, png_set_PLTE, (png_structrp png_ptr, + png_inforp info_ptr, png_const_colorp palette, int num_palette)); + +#ifdef PNG_sBIT_SUPPORTED +PNG_EXPORT(153, png_uint_32, png_get_sBIT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_color_8p *sig_bit)); +#endif + +#ifdef PNG_sBIT_SUPPORTED +PNG_EXPORT(154, void, png_set_sBIT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_color_8p sig_bit)); +#endif + +#ifdef PNG_sRGB_SUPPORTED +PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structrp png_ptr, + png_const_inforp info_ptr, int *file_srgb_intent)); +#endif + +#ifdef PNG_sRGB_SUPPORTED +PNG_EXPORT(156, void, png_set_sRGB, (png_const_structrp png_ptr, + png_inforp info_ptr, int srgb_intent)); +PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_const_structrp png_ptr, + png_inforp info_ptr, int srgb_intent)); +#endif + +#ifdef PNG_iCCP_SUPPORTED +PNG_EXPORT(158, png_uint_32, png_get_iCCP, (png_const_structrp png_ptr, + png_inforp info_ptr, png_charpp name, int *compression_type, + png_bytepp profile, png_uint_32 *proflen)); +#endif + +#ifdef PNG_iCCP_SUPPORTED +PNG_EXPORT(159, void, png_set_iCCP, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_charp name, int compression_type, + png_const_bytep profile, png_uint_32 proflen)); +#endif + +#ifdef PNG_sPLT_SUPPORTED +PNG_EXPORT(160, int, png_get_sPLT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_sPLT_tpp entries)); +#endif + +#ifdef PNG_sPLT_SUPPORTED +PNG_EXPORT(161, void, png_set_sPLT, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_sPLT_tp entries, int nentries)); +#endif + +#ifdef PNG_TEXT_SUPPORTED +/* png_get_text also returns the number of text chunks in *num_text */ +PNG_EXPORT(162, int, png_get_text, (png_const_structrp png_ptr, + png_inforp info_ptr, png_textp *text_ptr, int *num_text)); +#endif + +/* Note while png_set_text() will accept a structure whose text, + * language, and translated keywords are NULL pointers, the structure + * returned by png_get_text will always contain regular + * zero-terminated C strings. They might be empty strings but + * they will never be NULL pointers. + */ + +#ifdef PNG_TEXT_SUPPORTED +PNG_EXPORT(163, void, png_set_text, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_textp text_ptr, int num_text)); +#endif + +#ifdef PNG_tIME_SUPPORTED +PNG_EXPORT(164, png_uint_32, png_get_tIME, (png_const_structrp png_ptr, + png_inforp info_ptr, png_timep *mod_time)); +#endif + +#ifdef PNG_tIME_SUPPORTED +PNG_EXPORT(165, void, png_set_tIME, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_timep mod_time)); +#endif + +#ifdef PNG_tRNS_SUPPORTED +PNG_EXPORT(166, png_uint_32, png_get_tRNS, (png_const_structrp png_ptr, + png_inforp info_ptr, png_bytep *trans_alpha, int *num_trans, + png_color_16p *trans_color)); +#endif + +#ifdef PNG_tRNS_SUPPORTED +PNG_EXPORT(167, void, png_set_tRNS, (png_structrp png_ptr, + png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans, + png_const_color_16p trans_color)); +#endif + +#ifdef PNG_sCAL_SUPPORTED +PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr, + png_const_inforp info_ptr, int *unit, double *width, double *height)) +#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ + defined(PNG_FLOATING_POINT_SUPPORTED) +/* NOTE: this API is currently implemented using floating point arithmetic, + * consequently it can only be used on systems with floating point support. + * In any case the range of values supported by png_fixed_point is small and it + * is highly recommended that png_get_sCAL_s be used instead. + */ +PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, + png_fixed_point *width, png_fixed_point *height)) +#endif +PNG_EXPORT(169, png_uint_32, png_get_sCAL_s, + (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit, + png_charpp swidth, png_charpp sheight)); + +PNG_FP_EXPORT(170, void, png_set_sCAL, (png_const_structrp png_ptr, + png_inforp info_ptr, int unit, double width, double height)) +PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_const_structrp png_ptr, + png_inforp info_ptr, int unit, png_fixed_point width, + png_fixed_point height)) +PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr, + png_inforp info_ptr, int unit, + png_const_charp swidth, png_const_charp sheight)); +#endif /* sCAL */ + +#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED +/* Provide the default handling for all unknown chunks or, optionally, for + * specific unknown chunks. + * + * NOTE: prior to 1.6.0 the handling specified for particular chunks on read was + * ignored and the default was used, the per-chunk setting only had an effect on + * write. If you wish to have chunk-specific handling on read in code that must + * work on earlier versions you must use a user chunk callback to specify the + * desired handling (keep or discard.) + * + * The 'keep' parameter is a PNG_HANDLE_CHUNK_ value as listed below. The + * parameter is interpreted as follows: + * + * READ: + * PNG_HANDLE_CHUNK_AS_DEFAULT: + * Known chunks: do normal libpng processing, do not keep the chunk (but + * see the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED) + * Unknown chunks: for a specific chunk use the global default, when used + * as the default discard the chunk data. + * PNG_HANDLE_CHUNK_NEVER: + * Discard the chunk data. + * PNG_HANDLE_CHUNK_IF_SAFE: + * Keep the chunk data if the chunk is not critical else raise a chunk + * error. + * PNG_HANDLE_CHUNK_ALWAYS: + * Keep the chunk data. + * + * If the chunk data is saved it can be retrieved using png_get_unknown_chunks, + * below. Notice that specifying "AS_DEFAULT" as a global default is equivalent + * to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks + * it simply resets the behavior to the libpng default. + * + * INTERACTION WTIH USER CHUNK CALLBACKS: + * The per-chunk handling is always used when there is a png_user_chunk_ptr + * callback and the callback returns 0; the chunk is then always stored *unless* + * it is critical and the per-chunk setting is other than ALWAYS. Notice that + * the global default is *not* used in this case. (In effect the per-chunk + * value is incremented to at least IF_SAFE.) + * + * IMPORTANT NOTE: this behavior will change in libpng 1.7 - the global and + * per-chunk defaults will be honored. If you want to preserve the current + * behavior when your callback returns 0 you must set PNG_HANDLE_CHUNK_IF_SAFE + * as the default - if you don't do this libpng 1.6 will issue a warning. + * + * If you want unhandled unknown chunks to be discarded in libpng 1.6 and + * earlier simply return '1' (handled). + * + * PNG_HANDLE_AS_UNKNOWN_SUPPORTED: + * If this is *not* set known chunks will always be handled by libpng and + * will never be stored in the unknown chunk list. Known chunks listed to + * png_set_keep_unknown_chunks will have no effect. If it is set then known + * chunks listed with a keep other than AS_DEFAULT will *never* be processed + * by libpng, in addition critical chunks must either be processed by the + * callback or saved. + * + * The IHDR and IEND chunks must not be listed. Because this turns off the + * default handling for chunks that would otherwise be recognized the + * behavior of libpng transformations may well become incorrect! + * + * WRITE: + * When writing chunks the options only apply to the chunks specified by + * png_set_unknown_chunks (below), libpng will *always* write known chunks + * required by png_set_ calls and will always write the core critical chunks + * (as required for PLTE). + * + * Each chunk in the png_set_unknown_chunks list is looked up in the + * png_set_keep_unknown_chunks list to find the keep setting, this is then + * interpreted as follows: + * + * PNG_HANDLE_CHUNK_AS_DEFAULT: + * Write safe-to-copy chunks and write other chunks if the global + * default is set to _ALWAYS, otherwise don't write this chunk. + * PNG_HANDLE_CHUNK_NEVER: + * Do not write the chunk. + * PNG_HANDLE_CHUNK_IF_SAFE: + * Write the chunk if it is safe-to-copy, otherwise do not write it. + * PNG_HANDLE_CHUNK_ALWAYS: + * Write the chunk. + * + * Note that the default behavior is effectively the opposite of the read case - + * in read unknown chunks are not stored by default, in write they are written + * by default. Also the behavior of PNG_HANDLE_CHUNK_IF_SAFE is very different + * - on write the safe-to-copy bit is checked, on read the critical bit is + * checked and on read if the chunk is critical an error will be raised. + * + * num_chunks: + * =========== + * If num_chunks is positive, then the "keep" parameter specifies the manner + * for handling only those chunks appearing in the chunk_list array, + * otherwise the chunk list array is ignored. + * + * If num_chunks is 0 the "keep" parameter specifies the default behavior for + * unknown chunks, as described above. + * + * If num_chunks is negative, then the "keep" parameter specifies the manner + * for handling all unknown chunks plus all chunks recognized by libpng + * except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to + * be processed by libpng. + */ +PNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structrp png_ptr, + int keep, png_const_bytep chunk_list, int num_chunks)); + +/* The "keep" PNG_HANDLE_CHUNK_ parameter for the specified chunk is returned; + * the result is therefore true (non-zero) if special handling is required, + * false for the default handling. + */ +PNG_EXPORT(173, int, png_handle_as_unknown, (png_const_structrp png_ptr, + png_const_bytep chunk_name)); +#endif + +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +PNG_EXPORT(174, void, png_set_unknown_chunks, (png_const_structrp png_ptr, + png_inforp info_ptr, png_const_unknown_chunkp unknowns, + int num_unknowns)); + /* NOTE: prior to 1.6.0 this routine set the 'location' field of the added + * unknowns to the location currently stored in the png_struct. This is + * invariably the wrong value on write. To fix this call the following API + * for each chunk in the list with the correct location. If you know your + * code won't be compiled on earlier versions you can rely on + * png_set_unknown_chunks(write-ptr, png_get_unknown_chunks(read-ptr)) doing + * the correct thing. + */ + +PNG_EXPORT(175, void, png_set_unknown_chunk_location, + (png_const_structrp png_ptr, png_inforp info_ptr, int chunk, int location)); + +PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structrp png_ptr, + png_inforp info_ptr, png_unknown_chunkpp entries)); +#endif + +/* Png_free_data() will turn off the "valid" flag for anything it frees. + * If you need to turn it off for a chunk that your application has freed, + * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); + */ +PNG_EXPORT(177, void, png_set_invalid, (png_const_structrp png_ptr, + png_inforp info_ptr, int mask)); + +#ifdef PNG_INFO_IMAGE_SUPPORTED +/* The "params" pointer is currently not used and is for future expansion. */ +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +PNG_EXPORT(178, void, png_read_png, (png_structrp png_ptr, png_inforp info_ptr, + int transforms, png_voidp params)); +#endif +#ifdef PNG_WRITE_SUPPORTED +PNG_EXPORT(179, void, png_write_png, (png_structrp png_ptr, png_inforp info_ptr, + int transforms, png_voidp params)); +#endif +#endif + +PNG_EXPORT(180, png_const_charp, png_get_copyright, + (png_const_structrp png_ptr)); +PNG_EXPORT(181, png_const_charp, png_get_header_ver, + (png_const_structrp png_ptr)); +PNG_EXPORT(182, png_const_charp, png_get_header_version, + (png_const_structrp png_ptr)); +PNG_EXPORT(183, png_const_charp, png_get_libpng_ver, + (png_const_structrp png_ptr)); + +#ifdef PNG_MNG_FEATURES_SUPPORTED +PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structrp png_ptr, + png_uint_32 mng_features_permitted)); +#endif + +/* For use in png_set_keep_unknown, added to version 1.2.6 */ +#define PNG_HANDLE_CHUNK_AS_DEFAULT 0 +#define PNG_HANDLE_CHUNK_NEVER 1 +#define PNG_HANDLE_CHUNK_IF_SAFE 2 +#define PNG_HANDLE_CHUNK_ALWAYS 3 +#define PNG_HANDLE_CHUNK_LAST 4 + +/* Strip the prepended error numbers ("#nnn ") from error and warning + * messages before passing them to the error or warning handler. + */ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +PNG_EXPORT(185, void, png_set_strip_error_numbers, (png_structrp png_ptr, + png_uint_32 strip_mode)); +#endif + +/* Added in libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +PNG_EXPORT(186, void, png_set_user_limits, (png_structrp png_ptr, + png_uint_32 user_width_max, png_uint_32 user_height_max)); +PNG_EXPORT(187, png_uint_32, png_get_user_width_max, + (png_const_structrp png_ptr)); +PNG_EXPORT(188, png_uint_32, png_get_user_height_max, + (png_const_structrp png_ptr)); +/* Added in libpng-1.4.0 */ +PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structrp png_ptr, + png_uint_32 user_chunk_cache_max)); +PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max, + (png_const_structrp png_ptr)); +/* Added in libpng-1.4.1 */ +PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structrp png_ptr, + png_alloc_size_t user_chunk_cache_max)); +PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max, + (png_const_structrp png_ptr)); +#endif + +#if defined(PNG_INCH_CONVERSIONS_SUPPORTED) +PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch, + (png_const_structrp png_ptr, png_const_inforp info_ptr)); + +PNG_FP_EXPORT(196, float, png_get_x_offset_inches, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) +#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ +PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) +#endif + +PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structrp png_ptr, + png_const_inforp info_ptr)) +#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ +PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed, + (png_const_structrp png_ptr, png_const_inforp info_ptr)) +#endif + +# ifdef PNG_pHYs_SUPPORTED +PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structrp png_ptr, + png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, + int *unit_type)); +# endif /* pHYs */ +#endif /* INCH_CONVERSIONS */ + +/* Added in libpng-1.4.0 */ +#ifdef PNG_IO_STATE_SUPPORTED +PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_const_structrp png_ptr)); + +/* Removed from libpng 1.6; use png_get_io_chunk_type. */ +PNG_REMOVED(200, png_const_bytep, png_get_io_chunk_name, (png_structrp png_ptr), + PNG_DEPRECATED) + +PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, + (png_const_structrp png_ptr)); + +/* The flags returned by png_get_io_state() are the following: */ +# define PNG_IO_NONE 0x0000 /* no I/O at this moment */ +# define PNG_IO_READING 0x0001 /* currently reading */ +# define PNG_IO_WRITING 0x0002 /* currently writing */ +# define PNG_IO_SIGNATURE 0x0010 /* currently at the file signature */ +# define PNG_IO_CHUNK_HDR 0x0020 /* currently at the chunk header */ +# define PNG_IO_CHUNK_DATA 0x0040 /* currently at the chunk data */ +# define PNG_IO_CHUNK_CRC 0x0080 /* currently at the chunk crc */ +# define PNG_IO_MASK_OP 0x000f /* current operation: reading/writing */ +# define PNG_IO_MASK_LOC 0x00f0 /* current location: sig/hdr/data/crc */ +#endif /* IO_STATE */ + +/* Interlace support. The following macros are always defined so that if + * libpng interlace handling is turned off the macros may be used to handle + * interlaced images within the application. + */ +#define PNG_INTERLACE_ADAM7_PASSES 7 + +/* Two macros to return the first row and first column of the original, + * full, image which appears in a given pass. 'pass' is in the range 0 + * to 6 and the result is in the range 0 to 7. + */ +#define PNG_PASS_START_ROW(pass) (((1&~(pass))<<(3-((pass)>>1)))&7) +#define PNG_PASS_START_COL(pass) (((1& (pass))<<(3-(((pass)+1)>>1)))&7) + +/* A macro to return the offset between pixels in the output row for a pair of + * pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that + * follows. Note that ROW_OFFSET is the offset from one row to the next whereas + * COL_OFFSET is from one column to the next, within a row. + */ +#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8) +#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1)) + +/* Two macros to help evaluate the number of rows or columns in each + * pass. This is expressed as a shift - effectively log2 of the number or + * rows or columns in each 8x8 tile of the original image. + */ +#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3) +#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3) + +/* Hence two macros to determine the number of rows or columns in a given + * pass of an image given its height or width. In fact these macros may + * return non-zero even though the sub-image is empty, because the other + * dimension may be empty for a small image. + */ +#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\ + -1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass)) +#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\ + -1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass)) + +/* For the reader row callbacks (both progressive and sequential) it is + * necessary to find the row in the output image given a row in an interlaced + * image, so two more macros: + */ +#define PNG_ROW_FROM_PASS_ROW(y_in, pass) \ + (((y_in)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass)) +#define PNG_COL_FROM_PASS_COL(x_in, pass) \ + (((x_in)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass)) + +/* Two macros which return a boolean (0 or 1) saying whether the given row + * or column is in a particular pass. These use a common utility macro that + * returns a mask for a given pass - the offset 'off' selects the row or + * column version. The mask has the appropriate bit set for each column in + * the tile. + */ +#define PNG_PASS_MASK(pass,off) ( \ + ((0x110145AF>>(((7-(off))-(pass))<<2)) & 0xF) | \ + ((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0)) + +#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \ + ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1) +#define PNG_COL_IN_INTERLACE_PASS(x, pass) \ + ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1) + +#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED +/* With these routines we avoid an integer divide, which will be slower on + * most machines. However, it does take more operations than the corresponding + * divide method, so it may be slower on a few RISC systems. There are two + * shifts (by 8 or 16 bits) and an addition, versus a single integer divide. + * + * Note that the rounding factors are NOT supposed to be the same! 128 and + * 32768 are correct for the NODIV code; 127 and 32767 are correct for the + * standard method. + * + * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ] + */ + + /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ + +# define png_composite(composite, fg, alpha, bg) \ + { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \ + * (png_uint_16)(alpha) \ + + (png_uint_16)(bg)*(png_uint_16)(255 \ + - (png_uint_16)(alpha)) + 128); \ + (composite) = (png_byte)(((temp + (temp >> 8)) >> 8) & 0xff); } + +# define png_composite_16(composite, fg, alpha, bg) \ + { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \ + * (png_uint_32)(alpha) \ + + (png_uint_32)(bg)*(65535 \ + - (png_uint_32)(alpha)) + 32768); \ + (composite) = (png_uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); } + +#else /* Standard method using integer division */ + +# define png_composite(composite, fg, alpha, bg) \ + (composite) = \ + (png_byte)(0xff & (((png_uint_16)(fg) * (png_uint_16)(alpha) + \ + (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ + 127) / 255)) + +# define png_composite_16(composite, fg, alpha, bg) \ + (composite) = \ + (png_uint_16)(0xffff & (((png_uint_32)(fg) * (png_uint_32)(alpha) + \ + (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \ + 32767) / 65535)) +#endif /* READ_COMPOSITE_NODIV */ + +#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED +PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf)); +PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf)); +PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf)); +#endif + +PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_const_structrp png_ptr, + png_const_bytep buf)); +/* No png_get_int_16 -- may be added if there's a real need for it. */ + +/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */ +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED +PNG_EXPORT(205, void, png_save_uint_32, (png_bytep buf, png_uint_32 i)); +#endif +#ifdef PNG_SAVE_INT_32_SUPPORTED +PNG_EXPORT(206, void, png_save_int_32, (png_bytep buf, png_int_32 i)); +#endif + +/* Place a 16-bit number into a buffer in PNG byte order. + * The parameter is declared unsigned int, not png_uint_16, + * just to avoid potential problems on pre-ANSI C compilers. + */ +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED +PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); +/* No png_save_int_16 -- may be added if there's a real need for it. */ +#endif + +#ifdef PNG_USE_READ_MACROS +/* Inline macros to do direct reads of bytes from the input buffer. + * The png_get_int_32() routine assumes we are using two's complement + * format for negative values, which is almost certainly true. + */ +# define PNG_get_uint_32(buf) \ + (((png_uint_32)(*(buf)) << 24) + \ + ((png_uint_32)(*((buf) + 1)) << 16) + \ + ((png_uint_32)(*((buf) + 2)) << 8) + \ + ((png_uint_32)(*((buf) + 3)))) + + /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the + * function) incorrectly returned a value of type png_uint_32. + */ +# define PNG_get_uint_16(buf) \ + ((png_uint_16) \ + (((unsigned int)(*(buf)) << 8) + \ + ((unsigned int)(*((buf) + 1))))) + +# define PNG_get_int_32(buf) \ + ((png_int_32)((*(buf) & 0x80) \ + ? -((png_int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \ + : (png_int_32)png_get_uint_32(buf))) + + /* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h, + * but defining a macro name prefixed with PNG_PREFIX. + */ +# ifndef PNG_PREFIX +# define png_get_uint_32(buf) PNG_get_uint_32(buf) +# define png_get_uint_16(buf) PNG_get_uint_16(buf) +# define png_get_int_32(buf) PNG_get_int_32(buf) +# endif +#else +# ifdef PNG_PREFIX + /* No macros; revert to the (redefined) function */ +# define PNG_get_uint_32 (png_get_uint_32) +# define PNG_get_uint_16 (png_get_uint_16) +# define PNG_get_int_32 (png_get_int_32) +# endif +#endif + +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +PNG_EXPORT(242, void, png_set_check_for_invalid_index, + (png_structrp png_ptr, int allowed)); +# ifdef PNG_GET_PALETTE_MAX_SUPPORTED +PNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr, + png_const_infop info_ptr)); +# endif +#endif /* CHECK_FOR_INVALID_INDEX */ + +/******************************************************************************* + * Section 5: SIMPLIFIED API + ******************************************************************************* + * + * Please read the documentation in libpng-manual.txt (TODO: write said + * documentation) if you don't understand what follows. + * + * The simplified API hides the details of both libpng and the PNG file format + * itself. It allows PNG files to be read into a very limited number of + * in-memory bitmap formats or to be written from the same formats. If these + * formats do not accomodate your needs then you can, and should, use the more + * sophisticated APIs above - these support a wide variety of in-memory formats + * and a wide variety of sophisticated transformations to those formats as well + * as a wide variety of APIs to manipulate ancillary information. + * + * To read a PNG file using the simplified API: + * + * 1) Declare a 'png_image' structure (see below) on the stack, set the + * version field to PNG_IMAGE_VERSION and the 'opaque' pointer to NULL + * (this is REQUIRED, your program may crash if you don't do it.) + * 2) Call the appropriate png_image_begin_read... function. + * 3) Set the png_image 'format' member to the required sample format. + * 4) Allocate a buffer for the image and, if required, the color-map. + * 5) Call png_image_finish_read to read the image and, if required, the + * color-map into your buffers. + * + * There are no restrictions on the format of the PNG input itself; all valid + * color types, bit depths, and interlace methods are acceptable, and the + * input image is transformed as necessary to the requested in-memory format + * during the png_image_finish_read() step. The only caveat is that if you + * request a color-mapped image from a PNG that is full-color or makes + * complex use of an alpha channel the transformation is extremely lossy and the + * result may look terrible. + * + * To write a PNG file using the simplified API: + * + * 1) Declare a 'png_image' structure on the stack and memset() it to all zero. + * 2) Initialize the members of the structure that describe the image, setting + * the 'format' member to the format of the image samples. + * 3) Call the appropriate png_image_write... function with a pointer to the + * image and, if necessary, the color-map to write the PNG data. + * + * png_image is a structure that describes the in-memory format of an image + * when it is being read or defines the in-memory format of an image that you + * need to write: + */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) || \ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) + +#define PNG_IMAGE_VERSION 1 + +typedef struct png_control *png_controlp; +typedef struct +{ + png_controlp opaque; /* Initialize to NULL, free with png_image_free */ + png_uint_32 version; /* Set to PNG_IMAGE_VERSION */ + png_uint_32 width; /* Image width in pixels (columns) */ + png_uint_32 height; /* Image height in pixels (rows) */ + png_uint_32 format; /* Image format as defined below */ + png_uint_32 flags; /* A bit mask containing informational flags */ + png_uint_32 colormap_entries; + /* Number of entries in the color-map */ + + /* In the event of an error or warning the following field will be set to a + * non-zero value and the 'message' field will contain a '\0' terminated + * string with the libpng error or warning message. If both warnings and + * an error were encountered, only the error is recorded. If there + * are multiple warnings, only the first one is recorded. + * + * The upper 30 bits of this value are reserved, the low two bits contain + * a value as follows: + */ +# define PNG_IMAGE_WARNING 1 +# define PNG_IMAGE_ERROR 2 + /* + * The result is a two-bit code such that a value more than 1 indicates + * a failure in the API just called: + * + * 0 - no warning or error + * 1 - warning + * 2 - error + * 3 - error preceded by warning + */ +# define PNG_IMAGE_FAILED(png_cntrl) ((((png_cntrl).warning_or_error)&0x03)>1) + + png_uint_32 warning_or_error; + + char message[64]; +} png_image, *png_imagep; + +/* The samples of the image have one to four channels whose components have + * original values in the range 0 to 1.0: + * + * 1: A single gray or luminance channel (G). + * 2: A gray/luminance channel and an alpha channel (GA). + * 3: Three red, green, blue color channels (RGB). + * 4: Three color channels and an alpha channel (RGBA). + * + * The components are encoded in one of two ways: + * + * a) As a small integer, value 0..255, contained in a single byte. For the + * alpha channel the original value is simply value/255. For the color or + * luminance channels the value is encoded according to the sRGB specification + * and matches the 8-bit format expected by typical display devices. + * + * The color/gray channels are not scaled (pre-multiplied) by the alpha + * channel and are suitable for passing to color management software. + * + * b) As a value in the range 0..65535, contained in a 2-byte integer. All + * channels can be converted to the original value by dividing by 65535; all + * channels are linear. Color channels use the RGB encoding (RGB end-points) of + * the sRGB specification. This encoding is identified by the + * PNG_FORMAT_FLAG_LINEAR flag below. + * + * When the simplified API needs to convert between sRGB and linear colorspaces, + * the actual sRGB transfer curve defined in the sRGB specification (see the + * article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2 + * approximation used elsewhere in libpng. + * + * When an alpha channel is present it is expected to denote pixel coverage + * of the color or luminance channels and is returned as an associated alpha + * channel: the color/gray channels are scaled (pre-multiplied) by the alpha + * value. + * + * The samples are either contained directly in the image data, between 1 and 8 + * bytes per pixel according to the encoding, or are held in a color-map indexed + * by bytes in the image data. In the case of a color-map the color-map entries + * are individual samples, encoded as above, and the image data has one byte per + * pixel to select the relevant sample from the color-map. + */ + +/* PNG_FORMAT_* + * + * #defines to be used in png_image::format. Each #define identifies a + * particular layout of sample data and, if present, alpha values. There are + * separate defines for each of the two component encodings. + * + * A format is built up using single bit flag values. All combinations are + * valid. Formats can be built up from the flag values or you can use one of + * the predefined values below. When testing formats always use the FORMAT_FLAG + * macros to test for individual features - future versions of the library may + * add new flags. + * + * When reading or writing color-mapped images the format should be set to the + * format of the entries in the color-map then png_image_{read,write}_colormap + * called to read or write the color-map and set the format correctly for the + * image data. Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly! + * + * NOTE: libpng can be built with particular features disabled. If you see + * compiler errors because the definition of one of the following flags has been + * compiled out it is because libpng does not have the required support. It is + * possible, however, for the libpng configuration to enable the format on just + * read or just write; in that case you may see an error at run time. You can + * guard against this by checking for the definition of the appropriate + * "_SUPPORTED" macro, one of: + * + * PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED + */ +#define PNG_FORMAT_FLAG_ALPHA 0x01U /* format with an alpha channel */ +#define PNG_FORMAT_FLAG_COLOR 0x02U /* color format: otherwise grayscale */ +#define PNG_FORMAT_FLAG_LINEAR 0x04U /* 2-byte channels else 1-byte */ +#define PNG_FORMAT_FLAG_COLORMAP 0x08U /* image data is color-mapped */ + +#ifdef PNG_FORMAT_BGR_SUPPORTED +# define PNG_FORMAT_FLAG_BGR 0x10U /* BGR colors, else order is RGB */ +#endif + +#ifdef PNG_FORMAT_AFIRST_SUPPORTED +# define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */ +#endif + +/* Commonly used formats have predefined macros. + * + * First the single byte (sRGB) formats: + */ +#define PNG_FORMAT_GRAY 0 +#define PNG_FORMAT_GA PNG_FORMAT_FLAG_ALPHA +#define PNG_FORMAT_AG (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST) +#define PNG_FORMAT_RGB PNG_FORMAT_FLAG_COLOR +#define PNG_FORMAT_BGR (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR) +#define PNG_FORMAT_RGBA (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA) +#define PNG_FORMAT_ARGB (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST) +#define PNG_FORMAT_BGRA (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA) +#define PNG_FORMAT_ABGR (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST) + +/* Then the linear 2-byte formats. When naming these "Y" is used to + * indicate a luminance (gray) channel. + */ +#define PNG_FORMAT_LINEAR_Y PNG_FORMAT_FLAG_LINEAR +#define PNG_FORMAT_LINEAR_Y_ALPHA (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA) +#define PNG_FORMAT_LINEAR_RGB (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR) +#define PNG_FORMAT_LINEAR_RGB_ALPHA \ + (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA) + +/* With color-mapped formats the image data is one byte for each pixel, the byte + * is an index into the color-map which is formatted as above. To obtain a + * color-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP + * to one of the above definitions, or you can use one of the definitions below. + */ +#define PNG_FORMAT_RGB_COLORMAP (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_BGR_COLORMAP (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_RGBA_COLORMAP (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_ARGB_COLORMAP (PNG_FORMAT_ARGB|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_BGRA_COLORMAP (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_COLORMAP) +#define PNG_FORMAT_ABGR_COLORMAP (PNG_FORMAT_ABGR|PNG_FORMAT_FLAG_COLORMAP) + +/* PNG_IMAGE macros + * + * These are convenience macros to derive information from a png_image + * structure. The PNG_IMAGE_SAMPLE_ macros return values appropriate to the + * actual image sample values - either the entries in the color-map or the + * pixels in the image. The PNG_IMAGE_PIXEL_ macros return corresponding values + * for the pixels and will always return 1 for color-mapped formats. The + * remaining macros return information about the rows in the image and the + * complete image. + * + * NOTE: All the macros that take a png_image::format parameter are compile time + * constants if the format parameter is, itself, a constant. Therefore these + * macros can be used in array declarations and case labels where required. + * Similarly the macros are also pre-processor constants (sizeof is not used) so + * they can be used in #if tests. + * + * First the information about the samples. + */ +#define PNG_IMAGE_SAMPLE_CHANNELS(fmt)\ + (((fmt)&(PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA))+1) + /* Return the total number of channels in a given format: 1..4 */ + +#define PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\ + ((((fmt) & PNG_FORMAT_FLAG_LINEAR) >> 2)+1) + /* Return the size in bytes of a single component of a pixel or color-map + * entry (as appropriate) in the image: 1 or 2. + */ + +#define PNG_IMAGE_SAMPLE_SIZE(fmt)\ + (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)) + /* This is the size of the sample data for one sample. If the image is + * color-mapped it is the size of one color-map entry (and image pixels are + * one byte in size), otherwise it is the size of one image pixel. + */ + +#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\ + (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256) + /* The maximum size of the color-map required by the format expressed in a + * count of components. This can be used to compile-time allocate a + * color-map: + * + * png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)]; + * + * png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)]; + * + * Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the + * information from one of the png_image_begin_read_ APIs and dynamically + * allocate the required memory. + */ + +/* Corresponding information about the pixels */ +#define PNG_IMAGE_PIXEL_(test,fmt)\ + (((fmt)&PNG_FORMAT_FLAG_COLORMAP)?1:test(fmt)) + +#define PNG_IMAGE_PIXEL_CHANNELS(fmt)\ + PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_CHANNELS,fmt) + /* The number of separate channels (components) in a pixel; 1 for a + * color-mapped image. + */ + +#define PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\ + PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_COMPONENT_SIZE,fmt) + /* The size, in bytes, of each component in a pixel; 1 for a color-mapped + * image. + */ + +#define PNG_IMAGE_PIXEL_SIZE(fmt) PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_SIZE,fmt) + /* The size, in bytes, of a complete pixel; 1 for a color-mapped image. */ + +/* Information about the whole row, or whole image */ +#define PNG_IMAGE_ROW_STRIDE(image)\ + (PNG_IMAGE_PIXEL_CHANNELS((image).format) * (image).width) + /* Return the total number of components in a single row of the image; this + * is the minimum 'row stride', the minimum count of components between each + * row. For a color-mapped image this is the minimum number of bytes in a + * row. + */ + +#define PNG_IMAGE_BUFFER_SIZE(image, row_stride)\ + (PNG_IMAGE_PIXEL_COMPONENT_SIZE((image).format)*(image).height*(row_stride)) + /* Return the size, in bytes, of an image buffer given a png_image and a row + * stride - the number of components to leave space for in each row. + */ + +#define PNG_IMAGE_SIZE(image)\ + PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image)) + /* Return the size, in bytes, of the image in memory given just a png_image; + * the row stride is the minimum stride required for the image. + */ + +#define PNG_IMAGE_COLORMAP_SIZE(image)\ + (PNG_IMAGE_SAMPLE_SIZE((image).format) * (image).colormap_entries) + /* Return the size, in bytes, of the color-map of this image. If the image + * format is not a color-map format this will return a size sufficient for + * 256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if + * you don't want to allocate a color-map in this case. + */ + +/* PNG_IMAGE_FLAG_* + * + * Flags containing additional information about the image are held in the + * 'flags' field of png_image. + */ +#define PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB 0x01 + /* This indicates the the RGB values of the in-memory bitmap do not + * correspond to the red, green and blue end-points defined by sRGB. + */ + +#define PNG_IMAGE_FLAG_FAST 0x02 + /* On write emphasise speed over compression; the resultant PNG file will be + * larger but will be produced significantly faster, particular for large + * images. Do not use this option for images which will be distributed, only + * used it when producing intermediate files that will be read back in + * repeatedly. For a typical 24-bit image the option will double the read + * speed at the cost of increasing the image size by 25%, however for many + * more compressible images the PNG file can be 10 times larger with only a + * slight speed gain. + */ + +#define PNG_IMAGE_FLAG_16BIT_sRGB 0x04 + /* On read if the image is a 16-bit per component image and there is no gAMA + * or sRGB chunk assume that the components are sRGB encoded. Notice that + * images output by the simplified API always have gamma information; setting + * this flag only affects the interpretation of 16-bit images from an + * external source. It is recommended that the application expose this flag + * to the user; the user can normally easily recognize the difference between + * linear and sRGB encoding. This flag has no effect on write - the data + * passed to the write APIs must have the correct encoding (as defined + * above.) + * + * If the flag is not set (the default) input 16-bit per component data is + * assumed to be linear. + * + * NOTE: the flag can only be set after the png_image_begin_read_ call, + * because that call initializes the 'flags' field. + */ + +#ifdef PNG_SIMPLIFIED_READ_SUPPORTED +/* READ APIs + * --------- + * + * The png_image passed to the read APIs must have been initialized by setting + * the png_controlp field 'opaque' to NULL (or, safer, memset the whole thing.) + */ +#ifdef PNG_STDIO_SUPPORTED +PNG_EXPORT(234, int, png_image_begin_read_from_file, (png_imagep image, + const char *file_name)); + /* The named file is opened for read and the image header is filled in + * from the PNG header in the file. + */ + +PNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image, + FILE* file)); + /* The PNG header is read from the stdio FILE object. */ +#endif /* STDIO */ + +PNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image, + png_const_voidp memory, png_size_t size)); + /* The PNG header is read from the given memory buffer. */ + +PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image, + png_const_colorp background, void *buffer, png_int_32 row_stride, + void *colormap)); + /* Finish reading the image into the supplied buffer and clean up the + * png_image structure. + * + * row_stride is the step, in byte or 2-byte units as appropriate, + * between adjacent rows. A positive stride indicates that the top-most row + * is first in the buffer - the normal top-down arrangement. A negative + * stride indicates that the bottom-most row is first in the buffer. + * + * background need only be supplied if an alpha channel must be removed from + * a png_byte format and the removal is to be done by compositing on a solid + * color; otherwise it may be NULL and any composition will be done directly + * onto the buffer. The value is an sRGB color to use for the background, + * for grayscale output the green channel is used. + * + * background must be supplied when an alpha channel must be removed from a + * single byte color-mapped output format, in other words if: + * + * 1) The original format from png_image_begin_read_from_* had + * PNG_FORMAT_FLAG_ALPHA set. + * 2) The format set by the application does not. + * 3) The format set by the application has PNG_FORMAT_FLAG_COLORMAP set and + * PNG_FORMAT_FLAG_LINEAR *not* set. + * + * For linear output removing the alpha channel is always done by compositing + * on black and background is ignored. + * + * colormap must be supplied when PNG_FORMAT_FLAG_COLORMAP is set. It must + * be at least the size (in bytes) returned by PNG_IMAGE_COLORMAP_SIZE. + * image->colormap_entries will be updated to the actual number of entries + * written to the colormap; this may be less than the original value. + */ + +PNG_EXPORT(238, void, png_image_free, (png_imagep image)); + /* Free any data allocated by libpng in image->opaque, setting the pointer to + * NULL. May be called at any time after the structure is initialized. + */ +#endif /* SIMPLIFIED_READ */ + +#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED +#ifdef PNG_STDIO_SUPPORTED +/* WRITE APIS + * ---------- + * For write you must initialize a png_image structure to describe the image to + * be written. To do this use memset to set the whole structure to 0 then + * initialize fields describing your image. + * + * version: must be set to PNG_IMAGE_VERSION + * opaque: must be initialized to NULL + * width: image width in pixels + * height: image height in rows + * format: the format of the data (image and color-map) you wish to write + * flags: set to 0 unless one of the defined flags applies; set + * PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images where the RGB + * values do not correspond to the colors in sRGB. + * colormap_entries: set to the number of entries in the color-map (0 to 256) + */ +PNG_EXPORT(239, int, png_image_write_to_file, (png_imagep image, + const char *file, int convert_to_8bit, const void *buffer, + png_int_32 row_stride, const void *colormap)); + /* Write the image to the named file. */ + +PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file, + int convert_to_8_bit, const void *buffer, png_int_32 row_stride, + const void *colormap)); + /* Write the image to the given (FILE*). */ + +/* With both write APIs if image is in one of the linear formats with 16-bit + * data then setting convert_to_8_bit will cause the output to be an 8-bit PNG + * gamma encoded according to the sRGB specification, otherwise a 16-bit linear + * encoded PNG file is written. + * + * With color-mapped data formats the colormap parameter point to a color-map + * with at least image->colormap_entries encoded in the specified format. If + * the format is linear the written PNG color-map will be converted to sRGB + * regardless of the convert_to_8_bit flag. + * + * With all APIs row_stride is handled as in the read APIs - it is the spacing + * from one row to the next in component sized units (1 or 2 bytes) and if + * negative indicates a bottom-up row layout in the buffer. If row_stride is zero, + * libpng will calculate it for you from the image width and number of channels. + * + * Note that the write API does not support interlacing, sub-8-bit pixels, indexed + * PNG (color_type 3) or most ancillary chunks. + */ +#endif /* STDIO */ +#endif /* SIMPLIFIED_WRITE */ +/******************************************************************************* + * END OF SIMPLIFIED API + ******************************************************************************/ +#endif /* SIMPLIFIED_{READ|WRITE} */ + +/******************************************************************************* + * Section 6: IMPLEMENTATION OPTIONS + ******************************************************************************* + * + * Support for arbitrary implementation-specific optimizations. The API allows + * particular options to be turned on or off. 'Option' is the number of the + * option and 'onoff' is 0 (off) or non-0 (on). The value returned is given + * by the PNG_OPTION_ defines below. + * + * HARDWARE: normally hardware capabilites, such as the Intel SSE instructions, + * are detected at run time, however sometimes it may be impossible + * to do this in user mode, in which case it is necessary to discover + * the capabilities in an OS specific way. Such capabilities are + * listed here when libpng has support for them and must be turned + * ON by the application if present. + * + * SOFTWARE: sometimes software optimizations actually result in performance + * decrease on some architectures or systems, or with some sets of + * PNG images. 'Software' options allow such optimizations to be + * selected at run time. + */ +#ifdef PNG_SET_OPTION_SUPPORTED +#ifdef PNG_ARM_NEON_API_SUPPORTED +# define PNG_ARM_NEON 0 /* HARDWARE: ARM Neon SIMD instructions supported */ +#endif +#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */ +#define PNG_SKIP_sRGB_CHECK_PROFILE 4 /* SOFTWARE: Check ICC profile for sRGB */ +#define PNG_OPTION_NEXT 6 /* Next option - numbers must be even */ + +/* Return values: NOTE: there are four values and 'off' is *not* zero */ +#define PNG_OPTION_UNSET 0 /* Unset - defaults to off */ +#define PNG_OPTION_INVALID 1 /* Option number out of range */ +#define PNG_OPTION_OFF 2 +#define PNG_OPTION_ON 3 + +PNG_EXPORT(244, int, png_set_option, (png_structrp png_ptr, int option, + int onoff)); +#endif /* SET_OPTION */ + +/******************************************************************************* + * END OF HARDWARE AND SOFTWARE OPTIONS + ******************************************************************************/ + +/* Maintainer: Put new public prototypes here ^, in libpng.3, in project + * defs, and in scripts/symbols.def. + */ + +/* The last ordinal number (this is the *last* one already used; the next + * one to use is one more than this.) + */ +#ifdef PNG_EXPORT_LAST_ORDINAL + PNG_EXPORT_LAST_ORDINAL(244); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PNG_VERSION_INFO_ONLY */ +/* Do not put anything past this line */ +#endif /* PNG_H */ diff --git a/android/x86/include/png/pngconf.h b/android/x86/include/png/pngconf.h new file mode 100644 index 00000000..93446545 --- /dev/null +++ b/android/x86/include/png/pngconf.h @@ -0,0 +1,622 @@ + +/* pngconf.h - machine configurable file for libpng + * + * libpng version 1.6.21, January 15, 2016 + * + * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * Any machine specific code is near the front of this file, so if you + * are configuring libpng for a machine, you may want to read the section + * starting here down to where it starts to typedef png_color, png_text, + * and png_info. + */ + +#ifndef PNGCONF_H +#define PNGCONF_H + +#ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */ + +/* From libpng 1.6.0 libpng requires an ANSI X3.159-1989 ("ISOC90") compliant C + * compiler for correct compilation. The following header files are required by + * the standard. If your compiler doesn't provide these header files, or they + * do not match the standard, you will need to provide/improve them. + */ +#include <limits.h> +#include <stddef.h> + +/* Library header files. These header files are all defined by ISOC90; libpng + * expects conformant implementations, however, an ISOC90 conformant system need + * not provide these header files if the functionality cannot be implemented. + * In this case it will be necessary to disable the relevant parts of libpng in + * the build of pnglibconf.h. + * + * Prior to 1.6.0 string.h was included here; the API changes in 1.6.0 to not + * include this unnecessary header file. + */ + +#ifdef PNG_STDIO_SUPPORTED + /* Required for the definition of FILE: */ +# include <stdio.h> +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* Required for the definition of jmp_buf and the declaration of longjmp: */ +# include <setjmp.h> +#endif + +#ifdef PNG_CONVERT_tIME_SUPPORTED + /* Required for struct tm: */ +# include <time.h> +#endif + +#endif /* PNG_BUILDING_SYMBOL_TABLE */ + +/* Prior to 1.6.0 it was possible to turn off 'const' in declarations using + * PNG_NO_CONST; this is no longer supported except for data declarations which + * apparently still cause problems in 2011 on some compilers. + */ +#define PNG_CONST const /* backward compatibility only */ + +/* This controls optimization of the reading of 16-bit and 32-bit values + * from PNG files. It can be set on a per-app-file basis - it + * just changes whether a macro is used when the function is called. + * The library builder sets the default; if read functions are not + * built into the library the macro implementation is forced on. + */ +#ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED +# define PNG_USE_READ_MACROS +#endif +#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS) +# if PNG_DEFAULT_READ_MACROS +# define PNG_USE_READ_MACROS +# endif +#endif + +/* COMPILER SPECIFIC OPTIONS. + * + * These options are provided so that a variety of difficult compilers + * can be used. Some are fixed at build time (e.g. PNG_API_RULE + * below) but still have compiler specific implementations, others + * may be changed on a per-file basis when compiling against libpng. + */ + +/* The PNGARG macro was used in versions of libpng prior to 1.6.0 to protect + * against legacy (pre ISOC90) compilers that did not understand function + * prototypes. It is not required for modern C compilers. + */ +#ifndef PNGARG +# define PNGARG(arglist) arglist +#endif + +/* Function calling conventions. + * ============================= + * Normally it is not necessary to specify to the compiler how to call + * a function - it just does it - however on x86 systems derived from + * Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems + * and some others) there are multiple ways to call a function and the + * default can be changed on the compiler command line. For this reason + * libpng specifies the calling convention of every exported function and + * every function called via a user supplied function pointer. This is + * done in this file by defining the following macros: + * + * PNGAPI Calling convention for exported functions. + * PNGCBAPI Calling convention for user provided (callback) functions. + * PNGCAPI Calling convention used by the ANSI-C library (required + * for longjmp callbacks and sometimes used internally to + * specify the calling convention for zlib). + * + * These macros should never be overridden. If it is necessary to + * change calling convention in a private build this can be done + * by setting PNG_API_RULE (which defaults to 0) to one of the values + * below to select the correct 'API' variants. + * + * PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout. + * This is correct in every known environment. + * PNG_API_RULE=1 Use the operating system convention for PNGAPI and + * the 'C' calling convention (from PNGCAPI) for + * callbacks (PNGCBAPI). This is no longer required + * in any known environment - if it has to be used + * please post an explanation of the problem to the + * libpng mailing list. + * + * These cases only differ if the operating system does not use the C + * calling convention, at present this just means the above cases + * (x86 DOS/Windows sytems) and, even then, this does not apply to + * Cygwin running on those systems. + * + * Note that the value must be defined in pnglibconf.h so that what + * the application uses to call the library matches the conventions + * set when building the library. + */ + +/* Symbol export + * ============= + * When building a shared library it is almost always necessary to tell + * the compiler which symbols to export. The png.h macro 'PNG_EXPORT' + * is used to mark the symbols. On some systems these symbols can be + * extracted at link time and need no special processing by the compiler, + * on other systems the symbols are flagged by the compiler and just + * the declaration requires a special tag applied (unfortunately) in a + * compiler dependent way. Some systems can do either. + * + * A small number of older systems also require a symbol from a DLL to + * be flagged to the program that calls it. This is a problem because + * we do not know in the header file included by application code that + * the symbol will come from a shared library, as opposed to a statically + * linked one. For this reason the application must tell us by setting + * the magic flag PNG_USE_DLL to turn on the special processing before + * it includes png.h. + * + * Four additional macros are used to make this happen: + * + * PNG_IMPEXP The magic (if any) to cause a symbol to be exported from + * the build or imported if PNG_USE_DLL is set - compiler + * and system specific. + * + * PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to + * 'type', compiler specific. + * + * PNG_DLL_EXPORT Set to the magic to use during a libpng build to + * make a symbol exported from the DLL. Not used in the + * public header files; see pngpriv.h for how it is used + * in the libpng build. + * + * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come + * from a DLL - used to define PNG_IMPEXP when + * PNG_USE_DLL is set. + */ + +/* System specific discovery. + * ========================== + * This code is used at build time to find PNG_IMPEXP, the API settings + * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL + * import processing is possible. On Windows systems it also sets + * compiler-specific macros to the values required to change the calling + * conventions of the various functions. + */ +#if defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\ + defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) + /* Windows system (DOS doesn't support DLLs). Includes builds under Cygwin or + * MinGW on any architecture currently supported by Windows. Also includes + * Watcom builds but these need special treatment because they are not + * compatible with GCC or Visual C because of different calling conventions. + */ +# if PNG_API_RULE == 2 + /* If this line results in an error, either because __watcall is not + * understood or because of a redefine just below you cannot use *this* + * build of the library with the compiler you are using. *This* build was + * build using Watcom and applications must also be built using Watcom! + */ +# define PNGCAPI __watcall +# endif + +# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800)) +# define PNGCAPI __cdecl +# if PNG_API_RULE == 1 + /* If this line results in an error __stdcall is not understood and + * PNG_API_RULE should not have been set to '1'. + */ +# define PNGAPI __stdcall +# endif +# else + /* An older compiler, or one not detected (erroneously) above, + * if necessary override on the command line to get the correct + * variants for the compiler. + */ +# ifndef PNGCAPI +# define PNGCAPI _cdecl +# endif +# if PNG_API_RULE == 1 && !defined(PNGAPI) +# define PNGAPI _stdcall +# endif +# endif /* compiler/api */ + + /* NOTE: PNGCBAPI always defaults to PNGCAPI. */ + +# if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD) +# error "PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed" +# endif + +# if (defined(_MSC_VER) && _MSC_VER < 800) ||\ + (defined(__BORLANDC__) && __BORLANDC__ < 0x500) + /* older Borland and MSC + * compilers used '__export' and required this to be after + * the type. + */ +# ifndef PNG_EXPORT_TYPE +# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP +# endif +# define PNG_DLL_EXPORT __export +# else /* newer compiler */ +# define PNG_DLL_EXPORT __declspec(dllexport) +# ifndef PNG_DLL_IMPORT +# define PNG_DLL_IMPORT __declspec(dllimport) +# endif +# endif /* compiler */ + +#else /* !Windows */ +# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) +# define PNGAPI _System +# else /* !Windows/x86 && !OS/2 */ + /* Use the defaults, or define PNG*API on the command line (but + * this will have to be done for every compile!) + */ +# endif /* other system, !OS/2 */ +#endif /* !Windows/x86 */ + +/* Now do all the defaulting . */ +#ifndef PNGCAPI +# define PNGCAPI +#endif +#ifndef PNGCBAPI +# define PNGCBAPI PNGCAPI +#endif +#ifndef PNGAPI +# define PNGAPI PNGCAPI +#endif + +/* PNG_IMPEXP may be set on the compilation system command line or (if not set) + * then in an internal header file when building the library, otherwise (when + * using the library) it is set here. + */ +#ifndef PNG_IMPEXP +# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT) + /* This forces use of a DLL, disallowing static linking */ +# define PNG_IMPEXP PNG_DLL_IMPORT +# endif + +# ifndef PNG_IMPEXP +# define PNG_IMPEXP +# endif +#endif + +/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat + * 'attributes' as a storage class - the attributes go at the start of the + * function definition, and attributes are always appended regardless of the + * compiler. This considerably simplifies these macros but may cause problems + * if any compilers both need function attributes and fail to handle them as + * a storage class (this is unlikely.) + */ +#ifndef PNG_FUNCTION +# define PNG_FUNCTION(type, name, args, attributes) attributes type name args +#endif + +#ifndef PNG_EXPORT_TYPE +# define PNG_EXPORT_TYPE(type) PNG_IMPEXP type +#endif + + /* The ordinal value is only relevant when preprocessing png.h for symbol + * table entries, so we discard it here. See the .dfn files in the + * scripts directory. + */ + +#ifndef PNG_EXPORTA +# define PNG_EXPORTA(ordinal, type, name, args, attributes) \ + PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), PNGARG(args), \ + PNG_LINKAGE_API attributes) +#endif + +/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument, + * so make something non-empty to satisfy the requirement: + */ +#define PNG_EMPTY /*empty list*/ + +#define PNG_EXPORT(ordinal, type, name, args) \ + PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY) + +/* Use PNG_REMOVED to comment out a removed interface. */ +#ifndef PNG_REMOVED +# define PNG_REMOVED(ordinal, type, name, args, attributes) +#endif + +#ifndef PNG_CALLBACK +# define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args) +#endif + +/* Support for compiler specific function attributes. These are used + * so that where compiler support is available incorrect use of API + * functions in png.h will generate compiler warnings. + * + * Added at libpng-1.2.41. + */ + +#ifndef PNG_NO_PEDANTIC_WARNINGS +# ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED +# define PNG_PEDANTIC_WARNINGS_SUPPORTED +# endif +#endif + +#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED + /* Support for compiler specific function attributes. These are used + * so that where compiler support is available, incorrect use of API + * functions in png.h will generate compiler warnings. Added at libpng + * version 1.2.41. Disabling these removes the warnings but may also produce + * less efficient code. + */ +# if defined(__clang__) && defined(__has_attribute) + /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */ +# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__) +# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) +# endif +# if !defined(PNG_NORETURN) && __has_attribute(__noreturn__) +# define PNG_NORETURN __attribute__((__noreturn__)) +# endif +# if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__) +# define PNG_ALLOCATED __attribute__((__malloc__)) +# endif +# if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__) +# define PNG_DEPRECATED __attribute__((__deprecated__)) +# endif +# if !defined(PNG_PRIVATE) +# ifdef __has_extension +# if __has_extension(attribute_unavailable_with_message) +# define PNG_PRIVATE __attribute__((__unavailable__(\ + "This function is not exported by libpng."))) +# endif +# endif +# endif +# ifndef PNG_RESTRICT +# define PNG_RESTRICT __restrict +# endif + +# elif defined(__GNUC__) +# ifndef PNG_USE_RESULT +# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) +# endif +# ifndef PNG_NORETURN +# define PNG_NORETURN __attribute__((__noreturn__)) +# endif +# if __GNUC__ >= 3 +# ifndef PNG_ALLOCATED +# define PNG_ALLOCATED __attribute__((__malloc__)) +# endif +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __attribute__((__deprecated__)) +# endif +# ifndef PNG_PRIVATE +# if 0 /* Doesn't work so we use deprecated instead*/ +# define PNG_PRIVATE \ + __attribute__((warning("This function is not exported by libpng."))) +# else +# define PNG_PRIVATE \ + __attribute__((__deprecated__)) +# endif +# endif +# if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1)) +# ifndef PNG_RESTRICT +# define PNG_RESTRICT __restrict +# endif +# endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */ +# endif /* __GNUC__ >= 3 */ + +# elif defined(_MSC_VER) && (_MSC_VER >= 1300) +# ifndef PNG_USE_RESULT +# define PNG_USE_RESULT /* not supported */ +# endif +# ifndef PNG_NORETURN +# define PNG_NORETURN __declspec(noreturn) +# endif +# ifndef PNG_ALLOCATED +# if (_MSC_VER >= 1400) +# define PNG_ALLOCATED __declspec(restrict) +# endif +# endif +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __declspec(deprecated) +# endif +# ifndef PNG_PRIVATE +# define PNG_PRIVATE __declspec(deprecated) +# endif +# ifndef PNG_RESTRICT +# if (_MSC_VER >= 1400) +# define PNG_RESTRICT __restrict +# endif +# endif + +# elif defined(__WATCOMC__) +# ifndef PNG_RESTRICT +# define PNG_RESTRICT __restrict +# endif +# endif +#endif /* PNG_PEDANTIC_WARNINGS */ + +#ifndef PNG_DEPRECATED +# define PNG_DEPRECATED /* Use of this function is deprecated */ +#endif +#ifndef PNG_USE_RESULT +# define PNG_USE_RESULT /* The result of this function must be checked */ +#endif +#ifndef PNG_NORETURN +# define PNG_NORETURN /* This function does not return */ +#endif +#ifndef PNG_ALLOCATED +# define PNG_ALLOCATED /* The result of the function is new memory */ +#endif +#ifndef PNG_PRIVATE +# define PNG_PRIVATE /* This is a private libpng function */ +#endif +#ifndef PNG_RESTRICT +# define PNG_RESTRICT /* The C99 "restrict" feature */ +#endif + +#ifndef PNG_FP_EXPORT /* A floating point API. */ +# ifdef PNG_FLOATING_POINT_SUPPORTED +# define PNG_FP_EXPORT(ordinal, type, name, args)\ + PNG_EXPORT(ordinal, type, name, args); +# else /* No floating point APIs */ +# define PNG_FP_EXPORT(ordinal, type, name, args) +# endif +#endif +#ifndef PNG_FIXED_EXPORT /* A fixed point API. */ +# ifdef PNG_FIXED_POINT_SUPPORTED +# define PNG_FIXED_EXPORT(ordinal, type, name, args)\ + PNG_EXPORT(ordinal, type, name, args); +# else /* No fixed point APIs */ +# define PNG_FIXED_EXPORT(ordinal, type, name, args) +# endif +#endif + +#ifndef PNG_BUILDING_SYMBOL_TABLE +/* Some typedefs to get us started. These should be safe on most of the common + * platforms. + * + * png_uint_32 and png_int_32 may, currently, be larger than required to hold a + * 32-bit value however this is not normally advisable. + * + * png_uint_16 and png_int_16 should always be two bytes in size - this is + * verified at library build time. + * + * png_byte must always be one byte in size. + * + * The checks below use constants from limits.h, as defined by the ISOC90 + * standard. + */ +#if CHAR_BIT == 8 && UCHAR_MAX == 255 + typedef unsigned char png_byte; +#else +# error "libpng requires 8-bit bytes" +#endif + +#if INT_MIN == -32768 && INT_MAX == 32767 + typedef int png_int_16; +#elif SHRT_MIN == -32768 && SHRT_MAX == 32767 + typedef short png_int_16; +#else +# error "libpng requires a signed 16-bit type" +#endif + +#if UINT_MAX == 65535 + typedef unsigned int png_uint_16; +#elif USHRT_MAX == 65535 + typedef unsigned short png_uint_16; +#else +# error "libpng requires an unsigned 16-bit type" +#endif + +#if INT_MIN < -2147483646 && INT_MAX > 2147483646 + typedef int png_int_32; +#elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646 + typedef long int png_int_32; +#else +# error "libpng requires a signed 32-bit (or more) type" +#endif + +#if UINT_MAX > 4294967294 + typedef unsigned int png_uint_32; +#elif ULONG_MAX > 4294967294 + typedef unsigned long int png_uint_32; +#else +# error "libpng requires an unsigned 32-bit (or more) type" +#endif + +/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however, + * requires an ISOC90 compiler and relies on consistent behavior of sizeof. + */ +typedef size_t png_size_t; +typedef ptrdiff_t png_ptrdiff_t; + +/* libpng needs to know the maximum value of 'size_t' and this controls the + * definition of png_alloc_size_t, below. This maximum value of size_t limits + * but does not control the maximum allocations the library makes - there is + * direct application control of this through png_set_user_limits(). + */ +#ifndef PNG_SMALL_SIZE_T + /* Compiler specific tests for systems where size_t is known to be less than + * 32 bits (some of these systems may no longer work because of the lack of + * 'far' support; see above.) + */ +# if (defined(__TURBOC__) && !defined(__FLAT__)) ||\ + (defined(_MSC_VER) && defined(MAXSEG_64K)) +# define PNG_SMALL_SIZE_T +# endif +#endif + +/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, and no + * smaller than png_uint_32. Casts from png_size_t or png_uint_32 to + * png_alloc_size_t are not necessary; in fact, it is recommended not to use + * them at all so that the compiler can complain when something turns out to be + * problematic. + * + * Casts in the other direction (from png_alloc_size_t to png_size_t or + * png_uint_32) should be explicitly applied; however, we do not expect to + * encounter practical situations that require such conversions. + * + * PNG_SMALL_SIZE_T must be defined if the maximum value of size_t is less than + * 4294967295 - i.e. less than the maximum value of png_uint_32. + */ +#ifdef PNG_SMALL_SIZE_T + typedef png_uint_32 png_alloc_size_t; +#else + typedef png_size_t png_alloc_size_t; +#endif + +/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler + * implementations of Intel CPU specific support of user-mode segmented address + * spaces, where 16-bit pointers address more than 65536 bytes of memory using + * separate 'segment' registers. The implementation requires two different + * types of pointer (only one of which includes the segment value.) + * + * If required this support is available in version 1.2 of libpng and may be + * available in versions through 1.5, although the correctness of the code has + * not been verified recently. + */ + +/* Typedef for floating-point numbers that are converted to fixed-point with a + * multiple of 100,000, e.g., gamma + */ +typedef png_int_32 png_fixed_point; + +/* Add typedefs for pointers */ +typedef void * png_voidp; +typedef const void * png_const_voidp; +typedef png_byte * png_bytep; +typedef const png_byte * png_const_bytep; +typedef png_uint_32 * png_uint_32p; +typedef const png_uint_32 * png_const_uint_32p; +typedef png_int_32 * png_int_32p; +typedef const png_int_32 * png_const_int_32p; +typedef png_uint_16 * png_uint_16p; +typedef const png_uint_16 * png_const_uint_16p; +typedef png_int_16 * png_int_16p; +typedef const png_int_16 * png_const_int_16p; +typedef char * png_charp; +typedef const char * png_const_charp; +typedef png_fixed_point * png_fixed_point_p; +typedef const png_fixed_point * png_const_fixed_point_p; +typedef png_size_t * png_size_tp; +typedef const png_size_t * png_const_size_tp; + +#ifdef PNG_STDIO_SUPPORTED +typedef FILE * png_FILE_p; +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double * png_doublep; +typedef const double * png_const_doublep; +#endif + +/* Pointers to pointers; i.e. arrays */ +typedef png_byte * * png_bytepp; +typedef png_uint_32 * * png_uint_32pp; +typedef png_int_32 * * png_int_32pp; +typedef png_uint_16 * * png_uint_16pp; +typedef png_int_16 * * png_int_16pp; +typedef const char * * png_const_charpp; +typedef char * * png_charpp; +typedef png_fixed_point * * png_fixed_point_pp; +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double * * png_doublepp; +#endif + +/* Pointers to pointers to pointers; i.e., pointer to array */ +typedef char * * * png_charppp; + +#endif /* PNG_BUILDING_SYMBOL_TABLE */ + +#endif /* PNGCONF_H */ diff --git a/android/x86/include/png/pnglibconf.h b/android/x86/include/png/pnglibconf.h new file mode 100644 index 00000000..c0005678 --- /dev/null +++ b/android/x86/include/png/pnglibconf.h @@ -0,0 +1,212 @@ +/* pnglibconf.h - library build configuration */ + +/* libpng version 1.6.21, January 15, 2016 */ + +/* Copyright (c) 1998-2016 Glenn Randers-Pehrson */ + +/* This code is released under the libpng license. */ +/* For conditions of distribution and use, see the disclaimer */ +/* and license in png.h */ + +/* pnglibconf.h */ +/* Machine generated file: DO NOT EDIT */ +/* Derived from: scripts/pnglibconf.dfa */ +#ifndef PNGLCONF_H +#define PNGLCONF_H +/* options */ +#define PNG_16BIT_SUPPORTED +#define PNG_ALIGNED_MEMORY_SUPPORTED +/*#undef PNG_ARM_NEON_API_SUPPORTED*/ +/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/ +#define PNG_BENIGN_ERRORS_SUPPORTED +#define PNG_BENIGN_READ_ERRORS_SUPPORTED +/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/ +#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_COLORSPACE_SUPPORTED +#define PNG_CONSOLE_IO_SUPPORTED +#define PNG_CONVERT_tIME_SUPPORTED +#define PNG_EASY_ACCESS_SUPPORTED +/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/ +#define PNG_ERROR_TEXT_SUPPORTED +#define PNG_FIXED_POINT_SUPPORTED +#define PNG_FLOATING_ARITHMETIC_SUPPORTED +#define PNG_FLOATING_POINT_SUPPORTED +#define PNG_FORMAT_AFIRST_SUPPORTED +#define PNG_FORMAT_BGR_SUPPORTED +#define PNG_GAMMA_SUPPORTED +#define PNG_GET_PALETTE_MAX_SUPPORTED +#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +#define PNG_INCH_CONVERSIONS_SUPPORTED +#define PNG_INFO_IMAGE_SUPPORTED +#define PNG_IO_STATE_SUPPORTED +#define PNG_MNG_FEATURES_SUPPORTED +#define PNG_POINTER_INDEXING_SUPPORTED +#define PNG_PROGRESSIVE_READ_SUPPORTED +#define PNG_READ_16BIT_SUPPORTED +#define PNG_READ_ALPHA_MODE_SUPPORTED +#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED +#define PNG_READ_BACKGROUND_SUPPORTED +#define PNG_READ_BGR_SUPPORTED +#define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_READ_COMPOSITE_NODIV_SUPPORTED +#define PNG_READ_COMPRESSED_TEXT_SUPPORTED +#define PNG_READ_EXPAND_16_SUPPORTED +#define PNG_READ_EXPAND_SUPPORTED +#define PNG_READ_FILLER_SUPPORTED +#define PNG_READ_GAMMA_SUPPORTED +#define PNG_READ_GET_PALETTE_MAX_SUPPORTED +#define PNG_READ_GRAY_TO_RGB_SUPPORTED +#define PNG_READ_INTERLACING_SUPPORTED +#define PNG_READ_INT_FUNCTIONS_SUPPORTED +#define PNG_READ_INVERT_ALPHA_SUPPORTED +#define PNG_READ_INVERT_SUPPORTED +#define PNG_READ_OPT_PLTE_SUPPORTED +#define PNG_READ_PACKSWAP_SUPPORTED +#define PNG_READ_PACK_SUPPORTED +#define PNG_READ_QUANTIZE_SUPPORTED +#define PNG_READ_RGB_TO_GRAY_SUPPORTED +#define PNG_READ_SCALE_16_TO_8_SUPPORTED +#define PNG_READ_SHIFT_SUPPORTED +#define PNG_READ_STRIP_16_TO_8_SUPPORTED +#define PNG_READ_STRIP_ALPHA_SUPPORTED +#define PNG_READ_SUPPORTED +#define PNG_READ_SWAP_ALPHA_SUPPORTED +#define PNG_READ_SWAP_SUPPORTED +#define PNG_READ_TEXT_SUPPORTED +#define PNG_READ_TRANSFORMS_SUPPORTED +#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_READ_USER_CHUNKS_SUPPORTED +#define PNG_READ_USER_TRANSFORM_SUPPORTED +#define PNG_READ_bKGD_SUPPORTED +#define PNG_READ_cHRM_SUPPORTED +#define PNG_READ_gAMA_SUPPORTED +#define PNG_READ_hIST_SUPPORTED +#define PNG_READ_iCCP_SUPPORTED +#define PNG_READ_iTXt_SUPPORTED +#define PNG_READ_oFFs_SUPPORTED +#define PNG_READ_pCAL_SUPPORTED +#define PNG_READ_pHYs_SUPPORTED +#define PNG_READ_sBIT_SUPPORTED +#define PNG_READ_sCAL_SUPPORTED +#define PNG_READ_sPLT_SUPPORTED +#define PNG_READ_sRGB_SUPPORTED +#define PNG_READ_tEXt_SUPPORTED +#define PNG_READ_tIME_SUPPORTED +#define PNG_READ_tRNS_SUPPORTED +#define PNG_READ_zTXt_SUPPORTED +#define PNG_SAVE_INT_32_SUPPORTED +#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_SEQUENTIAL_READ_SUPPORTED +#define PNG_SETJMP_SUPPORTED +#define PNG_SET_OPTION_SUPPORTED +#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_SET_USER_LIMITS_SUPPORTED +#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED +#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED +#define PNG_SIMPLIFIED_READ_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_SUPPORTED +#define PNG_STDIO_SUPPORTED +#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_TEXT_SUPPORTED +#define PNG_TIME_RFC1123_SUPPORTED +#define PNG_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_USER_CHUNKS_SUPPORTED +#define PNG_USER_LIMITS_SUPPORTED +#define PNG_USER_MEM_SUPPORTED +#define PNG_USER_TRANSFORM_INFO_SUPPORTED +#define PNG_USER_TRANSFORM_PTR_SUPPORTED +#define PNG_WARNINGS_SUPPORTED +#define PNG_WRITE_16BIT_SUPPORTED +#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED +#define PNG_WRITE_BGR_SUPPORTED +#define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED +#define PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED +#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED +#define PNG_WRITE_FILLER_SUPPORTED +#define PNG_WRITE_FILTER_SUPPORTED +#define PNG_WRITE_FLUSH_SUPPORTED +#define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED +#define PNG_WRITE_INTERLACING_SUPPORTED +#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED +#define PNG_WRITE_INVERT_ALPHA_SUPPORTED +#define PNG_WRITE_INVERT_SUPPORTED +#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED +#define PNG_WRITE_PACKSWAP_SUPPORTED +#define PNG_WRITE_PACK_SUPPORTED +#define PNG_WRITE_SHIFT_SUPPORTED +#define PNG_WRITE_SUPPORTED +#define PNG_WRITE_SWAP_ALPHA_SUPPORTED +#define PNG_WRITE_SWAP_SUPPORTED +#define PNG_WRITE_TEXT_SUPPORTED +#define PNG_WRITE_TRANSFORMS_SUPPORTED +#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_WRITE_USER_TRANSFORM_SUPPORTED +#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED +#define PNG_WRITE_bKGD_SUPPORTED +#define PNG_WRITE_cHRM_SUPPORTED +#define PNG_WRITE_gAMA_SUPPORTED +#define PNG_WRITE_hIST_SUPPORTED +#define PNG_WRITE_iCCP_SUPPORTED +#define PNG_WRITE_iTXt_SUPPORTED +#define PNG_WRITE_oFFs_SUPPORTED +#define PNG_WRITE_pCAL_SUPPORTED +#define PNG_WRITE_pHYs_SUPPORTED +#define PNG_WRITE_sBIT_SUPPORTED +#define PNG_WRITE_sCAL_SUPPORTED +#define PNG_WRITE_sPLT_SUPPORTED +#define PNG_WRITE_sRGB_SUPPORTED +#define PNG_WRITE_tEXt_SUPPORTED +#define PNG_WRITE_tIME_SUPPORTED +#define PNG_WRITE_tRNS_SUPPORTED +#define PNG_WRITE_zTXt_SUPPORTED +#define PNG_bKGD_SUPPORTED +#define PNG_cHRM_SUPPORTED +#define PNG_gAMA_SUPPORTED +#define PNG_hIST_SUPPORTED +#define PNG_iCCP_SUPPORTED +#define PNG_iTXt_SUPPORTED +#define PNG_oFFs_SUPPORTED +#define PNG_pCAL_SUPPORTED +#define PNG_pHYs_SUPPORTED +#define PNG_sBIT_SUPPORTED +#define PNG_sCAL_SUPPORTED +#define PNG_sPLT_SUPPORTED +#define PNG_sRGB_SUPPORTED +#define PNG_tEXt_SUPPORTED +#define PNG_tIME_SUPPORTED +#define PNG_tRNS_SUPPORTED +#define PNG_zTXt_SUPPORTED +/* end of options */ +/* settings */ +#define PNG_API_RULE 0 +#define PNG_DEFAULT_READ_MACROS 1 +#define PNG_GAMMA_THRESHOLD_FIXED 5000 +#define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE +#define PNG_INFLATE_BUF_SIZE 1024 +#define PNG_LINKAGE_API extern +#define PNG_LINKAGE_CALLBACK extern +#define PNG_LINKAGE_DATA extern +#define PNG_LINKAGE_FUNCTION extern +#define PNG_MAX_GAMMA_8 11 +#define PNG_QUANTIZE_BLUE_BITS 5 +#define PNG_QUANTIZE_GREEN_BITS 5 +#define PNG_QUANTIZE_RED_BITS 5 +#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1) +#define PNG_TEXT_Z_DEFAULT_STRATEGY 0 +#define PNG_USER_CHUNK_CACHE_MAX 1000 +#define PNG_USER_CHUNK_MALLOC_MAX 8000000 +#define PNG_USER_HEIGHT_MAX 1000000 +#define PNG_USER_WIDTH_MAX 1000000 +#define PNG_ZBUF_SIZE 8192 +#define PNG_ZLIB_VERNUM 0x1280 +#define PNG_Z_DEFAULT_COMPRESSION (-1) +#define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0 +#define PNG_Z_DEFAULT_STRATEGY 1 +#define PNG_sCAL_PRECISION 5 +#define PNG_sRGB_PROFILE_CHECKS 2 +/* end of settings */ +#endif /* PNGLCONF_H */ diff --git a/android/x86/include/tiff/tiff.h b/android/x86/include/tiff/tiff.h new file mode 100644 index 00000000..bc46acd0 --- /dev/null +++ b/android/x86/include/tiff/tiff.h @@ -0,0 +1,681 @@ +/* $Id: tiff.h,v 1.69 2014-04-02 17:23:06 fwarmerdam Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _TIFF_ +#define _TIFF_ + +#include "tiffconf.h" + +/* + * Tag Image File Format (TIFF) + * + * Based on Rev 6.0 from: + * Developer's Desk + * Aldus Corporation + * 411 First Ave. South + * Suite 200 + * Seattle, WA 98104 + * 206-622-5500 + * + * (http://partners.adobe.com/asn/developer/PDFS/TN/TIFF6.pdf) + * + * For BigTIFF design notes see the following links + * http://www.remotesensing.org/libtiff/bigtiffdesign.html + * http://www.awaresystems.be/imaging/tiff/bigtiff.html + */ + +#define TIFF_VERSION_CLASSIC 42 +#define TIFF_VERSION_BIG 43 + +#define TIFF_BIGENDIAN 0x4d4d +#define TIFF_LITTLEENDIAN 0x4949 +#define MDI_LITTLEENDIAN 0x5045 +#define MDI_BIGENDIAN 0x4550 + +/* + * Intrinsic data types required by the file format: + * + * 8-bit quantities int8/uint8 + * 16-bit quantities int16/uint16 + * 32-bit quantities int32/uint32 + * 64-bit quantities int64/uint64 + * strings unsigned char* + */ + +typedef TIFF_INT8_T int8; +typedef TIFF_UINT8_T uint8; + +typedef TIFF_INT16_T int16; +typedef TIFF_UINT16_T uint16; + +typedef TIFF_INT32_T int32; +typedef TIFF_UINT32_T uint32; + +typedef TIFF_INT64_T int64; +typedef TIFF_UINT64_T uint64; + +/* + * Some types as promoted in a variable argument list + * We use uint16_vap rather then directly using int, because this way + * we document the type we actually want to pass through, conceptually, + * rather then confusing the issue by merely stating the type it gets + * promoted to + */ + +typedef int uint16_vap; + +/* + * TIFF header. + */ +typedef struct { + uint16 tiff_magic; /* magic number (defines byte order) */ + uint16 tiff_version; /* TIFF version number */ +} TIFFHeaderCommon; +typedef struct { + uint16 tiff_magic; /* magic number (defines byte order) */ + uint16 tiff_version; /* TIFF version number */ + uint32 tiff_diroff; /* byte offset to first directory */ +} TIFFHeaderClassic; +typedef struct { + uint16 tiff_magic; /* magic number (defines byte order) */ + uint16 tiff_version; /* TIFF version number */ + uint16 tiff_offsetsize; /* size of offsets, should be 8 */ + uint16 tiff_unused; /* unused word, should be 0 */ + uint64 tiff_diroff; /* byte offset to first directory */ +} TIFFHeaderBig; + + +/* + * NB: In the comments below, + * - items marked with a + are obsoleted by revision 5.0, + * - items marked with a ! are introduced in revision 6.0. + * - items marked with a % are introduced post revision 6.0. + * - items marked with a $ are obsoleted by revision 6.0. + * - items marked with a & are introduced by Adobe DNG specification. + */ + +/* + * Tag data type information. + * + * Note: RATIONALs are the ratio of two 32-bit integer values. + */ +typedef enum { + TIFF_NOTYPE = 0, /* placeholder */ + TIFF_BYTE = 1, /* 8-bit unsigned integer */ + TIFF_ASCII = 2, /* 8-bit bytes w/ last byte null */ + TIFF_SHORT = 3, /* 16-bit unsigned integer */ + TIFF_LONG = 4, /* 32-bit unsigned integer */ + TIFF_RATIONAL = 5, /* 64-bit unsigned fraction */ + TIFF_SBYTE = 6, /* !8-bit signed integer */ + TIFF_UNDEFINED = 7, /* !8-bit untyped data */ + TIFF_SSHORT = 8, /* !16-bit signed integer */ + TIFF_SLONG = 9, /* !32-bit signed integer */ + TIFF_SRATIONAL = 10, /* !64-bit signed fraction */ + TIFF_FLOAT = 11, /* !32-bit IEEE floating point */ + TIFF_DOUBLE = 12, /* !64-bit IEEE floating point */ + TIFF_IFD = 13, /* %32-bit unsigned integer (offset) */ + TIFF_LONG8 = 16, /* BigTIFF 64-bit unsigned integer */ + TIFF_SLONG8 = 17, /* BigTIFF 64-bit signed integer */ + TIFF_IFD8 = 18 /* BigTIFF 64-bit unsigned integer (offset) */ +} TIFFDataType; + +/* + * TIFF Tag Definitions. + */ +#define TIFFTAG_SUBFILETYPE 254 /* subfile data descriptor */ +#define FILETYPE_REDUCEDIMAGE 0x1 /* reduced resolution version */ +#define FILETYPE_PAGE 0x2 /* one page of many */ +#define FILETYPE_MASK 0x4 /* transparency mask */ +#define TIFFTAG_OSUBFILETYPE 255 /* +kind of data in subfile */ +#define OFILETYPE_IMAGE 1 /* full resolution image data */ +#define OFILETYPE_REDUCEDIMAGE 2 /* reduced size image data */ +#define OFILETYPE_PAGE 3 /* one page of many */ +#define TIFFTAG_IMAGEWIDTH 256 /* image width in pixels */ +#define TIFFTAG_IMAGELENGTH 257 /* image height in pixels */ +#define TIFFTAG_BITSPERSAMPLE 258 /* bits per channel (sample) */ +#define TIFFTAG_COMPRESSION 259 /* data compression technique */ +#define COMPRESSION_NONE 1 /* dump mode */ +#define COMPRESSION_CCITTRLE 2 /* CCITT modified Huffman RLE */ +#define COMPRESSION_CCITTFAX3 3 /* CCITT Group 3 fax encoding */ +#define COMPRESSION_CCITT_T4 3 /* CCITT T.4 (TIFF 6 name) */ +#define COMPRESSION_CCITTFAX4 4 /* CCITT Group 4 fax encoding */ +#define COMPRESSION_CCITT_T6 4 /* CCITT T.6 (TIFF 6 name) */ +#define COMPRESSION_LZW 5 /* Lempel-Ziv & Welch */ +#define COMPRESSION_OJPEG 6 /* !6.0 JPEG */ +#define COMPRESSION_JPEG 7 /* %JPEG DCT compression */ +#define COMPRESSION_T85 9 /* !TIFF/FX T.85 JBIG compression */ +#define COMPRESSION_T43 10 /* !TIFF/FX T.43 colour by layered JBIG compression */ +#define COMPRESSION_NEXT 32766 /* NeXT 2-bit RLE */ +#define COMPRESSION_CCITTRLEW 32771 /* #1 w/ word alignment */ +#define COMPRESSION_PACKBITS 32773 /* Macintosh RLE */ +#define COMPRESSION_THUNDERSCAN 32809 /* ThunderScan RLE */ +/* codes 32895-32898 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */ +#define COMPRESSION_IT8CTPAD 32895 /* IT8 CT w/padding */ +#define COMPRESSION_IT8LW 32896 /* IT8 Linework RLE */ +#define COMPRESSION_IT8MP 32897 /* IT8 Monochrome picture */ +#define COMPRESSION_IT8BL 32898 /* IT8 Binary line art */ +/* compression codes 32908-32911 are reserved for Pixar */ +#define COMPRESSION_PIXARFILM 32908 /* Pixar companded 10bit LZW */ +#define COMPRESSION_PIXARLOG 32909 /* Pixar companded 11bit ZIP */ +#define COMPRESSION_DEFLATE 32946 /* Deflate compression */ +#define COMPRESSION_ADOBE_DEFLATE 8 /* Deflate compression, + as recognized by Adobe */ +/* compression code 32947 is reserved for Oceana Matrix <dev@oceana.com> */ +#define COMPRESSION_DCS 32947 /* Kodak DCS encoding */ +#define COMPRESSION_JBIG 34661 /* ISO JBIG */ +#define COMPRESSION_SGILOG 34676 /* SGI Log Luminance RLE */ +#define COMPRESSION_SGILOG24 34677 /* SGI Log 24-bit packed */ +#define COMPRESSION_JP2000 34712 /* Leadtools JPEG2000 */ +#define COMPRESSION_LZMA 34925 /* LZMA2 */ +#define TIFFTAG_PHOTOMETRIC 262 /* photometric interpretation */ +#define PHOTOMETRIC_MINISWHITE 0 /* min value is white */ +#define PHOTOMETRIC_MINISBLACK 1 /* min value is black */ +#define PHOTOMETRIC_RGB 2 /* RGB color model */ +#define PHOTOMETRIC_PALETTE 3 /* color map indexed */ +#define PHOTOMETRIC_MASK 4 /* $holdout mask */ +#define PHOTOMETRIC_SEPARATED 5 /* !color separations */ +#define PHOTOMETRIC_YCBCR 6 /* !CCIR 601 */ +#define PHOTOMETRIC_CIELAB 8 /* !1976 CIE L*a*b* */ +#define PHOTOMETRIC_ICCLAB 9 /* ICC L*a*b* [Adobe TIFF Technote 4] */ +#define PHOTOMETRIC_ITULAB 10 /* ITU L*a*b* */ +#define PHOTOMETRIC_CFA 32803 /* color filter array */ +#define PHOTOMETRIC_LOGL 32844 /* CIE Log2(L) */ +#define PHOTOMETRIC_LOGLUV 32845 /* CIE Log2(L) (u',v') */ +#define TIFFTAG_THRESHHOLDING 263 /* +thresholding used on data */ +#define THRESHHOLD_BILEVEL 1 /* b&w art scan */ +#define THRESHHOLD_HALFTONE 2 /* or dithered scan */ +#define THRESHHOLD_ERRORDIFFUSE 3 /* usually floyd-steinberg */ +#define TIFFTAG_CELLWIDTH 264 /* +dithering matrix width */ +#define TIFFTAG_CELLLENGTH 265 /* +dithering matrix height */ +#define TIFFTAG_FILLORDER 266 /* data order within a byte */ +#define FILLORDER_MSB2LSB 1 /* most significant -> least */ +#define FILLORDER_LSB2MSB 2 /* least significant -> most */ +#define TIFFTAG_DOCUMENTNAME 269 /* name of doc. image is from */ +#define TIFFTAG_IMAGEDESCRIPTION 270 /* info about image */ +#define TIFFTAG_MAKE 271 /* scanner manufacturer name */ +#define TIFFTAG_MODEL 272 /* scanner model name/number */ +#define TIFFTAG_STRIPOFFSETS 273 /* offsets to data strips */ +#define TIFFTAG_ORIENTATION 274 /* +image orientation */ +#define ORIENTATION_TOPLEFT 1 /* row 0 top, col 0 lhs */ +#define ORIENTATION_TOPRIGHT 2 /* row 0 top, col 0 rhs */ +#define ORIENTATION_BOTRIGHT 3 /* row 0 bottom, col 0 rhs */ +#define ORIENTATION_BOTLEFT 4 /* row 0 bottom, col 0 lhs */ +#define ORIENTATION_LEFTTOP 5 /* row 0 lhs, col 0 top */ +#define ORIENTATION_RIGHTTOP 6 /* row 0 rhs, col 0 top */ +#define ORIENTATION_RIGHTBOT 7 /* row 0 rhs, col 0 bottom */ +#define ORIENTATION_LEFTBOT 8 /* row 0 lhs, col 0 bottom */ +#define TIFFTAG_SAMPLESPERPIXEL 277 /* samples per pixel */ +#define TIFFTAG_ROWSPERSTRIP 278 /* rows per strip of data */ +#define TIFFTAG_STRIPBYTECOUNTS 279 /* bytes counts for strips */ +#define TIFFTAG_MINSAMPLEVALUE 280 /* +minimum sample value */ +#define TIFFTAG_MAXSAMPLEVALUE 281 /* +maximum sample value */ +#define TIFFTAG_XRESOLUTION 282 /* pixels/resolution in x */ +#define TIFFTAG_YRESOLUTION 283 /* pixels/resolution in y */ +#define TIFFTAG_PLANARCONFIG 284 /* storage organization */ +#define PLANARCONFIG_CONTIG 1 /* single image plane */ +#define PLANARCONFIG_SEPARATE 2 /* separate planes of data */ +#define TIFFTAG_PAGENAME 285 /* page name image is from */ +#define TIFFTAG_XPOSITION 286 /* x page offset of image lhs */ +#define TIFFTAG_YPOSITION 287 /* y page offset of image lhs */ +#define TIFFTAG_FREEOFFSETS 288 /* +byte offset to free block */ +#define TIFFTAG_FREEBYTECOUNTS 289 /* +sizes of free blocks */ +#define TIFFTAG_GRAYRESPONSEUNIT 290 /* $gray scale curve accuracy */ +#define GRAYRESPONSEUNIT_10S 1 /* tenths of a unit */ +#define GRAYRESPONSEUNIT_100S 2 /* hundredths of a unit */ +#define GRAYRESPONSEUNIT_1000S 3 /* thousandths of a unit */ +#define GRAYRESPONSEUNIT_10000S 4 /* ten-thousandths of a unit */ +#define GRAYRESPONSEUNIT_100000S 5 /* hundred-thousandths */ +#define TIFFTAG_GRAYRESPONSECURVE 291 /* $gray scale response curve */ +#define TIFFTAG_GROUP3OPTIONS 292 /* 32 flag bits */ +#define TIFFTAG_T4OPTIONS 292 /* TIFF 6.0 proper name alias */ +#define GROUP3OPT_2DENCODING 0x1 /* 2-dimensional coding */ +#define GROUP3OPT_UNCOMPRESSED 0x2 /* data not compressed */ +#define GROUP3OPT_FILLBITS 0x4 /* fill to byte boundary */ +#define TIFFTAG_GROUP4OPTIONS 293 /* 32 flag bits */ +#define TIFFTAG_T6OPTIONS 293 /* TIFF 6.0 proper name */ +#define GROUP4OPT_UNCOMPRESSED 0x2 /* data not compressed */ +#define TIFFTAG_RESOLUTIONUNIT 296 /* units of resolutions */ +#define RESUNIT_NONE 1 /* no meaningful units */ +#define RESUNIT_INCH 2 /* english */ +#define RESUNIT_CENTIMETER 3 /* metric */ +#define TIFFTAG_PAGENUMBER 297 /* page numbers of multi-page */ +#define TIFFTAG_COLORRESPONSEUNIT 300 /* $color curve accuracy */ +#define COLORRESPONSEUNIT_10S 1 /* tenths of a unit */ +#define COLORRESPONSEUNIT_100S 2 /* hundredths of a unit */ +#define COLORRESPONSEUNIT_1000S 3 /* thousandths of a unit */ +#define COLORRESPONSEUNIT_10000S 4 /* ten-thousandths of a unit */ +#define COLORRESPONSEUNIT_100000S 5 /* hundred-thousandths */ +#define TIFFTAG_TRANSFERFUNCTION 301 /* !colorimetry info */ +#define TIFFTAG_SOFTWARE 305 /* name & release */ +#define TIFFTAG_DATETIME 306 /* creation date and time */ +#define TIFFTAG_ARTIST 315 /* creator of image */ +#define TIFFTAG_HOSTCOMPUTER 316 /* machine where created */ +#define TIFFTAG_PREDICTOR 317 /* prediction scheme w/ LZW */ +#define PREDICTOR_NONE 1 /* no prediction scheme used */ +#define PREDICTOR_HORIZONTAL 2 /* horizontal differencing */ +#define PREDICTOR_FLOATINGPOINT 3 /* floating point predictor */ +#define TIFFTAG_WHITEPOINT 318 /* image white point */ +#define TIFFTAG_PRIMARYCHROMATICITIES 319 /* !primary chromaticities */ +#define TIFFTAG_COLORMAP 320 /* RGB map for pallette image */ +#define TIFFTAG_HALFTONEHINTS 321 /* !highlight+shadow info */ +#define TIFFTAG_TILEWIDTH 322 /* !tile width in pixels */ +#define TIFFTAG_TILELENGTH 323 /* !tile height in pixels */ +#define TIFFTAG_TILEOFFSETS 324 /* !offsets to data tiles */ +#define TIFFTAG_TILEBYTECOUNTS 325 /* !byte counts for tiles */ +#define TIFFTAG_BADFAXLINES 326 /* lines w/ wrong pixel count */ +#define TIFFTAG_CLEANFAXDATA 327 /* regenerated line info */ +#define CLEANFAXDATA_CLEAN 0 /* no errors detected */ +#define CLEANFAXDATA_REGENERATED 1 /* receiver regenerated lines */ +#define CLEANFAXDATA_UNCLEAN 2 /* uncorrected errors exist */ +#define TIFFTAG_CONSECUTIVEBADFAXLINES 328 /* max consecutive bad lines */ +#define TIFFTAG_SUBIFD 330 /* subimage descriptors */ +#define TIFFTAG_INKSET 332 /* !inks in separated image */ +#define INKSET_CMYK 1 /* !cyan-magenta-yellow-black color */ +#define INKSET_MULTIINK 2 /* !multi-ink or hi-fi color */ +#define TIFFTAG_INKNAMES 333 /* !ascii names of inks */ +#define TIFFTAG_NUMBEROFINKS 334 /* !number of inks */ +#define TIFFTAG_DOTRANGE 336 /* !0% and 100% dot codes */ +#define TIFFTAG_TARGETPRINTER 337 /* !separation target */ +#define TIFFTAG_EXTRASAMPLES 338 /* !info about extra samples */ +#define EXTRASAMPLE_UNSPECIFIED 0 /* !unspecified data */ +#define EXTRASAMPLE_ASSOCALPHA 1 /* !associated alpha data */ +#define EXTRASAMPLE_UNASSALPHA 2 /* !unassociated alpha data */ +#define TIFFTAG_SAMPLEFORMAT 339 /* !data sample format */ +#define SAMPLEFORMAT_UINT 1 /* !unsigned integer data */ +#define SAMPLEFORMAT_INT 2 /* !signed integer data */ +#define SAMPLEFORMAT_IEEEFP 3 /* !IEEE floating point data */ +#define SAMPLEFORMAT_VOID 4 /* !untyped data */ +#define SAMPLEFORMAT_COMPLEXINT 5 /* !complex signed int */ +#define SAMPLEFORMAT_COMPLEXIEEEFP 6 /* !complex ieee floating */ +#define TIFFTAG_SMINSAMPLEVALUE 340 /* !variable MinSampleValue */ +#define TIFFTAG_SMAXSAMPLEVALUE 341 /* !variable MaxSampleValue */ +#define TIFFTAG_CLIPPATH 343 /* %ClipPath + [Adobe TIFF technote 2] */ +#define TIFFTAG_XCLIPPATHUNITS 344 /* %XClipPathUnits + [Adobe TIFF technote 2] */ +#define TIFFTAG_YCLIPPATHUNITS 345 /* %YClipPathUnits + [Adobe TIFF technote 2] */ +#define TIFFTAG_INDEXED 346 /* %Indexed + [Adobe TIFF Technote 3] */ +#define TIFFTAG_JPEGTABLES 347 /* %JPEG table stream */ +#define TIFFTAG_OPIPROXY 351 /* %OPI Proxy [Adobe TIFF technote] */ +/* Tags 400-435 are from the TIFF/FX spec */ +#define TIFFTAG_GLOBALPARAMETERSIFD 400 /* ! */ +#define TIFFTAG_PROFILETYPE 401 /* ! */ +#define PROFILETYPE_UNSPECIFIED 0 /* ! */ +#define PROFILETYPE_G3_FAX 1 /* ! */ +#define TIFFTAG_FAXPROFILE 402 /* ! */ +#define FAXPROFILE_S 1 /* !TIFF/FX FAX profile S */ +#define FAXPROFILE_F 2 /* !TIFF/FX FAX profile F */ +#define FAXPROFILE_J 3 /* !TIFF/FX FAX profile J */ +#define FAXPROFILE_C 4 /* !TIFF/FX FAX profile C */ +#define FAXPROFILE_L 5 /* !TIFF/FX FAX profile L */ +#define FAXPROFILE_M 6 /* !TIFF/FX FAX profile LM */ +#define TIFFTAG_CODINGMETHODS 403 /* !TIFF/FX coding methods */ +#define CODINGMETHODS_T4_1D (1 << 1) /* !T.4 1D */ +#define CODINGMETHODS_T4_2D (1 << 2) /* !T.4 2D */ +#define CODINGMETHODS_T6 (1 << 3) /* !T.6 */ +#define CODINGMETHODS_T85 (1 << 4) /* !T.85 JBIG */ +#define CODINGMETHODS_T42 (1 << 5) /* !T.42 JPEG */ +#define CODINGMETHODS_T43 (1 << 6) /* !T.43 colour by layered JBIG */ +#define TIFFTAG_VERSIONYEAR 404 /* !TIFF/FX version year */ +#define TIFFTAG_MODENUMBER 405 /* !TIFF/FX mode number */ +#define TIFFTAG_DECODE 433 /* !TIFF/FX decode */ +#define TIFFTAG_IMAGEBASECOLOR 434 /* !TIFF/FX image base colour */ +#define TIFFTAG_T82OPTIONS 435 /* !TIFF/FX T.82 options */ +/* + * Tags 512-521 are obsoleted by Technical Note #2 which specifies a + * revised JPEG-in-TIFF scheme. + */ +#define TIFFTAG_JPEGPROC 512 /* !JPEG processing algorithm */ +#define JPEGPROC_BASELINE 1 /* !baseline sequential */ +#define JPEGPROC_LOSSLESS 14 /* !Huffman coded lossless */ +#define TIFFTAG_JPEGIFOFFSET 513 /* !pointer to SOI marker */ +#define TIFFTAG_JPEGIFBYTECOUNT 514 /* !JFIF stream length */ +#define TIFFTAG_JPEGRESTARTINTERVAL 515 /* !restart interval length */ +#define TIFFTAG_JPEGLOSSLESSPREDICTORS 517 /* !lossless proc predictor */ +#define TIFFTAG_JPEGPOINTTRANSFORM 518 /* !lossless point transform */ +#define TIFFTAG_JPEGQTABLES 519 /* !Q matrice offsets */ +#define TIFFTAG_JPEGDCTABLES 520 /* !DCT table offsets */ +#define TIFFTAG_JPEGACTABLES 521 /* !AC coefficient offsets */ +#define TIFFTAG_YCBCRCOEFFICIENTS 529 /* !RGB -> YCbCr transform */ +#define TIFFTAG_YCBCRSUBSAMPLING 530 /* !YCbCr subsampling factors */ +#define TIFFTAG_YCBCRPOSITIONING 531 /* !subsample positioning */ +#define YCBCRPOSITION_CENTERED 1 /* !as in PostScript Level 2 */ +#define YCBCRPOSITION_COSITED 2 /* !as in CCIR 601-1 */ +#define TIFFTAG_REFERENCEBLACKWHITE 532 /* !colorimetry info */ +#define TIFFTAG_STRIPROWCOUNTS 559 /* !TIFF/FX strip row counts */ +#define TIFFTAG_XMLPACKET 700 /* %XML packet + [Adobe XMP Specification, + January 2004 */ +#define TIFFTAG_OPIIMAGEID 32781 /* %OPI ImageID + [Adobe TIFF technote] */ +/* tags 32952-32956 are private tags registered to Island Graphics */ +#define TIFFTAG_REFPTS 32953 /* image reference points */ +#define TIFFTAG_REGIONTACKPOINT 32954 /* region-xform tack point */ +#define TIFFTAG_REGIONWARPCORNERS 32955 /* warp quadrilateral */ +#define TIFFTAG_REGIONAFFINE 32956 /* affine transformation mat */ +/* tags 32995-32999 are private tags registered to SGI */ +#define TIFFTAG_MATTEING 32995 /* $use ExtraSamples */ +#define TIFFTAG_DATATYPE 32996 /* $use SampleFormat */ +#define TIFFTAG_IMAGEDEPTH 32997 /* z depth of image */ +#define TIFFTAG_TILEDEPTH 32998 /* z depth/data tile */ +/* tags 33300-33309 are private tags registered to Pixar */ +/* + * TIFFTAG_PIXAR_IMAGEFULLWIDTH and TIFFTAG_PIXAR_IMAGEFULLLENGTH + * are set when an image has been cropped out of a larger image. + * They reflect the size of the original uncropped image. + * The TIFFTAG_XPOSITION and TIFFTAG_YPOSITION can be used + * to determine the position of the smaller image in the larger one. + */ +#define TIFFTAG_PIXAR_IMAGEFULLWIDTH 33300 /* full image size in x */ +#define TIFFTAG_PIXAR_IMAGEFULLLENGTH 33301 /* full image size in y */ + /* Tags 33302-33306 are used to identify special image modes and data + * used by Pixar's texture formats. + */ +#define TIFFTAG_PIXAR_TEXTUREFORMAT 33302 /* texture map format */ +#define TIFFTAG_PIXAR_WRAPMODES 33303 /* s & t wrap modes */ +#define TIFFTAG_PIXAR_FOVCOT 33304 /* cotan(fov) for env. maps */ +#define TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN 33305 +#define TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA 33306 +/* tag 33405 is a private tag registered to Eastman Kodak */ +#define TIFFTAG_WRITERSERIALNUMBER 33405 /* device serial number */ +#define TIFFTAG_CFAREPEATPATTERNDIM 33421 /* dimensions of CFA pattern */ +#define TIFFTAG_CFAPATTERN 33422 /* color filter array pattern */ +/* tag 33432 is listed in the 6.0 spec w/ unknown ownership */ +#define TIFFTAG_COPYRIGHT 33432 /* copyright string */ +/* IPTC TAG from RichTIFF specifications */ +#define TIFFTAG_RICHTIFFIPTC 33723 +/* 34016-34029 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */ +#define TIFFTAG_IT8SITE 34016 /* site name */ +#define TIFFTAG_IT8COLORSEQUENCE 34017 /* color seq. [RGB,CMYK,etc] */ +#define TIFFTAG_IT8HEADER 34018 /* DDES Header */ +#define TIFFTAG_IT8RASTERPADDING 34019 /* raster scanline padding */ +#define TIFFTAG_IT8BITSPERRUNLENGTH 34020 /* # of bits in short run */ +#define TIFFTAG_IT8BITSPEREXTENDEDRUNLENGTH 34021/* # of bits in long run */ +#define TIFFTAG_IT8COLORTABLE 34022 /* LW colortable */ +#define TIFFTAG_IT8IMAGECOLORINDICATOR 34023 /* BP/BL image color switch */ +#define TIFFTAG_IT8BKGCOLORINDICATOR 34024 /* BP/BL bg color switch */ +#define TIFFTAG_IT8IMAGECOLORVALUE 34025 /* BP/BL image color value */ +#define TIFFTAG_IT8BKGCOLORVALUE 34026 /* BP/BL bg color value */ +#define TIFFTAG_IT8PIXELINTENSITYRANGE 34027 /* MP pixel intensity value */ +#define TIFFTAG_IT8TRANSPARENCYINDICATOR 34028 /* HC transparency switch */ +#define TIFFTAG_IT8COLORCHARACTERIZATION 34029 /* color character. table */ +#define TIFFTAG_IT8HCUSAGE 34030 /* HC usage indicator */ +#define TIFFTAG_IT8TRAPINDICATOR 34031 /* Trapping indicator + (untrapped=0, trapped=1) */ +#define TIFFTAG_IT8CMYKEQUIVALENT 34032 /* CMYK color equivalents */ +/* tags 34232-34236 are private tags registered to Texas Instruments */ +#define TIFFTAG_FRAMECOUNT 34232 /* Sequence Frame Count */ +/* tag 34377 is private tag registered to Adobe for PhotoShop */ +#define TIFFTAG_PHOTOSHOP 34377 +/* tags 34665, 34853 and 40965 are documented in EXIF specification */ +#define TIFFTAG_EXIFIFD 34665 /* Pointer to EXIF private directory */ +/* tag 34750 is a private tag registered to Adobe? */ +#define TIFFTAG_ICCPROFILE 34675 /* ICC profile data */ +#define TIFFTAG_IMAGELAYER 34732 /* !TIFF/FX image layer information */ +/* tag 34750 is a private tag registered to Pixel Magic */ +#define TIFFTAG_JBIGOPTIONS 34750 /* JBIG options */ +#define TIFFTAG_GPSIFD 34853 /* Pointer to GPS private directory */ +/* tags 34908-34914 are private tags registered to SGI */ +#define TIFFTAG_FAXRECVPARAMS 34908 /* encoded Class 2 ses. parms */ +#define TIFFTAG_FAXSUBADDRESS 34909 /* received SubAddr string */ +#define TIFFTAG_FAXRECVTIME 34910 /* receive time (secs) */ +#define TIFFTAG_FAXDCS 34911 /* encoded fax ses. params, Table 2/T.30 */ +/* tags 37439-37443 are registered to SGI <gregl@sgi.com> */ +#define TIFFTAG_STONITS 37439 /* Sample value to Nits */ +/* tag 34929 is a private tag registered to FedEx */ +#define TIFFTAG_FEDEX_EDR 34929 /* unknown use */ +#define TIFFTAG_INTEROPERABILITYIFD 40965 /* Pointer to Interoperability private directory */ +/* Adobe Digital Negative (DNG) format tags */ +#define TIFFTAG_DNGVERSION 50706 /* &DNG version number */ +#define TIFFTAG_DNGBACKWARDVERSION 50707 /* &DNG compatibility version */ +#define TIFFTAG_UNIQUECAMERAMODEL 50708 /* &name for the camera model */ +#define TIFFTAG_LOCALIZEDCAMERAMODEL 50709 /* &localized camera model + name */ +#define TIFFTAG_CFAPLANECOLOR 50710 /* &CFAPattern->LinearRaw space + mapping */ +#define TIFFTAG_CFALAYOUT 50711 /* &spatial layout of the CFA */ +#define TIFFTAG_LINEARIZATIONTABLE 50712 /* &lookup table description */ +#define TIFFTAG_BLACKLEVELREPEATDIM 50713 /* &repeat pattern size for + the BlackLevel tag */ +#define TIFFTAG_BLACKLEVEL 50714 /* &zero light encoding level */ +#define TIFFTAG_BLACKLEVELDELTAH 50715 /* &zero light encoding level + differences (columns) */ +#define TIFFTAG_BLACKLEVELDELTAV 50716 /* &zero light encoding level + differences (rows) */ +#define TIFFTAG_WHITELEVEL 50717 /* &fully saturated encoding + level */ +#define TIFFTAG_DEFAULTSCALE 50718 /* &default scale factors */ +#define TIFFTAG_DEFAULTCROPORIGIN 50719 /* &origin of the final image + area */ +#define TIFFTAG_DEFAULTCROPSIZE 50720 /* &size of the final image + area */ +#define TIFFTAG_COLORMATRIX1 50721 /* &XYZ->reference color space + transformation matrix 1 */ +#define TIFFTAG_COLORMATRIX2 50722 /* &XYZ->reference color space + transformation matrix 2 */ +#define TIFFTAG_CAMERACALIBRATION1 50723 /* &calibration matrix 1 */ +#define TIFFTAG_CAMERACALIBRATION2 50724 /* &calibration matrix 2 */ +#define TIFFTAG_REDUCTIONMATRIX1 50725 /* &dimensionality reduction + matrix 1 */ +#define TIFFTAG_REDUCTIONMATRIX2 50726 /* &dimensionality reduction + matrix 2 */ +#define TIFFTAG_ANALOGBALANCE 50727 /* &gain applied the stored raw + values*/ +#define TIFFTAG_ASSHOTNEUTRAL 50728 /* &selected white balance in + linear reference space */ +#define TIFFTAG_ASSHOTWHITEXY 50729 /* &selected white balance in + x-y chromaticity + coordinates */ +#define TIFFTAG_BASELINEEXPOSURE 50730 /* &how much to move the zero + point */ +#define TIFFTAG_BASELINENOISE 50731 /* &relative noise level */ +#define TIFFTAG_BASELINESHARPNESS 50732 /* &relative amount of + sharpening */ +#define TIFFTAG_BAYERGREENSPLIT 50733 /* &how closely the values of + the green pixels in the + blue/green rows track the + values of the green pixels + in the red/green rows */ +#define TIFFTAG_LINEARRESPONSELIMIT 50734 /* &non-linear encoding range */ +#define TIFFTAG_CAMERASERIALNUMBER 50735 /* &camera's serial number */ +#define TIFFTAG_LENSINFO 50736 /* info about the lens */ +#define TIFFTAG_CHROMABLURRADIUS 50737 /* &chroma blur radius */ +#define TIFFTAG_ANTIALIASSTRENGTH 50738 /* &relative strength of the + camera's anti-alias filter */ +#define TIFFTAG_SHADOWSCALE 50739 /* &used by Adobe Camera Raw */ +#define TIFFTAG_DNGPRIVATEDATA 50740 /* &manufacturer's private data */ +#define TIFFTAG_MAKERNOTESAFETY 50741 /* &whether the EXIF MakerNote + tag is safe to preserve + along with the rest of the + EXIF data */ +#define TIFFTAG_CALIBRATIONILLUMINANT1 50778 /* &illuminant 1 */ +#define TIFFTAG_CALIBRATIONILLUMINANT2 50779 /* &illuminant 2 */ +#define TIFFTAG_BESTQUALITYSCALE 50780 /* &best quality multiplier */ +#define TIFFTAG_RAWDATAUNIQUEID 50781 /* &unique identifier for + the raw image data */ +#define TIFFTAG_ORIGINALRAWFILENAME 50827 /* &file name of the original + raw file */ +#define TIFFTAG_ORIGINALRAWFILEDATA 50828 /* &contents of the original + raw file */ +#define TIFFTAG_ACTIVEAREA 50829 /* &active (non-masked) pixels + of the sensor */ +#define TIFFTAG_MASKEDAREAS 50830 /* &list of coordinates + of fully masked pixels */ +#define TIFFTAG_ASSHOTICCPROFILE 50831 /* &these two tags used to */ +#define TIFFTAG_ASSHOTPREPROFILEMATRIX 50832 /* map cameras's color space + into ICC profile space */ +#define TIFFTAG_CURRENTICCPROFILE 50833 /* & */ +#define TIFFTAG_CURRENTPREPROFILEMATRIX 50834 /* & */ +/* tag 65535 is an undefined tag used by Eastman Kodak */ +#define TIFFTAG_DCSHUESHIFTVALUES 65535 /* hue shift correction data */ + +/* + * The following are ``pseudo tags'' that can be used to control + * codec-specific functionality. These tags are not written to file. + * Note that these values start at 0xffff+1 so that they'll never + * collide with Aldus-assigned tags. + * + * If you want your private pseudo tags ``registered'' (i.e. added to + * this file), please post a bug report via the tracking system at + * http://www.remotesensing.org/libtiff/bugs.html with the appropriate + * C definitions to add. + */ +#define TIFFTAG_FAXMODE 65536 /* Group 3/4 format control */ +#define FAXMODE_CLASSIC 0x0000 /* default, include RTC */ +#define FAXMODE_NORTC 0x0001 /* no RTC at end of data */ +#define FAXMODE_NOEOL 0x0002 /* no EOL code at end of row */ +#define FAXMODE_BYTEALIGN 0x0004 /* byte align row */ +#define FAXMODE_WORDALIGN 0x0008 /* word align row */ +#define FAXMODE_CLASSF FAXMODE_NORTC /* TIFF Class F */ +#define TIFFTAG_JPEGQUALITY 65537 /* Compression quality level */ +/* Note: quality level is on the IJG 0-100 scale. Default value is 75 */ +#define TIFFTAG_JPEGCOLORMODE 65538 /* Auto RGB<=>YCbCr convert? */ +#define JPEGCOLORMODE_RAW 0x0000 /* no conversion (default) */ +#define JPEGCOLORMODE_RGB 0x0001 /* do auto conversion */ +#define TIFFTAG_JPEGTABLESMODE 65539 /* What to put in JPEGTables */ +#define JPEGTABLESMODE_QUANT 0x0001 /* include quantization tbls */ +#define JPEGTABLESMODE_HUFF 0x0002 /* include Huffman tbls */ +/* Note: default is JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF */ +#define TIFFTAG_FAXFILLFUNC 65540 /* G3/G4 fill function */ +#define TIFFTAG_PIXARLOGDATAFMT 65549 /* PixarLogCodec I/O data sz */ +#define PIXARLOGDATAFMT_8BIT 0 /* regular u_char samples */ +#define PIXARLOGDATAFMT_8BITABGR 1 /* ABGR-order u_chars */ +#define PIXARLOGDATAFMT_11BITLOG 2 /* 11-bit log-encoded (raw) */ +#define PIXARLOGDATAFMT_12BITPICIO 3 /* as per PICIO (1.0==2048) */ +#define PIXARLOGDATAFMT_16BIT 4 /* signed short samples */ +#define PIXARLOGDATAFMT_FLOAT 5 /* IEEE float samples */ +/* 65550-65556 are allocated to Oceana Matrix <dev@oceana.com> */ +#define TIFFTAG_DCSIMAGERTYPE 65550 /* imager model & filter */ +#define DCSIMAGERMODEL_M3 0 /* M3 chip (1280 x 1024) */ +#define DCSIMAGERMODEL_M5 1 /* M5 chip (1536 x 1024) */ +#define DCSIMAGERMODEL_M6 2 /* M6 chip (3072 x 2048) */ +#define DCSIMAGERFILTER_IR 0 /* infrared filter */ +#define DCSIMAGERFILTER_MONO 1 /* monochrome filter */ +#define DCSIMAGERFILTER_CFA 2 /* color filter array */ +#define DCSIMAGERFILTER_OTHER 3 /* other filter */ +#define TIFFTAG_DCSINTERPMODE 65551 /* interpolation mode */ +#define DCSINTERPMODE_NORMAL 0x0 /* whole image, default */ +#define DCSINTERPMODE_PREVIEW 0x1 /* preview of image (384x256) */ +#define TIFFTAG_DCSBALANCEARRAY 65552 /* color balance values */ +#define TIFFTAG_DCSCORRECTMATRIX 65553 /* color correction values */ +#define TIFFTAG_DCSGAMMA 65554 /* gamma value */ +#define TIFFTAG_DCSTOESHOULDERPTS 65555 /* toe & shoulder points */ +#define TIFFTAG_DCSCALIBRATIONFD 65556 /* calibration file desc */ +/* Note: quality level is on the ZLIB 1-9 scale. Default value is -1 */ +#define TIFFTAG_ZIPQUALITY 65557 /* compression quality level */ +#define TIFFTAG_PIXARLOGQUALITY 65558 /* PixarLog uses same scale */ +/* 65559 is allocated to Oceana Matrix <dev@oceana.com> */ +#define TIFFTAG_DCSCLIPRECTANGLE 65559 /* area of image to acquire */ +#define TIFFTAG_SGILOGDATAFMT 65560 /* SGILog user data format */ +#define SGILOGDATAFMT_FLOAT 0 /* IEEE float samples */ +#define SGILOGDATAFMT_16BIT 1 /* 16-bit samples */ +#define SGILOGDATAFMT_RAW 2 /* uninterpreted data */ +#define SGILOGDATAFMT_8BIT 3 /* 8-bit RGB monitor values */ +#define TIFFTAG_SGILOGENCODE 65561 /* SGILog data encoding control*/ +#define SGILOGENCODE_NODITHER 0 /* do not dither encoded values*/ +#define SGILOGENCODE_RANDITHER 1 /* randomly dither encd values */ +#define TIFFTAG_LZMAPRESET 65562 /* LZMA2 preset (compression level) */ +#define TIFFTAG_PERSAMPLE 65563 /* interface for per sample tags */ +#define PERSAMPLE_MERGED 0 /* present as a single value */ +#define PERSAMPLE_MULTI 1 /* present as multiple values */ + +/* + * EXIF tags + */ +#define EXIFTAG_EXPOSURETIME 33434 /* Exposure time */ +#define EXIFTAG_FNUMBER 33437 /* F number */ +#define EXIFTAG_EXPOSUREPROGRAM 34850 /* Exposure program */ +#define EXIFTAG_SPECTRALSENSITIVITY 34852 /* Spectral sensitivity */ +#define EXIFTAG_ISOSPEEDRATINGS 34855 /* ISO speed rating */ +#define EXIFTAG_OECF 34856 /* Optoelectric conversion + factor */ +#define EXIFTAG_EXIFVERSION 36864 /* Exif version */ +#define EXIFTAG_DATETIMEORIGINAL 36867 /* Date and time of original + data generation */ +#define EXIFTAG_DATETIMEDIGITIZED 36868 /* Date and time of digital + data generation */ +#define EXIFTAG_COMPONENTSCONFIGURATION 37121 /* Meaning of each component */ +#define EXIFTAG_COMPRESSEDBITSPERPIXEL 37122 /* Image compression mode */ +#define EXIFTAG_SHUTTERSPEEDVALUE 37377 /* Shutter speed */ +#define EXIFTAG_APERTUREVALUE 37378 /* Aperture */ +#define EXIFTAG_BRIGHTNESSVALUE 37379 /* Brightness */ +#define EXIFTAG_EXPOSUREBIASVALUE 37380 /* Exposure bias */ +#define EXIFTAG_MAXAPERTUREVALUE 37381 /* Maximum lens aperture */ +#define EXIFTAG_SUBJECTDISTANCE 37382 /* Subject distance */ +#define EXIFTAG_METERINGMODE 37383 /* Metering mode */ +#define EXIFTAG_LIGHTSOURCE 37384 /* Light source */ +#define EXIFTAG_FLASH 37385 /* Flash */ +#define EXIFTAG_FOCALLENGTH 37386 /* Lens focal length */ +#define EXIFTAG_SUBJECTAREA 37396 /* Subject area */ +#define EXIFTAG_MAKERNOTE 37500 /* Manufacturer notes */ +#define EXIFTAG_USERCOMMENT 37510 /* User comments */ +#define EXIFTAG_SUBSECTIME 37520 /* DateTime subseconds */ +#define EXIFTAG_SUBSECTIMEORIGINAL 37521 /* DateTimeOriginal subseconds */ +#define EXIFTAG_SUBSECTIMEDIGITIZED 37522 /* DateTimeDigitized subseconds */ +#define EXIFTAG_FLASHPIXVERSION 40960 /* Supported Flashpix version */ +#define EXIFTAG_COLORSPACE 40961 /* Color space information */ +#define EXIFTAG_PIXELXDIMENSION 40962 /* Valid image width */ +#define EXIFTAG_PIXELYDIMENSION 40963 /* Valid image height */ +#define EXIFTAG_RELATEDSOUNDFILE 40964 /* Related audio file */ +#define EXIFTAG_FLASHENERGY 41483 /* Flash energy */ +#define EXIFTAG_SPATIALFREQUENCYRESPONSE 41484 /* Spatial frequency response */ +#define EXIFTAG_FOCALPLANEXRESOLUTION 41486 /* Focal plane X resolution */ +#define EXIFTAG_FOCALPLANEYRESOLUTION 41487 /* Focal plane Y resolution */ +#define EXIFTAG_FOCALPLANERESOLUTIONUNIT 41488 /* Focal plane resolution unit */ +#define EXIFTAG_SUBJECTLOCATION 41492 /* Subject location */ +#define EXIFTAG_EXPOSUREINDEX 41493 /* Exposure index */ +#define EXIFTAG_SENSINGMETHOD 41495 /* Sensing method */ +#define EXIFTAG_FILESOURCE 41728 /* File source */ +#define EXIFTAG_SCENETYPE 41729 /* Scene type */ +#define EXIFTAG_CFAPATTERN 41730 /* CFA pattern */ +#define EXIFTAG_CUSTOMRENDERED 41985 /* Custom image processing */ +#define EXIFTAG_EXPOSUREMODE 41986 /* Exposure mode */ +#define EXIFTAG_WHITEBALANCE 41987 /* White balance */ +#define EXIFTAG_DIGITALZOOMRATIO 41988 /* Digital zoom ratio */ +#define EXIFTAG_FOCALLENGTHIN35MMFILM 41989 /* Focal length in 35 mm film */ +#define EXIFTAG_SCENECAPTURETYPE 41990 /* Scene capture type */ +#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ +#define EXIFTAG_CONTRAST 41992 /* Contrast */ +#define EXIFTAG_SATURATION 41993 /* Saturation */ +#define EXIFTAG_SHARPNESS 41994 /* Sharpness */ +#define EXIFTAG_DEVICESETTINGDESCRIPTION 41995 /* Device settings description */ +#define EXIFTAG_SUBJECTDISTANCERANGE 41996 /* Subject distance range */ +#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ +#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ +#define EXIFTAG_IMAGEUNIQUEID 42016 /* Unique image ID */ + +#endif /* _TIFF_ */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/android/x86/include/tiff/tiffconf.h b/android/x86/include/tiff/tiffconf.h new file mode 100644 index 00000000..6830ce5b --- /dev/null +++ b/android/x86/include/tiff/tiffconf.h @@ -0,0 +1,128 @@ +/* libtiff/tiffconf.h. Generated from tiffconf.h.in by configure. */ +/* + Configuration defines for installed libtiff. + This file maintained for backward compatibility. Do not use definitions + from this file in your programs. +*/ + +#ifndef _TIFFCONF_ +#define _TIFFCONF_ + +/* Signed 16-bit type */ +#define TIFF_INT16_T signed short + +/* Signed 32-bit type */ +#define TIFF_INT32_T signed int + +/* Signed 64-bit type */ +#define TIFF_INT64_T signed long long + +/* Signed 8-bit type */ +#define TIFF_INT8_T signed char + +/* Unsigned 16-bit type */ +#define TIFF_UINT16_T unsigned short + +/* Unsigned 32-bit type */ +#define TIFF_UINT32_T unsigned int + +/* Unsigned 64-bit type */ +#define TIFF_UINT64_T unsigned long long + +/* Unsigned 8-bit type */ +#define TIFF_UINT8_T unsigned char + +/* Signed size type */ +#define TIFF_SSIZE_T signed int + +/* Pointer difference type */ +#define TIFF_PTRDIFF_T ptrdiff_t + +/* Define to 1 if the system has the type `int16'. */ +/* #undef HAVE_INT16 */ + +/* Define to 1 if the system has the type `int32'. */ +/* #undef HAVE_INT32 */ + +/* Define to 1 if the system has the type `int8'. */ +/* #undef HAVE_INT8 */ + +/* Compatibility stuff. */ + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#define HOST_FILLORDER FILLORDER_LSB2MSB + +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian + (Intel) */ +#define HOST_BIGENDIAN 0 + +/* Support CCITT Group 3 & 4 algorithms */ +#define CCITT_SUPPORT 1 + +/* Support JPEG compression (requires IJG JPEG library) */ +/* #undef JPEG_SUPPORT */ + +/* Support JBIG compression (requires JBIG-KIT library) */ +/* #undef JBIG_SUPPORT */ + +/* Support LogLuv high dynamic range encoding */ +#define LOGLUV_SUPPORT 1 + +/* Support LZW algorithm */ +#define LZW_SUPPORT 1 + +/* Support NeXT 2-bit RLE algorithm */ +#define NEXT_SUPPORT 1 + +/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation + fails with unpatched IJG JPEG library) */ +/* #undef OJPEG_SUPPORT */ + +/* Support Macintosh PackBits algorithm */ +#define PACKBITS_SUPPORT 1 + +/* Support Pixar log-format algorithm (requires Zlib) */ +/* #undef PIXARLOG_SUPPORT */ + +/* Support ThunderScan 4-bit RLE algorithm */ +#define THUNDER_SUPPORT 1 + +/* Support Deflate compression */ +/* #undef ZIP_SUPPORT */ + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of ~8Kb to reduce memory usage) */ +#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP + +/* Enable SubIFD tag (330) support */ +#define SUBIFD_SUPPORT 1 + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 + +/* Support MS MDI magic number files as TIFF */ +#define MDI_SUPPORT 1 + +/* + * Feature support definitions. + * XXX: These macros are obsoleted. Don't use them in your apps! + * Macros stays here for backward compatibility and should be always defined. + */ +#define COLORIMETRY_SUPPORT +#define YCBCR_SUPPORT +#define CMYK_SUPPORT +#define ICC_SUPPORT +#define PHOTOSHOP_SUPPORT +#define IPTC_SUPPORT + +#endif /* _TIFFCONF_ */ diff --git a/android/x86/include/tiff/tiffio.h b/android/x86/include/tiff/tiffio.h new file mode 100644 index 00000000..038b6701 --- /dev/null +++ b/android/x86/include/tiff/tiffio.h @@ -0,0 +1,557 @@ +/* $Id: tiffio.h,v 1.91 2012-07-29 15:45:29 tgl Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _TIFFIO_ +#define _TIFFIO_ + +/* + * TIFF I/O Library Definitions. + */ +#include "tiff.h" +#include "tiffvers.h" + +/* + * TIFF is defined as an incomplete type to hide the + * library's internal data structures from clients. + */ +typedef struct tiff TIFF; + +/* + * The following typedefs define the intrinsic size of + * data types used in the *exported* interfaces. These + * definitions depend on the proper definition of types + * in tiff.h. Note also that the varargs interface used + * to pass tag types and values uses the types defined in + * tiff.h directly. + * + * NB: ttag_t is unsigned int and not unsigned short because + * ANSI C requires that the type before the ellipsis be a + * promoted type (i.e. one of int, unsigned int, pointer, + * or double) and because we defined pseudo-tags that are + * outside the range of legal Aldus-assigned tags. + * NB: tsize_t is int32 and not uint32 because some functions + * return -1. + * NB: toff_t is not off_t for many reasons; TIFFs max out at + * 32-bit file offsets, and BigTIFF maxes out at 64-bit + * offsets being the most important, and to ensure use of + * a consistently unsigned type across architectures. + * Prior to libtiff 4.0, this was an unsigned 32 bit type. + */ +/* + * this is the machine addressing size type, only it's signed, so make it + * int32 on 32bit machines, int64 on 64bit machines + */ +typedef TIFF_SSIZE_T tmsize_t; +typedef uint64 toff_t; /* file offset */ +/* the following are deprecated and should be replaced by their defining + counterparts */ +typedef uint32 ttag_t; /* directory tag */ +typedef uint16 tdir_t; /* directory index */ +typedef uint16 tsample_t; /* sample number */ +typedef uint32 tstrile_t; /* strip or tile number */ +typedef tstrile_t tstrip_t; /* strip number */ +typedef tstrile_t ttile_t; /* tile number */ +typedef tmsize_t tsize_t; /* i/o size in bytes */ +typedef void* tdata_t; /* image data ref */ + +#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32)) +#define __WIN32__ +#endif + +/* + * On windows you should define USE_WIN32_FILEIO if you are using tif_win32.c + * or AVOID_WIN32_FILEIO if you are using something else (like tif_unix.c). + * + * By default tif_unix.c is assumed. + */ + +#if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows) +# if !defined(__CYGWIN) && !defined(AVOID_WIN32_FILEIO) && !defined(USE_WIN32_FILEIO) +# define AVOID_WIN32_FILEIO +# endif +#endif + +#if defined(USE_WIN32_FILEIO) +# define VC_EXTRALEAN +# include <windows.h> +# ifdef __WIN32__ +DECLARE_HANDLE(thandle_t); /* Win32 file handle */ +# else +typedef HFILE thandle_t; /* client data handle */ +# endif /* __WIN32__ */ +#else +typedef void* thandle_t; /* client data handle */ +#endif /* USE_WIN32_FILEIO */ + +/* + * Flags to pass to TIFFPrintDirectory to control + * printing of data structures that are potentially + * very large. Bit-or these flags to enable printing + * multiple items. + */ +#define TIFFPRINT_NONE 0x0 /* no extra info */ +#define TIFFPRINT_STRIPS 0x1 /* strips/tiles info */ +#define TIFFPRINT_CURVES 0x2 /* color/gray response curves */ +#define TIFFPRINT_COLORMAP 0x4 /* colormap */ +#define TIFFPRINT_JPEGQTABLES 0x100 /* JPEG Q matrices */ +#define TIFFPRINT_JPEGACTABLES 0x200 /* JPEG AC tables */ +#define TIFFPRINT_JPEGDCTABLES 0x200 /* JPEG DC tables */ + +/* + * Colour conversion stuff + */ + +/* reference white */ +#define D65_X0 (95.0470F) +#define D65_Y0 (100.0F) +#define D65_Z0 (108.8827F) + +#define D50_X0 (96.4250F) +#define D50_Y0 (100.0F) +#define D50_Z0 (82.4680F) + +/* Structure for holding information about a display device. */ + +typedef unsigned char TIFFRGBValue; /* 8-bit samples */ + +typedef struct { + float d_mat[3][3]; /* XYZ -> luminance matrix */ + float d_YCR; /* Light o/p for reference white */ + float d_YCG; + float d_YCB; + uint32 d_Vrwr; /* Pixel values for ref. white */ + uint32 d_Vrwg; + uint32 d_Vrwb; + float d_Y0R; /* Residual light for black pixel */ + float d_Y0G; + float d_Y0B; + float d_gammaR; /* Gamma values for the three guns */ + float d_gammaG; + float d_gammaB; +} TIFFDisplay; + +typedef struct { /* YCbCr->RGB support */ + TIFFRGBValue* clamptab; /* range clamping table */ + int* Cr_r_tab; + int* Cb_b_tab; + int32* Cr_g_tab; + int32* Cb_g_tab; + int32* Y_tab; +} TIFFYCbCrToRGB; + +typedef struct { /* CIE Lab 1976->RGB support */ + int range; /* Size of conversion table */ +#define CIELABTORGB_TABLE_RANGE 1500 + float rstep, gstep, bstep; + float X0, Y0, Z0; /* Reference white point */ + TIFFDisplay display; + float Yr2r[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yr to r */ + float Yg2g[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yg to g */ + float Yb2b[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yb to b */ +} TIFFCIELabToRGB; + +/* + * RGBA-style image support. + */ +typedef struct _TIFFRGBAImage TIFFRGBAImage; +/* + * The image reading and conversion routines invoke + * ``put routines'' to copy/image/whatever tiles of + * raw image data. A default set of routines are + * provided to convert/copy raw image data to 8-bit + * packed ABGR format rasters. Applications can supply + * alternate routines that unpack the data into a + * different format or, for example, unpack the data + * and draw the unpacked raster on the display. + */ +typedef void (*tileContigRoutine) + (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32, + unsigned char*); +typedef void (*tileSeparateRoutine) + (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32, + unsigned char*, unsigned char*, unsigned char*, unsigned char*); +/* + * RGBA-reader state. + */ +struct _TIFFRGBAImage { + TIFF* tif; /* image handle */ + int stoponerr; /* stop on read error */ + int isContig; /* data is packed/separate */ + int alpha; /* type of alpha data present */ + uint32 width; /* image width */ + uint32 height; /* image height */ + uint16 bitspersample; /* image bits/sample */ + uint16 samplesperpixel; /* image samples/pixel */ + uint16 orientation; /* image orientation */ + uint16 req_orientation; /* requested orientation */ + uint16 photometric; /* image photometric interp */ + uint16* redcmap; /* colormap pallete */ + uint16* greencmap; + uint16* bluecmap; + /* get image data routine */ + int (*get)(TIFFRGBAImage*, uint32*, uint32, uint32); + /* put decoded strip/tile */ + union { + void (*any)(TIFFRGBAImage*); + tileContigRoutine contig; + tileSeparateRoutine separate; + } put; + TIFFRGBValue* Map; /* sample mapping array */ + uint32** BWmap; /* black&white map */ + uint32** PALmap; /* palette image map */ + TIFFYCbCrToRGB* ycbcr; /* YCbCr conversion state */ + TIFFCIELabToRGB* cielab; /* CIE L*a*b conversion state */ + + uint8* UaToAa; /* Unassociated alpha to associated alpha convertion LUT */ + uint8* Bitdepth16To8; /* LUT for conversion from 16bit to 8bit values */ + + int row_offset; + int col_offset; +}; + +/* + * Macros for extracting components from the + * packed ABGR form returned by TIFFReadRGBAImage. + */ +#define TIFFGetR(abgr) ((abgr) & 0xff) +#define TIFFGetG(abgr) (((abgr) >> 8) & 0xff) +#define TIFFGetB(abgr) (((abgr) >> 16) & 0xff) +#define TIFFGetA(abgr) (((abgr) >> 24) & 0xff) + +/* + * A CODEC is a software package that implements decoding, + * encoding, or decoding+encoding of a compression algorithm. + * The library provides a collection of builtin codecs. + * More codecs may be registered through calls to the library + * and/or the builtin implementations may be overridden. + */ +typedef int (*TIFFInitMethod)(TIFF*, int); +typedef struct { + char* name; + uint16 scheme; + TIFFInitMethod init; +} TIFFCodec; + +#include <stdio.h> +#include <stdarg.h> + +/* share internal LogLuv conversion routines? */ +#ifndef LOGLUV_PUBLIC +#define LOGLUV_PUBLIC 1 +#endif + +#if !defined(__GNUC__) && !defined(__attribute__) +# define __attribute__(x) /*nothing*/ +#endif + +#if defined(c_plusplus) || defined(__cplusplus) +extern "C" { +#endif +typedef void (*TIFFErrorHandler)(const char*, const char*, va_list); +typedef void (*TIFFErrorHandlerExt)(thandle_t, const char*, const char*, va_list); +typedef tmsize_t (*TIFFReadWriteProc)(thandle_t, void*, tmsize_t); +typedef toff_t (*TIFFSeekProc)(thandle_t, toff_t, int); +typedef int (*TIFFCloseProc)(thandle_t); +typedef toff_t (*TIFFSizeProc)(thandle_t); +typedef int (*TIFFMapFileProc)(thandle_t, void** base, toff_t* size); +typedef void (*TIFFUnmapFileProc)(thandle_t, void* base, toff_t size); +typedef void (*TIFFExtendProc)(TIFF*); + +extern const char* TIFFGetVersion(void); + +extern const TIFFCodec* TIFFFindCODEC(uint16); +extern TIFFCodec* TIFFRegisterCODEC(uint16, const char*, TIFFInitMethod); +extern void TIFFUnRegisterCODEC(TIFFCodec*); +extern int TIFFIsCODECConfigured(uint16); +extern TIFFCodec* TIFFGetConfiguredCODECs(void); + +/* + * Auxiliary functions. + */ + +extern void* _TIFFmalloc(tmsize_t s); +extern void* _TIFFrealloc(void* p, tmsize_t s); +extern void _TIFFmemset(void* p, int v, tmsize_t c); +extern void _TIFFmemcpy(void* d, const void* s, tmsize_t c); +extern int _TIFFmemcmp(const void* p1, const void* p2, tmsize_t c); +extern void _TIFFfree(void* p); + +/* +** Stuff, related to tag handling and creating custom tags. +*/ +extern int TIFFGetTagListCount( TIFF * ); +extern uint32 TIFFGetTagListEntry( TIFF *, int tag_index ); + +#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */ +#define TIFF_VARIABLE -1 /* marker for variable length tags */ +#define TIFF_SPP -2 /* marker for SamplesPerPixel tags */ +#define TIFF_VARIABLE2 -3 /* marker for uint32 var-length tags */ + +#define FIELD_CUSTOM 65 + +typedef struct _TIFFField TIFFField; +typedef struct _TIFFFieldArray TIFFFieldArray; + +extern const TIFFField* TIFFFindField(TIFF *, uint32, TIFFDataType); +extern const TIFFField* TIFFFieldWithTag(TIFF*, uint32); +extern const TIFFField* TIFFFieldWithName(TIFF*, const char *); + +extern uint32 TIFFFieldTag(const TIFFField*); +extern const char* TIFFFieldName(const TIFFField*); +extern TIFFDataType TIFFFieldDataType(const TIFFField*); +extern int TIFFFieldPassCount(const TIFFField*); +extern int TIFFFieldReadCount(const TIFFField*); +extern int TIFFFieldWriteCount(const TIFFField*); + +typedef int (*TIFFVSetMethod)(TIFF*, uint32, va_list); +typedef int (*TIFFVGetMethod)(TIFF*, uint32, va_list); +typedef void (*TIFFPrintMethod)(TIFF*, FILE*, long); + +typedef struct { + TIFFVSetMethod vsetfield; /* tag set routine */ + TIFFVGetMethod vgetfield; /* tag get routine */ + TIFFPrintMethod printdir; /* directory print routine */ +} TIFFTagMethods; + +extern TIFFTagMethods *TIFFAccessTagMethods(TIFF *); +extern void *TIFFGetClientInfo(TIFF *, const char *); +extern void TIFFSetClientInfo(TIFF *, void *, const char *); + +extern void TIFFCleanup(TIFF* tif); +extern void TIFFClose(TIFF* tif); +extern int TIFFFlush(TIFF* tif); +extern int TIFFFlushData(TIFF* tif); +extern int TIFFGetField(TIFF* tif, uint32 tag, ...); +extern int TIFFVGetField(TIFF* tif, uint32 tag, va_list ap); +extern int TIFFGetFieldDefaulted(TIFF* tif, uint32 tag, ...); +extern int TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap); +extern int TIFFReadDirectory(TIFF* tif); +extern int TIFFReadCustomDirectory(TIFF* tif, toff_t diroff, const TIFFFieldArray* infoarray); +extern int TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff); +extern uint64 TIFFScanlineSize64(TIFF* tif); +extern tmsize_t TIFFScanlineSize(TIFF* tif); +extern uint64 TIFFRasterScanlineSize64(TIFF* tif); +extern tmsize_t TIFFRasterScanlineSize(TIFF* tif); +extern uint64 TIFFStripSize64(TIFF* tif); +extern tmsize_t TIFFStripSize(TIFF* tif); +extern uint64 TIFFRawStripSize64(TIFF* tif, uint32 strip); +extern tmsize_t TIFFRawStripSize(TIFF* tif, uint32 strip); +extern uint64 TIFFVStripSize64(TIFF* tif, uint32 nrows); +extern tmsize_t TIFFVStripSize(TIFF* tif, uint32 nrows); +extern uint64 TIFFTileRowSize64(TIFF* tif); +extern tmsize_t TIFFTileRowSize(TIFF* tif); +extern uint64 TIFFTileSize64(TIFF* tif); +extern tmsize_t TIFFTileSize(TIFF* tif); +extern uint64 TIFFVTileSize64(TIFF* tif, uint32 nrows); +extern tmsize_t TIFFVTileSize(TIFF* tif, uint32 nrows); +extern uint32 TIFFDefaultStripSize(TIFF* tif, uint32 request); +extern void TIFFDefaultTileSize(TIFF*, uint32*, uint32*); +extern int TIFFFileno(TIFF*); +extern int TIFFSetFileno(TIFF*, int); +extern thandle_t TIFFClientdata(TIFF*); +extern thandle_t TIFFSetClientdata(TIFF*, thandle_t); +extern int TIFFGetMode(TIFF*); +extern int TIFFSetMode(TIFF*, int); +extern int TIFFIsTiled(TIFF*); +extern int TIFFIsByteSwapped(TIFF*); +extern int TIFFIsUpSampled(TIFF*); +extern int TIFFIsMSB2LSB(TIFF*); +extern int TIFFIsBigEndian(TIFF*); +extern TIFFReadWriteProc TIFFGetReadProc(TIFF*); +extern TIFFReadWriteProc TIFFGetWriteProc(TIFF*); +extern TIFFSeekProc TIFFGetSeekProc(TIFF*); +extern TIFFCloseProc TIFFGetCloseProc(TIFF*); +extern TIFFSizeProc TIFFGetSizeProc(TIFF*); +extern TIFFMapFileProc TIFFGetMapFileProc(TIFF*); +extern TIFFUnmapFileProc TIFFGetUnmapFileProc(TIFF*); +extern uint32 TIFFCurrentRow(TIFF*); +extern uint16 TIFFCurrentDirectory(TIFF*); +extern uint16 TIFFNumberOfDirectories(TIFF*); +extern uint64 TIFFCurrentDirOffset(TIFF*); +extern uint32 TIFFCurrentStrip(TIFF*); +extern uint32 TIFFCurrentTile(TIFF* tif); +extern int TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size); +extern int TIFFWriteBufferSetup(TIFF* tif, void* bp, tmsize_t size); +extern int TIFFSetupStrips(TIFF *); +extern int TIFFWriteCheck(TIFF*, int, const char *); +extern void TIFFFreeDirectory(TIFF*); +extern int TIFFCreateDirectory(TIFF*); +extern int TIFFCreateCustomDirectory(TIFF*,const TIFFFieldArray*); +extern int TIFFCreateEXIFDirectory(TIFF*); +extern int TIFFLastDirectory(TIFF*); +extern int TIFFSetDirectory(TIFF*, uint16); +extern int TIFFSetSubDirectory(TIFF*, uint64); +extern int TIFFUnlinkDirectory(TIFF*, uint16); +extern int TIFFSetField(TIFF*, uint32, ...); +extern int TIFFVSetField(TIFF*, uint32, va_list); +extern int TIFFUnsetField(TIFF*, uint32); +extern int TIFFWriteDirectory(TIFF *); +extern int TIFFWriteCustomDirectory(TIFF *, uint64 *); +extern int TIFFCheckpointDirectory(TIFF *); +extern int TIFFRewriteDirectory(TIFF *); + +#if defined(c_plusplus) || defined(__cplusplus) +extern void TIFFPrintDirectory(TIFF*, FILE*, long = 0); +extern int TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample = 0); +extern int TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample = 0); +extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int = 0); +extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*, + int = ORIENTATION_BOTLEFT, int = 0); +#else +extern void TIFFPrintDirectory(TIFF*, FILE*, long); +extern int TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample); +extern int TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample); +extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int); +extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*, int, int); +#endif + +extern int TIFFReadRGBAStrip(TIFF*, uint32, uint32 * ); +extern int TIFFReadRGBATile(TIFF*, uint32, uint32, uint32 * ); +extern int TIFFRGBAImageOK(TIFF*, char [1024]); +extern int TIFFRGBAImageBegin(TIFFRGBAImage*, TIFF*, int, char [1024]); +extern int TIFFRGBAImageGet(TIFFRGBAImage*, uint32*, uint32, uint32); +extern void TIFFRGBAImageEnd(TIFFRGBAImage*); +extern TIFF* TIFFOpen(const char*, const char*); +# ifdef __WIN32__ +extern TIFF* TIFFOpenW(const wchar_t*, const char*); +# endif /* __WIN32__ */ +extern TIFF* TIFFFdOpen(int, const char*, const char*); +extern TIFF* TIFFClientOpen(const char*, const char*, + thandle_t, + TIFFReadWriteProc, TIFFReadWriteProc, + TIFFSeekProc, TIFFCloseProc, + TIFFSizeProc, + TIFFMapFileProc, TIFFUnmapFileProc); +extern const char* TIFFFileName(TIFF*); +extern const char* TIFFSetFileName(TIFF*, const char *); +extern void TIFFError(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3))); +extern void TIFFErrorExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4))); +extern void TIFFWarning(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3))); +extern void TIFFWarningExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4))); +extern TIFFErrorHandler TIFFSetErrorHandler(TIFFErrorHandler); +extern TIFFErrorHandlerExt TIFFSetErrorHandlerExt(TIFFErrorHandlerExt); +extern TIFFErrorHandler TIFFSetWarningHandler(TIFFErrorHandler); +extern TIFFErrorHandlerExt TIFFSetWarningHandlerExt(TIFFErrorHandlerExt); +extern TIFFExtendProc TIFFSetTagExtender(TIFFExtendProc); +extern uint32 TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s); +extern int TIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s); +extern uint32 TIFFNumberOfTiles(TIFF*); +extern tmsize_t TIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s); +extern tmsize_t TIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s); +extern uint32 TIFFComputeStrip(TIFF*, uint32, uint16); +extern uint32 TIFFNumberOfStrips(TIFF*); +extern tmsize_t TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size); +extern tmsize_t TIFFReadRawStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size); +extern tmsize_t TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size); +extern tmsize_t TIFFReadRawTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size); +extern tmsize_t TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc); +extern tmsize_t TIFFWriteRawStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc); +extern tmsize_t TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc); +extern tmsize_t TIFFWriteRawTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc); +extern int TIFFDataWidth(TIFFDataType); /* table of tag datatype widths */ +extern void TIFFSetWriteOffset(TIFF* tif, toff_t off); +extern void TIFFSwabShort(uint16*); +extern void TIFFSwabLong(uint32*); +extern void TIFFSwabLong8(uint64*); +extern void TIFFSwabFloat(float*); +extern void TIFFSwabDouble(double*); +extern void TIFFSwabArrayOfShort(uint16* wp, tmsize_t n); +extern void TIFFSwabArrayOfTriples(uint8* tp, tmsize_t n); +extern void TIFFSwabArrayOfLong(uint32* lp, tmsize_t n); +extern void TIFFSwabArrayOfLong8(uint64* lp, tmsize_t n); +extern void TIFFSwabArrayOfFloat(float* fp, tmsize_t n); +extern void TIFFSwabArrayOfDouble(double* dp, tmsize_t n); +extern void TIFFReverseBits(uint8* cp, tmsize_t n); +extern const unsigned char* TIFFGetBitRevTable(int); + +#ifdef LOGLUV_PUBLIC +#define U_NEU 0.210526316 +#define V_NEU 0.473684211 +#define UVSCALE 410. +extern double LogL16toY(int); +extern double LogL10toY(int); +extern void XYZtoRGB24(float*, uint8*); +extern int uv_decode(double*, double*, int); +extern void LogLuv24toXYZ(uint32, float*); +extern void LogLuv32toXYZ(uint32, float*); +#if defined(c_plusplus) || defined(__cplusplus) +extern int LogL16fromY(double, int = SGILOGENCODE_NODITHER); +extern int LogL10fromY(double, int = SGILOGENCODE_NODITHER); +extern int uv_encode(double, double, int = SGILOGENCODE_NODITHER); +extern uint32 LogLuv24fromXYZ(float*, int = SGILOGENCODE_NODITHER); +extern uint32 LogLuv32fromXYZ(float*, int = SGILOGENCODE_NODITHER); +#else +extern int LogL16fromY(double, int); +extern int LogL10fromY(double, int); +extern int uv_encode(double, double, int); +extern uint32 LogLuv24fromXYZ(float*, int); +extern uint32 LogLuv32fromXYZ(float*, int); +#endif +#endif /* LOGLUV_PUBLIC */ + +extern int TIFFCIELabToRGBInit(TIFFCIELabToRGB*, const TIFFDisplay *, float*); +extern void TIFFCIELabToXYZ(TIFFCIELabToRGB *, uint32, int32, int32, + float *, float *, float *); +extern void TIFFXYZToRGB(TIFFCIELabToRGB *, float, float, float, + uint32 *, uint32 *, uint32 *); + +extern int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB*, float*, float*); +extern void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *, uint32, int32, int32, + uint32 *, uint32 *, uint32 *); + +/**************************************************************************** + * O B S O L E T E D I N T E R F A C E S + * + * Don't use this stuff in your applications, it may be removed in the future + * libtiff versions. + ****************************************************************************/ +typedef struct { + ttag_t field_tag; /* field's tag */ + short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */ + short field_writecount; /* write count/TIFF_VARIABLE */ + TIFFDataType field_type; /* type of associated data */ + unsigned short field_bit; /* bit in fieldsset bit vector */ + unsigned char field_oktochange; /* if true, can change while writing */ + unsigned char field_passcount; /* if true, pass dir count on set */ + char *field_name; /* ASCII name */ +} TIFFFieldInfo; + +extern int TIFFMergeFieldInfo(TIFF*, const TIFFFieldInfo[], uint32); + +#if defined(c_plusplus) || defined(__cplusplus) +} +#endif + +#endif /* _TIFFIO_ */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/android/x86/include/tiff/tiffvers.h b/android/x86/include/tiff/tiffvers.h new file mode 100644 index 00000000..e965814b --- /dev/null +++ b/android/x86/include/tiff/tiffvers.h @@ -0,0 +1,9 @@ +#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.6\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." +/* + * This define can be used in code that requires + * compilation-related definitions specific to a + * version or versions of the library. Runtime + * version checking should be done based on the + * string returned by TIFFGetVersion. + */ +#define TIFFLIB_VERSION 20150912 diff --git a/android/x86/include/uv/pthread-barrier.h b/android/x86/include/uv/pthread-barrier.h new file mode 100644 index 00000000..900ebedd --- /dev/null +++ b/android/x86/include/uv/pthread-barrier.h @@ -0,0 +1,68 @@ +/* +Copyright (c) 2016, Kari Tristan Helgason <kthelgason@gmail.com> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef _UV_PTHREAD_BARRIER_ +#define _UV_PTHREAD_BARRIER_ +#include <errno.h> +#include <pthread.h> +#if !defined(__MVS__) +#include <semaphore.h> /* sem_t */ +#endif + +#define PTHREAD_BARRIER_SERIAL_THREAD 0x12345 + +/* + * To maintain ABI compatibility with + * libuv v1.x struct is padded according + * to target platform + */ +#if defined(__ANDROID__) +# define UV_BARRIER_STRUCT_PADDING \ + sizeof(pthread_mutex_t) + \ + sizeof(pthread_cond_t) + \ + sizeof(unsigned int) - \ + sizeof(void *) +#elif defined(__APPLE__) +# define UV_BARRIER_STRUCT_PADDING \ + sizeof(pthread_mutex_t) + \ + 2 * sizeof(sem_t) + \ + 2 * sizeof(unsigned int) - \ + sizeof(void *) +#else +# define UV_BARRIER_STRUCT_PADDING 0 +#endif + +typedef struct { + pthread_mutex_t mutex; + pthread_cond_t cond; + unsigned threshold; + unsigned in; + unsigned out; +} _uv_barrier; + +typedef struct { + _uv_barrier* b; + char _pad[UV_BARRIER_STRUCT_PADDING]; +} pthread_barrier_t; + +int pthread_barrier_init(pthread_barrier_t* barrier, + const void* barrier_attr, + unsigned count); + +int pthread_barrier_wait(pthread_barrier_t* barrier); +int pthread_barrier_destroy(pthread_barrier_t *barrier); + +#endif /* _UV_PTHREAD_BARRIER_ */ diff --git a/android/x86/include/uv/stdint-msvc2008.h b/android/x86/include/uv/stdint-msvc2008.h new file mode 100644 index 00000000..d02608a5 --- /dev/null +++ b/android/x86/include/uv/stdint-msvc2008.h @@ -0,0 +1,247 @@ +// ISO C9x compliant stdint.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006-2008 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. The name of the author may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_STDINT_H_ // [ +#define _MSC_STDINT_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include <limits.h> + +// For Visual Studio 6 in C++ mode and for many Visual Studio versions when +// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}' +// or compiler give many errors like this: +// error C2733: second C linkage of overloaded function 'wmemchr' not allowed +#ifdef __cplusplus +extern "C" { +#endif +# include <wchar.h> +#ifdef __cplusplus +} +#endif + +// Define _W64 macros to mark types changing their size, like intptr_t. +#ifndef _W64 +# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 +# define _W64 __w64 +# else +# define _W64 +# endif +#endif + + +// 7.18.1 Integer types + +// 7.18.1.1 Exact-width integer types + +// Visual Studio 6 and Embedded Visual C++ 4 doesn't +// realize that, e.g. char has the same size as __int8 +// so we give up on __intX for them. +#if (_MSC_VER < 1300) + typedef signed char int8_t; + typedef signed short int16_t; + typedef signed int int32_t; + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; +#else + typedef signed __int8 int8_t; + typedef signed __int16 int16_t; + typedef signed __int32 int32_t; + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; +#endif +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; + + +// 7.18.1.2 Minimum-width integer types +typedef int8_t int_least8_t; +typedef int16_t int_least16_t; +typedef int32_t int_least32_t; +typedef int64_t int_least64_t; +typedef uint8_t uint_least8_t; +typedef uint16_t uint_least16_t; +typedef uint32_t uint_least32_t; +typedef uint64_t uint_least64_t; + +// 7.18.1.3 Fastest minimum-width integer types +typedef int8_t int_fast8_t; +typedef int16_t int_fast16_t; +typedef int32_t int_fast32_t; +typedef int64_t int_fast64_t; +typedef uint8_t uint_fast8_t; +typedef uint16_t uint_fast16_t; +typedef uint32_t uint_fast32_t; +typedef uint64_t uint_fast64_t; + +// 7.18.1.4 Integer types capable of holding object pointers +#ifdef _WIN64 // [ + typedef signed __int64 intptr_t; + typedef unsigned __int64 uintptr_t; +#else // _WIN64 ][ + typedef _W64 signed int intptr_t; + typedef _W64 unsigned int uintptr_t; +#endif // _WIN64 ] + +// 7.18.1.5 Greatest-width integer types +typedef int64_t intmax_t; +typedef uint64_t uintmax_t; + + +// 7.18.2 Limits of specified-width integer types + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 + +// 7.18.2.1 Limits of exact-width integer types +#define INT8_MIN ((int8_t)_I8_MIN) +#define INT8_MAX _I8_MAX +#define INT16_MIN ((int16_t)_I16_MIN) +#define INT16_MAX _I16_MAX +#define INT32_MIN ((int32_t)_I32_MIN) +#define INT32_MAX _I32_MAX +#define INT64_MIN ((int64_t)_I64_MIN) +#define INT64_MAX _I64_MAX +#define UINT8_MAX _UI8_MAX +#define UINT16_MAX _UI16_MAX +#define UINT32_MAX _UI32_MAX +#define UINT64_MAX _UI64_MAX + +// 7.18.2.2 Limits of minimum-width integer types +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +// 7.18.2.3 Limits of fastest minimum-width integer types +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST16_MAX INT16_MAX +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST64_MAX INT64_MAX +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_FAST16_MAX UINT16_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX + +// 7.18.2.4 Limits of integer types capable of holding object pointers +#ifdef _WIN64 // [ +# define INTPTR_MIN INT64_MIN +# define INTPTR_MAX INT64_MAX +# define UINTPTR_MAX UINT64_MAX +#else // _WIN64 ][ +# define INTPTR_MIN INT32_MIN +# define INTPTR_MAX INT32_MAX +# define UINTPTR_MAX UINT32_MAX +#endif // _WIN64 ] + +// 7.18.2.5 Limits of greatest-width integer types +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +// 7.18.3 Limits of other integer types + +#ifdef _WIN64 // [ +# define PTRDIFF_MIN _I64_MIN +# define PTRDIFF_MAX _I64_MAX +#else // _WIN64 ][ +# define PTRDIFF_MIN _I32_MIN +# define PTRDIFF_MAX _I32_MAX +#endif // _WIN64 ] + +#define SIG_ATOMIC_MIN INT_MIN +#define SIG_ATOMIC_MAX INT_MAX + +#ifndef SIZE_MAX // [ +# ifdef _WIN64 // [ +# define SIZE_MAX _UI64_MAX +# else // _WIN64 ][ +# define SIZE_MAX _UI32_MAX +# endif // _WIN64 ] +#endif // SIZE_MAX ] + +// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h> +#ifndef WCHAR_MIN // [ +# define WCHAR_MIN 0 +#endif // WCHAR_MIN ] +#ifndef WCHAR_MAX // [ +# define WCHAR_MAX _UI16_MAX +#endif // WCHAR_MAX ] + +#define WINT_MIN 0 +#define WINT_MAX _UI16_MAX + +#endif // __STDC_LIMIT_MACROS ] + + +// 7.18.4 Limits of other integer types + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 + +// 7.18.4.1 Macros for minimum-width integer constants + +#define INT8_C(val) val##i8 +#define INT16_C(val) val##i16 +#define INT32_C(val) val##i32 +#define INT64_C(val) val##i64 + +#define UINT8_C(val) val##ui8 +#define UINT16_C(val) val##ui16 +#define UINT32_C(val) val##ui32 +#define UINT64_C(val) val##ui64 + +// 7.18.4.2 Macros for greatest-width integer constants +#define INTMAX_C INT64_C +#define UINTMAX_C UINT64_C + +#endif // __STDC_CONSTANT_MACROS ] + + +#endif // _MSC_STDINT_H_ ] diff --git a/android/x86/include/uv/tree.h b/android/x86/include/uv/tree.h new file mode 100644 index 00000000..f936416e --- /dev/null +++ b/android/x86/include/uv/tree.h @@ -0,0 +1,768 @@ +/*- + * Copyright 2002 Niels Provos <provos@citi.umich.edu> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef UV_TREE_H_ +#define UV_TREE_H_ + +#ifndef UV__UNUSED +# if __GNUC__ +# define UV__UNUSED __attribute__((unused)) +# else +# define UV__UNUSED +# endif +#endif + +/* + * This file defines data structures for different types of trees: + * splay trees and red-black trees. + * + * A splay tree is a self-organizing data structure. Every operation + * on the tree causes a splay to happen. The splay moves the requested + * node to the root of the tree and partly rebalances it. + * + * This has the benefit that request locality causes faster lookups as + * the requested nodes move to the top of the tree. On the other hand, + * every lookup causes memory writes. + * + * The Balance Theorem bounds the total access time for m operations + * and n inserts on an initially empty tree as O((m + n)lg n). The + * amortized cost for a sequence of m accesses to a splay tree is O(lg n); + * + * A red-black tree is a binary search tree with the node color as an + * extra attribute. It fulfills a set of conditions: + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. + * + * Every operation on a red-black tree is bounded as O(lg n). + * The maximum height of a red-black tree is 2lg (n+1). + */ + +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} + +#define SPLAY_INITIALIZER(root) \ + { NULL } + +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} + +#define SPLAY_LEFT(elm, field) (elm)->field.spe_left +#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define SPLAY_ROOT(head) (head)->sph_root +#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) + +/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field); \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ + +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ +} + +/* Main splay operation. + * Moves node close to the key of elm to top + */ +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field); \ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ + \ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL; \ + __left = __right = &__node; \ + \ + while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) \ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL) \ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_SPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + \ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL; \ + __left = __right = &__node; \ + \ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) \ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL) \ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} + +#define SPLAY_NEGINF -1 +#define SPLAY_INF 1 + +#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) +#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) +#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) +#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) + +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = SPLAY_NEXT(name, head, x)) + +/* Macros that define a red-black tree */ +#define RB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ +} + +#define RB_INITIALIZER(root) \ + { NULL } + +#define RB_INIT(root) do { \ + (root)->rbh_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define RB_BLACK 0 +#define RB_RED 1 +#define RB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ +} + +#define RB_LEFT(elm, field) (elm)->field.rbe_left +#define RB_RIGHT(elm, field) (elm)->field.rbe_right +#define RB_PARENT(elm, field) (elm)->field.rbe_parent +#define RB_COLOR(elm, field) (elm)->field.rbe_color +#define RB_ROOT(head) (head)->rbh_root +#define RB_EMPTY(head) (RB_ROOT(head) == NULL) + +#define RB_SET(elm, parent, field) do { \ + RB_PARENT(elm, field) = parent; \ + RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ + RB_COLOR(elm, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#define RB_SET_BLACKRED(black, red, field) do { \ + RB_COLOR(black, field) = RB_BLACK; \ + RB_COLOR(red, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#ifndef RB_AUGMENT +#define RB_AUGMENT(x) do {} while (0) +#endif + +#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = RB_RIGHT(elm, field); \ + if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \ + RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_LEFT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \ + RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_RIGHT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ +#define RB_PROTOTYPE(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) +#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp, UV__UNUSED static) +#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ +attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ +attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ +attr struct type *name##_RB_REMOVE(struct name *, struct type *); \ +attr struct type *name##_RB_INSERT(struct name *, struct type *); \ +attr struct type *name##_RB_FIND(struct name *, struct type *); \ +attr struct type *name##_RB_NFIND(struct name *, struct type *); \ +attr struct type *name##_RB_NEXT(struct type *); \ +attr struct type *name##_RB_PREV(struct type *); \ +attr struct type *name##_RB_MINMAX(struct name *, int); \ + \ + +/* Main rb operation. + * Moves node close to the key of elm to top + */ +#define RB_GENERATE(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp,) +#define RB_GENERATE_STATIC(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp, UV__UNUSED static) +#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ +attr void \ +name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = RB_PARENT(elm, field)) != NULL && \ + RB_COLOR(parent, field) == RB_RED) { \ + gparent = RB_PARENT(parent, field); \ + if (parent == RB_LEFT(gparent, field)) { \ + tmp = RB_RIGHT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field); \ + elm = gparent; \ + continue; \ + } \ + if (RB_RIGHT(parent, field) == elm) { \ + RB_ROTATE_LEFT(head, parent, tmp, field); \ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = RB_LEFT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field); \ + elm = gparent; \ + continue; \ + } \ + if (RB_LEFT(parent, field) == elm) { \ + RB_ROTATE_RIGHT(head, parent, tmp, field); \ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + RB_COLOR(head->rbh_root, field) = RB_BLACK; \ +} \ + \ +attr void \ +name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, \ + struct type *elm) \ +{ \ + struct type *tmp; \ + while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ + elm != RB_ROOT(head)) { \ + if (RB_LEFT(parent, field) == elm) { \ + tmp = RB_RIGHT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_LEFT(head, parent, tmp, field); \ + tmp = RB_RIGHT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) && \ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) { \ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) { \ + struct type *oleft; \ + if ((oleft = RB_LEFT(tmp, field)) \ + != NULL) \ + RB_COLOR(oleft, field) = RB_BLACK; \ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_RIGHT(head, tmp, oleft, field); \ + tmp = RB_RIGHT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field); \ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_RIGHT(tmp, field)) \ + RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK; \ + RB_ROTATE_LEFT(head, parent, tmp, field); \ + elm = RB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = RB_LEFT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_RIGHT(head, parent, tmp, field); \ + tmp = RB_LEFT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) && \ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) { \ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) { \ + struct type *oright; \ + if ((oright = RB_RIGHT(tmp, field)) \ + != NULL) \ + RB_COLOR(oright, field) = RB_BLACK; \ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_LEFT(head, tmp, oright, field); \ + tmp = RB_LEFT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field); \ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_LEFT(tmp, field)) \ + RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK; \ + RB_ROTATE_RIGHT(head, parent, tmp, field); \ + elm = RB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + RB_COLOR(elm, field) = RB_BLACK; \ +} \ + \ +attr struct type * \ +name##_RB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (RB_LEFT(elm, field) == NULL) \ + child = RB_RIGHT(elm, field); \ + else if (RB_RIGHT(elm, field) == NULL) \ + child = RB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = RB_RIGHT(elm, field); \ + while ((left = RB_LEFT(elm, field)) != NULL) \ + elm = left; \ + child = RB_RIGHT(elm, field); \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ + if (RB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (RB_PARENT(old, field)) { \ + if (RB_LEFT(RB_PARENT(old, field), field) == old) \ + RB_LEFT(RB_PARENT(old, field), field) = elm; \ + else \ + RB_RIGHT(RB_PARENT(old, field), field) = elm; \ + RB_AUGMENT(RB_PARENT(old, field)); \ + } else \ + RB_ROOT(head) = elm; \ + RB_PARENT(RB_LEFT(old, field), field) = elm; \ + if (RB_RIGHT(old, field)) \ + RB_PARENT(RB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + RB_AUGMENT(left); \ + } while ((left = RB_PARENT(left, field)) != NULL); \ + } \ + goto color; \ + } \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ +color: \ + if (color == RB_BLACK) \ + name##_RB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + \ +/* Inserts a node into the RB tree */ \ +attr struct type * \ +name##_RB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = RB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + RB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + RB_LEFT(parent, field) = elm; \ + else \ + RB_RIGHT(parent, field) = elm; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = elm; \ + name##_RB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} \ + \ +/* Finds the node with the same key as elm */ \ +attr struct type * \ +name##_RB_FIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} \ + \ +/* Finds the first node greater than or equal to the search key */ \ +attr struct type * \ +name##_RB_NFIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *res = NULL; \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) { \ + res = tmp; \ + tmp = RB_LEFT(tmp, field); \ + } \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (res); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_NEXT(struct type *elm) \ +{ \ + if (RB_RIGHT(elm, field)) { \ + elm = RB_RIGHT(elm, field); \ + while (RB_LEFT(elm, field)) \ + elm = RB_LEFT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_PREV(struct type *elm) \ +{ \ + if (RB_LEFT(elm, field)) { \ + elm = RB_LEFT(elm, field); \ + while (RB_RIGHT(elm, field)) \ + elm = RB_RIGHT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +attr struct type * \ +name##_RB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = RB_LEFT(tmp, field); \ + else \ + tmp = RB_RIGHT(tmp, field); \ + } \ + return (parent); \ +} + +#define RB_NEGINF -1 +#define RB_INF 1 + +#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) +#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) +#define RB_FIND(name, x, y) name##_RB_FIND(x, y) +#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) +#define RB_NEXT(name, x, y) name##_RB_NEXT(y) +#define RB_PREV(name, x, y) name##_RB_PREV(y) +#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) +#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) + +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) + +#define RB_FOREACH_FROM(x, name, y) \ + for ((x) = (y); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \ + (x) = (y)) + +#define RB_FOREACH_SAFE(x, name, head, y) \ + for ((x) = RB_MIN(name, head); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE(x, name, head) \ + for ((x) = RB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_RB_PREV(x)) + +#define RB_FOREACH_REVERSE_FROM(x, name, y) \ + for ((x) = (y); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ + for ((x) = RB_MAX(name, head); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \ + (x) = (y)) + +#endif /* UV_TREE_H_ */ diff --git a/android/x86/include/uv/uv-aix.h b/android/x86/include/uv/uv-aix.h new file mode 100644 index 00000000..7dc992fa --- /dev/null +++ b/android/x86/include/uv/uv-aix.h @@ -0,0 +1,32 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_AIX_H +#define UV_AIX_H + +#define UV_PLATFORM_LOOP_FIELDS \ + int fs_fd; \ + +#define UV_PLATFORM_FS_EVENT_FIELDS \ + uv__io_t event_watcher; \ + char *dir_filename; \ + +#endif /* UV_AIX_H */ diff --git a/android/x86/include/uv/uv-bsd.h b/android/x86/include/uv/uv-bsd.h new file mode 100644 index 00000000..2d72b3d7 --- /dev/null +++ b/android/x86/include/uv/uv-bsd.h @@ -0,0 +1,34 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_BSD_H +#define UV_BSD_H + +#define UV_PLATFORM_FS_EVENT_FIELDS \ + uv__io_t event_watcher; \ + +#define UV_IO_PRIVATE_PLATFORM_FIELDS \ + int rcount; \ + int wcount; \ + +#define UV_HAVE_KQUEUE 1 + +#endif /* UV_BSD_H */ diff --git a/android/x86/include/uv/uv-darwin.h b/android/x86/include/uv/uv-darwin.h new file mode 100644 index 00000000..d2264158 --- /dev/null +++ b/android/x86/include/uv/uv-darwin.h @@ -0,0 +1,61 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_DARWIN_H +#define UV_DARWIN_H + +#if defined(__APPLE__) && defined(__MACH__) +# include <mach/mach.h> +# include <mach/task.h> +# include <mach/semaphore.h> +# include <TargetConditionals.h> +# define UV_PLATFORM_SEM_T semaphore_t +#endif + +#define UV_IO_PRIVATE_PLATFORM_FIELDS \ + int rcount; \ + int wcount; \ + +#define UV_PLATFORM_LOOP_FIELDS \ + uv_thread_t cf_thread; \ + void* _cf_reserved; \ + void* cf_state; \ + uv_mutex_t cf_mutex; \ + uv_sem_t cf_sem; \ + void* cf_signals[2]; \ + +#define UV_PLATFORM_FS_EVENT_FIELDS \ + uv__io_t event_watcher; \ + char* realpath; \ + int realpath_len; \ + int cf_flags; \ + uv_async_t* cf_cb; \ + void* cf_events[2]; \ + void* cf_member[2]; \ + int cf_error; \ + uv_mutex_t cf_mutex; \ + +#define UV_STREAM_PRIVATE_PLATFORM_FIELDS \ + void* select; \ + +#define UV_HAVE_KQUEUE 1 + +#endif /* UV_DARWIN_H */ diff --git a/android/x86/include/uv/uv-errno.h b/android/x86/include/uv/uv-errno.h new file mode 100644 index 00000000..f1371517 --- /dev/null +++ b/android/x86/include/uv/uv-errno.h @@ -0,0 +1,419 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_ERRNO_H_ +#define UV_ERRNO_H_ + +#include <errno.h> + +#define UV__EOF (-4095) +#define UV__UNKNOWN (-4094) + +#define UV__EAI_ADDRFAMILY (-3000) +#define UV__EAI_AGAIN (-3001) +#define UV__EAI_BADFLAGS (-3002) +#define UV__EAI_CANCELED (-3003) +#define UV__EAI_FAIL (-3004) +#define UV__EAI_FAMILY (-3005) +#define UV__EAI_MEMORY (-3006) +#define UV__EAI_NODATA (-3007) +#define UV__EAI_NONAME (-3008) +#define UV__EAI_OVERFLOW (-3009) +#define UV__EAI_SERVICE (-3010) +#define UV__EAI_SOCKTYPE (-3011) +#define UV__EAI_BADHINTS (-3013) +#define UV__EAI_PROTOCOL (-3014) + +/* Only map to the system errno on non-Windows platforms. It's apparently + * a fairly common practice for Windows programmers to redefine errno codes. + */ +#if defined(E2BIG) && !defined(_WIN32) +# define UV__E2BIG (-E2BIG) +#else +# define UV__E2BIG (-4093) +#endif + +#if defined(EACCES) && !defined(_WIN32) +# define UV__EACCES (-EACCES) +#else +# define UV__EACCES (-4092) +#endif + +#if defined(EADDRINUSE) && !defined(_WIN32) +# define UV__EADDRINUSE (-EADDRINUSE) +#else +# define UV__EADDRINUSE (-4091) +#endif + +#if defined(EADDRNOTAVAIL) && !defined(_WIN32) +# define UV__EADDRNOTAVAIL (-EADDRNOTAVAIL) +#else +# define UV__EADDRNOTAVAIL (-4090) +#endif + +#if defined(EAFNOSUPPORT) && !defined(_WIN32) +# define UV__EAFNOSUPPORT (-EAFNOSUPPORT) +#else +# define UV__EAFNOSUPPORT (-4089) +#endif + +#if defined(EAGAIN) && !defined(_WIN32) +# define UV__EAGAIN (-EAGAIN) +#else +# define UV__EAGAIN (-4088) +#endif + +#if defined(EALREADY) && !defined(_WIN32) +# define UV__EALREADY (-EALREADY) +#else +# define UV__EALREADY (-4084) +#endif + +#if defined(EBADF) && !defined(_WIN32) +# define UV__EBADF (-EBADF) +#else +# define UV__EBADF (-4083) +#endif + +#if defined(EBUSY) && !defined(_WIN32) +# define UV__EBUSY (-EBUSY) +#else +# define UV__EBUSY (-4082) +#endif + +#if defined(ECANCELED) && !defined(_WIN32) +# define UV__ECANCELED (-ECANCELED) +#else +# define UV__ECANCELED (-4081) +#endif + +#if defined(ECHARSET) && !defined(_WIN32) +# define UV__ECHARSET (-ECHARSET) +#else +# define UV__ECHARSET (-4080) +#endif + +#if defined(ECONNABORTED) && !defined(_WIN32) +# define UV__ECONNABORTED (-ECONNABORTED) +#else +# define UV__ECONNABORTED (-4079) +#endif + +#if defined(ECONNREFUSED) && !defined(_WIN32) +# define UV__ECONNREFUSED (-ECONNREFUSED) +#else +# define UV__ECONNREFUSED (-4078) +#endif + +#if defined(ECONNRESET) && !defined(_WIN32) +# define UV__ECONNRESET (-ECONNRESET) +#else +# define UV__ECONNRESET (-4077) +#endif + +#if defined(EDESTADDRREQ) && !defined(_WIN32) +# define UV__EDESTADDRREQ (-EDESTADDRREQ) +#else +# define UV__EDESTADDRREQ (-4076) +#endif + +#if defined(EEXIST) && !defined(_WIN32) +# define UV__EEXIST (-EEXIST) +#else +# define UV__EEXIST (-4075) +#endif + +#if defined(EFAULT) && !defined(_WIN32) +# define UV__EFAULT (-EFAULT) +#else +# define UV__EFAULT (-4074) +#endif + +#if defined(EHOSTUNREACH) && !defined(_WIN32) +# define UV__EHOSTUNREACH (-EHOSTUNREACH) +#else +# define UV__EHOSTUNREACH (-4073) +#endif + +#if defined(EINTR) && !defined(_WIN32) +# define UV__EINTR (-EINTR) +#else +# define UV__EINTR (-4072) +#endif + +#if defined(EINVAL) && !defined(_WIN32) +# define UV__EINVAL (-EINVAL) +#else +# define UV__EINVAL (-4071) +#endif + +#if defined(EIO) && !defined(_WIN32) +# define UV__EIO (-EIO) +#else +# define UV__EIO (-4070) +#endif + +#if defined(EISCONN) && !defined(_WIN32) +# define UV__EISCONN (-EISCONN) +#else +# define UV__EISCONN (-4069) +#endif + +#if defined(EISDIR) && !defined(_WIN32) +# define UV__EISDIR (-EISDIR) +#else +# define UV__EISDIR (-4068) +#endif + +#if defined(ELOOP) && !defined(_WIN32) +# define UV__ELOOP (-ELOOP) +#else +# define UV__ELOOP (-4067) +#endif + +#if defined(EMFILE) && !defined(_WIN32) +# define UV__EMFILE (-EMFILE) +#else +# define UV__EMFILE (-4066) +#endif + +#if defined(EMSGSIZE) && !defined(_WIN32) +# define UV__EMSGSIZE (-EMSGSIZE) +#else +# define UV__EMSGSIZE (-4065) +#endif + +#if defined(ENAMETOOLONG) && !defined(_WIN32) +# define UV__ENAMETOOLONG (-ENAMETOOLONG) +#else +# define UV__ENAMETOOLONG (-4064) +#endif + +#if defined(ENETDOWN) && !defined(_WIN32) +# define UV__ENETDOWN (-ENETDOWN) +#else +# define UV__ENETDOWN (-4063) +#endif + +#if defined(ENETUNREACH) && !defined(_WIN32) +# define UV__ENETUNREACH (-ENETUNREACH) +#else +# define UV__ENETUNREACH (-4062) +#endif + +#if defined(ENFILE) && !defined(_WIN32) +# define UV__ENFILE (-ENFILE) +#else +# define UV__ENFILE (-4061) +#endif + +#if defined(ENOBUFS) && !defined(_WIN32) +# define UV__ENOBUFS (-ENOBUFS) +#else +# define UV__ENOBUFS (-4060) +#endif + +#if defined(ENODEV) && !defined(_WIN32) +# define UV__ENODEV (-ENODEV) +#else +# define UV__ENODEV (-4059) +#endif + +#if defined(ENOENT) && !defined(_WIN32) +# define UV__ENOENT (-ENOENT) +#else +# define UV__ENOENT (-4058) +#endif + +#if defined(ENOMEM) && !defined(_WIN32) +# define UV__ENOMEM (-ENOMEM) +#else +# define UV__ENOMEM (-4057) +#endif + +#if defined(ENONET) && !defined(_WIN32) +# define UV__ENONET (-ENONET) +#else +# define UV__ENONET (-4056) +#endif + +#if defined(ENOSPC) && !defined(_WIN32) +# define UV__ENOSPC (-ENOSPC) +#else +# define UV__ENOSPC (-4055) +#endif + +#if defined(ENOSYS) && !defined(_WIN32) +# define UV__ENOSYS (-ENOSYS) +#else +# define UV__ENOSYS (-4054) +#endif + +#if defined(ENOTCONN) && !defined(_WIN32) +# define UV__ENOTCONN (-ENOTCONN) +#else +# define UV__ENOTCONN (-4053) +#endif + +#if defined(ENOTDIR) && !defined(_WIN32) +# define UV__ENOTDIR (-ENOTDIR) +#else +# define UV__ENOTDIR (-4052) +#endif + +#if defined(ENOTEMPTY) && !defined(_WIN32) +# define UV__ENOTEMPTY (-ENOTEMPTY) +#else +# define UV__ENOTEMPTY (-4051) +#endif + +#if defined(ENOTSOCK) && !defined(_WIN32) +# define UV__ENOTSOCK (-ENOTSOCK) +#else +# define UV__ENOTSOCK (-4050) +#endif + +#if defined(ENOTSUP) && !defined(_WIN32) +# define UV__ENOTSUP (-ENOTSUP) +#else +# define UV__ENOTSUP (-4049) +#endif + +#if defined(EPERM) && !defined(_WIN32) +# define UV__EPERM (-EPERM) +#else +# define UV__EPERM (-4048) +#endif + +#if defined(EPIPE) && !defined(_WIN32) +# define UV__EPIPE (-EPIPE) +#else +# define UV__EPIPE (-4047) +#endif + +#if defined(EPROTO) && !defined(_WIN32) +# define UV__EPROTO (-EPROTO) +#else +# define UV__EPROTO (-4046) +#endif + +#if defined(EPROTONOSUPPORT) && !defined(_WIN32) +# define UV__EPROTONOSUPPORT (-EPROTONOSUPPORT) +#else +# define UV__EPROTONOSUPPORT (-4045) +#endif + +#if defined(EPROTOTYPE) && !defined(_WIN32) +# define UV__EPROTOTYPE (-EPROTOTYPE) +#else +# define UV__EPROTOTYPE (-4044) +#endif + +#if defined(EROFS) && !defined(_WIN32) +# define UV__EROFS (-EROFS) +#else +# define UV__EROFS (-4043) +#endif + +#if defined(ESHUTDOWN) && !defined(_WIN32) +# define UV__ESHUTDOWN (-ESHUTDOWN) +#else +# define UV__ESHUTDOWN (-4042) +#endif + +#if defined(ESPIPE) && !defined(_WIN32) +# define UV__ESPIPE (-ESPIPE) +#else +# define UV__ESPIPE (-4041) +#endif + +#if defined(ESRCH) && !defined(_WIN32) +# define UV__ESRCH (-ESRCH) +#else +# define UV__ESRCH (-4040) +#endif + +#if defined(ETIMEDOUT) && !defined(_WIN32) +# define UV__ETIMEDOUT (-ETIMEDOUT) +#else +# define UV__ETIMEDOUT (-4039) +#endif + +#if defined(ETXTBSY) && !defined(_WIN32) +# define UV__ETXTBSY (-ETXTBSY) +#else +# define UV__ETXTBSY (-4038) +#endif + +#if defined(EXDEV) && !defined(_WIN32) +# define UV__EXDEV (-EXDEV) +#else +# define UV__EXDEV (-4037) +#endif + +#if defined(EFBIG) && !defined(_WIN32) +# define UV__EFBIG (-EFBIG) +#else +# define UV__EFBIG (-4036) +#endif + +#if defined(ENOPROTOOPT) && !defined(_WIN32) +# define UV__ENOPROTOOPT (-ENOPROTOOPT) +#else +# define UV__ENOPROTOOPT (-4035) +#endif + +#if defined(ERANGE) && !defined(_WIN32) +# define UV__ERANGE (-ERANGE) +#else +# define UV__ERANGE (-4034) +#endif + +#if defined(ENXIO) && !defined(_WIN32) +# define UV__ENXIO (-ENXIO) +#else +# define UV__ENXIO (-4033) +#endif + +#if defined(EMLINK) && !defined(_WIN32) +# define UV__EMLINK (-EMLINK) +#else +# define UV__EMLINK (-4032) +#endif + +/* EHOSTDOWN is not visible on BSD-like systems when _POSIX_C_SOURCE is + * defined. Fortunately, its value is always 64 so it's possible albeit + * icky to hard-code it. + */ +#if defined(EHOSTDOWN) && !defined(_WIN32) +# define UV__EHOSTDOWN (-EHOSTDOWN) +#elif defined(__APPLE__) || \ + defined(__DragonFly__) || \ + defined(__FreeBSD__) || \ + defined(__FreeBSD_kernel__) || \ + defined(__NetBSD__) || \ + defined(__OpenBSD__) +# define UV__EHOSTDOWN (-64) +#else +# define UV__EHOSTDOWN (-4031) +#endif + +#endif /* UV_ERRNO_H_ */ diff --git a/android/x86/include/uv/uv-linux.h b/android/x86/include/uv/uv-linux.h new file mode 100644 index 00000000..9b38405a --- /dev/null +++ b/android/x86/include/uv/uv-linux.h @@ -0,0 +1,34 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_LINUX_H +#define UV_LINUX_H + +#define UV_PLATFORM_LOOP_FIELDS \ + uv__io_t inotify_read_watcher; \ + void* inotify_watchers; \ + int inotify_fd; \ + +#define UV_PLATFORM_FS_EVENT_FIELDS \ + void* watchers[2]; \ + int wd; \ + +#endif /* UV_LINUX_H */ diff --git a/android/x86/include/uv/uv-os390.h b/android/x86/include/uv/uv-os390.h new file mode 100644 index 00000000..58f92611 --- /dev/null +++ b/android/x86/include/uv/uv-os390.h @@ -0,0 +1,30 @@ +/* Copyright libuv project contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_MVS_H +#define UV_MVS_H + +#define UV_PLATFORM_SEM_T int + +#define UV_PLATFORM_LOOP_FIELDS \ + void* ep; \ + +#endif /* UV_MVS_H */ diff --git a/android/x86/include/uv/uv-posix.h b/android/x86/include/uv/uv-posix.h new file mode 100644 index 00000000..9a96634d --- /dev/null +++ b/android/x86/include/uv/uv-posix.h @@ -0,0 +1,31 @@ +/* Copyright libuv project contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_POSIX_H +#define UV_POSIX_H + +#define UV_PLATFORM_LOOP_FIELDS \ + struct pollfd* poll_fds; \ + size_t poll_fds_used; \ + size_t poll_fds_size; \ + unsigned char poll_fds_iterating; \ + +#endif /* UV_POSIX_H */ diff --git a/android/x86/include/uv/uv-sunos.h b/android/x86/include/uv/uv-sunos.h new file mode 100644 index 00000000..04216642 --- /dev/null +++ b/android/x86/include/uv/uv-sunos.h @@ -0,0 +1,44 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_SUNOS_H +#define UV_SUNOS_H + +#include <sys/port.h> +#include <port.h> + +/* For the sake of convenience and reduced #ifdef-ery in src/unix/sunos.c, + * add the fs_event fields even when this version of SunOS doesn't support + * file watching. + */ +#define UV_PLATFORM_LOOP_FIELDS \ + uv__io_t fs_event_watcher; \ + int fs_fd; \ + +#if defined(PORT_SOURCE_FILE) + +# define UV_PLATFORM_FS_EVENT_FIELDS \ + file_obj_t fo; \ + int fd; \ + +#endif /* defined(PORT_SOURCE_FILE) */ + +#endif /* UV_SUNOS_H */ diff --git a/android/x86/include/uv/uv-threadpool.h b/android/x86/include/uv/uv-threadpool.h new file mode 100644 index 00000000..9708ebdd --- /dev/null +++ b/android/x86/include/uv/uv-threadpool.h @@ -0,0 +1,37 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/* + * This file is private to libuv. It provides common functionality to both + * Windows and Unix backends. + */ + +#ifndef UV_THREADPOOL_H_ +#define UV_THREADPOOL_H_ + +struct uv__work { + void (*work)(struct uv__work *w); + void (*done)(struct uv__work *w, int status); + struct uv_loop_s* loop; + void* wq[2]; +}; + +#endif /* UV_THREADPOOL_H_ */ diff --git a/android/x86/include/uv/uv-unix.h b/android/x86/include/uv/uv-unix.h new file mode 100644 index 00000000..d7754509 --- /dev/null +++ b/android/x86/include/uv/uv-unix.h @@ -0,0 +1,368 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_UNIX_H +#define UV_UNIX_H + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <dirent.h> + +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <arpa/inet.h> +#include <netdb.h> + +#include <termios.h> +#include <pwd.h> + +#if !defined(__MVS__) +#include <semaphore.h> +#endif +#include <pthread.h> +#include <signal.h> + +#include "uv-threadpool.h" + +#if defined(__linux__) +# include "uv-linux.h" +#elif defined (__MVS__) +# include "uv-os390.h" +#elif defined(_AIX) +# include "uv-aix.h" +#elif defined(__sun) +# include "uv-sunos.h" +#elif defined(__APPLE__) +# include "uv-darwin.h" +#elif defined(__DragonFly__) || \ + defined(__FreeBSD__) || \ + defined(__FreeBSD_kernel__) || \ + defined(__OpenBSD__) || \ + defined(__NetBSD__) +# include "uv-bsd.h" +#elif defined(__CYGWIN__) || defined(__MSYS__) +# include "uv-posix.h" +#endif + +#ifndef PTHREAD_BARRIER_SERIAL_THREAD +# include "pthread-barrier.h" +#endif + +#ifndef NI_MAXHOST +# define NI_MAXHOST 1025 +#endif + +#ifndef NI_MAXSERV +# define NI_MAXSERV 32 +#endif + +#ifndef UV_IO_PRIVATE_PLATFORM_FIELDS +# define UV_IO_PRIVATE_PLATFORM_FIELDS /* empty */ +#endif + +struct uv__io_s; +struct uv_loop_s; + +typedef void (*uv__io_cb)(struct uv_loop_s* loop, + struct uv__io_s* w, + unsigned int events); +typedef struct uv__io_s uv__io_t; + +struct uv__io_s { + uv__io_cb cb; + void* pending_queue[2]; + void* watcher_queue[2]; + unsigned int pevents; /* Pending event mask i.e. mask at next tick. */ + unsigned int events; /* Current event mask. */ + int fd; + UV_IO_PRIVATE_PLATFORM_FIELDS +}; + +#ifndef UV_PLATFORM_SEM_T +# define UV_PLATFORM_SEM_T sem_t +#endif + +#ifndef UV_PLATFORM_LOOP_FIELDS +# define UV_PLATFORM_LOOP_FIELDS /* empty */ +#endif + +#ifndef UV_PLATFORM_FS_EVENT_FIELDS +# define UV_PLATFORM_FS_EVENT_FIELDS /* empty */ +#endif + +#ifndef UV_STREAM_PRIVATE_PLATFORM_FIELDS +# define UV_STREAM_PRIVATE_PLATFORM_FIELDS /* empty */ +#endif + +/* Note: May be cast to struct iovec. See writev(2). */ +typedef struct uv_buf_t { + char* base; + size_t len; +} uv_buf_t; + +typedef int uv_file; +typedef int uv_os_sock_t; +typedef int uv_os_fd_t; + +#define UV_ONCE_INIT PTHREAD_ONCE_INIT + +typedef pthread_once_t uv_once_t; +typedef pthread_t uv_thread_t; +typedef pthread_mutex_t uv_mutex_t; +typedef pthread_rwlock_t uv_rwlock_t; +typedef UV_PLATFORM_SEM_T uv_sem_t; +typedef pthread_cond_t uv_cond_t; +typedef pthread_key_t uv_key_t; +typedef pthread_barrier_t uv_barrier_t; + + +/* Platform-specific definitions for uv_spawn support. */ +typedef gid_t uv_gid_t; +typedef uid_t uv_uid_t; + +typedef struct dirent uv__dirent_t; + +#if defined(DT_UNKNOWN) +# define HAVE_DIRENT_TYPES +# if defined(DT_REG) +# define UV__DT_FILE DT_REG +# else +# define UV__DT_FILE -1 +# endif +# if defined(DT_DIR) +# define UV__DT_DIR DT_DIR +# else +# define UV__DT_DIR -2 +# endif +# if defined(DT_LNK) +# define UV__DT_LINK DT_LNK +# else +# define UV__DT_LINK -3 +# endif +# if defined(DT_FIFO) +# define UV__DT_FIFO DT_FIFO +# else +# define UV__DT_FIFO -4 +# endif +# if defined(DT_SOCK) +# define UV__DT_SOCKET DT_SOCK +# else +# define UV__DT_SOCKET -5 +# endif +# if defined(DT_CHR) +# define UV__DT_CHAR DT_CHR +# else +# define UV__DT_CHAR -6 +# endif +# if defined(DT_BLK) +# define UV__DT_BLOCK DT_BLK +# else +# define UV__DT_BLOCK -7 +# endif +#endif + +/* Platform-specific definitions for uv_dlopen support. */ +#define UV_DYNAMIC /* empty */ + +typedef struct { + void* handle; + char* errmsg; +} uv_lib_t; + +#define UV_LOOP_PRIVATE_FIELDS \ + unsigned long flags; \ + int backend_fd; \ + void* pending_queue[2]; \ + void* watcher_queue[2]; \ + uv__io_t** watchers; \ + unsigned int nwatchers; \ + unsigned int nfds; \ + void* wq[2]; \ + uv_mutex_t wq_mutex; \ + uv_async_t wq_async; \ + uv_rwlock_t cloexec_lock; \ + uv_handle_t* closing_handles; \ + void* process_handles[2]; \ + void* prepare_handles[2]; \ + void* check_handles[2]; \ + void* idle_handles[2]; \ + void* async_handles[2]; \ + void (*async_unused)(void); /* TODO(bnoordhuis) Remove in libuv v2. */ \ + uv__io_t async_io_watcher; \ + int async_wfd; \ + struct { \ + void* min; \ + unsigned int nelts; \ + } timer_heap; \ + uint64_t timer_counter; \ + uint64_t time; \ + int signal_pipefd[2]; \ + uv__io_t signal_io_watcher; \ + uv_signal_t child_watcher; \ + int emfile_fd; \ + UV_PLATFORM_LOOP_FIELDS \ + +#define UV_REQ_TYPE_PRIVATE /* empty */ + +#define UV_REQ_PRIVATE_FIELDS /* empty */ + +#define UV_PRIVATE_REQ_TYPES /* empty */ + +#define UV_WRITE_PRIVATE_FIELDS \ + void* queue[2]; \ + unsigned int write_index; \ + uv_buf_t* bufs; \ + unsigned int nbufs; \ + int error; \ + uv_buf_t bufsml[4]; \ + +#define UV_CONNECT_PRIVATE_FIELDS \ + void* queue[2]; \ + +#define UV_SHUTDOWN_PRIVATE_FIELDS /* empty */ + +#define UV_UDP_SEND_PRIVATE_FIELDS \ + void* queue[2]; \ + struct sockaddr_storage addr; \ + unsigned int nbufs; \ + uv_buf_t* bufs; \ + ssize_t status; \ + uv_udp_send_cb send_cb; \ + uv_buf_t bufsml[4]; \ + +#define UV_HANDLE_PRIVATE_FIELDS \ + uv_handle_t* next_closing; \ + unsigned int flags; \ + +#define UV_STREAM_PRIVATE_FIELDS \ + uv_connect_t *connect_req; \ + uv_shutdown_t *shutdown_req; \ + uv__io_t io_watcher; \ + void* write_queue[2]; \ + void* write_completed_queue[2]; \ + uv_connection_cb connection_cb; \ + int delayed_error; \ + int accepted_fd; \ + void* queued_fds; \ + UV_STREAM_PRIVATE_PLATFORM_FIELDS \ + +#define UV_TCP_PRIVATE_FIELDS /* empty */ + +#define UV_UDP_PRIVATE_FIELDS \ + uv_alloc_cb alloc_cb; \ + uv_udp_recv_cb recv_cb; \ + uv__io_t io_watcher; \ + void* write_queue[2]; \ + void* write_completed_queue[2]; \ + +#define UV_PIPE_PRIVATE_FIELDS \ + const char* pipe_fname; /* strdup'ed */ + +#define UV_POLL_PRIVATE_FIELDS \ + uv__io_t io_watcher; + +#define UV_PREPARE_PRIVATE_FIELDS \ + uv_prepare_cb prepare_cb; \ + void* queue[2]; \ + +#define UV_CHECK_PRIVATE_FIELDS \ + uv_check_cb check_cb; \ + void* queue[2]; \ + +#define UV_IDLE_PRIVATE_FIELDS \ + uv_idle_cb idle_cb; \ + void* queue[2]; \ + +#define UV_ASYNC_PRIVATE_FIELDS \ + uv_async_cb async_cb; \ + void* queue[2]; \ + int pending; \ + +#define UV_TIMER_PRIVATE_FIELDS \ + uv_timer_cb timer_cb; \ + void* heap_node[3]; \ + uint64_t timeout; \ + uint64_t repeat; \ + uint64_t start_id; + +#define UV_GETADDRINFO_PRIVATE_FIELDS \ + struct uv__work work_req; \ + uv_getaddrinfo_cb cb; \ + struct addrinfo* hints; \ + char* hostname; \ + char* service; \ + struct addrinfo* addrinfo; \ + int retcode; + +#define UV_GETNAMEINFO_PRIVATE_FIELDS \ + struct uv__work work_req; \ + uv_getnameinfo_cb getnameinfo_cb; \ + struct sockaddr_storage storage; \ + int flags; \ + char host[NI_MAXHOST]; \ + char service[NI_MAXSERV]; \ + int retcode; + +#define UV_PROCESS_PRIVATE_FIELDS \ + void* queue[2]; \ + int status; \ + +#define UV_FS_PRIVATE_FIELDS \ + const char *new_path; \ + uv_file file; \ + int flags; \ + mode_t mode; \ + unsigned int nbufs; \ + uv_buf_t* bufs; \ + off_t off; \ + uv_uid_t uid; \ + uv_gid_t gid; \ + double atime; \ + double mtime; \ + struct uv__work work_req; \ + uv_buf_t bufsml[4]; \ + +#define UV_WORK_PRIVATE_FIELDS \ + struct uv__work work_req; + +#define UV_TTY_PRIVATE_FIELDS \ + struct termios orig_termios; \ + int mode; + +#define UV_SIGNAL_PRIVATE_FIELDS \ + /* RB_ENTRY(uv_signal_s) tree_entry; */ \ + struct { \ + struct uv_signal_s* rbe_left; \ + struct uv_signal_s* rbe_right; \ + struct uv_signal_s* rbe_parent; \ + int rbe_color; \ + } tree_entry; \ + /* Use two counters here so we don have to fiddle with atomics. */ \ + unsigned int caught_signals; \ + unsigned int dispatched_signals; + +#define UV_FS_EVENT_PRIVATE_FIELDS \ + uv_fs_event_cb cb; \ + UV_PLATFORM_FS_EVENT_FIELDS \ + +#endif /* UV_UNIX_H */ diff --git a/android/x86/include/uv/uv-version.h b/android/x86/include/uv/uv-version.h new file mode 100644 index 00000000..c80c40ea --- /dev/null +++ b/android/x86/include/uv/uv-version.h @@ -0,0 +1,43 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UV_VERSION_H +#define UV_VERSION_H + + /* + * Versions with the same major number are ABI stable. API is allowed to + * evolve between minor releases, but only in a backwards compatible way. + * Make sure you update the -soname directives in configure.ac + * and uv.gyp whenever you bump UV_VERSION_MAJOR or UV_VERSION_MINOR (but + * not UV_VERSION_PATCH.) + */ + +#define UV_VERSION_MAJOR 1 +#define UV_VERSION_MINOR 13 +#define UV_VERSION_PATCH 1 +#define UV_VERSION_IS_RELEASE 1 +#define UV_VERSION_SUFFIX "" + +#define UV_VERSION_HEX ((UV_VERSION_MAJOR << 16) | \ + (UV_VERSION_MINOR << 8) | \ + (UV_VERSION_PATCH)) + +#endif /* UV_VERSION_H */ diff --git a/android/x86/include/uv/uv-win.h b/android/x86/include/uv/uv-win.h new file mode 100644 index 00000000..9677ff16 --- /dev/null +++ b/android/x86/include/uv/uv-win.h @@ -0,0 +1,650 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0502 +#endif + +#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED) +typedef intptr_t ssize_t; +# define _SSIZE_T_ +# define _SSIZE_T_DEFINED +#endif + +#include <winsock2.h> + +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +typedef struct pollfd { + SOCKET fd; + short events; + short revents; +} WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD; +#endif + +#ifndef LOCALE_INVARIANT +# define LOCALE_INVARIANT 0x007f +#endif + +#include <mswsock.h> +#include <ws2tcpip.h> +#include <windows.h> + +#include <process.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/stat.h> + +#if defined(_MSC_VER) && _MSC_VER < 1600 +# include "stdint-msvc2008.h" +#else +# include <stdint.h> +#endif + +#include "tree.h" +#include "uv-threadpool.h" + +#define MAX_PIPENAME_LEN 256 + +#ifndef S_IFLNK +# define S_IFLNK 0xA000 +#endif + +/* Additional signals supported by uv_signal and or uv_kill. The CRT defines + * the following signals already: + * + * #define SIGINT 2 + * #define SIGILL 4 + * #define SIGABRT_COMPAT 6 + * #define SIGFPE 8 + * #define SIGSEGV 11 + * #define SIGTERM 15 + * #define SIGBREAK 21 + * #define SIGABRT 22 + * + * The additional signals have values that are common on other Unix + * variants (Linux and Darwin) + */ +#define SIGHUP 1 +#define SIGKILL 9 +#define SIGWINCH 28 + +/* The CRT defines SIGABRT_COMPAT as 6, which equals SIGABRT on many */ +/* unix-like platforms. However MinGW doesn't define it, so we do. */ +#ifndef SIGABRT_COMPAT +# define SIGABRT_COMPAT 6 +#endif + +/* + * Guids and typedefs for winsock extension functions + * Mingw32 doesn't have these :-( + */ +#ifndef WSAID_ACCEPTEX +# define WSAID_ACCEPTEX \ + {0xb5367df1, 0xcbac, 0x11cf, \ + {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} + +# define WSAID_CONNECTEX \ + {0x25a207b9, 0xddf3, 0x4660, \ + {0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}} + +# define WSAID_GETACCEPTEXSOCKADDRS \ + {0xb5367df2, 0xcbac, 0x11cf, \ + {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} + +# define WSAID_DISCONNECTEX \ + {0x7fda2e11, 0x8630, 0x436f, \ + {0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}} + +# define WSAID_TRANSMITFILE \ + {0xb5367df0, 0xcbac, 0x11cf, \ + {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} + + typedef BOOL (PASCAL *LPFN_ACCEPTEX) + (SOCKET sListenSocket, + SOCKET sAcceptSocket, + PVOID lpOutputBuffer, + DWORD dwReceiveDataLength, + DWORD dwLocalAddressLength, + DWORD dwRemoteAddressLength, + LPDWORD lpdwBytesReceived, + LPOVERLAPPED lpOverlapped); + + typedef BOOL (PASCAL *LPFN_CONNECTEX) + (SOCKET s, + const struct sockaddr* name, + int namelen, + PVOID lpSendBuffer, + DWORD dwSendDataLength, + LPDWORD lpdwBytesSent, + LPOVERLAPPED lpOverlapped); + + typedef void (PASCAL *LPFN_GETACCEPTEXSOCKADDRS) + (PVOID lpOutputBuffer, + DWORD dwReceiveDataLength, + DWORD dwLocalAddressLength, + DWORD dwRemoteAddressLength, + LPSOCKADDR* LocalSockaddr, + LPINT LocalSockaddrLength, + LPSOCKADDR* RemoteSockaddr, + LPINT RemoteSockaddrLength); + + typedef BOOL (PASCAL *LPFN_DISCONNECTEX) + (SOCKET hSocket, + LPOVERLAPPED lpOverlapped, + DWORD dwFlags, + DWORD reserved); + + typedef BOOL (PASCAL *LPFN_TRANSMITFILE) + (SOCKET hSocket, + HANDLE hFile, + DWORD nNumberOfBytesToWrite, + DWORD nNumberOfBytesPerSend, + LPOVERLAPPED lpOverlapped, + LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, + DWORD dwFlags); + + typedef PVOID RTL_SRWLOCK; + typedef RTL_SRWLOCK SRWLOCK, *PSRWLOCK; +#endif + +typedef int (WSAAPI* LPFN_WSARECV) + (SOCKET socket, + LPWSABUF buffers, + DWORD buffer_count, + LPDWORD bytes, + LPDWORD flags, + LPWSAOVERLAPPED overlapped, + LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine); + +typedef int (WSAAPI* LPFN_WSARECVFROM) + (SOCKET socket, + LPWSABUF buffers, + DWORD buffer_count, + LPDWORD bytes, + LPDWORD flags, + struct sockaddr* addr, + LPINT addr_len, + LPWSAOVERLAPPED overlapped, + LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine); + +#ifndef _NTDEF_ + typedef LONG NTSTATUS; + typedef NTSTATUS *PNTSTATUS; +#endif + +#ifndef RTL_CONDITION_VARIABLE_INIT + typedef PVOID CONDITION_VARIABLE, *PCONDITION_VARIABLE; +#endif + +typedef struct _AFD_POLL_HANDLE_INFO { + HANDLE Handle; + ULONG Events; + NTSTATUS Status; +} AFD_POLL_HANDLE_INFO, *PAFD_POLL_HANDLE_INFO; + +typedef struct _AFD_POLL_INFO { + LARGE_INTEGER Timeout; + ULONG NumberOfHandles; + ULONG Exclusive; + AFD_POLL_HANDLE_INFO Handles[1]; +} AFD_POLL_INFO, *PAFD_POLL_INFO; + +#define UV_MSAFD_PROVIDER_COUNT 3 + + +/** + * It should be possible to cast uv_buf_t[] to WSABUF[] + * see http://msdn.microsoft.com/en-us/library/ms741542(v=vs.85).aspx + */ +typedef struct uv_buf_t { + ULONG len; + char* base; +} uv_buf_t; + +typedef int uv_file; +typedef SOCKET uv_os_sock_t; +typedef HANDLE uv_os_fd_t; + +typedef HANDLE uv_thread_t; + +typedef HANDLE uv_sem_t; + +typedef CRITICAL_SECTION uv_mutex_t; + +/* This condition variable implementation is based on the SetEvent solution + * (section 3.2) at http://www.cs.wustl.edu/~schmidt/win32-cv-1.html + * We could not use the SignalObjectAndWait solution (section 3.4) because + * it want the 2nd argument (type uv_mutex_t) of uv_cond_wait() and + * uv_cond_timedwait() to be HANDLEs, but we use CRITICAL_SECTIONs. + */ + +typedef union { + CONDITION_VARIABLE cond_var; + struct { + unsigned int waiters_count; + CRITICAL_SECTION waiters_count_lock; + HANDLE signal_event; + HANDLE broadcast_event; + } fallback; +} uv_cond_t; + +typedef union { + struct { + unsigned int num_readers_; + CRITICAL_SECTION num_readers_lock_; + HANDLE write_semaphore_; + } state_; + /* TODO: remove me in v2.x. */ + struct { + SRWLOCK unused_; + } unused1_; + /* TODO: remove me in v2.x. */ + struct { + uv_mutex_t unused1_; + uv_mutex_t unused2_; + } unused2_; +} uv_rwlock_t; + +typedef struct { + unsigned int n; + unsigned int count; + uv_mutex_t mutex; + uv_sem_t turnstile1; + uv_sem_t turnstile2; +} uv_barrier_t; + +typedef struct { + DWORD tls_index; +} uv_key_t; + +#define UV_ONCE_INIT { 0, NULL } + +typedef struct uv_once_s { + unsigned char ran; + HANDLE event; +} uv_once_t; + +/* Platform-specific definitions for uv_spawn support. */ +typedef unsigned char uv_uid_t; +typedef unsigned char uv_gid_t; + +typedef struct uv__dirent_s { + int d_type; + char d_name[1]; +} uv__dirent_t; + +#define HAVE_DIRENT_TYPES +#define UV__DT_DIR UV_DIRENT_DIR +#define UV__DT_FILE UV_DIRENT_FILE +#define UV__DT_LINK UV_DIRENT_LINK +#define UV__DT_FIFO UV_DIRENT_FIFO +#define UV__DT_SOCKET UV_DIRENT_SOCKET +#define UV__DT_CHAR UV_DIRENT_CHAR +#define UV__DT_BLOCK UV_DIRENT_BLOCK + +/* Platform-specific definitions for uv_dlopen support. */ +#define UV_DYNAMIC FAR WINAPI +typedef struct { + HMODULE handle; + char* errmsg; +} uv_lib_t; + +RB_HEAD(uv_timer_tree_s, uv_timer_s); + +#define UV_LOOP_PRIVATE_FIELDS \ + /* The loop's I/O completion port */ \ + HANDLE iocp; \ + /* The current time according to the event loop. in msecs. */ \ + uint64_t time; \ + /* Tail of a single-linked circular queue of pending reqs. If the queue */ \ + /* is empty, tail_ is NULL. If there is only one item, */ \ + /* tail_->next_req == tail_ */ \ + uv_req_t* pending_reqs_tail; \ + /* Head of a single-linked list of closed handles */ \ + uv_handle_t* endgame_handles; \ + /* The head of the timers tree */ \ + struct uv_timer_tree_s timers; \ + /* Lists of active loop (prepare / check / idle) watchers */ \ + uv_prepare_t* prepare_handles; \ + uv_check_t* check_handles; \ + uv_idle_t* idle_handles; \ + /* This pointer will refer to the prepare/check/idle handle whose */ \ + /* callback is scheduled to be called next. This is needed to allow */ \ + /* safe removal from one of the lists above while that list being */ \ + /* iterated over. */ \ + uv_prepare_t* next_prepare_handle; \ + uv_check_t* next_check_handle; \ + uv_idle_t* next_idle_handle; \ + /* This handle holds the peer sockets for the fast variant of uv_poll_t */ \ + SOCKET poll_peer_sockets[UV_MSAFD_PROVIDER_COUNT]; \ + /* Counter to keep track of active tcp streams */ \ + unsigned int active_tcp_streams; \ + /* Counter to keep track of active udp streams */ \ + unsigned int active_udp_streams; \ + /* Counter to started timer */ \ + uint64_t timer_counter; \ + /* Threadpool */ \ + void* wq[2]; \ + uv_mutex_t wq_mutex; \ + uv_async_t wq_async; + +#define UV_REQ_TYPE_PRIVATE \ + /* TODO: remove the req suffix */ \ + UV_ACCEPT, \ + UV_FS_EVENT_REQ, \ + UV_POLL_REQ, \ + UV_PROCESS_EXIT, \ + UV_READ, \ + UV_UDP_RECV, \ + UV_WAKEUP, \ + UV_SIGNAL_REQ, + +#define UV_REQ_PRIVATE_FIELDS \ + union { \ + /* Used by I/O operations */ \ + struct { \ + OVERLAPPED overlapped; \ + size_t queued_bytes; \ + } io; \ + } u; \ + struct uv_req_s* next_req; + +#define UV_WRITE_PRIVATE_FIELDS \ + int ipc_header; \ + uv_buf_t write_buffer; \ + HANDLE event_handle; \ + HANDLE wait_handle; + +#define UV_CONNECT_PRIVATE_FIELDS \ + /* empty */ + +#define UV_SHUTDOWN_PRIVATE_FIELDS \ + /* empty */ + +#define UV_UDP_SEND_PRIVATE_FIELDS \ + /* empty */ + +#define UV_PRIVATE_REQ_TYPES \ + typedef struct uv_pipe_accept_s { \ + UV_REQ_FIELDS \ + HANDLE pipeHandle; \ + struct uv_pipe_accept_s* next_pending; \ + } uv_pipe_accept_t; \ + \ + typedef struct uv_tcp_accept_s { \ + UV_REQ_FIELDS \ + SOCKET accept_socket; \ + char accept_buffer[sizeof(struct sockaddr_storage) * 2 + 32]; \ + HANDLE event_handle; \ + HANDLE wait_handle; \ + struct uv_tcp_accept_s* next_pending; \ + } uv_tcp_accept_t; \ + \ + typedef struct uv_read_s { \ + UV_REQ_FIELDS \ + HANDLE event_handle; \ + HANDLE wait_handle; \ + } uv_read_t; + +#define uv_stream_connection_fields \ + unsigned int write_reqs_pending; \ + uv_shutdown_t* shutdown_req; + +#define uv_stream_server_fields \ + uv_connection_cb connection_cb; + +#define UV_STREAM_PRIVATE_FIELDS \ + unsigned int reqs_pending; \ + int activecnt; \ + uv_read_t read_req; \ + union { \ + struct { uv_stream_connection_fields } conn; \ + struct { uv_stream_server_fields } serv; \ + } stream; + +#define uv_tcp_server_fields \ + uv_tcp_accept_t* accept_reqs; \ + unsigned int processed_accepts; \ + uv_tcp_accept_t* pending_accepts; \ + LPFN_ACCEPTEX func_acceptex; + +#define uv_tcp_connection_fields \ + uv_buf_t read_buffer; \ + LPFN_CONNECTEX func_connectex; + +#define UV_TCP_PRIVATE_FIELDS \ + SOCKET socket; \ + int delayed_error; \ + union { \ + struct { uv_tcp_server_fields } serv; \ + struct { uv_tcp_connection_fields } conn; \ + } tcp; + +#define UV_UDP_PRIVATE_FIELDS \ + SOCKET socket; \ + unsigned int reqs_pending; \ + int activecnt; \ + uv_req_t recv_req; \ + uv_buf_t recv_buffer; \ + struct sockaddr_storage recv_from; \ + int recv_from_len; \ + uv_udp_recv_cb recv_cb; \ + uv_alloc_cb alloc_cb; \ + LPFN_WSARECV func_wsarecv; \ + LPFN_WSARECVFROM func_wsarecvfrom; + +#define uv_pipe_server_fields \ + int pending_instances; \ + uv_pipe_accept_t* accept_reqs; \ + uv_pipe_accept_t* pending_accepts; + +#define uv_pipe_connection_fields \ + uv_timer_t* eof_timer; \ + uv_write_t ipc_header_write_req; \ + int ipc_pid; \ + uint64_t remaining_ipc_rawdata_bytes; \ + struct { \ + void* queue[2]; \ + int queue_len; \ + } pending_ipc_info; \ + uv_write_t* non_overlapped_writes_tail; \ + uv_mutex_t readfile_mutex; \ + volatile HANDLE readfile_thread; + +#define UV_PIPE_PRIVATE_FIELDS \ + HANDLE handle; \ + WCHAR* name; \ + union { \ + struct { uv_pipe_server_fields } serv; \ + struct { uv_pipe_connection_fields } conn; \ + } pipe; + +/* TODO: put the parser states in an union - TTY handles are always */ +/* half-duplex so read-state can safely overlap write-state. */ +#define UV_TTY_PRIVATE_FIELDS \ + HANDLE handle; \ + union { \ + struct { \ + /* Used for readable TTY handles */ \ + /* TODO: remove me in v2.x. */ \ + HANDLE unused_; \ + uv_buf_t read_line_buffer; \ + HANDLE read_raw_wait; \ + /* Fields used for translating win keystrokes into vt100 characters */ \ + char last_key[8]; \ + unsigned char last_key_offset; \ + unsigned char last_key_len; \ + WCHAR last_utf16_high_surrogate; \ + INPUT_RECORD last_input_record; \ + } rd; \ + struct { \ + /* Used for writable TTY handles */ \ + /* utf8-to-utf16 conversion state */ \ + unsigned int utf8_codepoint; \ + unsigned char utf8_bytes_left; \ + /* eol conversion state */ \ + unsigned char previous_eol; \ + /* ansi parser state */ \ + unsigned char ansi_parser_state; \ + unsigned char ansi_csi_argc; \ + unsigned short ansi_csi_argv[4]; \ + COORD saved_position; \ + WORD saved_attributes; \ + } wr; \ + } tty; + +#define UV_POLL_PRIVATE_FIELDS \ + SOCKET socket; \ + /* Used in fast mode */ \ + SOCKET peer_socket; \ + AFD_POLL_INFO afd_poll_info_1; \ + AFD_POLL_INFO afd_poll_info_2; \ + /* Used in fast and slow mode. */ \ + uv_req_t poll_req_1; \ + uv_req_t poll_req_2; \ + unsigned char submitted_events_1; \ + unsigned char submitted_events_2; \ + unsigned char mask_events_1; \ + unsigned char mask_events_2; \ + unsigned char events; + +#define UV_TIMER_PRIVATE_FIELDS \ + RB_ENTRY(uv_timer_s) tree_entry; \ + uint64_t due; \ + uint64_t repeat; \ + uint64_t start_id; \ + uv_timer_cb timer_cb; + +#define UV_ASYNC_PRIVATE_FIELDS \ + struct uv_req_s async_req; \ + uv_async_cb async_cb; \ + /* char to avoid alignment issues */ \ + char volatile async_sent; + +#define UV_PREPARE_PRIVATE_FIELDS \ + uv_prepare_t* prepare_prev; \ + uv_prepare_t* prepare_next; \ + uv_prepare_cb prepare_cb; + +#define UV_CHECK_PRIVATE_FIELDS \ + uv_check_t* check_prev; \ + uv_check_t* check_next; \ + uv_check_cb check_cb; + +#define UV_IDLE_PRIVATE_FIELDS \ + uv_idle_t* idle_prev; \ + uv_idle_t* idle_next; \ + uv_idle_cb idle_cb; + +#define UV_HANDLE_PRIVATE_FIELDS \ + uv_handle_t* endgame_next; \ + unsigned int flags; + +#define UV_GETADDRINFO_PRIVATE_FIELDS \ + struct uv__work work_req; \ + uv_getaddrinfo_cb getaddrinfo_cb; \ + void* alloc; \ + WCHAR* node; \ + WCHAR* service; \ + /* The addrinfoW field is used to store a pointer to the hints, and */ \ + /* later on to store the result of GetAddrInfoW. The final result will */ \ + /* be converted to struct addrinfo* and stored in the addrinfo field. */ \ + struct addrinfoW* addrinfow; \ + struct addrinfo* addrinfo; \ + int retcode; + +#define UV_GETNAMEINFO_PRIVATE_FIELDS \ + struct uv__work work_req; \ + uv_getnameinfo_cb getnameinfo_cb; \ + struct sockaddr_storage storage; \ + int flags; \ + char host[NI_MAXHOST]; \ + char service[NI_MAXSERV]; \ + int retcode; + +#define UV_PROCESS_PRIVATE_FIELDS \ + struct uv_process_exit_s { \ + UV_REQ_FIELDS \ + } exit_req; \ + BYTE* child_stdio_buffer; \ + int exit_signal; \ + HANDLE wait_handle; \ + HANDLE process_handle; \ + volatile char exit_cb_pending; + +#define UV_FS_PRIVATE_FIELDS \ + struct uv__work work_req; \ + int flags; \ + DWORD sys_errno_; \ + union { \ + /* TODO: remove me in 0.9. */ \ + WCHAR* pathw; \ + int fd; \ + } file; \ + union { \ + struct { \ + int mode; \ + WCHAR* new_pathw; \ + int file_flags; \ + int fd_out; \ + unsigned int nbufs; \ + uv_buf_t* bufs; \ + int64_t offset; \ + uv_buf_t bufsml[4]; \ + } info; \ + struct { \ + double atime; \ + double mtime; \ + } time; \ + } fs; + +#define UV_WORK_PRIVATE_FIELDS \ + struct uv__work work_req; + +#define UV_FS_EVENT_PRIVATE_FIELDS \ + struct uv_fs_event_req_s { \ + UV_REQ_FIELDS \ + } req; \ + HANDLE dir_handle; \ + int req_pending; \ + uv_fs_event_cb cb; \ + WCHAR* filew; \ + WCHAR* short_filew; \ + WCHAR* dirw; \ + char* buffer; + +#define UV_SIGNAL_PRIVATE_FIELDS \ + RB_ENTRY(uv_signal_s) tree_entry; \ + struct uv_req_s signal_req; \ + unsigned long pending_signum; + +#ifndef F_OK +#define F_OK 0 +#endif +#ifndef R_OK +#define R_OK 4 +#endif +#ifndef W_OK +#define W_OK 2 +#endif +#ifndef X_OK +#define X_OK 1 +#endif diff --git a/android/x86/include/uv/uv.h b/android/x86/include/uv/uv.h new file mode 100644 index 00000000..f076094c --- /dev/null +++ b/android/x86/include/uv/uv.h @@ -0,0 +1,1508 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/* See https://github.com/libuv/libuv#documentation for documentation. */ + +#ifndef UV_H +#define UV_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _WIN32 + /* Windows - set up dll import/export decorators. */ +# if defined(BUILDING_UV_SHARED) + /* Building shared library. */ +# define UV_EXTERN __declspec(dllexport) +# elif defined(USING_UV_SHARED) + /* Using shared library. */ +# define UV_EXTERN __declspec(dllimport) +# else + /* Building static library. */ +# define UV_EXTERN /* nothing */ +# endif +#elif __GNUC__ >= 4 +# define UV_EXTERN __attribute__((visibility("default"))) +#else +# define UV_EXTERN /* nothing */ +#endif + +#include "uv-errno.h" +#include "uv-version.h" +#include <stddef.h> +#include <stdio.h> + +#if defined(_MSC_VER) && _MSC_VER < 1600 +# include "stdint-msvc2008.h" +#else +# include <stdint.h> +#endif + +#if defined(_WIN32) +# include "uv-win.h" +#else +# include "uv-unix.h" +#endif + +/* Expand this list if necessary. */ +#define UV_ERRNO_MAP(XX) \ + XX(E2BIG, "argument list too long") \ + XX(EACCES, "permission denied") \ + XX(EADDRINUSE, "address already in use") \ + XX(EADDRNOTAVAIL, "address not available") \ + XX(EAFNOSUPPORT, "address family not supported") \ + XX(EAGAIN, "resource temporarily unavailable") \ + XX(EAI_ADDRFAMILY, "address family not supported") \ + XX(EAI_AGAIN, "temporary failure") \ + XX(EAI_BADFLAGS, "bad ai_flags value") \ + XX(EAI_BADHINTS, "invalid value for hints") \ + XX(EAI_CANCELED, "request canceled") \ + XX(EAI_FAIL, "permanent failure") \ + XX(EAI_FAMILY, "ai_family not supported") \ + XX(EAI_MEMORY, "out of memory") \ + XX(EAI_NODATA, "no address") \ + XX(EAI_NONAME, "unknown node or service") \ + XX(EAI_OVERFLOW, "argument buffer overflow") \ + XX(EAI_PROTOCOL, "resolved protocol is unknown") \ + XX(EAI_SERVICE, "service not available for socket type") \ + XX(EAI_SOCKTYPE, "socket type not supported") \ + XX(EALREADY, "connection already in progress") \ + XX(EBADF, "bad file descriptor") \ + XX(EBUSY, "resource busy or locked") \ + XX(ECANCELED, "operation canceled") \ + XX(ECHARSET, "invalid Unicode character") \ + XX(ECONNABORTED, "software caused connection abort") \ + XX(ECONNREFUSED, "connection refused") \ + XX(ECONNRESET, "connection reset by peer") \ + XX(EDESTADDRREQ, "destination address required") \ + XX(EEXIST, "file already exists") \ + XX(EFAULT, "bad address in system call argument") \ + XX(EFBIG, "file too large") \ + XX(EHOSTUNREACH, "host is unreachable") \ + XX(EINTR, "interrupted system call") \ + XX(EINVAL, "invalid argument") \ + XX(EIO, "i/o error") \ + XX(EISCONN, "socket is already connected") \ + XX(EISDIR, "illegal operation on a directory") \ + XX(ELOOP, "too many symbolic links encountered") \ + XX(EMFILE, "too many open files") \ + XX(EMSGSIZE, "message too long") \ + XX(ENAMETOOLONG, "name too long") \ + XX(ENETDOWN, "network is down") \ + XX(ENETUNREACH, "network is unreachable") \ + XX(ENFILE, "file table overflow") \ + XX(ENOBUFS, "no buffer space available") \ + XX(ENODEV, "no such device") \ + XX(ENOENT, "no such file or directory") \ + XX(ENOMEM, "not enough memory") \ + XX(ENONET, "machine is not on the network") \ + XX(ENOPROTOOPT, "protocol not available") \ + XX(ENOSPC, "no space left on device") \ + XX(ENOSYS, "function not implemented") \ + XX(ENOTCONN, "socket is not connected") \ + XX(ENOTDIR, "not a directory") \ + XX(ENOTEMPTY, "directory not empty") \ + XX(ENOTSOCK, "socket operation on non-socket") \ + XX(ENOTSUP, "operation not supported on socket") \ + XX(EPERM, "operation not permitted") \ + XX(EPIPE, "broken pipe") \ + XX(EPROTO, "protocol error") \ + XX(EPROTONOSUPPORT, "protocol not supported") \ + XX(EPROTOTYPE, "protocol wrong type for socket") \ + XX(ERANGE, "result too large") \ + XX(EROFS, "read-only file system") \ + XX(ESHUTDOWN, "cannot send after transport endpoint shutdown") \ + XX(ESPIPE, "invalid seek") \ + XX(ESRCH, "no such process") \ + XX(ETIMEDOUT, "connection timed out") \ + XX(ETXTBSY, "text file is busy") \ + XX(EXDEV, "cross-device link not permitted") \ + XX(UNKNOWN, "unknown error") \ + XX(EOF, "end of file") \ + XX(ENXIO, "no such device or address") \ + XX(EMLINK, "too many links") \ + XX(EHOSTDOWN, "host is down") \ + +#define UV_HANDLE_TYPE_MAP(XX) \ + XX(ASYNC, async) \ + XX(CHECK, check) \ + XX(FS_EVENT, fs_event) \ + XX(FS_POLL, fs_poll) \ + XX(HANDLE, handle) \ + XX(IDLE, idle) \ + XX(NAMED_PIPE, pipe) \ + XX(POLL, poll) \ + XX(PREPARE, prepare) \ + XX(PROCESS, process) \ + XX(STREAM, stream) \ + XX(TCP, tcp) \ + XX(TIMER, timer) \ + XX(TTY, tty) \ + XX(UDP, udp) \ + XX(SIGNAL, signal) \ + +#define UV_REQ_TYPE_MAP(XX) \ + XX(REQ, req) \ + XX(CONNECT, connect) \ + XX(WRITE, write) \ + XX(SHUTDOWN, shutdown) \ + XX(UDP_SEND, udp_send) \ + XX(FS, fs) \ + XX(WORK, work) \ + XX(GETADDRINFO, getaddrinfo) \ + XX(GETNAMEINFO, getnameinfo) \ + +typedef enum { +#define XX(code, _) UV_ ## code = UV__ ## code, + UV_ERRNO_MAP(XX) +#undef XX + UV_ERRNO_MAX = UV__EOF - 1 +} uv_errno_t; + +typedef enum { + UV_UNKNOWN_HANDLE = 0, +#define XX(uc, lc) UV_##uc, + UV_HANDLE_TYPE_MAP(XX) +#undef XX + UV_FILE, + UV_HANDLE_TYPE_MAX +} uv_handle_type; + +typedef enum { + UV_UNKNOWN_REQ = 0, +#define XX(uc, lc) UV_##uc, + UV_REQ_TYPE_MAP(XX) +#undef XX + UV_REQ_TYPE_PRIVATE + UV_REQ_TYPE_MAX +} uv_req_type; + + +/* Handle types. */ +typedef struct uv_loop_s uv_loop_t; +typedef struct uv_handle_s uv_handle_t; +typedef struct uv_stream_s uv_stream_t; +typedef struct uv_tcp_s uv_tcp_t; +typedef struct uv_udp_s uv_udp_t; +typedef struct uv_pipe_s uv_pipe_t; +typedef struct uv_tty_s uv_tty_t; +typedef struct uv_poll_s uv_poll_t; +typedef struct uv_timer_s uv_timer_t; +typedef struct uv_prepare_s uv_prepare_t; +typedef struct uv_check_s uv_check_t; +typedef struct uv_idle_s uv_idle_t; +typedef struct uv_async_s uv_async_t; +typedef struct uv_process_s uv_process_t; +typedef struct uv_fs_event_s uv_fs_event_t; +typedef struct uv_fs_poll_s uv_fs_poll_t; +typedef struct uv_signal_s uv_signal_t; + +/* Request types. */ +typedef struct uv_req_s uv_req_t; +typedef struct uv_getaddrinfo_s uv_getaddrinfo_t; +typedef struct uv_getnameinfo_s uv_getnameinfo_t; +typedef struct uv_shutdown_s uv_shutdown_t; +typedef struct uv_write_s uv_write_t; +typedef struct uv_connect_s uv_connect_t; +typedef struct uv_udp_send_s uv_udp_send_t; +typedef struct uv_fs_s uv_fs_t; +typedef struct uv_work_s uv_work_t; + +/* None of the above. */ +typedef struct uv_cpu_info_s uv_cpu_info_t; +typedef struct uv_interface_address_s uv_interface_address_t; +typedef struct uv_dirent_s uv_dirent_t; +typedef struct uv_passwd_s uv_passwd_t; + +typedef enum { + UV_LOOP_BLOCK_SIGNAL +} uv_loop_option; + +typedef enum { + UV_RUN_DEFAULT = 0, + UV_RUN_ONCE, + UV_RUN_NOWAIT +} uv_run_mode; + + +UV_EXTERN unsigned int uv_version(void); +UV_EXTERN const char* uv_version_string(void); + +typedef void* (*uv_malloc_func)(size_t size); +typedef void* (*uv_realloc_func)(void* ptr, size_t size); +typedef void* (*uv_calloc_func)(size_t count, size_t size); +typedef void (*uv_free_func)(void* ptr); + +UV_EXTERN int uv_replace_allocator(uv_malloc_func malloc_func, + uv_realloc_func realloc_func, + uv_calloc_func calloc_func, + uv_free_func free_func); + +UV_EXTERN uv_loop_t* uv_default_loop(void); +UV_EXTERN int uv_loop_init(uv_loop_t* loop); +UV_EXTERN int uv_loop_close(uv_loop_t* loop); +/* + * NOTE: + * This function is DEPRECATED (to be removed after 0.12), users should + * allocate the loop manually and use uv_loop_init instead. + */ +UV_EXTERN uv_loop_t* uv_loop_new(void); +/* + * NOTE: + * This function is DEPRECATED (to be removed after 0.12). Users should use + * uv_loop_close and free the memory manually instead. + */ +UV_EXTERN void uv_loop_delete(uv_loop_t*); +UV_EXTERN size_t uv_loop_size(void); +UV_EXTERN int uv_loop_alive(const uv_loop_t* loop); +UV_EXTERN int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...); +UV_EXTERN int uv_loop_fork(uv_loop_t* loop); + +UV_EXTERN int uv_run(uv_loop_t*, uv_run_mode mode); +UV_EXTERN void uv_stop(uv_loop_t*); + +UV_EXTERN void uv_ref(uv_handle_t*); +UV_EXTERN void uv_unref(uv_handle_t*); +UV_EXTERN int uv_has_ref(const uv_handle_t*); + +UV_EXTERN void uv_update_time(uv_loop_t*); +UV_EXTERN uint64_t uv_now(const uv_loop_t*); + +UV_EXTERN int uv_backend_fd(const uv_loop_t*); +UV_EXTERN int uv_backend_timeout(const uv_loop_t*); + +typedef void (*uv_alloc_cb)(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf); +typedef void (*uv_read_cb)(uv_stream_t* stream, + ssize_t nread, + const uv_buf_t* buf); +typedef void (*uv_write_cb)(uv_write_t* req, int status); +typedef void (*uv_connect_cb)(uv_connect_t* req, int status); +typedef void (*uv_shutdown_cb)(uv_shutdown_t* req, int status); +typedef void (*uv_connection_cb)(uv_stream_t* server, int status); +typedef void (*uv_close_cb)(uv_handle_t* handle); +typedef void (*uv_poll_cb)(uv_poll_t* handle, int status, int events); +typedef void (*uv_timer_cb)(uv_timer_t* handle); +typedef void (*uv_async_cb)(uv_async_t* handle); +typedef void (*uv_prepare_cb)(uv_prepare_t* handle); +typedef void (*uv_check_cb)(uv_check_t* handle); +typedef void (*uv_idle_cb)(uv_idle_t* handle); +typedef void (*uv_exit_cb)(uv_process_t*, int64_t exit_status, int term_signal); +typedef void (*uv_walk_cb)(uv_handle_t* handle, void* arg); +typedef void (*uv_fs_cb)(uv_fs_t* req); +typedef void (*uv_work_cb)(uv_work_t* req); +typedef void (*uv_after_work_cb)(uv_work_t* req, int status); +typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req, + int status, + struct addrinfo* res); +typedef void (*uv_getnameinfo_cb)(uv_getnameinfo_t* req, + int status, + const char* hostname, + const char* service); + +typedef struct { + long tv_sec; + long tv_nsec; +} uv_timespec_t; + + +typedef struct { + uint64_t st_dev; + uint64_t st_mode; + uint64_t st_nlink; + uint64_t st_uid; + uint64_t st_gid; + uint64_t st_rdev; + uint64_t st_ino; + uint64_t st_size; + uint64_t st_blksize; + uint64_t st_blocks; + uint64_t st_flags; + uint64_t st_gen; + uv_timespec_t st_atim; + uv_timespec_t st_mtim; + uv_timespec_t st_ctim; + uv_timespec_t st_birthtim; +} uv_stat_t; + + +typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle, + const char* filename, + int events, + int status); + +typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle, + int status, + const uv_stat_t* prev, + const uv_stat_t* curr); + +typedef void (*uv_signal_cb)(uv_signal_t* handle, int signum); + + +typedef enum { + UV_LEAVE_GROUP = 0, + UV_JOIN_GROUP +} uv_membership; + + +UV_EXTERN int uv_translate_sys_error(int sys_errno); + +UV_EXTERN const char* uv_strerror(int err); +UV_EXTERN const char* uv_err_name(int err); + + +#define UV_REQ_FIELDS \ + /* public */ \ + void* data; \ + /* read-only */ \ + uv_req_type type; \ + /* private */ \ + void* active_queue[2]; \ + void* reserved[4]; \ + UV_REQ_PRIVATE_FIELDS \ + +/* Abstract base class of all requests. */ +struct uv_req_s { + UV_REQ_FIELDS +}; + + +/* Platform-specific request types. */ +UV_PRIVATE_REQ_TYPES + + +UV_EXTERN int uv_shutdown(uv_shutdown_t* req, + uv_stream_t* handle, + uv_shutdown_cb cb); + +struct uv_shutdown_s { + UV_REQ_FIELDS + uv_stream_t* handle; + uv_shutdown_cb cb; + UV_SHUTDOWN_PRIVATE_FIELDS +}; + + +#define UV_HANDLE_FIELDS \ + /* public */ \ + void* data; \ + /* read-only */ \ + uv_loop_t* loop; \ + uv_handle_type type; \ + /* private */ \ + uv_close_cb close_cb; \ + void* handle_queue[2]; \ + union { \ + int fd; \ + void* reserved[4]; \ + } u; \ + UV_HANDLE_PRIVATE_FIELDS \ + +/* The abstract base class of all handles. */ +struct uv_handle_s { + UV_HANDLE_FIELDS +}; + +UV_EXTERN size_t uv_handle_size(uv_handle_type type); +UV_EXTERN size_t uv_req_size(uv_req_type type); + +UV_EXTERN int uv_is_active(const uv_handle_t* handle); + +UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg); + +/* Helpers for ad hoc debugging, no API/ABI stability guaranteed. */ +UV_EXTERN void uv_print_all_handles(uv_loop_t* loop, FILE* stream); +UV_EXTERN void uv_print_active_handles(uv_loop_t* loop, FILE* stream); + +UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb); + +UV_EXTERN int uv_send_buffer_size(uv_handle_t* handle, int* value); +UV_EXTERN int uv_recv_buffer_size(uv_handle_t* handle, int* value); + +UV_EXTERN int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd); + +UV_EXTERN uv_buf_t uv_buf_init(char* base, unsigned int len); + + +#define UV_STREAM_FIELDS \ + /* number of bytes queued for writing */ \ + size_t write_queue_size; \ + uv_alloc_cb alloc_cb; \ + uv_read_cb read_cb; \ + /* private */ \ + UV_STREAM_PRIVATE_FIELDS + +/* + * uv_stream_t is a subclass of uv_handle_t. + * + * uv_stream is an abstract class. + * + * uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t and uv_tty_t. + */ +struct uv_stream_s { + UV_HANDLE_FIELDS + UV_STREAM_FIELDS +}; + +UV_EXTERN int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb); +UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client); + +UV_EXTERN int uv_read_start(uv_stream_t*, + uv_alloc_cb alloc_cb, + uv_read_cb read_cb); +UV_EXTERN int uv_read_stop(uv_stream_t*); + +UV_EXTERN int uv_write(uv_write_t* req, + uv_stream_t* handle, + const uv_buf_t bufs[], + unsigned int nbufs, + uv_write_cb cb); +UV_EXTERN int uv_write2(uv_write_t* req, + uv_stream_t* handle, + const uv_buf_t bufs[], + unsigned int nbufs, + uv_stream_t* send_handle, + uv_write_cb cb); +UV_EXTERN int uv_try_write(uv_stream_t* handle, + const uv_buf_t bufs[], + unsigned int nbufs); + +/* uv_write_t is a subclass of uv_req_t. */ +struct uv_write_s { + UV_REQ_FIELDS + uv_write_cb cb; + uv_stream_t* send_handle; + uv_stream_t* handle; + UV_WRITE_PRIVATE_FIELDS +}; + + +UV_EXTERN int uv_is_readable(const uv_stream_t* handle); +UV_EXTERN int uv_is_writable(const uv_stream_t* handle); + +UV_EXTERN int uv_stream_set_blocking(uv_stream_t* handle, int blocking); + +UV_EXTERN int uv_is_closing(const uv_handle_t* handle); + + +/* + * uv_tcp_t is a subclass of uv_stream_t. + * + * Represents a TCP stream or TCP server. + */ +struct uv_tcp_s { + UV_HANDLE_FIELDS + UV_STREAM_FIELDS + UV_TCP_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle); +UV_EXTERN int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, unsigned int flags); +UV_EXTERN int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock); +UV_EXTERN int uv_tcp_nodelay(uv_tcp_t* handle, int enable); +UV_EXTERN int uv_tcp_keepalive(uv_tcp_t* handle, + int enable, + unsigned int delay); +UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable); + +enum uv_tcp_flags { + /* Used with uv_tcp_bind, when an IPv6 address is used. */ + UV_TCP_IPV6ONLY = 1 +}; + +UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle, + const struct sockaddr* addr, + unsigned int flags); +UV_EXTERN int uv_tcp_getsockname(const uv_tcp_t* handle, + struct sockaddr* name, + int* namelen); +UV_EXTERN int uv_tcp_getpeername(const uv_tcp_t* handle, + struct sockaddr* name, + int* namelen); +UV_EXTERN int uv_tcp_connect(uv_connect_t* req, + uv_tcp_t* handle, + const struct sockaddr* addr, + uv_connect_cb cb); + +/* uv_connect_t is a subclass of uv_req_t. */ +struct uv_connect_s { + UV_REQ_FIELDS + uv_connect_cb cb; + uv_stream_t* handle; + UV_CONNECT_PRIVATE_FIELDS +}; + + +/* + * UDP support. + */ + +enum uv_udp_flags { + /* Disables dual stack mode. */ + UV_UDP_IPV6ONLY = 1, + /* + * Indicates message was truncated because read buffer was too small. The + * remainder was discarded by the OS. Used in uv_udp_recv_cb. + */ + UV_UDP_PARTIAL = 2, + /* + * Indicates if SO_REUSEADDR will be set when binding the handle. + * This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other + * Unix platforms, it sets the SO_REUSEADDR flag. What that means is that + * multiple threads or processes can bind to the same address without error + * (provided they all set the flag) but only the last one to bind will receive + * any traffic, in effect "stealing" the port from the previous listener. + */ + UV_UDP_REUSEADDR = 4 +}; + +typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status); +typedef void (*uv_udp_recv_cb)(uv_udp_t* handle, + ssize_t nread, + const uv_buf_t* buf, + const struct sockaddr* addr, + unsigned flags); + +/* uv_udp_t is a subclass of uv_handle_t. */ +struct uv_udp_s { + UV_HANDLE_FIELDS + /* read-only */ + /* + * Number of bytes queued for sending. This field strictly shows how much + * information is currently queued. + */ + size_t send_queue_size; + /* + * Number of send requests currently in the queue awaiting to be processed. + */ + size_t send_queue_count; + UV_UDP_PRIVATE_FIELDS +}; + +/* uv_udp_send_t is a subclass of uv_req_t. */ +struct uv_udp_send_s { + UV_REQ_FIELDS + uv_udp_t* handle; + uv_udp_send_cb cb; + UV_UDP_SEND_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle); +UV_EXTERN int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, unsigned int flags); +UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock); +UV_EXTERN int uv_udp_bind(uv_udp_t* handle, + const struct sockaddr* addr, + unsigned int flags); + +UV_EXTERN int uv_udp_getsockname(const uv_udp_t* handle, + struct sockaddr* name, + int* namelen); +UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle, + const char* multicast_addr, + const char* interface_addr, + uv_membership membership); +UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on); +UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl); +UV_EXTERN int uv_udp_set_multicast_interface(uv_udp_t* handle, + const char* interface_addr); +UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on); +UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl); +UV_EXTERN int uv_udp_send(uv_udp_send_t* req, + uv_udp_t* handle, + const uv_buf_t bufs[], + unsigned int nbufs, + const struct sockaddr* addr, + uv_udp_send_cb send_cb); +UV_EXTERN int uv_udp_try_send(uv_udp_t* handle, + const uv_buf_t bufs[], + unsigned int nbufs, + const struct sockaddr* addr); +UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle, + uv_alloc_cb alloc_cb, + uv_udp_recv_cb recv_cb); +UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle); + + +/* + * uv_tty_t is a subclass of uv_stream_t. + * + * Representing a stream for the console. + */ +struct uv_tty_s { + UV_HANDLE_FIELDS + UV_STREAM_FIELDS + UV_TTY_PRIVATE_FIELDS +}; + +typedef enum { + /* Initial/normal terminal mode */ + UV_TTY_MODE_NORMAL, + /* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */ + UV_TTY_MODE_RAW, + /* Binary-safe I/O mode for IPC (Unix-only) */ + UV_TTY_MODE_IO +} uv_tty_mode_t; + +UV_EXTERN int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable); +UV_EXTERN int uv_tty_set_mode(uv_tty_t*, uv_tty_mode_t mode); +UV_EXTERN int uv_tty_reset_mode(void); +UV_EXTERN int uv_tty_get_winsize(uv_tty_t*, int* width, int* height); + +#ifdef __cplusplus +extern "C++" { + +inline int uv_tty_set_mode(uv_tty_t* handle, int mode) { + return uv_tty_set_mode(handle, static_cast<uv_tty_mode_t>(mode)); +} + +} +#endif + +UV_EXTERN uv_handle_type uv_guess_handle(uv_file file); + +/* + * uv_pipe_t is a subclass of uv_stream_t. + * + * Representing a pipe stream or pipe server. On Windows this is a Named + * Pipe. On Unix this is a Unix domain socket. + */ +struct uv_pipe_s { + UV_HANDLE_FIELDS + UV_STREAM_FIELDS + int ipc; /* non-zero if this pipe is used for passing handles */ + UV_PIPE_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc); +UV_EXTERN int uv_pipe_open(uv_pipe_t*, uv_file file); +UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name); +UV_EXTERN void uv_pipe_connect(uv_connect_t* req, + uv_pipe_t* handle, + const char* name, + uv_connect_cb cb); +UV_EXTERN int uv_pipe_getsockname(const uv_pipe_t* handle, + char* buffer, + size_t* size); +UV_EXTERN int uv_pipe_getpeername(const uv_pipe_t* handle, + char* buffer, + size_t* size); +UV_EXTERN void uv_pipe_pending_instances(uv_pipe_t* handle, int count); +UV_EXTERN int uv_pipe_pending_count(uv_pipe_t* handle); +UV_EXTERN uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle); + + +struct uv_poll_s { + UV_HANDLE_FIELDS + uv_poll_cb poll_cb; + UV_POLL_PRIVATE_FIELDS +}; + +enum uv_poll_event { + UV_READABLE = 1, + UV_WRITABLE = 2, + UV_DISCONNECT = 4 +}; + +UV_EXTERN int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd); +UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop, + uv_poll_t* handle, + uv_os_sock_t socket); +UV_EXTERN int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb); +UV_EXTERN int uv_poll_stop(uv_poll_t* handle); + + +struct uv_prepare_s { + UV_HANDLE_FIELDS + UV_PREPARE_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_prepare_init(uv_loop_t*, uv_prepare_t* prepare); +UV_EXTERN int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb); +UV_EXTERN int uv_prepare_stop(uv_prepare_t* prepare); + + +struct uv_check_s { + UV_HANDLE_FIELDS + UV_CHECK_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_check_init(uv_loop_t*, uv_check_t* check); +UV_EXTERN int uv_check_start(uv_check_t* check, uv_check_cb cb); +UV_EXTERN int uv_check_stop(uv_check_t* check); + + +struct uv_idle_s { + UV_HANDLE_FIELDS + UV_IDLE_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_idle_init(uv_loop_t*, uv_idle_t* idle); +UV_EXTERN int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb); +UV_EXTERN int uv_idle_stop(uv_idle_t* idle); + + +struct uv_async_s { + UV_HANDLE_FIELDS + UV_ASYNC_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_async_init(uv_loop_t*, + uv_async_t* async, + uv_async_cb async_cb); +UV_EXTERN int uv_async_send(uv_async_t* async); + + +/* + * uv_timer_t is a subclass of uv_handle_t. + * + * Used to get woken up at a specified time in the future. + */ +struct uv_timer_s { + UV_HANDLE_FIELDS + UV_TIMER_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_timer_init(uv_loop_t*, uv_timer_t* handle); +UV_EXTERN int uv_timer_start(uv_timer_t* handle, + uv_timer_cb cb, + uint64_t timeout, + uint64_t repeat); +UV_EXTERN int uv_timer_stop(uv_timer_t* handle); +UV_EXTERN int uv_timer_again(uv_timer_t* handle); +UV_EXTERN void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat); +UV_EXTERN uint64_t uv_timer_get_repeat(const uv_timer_t* handle); + + +/* + * uv_getaddrinfo_t is a subclass of uv_req_t. + * + * Request object for uv_getaddrinfo. + */ +struct uv_getaddrinfo_s { + UV_REQ_FIELDS + /* read-only */ + uv_loop_t* loop; + /* struct addrinfo* addrinfo is marked as private, but it really isn't. */ + UV_GETADDRINFO_PRIVATE_FIELDS +}; + + +UV_EXTERN int uv_getaddrinfo(uv_loop_t* loop, + uv_getaddrinfo_t* req, + uv_getaddrinfo_cb getaddrinfo_cb, + const char* node, + const char* service, + const struct addrinfo* hints); +UV_EXTERN void uv_freeaddrinfo(struct addrinfo* ai); + + +/* +* uv_getnameinfo_t is a subclass of uv_req_t. +* +* Request object for uv_getnameinfo. +*/ +struct uv_getnameinfo_s { + UV_REQ_FIELDS + /* read-only */ + uv_loop_t* loop; + /* host and service are marked as private, but they really aren't. */ + UV_GETNAMEINFO_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_getnameinfo(uv_loop_t* loop, + uv_getnameinfo_t* req, + uv_getnameinfo_cb getnameinfo_cb, + const struct sockaddr* addr, + int flags); + + +/* uv_spawn() options. */ +typedef enum { + UV_IGNORE = 0x00, + UV_CREATE_PIPE = 0x01, + UV_INHERIT_FD = 0x02, + UV_INHERIT_STREAM = 0x04, + + /* + * When UV_CREATE_PIPE is specified, UV_READABLE_PIPE and UV_WRITABLE_PIPE + * determine the direction of flow, from the child process' perspective. Both + * flags may be specified to create a duplex data stream. + */ + UV_READABLE_PIPE = 0x10, + UV_WRITABLE_PIPE = 0x20 +} uv_stdio_flags; + +typedef struct uv_stdio_container_s { + uv_stdio_flags flags; + + union { + uv_stream_t* stream; + int fd; + } data; +} uv_stdio_container_t; + +typedef struct uv_process_options_s { + uv_exit_cb exit_cb; /* Called after the process exits. */ + const char* file; /* Path to program to execute. */ + /* + * Command line arguments. args[0] should be the path to the program. On + * Windows this uses CreateProcess which concatenates the arguments into a + * string this can cause some strange errors. See the note at + * windows_verbatim_arguments. + */ + char** args; + /* + * This will be set as the environ variable in the subprocess. If this is + * NULL then the parents environ will be used. + */ + char** env; + /* + * If non-null this represents a directory the subprocess should execute + * in. Stands for current working directory. + */ + const char* cwd; + /* + * Various flags that control how uv_spawn() behaves. See the definition of + * `enum uv_process_flags` below. + */ + unsigned int flags; + /* + * The `stdio` field points to an array of uv_stdio_container_t structs that + * describe the file descriptors that will be made available to the child + * process. The convention is that stdio[0] points to stdin, fd 1 is used for + * stdout, and fd 2 is stderr. + * + * Note that on windows file descriptors greater than 2 are available to the + * child process only if the child processes uses the MSVCRT runtime. + */ + int stdio_count; + uv_stdio_container_t* stdio; + /* + * Libuv can change the child process' user/group id. This happens only when + * the appropriate bits are set in the flags fields. This is not supported on + * windows; uv_spawn() will fail and set the error to UV_ENOTSUP. + */ + uv_uid_t uid; + uv_gid_t gid; +} uv_process_options_t; + +/* + * These are the flags that can be used for the uv_process_options.flags field. + */ +enum uv_process_flags { + /* + * Set the child process' user id. The user id is supplied in the `uid` field + * of the options struct. This does not work on windows; setting this flag + * will cause uv_spawn() to fail. + */ + UV_PROCESS_SETUID = (1 << 0), + /* + * Set the child process' group id. The user id is supplied in the `gid` + * field of the options struct. This does not work on windows; setting this + * flag will cause uv_spawn() to fail. + */ + UV_PROCESS_SETGID = (1 << 1), + /* + * Do not wrap any arguments in quotes, or perform any other escaping, when + * converting the argument list into a command line string. This option is + * only meaningful on Windows systems. On Unix it is silently ignored. + */ + UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = (1 << 2), + /* + * Spawn the child process in a detached state - this will make it a process + * group leader, and will effectively enable the child to keep running after + * the parent exits. Note that the child process will still keep the + * parent's event loop alive unless the parent process calls uv_unref() on + * the child's process handle. + */ + UV_PROCESS_DETACHED = (1 << 3), + /* + * Hide the subprocess console window that would normally be created. This + * option is only meaningful on Windows systems. On Unix it is silently + * ignored. + */ + UV_PROCESS_WINDOWS_HIDE = (1 << 4) +}; + +/* + * uv_process_t is a subclass of uv_handle_t. + */ +struct uv_process_s { + UV_HANDLE_FIELDS + uv_exit_cb exit_cb; + int pid; + UV_PROCESS_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_spawn(uv_loop_t* loop, + uv_process_t* handle, + const uv_process_options_t* options); +UV_EXTERN int uv_process_kill(uv_process_t*, int signum); +UV_EXTERN int uv_kill(int pid, int signum); + + +/* + * uv_work_t is a subclass of uv_req_t. + */ +struct uv_work_s { + UV_REQ_FIELDS + uv_loop_t* loop; + uv_work_cb work_cb; + uv_after_work_cb after_work_cb; + UV_WORK_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_queue_work(uv_loop_t* loop, + uv_work_t* req, + uv_work_cb work_cb, + uv_after_work_cb after_work_cb); + +UV_EXTERN int uv_cancel(uv_req_t* req); + + +struct uv_cpu_info_s { + char* model; + int speed; + struct uv_cpu_times_s { + uint64_t user; + uint64_t nice; + uint64_t sys; + uint64_t idle; + uint64_t irq; + } cpu_times; +}; + +struct uv_interface_address_s { + char* name; + char phys_addr[6]; + int is_internal; + union { + struct sockaddr_in address4; + struct sockaddr_in6 address6; + } address; + union { + struct sockaddr_in netmask4; + struct sockaddr_in6 netmask6; + } netmask; +}; + +struct uv_passwd_s { + char* username; + long uid; + long gid; + char* shell; + char* homedir; +}; + +typedef enum { + UV_DIRENT_UNKNOWN, + UV_DIRENT_FILE, + UV_DIRENT_DIR, + UV_DIRENT_LINK, + UV_DIRENT_FIFO, + UV_DIRENT_SOCKET, + UV_DIRENT_CHAR, + UV_DIRENT_BLOCK +} uv_dirent_type_t; + +struct uv_dirent_s { + const char* name; + uv_dirent_type_t type; +}; + +UV_EXTERN char** uv_setup_args(int argc, char** argv); +UV_EXTERN int uv_get_process_title(char* buffer, size_t size); +UV_EXTERN int uv_set_process_title(const char* title); +UV_EXTERN int uv_resident_set_memory(size_t* rss); +UV_EXTERN int uv_uptime(double* uptime); +UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd); + +typedef struct { + long tv_sec; + long tv_usec; +} uv_timeval_t; + +typedef struct { + uv_timeval_t ru_utime; /* user CPU time used */ + uv_timeval_t ru_stime; /* system CPU time used */ + uint64_t ru_maxrss; /* maximum resident set size */ + uint64_t ru_ixrss; /* integral shared memory size */ + uint64_t ru_idrss; /* integral unshared data size */ + uint64_t ru_isrss; /* integral unshared stack size */ + uint64_t ru_minflt; /* page reclaims (soft page faults) */ + uint64_t ru_majflt; /* page faults (hard page faults) */ + uint64_t ru_nswap; /* swaps */ + uint64_t ru_inblock; /* block input operations */ + uint64_t ru_oublock; /* block output operations */ + uint64_t ru_msgsnd; /* IPC messages sent */ + uint64_t ru_msgrcv; /* IPC messages received */ + uint64_t ru_nsignals; /* signals received */ + uint64_t ru_nvcsw; /* voluntary context switches */ + uint64_t ru_nivcsw; /* involuntary context switches */ +} uv_rusage_t; + +UV_EXTERN int uv_getrusage(uv_rusage_t* rusage); + +UV_EXTERN int uv_os_homedir(char* buffer, size_t* size); +UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size); +UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd); +UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd); + +UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count); +UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count); + +UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses, + int* count); +UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses, + int count); + +UV_EXTERN int uv_os_getenv(const char* name, char* buffer, size_t* size); +UV_EXTERN int uv_os_setenv(const char* name, const char* value); +UV_EXTERN int uv_os_unsetenv(const char* name); + +UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size); + + +typedef enum { + UV_FS_UNKNOWN = -1, + UV_FS_CUSTOM, + UV_FS_OPEN, + UV_FS_CLOSE, + UV_FS_READ, + UV_FS_WRITE, + UV_FS_SENDFILE, + UV_FS_STAT, + UV_FS_LSTAT, + UV_FS_FSTAT, + UV_FS_FTRUNCATE, + UV_FS_UTIME, + UV_FS_FUTIME, + UV_FS_ACCESS, + UV_FS_CHMOD, + UV_FS_FCHMOD, + UV_FS_FSYNC, + UV_FS_FDATASYNC, + UV_FS_UNLINK, + UV_FS_RMDIR, + UV_FS_MKDIR, + UV_FS_MKDTEMP, + UV_FS_RENAME, + UV_FS_SCANDIR, + UV_FS_LINK, + UV_FS_SYMLINK, + UV_FS_READLINK, + UV_FS_CHOWN, + UV_FS_FCHOWN, + UV_FS_REALPATH +} uv_fs_type; + +/* uv_fs_t is a subclass of uv_req_t. */ +struct uv_fs_s { + UV_REQ_FIELDS + uv_fs_type fs_type; + uv_loop_t* loop; + uv_fs_cb cb; + ssize_t result; + void* ptr; + const char* path; + uv_stat_t statbuf; /* Stores the result of uv_fs_stat() and uv_fs_fstat(). */ + UV_FS_PRIVATE_FIELDS +}; + +UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req); +UV_EXTERN int uv_fs_close(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + uv_fs_cb cb); +UV_EXTERN int uv_fs_open(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + int flags, + int mode, + uv_fs_cb cb); +UV_EXTERN int uv_fs_read(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + const uv_buf_t bufs[], + unsigned int nbufs, + int64_t offset, + uv_fs_cb cb); +UV_EXTERN int uv_fs_unlink(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + uv_fs_cb cb); +UV_EXTERN int uv_fs_write(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + const uv_buf_t bufs[], + unsigned int nbufs, + int64_t offset, + uv_fs_cb cb); +UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + int mode, + uv_fs_cb cb); +UV_EXTERN int uv_fs_mkdtemp(uv_loop_t* loop, + uv_fs_t* req, + const char* tpl, + uv_fs_cb cb); +UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + uv_fs_cb cb); +UV_EXTERN int uv_fs_scandir(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + int flags, + uv_fs_cb cb); +UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req, + uv_dirent_t* ent); +UV_EXTERN int uv_fs_stat(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + uv_fs_cb cb); +UV_EXTERN int uv_fs_fstat(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + uv_fs_cb cb); +UV_EXTERN int uv_fs_rename(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + const char* new_path, + uv_fs_cb cb); +UV_EXTERN int uv_fs_fsync(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + uv_fs_cb cb); +UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + uv_fs_cb cb); +UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + int64_t offset, + uv_fs_cb cb); +UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop, + uv_fs_t* req, + uv_file out_fd, + uv_file in_fd, + int64_t in_offset, + size_t length, + uv_fs_cb cb); +UV_EXTERN int uv_fs_access(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + int mode, + uv_fs_cb cb); +UV_EXTERN int uv_fs_chmod(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + int mode, + uv_fs_cb cb); +UV_EXTERN int uv_fs_utime(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + double atime, + double mtime, + uv_fs_cb cb); +UV_EXTERN int uv_fs_futime(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + double atime, + double mtime, + uv_fs_cb cb); +UV_EXTERN int uv_fs_lstat(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + uv_fs_cb cb); +UV_EXTERN int uv_fs_link(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + const char* new_path, + uv_fs_cb cb); + +/* + * This flag can be used with uv_fs_symlink() on Windows to specify whether + * path argument points to a directory. + */ +#define UV_FS_SYMLINK_DIR 0x0001 + +/* + * This flag can be used with uv_fs_symlink() on Windows to specify whether + * the symlink is to be created using junction points. + */ +#define UV_FS_SYMLINK_JUNCTION 0x0002 + +UV_EXTERN int uv_fs_symlink(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + const char* new_path, + int flags, + uv_fs_cb cb); +UV_EXTERN int uv_fs_readlink(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + uv_fs_cb cb); +UV_EXTERN int uv_fs_realpath(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + uv_fs_cb cb); +UV_EXTERN int uv_fs_fchmod(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + int mode, + uv_fs_cb cb); +UV_EXTERN int uv_fs_chown(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + uv_uid_t uid, + uv_gid_t gid, + uv_fs_cb cb); +UV_EXTERN int uv_fs_fchown(uv_loop_t* loop, + uv_fs_t* req, + uv_file file, + uv_uid_t uid, + uv_gid_t gid, + uv_fs_cb cb); + + +enum uv_fs_event { + UV_RENAME = 1, + UV_CHANGE = 2 +}; + + +struct uv_fs_event_s { + UV_HANDLE_FIELDS + /* private */ + char* path; + UV_FS_EVENT_PRIVATE_FIELDS +}; + + +/* + * uv_fs_stat() based polling file watcher. + */ +struct uv_fs_poll_s { + UV_HANDLE_FIELDS + /* Private, don't touch. */ + void* poll_ctx; +}; + +UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle); +UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle, + uv_fs_poll_cb poll_cb, + const char* path, + unsigned int interval); +UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle); +UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle, + char* buffer, + size_t* size); + + +struct uv_signal_s { + UV_HANDLE_FIELDS + uv_signal_cb signal_cb; + int signum; + UV_SIGNAL_PRIVATE_FIELDS +}; + +UV_EXTERN int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle); +UV_EXTERN int uv_signal_start(uv_signal_t* handle, + uv_signal_cb signal_cb, + int signum); +UV_EXTERN int uv_signal_start_oneshot(uv_signal_t* handle, + uv_signal_cb signal_cb, + int signum); +UV_EXTERN int uv_signal_stop(uv_signal_t* handle); + +UV_EXTERN void uv_loadavg(double avg[3]); + + +/* + * Flags to be passed to uv_fs_event_start(). + */ +enum uv_fs_event_flags { + /* + * By default, if the fs event watcher is given a directory name, we will + * watch for all events in that directory. This flags overrides this behavior + * and makes fs_event report only changes to the directory entry itself. This + * flag does not affect individual files watched. + * This flag is currently not implemented yet on any backend. + */ + UV_FS_EVENT_WATCH_ENTRY = 1, + + /* + * By default uv_fs_event will try to use a kernel interface such as inotify + * or kqueue to detect events. This may not work on remote filesystems such + * as NFS mounts. This flag makes fs_event fall back to calling stat() on a + * regular interval. + * This flag is currently not implemented yet on any backend. + */ + UV_FS_EVENT_STAT = 2, + + /* + * By default, event watcher, when watching directory, is not registering + * (is ignoring) changes in it's subdirectories. + * This flag will override this behaviour on platforms that support it. + */ + UV_FS_EVENT_RECURSIVE = 4 +}; + + +UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle); +UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle, + uv_fs_event_cb cb, + const char* path, + unsigned int flags); +UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle); +UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle, + char* buffer, + size_t* size); + +UV_EXTERN int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr); +UV_EXTERN int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr); + +UV_EXTERN int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size); +UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size); + +UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size); +UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst); + +UV_EXTERN int uv_exepath(char* buffer, size_t* size); + +UV_EXTERN int uv_cwd(char* buffer, size_t* size); + +UV_EXTERN int uv_chdir(const char* dir); + +UV_EXTERN uint64_t uv_get_free_memory(void); +UV_EXTERN uint64_t uv_get_total_memory(void); + +UV_EXTERN uint64_t uv_hrtime(void); + +UV_EXTERN void uv_disable_stdio_inheritance(void); + +UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib); +UV_EXTERN void uv_dlclose(uv_lib_t* lib); +UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr); +UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib); + +UV_EXTERN int uv_mutex_init(uv_mutex_t* handle); +UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle); +UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle); +UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle); +UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle); + +UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock); +UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock); +UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock); +UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock); +UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock); +UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock); +UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock); +UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock); + +UV_EXTERN int uv_sem_init(uv_sem_t* sem, unsigned int value); +UV_EXTERN void uv_sem_destroy(uv_sem_t* sem); +UV_EXTERN void uv_sem_post(uv_sem_t* sem); +UV_EXTERN void uv_sem_wait(uv_sem_t* sem); +UV_EXTERN int uv_sem_trywait(uv_sem_t* sem); + +UV_EXTERN int uv_cond_init(uv_cond_t* cond); +UV_EXTERN void uv_cond_destroy(uv_cond_t* cond); +UV_EXTERN void uv_cond_signal(uv_cond_t* cond); +UV_EXTERN void uv_cond_broadcast(uv_cond_t* cond); + +UV_EXTERN int uv_barrier_init(uv_barrier_t* barrier, unsigned int count); +UV_EXTERN void uv_barrier_destroy(uv_barrier_t* barrier); +UV_EXTERN int uv_barrier_wait(uv_barrier_t* barrier); + +UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex); +UV_EXTERN int uv_cond_timedwait(uv_cond_t* cond, + uv_mutex_t* mutex, + uint64_t timeout); + +UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void)); + +UV_EXTERN int uv_key_create(uv_key_t* key); +UV_EXTERN void uv_key_delete(uv_key_t* key); +UV_EXTERN void* uv_key_get(uv_key_t* key); +UV_EXTERN void uv_key_set(uv_key_t* key, void* value); + +typedef void (*uv_thread_cb)(void* arg); + +UV_EXTERN int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg); +UV_EXTERN uv_thread_t uv_thread_self(void); +UV_EXTERN int uv_thread_join(uv_thread_t *tid); +UV_EXTERN int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2); + +/* The presence of these unions force similar struct layout. */ +#define XX(_, name) uv_ ## name ## _t name; +union uv_any_handle { + UV_HANDLE_TYPE_MAP(XX) +}; + +union uv_any_req { + UV_REQ_TYPE_MAP(XX) +}; +#undef XX + + +struct uv_loop_s { + /* User data - use this for whatever. */ + void* data; + /* Loop reference counting. */ + unsigned int active_handles; + void* handle_queue[2]; + void* active_reqs[2]; + /* Internal flag to signal loop stop. */ + unsigned int stop_flag; + UV_LOOP_PRIVATE_FIELDS +}; + + +/* Don't export the private CPP symbols. */ +#undef UV_HANDLE_TYPE_PRIVATE +#undef UV_REQ_TYPE_PRIVATE +#undef UV_REQ_PRIVATE_FIELDS +#undef UV_STREAM_PRIVATE_FIELDS +#undef UV_TCP_PRIVATE_FIELDS +#undef UV_PREPARE_PRIVATE_FIELDS +#undef UV_CHECK_PRIVATE_FIELDS +#undef UV_IDLE_PRIVATE_FIELDS +#undef UV_ASYNC_PRIVATE_FIELDS +#undef UV_TIMER_PRIVATE_FIELDS +#undef UV_GETADDRINFO_PRIVATE_FIELDS +#undef UV_GETNAMEINFO_PRIVATE_FIELDS +#undef UV_FS_REQ_PRIVATE_FIELDS +#undef UV_WORK_PRIVATE_FIELDS +#undef UV_FS_EVENT_PRIVATE_FIELDS +#undef UV_SIGNAL_PRIVATE_FIELDS +#undef UV_LOOP_PRIVATE_FIELDS +#undef UV_LOOP_PRIVATE_PLATFORM_FIELDS + +#ifdef __cplusplus +} +#endif +#endif /* UV_H */ diff --git a/android/x86/include/v8/APIDesign.md b/android/x86/include/v8/APIDesign.md new file mode 100755 index 00000000..8830fff7 --- /dev/null +++ b/android/x86/include/v8/APIDesign.md @@ -0,0 +1,69 @@ +# The V8 public C++ API + +# Overview + +The V8 public C++ API aims to support four use cases: + +1. Enable applications that embed V8 (called the embedder) to configure and run + one or more instances of V8. +2. Expose ECMAScript-like capabilities to the embedder. +3. Enable the embedder to interact with ECMAScript by exposing API objects. +4. Provide access to the V8 debugger (inspector). + +# Configuring and running an instance of V8 + +V8 requires access to certain OS-level primitives such as the ability to +schedule work on threads, or allocate memory. + +The embedder can define how to access those primitives via the v8::Platform +interface. While V8 bundles a basic implementation, embedders are highly +encouraged to implement v8::Platform themselves. + +Currently, the v8::ArrayBuffer::Allocator is passed to the v8::Isolate factory +method, however, conceptually it should also be part of the v8::Platform since +all instances of V8 should share one allocator. + +Once the v8::Platform is configured, an v8::Isolate can be created. All +further interactions with V8 should explicitly reference the v8::Isolate they +refer to. All API methods should eventually take an v8::Isolate parameter. + +When a given instance of V8 is no longer needed, it can be destroyed by +disposing the respective v8::Isolate. If the embedder wishes to free all memory +associated with the v8::Isolate, it has to first clear all global handles +associated with that v8::Isolate. + +# ECMAScript-like capabilities + +In general, the C++ API shouldn't enable capabilities that aren't available to +scripts running in V8. Experience has shown that it's not possible to maintain +such API methods in the long term. However, capabilities also available to +scripts, i.e., ones that are defined in the ECMAScript standard are there to +stay, and we can safely expose them to embedders. + +The C++ API should also be pleasant to use, and not require learning new +paradigms. Similarly to how the API exposed to scripts aims to provide good +ergonomics, we should aim to provide a reasonable developer experience for this +API surface. + +ECMAScript makes heavy use of exceptions, however, V8's C++ code doesn't use +C++ exceptions. Therefore, all API methods that can throw exceptions should +indicate so by returning a v8::Maybe<> or v8::MaybeLocal<> result, +and by taking a v8::Local<v8::Context> parameter that indicates in which +context a possible exception should be thrown. + +# API objects + +V8 allows embedders to define special objects that expose additional +capabilities and APIs to scripts. The most prominent example is exposing the +HTML DOM in Blink. Other examples are e.g. node.js. It is less clear what kind +of capabilities we want to expose via this API surface. As a rule of thumb, we +want to expose operations as defined in the WebIDL and HTML spec: we +assume that those requirements are somewhat stable, and that they are a +superset of the requirements of other embedders including node.js. + +Ideally, the API surfaces defined in those specs hook into the ECMAScript spec +which in turn guarantees long-term stability of the API. + +# The V8 inspector + +All debugging capabilities of V8 should be exposed via the inspector protocol. diff --git a/android/x86/include/v8/DEPS b/android/x86/include/v8/DEPS new file mode 100755 index 00000000..ca60f841 --- /dev/null +++ b/android/x86/include/v8/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + # v8-inspector-protocol.h depends on generated files under include/inspector. + "+inspector", +] diff --git a/android/x86/include/v8/OWNERS b/android/x86/include/v8/OWNERS new file mode 100755 index 00000000..7953cfe1 --- /dev/null +++ b/android/x86/include/v8/OWNERS @@ -0,0 +1,16 @@ +set noparent + +adamk@chromium.org +danno@chromium.org +ulan@chromium.org +yangguo@chromium.org + +per-file v8-internal.h=file://OWNERS +per-file v8-inspector.h=dgozman@chromium.org +per-file v8-inspector.h=pfeldman@chromium.org +per-file v8-inspector.h=kozyatinskiy@chromium.org +per-file v8-inspector-protocol.h=dgozman@chromium.org +per-file v8-inspector-protocol.h=pfeldman@chromium.org +per-file v8-inspector-protocol.h=kozyatinskiy@chromium.org + +# COMPONENT: Blink>JavaScript>API diff --git a/android/x86/include/v8/libc++/CMakeLists.txt b/android/x86/include/v8/libc++/CMakeLists.txt new file mode 100755 index 00000000..9880115c --- /dev/null +++ b/android/x86/include/v8/libc++/CMakeLists.txt @@ -0,0 +1,273 @@ +set(files + __bit_reference + __bsd_locale_defaults.h + __bsd_locale_fallbacks.h + __errc + __debug + __functional_03 + __functional_base + __functional_base_03 + __hash_table + __libcpp_version + __locale + __mutex_base + __node_handle + __nullptr + __split_buffer + __sso_allocator + __std_stream + __string + __threading_support + __tree + __tuple + __undef_macros + algorithm + any + array + atomic + bit + bitset + cassert + ccomplex + cctype + cerrno + cfenv + cfloat + charconv + chrono + cinttypes + ciso646 + climits + clocale + cmath + codecvt + compare + complex + complex.h + condition_variable + csetjmp + csignal + cstdarg + cstdbool + cstddef + cstdint + cstdio + cstdlib + cstring + ctgmath + ctime + ctype.h + cwchar + cwctype + deque + errno.h + exception + experimental/__config + experimental/__memory + experimental/algorithm + experimental/any + experimental/chrono + experimental/coroutine + experimental/deque + experimental/filesystem + experimental/forward_list + experimental/functional + experimental/iterator + experimental/list + experimental/map + experimental/memory_resource + experimental/numeric + experimental/optional + experimental/propagate_const + experimental/ratio + experimental/regex + experimental/set + experimental/simd + experimental/string + experimental/string_view + experimental/system_error + experimental/tuple + experimental/type_traits + experimental/unordered_map + experimental/unordered_set + experimental/utility + experimental/vector + ext/__hash + ext/hash_map + ext/hash_set + fenv.h + filesystem + float.h + forward_list + fstream + functional + future + initializer_list + inttypes.h + iomanip + ios + iosfwd + iostream + istream + iterator + limits + limits.h + list + locale + locale.h + map + math.h + memory + module.modulemap + mutex + new + numeric + optional + ostream + queue + random + ratio + regex + scoped_allocator + set + setjmp.h + shared_mutex + span + sstream + stack + stdbool.h + stddef.h + stdexcept + stdint.h + stdio.h + stdlib.h + streambuf + string + string.h + string_view + strstream + system_error + tgmath.h + thread + tuple + type_traits + typeindex + typeinfo + unordered_map + unordered_set + utility + valarray + variant + vector + version + wchar.h + wctype.h + ) + +if(LIBCXX_INSTALL_SUPPORT_HEADERS) + set(files + ${files} + support/android/locale_bionic.h + support/fuchsia/xlocale.h + support/ibm/limits.h + support/ibm/locale_mgmt_aix.h + support/ibm/support.h + support/ibm/xlocale.h + support/musl/xlocale.h + support/newlib/xlocale.h + support/solaris/floatingpoint.h + support/solaris/wchar.h + support/solaris/xlocale.h + support/win32/limits_msvc_win32.h + support/win32/locale_win32.h + support/xlocale/__nop_locale_mgmt.h + support/xlocale/__posix_l_fallback.h + support/xlocale/__strtonum_fallback.h + ) +endif() + +if (LIBCXX_NEEDS_SITE_CONFIG) + # Generate a custom __config header. The new header is created + # by prepending __config_site to the current __config header. + add_custom_command(OUTPUT ${LIBCXX_BINARY_DIR}/__generated_config + COMMAND ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/cat_files.py + ${LIBCXX_BINARY_DIR}/__config_site + ${LIBCXX_SOURCE_DIR}/include/__config + -o ${LIBCXX_BINARY_DIR}/__generated_config + DEPENDS ${LIBCXX_SOURCE_DIR}/include/__config + ${LIBCXX_BINARY_DIR}/__config_site + ) + # Add a target that executes the generation commands. + add_custom_target(cxx-generated-config ALL + DEPENDS ${LIBCXX_BINARY_DIR}/__generated_config) + set(generated_config_deps cxx-generated-config) +else() + set(files + ${files} + __config + ) +endif() + +if(NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR) + set(output_dir ${LIBCXX_HEADER_DIR}/include/c++/v1) + + set(out_files) + foreach(f ${files}) + set(src ${CMAKE_CURRENT_SOURCE_DIR}/${f}) + set(dst ${output_dir}/${f}) + add_custom_command(OUTPUT ${dst} + DEPENDS ${src} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} + COMMENT "Copying CXX header ${f}") + list(APPEND out_files ${dst}) + endforeach() + + if (LIBCXX_NEEDS_SITE_CONFIG) + # Copy the generated header as __config into build directory. + set(src ${LIBCXX_BINARY_DIR}/__generated_config) + set(dst ${output_dir}/__config) + add_custom_command(OUTPUT ${dst} + DEPENDS ${src} ${generated_config_deps} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} + COMMENT "Copying CXX __config") + list(APPEND out_files ${dst}) + endif() + + add_custom_target(cxx-headers ALL DEPENDS ${out_files} ${LIBCXX_CXX_ABI_HEADER_TARGET}) +else() + add_custom_target(cxx-headers) +endif() +set_target_properties(cxx-headers PROPERTIES FOLDER "Misc") + +if (LIBCXX_INSTALL_HEADERS) + foreach(file ${files}) + get_filename_component(dir ${file} DIRECTORY) + install(FILES ${file} + DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) + endforeach() + + if (LIBCXX_NEEDS_SITE_CONFIG) + # Install the generated header as __config. + install(FILES ${LIBCXX_BINARY_DIR}/__generated_config + DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + RENAME __config + COMPONENT cxx-headers) + endif() + + if (NOT CMAKE_CONFIGURATION_TYPES) + add_custom_target(install-cxx-headers + DEPENDS cxx-headers ${generated_config_deps} + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxx-headers + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + # Stripping is a no-op for headers + add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers) + + add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers) + add_custom_target(install-libcxx-headers-stripped DEPENDS install-cxx-headers-stripped) + endif() +endif() diff --git a/android/x86/include/v8/libc++/__bit_reference b/android/x86/include/v8/libc++/__bit_reference new file mode 100755 index 00000000..4fd1d2f6 --- /dev/null +++ b/android/x86/include/v8/libc++/__bit_reference @@ -0,0 +1,1280 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___BIT_REFERENCE +#define _LIBCPP___BIT_REFERENCE + +#include <__config> +#include <bit> +#include <algorithm> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0> class __bit_iterator; +template <class _Cp> class __bit_const_reference; + +template <class _Tp> +struct __has_storage_type +{ + static const bool value = false; +}; + +template <class _Cp, bool = __has_storage_type<_Cp>::value> +class __bit_reference +{ + typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + + friend typename _Cp::__self; + + friend class __bit_const_reference<_Cp>; + friend class __bit_iterator<_Cp, false>; +public: + _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT + {return static_cast<bool>(*__seg_ & __mask_);} + _LIBCPP_INLINE_VISIBILITY bool operator ~() const _NOEXCEPT + {return !static_cast<bool>(*this);} + + _LIBCPP_INLINE_VISIBILITY + __bit_reference& operator=(bool __x) _NOEXCEPT + { + if (__x) + *__seg_ |= __mask_; + else + *__seg_ &= ~__mask_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT + {return operator=(static_cast<bool>(__x));} + + _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;} + _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const _NOEXCEPT + {return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(__ctz(__mask_)));} +private: + _LIBCPP_INLINE_VISIBILITY + __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT + : __seg_(__s), __mask_(__m) {} +}; + +template <class _Cp> +class __bit_reference<_Cp, false> +{ +}; + +template <class _Cp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template <class _Cp, class _Dp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template <class _Cp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template <class _Cp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template <class _Cp> +class __bit_const_reference +{ + typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__const_storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + + friend typename _Cp::__self; + friend class __bit_iterator<_Cp, true>; +public: + _LIBCPP_INLINE_VISIBILITY + __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT + : __seg_(__x.__seg_), __mask_(__x.__mask_) {} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT + {return static_cast<bool>(*__seg_ & __mask_);} + + _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT + {return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__ctz(__mask_)));} +private: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR + __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT + : __seg_(__s), __mask_(__m) {} + + __bit_const_reference& operator=(const __bit_const_reference& __x); +}; + +// find + +template <class _Cp, bool _IsConst> +__bit_iterator<_Cp, _IsConst> +__find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + static const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + if (__n == __dn) + return __first + __n; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + if (*__first.__seg_) + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(*__first.__seg_))); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + } + return _It(__first.__seg_, static_cast<unsigned>(__n)); +} + +template <class _Cp, bool _IsConst> +__bit_iterator<_Cp, _IsConst> +__find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = ~*__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + if (__n == __dn) + return __first + __n; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + { + __storage_type __b = ~*__first.__seg_; + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + } + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = ~*__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + } + return _It(__first.__seg_, static_cast<unsigned>(__n)); +} + +template <class _Cp, bool _IsConst, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_Cp, _IsConst> +find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_) +{ + if (static_cast<bool>(__value_)) + return __find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first)); + return __find_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first)); +} + +// count + +template <class _Cp, bool _IsConst> +typename __bit_iterator<_Cp, _IsConst>::difference_type +__count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + const int __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _VSTD::__popcount(*__first.__seg_ & __m); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _VSTD::__popcount(*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _VSTD::__popcount(*__first.__seg_ & __m); + } + return __r; +} + +template <class _Cp, bool _IsConst> +typename __bit_iterator<_Cp, _IsConst>::difference_type +__count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, _IsConst> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + const int __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _VSTD::__popcount(~*__first.__seg_ & __m); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _VSTD::__popcount(~*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _VSTD::__popcount(~*__first.__seg_ & __m); + } + return __r; +} + +template <class _Cp, bool _IsConst, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename __bit_iterator<_Cp, _IsConst>::difference_type +count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_) +{ + if (static_cast<bool>(__value_)) + return __count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first)); + return __count_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first)); +} + +// fill_n + +template <class _Cp> +void +__fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, false> _It; + typedef typename _It::__storage_type __storage_type; + const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + *__first.__seg_ &= ~__m; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + __storage_type __nw = __n / __bits_per_word; + _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), 0, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last partial word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__first.__seg_ &= ~__m; + } +} + +template <class _Cp> +void +__fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) +{ + typedef __bit_iterator<_Cp, false> _It; + typedef typename _It::__storage_type __storage_type; + const int __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + *__first.__seg_ |= __m; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + __storage_type __nw = __n / __bits_per_word; + _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), -1, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last partial word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__first.__seg_ |= __m; + } +} + +template <class _Cp> +inline _LIBCPP_INLINE_VISIBILITY +void +fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value_) +{ + if (__n > 0) + { + if (__value_) + __fill_n_true(__first, __n); + else + __fill_n_false(__first, __n); + } +} + +// fill + +template <class _Cp> +inline _LIBCPP_INLINE_VISIBILITY +void +fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value_) +{ + _VSTD::fill_n(__first, static_cast<typename _Cp::size_type>(__last - __first), __value_); +} + +// copy + +template <class _Cp, bool _IsConst> +__bit_iterator<_Cp, false> +__copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first.__ctz_; + difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + __storage_type __b = *__first.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word); + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + __storage_type __nw = __n / __bits_per_word; + _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_), + _VSTD::__to_raw_pointer(__first.__seg_), + __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + __result.__seg_ += __nw; + // do last word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast<unsigned>(__n); + } + } + return __result; +} + +template <class _Cp, bool _IsConst> +__bit_iterator<_Cp, false> +__copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + static const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first.__ctz_; + difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __first.__ctz_) + *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_); + else + *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_); + __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn); + __result.__ctz_ = static_cast<unsigned>(__dn); + } + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __m = ~__storage_type(0) << __result.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) + { + __storage_type __b = *__first.__seg_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << __result.__ctz_; + ++__result.__seg_; + *__result.__seg_ &= __m; + *__result.__seg_ |= __b >> __clz_r; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__clz_r)); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << __result.__ctz_; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> __dn; + __result.__ctz_ = static_cast<unsigned>(__n); + } + } + } + return __result; +} + +template <class _Cp, bool _IsConst> +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + if (__first.__ctz_ == __result.__ctz_) + return __copy_aligned(__first, __last, __result); + return __copy_unaligned(__first, __last, __result); +} + +// copy_backward + +template <class _Cp, bool _IsConst> +__bit_iterator<_Cp, false> +__copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__last.__ctz_ != 0) + { + difference_type __dn = _VSTD::min(static_cast<difference_type>(__last.__ctz_), __n); + __n -= __dn; + unsigned __clz = __bits_per_word - __last.__ctz_; + __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz); + __storage_type __b = *__last.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + // __last.__ctz_ = 0 + } + // __last.__ctz_ == 0 || __n == 0 + // __result.__ctz_ == 0 || __n == 0 + // do middle words + __storage_type __nw = __n / __bits_per_word; + __result.__seg_ -= __nw; + __last.__seg_ -= __nw; + _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_), + _VSTD::__to_raw_pointer(__last.__seg_), + __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) << (__bits_per_word - __n); + __storage_type __b = *--__last.__seg_ & __m; + *--__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1)); + } + } + return __result; +} + +template <class _Cp, bool _IsConst> +__bit_iterator<_Cp, false> +__copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, + __bit_iterator<_Cp, false> __result) +{ + typedef __bit_iterator<_Cp, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + const int __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__last.__ctz_ != 0) + { + difference_type __dn = _VSTD::min(static_cast<difference_type>(__last.__ctz_), __n); + __n -= __dn; + unsigned __clz_l = __bits_per_word - __last.__ctz_; + __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l); + __storage_type __b = *__last.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _VSTD::min(__dn, static_cast<difference_type>(__result.__ctz_)); + if (__ddn > 0) + { + __m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r); + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __last.__ctz_) + *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); + else + *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_); + __result.__ctz_ = static_cast<unsigned>(((-__ddn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + } + if (__dn > 0) + { + // __result.__ctz_ == 0 + --__result.__seg_; + __result.__ctz_ = static_cast<unsigned>(-__dn & (__bits_per_word - 1)); + __m = ~__storage_type(0) << __result.__ctz_; + *__result.__seg_ &= ~__m; + __last.__ctz_ -= __dn + __ddn; + *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); + } + // __last.__ctz_ = 0 + } + // __last.__ctz_ == 0 || __n == 0 + // __result.__ctz_ != 0 || __n == 0 + // do middle words + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __m = ~__storage_type(0) >> __clz_r; + for (; __n >= __bits_per_word; __n -= __bits_per_word) + { + __storage_type __b = *--__last.__seg_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> __clz_r; + *--__result.__seg_ &= __m; + *__result.__seg_ |= __b << __result.__ctz_; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) << (__bits_per_word - __n); + __storage_type __b = *--__last.__seg_ & __m; + __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__result.__ctz_)); + __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_); + __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + // __result.__ctz_ == 0 + --__result.__seg_; + __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1)); + __m = ~__storage_type(0) << __result.__ctz_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn)); + } + } + } + return __result; +} + +template <class _Cp, bool _IsConst> +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + if (__last.__ctz_ == __result.__ctz_) + return __copy_backward_aligned(__first, __last, __result); + return __copy_backward_unaligned(__first, __last, __result); +} + +// move + +template <class _Cp, bool _IsConst> +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +move(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + return _VSTD::copy(__first, __last, __result); +} + +// move_backward + +template <class _Cp, bool _IsConst> +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_Cp, false> +move_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) +{ + return _VSTD::copy_backward(__first, __last, __result); +} + +// swap_ranges + +template <class __C1, class __C2> +__bit_iterator<__C2, false> +__swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, + __bit_iterator<__C2, false> __result) +{ + typedef __bit_iterator<__C1, false> _I1; + typedef typename _I1::difference_type difference_type; + typedef typename _I1::__storage_type __storage_type; + const int __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first.__ctz_; + difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word); + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_) + swap(*__first.__seg_, *__result.__seg_); + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__ctz_ = static_cast<unsigned>(__n); + } + } + return __result; +} + +template <class __C1, class __C2> +__bit_iterator<__C2, false> +__swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, + __bit_iterator<__C2, false> __result) +{ + typedef __bit_iterator<__C1, false> _I1; + typedef typename _I1::difference_type difference_type; + typedef typename _I1::__storage_type __storage_type; + const int __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first.__ctz_; + difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __first.__ctz_) + { + unsigned __s = __result.__ctz_ - __first.__ctz_; + *__result.__seg_ |= __b1 << __s; + *__first.__seg_ |= __b2 >> __s; + } + else + { + unsigned __s = __first.__ctz_ - __result.__ctz_; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + } + __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + unsigned __s = __first.__ctz_ + __ddn; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + __result.__ctz_ = static_cast<unsigned>(__dn); + } + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + __storage_type __m = ~__storage_type(0) << __result.__ctz_; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) + { + __storage_type __b1 = *__first.__seg_; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ = __b2 >> __result.__ctz_; + ++__result.__seg_; + __b2 = *__result.__seg_ & ~__m; + *__result.__seg_ &= __m; + *__result.__seg_ |= __b1 >> __clz_r; + *__first.__seg_ |= __b2 << __clz_r; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __dn = _VSTD::min<__storage_type>(__n, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ |= __b2 >> __result.__ctz_; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 >> __dn; + *__first.__seg_ |= __b2 << __dn; + __result.__ctz_ = static_cast<unsigned>(__n); + } + } + } + return __result; +} + +template <class __C1, class __C2> +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<__C2, false> +swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1, + __bit_iterator<__C2, false> __first2) +{ + if (__first1.__ctz_ == __first2.__ctz_) + return __swap_ranges_aligned(__first1, __last1, __first2); + return __swap_ranges_unaligned(__first1, __last1, __first2); +} + +// rotate + +template <class _Cp> +struct __bit_array +{ + typedef typename _Cp::difference_type difference_type; + typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__storage_pointer __storage_pointer; + typedef typename _Cp::iterator iterator; + static const unsigned __bits_per_word = _Cp::__bits_per_word; + static const unsigned _Np = 4; + + difference_type __size_; + __storage_type __word_[_Np]; + + _LIBCPP_INLINE_VISIBILITY static difference_type capacity() + {return static_cast<difference_type>(_Np * __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {} + _LIBCPP_INLINE_VISIBILITY iterator begin() + { + return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0); + } + _LIBCPP_INLINE_VISIBILITY iterator end() + { + return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word, + static_cast<unsigned>(__size_ % __bits_per_word)); + } +}; + +template <class _Cp> +__bit_iterator<_Cp, false> +rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last) +{ + typedef __bit_iterator<_Cp, false> _I1; + typedef typename _I1::difference_type difference_type; + difference_type __d1 = __middle - __first; + difference_type __d2 = __last - __middle; + _I1 __r = __first + __d2; + while (__d1 != 0 && __d2 != 0) + { + if (__d1 <= __d2) + { + if (__d1 <= __bit_array<_Cp>::capacity()) + { + __bit_array<_Cp> __b(__d1); + _VSTD::copy(__first, __middle, __b.begin()); + _VSTD::copy(__b.begin(), __b.end(), _VSTD::copy(__middle, __last, __first)); + break; + } + else + { + __bit_iterator<_Cp, false> __mp = _VSTD::swap_ranges(__first, __middle, __middle); + __first = __middle; + __middle = __mp; + __d2 -= __d1; + } + } + else + { + if (__d2 <= __bit_array<_Cp>::capacity()) + { + __bit_array<_Cp> __b(__d2); + _VSTD::copy(__middle, __last, __b.begin()); + _VSTD::copy_backward(__b.begin(), __b.end(), _VSTD::copy_backward(__first, __middle, __last)); + break; + } + else + { + __bit_iterator<_Cp, false> __mp = __first + __d2; + _VSTD::swap_ranges(__first, __mp, __middle); + __first = __mp; + __d1 -= __d2; + } + } + } + return __r; +} + +// equal + +template <class _Cp, bool _IC1, bool _IC2> +bool +__equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, + __bit_iterator<_Cp, _IC2> __first2) +{ + typedef __bit_iterator<_Cp, _IC1> _It; + typedef typename _It::difference_type difference_type; + typedef typename _It::__storage_type __storage_type; + static const int __bits_per_word = _It::__bits_per_word; + difference_type __n = __last1 - __first1; + if (__n > 0) + { + // do first word + if (__first1.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first1.__ctz_; + difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first1.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __first2.__ctz_; + __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + if (__first2.__ctz_ > __first1.__ctz_) + { + if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_))) + return false; + } + else + { + if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_))) + return false; + } + __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word; + __first2.__ctz_ = static_cast<unsigned>((__ddn + __first2.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn))) + return false; + __first2.__ctz_ = static_cast<unsigned>(__dn); + } + ++__first1.__seg_; + // __first1.__ctz_ = 0; + } + // __first1.__ctz_ == 0; + // do middle words + unsigned __clz_r = __bits_per_word - __first2.__ctz_; + __storage_type __m = ~__storage_type(0) << __first2.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_) + { + __storage_type __b = *__first1.__seg_; + if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) + return false; + ++__first2.__seg_; + if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r)) + return false; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first1.__seg_ & __m; + __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__clz_r)); + __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) + return false; + __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word; + __first2.__ctz_ = static_cast<unsigned>((__dn + __first2.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + if ((*__first2.__seg_ & __m) != (__b >> __dn)) + return false; + } + } + } + return true; +} + +template <class _Cp, bool _IC1, bool _IC2> +bool +__equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, + __bit_iterator<_Cp, _IC2> __first2) +{ + typedef __bit_iterator<_Cp, _IC1> _It; + typedef typename _It::difference_type difference_type; + typedef typename _It::__storage_type __storage_type; + static const int __bits_per_word = _It::__bits_per_word; + difference_type __n = __last1 - __first1; + if (__n > 0) + { + // do first word + if (__first1.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first1.__ctz_; + difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) + return false; + ++__first2.__seg_; + ++__first1.__seg_; + // __first1.__ctz_ = 0; + // __first2.__ctz_ = 0; + } + // __first1.__ctz_ == 0; + // __first2.__ctz_ == 0; + // do middle words + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_) + if (*__first2.__seg_ != *__first1.__seg_) + return false; + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) + return false; + } + } + return true; +} + +template <class _Cp, bool _IC1, bool _IC2> +inline _LIBCPP_INLINE_VISIBILITY +bool +equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) +{ + if (__first1.__ctz_ == __first2.__ctz_) + return __equal_aligned(__first1, __last1, __first2); + return __equal_unaligned(__first1, __last1, __first2); +} + +template <class _Cp, bool _IsConst, + typename _Cp::__storage_type> +class __bit_iterator +{ +public: + typedef typename _Cp::difference_type difference_type; + typedef bool value_type; + typedef __bit_iterator pointer; + typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference; + typedef random_access_iterator_tag iterator_category; + +private: + typedef typename _Cp::__storage_type __storage_type; + typedef typename conditional<_IsConst, typename _Cp::__const_storage_pointer, + typename _Cp::__storage_pointer>::type __storage_pointer; + static const unsigned __bits_per_word = _Cp::__bits_per_word; + + __storage_pointer __seg_; + unsigned __ctz_; + +public: + _LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __seg_(nullptr), __ctz_(0) +#endif + {} + + _LIBCPP_INLINE_VISIBILITY + __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT + : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT + {return reference(__seg_, __storage_type(1) << __ctz_);} + + _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator++() + { + if (__ctz_ != __bits_per_word-1) + ++__ctz_; + else + { + __ctz_ = 0; + ++__seg_; + } + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator operator++(int) + { + __bit_iterator __tmp = *this; + ++(*this); + return __tmp; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator--() + { + if (__ctz_ != 0) + --__ctz_; + else + { + __ctz_ = __bits_per_word - 1; + --__seg_; + } + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator operator--(int) + { + __bit_iterator __tmp = *this; + --(*this); + return __tmp; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator+=(difference_type __n) + { + if (__n >= 0) + __seg_ += (__n + __ctz_) / __bits_per_word; + else + __seg_ += static_cast<difference_type>(__n - __bits_per_word + __ctz_ + 1) + / static_cast<difference_type>(__bits_per_word); + __n &= (__bits_per_word - 1); + __ctz_ = static_cast<unsigned>((__n + __ctz_) % __bits_per_word); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator-=(difference_type __n) + { + return *this += -__n; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator operator+(difference_type __n) const + { + __bit_iterator __t(*this); + __t += __n; + return __t; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator operator-(difference_type __n) const + { + __bit_iterator __t(*this); + __t -= __n; + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;} + + _LIBCPP_INLINE_VISIBILITY + friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y) + {return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;} + + _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);} + + _LIBCPP_INLINE_VISIBILITY friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y) + {return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;} + + _LIBCPP_INLINE_VISIBILITY friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__x == __y);} + + _LIBCPP_INLINE_VISIBILITY friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y) + {return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);} + + _LIBCPP_INLINE_VISIBILITY friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y) + {return __y < __x;} + + _LIBCPP_INLINE_VISIBILITY friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__y < __x);} + + _LIBCPP_INLINE_VISIBILITY friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__x < __y);} + +private: + _LIBCPP_INLINE_VISIBILITY + __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT + : __seg_(__s), __ctz_(__ctz) {} + + friend typename _Cp::__self; + + friend class __bit_reference<_Cp>; + friend class __bit_const_reference<_Cp>; + friend class __bit_iterator<_Cp, true>; + template <class _Dp> friend struct __bit_array; + template <class _Dp> friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); + template <class _Dp> friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); + template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first, + __bit_iterator<_Dp, _IC> __last, + __bit_iterator<_Dp, false> __result); + template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template <class __C1, class __C2>friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template <class _Dp> friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>, + __bit_iterator<_Dp, false>, + __bit_iterator<_Dp, false>); + template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC2>); + template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC2>); + template <class _Dp, bool _IC1, bool _IC2> friend bool equal(__bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC1>, + __bit_iterator<_Dp, _IC2>); + template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>, + typename _Dp::size_type); + template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>, + typename _Dp::size_type); + template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type + __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); + template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type + __count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); +}; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___BIT_REFERENCE diff --git a/android/x86/include/v8/libc++/__bsd_locale_defaults.h b/android/x86/include/v8/libc++/__bsd_locale_defaults.h new file mode 100755 index 00000000..2ace2a21 --- /dev/null +++ b/android/x86/include/v8/libc++/__bsd_locale_defaults.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===---------------------- __bsd_locale_defaults.h -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// The BSDs have lots of *_l functions. We don't want to define those symbols +// on other platforms though, for fear of conflicts with user code. So here, +// we will define the mapping from an internal macro to the real BSD symbol. +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_BSD_LOCALE_DEFAULTS_H +#define _LIBCPP_BSD_LOCALE_DEFAULTS_H + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc) +#define __libcpp_btowc_l(ch, loc) btowc_l(ch, loc) +#define __libcpp_wctob_l(wch, loc) wctob_l(wch, loc) +#define __libcpp_wcsnrtombs_l(dst, src, nwc, len, ps, loc) wcsnrtombs_l(dst, src, nwc, len, ps, loc) +#define __libcpp_wcrtomb_l(src, wc, ps, loc) wcrtomb_l(src, wc, ps, loc) +#define __libcpp_mbsnrtowcs_l(dst, src, nms, len, ps, loc) mbsnrtowcs_l(dst, src, nms, len, ps, loc) +#define __libcpp_mbrtowc_l(pwc, s, n, ps, l) mbrtowc_l(pwc, s, n, ps, l) +#define __libcpp_mbtowc_l(pwc, pmb, max, l) mbtowc_l(pwc, pmb, max, l) +#define __libcpp_mbrlen_l(s, n, ps, l) mbrlen_l(s, n, ps, l) +#define __libcpp_localeconv_l(l) localeconv_l(l) +#define __libcpp_mbsrtowcs_l(dest, src, len, ps, l) mbsrtowcs_l(dest, src, len, ps, l) +#define __libcpp_snprintf_l(...) snprintf_l(__VA_ARGS__) +#define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__) +#define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__) + +#endif // _LIBCPP_BSD_LOCALE_DEFAULTS_H diff --git a/android/x86/include/v8/libc++/__bsd_locale_fallbacks.h b/android/x86/include/v8/libc++/__bsd_locale_fallbacks.h new file mode 100755 index 00000000..a807fe03 --- /dev/null +++ b/android/x86/include/v8/libc++/__bsd_locale_fallbacks.h @@ -0,0 +1,139 @@ +// -*- C++ -*- +//===---------------------- __bsd_locale_fallbacks.h ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// The BSDs have lots of *_l functions. This file provides reimplementations +// of those functions for non-BSD platforms. +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H +#define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H + +#include <stdlib.h> +#include <stdarg.h> +#include <memory> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +inline _LIBCPP_INLINE_VISIBILITY +decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return MB_CUR_MAX; +} + +inline _LIBCPP_INLINE_VISIBILITY +wint_t __libcpp_btowc_l(int __c, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return btowc(__c); +} + +inline _LIBCPP_INLINE_VISIBILITY +int __libcpp_wctob_l(wint_t __c, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return wctob(__c); +} + +inline _LIBCPP_INLINE_VISIBILITY +size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc, + size_t __len, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return wcsnrtombs(__dest, __src, __nwc, __len, __ps); +} + +inline _LIBCPP_INLINE_VISIBILITY +size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return wcrtomb(__s, __wc, __ps); +} + +inline _LIBCPP_INLINE_VISIBILITY +size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms, + size_t __len, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbsnrtowcs(__dest, __src, __nms, __len, __ps); +} + +inline _LIBCPP_INLINE_VISIBILITY +size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n, + mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbrtowc(__pwc, __s, __n, __ps); +} + +inline _LIBCPP_INLINE_VISIBILITY +int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbtowc(__pwc, __pmb, __max); +} + +inline _LIBCPP_INLINE_VISIBILITY +size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbrlen(__s, __n, __ps); +} + +inline _LIBCPP_INLINE_VISIBILITY +lconv *__libcpp_localeconv_l(locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return localeconv(); +} + +inline _LIBCPP_INLINE_VISIBILITY +size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len, + mbstate_t *__ps, locale_t __l) +{ + __libcpp_locale_guard __current(__l); + return mbsrtowcs(__dest, __src, __len, __ps); +} + +inline +int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); + __libcpp_locale_guard __current(__l); + int __res = vsnprintf(__s, __n, __format, __va); + va_end(__va); + return __res; +} + +inline +int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); + __libcpp_locale_guard __current(__l); + int __res = vasprintf(__s, __format, __va); + va_end(__va); + return __res; +} + +inline +int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); + __libcpp_locale_guard __current(__l); + int __res = vsscanf(__s, __format, __va); + va_end(__va); + return __res; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H diff --git a/android/x86/include/v8/libc++/__config b/android/x86/include/v8/libc++/__config new file mode 100755 index 00000000..a7d0b141 --- /dev/null +++ b/android/x86/include/v8/libc++/__config @@ -0,0 +1,1463 @@ +// -*- C++ -*- +//===--------------------------- __config ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CONFIG +#define _LIBCPP_CONFIG + +#if defined(_MSC_VER) && !defined(__clang__) +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +# endif +#endif + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +#pragma GCC system_header +#endif + +#ifdef __cplusplus + +#ifdef __GNUC__ +# define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__) +// The _GNUC_VER_NEW macro better represents the new GCC versioning scheme +// introduced in GCC 5.0. +# define _GNUC_VER_NEW (_GNUC_VER * 10 + __GNUC_PATCHLEVEL__) +#else +# define _GNUC_VER 0 +# define _GNUC_VER_NEW 0 +#endif + +#define _LIBCPP_VERSION 9000 + +#ifndef _LIBCPP_ABI_VERSION +# define _LIBCPP_ABI_VERSION 1 +#endif + +#ifndef __STDC_HOSTED__ +# define _LIBCPP_FREESTANDING +#endif + +#ifndef _LIBCPP_STD_VER +# if __cplusplus <= 201103L +# define _LIBCPP_STD_VER 11 +# elif __cplusplus <= 201402L +# define _LIBCPP_STD_VER 14 +# elif __cplusplus <= 201703L +# define _LIBCPP_STD_VER 17 +# else +# define _LIBCPP_STD_VER 18 // current year, or date of c++2a ratification +# endif +#endif // _LIBCPP_STD_VER + +#if defined(__ELF__) +# define _LIBCPP_OBJECT_FORMAT_ELF 1 +#elif defined(__MACH__) +# define _LIBCPP_OBJECT_FORMAT_MACHO 1 +#elif defined(_WIN32) +# define _LIBCPP_OBJECT_FORMAT_COFF 1 +#elif defined(__wasm__) +# define _LIBCPP_OBJECT_FORMAT_WASM 1 +#else +# error Unknown object file format +#endif + +#if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2 +// Change short string representation so that string data starts at offset 0, +// improving its alignment in some cases. +# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT +// Fix deque iterator type in order to support incomplete types. +# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE +// Fix undefined behavior in how std::list stores its linked nodes. +# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB +// Fix undefined behavior in how __tree stores its end and parent nodes. +# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB +// Fix undefined behavior in how __hash_table stores its pointer types. +# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB +# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB +# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE +// Don't use a nullptr_t simulation type in C++03 instead using C++11 nullptr +// provided under the alternate keyword __nullptr, which changes the mangling +// of nullptr_t. This option is ABI incompatible with GCC in C++03 mode. +# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR +// Define the `pointer_safety` enum as a C++11 strongly typed enumeration +// instead of as a class simulating an enum. If this option is enabled +// `pointer_safety` and `get_pointer_safety()` will no longer be available +// in C++03. +# define _LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE +// Define a key function for `bad_function_call` in the library, to centralize +// its vtable and typeinfo to libc++ rather than having all other libraries +// using that class define their own copies. +# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +// Enable optimized version of __do_get_(un)signed which avoids redundant copies. +# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET +// Use the smallest possible integer type to represent the index of the variant. +// Previously libc++ used "unsigned int" exclusively. +# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION +// Unstable attempt to provide a more optimized std::function +# define _LIBCPP_ABI_OPTIMIZED_FUNCTION +// All the regex constants must be distinct and nonzero. +# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO +#elif _LIBCPP_ABI_VERSION == 1 +# if !defined(_LIBCPP_OBJECT_FORMAT_COFF) +// Enable compiling copies of now inline methods into the dylib to support +// applications compiled against older libraries. This is unnecessary with +// COFF dllexport semantics, since dllexport forces a non-inline definition +// of inline functions to be emitted anyway. Our own non-inline copy would +// conflict with the dllexport-emitted copy, so we disable it. +# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS +# endif +// Feature macros for disabling pre ABI v1 features. All of these options +// are deprecated. +# if defined(__FreeBSD__) +# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR +# endif +#endif + +#ifdef _LIBCPP_TRIVIAL_PAIR_COPY_CTOR +#error "_LIBCPP_TRIVIAL_PAIR_COPY_CTOR" is no longer supported. \ + use _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR instead +#endif + +#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y +#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) + +#ifndef _LIBCPP_ABI_NAMESPACE +# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION) +#endif + +#if __cplusplus < 201103L +#define _LIBCPP_CXX03_LANG +#endif + +#ifndef __has_attribute +#define __has_attribute(__x) 0 +#endif + +#ifndef __has_builtin +#define __has_builtin(__x) 0 +#endif + +#ifndef __has_extension +#define __has_extension(__x) 0 +#endif + +#ifndef __has_feature +#define __has_feature(__x) 0 +#endif + +#ifndef __has_cpp_attribute +#define __has_cpp_attribute(__x) 0 +#endif + +// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by +// the compiler and '1' otherwise. +#ifndef __is_identifier +#define __is_identifier(__x) 1 +#endif + +#ifndef __has_declspec_attribute +#define __has_declspec_attribute(__x) 0 +#endif + +#define __has_keyword(__x) !(__is_identifier(__x)) + +#ifndef __has_include +#define __has_include(...) 0 +#endif + +#if defined(__clang__) +# define _LIBCPP_COMPILER_CLANG +# ifndef __apple_build_version__ +# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) +# endif +#elif defined(__GNUC__) +# define _LIBCPP_COMPILER_GCC +#elif defined(_MSC_VER) +# define _LIBCPP_COMPILER_MSVC +#elif defined(__IBMCPP__) +# define _LIBCPP_COMPILER_IBM +#endif + +#ifndef _LIBCPP_CLANG_VER +#define _LIBCPP_CLANG_VER 0 +#endif + +// FIXME: ABI detection should be done via compiler builtin macros. This +// is just a placeholder until Clang implements such macros. For now assume +// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, +// and allow the user to explicitly specify the ABI to handle cases where this +// heuristic falls short. +#if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) +# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" +#elif defined(_LIBCPP_ABI_FORCE_ITANIUM) +# define _LIBCPP_ABI_ITANIUM +#elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) +# define _LIBCPP_ABI_MICROSOFT +#else +# if defined(_WIN32) && defined(_MSC_VER) +# define _LIBCPP_ABI_MICROSOFT +# else +# define _LIBCPP_ABI_ITANIUM +# endif +#endif + +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +# define _LIBCPP_ABI_VCRUNTIME +#endif + +// Need to detect which libc we're using if we're on Linux. +#if defined(__linux__) +# include <features.h> +# if defined(__GLIBC_PREREQ) +# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) +# else +# define _LIBCPP_GLIBC_PREREQ(a, b) 0 +# endif // defined(__GLIBC_PREREQ) +#endif // defined(__linux__) + +#ifdef __LITTLE_ENDIAN__ +# if __LITTLE_ENDIAN__ +# define _LIBCPP_LITTLE_ENDIAN +# endif // __LITTLE_ENDIAN__ +#endif // __LITTLE_ENDIAN__ + +#ifdef __BIG_ENDIAN__ +# if __BIG_ENDIAN__ +# define _LIBCPP_BIG_ENDIAN +# endif // __BIG_ENDIAN__ +#endif // __BIG_ENDIAN__ + +#ifdef __BYTE_ORDER__ +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define _LIBCPP_LITTLE_ENDIAN +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define _LIBCPP_BIG_ENDIAN +# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#endif // __BYTE_ORDER__ + +#ifdef __FreeBSD__ +# include <sys/endian.h> +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN +# else // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_BIG_ENDIAN +# endif // _BYTE_ORDER == _LITTLE_ENDIAN +# ifndef __LONG_LONG_SUPPORTED +# define _LIBCPP_HAS_NO_LONG_LONG +# endif // __LONG_LONG_SUPPORTED +#endif // __FreeBSD__ + +#ifdef __NetBSD__ +# include <sys/endian.h> +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN +# else // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_BIG_ENDIAN +# endif // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_HAS_QUICK_EXIT +#endif // __NetBSD__ + +#if defined(_WIN32) +# define _LIBCPP_WIN32API +# define _LIBCPP_LITTLE_ENDIAN +# define _LIBCPP_SHORT_WCHAR 1 +// Both MinGW and native MSVC provide a "MSVC"-like environment +# define _LIBCPP_MSVCRT_LIKE +// If mingw not explicitly detected, assume using MS C runtime only if +// a MS compatibility version is specified. +# if defined(_MSC_VER) && !defined(__MINGW32__) +# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library +# endif +# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) +# define _LIBCPP_HAS_BITSCAN64 +# endif +# define _LIBCPP_HAS_OPEN_WITH_WCHAR +# if defined(_LIBCPP_MSVCRT) +# define _LIBCPP_HAS_QUICK_EXIT +# endif + +// Some CRT APIs are unavailable to store apps +# if defined(WINAPI_FAMILY) +# include <winapifamily.h> +# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && \ + (!defined(WINAPI_PARTITION_SYSTEM) || \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM)) +# define _LIBCPP_WINDOWS_STORE_APP +# endif +# endif +#endif // defined(_WIN32) + +#ifdef __sun__ +# include <sys/isa_defs.h> +# ifdef _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN +# else +# define _LIBCPP_BIG_ENDIAN +# endif +#endif // __sun__ + +#if defined(__CloudABI__) + // Certain architectures provide arc4random(). Prefer using + // arc4random() over /dev/{u,}random to make it possible to obtain + // random data even when using sandboxing mechanisms such as chroots, + // Capsicum, etc. +# define _LIBCPP_USING_ARC4_RANDOM +#elif defined(__Fuchsia__) +# define _LIBCPP_USING_GETENTROPY +#elif defined(__native_client__) + // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, + // including accesses to the special files under /dev. C++11's + // std::random_device is instead exposed through a NaCl syscall. +# define _LIBCPP_USING_NACL_RANDOM +#elif defined(_LIBCPP_WIN32API) +# define _LIBCPP_USING_WIN32_RANDOM +#else +# define _LIBCPP_USING_DEV_RANDOM +#endif + +#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) +# include <endian.h> +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN +# elif __BYTE_ORDER == __BIG_ENDIAN +# define _LIBCPP_BIG_ENDIAN +# else // __BYTE_ORDER == __BIG_ENDIAN +# error unable to determine endian +# endif +#endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) + +#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) +# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) +#else +# define _LIBCPP_NO_CFI +#endif + +#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L +# if defined(__FreeBSD__) +# define _LIBCPP_HAS_QUICK_EXIT +# define _LIBCPP_HAS_C11_FEATURES +# elif defined(__Fuchsia__) +# define _LIBCPP_HAS_QUICK_EXIT +# define _LIBCPP_HAS_TIMESPEC_GET +# define _LIBCPP_HAS_C11_FEATURES +# elif defined(__linux__) +# if !defined(_LIBCPP_HAS_MUSL_LIBC) +# if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__) +# define _LIBCPP_HAS_QUICK_EXIT +# endif +# if _LIBCPP_GLIBC_PREREQ(2, 17) +# define _LIBCPP_HAS_C11_FEATURES +# define _LIBCPP_HAS_TIMESPEC_GET +# endif +# else // defined(_LIBCPP_HAS_MUSL_LIBC) +# define _LIBCPP_HAS_QUICK_EXIT +# define _LIBCPP_HAS_TIMESPEC_GET +# define _LIBCPP_HAS_C11_FEATURES +# endif +# endif // __linux__ +#endif + +#ifndef _LIBCPP_CXX03_LANG +# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) +#elif defined(_LIBCPP_COMPILER_CLANG) +# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) +#else +// This definition is potentially buggy, but it's only taken with GCC in C++03, +// which we barely support anyway. See llvm.org/PR39713 +# define _LIBCPP_ALIGNOF(_Tp) __alignof(_Tp) +#endif + +#define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) + +#if defined(_LIBCPP_COMPILER_CLANG) + +// _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for +// _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility. +#if (defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \ + (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)) || \ + defined(_LIBCPP_ALTERNATE_STRING_LAYOUT) +#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT +#endif + +#if __has_feature(cxx_alignas) +# define _ALIGNAS_TYPE(x) alignas(x) +# define _ALIGNAS(x) alignas(x) +#else +# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) +# define _ALIGNAS(x) __attribute__((__aligned__(x))) +#endif + +#if __cplusplus < 201103L +typedef __char16_t char16_t; +typedef __char32_t char32_t; +#endif + +#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS) +#define _LIBCPP_NO_EXCEPTIONS +#endif + +#if !(__has_feature(cxx_rtti)) && !defined(_LIBCPP_NO_RTTI) +#define _LIBCPP_NO_RTTI +#endif + +#if !(__has_feature(cxx_strong_enums)) +#define _LIBCPP_HAS_NO_STRONG_ENUMS +#endif + +#if !(__has_feature(cxx_decltype)) +#define _LIBCPP_HAS_NO_DECLTYPE +#endif + +#if __has_feature(cxx_attributes) +# define _LIBCPP_NORETURN [[noreturn]] +#else +# define _LIBCPP_NORETURN __attribute__ ((noreturn)) +#endif + +#if !(__has_feature(cxx_lambdas)) +#define _LIBCPP_HAS_NO_LAMBDAS +#endif + +#if !(__has_feature(cxx_nullptr)) +# if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR) +# define nullptr __nullptr +# else +# define _LIBCPP_HAS_NO_NULLPTR +# endif +#endif + +#if !(__has_feature(cxx_rvalue_references)) +#define _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif + +#if !(__has_feature(cxx_auto_type)) +#define _LIBCPP_HAS_NO_AUTO_TYPE +#endif + +#if !(__has_feature(cxx_variadic_templates)) +#define _LIBCPP_HAS_NO_VARIADICS +#endif + +#if !(__has_feature(cxx_generalized_initializers)) +#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif + +#if __has_feature(is_base_of) +#define _LIBCPP_HAS_IS_BASE_OF +#endif + +#if __has_feature(is_final) +#define _LIBCPP_HAS_IS_FINAL +#endif + +// Objective-C++ features (opt-in) +#if __has_feature(objc_arc) +#define _LIBCPP_HAS_OBJC_ARC +#endif + +#if __has_feature(objc_arc_weak) +#define _LIBCPP_HAS_OBJC_ARC_WEAK +#endif + +#if !(__has_feature(cxx_constexpr)) +#define _LIBCPP_HAS_NO_CONSTEXPR +#endif + +#if !(__has_feature(cxx_relaxed_constexpr)) +#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR +#endif + +#if !(__has_feature(cxx_variable_templates)) +#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES +#endif + +#if !(__has_feature(cxx_noexcept)) +#define _LIBCPP_HAS_NO_NOEXCEPT +#endif + +#if __has_feature(underlying_type) +#define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T) +#endif + +#if __has_feature(is_literal) +#define _LIBCPP_IS_LITERAL(T) __is_literal(T) +#endif + +#if !defined(_LIBCPP_HAS_NO_ASAN) && !__has_feature(address_sanitizer) +#define _LIBCPP_HAS_NO_ASAN +#endif + +// Allow for build-time disabling of unsigned integer sanitization +#if !defined(_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK) && __has_attribute(no_sanitize) +#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) +#endif + +#if __has_builtin(__builtin_launder) +#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER +#endif + +#if !__is_identifier(__has_unique_object_representations) +#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS +#endif + +#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) + +// No apple compilers support ""d and ""y at this time. +#if _LIBCPP_CLANG_VER < 800 || defined(__apple_build_version__) +#define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS +#endif + +#elif defined(_LIBCPP_COMPILER_GCC) + +#define _ALIGNAS(x) __attribute__((__aligned__(x))) +#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) + +#define _LIBCPP_NORETURN __attribute__((noreturn)) + +#if _GNUC_VER >= 407 +#define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T) +#define _LIBCPP_IS_LITERAL(T) __is_literal_type(T) +#define _LIBCPP_HAS_IS_FINAL +#endif + +#if defined(__GNUC__) && _GNUC_VER >= 403 +#define _LIBCPP_HAS_IS_BASE_OF +#endif + +#if !__EXCEPTIONS && !defined(_LIBCPP_NO_EXCEPTIONS) +#define _LIBCPP_NO_EXCEPTIONS +#endif + +// constexpr was added to GCC in 4.6. +#if _GNUC_VER < 406 +# define _LIBCPP_HAS_NO_CONSTEXPR +// Can only use constexpr in c++11 mode. +#elif !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L +# define _LIBCPP_HAS_NO_CONSTEXPR +#endif + +// Determine if GCC supports relaxed constexpr +#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L +#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR +#endif + +// GCC 5 will support variable templates +#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L +#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES +#endif + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ + +#define _LIBCPP_HAS_NO_DECLTYPE +#define _LIBCPP_HAS_NO_NULLPTR +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#define _LIBCPP_HAS_NO_VARIADICS +#define _LIBCPP_HAS_NO_RVALUE_REFERENCES +#define _LIBCPP_HAS_NO_STRONG_ENUMS +#define _LIBCPP_HAS_NO_NOEXCEPT + +#else // __GXX_EXPERIMENTAL_CXX0X__ + +#if _GNUC_VER < 403 +#define _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif + + +#if _GNUC_VER < 404 +#define _LIBCPP_HAS_NO_DECLTYPE +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#define _LIBCPP_HAS_NO_VARIADICS +#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _GNUC_VER < 404 + +#if _GNUC_VER < 406 +#define _LIBCPP_HAS_NO_NOEXCEPT +#define _LIBCPP_HAS_NO_NULLPTR +#endif + +#endif // __GXX_EXPERIMENTAL_CXX0X__ + +#if !defined(_LIBCPP_HAS_NO_ASAN) && !defined(__SANITIZE_ADDRESS__) +#define _LIBCPP_HAS_NO_ASAN +#endif + +#if _GNUC_VER >= 700 +#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER +#endif + +#if _GNUC_VER >= 700 +#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS +#endif + +#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) + +#elif defined(_LIBCPP_COMPILER_MSVC) + +#define _LIBCPP_TOSTRING2(x) #x +#define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) +#define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x)) + +#if _MSC_VER < 1900 +#error "MSVC versions prior to Visual Studio 2015 are not supported" +#endif + +#define _LIBCPP_HAS_IS_BASE_OF +#define _LIBCPP_HAS_NO_CONSTEXPR +#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR +#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES +#define _LIBCPP_HAS_NO_NOEXCEPT +#define __alignof__ __alignof +#define _LIBCPP_NORETURN __declspec(noreturn) +#define _ALIGNAS(x) __declspec(align(x)) +#define _ALIGNAS_TYPE(x) alignas(x) +#define _LIBCPP_HAS_NO_VARIADICS + +#define _LIBCPP_WEAK + +#define _LIBCPP_HAS_NO_ASAN + +#define _LIBCPP_ALWAYS_INLINE __forceinline + +#define _LIBCPP_HAS_NO_VECTOR_EXTENSION + +#elif defined(_LIBCPP_COMPILER_IBM) + +#define _ALIGNAS(x) __attribute__((__aligned__(x))) +#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) +#define _ATTRIBUTE(x) __attribute__((x)) +#define _LIBCPP_NORETURN __attribute__((noreturn)) + +#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#define _LIBCPP_HAS_NO_NOEXCEPT +#define _LIBCPP_HAS_NO_NULLPTR +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#define _LIBCPP_HAS_IS_BASE_OF +#define _LIBCPP_HAS_IS_FINAL +#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES + +#if defined(_AIX) +#define __MULTILOCALE_API +#endif + +#define _LIBCPP_HAS_NO_ASAN + +#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) + +#define _LIBCPP_HAS_NO_VECTOR_EXTENSION + +#endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM] + +#if defined(_LIBCPP_OBJECT_FORMAT_COFF) + +#ifdef _DLL +# define _LIBCPP_CRT_FUNC __declspec(dllimport) +#else +# define _LIBCPP_CRT_FUNC +#endif + +#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCPP_DLL_VIS +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS +# define _LIBCPP_OVERRIDABLE_FUNC_VIS +# define _LIBCPP_EXPORTED_FROM_ABI +#elif defined(_LIBCPP_BUILDING_LIBRARY) +# define _LIBCPP_DLL_VIS __declspec(dllexport) +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS +# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS +# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) +#else +# define _LIBCPP_DLL_VIS __declspec(dllimport) +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS +# define _LIBCPP_OVERRIDABLE_FUNC_VIS +# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) +#endif + +#define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS +#define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS +#define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS +#define _LIBCPP_HIDDEN +#define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS +#define _LIBCPP_TEMPLATE_VIS +#define _LIBCPP_ENUM_VIS + +#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) + +#ifndef _LIBCPP_HIDDEN +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden"))) +# else +# define _LIBCPP_HIDDEN +# endif +#endif + +#ifndef _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +// The inline should be removed once PR32114 is resolved +# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN +# else +# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS +# endif +#endif + +#ifndef _LIBCPP_FUNC_VIS +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default"))) +# else +# define _LIBCPP_FUNC_VIS +# endif +#endif + +#ifndef _LIBCPP_TYPE_VIS +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default"))) +# else +# define _LIBCPP_TYPE_VIS +# endif +#endif + +#ifndef _LIBCPP_TEMPLATE_VIS +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +# if __has_attribute(__type_visibility__) +# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__type_visibility__("default"))) +# else +# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__visibility__("default"))) +# endif +# else +# define _LIBCPP_TEMPLATE_VIS +# endif +#endif + +#ifndef _LIBCPP_EXPORTED_FROM_ABI +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCPP_EXPORTED_FROM_ABI __attribute__((__visibility__("default"))) +# else +# define _LIBCPP_EXPORTED_FROM_ABI +# endif +#endif + +#ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS +#define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_FUNC_VIS +#endif + +#ifndef _LIBCPP_EXCEPTION_ABI +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +# define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default"))) +# else +# define _LIBCPP_EXCEPTION_ABI +# endif +#endif + +#ifndef _LIBCPP_ENUM_VIS +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) +# define _LIBCPP_ENUM_VIS __attribute__ ((__type_visibility__("default"))) +# else +# define _LIBCPP_ENUM_VIS +# endif +#endif + +#ifndef _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS +# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default"))) +# else +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS +# endif +#endif + +#ifndef _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS +#define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS +#endif + +#if __has_attribute(internal_linkage) +# define _LIBCPP_INTERNAL_LINKAGE __attribute__ ((internal_linkage)) +#else +# define _LIBCPP_INTERNAL_LINKAGE _LIBCPP_ALWAYS_INLINE +#endif + +#if __has_attribute(exclude_from_explicit_instantiation) +# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__ ((__exclude_from_explicit_instantiation__)) +#else + // Try to approximate the effect of exclude_from_explicit_instantiation + // (which is that entities are not assumed to be provided by explicit + // template instantiations in the dylib) by always inlining those entities. +# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE +#endif + +#ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU +# ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT +# define _LIBCPP_HIDE_FROM_ABI_PER_TU 0 +# else +# define _LIBCPP_HIDE_FROM_ABI_PER_TU 1 +# endif +#endif + +#ifndef _LIBCPP_HIDE_FROM_ABI +# if _LIBCPP_HIDE_FROM_ABI_PER_TU +# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE +# else +# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION +# endif +#endif + +#ifdef _LIBCPP_BUILDING_LIBRARY +# if _LIBCPP_ABI_VERSION > 1 +# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI +# else +# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 +# endif +#else +# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI +#endif + +// Just so we can migrate to the new macros gradually. +#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI + +// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. +#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { +#define _LIBCPP_END_NAMESPACE_STD } } +#define _VSTD std::_LIBCPP_ABI_NAMESPACE +_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 17 +#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ + _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem { +#else +#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ + _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem { +#endif + +#define _LIBCPP_END_NAMESPACE_FILESYSTEM \ + _LIBCPP_END_NAMESPACE_STD } } + +#define _VSTD_FS _VSTD::__fs::filesystem + +#ifndef _LIBCPP_PREFERRED_OVERLOAD +# if __has_attribute(__enable_if__) +# define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, ""))) +# endif +#endif + +#ifndef _LIBCPP_HAS_NO_NOEXCEPT +# define _NOEXCEPT noexcept +# define _NOEXCEPT_(x) noexcept(x) +#else +# define _NOEXCEPT throw() +# define _NOEXCEPT_(x) +#endif + +#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS +typedef unsigned short char16_t; +typedef unsigned int char32_t; +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +#ifndef __SIZEOF_INT128__ +#define _LIBCPP_HAS_NO_INT128 +#endif + +#ifdef _LIBCPP_CXX03_LANG +# if __has_extension(c_static_assert) +# define static_assert(__b, __m) _Static_assert(__b, __m) +# else +extern "C++" { +template <bool> struct __static_assert_test; +template <> struct __static_assert_test<true> {}; +template <unsigned> struct __static_assert_check {}; +} +# define static_assert(__b, __m) \ + typedef __static_assert_check<sizeof(__static_assert_test<(__b)>)> \ + _LIBCPP_CONCAT(__t, __LINE__) +# endif // __has_extension(c_static_assert) +#endif // _LIBCPP_CXX03_LANG + +#ifdef _LIBCPP_HAS_NO_DECLTYPE +// GCC 4.6 provides __decltype in all standard modes. +# if __has_keyword(__decltype) || _LIBCPP_CLANG_VER >= 304 || _GNUC_VER >= 406 +# define decltype(__x) __decltype(__x) +# else +# define decltype(__x) __typeof__(__x) +# endif +#endif + +#ifdef _LIBCPP_HAS_NO_CONSTEXPR +# define _LIBCPP_CONSTEXPR +#else +# define _LIBCPP_CONSTEXPR constexpr +#endif + +#ifdef _LIBCPP_CXX03_LANG +# define _LIBCPP_DEFAULT {} +#else +# define _LIBCPP_DEFAULT = default; +#endif + +#ifdef _LIBCPP_CXX03_LANG +# define _LIBCPP_EQUAL_DELETE +#else +# define _LIBCPP_EQUAL_DELETE = delete +#endif + +#ifdef __GNUC__ +# define _LIBCPP_NOALIAS __attribute__((__malloc__)) +#else +# define _LIBCPP_NOALIAS +#endif + +#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__) || \ + (!defined(_LIBCPP_CXX03_LANG) && defined(__GNUC__)) // All supported GCC versions +# define _LIBCPP_EXPLICIT explicit +#else +# define _LIBCPP_EXPLICIT +#endif + +#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete) +#define _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE +#endif + +#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS +# define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx +# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ + __lx __v_; \ + _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \ + _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ + _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} \ + }; +#else // _LIBCPP_HAS_NO_STRONG_ENUMS +# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x +# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) +#endif // _LIBCPP_HAS_NO_STRONG_ENUMS + +#ifdef _LIBCPP_DEBUG +# if _LIBCPP_DEBUG == 0 +# define _LIBCPP_DEBUG_LEVEL 1 +# elif _LIBCPP_DEBUG == 1 +# define _LIBCPP_DEBUG_LEVEL 2 +# else +# error Supported values for _LIBCPP_DEBUG are 0 and 1 +# endif +# if !defined(_LIBCPP_BUILDING_LIBRARY) +# define _LIBCPP_EXTERN_TEMPLATE(...) +# endif +#endif + +#ifdef _LIBCPP_DISABLE_EXTERN_TEMPLATE +#define _LIBCPP_EXTERN_TEMPLATE(...) +#define _LIBCPP_EXTERN_TEMPLATE2(...) +#endif + +#ifndef _LIBCPP_EXTERN_TEMPLATE +#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__; +#endif + +#ifndef _LIBCPP_EXTERN_TEMPLATE2 +#define _LIBCPP_EXTERN_TEMPLATE2(...) extern template __VA_ARGS__; +#endif + +#if defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__) +#define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63) +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \ + defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__) +#define _LIBCPP_LOCALE__L_EXTENSIONS 1 +#endif + +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +// Most unix variants have catopen. These are the specific ones that don't. +# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) +# define _LIBCPP_HAS_CATOPEN 1 +# endif +#endif + +#ifdef __FreeBSD__ +#define _DECLARE_C99_LDBL_MATH 1 +#endif + +// If we are getting operator new from the MSVC CRT, then allocation overloads +// for align_val_t were added in 19.12, aka VS 2017 version 15.3. +#if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 +# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +#elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) + // We're deferring to Microsoft's STL to provide aligned new et al. We don't + // have it unless the language feature test macro is defined. +# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +#endif + +#if defined(__APPLE__) +# if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \ + defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) +# define __MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ +# endif +#endif // defined(__APPLE__) + +#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \ + (defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \ + (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)) +# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) +#define _LIBCPP_HAS_DEFAULTRUNELOCALE +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) +#define _LIBCPP_WCTYPE_IS_MASK +#endif + +#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) +#define _LIBCPP_NO_HAS_CHAR8_T +#endif + +// Deprecation macros. +// +// Deprecations warnings are always enabled, except when users explicitly opt-out +// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. +#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) +# if __has_attribute(deprecated) +# define _LIBCPP_DEPRECATED __attribute__ ((deprecated)) +# elif _LIBCPP_STD_VER > 11 +# define _LIBCPP_DEPRECATED [[deprecated]] +# else +# define _LIBCPP_DEPRECATED +# endif +#else +# define _LIBCPP_DEPRECATED +#endif + +#if !defined(_LIBCPP_CXX03_LANG) +# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED +#else +# define _LIBCPP_DEPRECATED_IN_CXX11 +#endif + +#if _LIBCPP_STD_VER >= 14 +# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED +#else +# define _LIBCPP_DEPRECATED_IN_CXX14 +#endif + +#if _LIBCPP_STD_VER >= 17 +# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED +#else +# define _LIBCPP_DEPRECATED_IN_CXX17 +#endif + +#if _LIBCPP_STD_VER <= 11 +# define _LIBCPP_EXPLICIT_AFTER_CXX11 +#else +# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit +#endif + +#if _LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) +# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr +#else +# define _LIBCPP_CONSTEXPR_AFTER_CXX11 +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) +# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr +#else +# define _LIBCPP_CONSTEXPR_AFTER_CXX14 +#endif + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) +# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr +#else +# define _LIBCPP_CONSTEXPR_AFTER_CXX17 +#endif + +// The _LIBCPP_NODISCARD_ATTRIBUTE should only be used to define other +// NODISCARD macros to the correct attribute. +#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC) +# define _LIBCPP_NODISCARD_ATTRIBUTE [[nodiscard]] +#elif defined(_LIBCPP_COMPILER_CLANG) && !defined(_LIBCPP_CXX03_LANG) +# define _LIBCPP_NODISCARD_ATTRIBUTE [[clang::warn_unused_result]] +#else +// We can't use GCC's [[gnu::warn_unused_result]] and +// __attribute__((warn_unused_result)), because GCC does not silence them via +// (void) cast. +# define _LIBCPP_NODISCARD_ATTRIBUTE +#endif + +// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not +// specified as such as an extension. +#if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT) +# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD_ATTRIBUTE +#else +# define _LIBCPP_NODISCARD_EXT +#endif + +#if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \ + (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD)) +# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD_ATTRIBUTE +#else +# define _LIBCPP_NODISCARD_AFTER_CXX17 +#endif + +#if _LIBCPP_STD_VER > 14 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L) +# define _LIBCPP_INLINE_VAR inline +#else +# define _LIBCPP_INLINE_VAR +#endif + +#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES +# define _LIBCPP_EXPLICIT_MOVE(x) _VSTD::move(x) +#else +# define _LIBCPP_EXPLICIT_MOVE(x) (x) +#endif + +#ifndef _LIBCPP_CONSTEXPR_IF_NODEBUG +#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) +#define _LIBCPP_CONSTEXPR_IF_NODEBUG +#else +#define _LIBCPP_CONSTEXPR_IF_NODEBUG constexpr +#endif +#endif + +#ifndef _LIBCPP_HAS_NO_ASAN +_LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( + const void *, const void *, const void *, const void *); +#endif + +// Try to find out if RTTI is disabled. +// g++ and cl.exe have RTTI on by default and define a macro when it is. +// g++ only defines the macro in 4.3.2 and onwards. +#if !defined(_LIBCPP_NO_RTTI) +# if defined(__GNUC__) && \ + ((__GNUC__ >= 5) || \ + (__GNUC__ == 4 && (__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2))) && \ + !defined(__GXX_RTTI) +# define _LIBCPP_NO_RTTI +# elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI) +# define _LIBCPP_NO_RTTI +# endif +#endif + +#ifndef _LIBCPP_WEAK +#define _LIBCPP_WEAK __attribute__((__weak__)) +#endif + +// Thread API +#if !defined(_LIBCPP_HAS_NO_THREADS) && \ + !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ + !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ + !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) +# if defined(__FreeBSD__) || \ + defined(__Fuchsia__) || \ + defined(__NetBSD__) || \ + defined(__linux__) || \ + defined(__GNU__) || \ + defined(__APPLE__) || \ + defined(__CloudABI__) || \ + defined(__sun__) || \ + (defined(__MINGW32__) && __has_include(<pthread.h>)) +# define _LIBCPP_HAS_THREAD_API_PTHREAD +# elif defined(_LIBCPP_WIN32API) +# define _LIBCPP_HAS_THREAD_API_WIN32 +# else +# error "No thread API" +# endif // _LIBCPP_HAS_THREAD_API +#endif // _LIBCPP_HAS_NO_THREADS + +#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) +#error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ + _LIBCPP_HAS_NO_THREADS is not defined. +#endif + +#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) +#error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ + _LIBCPP_HAS_NO_THREADS is defined. +#endif + +#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) +#error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ + _LIBCPP_HAS_NO_THREADS is defined. +#endif + +// Systems that use capability-based security (FreeBSD with Capsicum, +// Nuxi CloudABI) may only provide local filesystem access (using *at()). +// Functions like open(), rename(), unlink() and stat() should not be +// used, as they attempt to access the global filesystem namespace. +#ifdef __CloudABI__ +#define _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +#endif + +// CloudABI is intended for running networked services. Processes do not +// have standard input and output channels. +#ifdef __CloudABI__ +#define _LIBCPP_HAS_NO_STDIN +#define _LIBCPP_HAS_NO_STDOUT +#endif + +#if defined(__BIONIC__) || defined(__CloudABI__) || \ + defined(__Fuchsia__) || defined(_LIBCPP_HAS_MUSL_LIBC) +#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE +#endif + +// Thread-unsafe functions such as strtok() and localtime() +// are not available. +#ifdef __CloudABI__ +#define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +#endif + +#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) +# define _LIBCPP_HAS_C_ATOMIC_IMP +#elif _GNUC_VER > 407 +# define _LIBCPP_HAS_GCC_ATOMIC_IMP +#endif + +#if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \ + !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ + !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)) \ + || defined(_LIBCPP_HAS_NO_THREADS) +# define _LIBCPP_HAS_NO_ATOMIC_HEADER +#else +# ifndef _LIBCPP_ATOMIC_FLAG_TYPE +# define _LIBCPP_ATOMIC_FLAG_TYPE bool +# endif +# ifdef _LIBCPP_FREESTANDING +# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS +# endif +#endif + +#ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +#endif + +#if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) +# if defined(__clang__) && __has_attribute(acquire_capability) +// Work around the attribute handling in clang. When both __declspec and +// __attribute__ are present, the processing goes awry preventing the definition +// of the types. +# if !defined(_LIBCPP_OBJECT_FORMAT_COFF) +# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS +# endif +# endif +#endif + +#if __has_attribute(require_constant_initialization) +# define _LIBCPP_SAFE_STATIC __attribute__((__require_constant_initialization__)) +#else +# define _LIBCPP_SAFE_STATIC +#endif + +#if !__has_builtin(__builtin_addressof) && _GNUC_VER < 700 +#define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF +#endif + +#if !defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) +# if defined(_LIBCPP_MSVCRT) || defined(_NEWLIB_VERSION) +# define _LIBCPP_HAS_NO_OFF_T_FUNCTIONS +# endif +#endif + +#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) +# define _LIBCPP_DIAGNOSE_WARNING(...) \ + __attribute__((diagnose_if(__VA_ARGS__, "warning"))) +# define _LIBCPP_DIAGNOSE_ERROR(...) \ + __attribute__((diagnose_if(__VA_ARGS__, "error"))) +#else +# define _LIBCPP_DIAGNOSE_WARNING(...) +# define _LIBCPP_DIAGNOSE_ERROR(...) +#endif + +// Use a function like macro to imply that it must be followed by a semicolon +#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough) +# define _LIBCPP_FALLTHROUGH() [[fallthrough]] +#elif __has_cpp_attribute(clang::fallthrough) +# define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]] +#elif __has_attribute(fallthough) || _GNUC_VER >= 700 +# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) +#else +# define _LIBCPP_FALLTHROUGH() ((void)0) +#endif + +#if defined(_LIBCPP_ABI_MICROSOFT) && \ + (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases)) +# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) +#else +# define _LIBCPP_DECLSPEC_EMPTY_BASES +#endif + +#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) +#define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR +#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS +#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE +#define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS +#endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES + +#if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611 +#define _LIBCPP_HAS_NO_DEDUCTION_GUIDES +#endif + +#if !__has_keyword(__is_aggregate) && (_GNUC_VER_NEW < 7001) +#define _LIBCPP_HAS_NO_IS_AGGREGATE +#endif + +#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L +#define _LIBCPP_HAS_NO_COROUTINES +#endif + +// FIXME: Correct this macro when either (A) a feature test macro for the +// spaceship operator is provided, or (B) a compiler provides a complete +// implementation. +#define _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + +// Decide whether to use availability macros. +#if !defined(_LIBCPP_BUILDING_LIBRARY) && \ + !defined(_LIBCPP_DISABLE_AVAILABILITY) && \ + __has_feature(attribute_availability_with_strict) && \ + __has_feature(attribute_availability_in_templates) && \ + __has_extension(pragma_clang_attribute_external_declaration) +# ifdef __APPLE__ +# define _LIBCPP_USE_AVAILABILITY_APPLE +# endif +#endif + +// Define availability macros. +#if defined(_LIBCPP_USE_AVAILABILITY_APPLE) +# define _LIBCPP_AVAILABILITY_SHARED_MUTEX \ + __attribute__((availability(macosx,strict,introduced=10.12))) \ + __attribute__((availability(ios,strict,introduced=10.0))) \ + __attribute__((availability(tvos,strict,introduced=10.0))) \ + __attribute__((availability(watchos,strict,introduced=3.0))) +# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS \ + __attribute__((availability(macosx,strict,introduced=10.14))) \ + __attribute__((availability(ios,strict,introduced=12.0))) \ + __attribute__((availability(tvos,strict,introduced=12.0))) \ + __attribute__((availability(watchos,strict,introduced=5.0))) +# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS \ + _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST \ + _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS \ + __attribute__((availability(macosx,strict,introduced=10.12))) \ + __attribute__((availability(ios,strict,introduced=10.0))) \ + __attribute__((availability(tvos,strict,introduced=10.0))) \ + __attribute__((availability(watchos,strict,introduced=3.0))) +# define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE \ + __attribute__((availability(macosx,strict,introduced=10.12))) \ + __attribute__((availability(ios,strict,introduced=10.0))) \ + __attribute__((availability(tvos,strict,introduced=10.0))) \ + __attribute__((availability(watchos,strict,introduced=3.0))) +# define _LIBCPP_AVAILABILITY_FUTURE_ERROR \ + __attribute__((availability(ios,strict,introduced=6.0))) +# define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE \ + __attribute__((availability(macosx,strict,introduced=10.9))) \ + __attribute__((availability(ios,strict,introduced=7.0))) +# define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY \ + __attribute__((availability(macosx,strict,introduced=10.9))) \ + __attribute__((availability(ios,strict,introduced=7.0))) +# define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR \ + __attribute__((availability(macosx,strict,introduced=10.9))) \ + __attribute__((availability(ios,strict,introduced=7.0))) +# define _LIBCPP_AVAILABILITY_FILESYSTEM \ + __attribute__((availability(macosx,strict,unavailable))) \ + __attribute__((availability(ios,strict,unavailable))) \ + __attribute__((availability(tvos,strict,unavailable))) \ + __attribute__((availability(watchos,strict,unavailable))) +# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH \ + _Pragma("clang attribute push(__attribute__((availability(macosx,strict,unavailable))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(ios,strict,unavailable))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(tvos,strict,unavailable))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(watchos,strict,unavailable))), apply_to=any(function,record))") +# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") +#else +# define _LIBCPP_AVAILABILITY_SHARED_MUTEX +# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS +# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST +# define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS +# define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE +# define _LIBCPP_AVAILABILITY_FUTURE_ERROR +# define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE +# define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY +# define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +# define _LIBCPP_AVAILABILITY_FILESYSTEM +# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH +# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP +#endif + +// Define availability that depends on _LIBCPP_NO_EXCEPTIONS. +#ifdef _LIBCPP_NO_EXCEPTIONS +# define _LIBCPP_AVAILABILITY_FUTURE +# define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST +# define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS +# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +#else +# define _LIBCPP_AVAILABILITY_FUTURE _LIBCPP_AVAILABILITY_FUTURE_ERROR +# define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_ANY_CAST +# define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS +# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS +#endif + +// The stream API was dropped and re-added in the dylib shipped on macOS +// and iOS. We can only assume the dylib to provide these definitions for +// macosx >= 10.9 and ios >= 7.0. Otherwise, the definitions are available +// from the headers, but not from the dylib. Explicit instantiation +// declarations for streams exist conditionally to this; if we provide +// an explicit instantiation declaration and we try to deploy to a dylib +// that does not provide those symbols, we'll get a load-time error. +#if !defined(_LIBCPP_BUILDING_LIBRARY) && \ + ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1090) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 70000)) +# define _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB +#endif + +#if defined(_LIBCPP_COMPILER_IBM) +#define _LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO +#endif + +#if defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO) +# define _LIBCPP_PUSH_MACROS +# define _LIBCPP_POP_MACROS +#else + // Don't warn about macro conflicts when we can restore them at the + // end of the header. +# ifndef _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS +# define _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS +# endif +# if defined(_LIBCPP_COMPILER_MSVC) +# define _LIBCPP_PUSH_MACROS \ + __pragma(push_macro("min")) \ + __pragma(push_macro("max")) +# define _LIBCPP_POP_MACROS \ + __pragma(pop_macro("min")) \ + __pragma(pop_macro("max")) +# else +# define _LIBCPP_PUSH_MACROS \ + _Pragma("push_macro(\"min\")") \ + _Pragma("push_macro(\"max\")") +# define _LIBCPP_POP_MACROS \ + _Pragma("pop_macro(\"min\")") \ + _Pragma("pop_macro(\"max\")") +# endif +#endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO) + +#ifndef _LIBCPP_NO_AUTO_LINK +# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) +# if defined(_DLL) +# pragma comment(lib, "c++.lib") +# else +# pragma comment(lib, "libc++.lib") +# endif +# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) +#endif // _LIBCPP_NO_AUTO_LINK + +#define _LIBCPP_UNUSED_VAR(x) ((void)(x)) + +#endif // __cplusplus + +#endif // _LIBCPP_CONFIG diff --git a/android/x86/include/v8/libc++/__config_site.in b/android/x86/include/v8/libc++/__config_site.in new file mode 100755 index 00000000..0818d6e1 --- /dev/null +++ b/android/x86/include/v8/libc++/__config_site.in @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CONFIG_SITE +#define _LIBCPP_CONFIG_SITE + +#cmakedefine _LIBCPP_ABI_VERSION @_LIBCPP_ABI_VERSION@ +#cmakedefine _LIBCPP_ABI_UNSTABLE +#cmakedefine _LIBCPP_ABI_FORCE_ITANIUM +#cmakedefine _LIBCPP_ABI_FORCE_MICROSOFT +#cmakedefine _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT +#cmakedefine _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +#cmakedefine _LIBCPP_HAS_NO_STDIN +#cmakedefine _LIBCPP_HAS_NO_STDOUT +#cmakedefine _LIBCPP_HAS_NO_THREADS +#cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK +#cmakedefine _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +#cmakedefine _LIBCPP_HAS_MUSL_LIBC +#cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD +#cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL +#cmakedefine _LIBCPP_HAS_THREAD_API_WIN32 +#cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL +#cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#cmakedefine _LIBCPP_NO_VCRUNTIME +#cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@ + +@_LIBCPP_ABI_DEFINES@ + +#endif // _LIBCPP_CONFIG_SITE diff --git a/android/x86/include/v8/libc++/__debug b/android/x86/include/v8/libc++/__debug new file mode 100755 index 00000000..524c5ff0 --- /dev/null +++ b/android/x86/include/v8/libc++/__debug @@ -0,0 +1,279 @@ +// -*- C++ -*- +//===--------------------------- __debug ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_DEBUG_H +#define _LIBCPP_DEBUG_H + +#include <__config> +#include <iosfwd> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if defined(_LIBCPP_HAS_NO_NULLPTR) +# include <cstddef> +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY) +# include <cstdlib> +# include <cstdio> +# include <cstddef> +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_ASSERT) +# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : \ + _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 2 +#ifndef _LIBCPP_DEBUG_ASSERT +#define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m) +#endif +#define _LIBCPP_DEBUG_MODE(...) __VA_ARGS__ +#endif + +#ifndef _LIBCPP_ASSERT +# define _LIBCPP_ASSERT(x, m) ((void)0) +#endif +#ifndef _LIBCPP_DEBUG_ASSERT +# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) +#endif +#ifndef _LIBCPP_DEBUG_MODE +#define _LIBCPP_DEBUG_MODE(...) ((void)0) +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __libcpp_debug_info() + : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m) + : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {} + + _LIBCPP_FUNC_VIS std::string what() const; + + const char* __file_; + int __line_; + const char* __pred_; + const char* __msg_; +}; + +/// __libcpp_debug_function_type - The type of the assertion failure handler. +typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&); + +/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT +/// fails. +extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function; + +/// __libcpp_abort_debug_function - A debug handler that aborts when called. +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS +void __libcpp_abort_debug_function(__libcpp_debug_info const&); + +/// __libcpp_set_debug_function - Set the debug handler to the specified +/// function. +_LIBCPP_FUNC_VIS +bool __libcpp_set_debug_function(__libcpp_debug_function_type __func); + +#if _LIBCPP_DEBUG_LEVEL >= 2 || defined(_LIBCPP_BUILDING_LIBRARY) + +struct _LIBCPP_TYPE_VIS __c_node; + +struct _LIBCPP_TYPE_VIS __i_node +{ + void* __i_; + __i_node* __next_; + __c_node* __c_; + +#ifndef _LIBCPP_CXX03_LANG + __i_node(const __i_node&) = delete; + __i_node& operator=(const __i_node&) = delete; +#else +private: + __i_node(const __i_node&); + __i_node& operator=(const __i_node&); +public: +#endif + _LIBCPP_INLINE_VISIBILITY + __i_node(void* __i, __i_node* __next, __c_node* __c) + : __i_(__i), __next_(__next), __c_(__c) {} + ~__i_node(); +}; + +struct _LIBCPP_TYPE_VIS __c_node +{ + void* __c_; + __c_node* __next_; + __i_node** beg_; + __i_node** end_; + __i_node** cap_; + +#ifndef _LIBCPP_CXX03_LANG + __c_node(const __c_node&) = delete; + __c_node& operator=(const __c_node&) = delete; +#else +private: + __c_node(const __c_node&); + __c_node& operator=(const __c_node&); +public: +#endif + _LIBCPP_INLINE_VISIBILITY + __c_node(void* __c, __c_node* __next) + : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} + virtual ~__c_node(); + + virtual bool __dereferenceable(const void*) const = 0; + virtual bool __decrementable(const void*) const = 0; + virtual bool __addable(const void*, ptrdiff_t) const = 0; + virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; + + void __add(__i_node* __i); + _LIBCPP_HIDDEN void __remove(__i_node* __i); +}; + +template <class _Cont> +struct _C_node + : public __c_node +{ + _C_node(void* __c, __c_node* __n) + : __c_node(__c, __n) {} + + virtual bool __dereferenceable(const void*) const; + virtual bool __decrementable(const void*) const; + virtual bool __addable(const void*, ptrdiff_t) const; + virtual bool __subscriptable(const void*, ptrdiff_t) const; +}; + +template <class _Cont> +inline bool +_C_node<_Cont>::__dereferenceable(const void* __i) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast<const iterator*>(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__dereferenceable(__j); +} + +template <class _Cont> +inline bool +_C_node<_Cont>::__decrementable(const void* __i) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast<const iterator*>(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__decrementable(__j); +} + +template <class _Cont> +inline bool +_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast<const iterator*>(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__addable(__j, __n); +} + +template <class _Cont> +inline bool +_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast<const iterator*>(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__subscriptable(__j, __n); +} + +class _LIBCPP_TYPE_VIS __libcpp_db +{ + __c_node** __cbeg_; + __c_node** __cend_; + size_t __csz_; + __i_node** __ibeg_; + __i_node** __iend_; + size_t __isz_; + + __libcpp_db(); +public: +#ifndef _LIBCPP_CXX03_LANG + __libcpp_db(const __libcpp_db&) = delete; + __libcpp_db& operator=(const __libcpp_db&) = delete; +#else +private: + __libcpp_db(const __libcpp_db&); + __libcpp_db& operator=(const __libcpp_db&); +public: +#endif + ~__libcpp_db(); + + class __db_c_iterator; + class __db_c_const_iterator; + class __db_i_iterator; + class __db_i_const_iterator; + + __db_c_const_iterator __c_end() const; + __db_i_const_iterator __i_end() const; + + typedef __c_node*(_InsertConstruct)(void*, void*, __c_node*); + + template <class _Cont> + _LIBCPP_INLINE_VISIBILITY static __c_node* __create_C_node(void *__mem, void *__c, __c_node *__next) { + return ::new(__mem) _C_node<_Cont>(__c, __next); + } + + template <class _Cont> + _LIBCPP_INLINE_VISIBILITY + void __insert_c(_Cont* __c) + { + __insert_c(static_cast<void*>(__c), &__create_C_node<_Cont>); + } + + void __insert_i(void* __i); + void __insert_c(void* __c, _InsertConstruct* __fn); + void __erase_c(void* __c); + + void __insert_ic(void* __i, const void* __c); + void __iterator_copy(void* __i, const void* __i0); + void __erase_i(void* __i); + + void* __find_c_from_i(void* __i) const; + void __invalidate_all(void* __c); + __c_node* __find_c_and_lock(void* __c) const; + __c_node* __find_c(void* __c) const; + void unlock() const; + + void swap(void* __c1, void* __c2); + + + bool __dereferenceable(const void* __i) const; + bool __decrementable(const void* __i) const; + bool __addable(const void* __i, ptrdiff_t __n) const; + bool __subscriptable(const void* __i, ptrdiff_t __n) const; + bool __less_than_comparable(const void* __i, const void* __j) const; +private: + _LIBCPP_HIDDEN + __i_node* __insert_iterator(void* __i); + _LIBCPP_HIDDEN + __i_node* __find_iterator(const void* __i) const; + + friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db(); +}; + +_LIBCPP_FUNC_VIS __libcpp_db* __get_db(); +_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db(); + + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 || defined(_LIBCPP_BUILDING_LIBRARY) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_DEBUG_H + diff --git a/android/x86/include/v8/libc++/__errc b/android/x86/include/v8/libc++/__errc new file mode 100755 index 00000000..a8ad29f3 --- /dev/null +++ b/android/x86/include/v8/libc++/__errc @@ -0,0 +1,217 @@ +// -*- C++ -*- +//===---------------------------- __errc ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ERRC +#define _LIBCPP___ERRC + +/* + system_error synopsis + +namespace std +{ + +enum class errc +{ + address_family_not_supported, // EAFNOSUPPORT + address_in_use, // EADDRINUSE + address_not_available, // EADDRNOTAVAIL + already_connected, // EISCONN + argument_list_too_long, // E2BIG + argument_out_of_domain, // EDOM + bad_address, // EFAULT + bad_file_descriptor, // EBADF + bad_message, // EBADMSG + broken_pipe, // EPIPE + connection_aborted, // ECONNABORTED + connection_already_in_progress, // EALREADY + connection_refused, // ECONNREFUSED + connection_reset, // ECONNRESET + cross_device_link, // EXDEV + destination_address_required, // EDESTADDRREQ + device_or_resource_busy, // EBUSY + directory_not_empty, // ENOTEMPTY + executable_format_error, // ENOEXEC + file_exists, // EEXIST + file_too_large, // EFBIG + filename_too_long, // ENAMETOOLONG + function_not_supported, // ENOSYS + host_unreachable, // EHOSTUNREACH + identifier_removed, // EIDRM + illegal_byte_sequence, // EILSEQ + inappropriate_io_control_operation, // ENOTTY + interrupted, // EINTR + invalid_argument, // EINVAL + invalid_seek, // ESPIPE + io_error, // EIO + is_a_directory, // EISDIR + message_size, // EMSGSIZE + network_down, // ENETDOWN + network_reset, // ENETRESET + network_unreachable, // ENETUNREACH + no_buffer_space, // ENOBUFS + no_child_process, // ECHILD + no_link, // ENOLINK + no_lock_available, // ENOLCK + no_message_available, // ENODATA + no_message, // ENOMSG + no_protocol_option, // ENOPROTOOPT + no_space_on_device, // ENOSPC + no_stream_resources, // ENOSR + no_such_device_or_address, // ENXIO + no_such_device, // ENODEV + no_such_file_or_directory, // ENOENT + no_such_process, // ESRCH + not_a_directory, // ENOTDIR + not_a_socket, // ENOTSOCK + not_a_stream, // ENOSTR + not_connected, // ENOTCONN + not_enough_memory, // ENOMEM + not_supported, // ENOTSUP + operation_canceled, // ECANCELED + operation_in_progress, // EINPROGRESS + operation_not_permitted, // EPERM + operation_not_supported, // EOPNOTSUPP + operation_would_block, // EWOULDBLOCK + owner_dead, // EOWNERDEAD + permission_denied, // EACCES + protocol_error, // EPROTO + protocol_not_supported, // EPROTONOSUPPORT + read_only_file_system, // EROFS + resource_deadlock_would_occur, // EDEADLK + resource_unavailable_try_again, // EAGAIN + result_out_of_range, // ERANGE + state_not_recoverable, // ENOTRECOVERABLE + stream_timeout, // ETIME + text_file_busy, // ETXTBSY + timed_out, // ETIMEDOUT + too_many_files_open_in_system, // ENFILE + too_many_files_open, // EMFILE + too_many_links, // EMLINK + too_many_symbolic_link_levels, // ELOOP + value_too_large, // EOVERFLOW + wrong_protocol_type // EPROTOTYPE +}; + +*/ + +#include <__config> +#include <cerrno> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Some error codes are not present on all platforms, so we provide equivalents +// for them: + +//enum class errc +_LIBCPP_DECLARE_STRONG_ENUM(errc) +{ + address_family_not_supported = EAFNOSUPPORT, + address_in_use = EADDRINUSE, + address_not_available = EADDRNOTAVAIL, + already_connected = EISCONN, + argument_list_too_long = E2BIG, + argument_out_of_domain = EDOM, + bad_address = EFAULT, + bad_file_descriptor = EBADF, + bad_message = EBADMSG, + broken_pipe = EPIPE, + connection_aborted = ECONNABORTED, + connection_already_in_progress = EALREADY, + connection_refused = ECONNREFUSED, + connection_reset = ECONNRESET, + cross_device_link = EXDEV, + destination_address_required = EDESTADDRREQ, + device_or_resource_busy = EBUSY, + directory_not_empty = ENOTEMPTY, + executable_format_error = ENOEXEC, + file_exists = EEXIST, + file_too_large = EFBIG, + filename_too_long = ENAMETOOLONG, + function_not_supported = ENOSYS, + host_unreachable = EHOSTUNREACH, + identifier_removed = EIDRM, + illegal_byte_sequence = EILSEQ, + inappropriate_io_control_operation = ENOTTY, + interrupted = EINTR, + invalid_argument = EINVAL, + invalid_seek = ESPIPE, + io_error = EIO, + is_a_directory = EISDIR, + message_size = EMSGSIZE, + network_down = ENETDOWN, + network_reset = ENETRESET, + network_unreachable = ENETUNREACH, + no_buffer_space = ENOBUFS, + no_child_process = ECHILD, + no_link = ENOLINK, + no_lock_available = ENOLCK, +#ifdef ENODATA + no_message_available = ENODATA, +#else + no_message_available = ENOMSG, +#endif + no_message = ENOMSG, + no_protocol_option = ENOPROTOOPT, + no_space_on_device = ENOSPC, +#ifdef ENOSR + no_stream_resources = ENOSR, +#else + no_stream_resources = ENOMEM, +#endif + no_such_device_or_address = ENXIO, + no_such_device = ENODEV, + no_such_file_or_directory = ENOENT, + no_such_process = ESRCH, + not_a_directory = ENOTDIR, + not_a_socket = ENOTSOCK, +#ifdef ENOSTR + not_a_stream = ENOSTR, +#else + not_a_stream = EINVAL, +#endif + not_connected = ENOTCONN, + not_enough_memory = ENOMEM, + not_supported = ENOTSUP, + operation_canceled = ECANCELED, + operation_in_progress = EINPROGRESS, + operation_not_permitted = EPERM, + operation_not_supported = EOPNOTSUPP, + operation_would_block = EWOULDBLOCK, + owner_dead = EOWNERDEAD, + permission_denied = EACCES, + protocol_error = EPROTO, + protocol_not_supported = EPROTONOSUPPORT, + read_only_file_system = EROFS, + resource_deadlock_would_occur = EDEADLK, + resource_unavailable_try_again = EAGAIN, + result_out_of_range = ERANGE, + state_not_recoverable = ENOTRECOVERABLE, +#ifdef ETIME + stream_timeout = ETIME, +#else + stream_timeout = ETIMEDOUT, +#endif + text_file_busy = ETXTBSY, + timed_out = ETIMEDOUT, + too_many_files_open_in_system = ENFILE, + too_many_files_open = EMFILE, + too_many_links = EMLINK, + too_many_symbolic_link_levels = ELOOP, + value_too_large = EOVERFLOW, + wrong_protocol_type = EPROTOTYPE +}; +_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(errc) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ERRC diff --git a/android/x86/include/v8/libc++/__functional_03 b/android/x86/include/v8/libc++/__functional_03 new file mode 100755 index 00000000..a90cbb75 --- /dev/null +++ b/android/x86/include/v8/libc++/__functional_03 @@ -0,0 +1,1591 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUNCTIONAL_03 +#define _LIBCPP_FUNCTIONAL_03 + +// manual variadic expansion for <functional> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace __function { + +template<class _Fp> class __base; + +template<class _Rp> +class __base<_Rp()> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _Rp operator()() = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Rp, class _A0> +class __base<_Rp(_A0)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _Rp operator()(_A0) = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Rp, class _A0, class _A1> +class __base<_Rp(_A0, _A1)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _Rp operator()(_A0, _A1) = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Rp, class _A0, class _A1, class _A2> +class __base<_Rp(_A0, _A1, _A2)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _Rp operator()(_A0, _A1, _A2) = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _FD, class _Alloc, class _FB> class __func; + +template<class _Fp, class _Alloc, class _Rp> +class __func<_Fp, _Alloc, _Rp()> + : public __base<_Rp()> +{ + __compressed_pair<_Fp, _Alloc> __f_; +public: + explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} + explicit __func(_Fp __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + virtual __base<_Rp()>* __clone() const; + virtual void __clone(__base<_Rp()>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _Rp operator()(); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Fp, class _Alloc, class _Rp> +__base<_Rp()>* +__func<_Fp, _Alloc, _Rp()>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template<class _Fp, class _Alloc, class _Rp> +void +__func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template<class _Fp, class _Alloc, class _Rp> +void +__func<_Fp, _Alloc, _Rp()>::destroy() +{ + __f_.~__compressed_pair<_Fp, _Alloc>(); +} + +template<class _Fp, class _Alloc, class _Rp> +void +__func<_Fp, _Alloc, _Rp()>::destroy_deallocate() +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + __f_.~__compressed_pair<_Fp, _Alloc>(); + __a.deallocate(this, 1); +} + +template<class _Fp, class _Alloc, class _Rp> +_Rp +__func<_Fp, _Alloc, _Rp()>::operator()() +{ + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first()); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Fp, class _Alloc, class _Rp> +const void* +__func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const +{ + if (__ti == typeid(_Fp)) + return &__f_.first(); + return (const void*)0; +} + +template<class _Fp, class _Alloc, class _Rp> +const std::type_info& +__func<_Fp, _Alloc, _Rp()>::target_type() const +{ + return typeid(_Fp); +} + +#endif // _LIBCPP_NO_RTTI + +template<class _Fp, class _Alloc, class _Rp, class _A0> +class __func<_Fp, _Alloc, _Rp(_A0)> + : public __base<_Rp(_A0)> +{ + __compressed_pair<_Fp, _Alloc> __f_; +public: + _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} + _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) + : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + virtual __base<_Rp(_A0)>* __clone() const; + virtual void __clone(__base<_Rp(_A0)>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _Rp operator()(_A0); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Fp, class _Alloc, class _Rp, class _A0> +__base<_Rp(_A0)>* +__func<_Fp, _Alloc, _Rp(_A0)>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0> +void +__func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0> +void +__func<_Fp, _Alloc, _Rp(_A0)>::destroy() +{ + __f_.~__compressed_pair<_Fp, _Alloc>(); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0> +void +__func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate() +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + __f_.~__compressed_pair<_Fp, _Alloc>(); + __a.deallocate(this, 1); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0> +_Rp +__func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0) +{ + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first(), __a0); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Fp, class _Alloc, class _Rp, class _A0> +const void* +__func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const +{ + if (__ti == typeid(_Fp)) + return &__f_.first(); + return (const void*)0; +} + +template<class _Fp, class _Alloc, class _Rp, class _A0> +const std::type_info& +__func<_Fp, _Alloc, _Rp(_A0)>::target_type() const +{ + return typeid(_Fp); +} + +#endif // _LIBCPP_NO_RTTI + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> +class __func<_Fp, _Alloc, _Rp(_A0, _A1)> + : public __base<_Rp(_A0, _A1)> +{ + __compressed_pair<_Fp, _Alloc> __f_; +public: + _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} + _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) + : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + virtual __base<_Rp(_A0, _A1)>* __clone() const; + virtual void __clone(__base<_Rp(_A0, _A1)>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _Rp operator()(_A0, _A1); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> +__base<_Rp(_A0, _A1)>* +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> +void +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> +void +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy() +{ + __f_.~__compressed_pair<_Fp, _Alloc>(); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> +void +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate() +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + __f_.~__compressed_pair<_Fp, _Alloc>(); + __a.deallocate(this, 1); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> +_Rp +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) +{ + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first(), __a0, __a1); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> +const void* +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const +{ + if (__ti == typeid(_Fp)) + return &__f_.first(); + return (const void*)0; +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> +const std::type_info& +__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const +{ + return typeid(_Fp); +} + +#endif // _LIBCPP_NO_RTTI + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> +class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> + : public __base<_Rp(_A0, _A1, _A2)> +{ + __compressed_pair<_Fp, _Alloc> __f_; +public: + _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} + _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) + : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const; + virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _Rp operator()(_A0, _A1, _A2); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> +__base<_Rp(_A0, _A1, _A2)>* +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> +void +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> +void +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy() +{ + __f_.~__compressed_pair<_Fp, _Alloc>(); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> +void +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate() +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.second()); + __f_.~__compressed_pair<_Fp, _Alloc>(); + __a.deallocate(this, 1); +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> +_Rp +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) +{ + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first(), __a0, __a1, __a2); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> +const void* +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target(const type_info& __ti) const +{ + if (__ti == typeid(_Fp)) + return &__f_.first(); + return (const void*)0; +} + +template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> +const std::type_info& +__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const +{ + return typeid(_Fp); +} + +#endif // _LIBCPP_NO_RTTI + +} // __function + +template<class _Rp> +class _LIBCPP_TEMPLATE_VIS function<_Rp()> +{ + typedef __function::__base<_Rp()> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _Rp result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template<class _Fp> + function(_Fp, + typename enable_if<!is_integral<_Fp>::value>::type* = 0); + + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template<class _Alloc> + function(allocator_arg_t, const _Alloc&, const function&); + template<class _Fp, class _Alloc> + function(allocator_arg_t, const _Alloc& __a, _Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template<class _Fp> + typename enable_if + < + !is_integral<_Fp>::value, + function& + >::type + operator=(_Fp); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template<class _Fp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + void assign(_Fp __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template<class _R2> + bool operator==(const function<_R2()>&) const;// = delete; + template<class _R2> + bool operator!=(const function<_R2()>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _Rp operator()() const; + +#ifndef _LIBCPP_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template <typename _Tp> _Tp* target(); + template <typename _Tp> const _Tp* target() const; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Rp> +function<_Rp()>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template<class _Rp> +template<class _Alloc> +function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template<class _Rp> +template <class _Fp> +function<_Rp()>::function(_Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type*) + : __f_(0) +{ + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _Ap; + _Ap __a; + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + __f_ = __hold.release(); + } + } +} + +template<class _Rp> +template <class _Fp, class _Alloc> +function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, _Alloc, _Rp()> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f, __a0); + } + else + { + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + _Ap __a(__a0); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template<class _Rp> +function<_Rp()>& +function<_Rp()>::operator=(const function& __f) +{ + if (__f) + function(__f).swap(*this); + else + *this = nullptr; + return *this; +} + +template<class _Rp> +function<_Rp()>& +function<_Rp()>::operator=(nullptr_t) +{ + __base* __t = __f_; + __f_ = 0; + if (__t == (__base*)&__buf_) + __t->destroy(); + else if (__t) + __t->destroy_deallocate(); + return *this; +} + +template<class _Rp> +template <class _Fp> +typename enable_if +< + !is_integral<_Fp>::value, + function<_Rp()>& +>::type +function<_Rp()>::operator=(_Fp __f) +{ + function(_VSTD::move(__f)).swap(*this); + return *this; +} + +template<class _Rp> +function<_Rp()>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template<class _Rp> +void +function<_Rp()>::swap(function& __f) +{ + if (_VSTD::addressof(__f) == this) + return; + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage<sizeof(__buf_)>::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template<class _Rp> +_Rp +function<_Rp()>::operator()() const +{ + if (__f_ == 0) + __throw_bad_function_call(); + return (*__f_)(); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Rp> +const std::type_info& +function<_Rp()>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template<class _Rp> +template <typename _Tp> +_Tp* +function<_Rp()>::target() +{ + if (__f_ == 0) + return (_Tp*)0; + return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); +} + +template<class _Rp> +template <typename _Tp> +const _Tp* +function<_Rp()>::target() const +{ + if (__f_ == 0) + return (const _Tp*)0; + return (const _Tp*)__f_->target(typeid(_Tp)); +} + +#endif // _LIBCPP_NO_RTTI + +template<class _Rp, class _A0> +class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0)> + : public unary_function<_A0, _Rp> +{ + typedef __function::__base<_Rp(_A0)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _Rp result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template<class _Fp> + function(_Fp, + typename enable_if<!is_integral<_Fp>::value>::type* = 0); + + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template<class _Alloc> + function(allocator_arg_t, const _Alloc&, const function&); + template<class _Fp, class _Alloc> + function(allocator_arg_t, const _Alloc& __a, _Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template<class _Fp> + typename enable_if + < + !is_integral<_Fp>::value, + function& + >::type + operator=(_Fp); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template<class _Fp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + void assign(_Fp __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template<class _R2, class _B0> + bool operator==(const function<_R2(_B0)>&) const;// = delete; + template<class _R2, class _B0> + bool operator!=(const function<_R2(_B0)>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _Rp operator()(_A0) const; + +#ifndef _LIBCPP_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template <typename _Tp> _Tp* target(); + template <typename _Tp> const _Tp* target() const; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Rp, class _A0> +function<_Rp(_A0)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template<class _Rp, class _A0> +template<class _Alloc> +function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template<class _Rp, class _A0> +template <class _Fp> +function<_Rp(_A0)>::function(_Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type*) + : __f_(0) +{ + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _Ap; + _Ap __a; + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + __f_ = __hold.release(); + } + } +} + +template<class _Rp, class _A0> +template <class _Fp, class _Alloc> +function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f, __a0); + } + else + { + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + _Ap __a(__a0); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template<class _Rp, class _A0> +function<_Rp(_A0)>& +function<_Rp(_A0)>::operator=(const function& __f) +{ + if (__f) + function(__f).swap(*this); + else + *this = nullptr; + return *this; +} + +template<class _Rp, class _A0> +function<_Rp(_A0)>& +function<_Rp(_A0)>::operator=(nullptr_t) +{ + __base* __t = __f_; + __f_ = 0; + if (__t == (__base*)&__buf_) + __t->destroy(); + else if (__t) + __t->destroy_deallocate(); + return *this; +} + +template<class _Rp, class _A0> +template <class _Fp> +typename enable_if +< + !is_integral<_Fp>::value, + function<_Rp(_A0)>& +>::type +function<_Rp(_A0)>::operator=(_Fp __f) +{ + function(_VSTD::move(__f)).swap(*this); + return *this; +} + +template<class _Rp, class _A0> +function<_Rp(_A0)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template<class _Rp, class _A0> +void +function<_Rp(_A0)>::swap(function& __f) +{ + if (_VSTD::addressof(__f) == this) + return; + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage<sizeof(__buf_)>::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template<class _Rp, class _A0> +_Rp +function<_Rp(_A0)>::operator()(_A0 __a0) const +{ + if (__f_ == 0) + __throw_bad_function_call(); + return (*__f_)(__a0); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Rp, class _A0> +const std::type_info& +function<_Rp(_A0)>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template<class _Rp, class _A0> +template <typename _Tp> +_Tp* +function<_Rp(_A0)>::target() +{ + if (__f_ == 0) + return (_Tp*)0; + return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); +} + +template<class _Rp, class _A0> +template <typename _Tp> +const _Tp* +function<_Rp(_A0)>::target() const +{ + if (__f_ == 0) + return (const _Tp*)0; + return (const _Tp*)__f_->target(typeid(_Tp)); +} + +#endif // _LIBCPP_NO_RTTI + +template<class _Rp, class _A0, class _A1> +class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1)> + : public binary_function<_A0, _A1, _Rp> +{ + typedef __function::__base<_Rp(_A0, _A1)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _Rp result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template<class _Fp> + function(_Fp, + typename enable_if<!is_integral<_Fp>::value>::type* = 0); + + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template<class _Alloc> + function(allocator_arg_t, const _Alloc&, const function&); + template<class _Fp, class _Alloc> + function(allocator_arg_t, const _Alloc& __a, _Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template<class _Fp> + typename enable_if + < + !is_integral<_Fp>::value, + function& + >::type + operator=(_Fp); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template<class _Fp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + void assign(_Fp __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template<class _R2, class _B0, class _B1> + bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete; + template<class _R2, class _B0, class _B1> + bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _Rp operator()(_A0, _A1) const; + +#ifndef _LIBCPP_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template <typename _Tp> _Tp* target(); + template <typename _Tp> const _Tp* target() const; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Rp, class _A0, class _A1> +function<_Rp(_A0, _A1)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template<class _Rp, class _A0, class _A1> +template<class _Alloc> +function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template<class _Rp, class _A0, class _A1> +template <class _Fp> +function<_Rp(_A0, _A1)>::function(_Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type*) + : __f_(0) +{ + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _Ap; + _Ap __a; + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + __f_ = __hold.release(); + } + } +} + +template<class _Rp, class _A0, class _A1> +template <class _Fp, class _Alloc> +function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f, __a0); + } + else + { + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + _Ap __a(__a0); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template<class _Rp, class _A0, class _A1> +function<_Rp(_A0, _A1)>& +function<_Rp(_A0, _A1)>::operator=(const function& __f) +{ + if (__f) + function(__f).swap(*this); + else + *this = nullptr; + return *this; +} + +template<class _Rp, class _A0, class _A1> +function<_Rp(_A0, _A1)>& +function<_Rp(_A0, _A1)>::operator=(nullptr_t) +{ + __base* __t = __f_; + __f_ = 0; + if (__t == (__base*)&__buf_) + __t->destroy(); + else if (__t) + __t->destroy_deallocate(); + return *this; +} + +template<class _Rp, class _A0, class _A1> +template <class _Fp> +typename enable_if +< + !is_integral<_Fp>::value, + function<_Rp(_A0, _A1)>& +>::type +function<_Rp(_A0, _A1)>::operator=(_Fp __f) +{ + function(_VSTD::move(__f)).swap(*this); + return *this; +} + +template<class _Rp, class _A0, class _A1> +function<_Rp(_A0, _A1)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template<class _Rp, class _A0, class _A1> +void +function<_Rp(_A0, _A1)>::swap(function& __f) +{ + if (_VSTD::addressof(__f) == this) + return; + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage<sizeof(__buf_)>::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template<class _Rp, class _A0, class _A1> +_Rp +function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const +{ + if (__f_ == 0) + __throw_bad_function_call(); + return (*__f_)(__a0, __a1); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Rp, class _A0, class _A1> +const std::type_info& +function<_Rp(_A0, _A1)>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template<class _Rp, class _A0, class _A1> +template <typename _Tp> +_Tp* +function<_Rp(_A0, _A1)>::target() +{ + if (__f_ == 0) + return (_Tp*)0; + return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); +} + +template<class _Rp, class _A0, class _A1> +template <typename _Tp> +const _Tp* +function<_Rp(_A0, _A1)>::target() const +{ + if (__f_ == 0) + return (const _Tp*)0; + return (const _Tp*)__f_->target(typeid(_Tp)); +} + +#endif // _LIBCPP_NO_RTTI + +template<class _Rp, class _A0, class _A1, class _A2> +class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1, _A2)> +{ + typedef __function::__base<_Rp(_A0, _A1, _A2)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _Rp result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template<class _Fp> + function(_Fp, + typename enable_if<!is_integral<_Fp>::value>::type* = 0); + + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template<class _Alloc> + function(allocator_arg_t, const _Alloc&, const function&); + template<class _Fp, class _Alloc> + function(allocator_arg_t, const _Alloc& __a, _Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template<class _Fp> + typename enable_if + < + !is_integral<_Fp>::value, + function& + >::type + operator=(_Fp); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template<class _Fp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + void assign(_Fp __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template<class _R2, class _B0, class _B1, class _B2> + bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; + template<class _R2, class _B0, class _B1, class _B2> + bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _Rp operator()(_A0, _A1, _A2) const; + +#ifndef _LIBCPP_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template <typename _Tp> _Tp* target(); + template <typename _Tp> const _Tp* target() const; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Rp, class _A0, class _A1, class _A2> +function<_Rp(_A0, _A1, _A2)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template<class _Rp, class _A0, class _A1, class _A2> +template<class _Alloc> +function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&, + const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template<class _Rp, class _A0, class _A1, class _A2> +template <class _Fp> +function<_Rp(_A0, _A1, _A2)>::function(_Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type*) + : __f_(0) +{ + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _Ap; + _Ap __a; + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); + __f_ = __hold.release(); + } + } +} + +template<class _Rp, class _A0, class _A1, class _A2> +template <class _Fp, class _Alloc> +function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, + typename enable_if<!is_integral<_Fp>::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__function::__not_null(__f)) + { + typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f, __a0); + } + else + { + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + _Ap __a(__a0); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template<class _Rp, class _A0, class _A1, class _A2> +function<_Rp(_A0, _A1, _A2)>& +function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f) +{ + if (__f) + function(__f).swap(*this); + else + *this = nullptr; + return *this; +} + +template<class _Rp, class _A0, class _A1, class _A2> +function<_Rp(_A0, _A1, _A2)>& +function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t) +{ + __base* __t = __f_; + __f_ = 0; + if (__t == (__base*)&__buf_) + __t->destroy(); + else if (__t) + __t->destroy_deallocate(); + return *this; +} + +template<class _Rp, class _A0, class _A1, class _A2> +template <class _Fp> +typename enable_if +< + !is_integral<_Fp>::value, + function<_Rp(_A0, _A1, _A2)>& +>::type +function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f) +{ + function(_VSTD::move(__f)).swap(*this); + return *this; +} + +template<class _Rp, class _A0, class _A1, class _A2> +function<_Rp(_A0, _A1, _A2)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template<class _Rp, class _A0, class _A1, class _A2> +void +function<_Rp(_A0, _A1, _A2)>::swap(function& __f) +{ + if (_VSTD::addressof(__f) == this) + return; + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage<sizeof(__buf_)>::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template<class _Rp, class _A0, class _A1, class _A2> +_Rp +function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const +{ + if (__f_ == 0) + __throw_bad_function_call(); + return (*__f_)(__a0, __a1, __a2); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Rp, class _A0, class _A1, class _A2> +const std::type_info& +function<_Rp(_A0, _A1, _A2)>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template<class _Rp, class _A0, class _A1, class _A2> +template <typename _Tp> +_Tp* +function<_Rp(_A0, _A1, _A2)>::target() +{ + if (__f_ == 0) + return (_Tp*)0; + return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); +} + +template<class _Rp, class _A0, class _A1, class _A2> +template <typename _Tp> +const _Tp* +function<_Rp(_A0, _A1, _A2)>::target() const +{ + if (__f_ == 0) + return (const _Tp*)0; + return (const _Tp*)__f_->target(typeid(_Tp)); +} + +#endif // _LIBCPP_NO_RTTI + +template <class _Fp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const function<_Fp>& __f, nullptr_t) {return !__f;} + +template <class _Fp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(nullptr_t, const function<_Fp>& __f) {return !__f;} + +template <class _Fp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;} + +template <class _Fp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;} + +template <class _Fp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(function<_Fp>& __x, function<_Fp>& __y) +{return __x.swap(__y);} + +#endif // _LIBCPP_FUNCTIONAL_03 diff --git a/android/x86/include/v8/libc++/__functional_base b/android/x86/include/v8/libc++/__functional_base new file mode 100755 index 00000000..8da83245 --- /dev/null +++ b/android/x86/include/v8/libc++/__functional_base @@ -0,0 +1,652 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUNCTIONAL_BASE +#define _LIBCPP_FUNCTIONAL_BASE + +#include <__config> +#include <type_traits> +#include <typeinfo> +#include <exception> +#include <new> +#include <utility> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Arg1, class _Arg2, class _Result> +struct _LIBCPP_TEMPLATE_VIS binary_function +{ + typedef _Arg1 first_argument_type; + typedef _Arg2 second_argument_type; + typedef _Result result_type; +}; + +template <class _Tp> +struct __has_result_type +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + template <class _Up> static char __test(typename _Up::result_type* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS less : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x < __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS less<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +// __weak_result_type + +template <class _Tp> +struct __derives_from_unary_function +{ +private: + struct __two {char __lx; char __lxx;}; + static __two __test(...); + template <class _Ap, class _Rp> + static unary_function<_Ap, _Rp> + __test(const volatile unary_function<_Ap, _Rp>*); +public: + static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; + typedef decltype(__test((_Tp*)0)) type; +}; + +template <class _Tp> +struct __derives_from_binary_function +{ +private: + struct __two {char __lx; char __lxx;}; + static __two __test(...); + template <class _A1, class _A2, class _Rp> + static binary_function<_A1, _A2, _Rp> + __test(const volatile binary_function<_A1, _A2, _Rp>*); +public: + static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; + typedef decltype(__test((_Tp*)0)) type; +}; + +template <class _Tp, bool = __derives_from_unary_function<_Tp>::value> +struct __maybe_derive_from_unary_function // bool is true + : public __derives_from_unary_function<_Tp>::type +{ +}; + +template <class _Tp> +struct __maybe_derive_from_unary_function<_Tp, false> +{ +}; + +template <class _Tp, bool = __derives_from_binary_function<_Tp>::value> +struct __maybe_derive_from_binary_function // bool is true + : public __derives_from_binary_function<_Tp>::type +{ +}; + +template <class _Tp> +struct __maybe_derive_from_binary_function<_Tp, false> +{ +}; + +template <class _Tp, bool = __has_result_type<_Tp>::value> +struct __weak_result_type_imp // bool is true + : public __maybe_derive_from_unary_function<_Tp>, + public __maybe_derive_from_binary_function<_Tp> +{ + typedef typename _Tp::result_type result_type; +}; + +template <class _Tp> +struct __weak_result_type_imp<_Tp, false> + : public __maybe_derive_from_unary_function<_Tp>, + public __maybe_derive_from_binary_function<_Tp> +{ +}; + +template <class _Tp> +struct __weak_result_type + : public __weak_result_type_imp<_Tp> +{ +}; + +// 0 argument case + +template <class _Rp> +struct __weak_result_type<_Rp ()> +{ + typedef _Rp result_type; +}; + +template <class _Rp> +struct __weak_result_type<_Rp (&)()> +{ + typedef _Rp result_type; +}; + +template <class _Rp> +struct __weak_result_type<_Rp (*)()> +{ + typedef _Rp result_type; +}; + +// 1 argument case + +template <class _Rp, class _A1> +struct __weak_result_type<_Rp (_A1)> + : public unary_function<_A1, _Rp> +{ +}; + +template <class _Rp, class _A1> +struct __weak_result_type<_Rp (&)(_A1)> + : public unary_function<_A1, _Rp> +{ +}; + +template <class _Rp, class _A1> +struct __weak_result_type<_Rp (*)(_A1)> + : public unary_function<_A1, _Rp> +{ +}; + +template <class _Rp, class _Cp> +struct __weak_result_type<_Rp (_Cp::*)()> + : public unary_function<_Cp*, _Rp> +{ +}; + +template <class _Rp, class _Cp> +struct __weak_result_type<_Rp (_Cp::*)() const> + : public unary_function<const _Cp*, _Rp> +{ +}; + +template <class _Rp, class _Cp> +struct __weak_result_type<_Rp (_Cp::*)() volatile> + : public unary_function<volatile _Cp*, _Rp> +{ +}; + +template <class _Rp, class _Cp> +struct __weak_result_type<_Rp (_Cp::*)() const volatile> + : public unary_function<const volatile _Cp*, _Rp> +{ +}; + +// 2 argument case + +template <class _Rp, class _A1, class _A2> +struct __weak_result_type<_Rp (_A1, _A2)> + : public binary_function<_A1, _A2, _Rp> +{ +}; + +template <class _Rp, class _A1, class _A2> +struct __weak_result_type<_Rp (*)(_A1, _A2)> + : public binary_function<_A1, _A2, _Rp> +{ +}; + +template <class _Rp, class _A1, class _A2> +struct __weak_result_type<_Rp (&)(_A1, _A2)> + : public binary_function<_A1, _A2, _Rp> +{ +}; + +template <class _Rp, class _Cp, class _A1> +struct __weak_result_type<_Rp (_Cp::*)(_A1)> + : public binary_function<_Cp*, _A1, _Rp> +{ +}; + +template <class _Rp, class _Cp, class _A1> +struct __weak_result_type<_Rp (_Cp::*)(_A1) const> + : public binary_function<const _Cp*, _A1, _Rp> +{ +}; + +template <class _Rp, class _Cp, class _A1> +struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile> + : public binary_function<volatile _Cp*, _A1, _Rp> +{ +}; + +template <class _Rp, class _Cp, class _A1> +struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile> + : public binary_function<const volatile _Cp*, _A1, _Rp> +{ +}; + + +#ifndef _LIBCPP_CXX03_LANG +// 3 or more arguments + +template <class _Rp, class _A1, class _A2, class _A3, class ..._A4> +struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)> +{ + typedef _Rp result_type; +}; + +template <class _Rp, class _A1, class _A2, class _A3, class ..._A4> +struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)> +{ + typedef _Rp result_type; +}; + +template <class _Rp, class _A1, class _A2, class _A3, class ..._A4> +struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)> +{ + typedef _Rp result_type; +}; + +template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> +struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)> +{ + typedef _Rp result_type; +}; + +template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> +struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const> +{ + typedef _Rp result_type; +}; + +template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> +struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile> +{ + typedef _Rp result_type; +}; + +template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> +struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> +{ + typedef _Rp result_type; +}; + +template <class _Tp, class ..._Args> +struct __invoke_return +{ + typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type; +}; + +#else // defined(_LIBCPP_CXX03_LANG) + +#include <__functional_base_03> + +#endif // !defined(_LIBCPP_CXX03_LANG) + + +template <class _Ret> +struct __invoke_void_return_wrapper +{ +#ifndef _LIBCPP_CXX03_LANG + template <class ..._Args> + static _Ret __call(_Args&&... __args) { + return __invoke(_VSTD::forward<_Args>(__args)...); + } +#else + template <class _Fn> + static _Ret __call(_Fn __f) { + return __invoke(__f); + } + + template <class _Fn, class _A0> + static _Ret __call(_Fn __f, _A0& __a0) { + return __invoke(__f, __a0); + } + + template <class _Fn, class _A0, class _A1> + static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) { + return __invoke(__f, __a0, __a1); + } + + template <class _Fn, class _A0, class _A1, class _A2> + static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){ + return __invoke(__f, __a0, __a1, __a2); + } +#endif +}; + +template <> +struct __invoke_void_return_wrapper<void> +{ +#ifndef _LIBCPP_CXX03_LANG + template <class ..._Args> + static void __call(_Args&&... __args) { + __invoke(_VSTD::forward<_Args>(__args)...); + } +#else + template <class _Fn> + static void __call(_Fn __f) { + __invoke(__f); + } + + template <class _Fn, class _A0> + static void __call(_Fn __f, _A0& __a0) { + __invoke(__f, __a0); + } + + template <class _Fn, class _A0, class _A1> + static void __call(_Fn __f, _A0& __a0, _A1& __a1) { + __invoke(__f, __a0, __a1); + } + + template <class _Fn, class _A0, class _A1, class _A2> + static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) { + __invoke(__f, __a0, __a1, __a2); + } +#endif +}; + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS reference_wrapper + : public __weak_result_type<_Tp> +{ +public: + // types + typedef _Tp type; +private: + type* __f_; + +public: + // construct/copy/destroy + _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT + : __f_(_VSTD::addressof(__f)) {} +#ifndef _LIBCPP_CXX03_LANG + private: reference_wrapper(type&&); public: // = delete; // do not bind to temps +#endif + + // access + _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;} + _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;} + +#ifndef _LIBCPP_CXX03_LANG + // invoke + template <class... _ArgTypes> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_of<type&, _ArgTypes...>::type + operator() (_ArgTypes&&... __args) const { + return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...); + } +#else + + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return<type>::type + operator() () const { + return __invoke(get()); + } + + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return0<type, _A0>::type + operator() (_A0& __a0) const { + return __invoke(get(), __a0); + } + + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return0<type, _A0 const>::type + operator() (_A0 const& __a0) const { + return __invoke(get(), __a0); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0, _A1>::type + operator() (_A0& __a0, _A1& __a1) const { + return __invoke(get(), __a0, __a1); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0 const, _A1>::type + operator() (_A0 const& __a0, _A1& __a1) const { + return __invoke(get(), __a0, __a1); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0, _A1 const>::type + operator() (_A0& __a0, _A1 const& __a1) const { + return __invoke(get(), __a0, __a1); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0 const, _A1 const>::type + operator() (_A0 const& __a0, _A1 const& __a1) const { + return __invoke(get(), __a0, __a1); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1, _A2>::type + operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1, _A2>::type + operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1 const, _A2>::type + operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1, _A2 const>::type + operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type + operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type + operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type + operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type + operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } +#endif // _LIBCPP_CXX03_LANG +}; + + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper<_Tp> +ref(_Tp& __t) _NOEXCEPT +{ + return reference_wrapper<_Tp>(__t); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper<_Tp> +ref(reference_wrapper<_Tp> __t) _NOEXCEPT +{ + return ref(__t.get()); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper<const _Tp> +cref(const _Tp& __t) _NOEXCEPT +{ + return reference_wrapper<const _Tp>(__t); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper<const _Tp> +cref(reference_wrapper<_Tp> __t) _NOEXCEPT +{ + return cref(__t.get()); +} + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp> void ref(const _Tp&&) = delete; +template <class _Tp> void cref(const _Tp&&) = delete; +#endif + +#if _LIBCPP_STD_VER > 11 +template <class _Tp, class, class = void> +struct __is_transparent : false_type {}; + +template <class _Tp, class _Up> +struct __is_transparent<_Tp, _Up, + typename __void_t<typename _Tp::is_transparent>::type> + : true_type {}; +#endif + +// allocator_arg_t + +struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { }; + +#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) +extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg; +#else +/* _LIBCPP_INLINE_VAR */ constexpr allocator_arg_t allocator_arg = allocator_arg_t(); +#endif + +// uses_allocator + +template <class _Tp> +struct __has_allocator_type +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + template <class _Up> static char __test(typename _Up::allocator_type* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value> +struct __uses_allocator + : public integral_constant<bool, + is_convertible<_Alloc, typename _Tp::allocator_type>::value> +{ +}; + +template <class _Tp, class _Alloc> +struct __uses_allocator<_Tp, _Alloc, false> + : public false_type +{ +}; + +template <class _Tp, class _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator + : public __uses_allocator<_Tp, _Alloc> +{ +}; + +#if _LIBCPP_STD_VER > 14 +template <class _Tp, class _Alloc> +_LIBCPP_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value; +#endif + +#ifndef _LIBCPP_CXX03_LANG + +// allocator construction + +template <class _Tp, class _Alloc, class ..._Args> +struct __uses_alloc_ctor_imp +{ + typedef typename __uncvref<_Alloc>::type _RawAlloc; + static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; + static const bool __ic = + is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; + static const int value = __ua ? 2 - __ic : 0; +}; + +template <class _Tp, class _Alloc, class ..._Args> +struct __uses_alloc_ctor + : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value> + {}; + +template <class _Tp, class _Allocator, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args ) +{ + new (__storage) _Tp (_VSTD::forward<_Args>(__args)...); +} + +// FIXME: This should have a version which takes a non-const alloc. +template <class _Tp, class _Allocator, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) +{ + new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...); +} + +// FIXME: This should have a version which takes a non-const alloc. +template <class _Tp, class _Allocator, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) +{ + new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a); +} + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_FUNCTIONAL_BASE diff --git a/android/x86/include/v8/libc++/__functional_base_03 b/android/x86/include/v8/libc++/__functional_base_03 new file mode 100755 index 00000000..e6dac90c --- /dev/null +++ b/android/x86/include/v8/libc++/__functional_base_03 @@ -0,0 +1,223 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUNCTIONAL_BASE_03 +#define _LIBCPP_FUNCTIONAL_BASE_03 + +// manual variadic expansion for <functional> + +// __invoke + +template <class _Ret, class _T1, bool _IsFunc, bool _IsBase> +struct __enable_invoke_imp; + +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1, true, true> { + typedef _Ret _Bullet1; + typedef _Bullet1 type; +}; + +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1, true, false> { + typedef _Ret _Bullet2; + typedef _Bullet2 type; +}; + +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1, false, true> { + typedef typename add_lvalue_reference< + typename __apply_cv<_T1, _Ret>::type + >::type _Bullet3; + typedef _Bullet3 type; +}; + +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1, false, false> { + typedef typename add_lvalue_reference< + typename __apply_cv<decltype(*_VSTD::declval<_T1>()), _Ret>::type + >::type _Bullet4; + typedef _Bullet4 type; +}; + +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1*, false, false> { + typedef typename add_lvalue_reference< + typename __apply_cv<_T1, _Ret>::type + >::type _Bullet4; + typedef _Bullet4 type; +}; + +template <class _Fn, class _T1, + class _Traits = __member_pointer_traits<_Fn>, + class _Ret = typename _Traits::_ReturnType, + class _Class = typename _Traits::_ClassType> +struct __enable_invoke : __enable_invoke_imp< + _Ret, _T1, + is_member_function_pointer<_Fn>::value, + is_base_of<_Class, typename remove_reference<_T1>::type>::value> +{ +}; + +__nat __invoke(__any, ...); + +// first bullet + +template <class _Fn, class _T1> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1) { + return (__t1.*__f)(); +} + +template <class _Fn, class _T1, class _A0> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1, _A0& __a0) { + return (__t1.*__f)(__a0); +} + +template <class _Fn, class _T1, class _A0, class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) { + return (__t1.*__f)(__a0, __a1); +} + +template <class _Fn, class _T1, class _A0, class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) { + return (__t1.*__f)(__a0, __a1, __a2); +} + +template <class _Fn, class _T1> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1) { + return ((*__t1).*__f)(); +} + +template <class _Fn, class _T1, class _A0> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1, _A0& __a0) { + return ((*__t1).*__f)(__a0); +} + +template <class _Fn, class _T1, class _A0, class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) { + return ((*__t1).*__f)(__a0, __a1); +} + +template <class _Fn, class _T1, class _A0, class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) { + return ((*__t1).*__f)(__a0, __a1, __a2); +} + +template <class _Fn, class _T1> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet3 +__invoke(_Fn __f, _T1& __t1) { + return __t1.*__f; +} + +template <class _Fn, class _T1> +inline _LIBCPP_INLINE_VISIBILITY +typename __enable_invoke<_Fn, _T1>::_Bullet4 +__invoke(_Fn __f, _T1& __t1) { + return (*__t1).*__f; +} + +// fifth bullet + +template <class _Fp> +inline _LIBCPP_INLINE_VISIBILITY +decltype(_VSTD::declval<_Fp&>()()) +__invoke(_Fp& __f) +{ + return __f(); +} + +template <class _Fp, class _A0> +inline _LIBCPP_INLINE_VISIBILITY +decltype(_VSTD::declval<_Fp&>()(_VSTD::declval<_A0&>())) +__invoke(_Fp& __f, _A0& __a0) +{ + return __f(__a0); +} + +template <class _Fp, class _A0, class _A1> +inline _LIBCPP_INLINE_VISIBILITY +decltype(_VSTD::declval<_Fp&>()(_VSTD::declval<_A0&>(), _VSTD::declval<_A1&>())) +__invoke(_Fp& __f, _A0& __a0, _A1& __a1) +{ + return __f(__a0, __a1); +} + +template <class _Fp, class _A0, class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +decltype(_VSTD::declval<_Fp&>()(_VSTD::declval<_A0&>(), _VSTD::declval<_A1&>(), _VSTD::declval<_A2&>())) +__invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return __f(__a0, __a1, __a2); +} + +template <class _Fp, bool = __has_result_type<__weak_result_type<_Fp> >::value> +struct __invoke_return +{ + typedef typename __weak_result_type<_Fp>::result_type type; +}; + +template <class _Fp> +struct __invoke_return<_Fp, false> +{ + typedef decltype(__invoke(_VSTD::declval<_Fp&>())) type; +}; + +template <class _Tp, class _A0> +struct __invoke_return0 +{ + typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>())) type; +}; + +template <class _Rp, class _Tp, class _A0> +struct __invoke_return0<_Rp _Tp::*, _A0> +{ + typedef typename __enable_invoke<_Rp _Tp::*, _A0>::type type; +}; + +template <class _Tp, class _A0, class _A1> +struct __invoke_return1 +{ + typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>(), + _VSTD::declval<_A1&>())) type; +}; + +template <class _Rp, class _Class, class _A0, class _A1> +struct __invoke_return1<_Rp _Class::*, _A0, _A1> { + typedef typename __enable_invoke<_Rp _Class::*, _A0>::type type; +}; + +template <class _Tp, class _A0, class _A1, class _A2> +struct __invoke_return2 +{ + typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>(), + _VSTD::declval<_A1&>(), + _VSTD::declval<_A2&>())) type; +}; + +template <class _Ret, class _Class, class _A0, class _A1, class _A2> +struct __invoke_return2<_Ret _Class::*, _A0, _A1, _A2> { + typedef typename __enable_invoke<_Ret _Class::*, _A0>::type type; +}; +#endif // _LIBCPP_FUNCTIONAL_BASE_03 diff --git a/android/x86/include/v8/libc++/__hash_table b/android/x86/include/v8/libc++/__hash_table new file mode 100755 index 00000000..4b04dd62 --- /dev/null +++ b/android/x86/include/v8/libc++/__hash_table @@ -0,0 +1,2913 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP__HASH_TABLE +#define _LIBCPP__HASH_TABLE + +#include <__config> +#include <initializer_list> +#include <memory> +#include <iterator> +#include <algorithm> +#include <cmath> +#include <utility> +#include <type_traits> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Key, class _Tp> +struct __hash_value_type; + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp> +struct __is_hash_value_type_imp : false_type {}; + +template <class _Key, class _Value> +struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {}; + +template <class ..._Args> +struct __is_hash_value_type : false_type {}; + +template <class _One> +struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {}; +#endif + +_LIBCPP_FUNC_VIS +size_t __next_prime(size_t __n); + +template <class _NodePtr> +struct __hash_node_base +{ + typedef typename pointer_traits<_NodePtr>::element_type __node_type; + typedef __hash_node_base __first_node; + typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer; + typedef _NodePtr __node_pointer; + +#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB) + typedef __node_base_pointer __next_pointer; +#else + typedef typename conditional< + is_pointer<__node_pointer>::value, + __node_base_pointer, + __node_pointer>::type __next_pointer; +#endif + + __next_pointer __next_; + + _LIBCPP_INLINE_VISIBILITY + __next_pointer __ptr() _NOEXCEPT { + return static_cast<__next_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(*this)); + } + + _LIBCPP_INLINE_VISIBILITY + __node_pointer __upcast() _NOEXCEPT { + return static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(*this)); + } + + _LIBCPP_INLINE_VISIBILITY + size_t __hash() const _NOEXCEPT { + return static_cast<__node_type const&>(*this).__hash_; + } + + _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {} +}; + +template <class _Tp, class _VoidPtr> +struct __hash_node + : public __hash_node_base + < + typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type + > +{ + typedef _Tp __node_value_type; + + size_t __hash_; + __node_value_type __value_; +}; + +inline _LIBCPP_INLINE_VISIBILITY +bool +__is_hash_power2(size_t __bc) +{ + return __bc > 2 && !(__bc & (__bc - 1)); +} + +inline _LIBCPP_INLINE_VISIBILITY +size_t +__constrain_hash(size_t __h, size_t __bc) +{ + return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : + (__h < __bc ? __h : __h % __bc); +} + +inline _LIBCPP_INLINE_VISIBILITY +size_t +__next_hash_pow2(size_t __n) +{ + return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1))); +} + + +template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table; + +template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_iterator; +template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; +template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_local_iterator; +template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; +template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; +template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; + +template <class _Tp> +struct __hash_key_value_types { + static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, ""); + typedef _Tp key_type; + typedef _Tp __node_value_type; + typedef _Tp __container_value_type; + static const bool __is_map = false; + + _LIBCPP_INLINE_VISIBILITY + static key_type const& __get_key(_Tp const& __v) { + return __v; + } + _LIBCPP_INLINE_VISIBILITY + static __container_value_type const& __get_value(__node_value_type const& __v) { + return __v; + } + _LIBCPP_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _VSTD::addressof(__n); + } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + static __container_value_type&& __move(__node_value_type& __v) { + return _VSTD::move(__v); + } +#endif +}; + +template <class _Key, class _Tp> +struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > { + typedef _Key key_type; + typedef _Tp mapped_type; + typedef __hash_value_type<_Key, _Tp> __node_value_type; + typedef pair<const _Key, _Tp> __container_value_type; + typedef __container_value_type __map_value_type; + static const bool __is_map = true; + + _LIBCPP_INLINE_VISIBILITY + static key_type const& __get_key(__container_value_type const& __v) { + return __v.first; + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value, + __container_value_type const&>::type + __get_value(_Up& __t) { + return __t.__get_value(); + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, + __container_value_type const&>::type + __get_value(_Up& __t) { + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _VSTD::addressof(__n.__get_value()); + } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) { + return __v.__move(); + } +#endif + +}; + +template <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>, + bool = _KVTypes::__is_map> +struct __hash_map_pointer_types {}; + +template <class _Tp, class _AllocPtr, class _KVTypes> +struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { + typedef typename _KVTypes::__map_value_type _Mv; + typedef typename __rebind_pointer<_AllocPtr, _Mv>::type + __map_value_type_pointer; + typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type + __const_map_value_type_pointer; +}; + +template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type> +struct __hash_node_types; + +template <class _NodePtr, class _Tp, class _VoidPtr> +struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> > + : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr> + +{ + typedef __hash_key_value_types<_Tp> __base; + +public: + typedef ptrdiff_t difference_type; + typedef size_t size_type; + + typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer; + + typedef typename pointer_traits<_NodePtr>::element_type __node_type; + typedef _NodePtr __node_pointer; + + typedef __hash_node_base<__node_pointer> __node_base_type; + typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type + __node_base_pointer; + + typedef typename __node_base_type::__next_pointer __next_pointer; + + typedef _Tp __node_value_type; + typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type + __node_value_type_pointer; + typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type + __const_node_value_type_pointer; + +private: + static_assert(!is_const<__node_type>::value, + "_NodePtr should never be a pointer to const"); + static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value), + "_VoidPtr does not point to unqualified void type"); + static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type, + _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); +}; + +template <class _HashIterator> +struct __hash_node_types_from_iterator; +template <class _NodePtr> +struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; +template <class _NodePtr> +struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; +template <class _NodePtr> +struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; +template <class _NodePtr> +struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; + + +template <class _NodeValueTp, class _VoidPtr> +struct __make_hash_node_types { + typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp; + typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr; + typedef __hash_node_types<_NodePtr> type; +}; + +template <class _NodePtr> +class _LIBCPP_TEMPLATE_VIS __hash_iterator +{ + typedef __hash_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__node_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) { + _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_iterator(const __hash_iterator& __i) + : __node_(__i.__node_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCPP_INLINE_VISIBILITY + ~__hash_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_iterator& operator=(const __hash_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + } + return *this; + } +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container iterator"); + return __node_->__upcast()->__value_; + } + + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container iterator"); + return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_iterator& operator++() { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container iterator"); + __node_ = __node_->__next_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __hash_iterator operator++(int) + { + __hash_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) + {return !(__x == __y);} + +private: +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT + : __node_(__node) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCPP_INLINE_VISIBILITY + __hash_iterator(__next_pointer __node) _NOEXCEPT + : __node_(__node) + {} +#endif + template <class, class, class, class> friend class __hash_table; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; +}; + +template <class _NodePtr> +class _LIBCPP_TEMPLATE_VIS __hash_const_iterator +{ + static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, ""); + typedef __hash_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + +public: + typedef __hash_iterator<_NodePtr> __non_const_iterator; + + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_node_value_type_pointer pointer; + + + _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) { + _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT + : __node_(__x.__node_) + { + _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator(const __hash_const_iterator& __i) + : __node_(__i.__node_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCPP_INLINE_VISIBILITY + ~__hash_const_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator& operator=(const __hash_const_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + } + return *this; + } +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_iterator"); + return __node_->__upcast()->__value_; + } + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_iterator"); + return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator& operator++() { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container const_iterator"); + __node_ = __node_->__next_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator operator++(int) + { + __hash_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y) + {return !(__x == __y);} + +private: +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT + : __node_(__node) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator(__next_pointer __node) _NOEXCEPT + : __node_(__node) + {} +#endif + template <class, class, class, class> friend class __hash_table; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; +}; + +template <class _NodePtr> +class _LIBCPP_TEMPLATE_VIS __hash_local_iterator +{ + typedef __hash_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + size_t __bucket_; + size_t __bucket_count_; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__node_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) { + _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator(const __hash_local_iterator& __i) + : __node_(__i.__node_), + __bucket_(__i.__bucket_), + __bucket_count_(__i.__bucket_count_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCPP_INLINE_VISIBILITY + ~__hash_local_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator& operator=(const __hash_local_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + __bucket_ = __i.__bucket_; + __bucket_count_ = __i.__bucket_count_; + } + return *this; + } +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container local_iterator"); + return __node_->__upcast()->__value_; + } + + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container local_iterator"); + return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator& operator++() { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container local_iterator"); + __node_ = __node_->__next_; + if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) + __node_ = nullptr; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator operator++(int) + { + __hash_local_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y) + {return !(__x == __y);} + +private: +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count, const void* __c) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + __get_db()->__insert_ic(this, __c); + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#else + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#endif + template <class, class, class, class> friend class __hash_table; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; +}; + +template <class _ConstNodePtr> +class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator +{ + typedef __hash_node_types<_ConstNodePtr> _NodeTypes; + typedef _ConstNodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + + __next_pointer __node_; + size_t __bucket_; + size_t __bucket_count_; + + typedef pointer_traits<__node_pointer> __pointer_traits; + typedef typename __pointer_traits::element_type __node; + typedef typename remove_const<__node>::type __non_const_node; + typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type + __non_const_node_pointer; +public: + typedef __hash_local_iterator<__non_const_node_pointer> + __non_const_iterator; + + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__node_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_node_value_type_pointer pointer; + + + _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) { + _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT + : __node_(__x.__node_), + __bucket_(__x.__bucket_), + __bucket_count_(__x.__bucket_count_) + { + _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator(const __hash_const_local_iterator& __i) + : __node_(__i.__node_), + __bucket_(__i.__bucket_), + __bucket_count_(__i.__bucket_count_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCPP_INLINE_VISIBILITY + ~__hash_const_local_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + __bucket_ = __i.__bucket_; + __bucket_count_ = __i.__bucket_count_; + } + return *this; + } +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); + return __node_->__upcast()->__value_; + } + + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); + return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator& operator++() { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container const_local_iterator"); + __node_ = __node_->__next_; + if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) + __node_ = nullptr; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator operator++(int) + { + __hash_const_local_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) + { + return __x.__node_ == __y.__node_; + } + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) + {return !(__x == __y);} + +private: +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count, const void* __c) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + __get_db()->__insert_ic(this, __c); + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#else + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#endif + template <class, class, class, class> friend class __hash_table; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; +}; + +template <class _Alloc> +class __bucket_list_deallocator +{ + typedef _Alloc allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __alloc_traits::size_type size_type; + + __compressed_pair<size_type, allocator_type> __data_; +public: + typedef typename __alloc_traits::pointer pointer; + + _LIBCPP_INLINE_VISIBILITY + __bucket_list_deallocator() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + : __data_(0) {} + + _LIBCPP_INLINE_VISIBILITY + __bucket_list_deallocator(const allocator_type& __a, size_type __size) + _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) + : __data_(__size, __a) {} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __bucket_list_deallocator(__bucket_list_deallocator&& __x) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) + : __data_(_VSTD::move(__x.__data_)) + { + __x.size() = 0; + } +#endif + + _LIBCPP_INLINE_VISIBILITY + size_type& size() _NOEXCEPT {return __data_.first();} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __data_.first();} + + _LIBCPP_INLINE_VISIBILITY + allocator_type& __alloc() _NOEXCEPT {return __data_.second();} + _LIBCPP_INLINE_VISIBILITY + const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();} + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + __alloc_traits::deallocate(__alloc(), __p, size()); + } +}; + +template <class _Alloc> class __hash_map_node_destructor; + +template <class _Alloc> +class __hash_node_destructor +{ + typedef _Alloc allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + +public: + typedef typename __alloc_traits::pointer pointer; +private: + typedef __hash_node_types<pointer> _NodeTypes; + + allocator_type& __na_; + + __hash_node_destructor& operator=(const __hash_node_destructor&); + +public: + bool __value_constructed; + + _LIBCPP_INLINE_VISIBILITY + explicit __hash_node_destructor(allocator_type& __na, + bool __constructed = false) _NOEXCEPT + : __na_(__na), + __value_constructed(__constructed) + {} + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + if (__value_constructed) + __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } + + template <class> friend class __hash_map_node_destructor; +}; + +#if _LIBCPP_STD_VER > 14 +template <class _NodeType, class _Alloc> +struct __generic_container_node_destructor; + +template <class _Tp, class _VoidPtr, class _Alloc> +struct __generic_container_node_destructor<__hash_node<_Tp, _VoidPtr>, _Alloc> + : __hash_node_destructor<_Alloc> +{ + using __hash_node_destructor<_Alloc>::__hash_node_destructor; +}; +#endif + +template <class _Key, class _Hash, class _Equal> +struct __enforce_unordered_container_requirements { +#ifndef _LIBCPP_CXX03_LANG + static_assert(__check_hash_requirements<_Key, _Hash>::value, + "the specified hash does not meet the Hash requirements"); + static_assert(is_copy_constructible<_Equal>::value, + "the specified comparator is required to be copy constructible"); +#endif + typedef int type; +}; + +template <class _Key, class _Hash, class _Equal> +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_DIAGNOSE_WARNING(!__invokable<_Equal const&, _Key const&, _Key const&>::value, + "the specified comparator type does not provide a viable const call operator") + _LIBCPP_DIAGNOSE_WARNING(!__invokable<_Hash const&, _Key const&>::value, + "the specified hash functor does not provide a viable const call operator") +#endif +typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type +__diagnose_unordered_container_requirements(int); + +// This dummy overload is used so that the compiler won't emit a spurious +// "no matching function for call to __diagnose_unordered_xxx" diagnostic +// when the overload above causes a hard error. +template <class _Key, class _Hash, class _Equal> +int __diagnose_unordered_container_requirements(void*); + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +class __hash_table +{ +public: + typedef _Tp value_type; + typedef _Hash hasher; + typedef _Equal key_equal; + typedef _Alloc allocator_type; + +private: + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename + __make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type + _NodeTypes; +public: + + typedef typename _NodeTypes::__node_value_type __node_value_type; + typedef typename _NodeTypes::__container_value_type __container_value_type; + typedef typename _NodeTypes::key_type key_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; +#ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE + typedef typename __alloc_traits::size_type size_type; +#else + typedef typename _NodeTypes::size_type size_type; +#endif + typedef typename _NodeTypes::difference_type difference_type; +public: + // Create __node + + typedef typename _NodeTypes::__node_type __node; + typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + typedef typename _NodeTypes::__void_pointer __void_pointer; + typedef typename _NodeTypes::__node_pointer __node_pointer; + typedef typename _NodeTypes::__node_pointer __node_const_pointer; + typedef typename _NodeTypes::__node_base_type __first_node; + typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; + +private: + // check for sane allocator pointer rebinding semantics. Rebinding the + // allocator for a new pointer type should be exactly the same as rebinding + // the pointer using 'pointer_traits'. + static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type + __node_base_allocator; + typedef allocator_traits<__node_base_allocator> __node_base_traits; + static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + +private: + + typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator; + typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; + typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; + typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; + typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; + + // --- Member data begin --- + __bucket_list __bucket_list_; + __compressed_pair<__first_node, __node_allocator> __p1_; + __compressed_pair<size_type, hasher> __p2_; + __compressed_pair<float, key_equal> __p3_; + // --- Member data end --- + + _LIBCPP_INLINE_VISIBILITY + size_type& size() _NOEXCEPT {return __p2_.first();} +public: + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __p2_.first();} + + _LIBCPP_INLINE_VISIBILITY + hasher& hash_function() _NOEXCEPT {return __p2_.second();} + _LIBCPP_INLINE_VISIBILITY + const hasher& hash_function() const _NOEXCEPT {return __p2_.second();} + + _LIBCPP_INLINE_VISIBILITY + float& max_load_factor() _NOEXCEPT {return __p3_.first();} + _LIBCPP_INLINE_VISIBILITY + float max_load_factor() const _NOEXCEPT {return __p3_.first();} + + _LIBCPP_INLINE_VISIBILITY + key_equal& key_eq() _NOEXCEPT {return __p3_.second();} + _LIBCPP_INLINE_VISIBILITY + const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();} + + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();} + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __node_alloc() const _NOEXCEPT + {return __p1_.second();} + +public: + typedef __hash_iterator<__node_pointer> iterator; + typedef __hash_const_iterator<__node_pointer> const_iterator; + typedef __hash_local_iterator<__node_pointer> local_iterator; + typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; + + _LIBCPP_INLINE_VISIBILITY + __hash_table() + _NOEXCEPT_( + is_nothrow_default_constructible<__bucket_list>::value && + is_nothrow_default_constructible<__first_node>::value && + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_default_constructible<hasher>::value && + is_nothrow_default_constructible<key_equal>::value); + _LIBCPP_INLINE_VISIBILITY + __hash_table(const hasher& __hf, const key_equal& __eql); + __hash_table(const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); + explicit __hash_table(const allocator_type& __a); + __hash_table(const __hash_table& __u); + __hash_table(const __hash_table& __u, const allocator_type& __a); +#ifndef _LIBCPP_CXX03_LANG + __hash_table(__hash_table&& __u) + _NOEXCEPT_( + is_nothrow_move_constructible<__bucket_list>::value && + is_nothrow_move_constructible<__first_node>::value && + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible<hasher>::value && + is_nothrow_move_constructible<key_equal>::value); + __hash_table(__hash_table&& __u, const allocator_type& __a); +#endif // _LIBCPP_CXX03_LANG + ~__hash_table(); + + __hash_table& operator=(const __hash_table& __u); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __hash_table& operator=(__hash_table&& __u) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable<hasher>::value && + is_nothrow_move_assignable<key_equal>::value); +#endif + template <class _InputIterator> + void __assign_unique(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + void __assign_multi(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + { + return std::min<size_type>( + __node_traits::max_size(__node_alloc()), + numeric_limits<difference_type >::max() + ); + } + +private: + _LIBCPP_INLINE_VISIBILITY + __next_pointer __node_insert_multi_prepare(size_t __cp_hash, + value_type& __cp_val); + _LIBCPP_INLINE_VISIBILITY + void __node_insert_multi_perform(__node_pointer __cp, + __next_pointer __pn) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + __next_pointer __node_insert_unique_prepare(size_t __nd_hash, + value_type& __nd_val); + _LIBCPP_INLINE_VISIBILITY + void __node_insert_unique_perform(__node_pointer __ptr) _NOEXCEPT; + +public: + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __node_insert_unique(__node_pointer __nd); + _LIBCPP_INLINE_VISIBILITY + iterator __node_insert_multi(__node_pointer __nd); + _LIBCPP_INLINE_VISIBILITY + iterator __node_insert_multi(const_iterator __p, + __node_pointer __nd); + +#ifndef _LIBCPP_CXX03_LANG + template <class _Key, class ..._Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args); + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique_impl(_Args&&... __args); + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique(_Pp&& __x) { + return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x), + __can_extract_key<_Pp, key_type>()); + } + + template <class _First, class _Second> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + __can_extract_map_key<_First, key_type, __container_value_type>::value, + pair<iterator, bool> + >::type __emplace_unique(_First&& __f, _Second&& __s) { + return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f), + _VSTD::forward<_Second>(__s)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique(_Args&&... __args) { + return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { + return __emplace_unique_impl(_VSTD::forward<_Pp>(__x)); + } + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { + return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x)); + } + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { + return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator __emplace_multi(_Args&&... __args); + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); + + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __insert_unique(__container_value_type&& __x) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x)); + } + + template <class _Pp, class = typename enable_if< + !__is_same_uncvref<_Pp, __container_value_type>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __insert_unique(_Pp&& __x) { + return __emplace_unique(_VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(_Pp&& __x) { + return __emplace_multi(_VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(const_iterator __p, _Pp&& __x) { + return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x)); + } + +#else // !defined(_LIBCPP_CXX03_LANG) + template <class _Key, class _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args); + + iterator __insert_multi(const __container_value_type& __x); + iterator __insert_multi(const_iterator __p, const __container_value_type& __x); +#endif + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __insert_unique(const __container_value_type& __x) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x); + } + +#if _LIBCPP_STD_VER > 14 + template <class _NodeHandle, class _InsertReturnType> + _LIBCPP_INLINE_VISIBILITY + _InsertReturnType __node_handle_insert_unique(_NodeHandle&& __nh); + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + iterator __node_handle_insert_unique(const_iterator __hint, + _NodeHandle&& __nh); + template <class _Table> + _LIBCPP_INLINE_VISIBILITY + void __node_handle_merge_unique(_Table& __source); + + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + iterator __node_handle_insert_multi(_NodeHandle&& __nh); + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + iterator __node_handle_insert_multi(const_iterator __hint, _NodeHandle&& __nh); + template <class _Table> + _LIBCPP_INLINE_VISIBILITY + void __node_handle_merge_multi(_Table& __source); + + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(key_type const& __key); + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(const_iterator __it); +#endif + + void clear() _NOEXCEPT; + void rehash(size_type __n); + _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n) + {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const _NOEXCEPT + { + return __bucket_list_.get_deleter().size(); + } + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT; + + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + size_type bucket(const _Key& __k) const + { + _LIBCPP_ASSERT(bucket_count() > 0, + "unordered container::bucket(key) called when bucket_count() == 0"); + return __constrain_hash(hash_function()(__k), bucket_count()); + } + + template <class _Key> + iterator find(const _Key& __x); + template <class _Key> + const_iterator find(const _Key& __x) const; + + typedef __hash_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + + iterator erase(const_iterator __p); + iterator erase(const_iterator __first, const_iterator __last); + template <class _Key> + size_type __erase_unique(const _Key& __k); + template <class _Key> + size_type __erase_multi(const _Key& __k); + __node_holder remove(const_iterator __p) _NOEXCEPT; + + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + size_type __count_unique(const _Key& __k) const; + template <class _Key> + size_type __count_multi(const _Key& __k) const; + + template <class _Key> + pair<iterator, iterator> + __equal_range_unique(const _Key& __k); + template <class _Key> + pair<const_iterator, const_iterator> + __equal_range_unique(const _Key& __k) const; + + template <class _Key> + pair<iterator, iterator> + __equal_range_multi(const _Key& __k); + template <class _Key> + pair<const_iterator, const_iterator> + __equal_range_multi(const _Key& __k) const; + + void swap(__hash_table& __u) +#if _LIBCPP_STD_VER <= 11 + _NOEXCEPT_( + __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value + && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value + || __is_nothrow_swappable<__pointer_allocator>::value) + && (!__node_traits::propagate_on_container_swap::value + || __is_nothrow_swappable<__node_allocator>::value) + ); +#else + _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value); +#endif + + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const _NOEXCEPT + {return max_size(); } + size_type bucket_size(size_type __n) const; + _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT + { + size_type __bc = bucket_count(); + return __bc != 0 ? (float)size() / __bc : 0.f; + } + _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT + { + _LIBCPP_ASSERT(__mlf > 0, + "unordered container::max_load_factor(lf) called with lf <= 0"); + max_load_factor() = _VSTD::max(__mlf, load_factor()); + } + + _LIBCPP_INLINE_VISIBILITY + local_iterator + begin(size_type __n) + { + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::begin(n) called with n >= bucket_count()"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return local_iterator(__bucket_list_[__n], __n, bucket_count(), this); +#else + return local_iterator(__bucket_list_[__n], __n, bucket_count()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + local_iterator + end(size_type __n) + { + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::end(n) called with n >= bucket_count()"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return local_iterator(nullptr, __n, bucket_count(), this); +#else + return local_iterator(nullptr, __n, bucket_count()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + const_local_iterator + cbegin(size_type __n) const + { + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::cbegin(n) called with n >= bucket_count()"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this); +#else + return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + const_local_iterator + cend(size_type __n) const + { + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::cend(n) called with n >= bucket_count()"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_local_iterator(nullptr, __n, bucket_count(), this); +#else + return const_local_iterator(nullptr, __n, bucket_count()); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const; + bool __decrementable(const const_iterator* __i) const; + bool __addable(const const_iterator* __i, ptrdiff_t __n) const; + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +private: + void __rehash(size_type __n); + +#ifndef _LIBCPP_CXX03_LANG + template <class ..._Args> + __node_holder __construct_node(_Args&& ...__args); + + template <class _First, class ..._Rest> + __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest); +#else // _LIBCPP_CXX03_LANG + __node_holder __construct_node(const __container_value_type& __v); + __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v); +#endif + + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __hash_table& __u) + {__copy_assign_alloc(__u, integral_constant<bool, + __node_traits::propagate_on_container_copy_assignment::value>());} + void __copy_assign_alloc(const __hash_table& __u, true_type); + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __hash_table&, false_type) {} + +#ifndef _LIBCPP_CXX03_LANG + void __move_assign(__hash_table& __u, false_type); + void __move_assign(__hash_table& __u, true_type) + _NOEXCEPT_( + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable<hasher>::value && + is_nothrow_move_assignable<key_equal>::value); + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table& __u) + _NOEXCEPT_( + !__node_traits::propagate_on_container_move_assignment::value || + (is_nothrow_move_assignable<__pointer_allocator>::value && + is_nothrow_move_assignable<__node_allocator>::value)) + {__move_assign_alloc(__u, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>());} + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table& __u, true_type) + _NOEXCEPT_( + is_nothrow_move_assignable<__pointer_allocator>::value && + is_nothrow_move_assignable<__node_allocator>::value) + { + __bucket_list_.get_deleter().__alloc() = + _VSTD::move(__u.__bucket_list_.get_deleter().__alloc()); + __node_alloc() = _VSTD::move(__u.__node_alloc()); + } + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {} +#endif // _LIBCPP_CXX03_LANG + + void __deallocate_node(__next_pointer __np) _NOEXCEPT; + __next_pointer __detach() _NOEXCEPT; + + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; +}; + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +inline +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() + _NOEXCEPT_( + is_nothrow_default_constructible<__bucket_list>::value && + is_nothrow_default_constructible<__first_node>::value && + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_default_constructible<hasher>::value && + is_nothrow_default_constructible<key_equal>::value) + : __p2_(0), + __p3_(1.0f) +{ +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +inline +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, + const key_equal& __eql) + : __bucket_list_(nullptr, __bucket_list_deleter()), + __p1_(), + __p2_(0, __hf), + __p3_(1.0f, __eql) +{ +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0, __hf), + __p3_(1.0f, __eql) +{ +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0), + __p3_(1.0f) +{ +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) + : __bucket_list_(nullptr, + __bucket_list_deleter(allocator_traits<__pointer_allocator>:: + select_on_container_copy_construction( + __u.__bucket_list_.get_deleter().__alloc()), 0)), + __p1_(__second_tag(), allocator_traits<__node_allocator>:: + select_on_container_copy_construction(__u.__node_alloc())), + __p2_(0, __u.hash_function()), + __p3_(__u.__p3_) +{ +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0, __u.hash_function()), + __p3_(__u.__p3_) +{ +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) + _NOEXCEPT_( + is_nothrow_move_constructible<__bucket_list>::value && + is_nothrow_move_constructible<__first_node>::value && + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible<hasher>::value && + is_nothrow_move_constructible<key_equal>::value) + : __bucket_list_(_VSTD::move(__u.__bucket_list_)), + __p1_(_VSTD::move(__u.__p1_)), + __p2_(_VSTD::move(__u.__p2_)), + __p3_(_VSTD::move(__u.__p3_)) +{ + if (size() > 0) + { + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + __u.__p1_.first().__next_ = nullptr; + __u.size() = 0; + } +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__second_tag(), __node_allocator(__a)), + __p2_(0, _VSTD::move(__u.hash_function())), + __p3_(_VSTD::move(__u.__p3_)) +{ + if (__a == allocator_type(__u.__node_alloc())) + { + __bucket_list_.reset(__u.__bucket_list_.release()); + __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); + __u.__bucket_list_.get_deleter().size() = 0; + if (__u.size() > 0) + { + __p1_.first().__next_ = __u.__p1_.first().__next_; + __u.__p1_.first().__next_ = nullptr; + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + size() = __u.size(); + __u.size() = 0; + } + } +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() +{ +#if defined(_LIBCPP_CXX03_LANG) + static_assert((is_copy_constructible<key_equal>::value), + "Predicate must be copy-constructible."); + static_assert((is_copy_constructible<hasher>::value), + "Hasher must be copy-constructible."); +#endif + + __deallocate_node(__p1_.first().__next_); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__erase_c(this); +#endif +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc( + const __hash_table& __u, true_type) +{ + if (__node_alloc() != __u.__node_alloc()) + { + clear(); + __bucket_list_.reset(); + __bucket_list_.get_deleter().size() = 0; + } + __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc(); + __node_alloc() = __u.__node_alloc(); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +__hash_table<_Tp, _Hash, _Equal, _Alloc>& +__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) +{ + if (this != &__u) + { + __copy_assign_alloc(__u); + hash_function() = __u.hash_function(); + key_eq() = __u.key_eq(); + max_load_factor() = __u.max_load_factor(); + __assign_multi(__u.begin(), __u.end()); + } + return *this; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np) + _NOEXCEPT +{ + __node_allocator& __na = __node_alloc(); + while (__np != nullptr) + { + __next_pointer __next = __np->__next_; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast<iterator*>((*__p)->__i_); + if (__i->__node_ == __np) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_pointer __real_np = __np->__upcast(); + __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_)); + __node_traits::deallocate(__na, __real_np, 1); + __np = __next; + } +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT +{ + size_type __bc = bucket_count(); + for (size_type __i = 0; __i < __bc; ++__i) + __bucket_list_[__i] = nullptr; + size() = 0; + __next_pointer __cache = __p1_.first().__next_; + __p1_.first().__next_ = nullptr; + return __cache; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( + __hash_table& __u, true_type) + _NOEXCEPT_( + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable<hasher>::value && + is_nothrow_move_assignable<key_equal>::value) +{ + clear(); + __bucket_list_.reset(__u.__bucket_list_.release()); + __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); + __u.__bucket_list_.get_deleter().size() = 0; + __move_assign_alloc(__u); + size() = __u.size(); + hash_function() = _VSTD::move(__u.hash_function()); + max_load_factor() = __u.max_load_factor(); + key_eq() = _VSTD::move(__u.key_eq()); + __p1_.first().__next_ = __u.__p1_.first().__next_; + if (size() > 0) + { + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + __u.__p1_.first().__next_ = nullptr; + __u.size() = 0; + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->swap(this, &__u); +#endif +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( + __hash_table& __u, false_type) +{ + if (__node_alloc() == __u.__node_alloc()) + __move_assign(__u, true_type()); + else + { + hash_function() = _VSTD::move(__u.hash_function()); + key_eq() = _VSTD::move(__u.key_eq()); + max_load_factor() = __u.max_load_factor(); + if (bucket_count() != 0) + { + __next_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + const_iterator __i = __u.begin(); + while (__cache != nullptr && __u.size() != 0) + { + __cache->__upcast()->__value_ = + _VSTD::move(__u.remove(__i++)->__value_); + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __deallocate_node(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __deallocate_node(__cache); + } + const_iterator __i = __u.begin(); + while (__u.size() != 0) + { + __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_)); + __node_insert_multi(__h.get()); + __h.release(); + } + } +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +inline +__hash_table<_Tp, _Hash, _Equal, _Alloc>& +__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable<hasher>::value && + is_nothrow_move_assignable<key_equal>::value) +{ + __move_assign(__u, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _InputIterator> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first, + _InputIterator __last) +{ + typedef iterator_traits<_InputIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value), + "__assign_unique may only be called with the containers value type"); + + if (bucket_count() != 0) + { + __next_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__upcast()->__value_ = *__first; + __next_pointer __next = __cache->__next_; + __node_insert_unique(__cache->__upcast()); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __deallocate_node(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __deallocate_node(__cache); + } + for (; __first != __last; ++__first) + __insert_unique(*__first); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _InputIterator> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, + _InputIterator __last) +{ + typedef iterator_traits<_InputIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value || + is_same<_ItValueType, __node_value_type>::value), + "__assign_multi may only be called with the containers value type" + " or the nodes value type"); + if (bucket_count() != 0) + { + __next_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__upcast()->__value_ = *__first; + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __deallocate_node(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __deallocate_node(__cache); + } + for (; __first != __last; ++__first) + __insert_multi(_NodeTypes::__get_value(*__first)); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__p1_.first().__next_, this); +#else + return iterator(__p1_.first().__next_); +#endif +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(nullptr, this); +#else + return iterator(nullptr); +#endif +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(__p1_.first().__next_, this); +#else + return const_iterator(__p1_.first().__next_); +#endif +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(nullptr, this); +#else + return const_iterator(nullptr); +#endif +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT +{ + if (size() > 0) + { + __deallocate_node(__p1_.first().__next_); + __p1_.first().__next_ = nullptr; + size_type __bc = bucket_count(); + for (size_type __i = 0; __i < __bc; ++__i) + __bucket_list_[__i] = nullptr; + size() = 0; + } +} + + +// Prepare the container for an insertion of the value __value with the hash +// __hash. This does a lookup into the container to see if __value is already +// present, and performs a rehash if necessary. Returns a pointer to the +// existing element if it exists, otherwise nullptr. +// +// Note that this function does forward exceptions if key_eq() throws, and never +// mutates __value or actually inserts into the map. +template <class _Tp, class _Hash, class _Equal, class _Alloc> +_LIBCPP_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare( + size_t __hash, value_type& __value) +{ + size_type __bc = bucket_count(); + + if (__bc != 0) + { + size_t __chash = __constrain_hash(__hash, __bc); + __next_pointer __ndptr = __bucket_list_[__chash]; + if (__ndptr != nullptr) + { + for (__ndptr = __ndptr->__next_; __ndptr != nullptr && + __constrain_hash(__ndptr->__hash(), __bc) == __chash; + __ndptr = __ndptr->__next_) + { + if (key_eq()(__ndptr->__upcast()->__value_, __value)) + return __ndptr; + } + } + } + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + } + return nullptr; +} + +// Insert the node __nd into the container by pushing it into the right bucket, +// and updating size(). Assumes that __nd->__hash is up-to-date, and that +// rehashing has already occurred and that no element with the same key exists +// in the map. +template <class _Tp, class _Hash, class _Equal, class _Alloc> +_LIBCPP_INLINE_VISIBILITY +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform( + __node_pointer __nd) _NOEXCEPT +{ + size_type __bc = bucket_count(); + size_t __chash = __constrain_hash(__nd->__hash(), __bc); + // insert_after __bucket_list_[__chash], or __first_node if bucket is null + __next_pointer __pn = __bucket_list_[__chash]; + if (__pn == nullptr) + { + __pn =__p1_.first().__ptr(); + __nd->__next_ = __pn->__next_; + __pn->__next_ = __nd->__ptr(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__nd->__next_ != nullptr) + __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); + } + else + { + __nd->__next_ = __pn->__next_; + __pn->__next_ = __nd->__ptr(); + } + ++size(); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd) +{ + __nd->__hash_ = hash_function()(__nd->__value_); + __next_pointer __existing_node = + __node_insert_unique_prepare(__nd->__hash(), __nd->__value_); + + // Insert the node, unless it already exists in the container. + bool __inserted = false; + if (__existing_node == nullptr) + { + __node_insert_unique_perform(__nd); + __existing_node = __nd->__ptr(); + __inserted = true; + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + return pair<iterator, bool>(iterator(__existing_node, this), __inserted); +#else + return pair<iterator, bool>(iterator(__existing_node), __inserted); +#endif +} + +// Prepare the container for an insertion of the value __cp_val with the hash +// __cp_hash. This does a lookup into the container to see if __cp_value is +// already present, and performs a rehash if necessary. Returns a pointer to the +// last occurance of __cp_val in the map. +// +// Note that this function does forward exceptions if key_eq() throws, and never +// mutates __value or actually inserts into the map. +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare( + size_t __cp_hash, value_type& __cp_val) +{ + size_type __bc = bucket_count(); + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + } + size_t __chash = __constrain_hash(__cp_hash, __bc); + __next_pointer __pn = __bucket_list_[__chash]; + if (__pn != nullptr) + { + for (bool __found = false; __pn->__next_ != nullptr && + __constrain_hash(__pn->__next_->__hash(), __bc) == __chash; + __pn = __pn->__next_) + { + // __found key_eq() action + // false false loop + // true true loop + // false true set __found to true + // true false break + if (__found != (__pn->__next_->__hash() == __cp_hash && + key_eq()(__pn->__next_->__upcast()->__value_, __cp_val))) + { + if (!__found) + __found = true; + else + break; + } + } + } + return __pn; +} + +// Insert the node __cp into the container after __pn (which is the last node in +// the bucket that compares equal to __cp). Rehashing, and checking for +// uniqueness has already been performed (in __node_insert_multi_prepare), so +// all we need to do is update the bucket and size(). Assumes that __cp->__hash +// is up-to-date. +template <class _Tp, class _Hash, class _Equal, class _Alloc> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( + __node_pointer __cp, __next_pointer __pn) _NOEXCEPT +{ + size_type __bc = bucket_count(); + size_t __chash = __constrain_hash(__cp->__hash_, __bc); + if (__pn == nullptr) + { + __pn =__p1_.first().__ptr(); + __cp->__next_ = __pn->__next_; + __pn->__next_ = __cp->__ptr(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__cp->__next_ != nullptr) + __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)] + = __cp->__ptr(); + } + else + { + __cp->__next_ = __pn->__next_; + __pn->__next_ = __cp->__ptr(); + if (__cp->__next_ != nullptr) + { + size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc); + if (__nhash != __chash) + __bucket_list_[__nhash] = __cp->__ptr(); + } + } + ++size(); +} + + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp) +{ + __cp->__hash_ = hash_function()(__cp->__value_); + __next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__value_); + __node_insert_multi_perform(__cp, __pn); + +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__cp->__ptr(), this); +#else + return iterator(__cp->__ptr()); +#endif +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( + const_iterator __p, __node_pointer __cp) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered container"); +#endif + if (__p != end() && key_eq()(*__p, __cp->__value_)) + { + __next_pointer __np = __p.__node_; + __cp->__hash_ = __np->__hash(); + size_type __bc = bucket_count(); + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + } + size_t __chash = __constrain_hash(__cp->__hash_, __bc); + __next_pointer __pp = __bucket_list_[__chash]; + while (__pp->__next_ != __np) + __pp = __pp->__next_; + __cp->__next_ = __np; + __pp->__next_ = static_cast<__next_pointer>(__cp); + ++size(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(static_cast<__next_pointer>(__cp), this); +#else + return iterator(static_cast<__next_pointer>(__cp)); +#endif + } + return __node_insert_multi(__cp); +} + + + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key, class ..._Args> +pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) +#else +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key, class _Args> +pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args) +#endif +{ + + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + bool __inserted = false; + __next_pointer __nd; + size_t __chash; + if (__bc != 0) + { + __chash = __constrain_hash(__hash, __bc); + __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash); + __nd = __nd->__next_) + { + if (key_eq()(__nd->__upcast()->__value_, __k)) + goto __done; + } + } + } + { +#ifndef _LIBCPP_CXX03_LANG + __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...); +#else + __node_holder __h = __construct_node_hash(__hash, __args); +#endif + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + __chash = __constrain_hash(__hash, __bc); + } + // insert_after __bucket_list_[__chash], or __first_node if bucket is null + __next_pointer __pn = __bucket_list_[__chash]; + if (__pn == nullptr) + { + __pn = __p1_.first().__ptr(); + __h->__next_ = __pn->__next_; + __pn->__next_ = __h.get()->__ptr(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__h->__next_ != nullptr) + __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)] + = __h.get()->__ptr(); + } + else + { + __h->__next_ = __pn->__next_; + __pn->__next_ = static_cast<__next_pointer>(__h.get()); + } + __nd = static_cast<__next_pointer>(__h.release()); + // increment size + ++size(); + __inserted = true; + } +__done: +#if _LIBCPP_DEBUG_LEVEL >= 2 + return pair<iterator, bool>(iterator(__nd, this), __inserted); +#else + return pair<iterator, bool>(iterator(__nd), __inserted); +#endif +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class... _Args> +pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + pair<iterator, bool> __r = __node_insert_unique(__h.get()); + if (__r.second) + __h.release(); + return __r; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class... _Args> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + iterator __r = __node_insert_multi(__h.get()); + __h.release(); + return __r; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class... _Args> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi( + const_iterator __p, _Args&&... __args) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered container"); +#endif + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + iterator __r = __node_insert_multi(__p, __h.get()); + __h.release(); + return __r; +} + +#else // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x) +{ + __node_holder __h = __construct_node(__x); + iterator __r = __node_insert_multi(__h.get()); + __h.release(); + return __r; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p, + const __container_value_type& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::insert(const_iterator, lvalue) called with an iterator not" + " referring to this unordered container"); +#endif + __node_holder __h = __construct_node(__x); + iterator __r = __node_insert_multi(__p, __h.get()); + __h.release(); + return __r; +} + +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 14 +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _NodeHandle, class _InsertReturnType> +_LIBCPP_INLINE_VISIBILITY +_InsertReturnType +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( + _NodeHandle&& __nh) +{ + if (__nh.empty()) + return _InsertReturnType{end(), false, _NodeHandle()}; + pair<iterator, bool> __result = __node_insert_unique(__nh.__ptr_); + if (__result.second) + __nh.__release(); + return _InsertReturnType{__result.first, __result.second, _VSTD::move(__nh)}; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( + const_iterator, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + pair<iterator, bool> __result = __node_insert_unique(__nh.__ptr_); + if (__result.second) + __nh.__release(); + return __result.first; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +_NodeHandle +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract( + key_type const& __key) +{ + iterator __i = find(__key); + if (__i == end()) + return _NodeHandle(); + return __node_handle_extract<_NodeHandle>(__i); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +_NodeHandle +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract( + const_iterator __p) +{ + allocator_type __alloc(__node_alloc()); + return _NodeHandle(remove(__p).release(), __alloc); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Table> +_LIBCPP_INLINE_VISIBILITY +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_unique( + _Table& __source) +{ + static_assert(is_same<__node, typename _Table::__node>::value, ""); + + for (typename _Table::iterator __it = __source.begin(); + __it != __source.end();) + { + __node_pointer __src_ptr = __it.__node_->__upcast(); + size_t __hash = hash_function()(__src_ptr->__value_); + __next_pointer __existing_node = + __node_insert_unique_prepare(__hash, __src_ptr->__value_); + auto __prev_iter = __it++; + if (__existing_node == nullptr) + { + (void)__source.remove(__prev_iter).release(); + __src_ptr->__hash_ = __hash; + __node_insert_unique_perform(__src_ptr); + } + } +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( + _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + iterator __result = __node_insert_multi(__nh.__ptr_); + __nh.__release(); + return __result; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( + const_iterator __hint, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + iterator __result = __node_insert_multi(__hint, __nh.__ptr_); + __nh.__release(); + return __result; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Table> +_LIBCPP_INLINE_VISIBILITY +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_multi( + _Table& __source) +{ + static_assert(is_same<typename _Table::__node, __node>::value, ""); + + for (typename _Table::iterator __it = __source.begin(); + __it != __source.end();) + { + __node_pointer __src_ptr = __it.__node_->__upcast(); + size_t __src_hash = hash_function()(__src_ptr->__value_); + __next_pointer __pn = + __node_insert_multi_prepare(__src_hash, __src_ptr->__value_); + (void)__source.remove(__it++).release(); + __src_ptr->__hash_ = __src_hash; + __node_insert_multi_perform(__src_ptr, __pn); + } +} +#endif // _LIBCPP_STD_VER > 14 + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n) +_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ + if (__n == 1) + __n = 2; + else if (__n & (__n - 1)) + __n = __next_prime(__n); + size_type __bc = bucket_count(); + if (__n > __bc) + __rehash(__n); + else if (__n < __bc) + { + __n = _VSTD::max<size_type> + ( + __n, + __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) : + __next_prime(size_t(ceil(float(size()) / max_load_factor()))) + ); + if (__n < __bc) + __rehash(__n); + } +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); + __bucket_list_.reset(__nbc > 0 ? + __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); + __bucket_list_.get_deleter().size() = __nbc; + if (__nbc > 0) + { + for (size_type __i = 0; __i < __nbc; ++__i) + __bucket_list_[__i] = nullptr; + __next_pointer __pp = __p1_.first().__ptr(); + __next_pointer __cp = __pp->__next_; + if (__cp != nullptr) + { + size_type __chash = __constrain_hash(__cp->__hash(), __nbc); + __bucket_list_[__chash] = __pp; + size_type __phash = __chash; + for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr; + __cp = __pp->__next_) + { + __chash = __constrain_hash(__cp->__hash(), __nbc); + if (__chash == __phash) + __pp = __cp; + else + { + if (__bucket_list_[__chash] == nullptr) + { + __bucket_list_[__chash] = __pp; + __pp = __cp; + __phash = __chash; + } + else + { + __next_pointer __np = __cp; + for (; __np->__next_ != nullptr && + key_eq()(__cp->__upcast()->__value_, + __np->__next_->__upcast()->__value_); + __np = __np->__next_) + ; + __pp->__next_ = __np->__next_; + __np->__next_ = __bucket_list_[__chash]->__next_; + __bucket_list_[__chash]->__next_ = __cp; + + } + } + } + } + } +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) +{ + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + if (__bc != 0) + { + size_t __chash = __constrain_hash(__hash, __bc); + __next_pointer __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + (__nd->__hash() == __hash + || __constrain_hash(__nd->__hash(), __bc) == __chash); + __nd = __nd->__next_) + { + if ((__nd->__hash() == __hash) + && key_eq()(__nd->__upcast()->__value_, __k)) +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__nd, this); +#else + return iterator(__nd); +#endif + } + } + } + return end(); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const +{ + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + if (__bc != 0) + { + size_t __chash = __constrain_hash(__hash, __bc); + __next_pointer __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + (__hash == __nd->__hash() + || __constrain_hash(__nd->__hash(), __bc) == __chash); + __nd = __nd->__next_) + { + if ((__nd->__hash() == __hash) + && key_eq()(__nd->__upcast()->__value_, __k)) +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(__nd, this); +#else + return const_iterator(__nd); +#endif + } + } + + } + return end(); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class ..._Args> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args) +{ + static_assert(!__is_hash_value_type<_Args...>::value, + "Construct cannot be called with a hash value type"); + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = hash_function()(__h->__value_); + __h->__next_ = nullptr; + return __h; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _First, class ..._Rest> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash( + size_t __hash, _First&& __f, _Rest&& ...__rest) +{ + static_assert(!__is_hash_value_type<_First, _Rest...>::value, + "Construct cannot be called with a hash value type"); + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), + _VSTD::forward<_First>(__f), + _VSTD::forward<_Rest>(__rest)...); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = __hash; + __h->__next_ = nullptr; + return __h; +} + +#else // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = hash_function()(__h->__value_); + __h->__next_ = nullptr; + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash, + const __container_value_type& __v) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = __hash; + __h->__next_ = nullptr; + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) +{ + __next_pointer __np = __p.__node_; +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container erase(iterator) called with an iterator not" + " referring to this container"); + _LIBCPP_ASSERT(__p != end(), + "unordered container erase(iterator) called with a non-dereferenceable iterator"); + iterator __r(__np, this); +#else + iterator __r(__np); +#endif + ++__r; + remove(__p); + return __r; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, + const_iterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, + "unodered container::erase(iterator, iterator) called with an iterator not" + " referring to this unodered container"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, + "unodered container::erase(iterator, iterator) called with an iterator not" + " referring to this unodered container"); +#endif + for (const_iterator __p = __first; __first != __last; __p = __first) + { + ++__first; + erase(__p); + } + __next_pointer __np = __last.__node_; +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator (__np, this); +#else + return iterator (__np); +#endif +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k) +{ + iterator __i = find(__k); + if (__i == end()) + return 0; + erase(__i); + return 1; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k) +{ + size_type __r = 0; + iterator __i = find(__k); + if (__i != end()) + { + iterator __e = end(); + do + { + erase(__i++); + ++__r; + } while (__i != __e && key_eq()(*__i, __k)); + } + return __r; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT +{ + // current node + __next_pointer __cn = __p.__node_; + size_type __bc = bucket_count(); + size_t __chash = __constrain_hash(__cn->__hash(), __bc); + // find previous node + __next_pointer __pn = __bucket_list_[__chash]; + for (; __pn->__next_ != __cn; __pn = __pn->__next_) + ; + // Fix up __bucket_list_ + // if __pn is not in same bucket (before begin is not in same bucket) && + // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) + if (__pn == __p1_.first().__ptr() + || __constrain_hash(__pn->__hash(), __bc) != __chash) + { + if (__cn->__next_ == nullptr + || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash) + __bucket_list_[__chash] = nullptr; + } + // if __cn->__next_ is not in same bucket (nullptr is in same bucket) + if (__cn->__next_ != nullptr) + { + size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc); + if (__nhash != __chash) + __bucket_list_[__nhash] = __pn; + } + // remove __cn + __pn->__next_ = __cn->__next_; + __cn->__next_ = nullptr; + --size(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __dp = __c->end_; __dp != __c->beg_; ) + { + --__dp; + iterator* __i = static_cast<iterator*>((*__dp)->__i_); + if (__i->__node_ == __cn) + { + (*__dp)->__c_ = nullptr; + if (--__c->end_ != __dp) + memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true)); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +inline +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const +{ + return static_cast<size_type>(find(__k) != end()); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const +{ + size_type __r = 0; + const_iterator __i = find(__k); + if (__i != end()) + { + const_iterator __e = end(); + do + { + ++__i; + ++__r; + } while (__i != __e && key_eq()(*__i, __k)); + } + return __r; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( + const _Key& __k) +{ + iterator __i = find(__k); + iterator __j = __i; + if (__i != end()) + ++__j; + return pair<iterator, iterator>(__i, __j); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( + const _Key& __k) const +{ + const_iterator __i = find(__k); + const_iterator __j = __i; + if (__i != end()) + ++__j; + return pair<const_iterator, const_iterator>(__i, __j); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( + const _Key& __k) +{ + iterator __i = find(__k); + iterator __j = __i; + if (__i != end()) + { + iterator __e = end(); + do + { + ++__j; + } while (__j != __e && key_eq()(*__j, __k)); + } + return pair<iterator, iterator>(__i, __j); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +template <class _Key> +pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( + const _Key& __k) const +{ + const_iterator __i = find(__k); + const_iterator __j = __i; + if (__i != end()) + { + const_iterator __e = end(); + do + { + ++__j; + } while (__j != __e && key_eq()(*__j, __k)); + } + return pair<const_iterator, const_iterator>(__i, __j); +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) +#if _LIBCPP_STD_VER <= 11 + _NOEXCEPT_( + __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value + && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value + || __is_nothrow_swappable<__pointer_allocator>::value) + && (!__node_traits::propagate_on_container_swap::value + || __is_nothrow_swappable<__node_allocator>::value) + ) +#else + _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value) +#endif +{ + _LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value || + this->__node_alloc() == __u.__node_alloc(), + "list::swap: Either propagate_on_container_swap must be true" + " or the allocators must compare equal"); + { + __node_pointer_pointer __npp = __bucket_list_.release(); + __bucket_list_.reset(__u.__bucket_list_.release()); + __u.__bucket_list_.reset(__npp); + } + _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); + __swap_allocator(__bucket_list_.get_deleter().__alloc(), + __u.__bucket_list_.get_deleter().__alloc()); + __swap_allocator(__node_alloc(), __u.__node_alloc()); + _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_); + __p2_.swap(__u.__p2_); + __p3_.swap(__u.__p3_); + if (size() > 0) + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); + if (__u.size() > 0) + __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = + __u.__p1_.first().__ptr(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->swap(this, &__u); +#endif +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const +{ + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::bucket_size(n) called with n >= bucket_count()"); + __next_pointer __np = __bucket_list_[__n]; + size_type __bc = bucket_count(); + size_type __r = 0; + if (__np != nullptr) + { + for (__np = __np->__next_; __np != nullptr && + __constrain_hash(__np->__hash(), __bc) == __n; + __np = __np->__next_, ++__r) + ; + } + return __r; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, + __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const +{ + return __i->__node_ != nullptr; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const +{ + return false; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP__HASH_TABLE diff --git a/android/x86/include/v8/libc++/__libcpp_version b/android/x86/include/v8/libc++/__libcpp_version new file mode 100755 index 00000000..d58c55a3 --- /dev/null +++ b/android/x86/include/v8/libc++/__libcpp_version @@ -0,0 +1 @@ +9000 diff --git a/android/x86/include/v8/libc++/__locale b/android/x86/include/v8/libc++/__locale new file mode 100755 index 00000000..d9d2682c --- /dev/null +++ b/android/x86/include/v8/libc++/__locale @@ -0,0 +1,1537 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE +#define _LIBCPP___LOCALE + +#include <__config> +#include <string> +#include <memory> +#include <utility> +#include <mutex> +#include <cstdint> +#include <cctype> +#include <locale.h> +#if defined(_LIBCPP_MSVCRT_LIKE) +# include <cstring> +# include <support/win32/locale_win32.h> +#elif defined(_AIX) +# include <support/ibm/xlocale.h> +#elif defined(__ANDROID__) +# include <support/android/locale_bionic.h> +#elif defined(__sun__) +# include <xlocale.h> +# include <support/solaris/xlocale.h> +#elif defined(_NEWLIB_VERSION) +# include <support/newlib/xlocale.h> +#elif (defined(__APPLE__) || defined(__FreeBSD__) \ + || defined(__EMSCRIPTEN__) || defined(__IBMCPP__)) +# include <xlocale.h> +#elif defined(__Fuchsia__) +# include <support/fuchsia/xlocale.h> +#elif defined(_LIBCPP_HAS_MUSL_LIBC) +# include <support/musl/xlocale.h> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) +struct __libcpp_locale_guard { + _LIBCPP_INLINE_VISIBILITY + __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {} + + _LIBCPP_INLINE_VISIBILITY + ~__libcpp_locale_guard() { + if (__old_loc_) + uselocale(__old_loc_); + } + + locale_t __old_loc_; +private: + __libcpp_locale_guard(__libcpp_locale_guard const&); + __libcpp_locale_guard& operator=(__libcpp_locale_guard const&); +}; +#elif defined(_LIBCPP_MSVCRT_LIKE) +struct __libcpp_locale_guard { + __libcpp_locale_guard(locale_t __l) : + __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) { + // Setting the locale can be expensive even when the locale given is + // already the current locale, so do an explicit check to see if the + // current locale is already the one we want. + const char* __lc = __setlocale(nullptr); + // If every category is the same, the locale string will simply be the + // locale name, otherwise it will be a semicolon-separated string listing + // each category. In the second case, we know at least one category won't + // be what we want, so we only have to check the first case. + if (strcmp(__l.__get_locale(), __lc) != 0) { + __locale_all = _strdup(__lc); + if (__locale_all == nullptr) + __throw_bad_alloc(); + __setlocale(__l.__get_locale()); + } + } + ~__libcpp_locale_guard() { + // The CRT documentation doesn't explicitly say, but setlocale() does the + // right thing when given a semicolon-separated list of locale settings + // for the different categories in the same format as returned by + // setlocale(LC_ALL, nullptr). + if (__locale_all != nullptr) { + __setlocale(__locale_all); + free(__locale_all); + } + _configthreadlocale(__status); + } + static const char* __setlocale(const char* __locale) { + const char* __new_locale = setlocale(LC_ALL, __locale); + if (__new_locale == nullptr) + __throw_bad_alloc(); + return __new_locale; + } + int __status; + char* __locale_all = nullptr; +}; +#endif + + +class _LIBCPP_TYPE_VIS locale; + +template <class _Facet> +_LIBCPP_INLINE_VISIBILITY +bool +has_facet(const locale&) _NOEXCEPT; + +template <class _Facet> +_LIBCPP_INLINE_VISIBILITY +const _Facet& +use_facet(const locale&); + +class _LIBCPP_TYPE_VIS locale +{ +public: + // types: + class _LIBCPP_TYPE_VIS facet; + class _LIBCPP_TYPE_VIS id; + + typedef int category; + _LIBCPP_AVAILABILITY_LOCALE_CATEGORY + static const category // values assigned here are for exposition only + none = 0, + collate = LC_COLLATE_MASK, + ctype = LC_CTYPE_MASK, + monetary = LC_MONETARY_MASK, + numeric = LC_NUMERIC_MASK, + time = LC_TIME_MASK, + messages = LC_MESSAGES_MASK, + all = collate | ctype | monetary | numeric | time | messages; + + // construct/copy/destroy: + locale() _NOEXCEPT; + locale(const locale&) _NOEXCEPT; + explicit locale(const char*); + explicit locale(const string&); + locale(const locale&, const char*, category); + locale(const locale&, const string&, category); + template <class _Facet> + _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*); + locale(const locale&, const locale&, category); + + ~locale(); + + const locale& operator=(const locale&) _NOEXCEPT; + + template <class _Facet> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + locale combine(const locale&) const; + + // locale operations: + string name() const; + bool operator==(const locale&) const; + bool operator!=(const locale& __y) const {return !(*this == __y);} + template <class _CharT, class _Traits, class _Allocator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + bool operator()(const basic_string<_CharT, _Traits, _Allocator>&, + const basic_string<_CharT, _Traits, _Allocator>&) const; + + // global locale objects: + static locale global(const locale&); + static const locale& classic(); + +private: + class __imp; + __imp* __locale_; + + void __install_ctor(const locale&, facet*, long); + static locale& __global(); + bool has_facet(id&) const; + const facet* use_facet(id&) const; + + template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT; + template <class _Facet> friend const _Facet& use_facet(const locale&); +}; + +class _LIBCPP_TYPE_VIS locale::facet + : public __shared_count +{ +protected: + _LIBCPP_INLINE_VISIBILITY + explicit facet(size_t __refs = 0) + : __shared_count(static_cast<long>(__refs)-1) {} + + virtual ~facet(); + +// facet(const facet&) = delete; // effectively done in __shared_count +// void operator=(const facet&) = delete; +private: + virtual void __on_zero_shared() _NOEXCEPT; +}; + +class _LIBCPP_TYPE_VIS locale::id +{ + once_flag __flag_; + int32_t __id_; + + static int32_t __next_id; +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {} +private: + void __init(); + void operator=(const id&); // = delete; + id(const id&); // = delete; +public: // only needed for tests + long __get(); + + friend class locale; + friend class locale::__imp; +}; + +template <class _Facet> +inline _LIBCPP_INLINE_VISIBILITY +locale::locale(const locale& __other, _Facet* __f) +{ + __install_ctor(__other, __f, __f ? __f->id.__get() : 0); +} + +template <class _Facet> +locale +locale::combine(const locale& __other) const +{ + if (!_VSTD::has_facet<_Facet>(__other)) + __throw_runtime_error("locale::combine: locale missing facet"); + + return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other))); +} + +template <class _Facet> +inline _LIBCPP_INLINE_VISIBILITY +bool +has_facet(const locale& __l) _NOEXCEPT +{ + return __l.has_facet(_Facet::id); +} + +template <class _Facet> +inline _LIBCPP_INLINE_VISIBILITY +const _Facet& +use_facet(const locale& __l) +{ + return static_cast<const _Facet&>(*__l.use_facet(_Facet::id)); +} + +// template <class _CharT> class collate; + +template <class _CharT> +class _LIBCPP_TEMPLATE_VIS collate + : public locale::facet +{ +public: + typedef _CharT char_type; + typedef basic_string<char_type> string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit collate(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + int compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const + { + return do_compare(__lo1, __hi1, __lo2, __hi2); + } + + // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work + // around a dllimport bug that expects an external instantiation. + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_ALWAYS_INLINE + string_type transform(const char_type* __lo, const char_type* __hi) const + { + return do_transform(__lo, __hi); + } + + _LIBCPP_INLINE_VISIBILITY + long hash(const char_type* __lo, const char_type* __hi) const + { + return do_hash(__lo, __hi); + } + + static locale::id id; + +protected: + ~collate(); + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const + {return string_type(__lo, __hi);} + virtual long do_hash(const char_type* __lo, const char_type* __hi) const; +}; + +template <class _CharT> locale::id collate<_CharT>::id; + +template <class _CharT> +collate<_CharT>::~collate() +{ +} + +template <class _CharT> +int +collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const +{ + for (; __lo2 != __hi2; ++__lo1, ++__lo2) + { + if (__lo1 == __hi1 || *__lo1 < *__lo2) + return -1; + if (*__lo2 < *__lo1) + return 1; + } + return __lo1 != __hi1; +} + +template <class _CharT> +long +collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const +{ + size_t __h = 0; + const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8; + const size_t __mask = size_t(0xF) << (__sr + 4); + for(const char_type* __p = __lo; __p != __hi; ++__p) + { + __h = (__h << 4) + static_cast<size_t>(*__p); + size_t __g = __h & __mask; + __h ^= __g | (__g >> __sr); + } + return static_cast<long>(__h); +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>) + +// template <class CharT> class collate_byname; + +template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname; + +template <> +class _LIBCPP_TYPE_VIS collate_byname<char> + : public collate<char> +{ + locale_t __l; +public: + typedef char char_type; + typedef basic_string<char_type> string_type; + + explicit collate_byname(const char* __n, size_t __refs = 0); + explicit collate_byname(const string& __n, size_t __refs = 0); + +protected: + ~collate_byname(); + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; +}; + +template <> +class _LIBCPP_TYPE_VIS collate_byname<wchar_t> + : public collate<wchar_t> +{ + locale_t __l; +public: + typedef wchar_t char_type; + typedef basic_string<char_type> string_type; + + explicit collate_byname(const char* __n, size_t __refs = 0); + explicit collate_byname(const string& __n, size_t __refs = 0); + +protected: + ~collate_byname(); + + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; +}; + +template <class _CharT, class _Traits, class _Allocator> +bool +locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, + const basic_string<_CharT, _Traits, _Allocator>& __y) const +{ + return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare( + __x.data(), __x.data() + __x.size(), + __y.data(), __y.data() + __y.size()) < 0; +} + +// template <class charT> class ctype + +class _LIBCPP_TYPE_VIS ctype_base +{ +public: +#if defined(__GLIBC__) + typedef unsigned short mask; + static const mask space = _ISspace; + static const mask print = _ISprint; + static const mask cntrl = _IScntrl; + static const mask upper = _ISupper; + static const mask lower = _ISlower; + static const mask alpha = _ISalpha; + static const mask digit = _ISdigit; + static const mask punct = _ISpunct; + static const mask xdigit = _ISxdigit; + static const mask blank = _ISblank; +#elif defined(_LIBCPP_MSVCRT_LIKE) + typedef unsigned short mask; + static const mask space = _SPACE; + static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT; + static const mask cntrl = _CONTROL; + static const mask upper = _UPPER; + static const mask lower = _LOWER; + static const mask alpha = _ALPHA; + static const mask digit = _DIGIT; + static const mask punct = _PUNCT; + static const mask xdigit = _HEX; + static const mask blank = _BLANK; +# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) +# ifdef __APPLE__ + typedef __uint32_t mask; +# elif defined(__FreeBSD__) + typedef unsigned long mask; +# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__) + typedef unsigned short mask; +# endif + static const mask space = _CTYPE_S; + static const mask print = _CTYPE_R; + static const mask cntrl = _CTYPE_C; + static const mask upper = _CTYPE_U; + static const mask lower = _CTYPE_L; + static const mask alpha = _CTYPE_A; + static const mask digit = _CTYPE_D; + static const mask punct = _CTYPE_P; + static const mask xdigit = _CTYPE_X; + +# if defined(__NetBSD__) + static const mask blank = _CTYPE_BL; +# else + static const mask blank = _CTYPE_B; +# endif +#elif defined(__sun__) || defined(_AIX) + typedef unsigned int mask; + static const mask space = _ISSPACE; + static const mask print = _ISPRINT; + static const mask cntrl = _ISCNTRL; + static const mask upper = _ISUPPER; + static const mask lower = _ISLOWER; + static const mask alpha = _ISALPHA; + static const mask digit = _ISDIGIT; + static const mask punct = _ISPUNCT; + static const mask xdigit = _ISXDIGIT; + static const mask blank = _ISBLANK; +#elif defined(_NEWLIB_VERSION) + // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. + typedef char mask; + static const mask space = _S; + static const mask print = _P | _U | _L | _N | _B; + static const mask cntrl = _C; + static const mask upper = _U; + static const mask lower = _L; + static const mask alpha = _U | _L; + static const mask digit = _N; + static const mask punct = _P; + static const mask xdigit = _X | _N; + static const mask blank = _B; +# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT +# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA +# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT +#else + typedef unsigned long mask; + static const mask space = 1<<0; + static const mask print = 1<<1; + static const mask cntrl = 1<<2; + static const mask upper = 1<<3; + static const mask lower = 1<<4; + static const mask alpha = 1<<5; + static const mask digit = 1<<6; + static const mask punct = 1<<7; + static const mask xdigit = 1<<8; + static const mask blank = 1<<9; +#endif + static const mask alnum = alpha | digit; + static const mask graph = alnum | punct; + + _LIBCPP_INLINE_VISIBILITY ctype_base() {} +}; + +template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype; + +template <> +class _LIBCPP_TYPE_VIS ctype<wchar_t> + : public locale::facet, + public ctype_base +{ +public: + typedef wchar_t char_type; + + _LIBCPP_INLINE_VISIBILITY + explicit ctype(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + bool is(mask __m, char_type __c) const + { + return do_is(__m, __c); + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const + { + return do_is(__low, __high, __vec); + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const + { + return do_scan_is(__m, __low, __high); + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const + { + return do_scan_not(__m, __low, __high); + } + + _LIBCPP_INLINE_VISIBILITY + char_type toupper(char_type __c) const + { + return do_toupper(__c); + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* toupper(char_type* __low, const char_type* __high) const + { + return do_toupper(__low, __high); + } + + _LIBCPP_INLINE_VISIBILITY + char_type tolower(char_type __c) const + { + return do_tolower(__c); + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* tolower(char_type* __low, const char_type* __high) const + { + return do_tolower(__low, __high); + } + + _LIBCPP_INLINE_VISIBILITY + char_type widen(char __c) const + { + return do_widen(__c); + } + + _LIBCPP_INLINE_VISIBILITY + const char* widen(const char* __low, const char* __high, char_type* __to) const + { + return do_widen(__low, __high, __to); + } + + _LIBCPP_INLINE_VISIBILITY + char narrow(char_type __c, char __dfault) const + { + return do_narrow(__c, __dfault); + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const + { + return do_narrow(__low, __high, __dfault, __to); + } + + static locale::id id; + +protected: + ~ctype(); + virtual bool do_is(mask __m, char_type __c) const; + virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; + virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; + virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; + virtual char do_narrow(char_type, char __dfault) const; + virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; +}; + +template <> +class _LIBCPP_TYPE_VIS ctype<char> + : public locale::facet, public ctype_base +{ + const mask* __tab_; + bool __del_; +public: + typedef char char_type; + + explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0); + + _LIBCPP_INLINE_VISIBILITY + bool is(mask __m, char_type __c) const + { + return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false; + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const + { + for (; __low != __high; ++__low, ++__vec) + *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0; + return __low; + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const + { + for (; __low != __high; ++__low) + if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)) + break; + return __low; + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const + { + for (; __low != __high; ++__low) + if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))) + break; + return __low; + } + + _LIBCPP_INLINE_VISIBILITY + char_type toupper(char_type __c) const + { + return do_toupper(__c); + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* toupper(char_type* __low, const char_type* __high) const + { + return do_toupper(__low, __high); + } + + _LIBCPP_INLINE_VISIBILITY + char_type tolower(char_type __c) const + { + return do_tolower(__c); + } + + _LIBCPP_INLINE_VISIBILITY + const char_type* tolower(char_type* __low, const char_type* __high) const + { + return do_tolower(__low, __high); + } + + _LIBCPP_INLINE_VISIBILITY + char_type widen(char __c) const + { + return do_widen(__c); + } + + _LIBCPP_INLINE_VISIBILITY + const char* widen(const char* __low, const char* __high, char_type* __to) const + { + return do_widen(__low, __high, __to); + } + + _LIBCPP_INLINE_VISIBILITY + char narrow(char_type __c, char __dfault) const + { + return do_narrow(__c, __dfault); + } + + _LIBCPP_INLINE_VISIBILITY + const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const + { + return do_narrow(__low, __high, __dfault, __to); + } + + static locale::id id; + +#ifdef _CACHED_RUNES + static const size_t table_size = _CACHED_RUNES; +#else + static const size_t table_size = 256; // FIXME: Don't hardcode this. +#endif + _LIBCPP_INLINE_VISIBILITY const mask* table() const _NOEXCEPT {return __tab_;} + static const mask* classic_table() _NOEXCEPT; +#if defined(__GLIBC__) || defined(__EMSCRIPTEN__) + static const int* __classic_upper_table() _NOEXCEPT; + static const int* __classic_lower_table() _NOEXCEPT; +#endif +#if defined(__NetBSD__) + static const short* __classic_upper_table() _NOEXCEPT; + static const short* __classic_lower_table() _NOEXCEPT; +#endif + +protected: + ~ctype(); + virtual char_type do_toupper(char_type __c) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type __c) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char __c) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; + virtual char do_narrow(char_type __c, char __dfault) const; + virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const; +}; + +// template <class CharT> class ctype_byname; + +template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname; + +template <> +class _LIBCPP_TYPE_VIS ctype_byname<char> + : public ctype<char> +{ + locale_t __l; + +public: + explicit ctype_byname(const char*, size_t = 0); + explicit ctype_byname(const string&, size_t = 0); + +protected: + ~ctype_byname(); + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; +}; + +template <> +class _LIBCPP_TYPE_VIS ctype_byname<wchar_t> + : public ctype<wchar_t> +{ + locale_t __l; + +public: + explicit ctype_byname(const char*, size_t = 0); + explicit ctype_byname(const string&, size_t = 0); + +protected: + ~ctype_byname(); + virtual bool do_is(mask __m, char_type __c) const; + virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; + virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; + virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; + virtual char do_narrow(char_type, char __dfault) const; + virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; +}; + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +isspace(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +isprint(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +iscntrl(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +isupper(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +islower(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +isalpha(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +isdigit(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +ispunct(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +isxdigit(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +isalnum(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +bool +isgraph(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +_CharT +toupper(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).toupper(__c); +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +_CharT +tolower(_CharT __c, const locale& __loc) +{ + return use_facet<ctype<_CharT> >(__loc).tolower(__c); +} + +// codecvt_base + +class _LIBCPP_TYPE_VIS codecvt_base +{ +public: + _LIBCPP_INLINE_VISIBILITY codecvt_base() {} + enum result {ok, partial, error, noconv}; +}; + +// template <class internT, class externT, class stateT> class codecvt; + +template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt; + +// template <> class codecvt<char, char, mbstate_t> + +template <> +class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t> + : public locale::facet, + public codecvt_base +{ +public: + typedef char intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCPP_INLINE_VISIBILITY + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCPP_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCPP_INLINE_VISIBILITY + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCPP_INLINE_VISIBILITY + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <> class codecvt<wchar_t, char, mbstate_t> + +template <> +class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t> + : public locale::facet, + public codecvt_base +{ + locale_t __l; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + explicit codecvt(size_t __refs = 0); + + _LIBCPP_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCPP_INLINE_VISIBILITY + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCPP_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCPP_INLINE_VISIBILITY + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + explicit codecvt(const char*, size_t __refs = 0); + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <> class codecvt<char16_t, char, mbstate_t> + +template <> +class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t> + : public locale::facet, + public codecvt_base +{ +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCPP_INLINE_VISIBILITY + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCPP_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCPP_INLINE_VISIBILITY + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCPP_INLINE_VISIBILITY + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <> class codecvt<char32_t, char, mbstate_t> + +template <> +class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t> + : public locale::facet, + public codecvt_base +{ +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_INLINE_VISIBILITY + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCPP_INLINE_VISIBILITY + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCPP_INLINE_VISIBILITY + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCPP_INLINE_VISIBILITY + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCPP_INLINE_VISIBILITY + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname + +template <class _InternT, class _ExternT, class _StateT> +class _LIBCPP_TEMPLATE_VIS codecvt_byname + : public codecvt<_InternT, _ExternT, _StateT> +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit codecvt_byname(const char* __nm, size_t __refs = 0) + : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {} + _LIBCPP_INLINE_VISIBILITY + explicit codecvt_byname(const string& __nm, size_t __refs = 0) + : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {} +protected: + ~codecvt_byname(); +}; + +template <class _InternT, class _ExternT, class _StateT> +codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() +{ +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>) + +template <size_t _Np> +struct __narrow_to_utf8 +{ + template <class _OutputIterator, class _CharT> + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const; +}; + +template <> +struct __narrow_to_utf8<8> +{ + template <class _OutputIterator, class _CharT> + _LIBCPP_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + for (; __wb < __we; ++__wb, ++__s) + *__s = *__wb; + return __s; + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<16> + : public codecvt<char16_t, char, mbstate_t> +{ + _LIBCPP_INLINE_VISIBILITY + __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {} + + _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8(); + + template <class _OutputIterator, class _CharT> + _LIBCPP_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + result __r = ok; + mbstate_t __mb; + while (__wb < __we && __r != error) + { + const int __sz = 32; + char __buf[__sz]; + char* __bn; + const char16_t* __wn = (const char16_t*)__wb; + __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __wn == (const char16_t*)__wb) + __throw_runtime_error("locale not supported"); + for (const char* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = *__p; + __wb = (const _CharT*)__wn; + } + return __s; + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<32> + : public codecvt<char32_t, char, mbstate_t> +{ + _LIBCPP_INLINE_VISIBILITY + __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {} + + _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8(); + + template <class _OutputIterator, class _CharT> + _LIBCPP_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + result __r = ok; + mbstate_t __mb; + while (__wb < __we && __r != error) + { + const int __sz = 32; + char __buf[__sz]; + char* __bn; + const char32_t* __wn = (const char32_t*)__wb; + __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __wn == (const char32_t*)__wb) + __throw_runtime_error("locale not supported"); + for (const char* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = *__p; + __wb = (const _CharT*)__wn; + } + return __s; + } +}; + +template <size_t _Np> +struct __widen_from_utf8 +{ + template <class _OutputIterator> + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const; +}; + +template <> +struct __widen_from_utf8<8> +{ + template <class _OutputIterator> + _LIBCPP_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + for (; __nb < __ne; ++__nb, ++__s) + *__s = *__nb; + return __s; + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<16> + : public codecvt<char16_t, char, mbstate_t> +{ + _LIBCPP_INLINE_VISIBILITY + __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {} + + _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8(); + + template <class _OutputIterator> + _LIBCPP_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + result __r = ok; + mbstate_t __mb; + while (__nb < __ne && __r != error) + { + const int __sz = 32; + char16_t __buf[__sz]; + char16_t* __bn; + const char* __nn = __nb; + __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __nn == __nb) + __throw_runtime_error("locale not supported"); + for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = (wchar_t)*__p; + __nb = __nn; + } + return __s; + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<32> + : public codecvt<char32_t, char, mbstate_t> +{ + _LIBCPP_INLINE_VISIBILITY + __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {} + + _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8(); + + template <class _OutputIterator> + _LIBCPP_INLINE_VISIBILITY + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + result __r = ok; + mbstate_t __mb; + while (__nb < __ne && __r != error) + { + const int __sz = 32; + char32_t __buf[__sz]; + char32_t* __bn; + const char* __nn = __nb; + __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __nn == __nb) + __throw_runtime_error("locale not supported"); + for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = (wchar_t)*__p; + __nb = __nn; + } + return __s; + } +}; + +// template <class charT> class numpunct + +template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct; + +template <> +class _LIBCPP_TYPE_VIS numpunct<char> + : public locale::facet +{ +public: + typedef char char_type; + typedef basic_string<char_type> string_type; + + explicit numpunct(size_t __refs = 0); + + _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();} + _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();} + _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();} + _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();} + _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();} + + static locale::id id; + +protected: + ~numpunct(); + virtual char_type do_decimal_point() const; + virtual char_type do_thousands_sep() const; + virtual string do_grouping() const; + virtual string_type do_truename() const; + virtual string_type do_falsename() const; + + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; +}; + +template <> +class _LIBCPP_TYPE_VIS numpunct<wchar_t> + : public locale::facet +{ +public: + typedef wchar_t char_type; + typedef basic_string<char_type> string_type; + + explicit numpunct(size_t __refs = 0); + + _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();} + _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();} + _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();} + _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();} + _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();} + + static locale::id id; + +protected: + ~numpunct(); + virtual char_type do_decimal_point() const; + virtual char_type do_thousands_sep() const; + virtual string do_grouping() const; + virtual string_type do_truename() const; + virtual string_type do_falsename() const; + + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; +}; + +// template <class charT> class numpunct_byname + +template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname; + +template <> +class _LIBCPP_TYPE_VIS numpunct_byname<char> +: public numpunct<char> +{ +public: + typedef char char_type; + typedef basic_string<char_type> string_type; + + explicit numpunct_byname(const char* __nm, size_t __refs = 0); + explicit numpunct_byname(const string& __nm, size_t __refs = 0); + +protected: + ~numpunct_byname(); + +private: + void __init(const char*); +}; + +template <> +class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t> +: public numpunct<wchar_t> +{ +public: + typedef wchar_t char_type; + typedef basic_string<char_type> string_type; + + explicit numpunct_byname(const char* __nm, size_t __refs = 0); + explicit numpunct_byname(const string& __nm, size_t __refs = 0); + +protected: + ~numpunct_byname(); + +private: + void __init(const char*); +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___LOCALE diff --git a/android/x86/include/v8/libc++/__mutex_base b/android/x86/include/v8/libc++/__mutex_base new file mode 100755 index 00000000..008be959 --- /dev/null +++ b/android/x86/include/v8/libc++/__mutex_base @@ -0,0 +1,439 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MUTEX_BASE +#define _LIBCPP___MUTEX_BASE + +#include <__config> +#include <chrono> +#include <system_error> +#include <__threading_support> + + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_HAS_NO_THREADS + +#ifndef _LIBCPP_THREAD_SAFETY_ANNOTATION +# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS +# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) +# else +# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) +# endif +#endif // _LIBCPP_THREAD_SAFETY_ANNOTATION + +class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex +{ +#ifndef _LIBCPP_CXX03_LANG + __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER; +#else + __libcpp_mutex_t __m_; +#endif + +public: + _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_CXX03_LANG + constexpr mutex() = default; +#else + mutex() _NOEXCEPT {__m_ = (__libcpp_mutex_t)_LIBCPP_MUTEX_INITIALIZER;} +#endif + ~mutex(); + +private: + mutex(const mutex&);// = delete; + mutex& operator=(const mutex&);// = delete; + +public: + void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability()); + bool try_lock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)); + void unlock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()); + + typedef __libcpp_mutex_t* native_handle_type; + _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;} +}; + +static_assert(is_nothrow_default_constructible<mutex>::value, + "the default constructor for std::mutex must be nothrow"); + +struct _LIBCPP_TYPE_VIS defer_lock_t {}; +struct _LIBCPP_TYPE_VIS try_to_lock_t {}; +struct _LIBCPP_TYPE_VIS adopt_lock_t {}; + +#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) + +extern _LIBCPP_EXPORTED_FROM_ABI const defer_lock_t defer_lock; +extern _LIBCPP_EXPORTED_FROM_ABI const try_to_lock_t try_to_lock; +extern _LIBCPP_EXPORTED_FROM_ABI const adopt_lock_t adopt_lock; + +#else + +/* _LIBCPP_INLINE_VAR */ constexpr defer_lock_t defer_lock = defer_lock_t(); +/* _LIBCPP_INLINE_VAR */ constexpr try_to_lock_t try_to_lock = try_to_lock_t(); +/* _LIBCPP_INLINE_VAR */ constexpr adopt_lock_t adopt_lock = adopt_lock_t(); + +#endif + +template <class _Mutex> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) +lock_guard +{ +public: + typedef _Mutex mutex_type; + +private: + mutex_type& __m_; +public: + + _LIBCPP_INLINE_VISIBILITY + explicit lock_guard(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m)) + : __m_(__m) {__m_.lock();} + _LIBCPP_INLINE_VISIBILITY + lock_guard(mutex_type& __m, adopt_lock_t) _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m)) + : __m_(__m) {} + _LIBCPP_INLINE_VISIBILITY + ~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) {__m_.unlock();} + +private: + lock_guard(lock_guard const&) _LIBCPP_EQUAL_DELETE; + lock_guard& operator=(lock_guard const&) _LIBCPP_EQUAL_DELETE; +}; + +template <class _Mutex> +class _LIBCPP_TEMPLATE_VIS unique_lock +{ +public: + typedef _Mutex mutex_type; + +private: + mutex_type* __m_; + bool __owns_; + +public: + _LIBCPP_INLINE_VISIBILITY + unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {} + _LIBCPP_INLINE_VISIBILITY + explicit unique_lock(mutex_type& __m) + : __m_(_VSTD::addressof(__m)), __owns_(true) {__m_->lock();} + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT + : __m_(_VSTD::addressof(__m)), __owns_(false) {} + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, try_to_lock_t) + : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock()) {} + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, adopt_lock_t) + : __m_(_VSTD::addressof(__m)), __owns_(true) {} + template <class _Clock, class _Duration> + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, const chrono::time_point<_Clock, _Duration>& __t) + : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_until(__t)) {} + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __d) + : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_for(__d)) {} + _LIBCPP_INLINE_VISIBILITY + ~unique_lock() + { + if (__owns_) + __m_->unlock(); + } + +private: + unique_lock(unique_lock const&); // = delete; + unique_lock& operator=(unique_lock const&); // = delete; + +public: +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + unique_lock(unique_lock&& __u) _NOEXCEPT + : __m_(__u.__m_), __owns_(__u.__owns_) + {__u.__m_ = nullptr; __u.__owns_ = false;} + _LIBCPP_INLINE_VISIBILITY + unique_lock& operator=(unique_lock&& __u) _NOEXCEPT + { + if (__owns_) + __m_->unlock(); + __m_ = __u.__m_; + __owns_ = __u.__owns_; + __u.__m_ = nullptr; + __u.__owns_ = false; + return *this; + } + +#endif // _LIBCPP_CXX03_LANG + + void lock(); + bool try_lock(); + + template <class _Rep, class _Period> + bool try_lock_for(const chrono::duration<_Rep, _Period>& __d); + template <class _Clock, class _Duration> + bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t); + + void unlock(); + + _LIBCPP_INLINE_VISIBILITY + void swap(unique_lock& __u) _NOEXCEPT + { + _VSTD::swap(__m_, __u.__m_); + _VSTD::swap(__owns_, __u.__owns_); + } + _LIBCPP_INLINE_VISIBILITY + mutex_type* release() _NOEXCEPT + { + mutex_type* __m = __m_; + __m_ = nullptr; + __owns_ = false; + return __m; + } + + _LIBCPP_INLINE_VISIBILITY + bool owns_lock() const _NOEXCEPT {return __owns_;} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT + operator bool () const _NOEXCEPT {return __owns_;} + _LIBCPP_INLINE_VISIBILITY + mutex_type* mutex() const _NOEXCEPT {return __m_;} +}; + +template <class _Mutex> +void +unique_lock<_Mutex>::lock() +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "unique_lock::lock: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "unique_lock::lock: already locked"); + __m_->lock(); + __owns_ = true; +} + +template <class _Mutex> +bool +unique_lock<_Mutex>::try_lock() +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "unique_lock::try_lock: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "unique_lock::try_lock: already locked"); + __owns_ = __m_->try_lock(); + return __owns_; +} + +template <class _Mutex> +template <class _Rep, class _Period> +bool +unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "unique_lock::try_lock_for: already locked"); + __owns_ = __m_->try_lock_for(__d); + return __owns_; +} + +template <class _Mutex> +template <class _Clock, class _Duration> +bool +unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "unique_lock::try_lock_until: already locked"); + __owns_ = __m_->try_lock_until(__t); + return __owns_; +} + +template <class _Mutex> +void +unique_lock<_Mutex>::unlock() +{ + if (!__owns_) + __throw_system_error(EPERM, "unique_lock::unlock: not locked"); + __m_->unlock(); + __owns_ = false; +} + +template <class _Mutex> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) _NOEXCEPT + {__x.swap(__y);} + +//enum class cv_status +_LIBCPP_DECLARE_STRONG_ENUM(cv_status) +{ + no_timeout, + timeout +}; +_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status) + +class _LIBCPP_TYPE_VIS condition_variable +{ +#ifndef _LIBCPP_CXX03_LANG + __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER; +#else + __libcpp_condvar_t __cv_; +#endif + +public: + _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_CXX03_LANG + constexpr condition_variable() _NOEXCEPT = default; +#else + condition_variable() _NOEXCEPT {__cv_ = (__libcpp_condvar_t)_LIBCPP_CONDVAR_INITIALIZER;} +#endif + ~condition_variable(); + +private: + condition_variable(const condition_variable&); // = delete; + condition_variable& operator=(const condition_variable&); // = delete; + +public: + void notify_one() _NOEXCEPT; + void notify_all() _NOEXCEPT; + + void wait(unique_lock<mutex>& __lk) _NOEXCEPT; + template <class _Predicate> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + void wait(unique_lock<mutex>& __lk, _Predicate __pred); + + template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + cv_status + wait_until(unique_lock<mutex>& __lk, + const chrono::time_point<_Clock, _Duration>& __t); + + template <class _Clock, class _Duration, class _Predicate> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + bool + wait_until(unique_lock<mutex>& __lk, + const chrono::time_point<_Clock, _Duration>& __t, + _Predicate __pred); + + template <class _Rep, class _Period> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + cv_status + wait_for(unique_lock<mutex>& __lk, + const chrono::duration<_Rep, _Period>& __d); + + template <class _Rep, class _Period, class _Predicate> + bool + _LIBCPP_INLINE_VISIBILITY + wait_for(unique_lock<mutex>& __lk, + const chrono::duration<_Rep, _Period>& __d, + _Predicate __pred); + + typedef __libcpp_condvar_t* native_handle_type; + _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__cv_;} + +private: + void __do_timed_wait(unique_lock<mutex>& __lk, + chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT; +}; +#endif // !_LIBCPP_HAS_NO_THREADS + +template <class _To, class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + chrono::__is_duration<_To>::value, + _To +>::type +__ceil(chrono::duration<_Rep, _Period> __d) +{ + using namespace chrono; + _To __r = duration_cast<_To>(__d); + if (__r < __d) + ++__r; + return __r; +} + +#ifndef _LIBCPP_HAS_NO_THREADS +template <class _Predicate> +void +condition_variable::wait(unique_lock<mutex>& __lk, _Predicate __pred) +{ + while (!__pred()) + wait(__lk); +} + +template <class _Clock, class _Duration> +cv_status +condition_variable::wait_until(unique_lock<mutex>& __lk, + const chrono::time_point<_Clock, _Duration>& __t) +{ + using namespace chrono; + wait_for(__lk, __t - _Clock::now()); + return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout; +} + +template <class _Clock, class _Duration, class _Predicate> +bool +condition_variable::wait_until(unique_lock<mutex>& __lk, + const chrono::time_point<_Clock, _Duration>& __t, + _Predicate __pred) +{ + while (!__pred()) + { + if (wait_until(__lk, __t) == cv_status::timeout) + return __pred(); + } + return true; +} + +template <class _Rep, class _Period> +cv_status +condition_variable::wait_for(unique_lock<mutex>& __lk, + const chrono::duration<_Rep, _Period>& __d) +{ + using namespace chrono; + if (__d <= __d.zero()) + return cv_status::timeout; + typedef time_point<system_clock, duration<long double, nano> > __sys_tpf; + typedef time_point<system_clock, nanoseconds> __sys_tpi; + __sys_tpf _Max = __sys_tpi::max(); + steady_clock::time_point __c_now = steady_clock::now(); + system_clock::time_point __s_now = system_clock::now(); + if (_Max - __d > __s_now) + __do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__d)); + else + __do_timed_wait(__lk, __sys_tpi::max()); + return steady_clock::now() - __c_now < __d ? cv_status::no_timeout : + cv_status::timeout; +} + +template <class _Rep, class _Period, class _Predicate> +inline +bool +condition_variable::wait_for(unique_lock<mutex>& __lk, + const chrono::duration<_Rep, _Period>& __d, + _Predicate __pred) +{ + return wait_until(__lk, chrono::steady_clock::now() + __d, + _VSTD::move(__pred)); +} + +#endif // !_LIBCPP_HAS_NO_THREADS + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MUTEX_BASE diff --git a/android/x86/include/v8/libc++/__node_handle b/android/x86/include/v8/libc++/__node_handle new file mode 100755 index 00000000..e543fa9b --- /dev/null +++ b/android/x86/include/v8/libc++/__node_handle @@ -0,0 +1,208 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___NODE_HANDLE +#define _LIBCPP___NODE_HANDLE + +#include <__config> +#include <memory> +#include <optional> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +// Specialized in __tree & __hash_table for their _NodeType. +template <class _NodeType, class _Alloc> +struct __generic_container_node_destructor; + +template <class _NodeType, class _Alloc, + template <class, class> class _MapOrSetSpecifics> +class _LIBCPP_TEMPLATE_VIS __basic_node_handle + : public _MapOrSetSpecifics< + _NodeType, + __basic_node_handle<_NodeType, _Alloc, _MapOrSetSpecifics>> +{ + template <class _Tp, class _Compare, class _Allocator> + friend class __tree; + template <class _Tp, class _Hash, class _Equal, class _Allocator> + friend class __hash_table; + friend struct _MapOrSetSpecifics< + _NodeType, __basic_node_handle<_NodeType, _Alloc, _MapOrSetSpecifics>>; + + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_pointer<typename __alloc_traits::void_pointer, + _NodeType>::type + __node_pointer_type; + +public: + typedef _Alloc allocator_type; + +private: + __node_pointer_type __ptr_ = nullptr; + optional<allocator_type> __alloc_; + + _LIBCPP_INLINE_VISIBILITY + void __release() + { + __ptr_ = nullptr; + __alloc_ = _VSTD::nullopt; + } + + _LIBCPP_INLINE_VISIBILITY + void __destroy_node_pointer() + { + if (__ptr_ != nullptr) + { + typedef typename __allocator_traits_rebind< + allocator_type, _NodeType>::type __node_alloc_type; + __node_alloc_type __alloc(*__alloc_); + __generic_container_node_destructor<_NodeType, __node_alloc_type>( + __alloc, true)(__ptr_); + __ptr_ = nullptr; + } + } + + _LIBCPP_INLINE_VISIBILITY + __basic_node_handle(__node_pointer_type __ptr, + allocator_type const& __alloc) + : __ptr_(__ptr), __alloc_(__alloc) + { + } + +public: + _LIBCPP_INLINE_VISIBILITY + __basic_node_handle() = default; + + _LIBCPP_INLINE_VISIBILITY + __basic_node_handle(__basic_node_handle&& __other) noexcept + : __ptr_(__other.__ptr_), + __alloc_(_VSTD::move(__other.__alloc_)) + { + __other.__ptr_ = nullptr; + __other.__alloc_ = _VSTD::nullopt; + } + + _LIBCPP_INLINE_VISIBILITY + __basic_node_handle& operator=(__basic_node_handle&& __other) + { + _LIBCPP_ASSERT( + __alloc_ == _VSTD::nullopt || + __alloc_traits::propagate_on_container_move_assignment::value || + __alloc_ == __other.__alloc_, + "node_type with incompatible allocator passed to " + "node_type::operator=(node_type&&)"); + + __destroy_node_pointer(); + __ptr_ = __other.__ptr_; + + if (__alloc_traits::propagate_on_container_move_assignment::value || + __alloc_ == _VSTD::nullopt) + __alloc_ = _VSTD::move(__other.__alloc_); + + __other.__ptr_ = nullptr; + __other.__alloc_ = _VSTD::nullopt; + + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const { return *__alloc_; } + + _LIBCPP_INLINE_VISIBILITY + explicit operator bool() const { return __ptr_ != nullptr; } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const { return __ptr_ == nullptr; } + + _LIBCPP_INLINE_VISIBILITY + void swap(__basic_node_handle& __other) noexcept( + __alloc_traits::propagate_on_container_swap::value || + __alloc_traits::is_always_equal::value) + { + using _VSTD::swap; + swap(__ptr_, __other.__ptr_); + if (__alloc_traits::propagate_on_container_swap::value || + __alloc_ == _VSTD::nullopt || __other.__alloc_ == _VSTD::nullopt) + swap(__alloc_, __other.__alloc_); + } + + _LIBCPP_INLINE_VISIBILITY + friend void swap(__basic_node_handle& __a, __basic_node_handle& __b) + noexcept(noexcept(__a.swap(__b))) { __a.swap(__b); } + + _LIBCPP_INLINE_VISIBILITY + ~__basic_node_handle() + { + __destroy_node_pointer(); + } +}; + +template <class _NodeType, class _Derived> +struct __set_node_handle_specifics +{ + typedef typename _NodeType::__node_value_type value_type; + + _LIBCPP_INLINE_VISIBILITY + value_type& value() const + { + return static_cast<_Derived const*>(this)->__ptr_->__value_; + } +}; + +template <class _NodeType, class _Derived> +struct __map_node_handle_specifics +{ + typedef typename _NodeType::__node_value_type::key_type key_type; + typedef typename _NodeType::__node_value_type::mapped_type mapped_type; + + _LIBCPP_INLINE_VISIBILITY + key_type& key() const + { + return static_cast<_Derived const*>(this)-> + __ptr_->__value_.__ref().first; + } + + _LIBCPP_INLINE_VISIBILITY + mapped_type& mapped() const + { + return static_cast<_Derived const*>(this)-> + __ptr_->__value_.__ref().second; + } +}; + +template <class _NodeType, class _Alloc> +using __set_node_handle = + __basic_node_handle< _NodeType, _Alloc, __set_node_handle_specifics>; + +template <class _NodeType, class _Alloc> +using __map_node_handle = + __basic_node_handle< _NodeType, _Alloc, __map_node_handle_specifics>; + +template <class _Iterator, class _NodeType> +struct _LIBCPP_TEMPLATE_VIS __insert_return_type +{ + _Iterator position; + bool inserted; + _NodeType node; +}; + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + +#endif diff --git a/android/x86/include/v8/libc++/__nullptr b/android/x86/include/v8/libc++/__nullptr new file mode 100755 index 00000000..45529a71 --- /dev/null +++ b/android/x86/include/v8/libc++/__nullptr @@ -0,0 +1,61 @@ +// -*- C++ -*- +//===--------------------------- __nullptr --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_NULLPTR +#define _LIBCPP_NULLPTR + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_NULLPTR + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_TEMPLATE_VIS nullptr_t +{ + void* __lx; + + struct __nat {int __for_bool_;}; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;} + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + operator _Tp* () const {return 0;} + + template <class _Tp, class _Up> + _LIBCPP_INLINE_VISIBILITY + operator _Tp _Up::* () const {return 0;} + + friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;} + friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;} +}; + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);} + +#define nullptr _VSTD::__get_nullptr_t() + +_LIBCPP_END_NAMESPACE_STD + +#else // _LIBCPP_HAS_NO_NULLPTR + +namespace std +{ + typedef decltype(nullptr) nullptr_t; +} + +#endif // _LIBCPP_HAS_NO_NULLPTR + +#endif // _LIBCPP_NULLPTR diff --git a/android/x86/include/v8/libc++/__split_buffer b/android/x86/include/v8/libc++/__split_buffer new file mode 100755 index 00000000..1daa4e5a --- /dev/null +++ b/android/x86/include/v8/libc++/__split_buffer @@ -0,0 +1,637 @@ +// -*- C++ -*- +#ifndef _LIBCPP_SPLIT_BUFFER +#define _LIBCPP_SPLIT_BUFFER + +#include <__config> +#include <type_traits> +#include <algorithm> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <bool> +class __split_buffer_common +{ +protected: + void __throw_length_error() const; + void __throw_out_of_range() const; +}; + +template <class _Tp, class _Allocator = allocator<_Tp> > +struct __split_buffer + : private __split_buffer_common<true> +{ +private: + __split_buffer(const __split_buffer&); + __split_buffer& operator=(const __split_buffer&); +public: + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef typename remove_reference<allocator_type>::type __alloc_rr; + typedef allocator_traits<__alloc_rr> __alloc_traits; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef pointer iterator; + typedef const_pointer const_iterator; + + pointer __first_; + pointer __begin_; + pointer __end_; + __compressed_pair<pointer, allocator_type> __end_cap_; + + typedef typename add_lvalue_reference<allocator_type>::type __alloc_ref; + typedef typename add_lvalue_reference<allocator_type>::type __alloc_const_ref; + + _LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() _NOEXCEPT {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY const __alloc_rr& __alloc() const _NOEXCEPT {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();} + _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();} + + _LIBCPP_INLINE_VISIBILITY + __split_buffer() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY + explicit __split_buffer(__alloc_rr& __a); + _LIBCPP_INLINE_VISIBILITY + explicit __split_buffer(const __alloc_rr& __a); + __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a); + ~__split_buffer(); + +#ifndef _LIBCPP_CXX03_LANG + __split_buffer(__split_buffer&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); + __split_buffer(__split_buffer&& __c, const __alloc_rr& __a); + __split_buffer& operator=(__split_buffer&& __c) + _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value) || + !__alloc_traits::propagate_on_container_move_assignment::value); +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;} + _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;} + _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __end_;} + _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __end_;} + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT + {__destruct_at_end(__begin_);} + _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(__end_ - __begin_);} + _LIBCPP_INLINE_VISIBILITY bool empty() const {return __end_ == __begin_;} + _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __first_);} + _LIBCPP_INLINE_VISIBILITY size_type __front_spare() const {return static_cast<size_type>(__begin_ - __first_);} + _LIBCPP_INLINE_VISIBILITY size_type __back_spare() const {return static_cast<size_type>(__end_cap() - __end_);} + + _LIBCPP_INLINE_VISIBILITY reference front() {return *__begin_;} + _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *__begin_;} + _LIBCPP_INLINE_VISIBILITY reference back() {return *(__end_ - 1);} + _LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(__end_ - 1);} + + void reserve(size_type __n); + void shrink_to_fit() _NOEXCEPT; + void push_front(const_reference __x); + _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); +#ifndef _LIBCPP_CXX03_LANG + void push_front(value_type&& __x); + void push_back(value_type&& __x); + template <class... _Args> + void emplace_back(_Args&&... __args); +#endif // !defined(_LIBCPP_CXX03_LANG) + + _LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);} + _LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);} + + void __construct_at_end(size_type __n); + void __construct_at_end(size_type __n, const_reference __x); + template <class _InputIter> + typename enable_if + < + __is_input_iterator<_InputIter>::value && + !__is_forward_iterator<_InputIter>::value, + void + >::type + __construct_at_end(_InputIter __first, _InputIter __last); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + void + >::type + __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); + + _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin) + {__destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());} + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_begin(pointer __new_begin, false_type); + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_begin(pointer __new_begin, true_type); + + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last) _NOEXCEPT + {__destruct_at_end(__new_last, false_type());} + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT; + + void swap(__split_buffer& __x) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value); + + bool __invariants() const; + +private: + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__split_buffer& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) + { + __alloc() = _VSTD::move(__c.__alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT + {} +}; + +template <class _Tp, class _Allocator> +bool +__split_buffer<_Tp, _Allocator>::__invariants() const +{ + if (__first_ == nullptr) + { + if (__begin_ != nullptr) + return false; + if (__end_ != nullptr) + return false; + if (__end_cap() != nullptr) + return false; + } + else + { + if (__begin_ < __first_) + return false; + if (__end_ < __begin_) + return false; + if (__end_cap() < __end_) + return false; + } + return true; +} + +// Default constructs __n objects starting at __end_ +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == size() + __n +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n) +{ + __alloc_rr& __a = this->__alloc(); + do + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); + ++this->__end_; + --__n; + } while (__n > 0); +} + +// Copy constructs __n objects starting at __end_ from __x +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == old size() + __n +// Postcondition: [i] == __x for all i in [size() - __n, __n) +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) +{ + __alloc_rr& __a = this->__alloc(); + do + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); + ++this->__end_; + --__n; + } while (__n > 0); +} + +template <class _Tp, class _Allocator> +template <class _InputIter> +typename enable_if +< + __is_input_iterator<_InputIter>::value && + !__is_forward_iterator<_InputIter>::value, + void +>::type +__split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIter __last) +{ + __alloc_rr& __a = this->__alloc(); + for (; __first != __last; ++__first) + { + if (__end_ == __end_cap()) + { + size_type __old_cap = __end_cap() - __first_; + size_type __new_cap = _VSTD::max<size_type>(2 * __old_cap, 8); + __split_buffer __buf(__new_cap, 0, __a); + for (pointer __p = __begin_; __p != __end_; ++__p, ++__buf.__end_) + __alloc_traits::construct(__buf.__alloc(), + _VSTD::__to_raw_pointer(__buf.__end_), _VSTD::move(*__p)); + swap(__buf); + } + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); + ++this->__end_; + } +} + +template <class _Tp, class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value, + void +>::type +__split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) +{ + __alloc_rr& __a = this->__alloc(); + for (; __first != __last; ++__first) + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); + ++this->__end_; + } +} + +template <class _Tp, class _Allocator> +inline +void +__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type) +{ + while (__begin_ != __new_begin) + __alloc_traits::destroy(__alloc(), __to_raw_pointer(__begin_++)); +} + +template <class _Tp, class _Allocator> +inline +void +__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type) +{ + __begin_ = __new_begin; +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT +{ + while (__new_last != __end_) + __alloc_traits::destroy(__alloc(), __to_raw_pointer(--__end_)); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT +{ + __end_ = __new_last; +} + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a) + : __end_cap_(nullptr, __a) +{ + __first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr; + __begin_ = __end_ = __first_ + __start; + __end_cap() = __first_ + __cap; +} + +template <class _Tp, class _Allocator> +inline +__split_buffer<_Tp, _Allocator>::__split_buffer() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr) +{ +} + +template <class _Tp, class _Allocator> +inline +__split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a) + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) +{ +} + +template <class _Tp, class _Allocator> +inline +__split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a) + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) +{ +} + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>::~__split_buffer() +{ + clear(); + if (__first_) + __alloc_traits::deallocate(__alloc(), __first_, capacity()); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) + : __first_(_VSTD::move(__c.__first_)), + __begin_(_VSTD::move(__c.__begin_)), + __end_(_VSTD::move(__c.__end_)), + __end_cap_(_VSTD::move(__c.__end_cap_)) +{ + __c.__first_ = nullptr; + __c.__begin_ = nullptr; + __c.__end_ = nullptr; + __c.__end_cap() = nullptr; +} + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a) + : __end_cap_(__second_tag(), __a) +{ + if (__a == __c.__alloc()) + { + __first_ = __c.__first_; + __begin_ = __c.__begin_; + __end_ = __c.__end_; + __end_cap() = __c.__end_cap(); + __c.__first_ = nullptr; + __c.__begin_ = nullptr; + __c.__end_ = nullptr; + __c.__end_cap() = nullptr; + } + else + { + size_type __cap = __c.size(); + __first_ = __alloc_traits::allocate(__alloc(), __cap); + __begin_ = __end_ = __first_; + __end_cap() = __first_ + __cap; + typedef move_iterator<iterator> _Ip; + __construct_at_end(_Ip(__c.begin()), _Ip(__c.end())); + } +} + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>& +__split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c) + _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value) || + !__alloc_traits::propagate_on_container_move_assignment::value) +{ + clear(); + shrink_to_fit(); + __first_ = __c.__first_; + __begin_ = __c.__begin_; + __end_ = __c.__end_; + __end_cap() = __c.__end_cap(); + __move_assign_alloc(__c, + integral_constant<bool, + __alloc_traits::propagate_on_container_move_assignment::value>()); + __c.__first_ = __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value) +{ + _VSTD::swap(__first_, __x.__first_); + _VSTD::swap(__begin_, __x.__begin_); + _VSTD::swap(__end_, __x.__end_); + _VSTD::swap(__end_cap(), __x.__end_cap()); + __swap_allocator(__alloc(), __x.__alloc()); +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::reserve(size_type __n) +{ + if (__n < capacity()) + { + __split_buffer<value_type, __alloc_rr&> __t(__n, 0, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT +{ + if (capacity() > size()) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + __t.__end_ = __t.__begin_ + (__end_ - __begin_); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::push_front(const_reference __x) +{ + if (__begin_ == __first_) + { + if (__end_ < __end_cap()) + { + difference_type __d = __end_cap() - __end_; + __d = (__d + 1) / 2; + __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d); + __end_ += __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1), __x); + --__begin_; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::push_front(value_type&& __x) +{ + if (__begin_ == __first_) + { + if (__end_ < __end_cap()) + { + difference_type __d = __end_cap() - __end_; + __d = (__d + 1) / 2; + __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d); + __end_ += __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1), + _VSTD::move(__x)); + --__begin_; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +__split_buffer<_Tp, _Allocator>::push_back(const_reference __x) +{ + if (__end_ == __end_cap()) + { + if (__begin_ > __first_) + { + difference_type __d = __begin_ - __first_; + __d = (__d + 1) / 2; + __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); + __begin_ -= __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), __x); + ++__end_; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::push_back(value_type&& __x) +{ + if (__end_ == __end_cap()) + { + if (__begin_ > __first_) + { + difference_type __d = __begin_ - __first_; + __d = (__d + 1) / 2; + __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); + __begin_ -= __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), + _VSTD::move(__x)); + ++__end_; +} + +template <class _Tp, class _Allocator> +template <class... _Args> +void +__split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args) +{ + if (__end_ == __end_cap()) + { + if (__begin_ > __first_) + { + difference_type __d = __begin_ - __first_; + __d = (__d + 1) / 2; + __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); + __begin_ -= __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), + _VSTD::forward<_Args>(__args)...); + ++__end_; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_SPLIT_BUFFER diff --git a/android/x86/include/v8/libc++/__sso_allocator b/android/x86/include/v8/libc++/__sso_allocator new file mode 100755 index 00000000..39301287 --- /dev/null +++ b/android/x86/include/v8/libc++/__sso_allocator @@ -0,0 +1,76 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___SSO_ALLOCATOR +#define _LIBCPP___SSO_ALLOCATOR + +#include <__config> +#include <type_traits> +#include <new> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp, size_t _Np> class _LIBCPP_HIDDEN __sso_allocator; + +template <size_t _Np> +class _LIBCPP_HIDDEN __sso_allocator<void, _Np> +{ +public: + typedef const void* const_pointer; + typedef void value_type; +}; + +template <class _Tp, size_t _Np> +class _LIBCPP_HIDDEN __sso_allocator +{ + typename aligned_storage<sizeof(_Tp) * _Np>::type buf_; + bool __allocated_; +public: + typedef size_t size_type; + typedef _Tp* pointer; + typedef _Tp value_type; + + _LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {} + _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {} + template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) throw() + : __allocated_(false) {} +private: + __sso_allocator& operator=(const __sso_allocator&); +public: + _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, typename __sso_allocator<void, _Np>::const_pointer = 0) + { + if (!__allocated_ && __n <= _Np) + { + __allocated_ = true; + return (pointer)&buf_; + } + return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); + } + _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) + { + if (__p == (pointer)&buf_) + __allocated_ = false; + else + _VSTD::__libcpp_deallocate(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + } + _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);} + + _LIBCPP_INLINE_VISIBILITY + bool operator==(__sso_allocator& __a) const {return &buf_ == &__a.buf_;} + _LIBCPP_INLINE_VISIBILITY + bool operator!=(__sso_allocator& __a) const {return &buf_ != &__a.buf_;} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___SSO_ALLOCATOR diff --git a/android/x86/include/v8/libc++/__std_stream b/android/x86/include/v8/libc++/__std_stream new file mode 100755 index 00000000..5a9a470a --- /dev/null +++ b/android/x86/include/v8/libc++/__std_stream @@ -0,0 +1,361 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___STD_STREAM +#define _LIBCPP___STD_STREAM + +#include <__config> +#include <ostream> +#include <istream> +#include <__locale> +#include <cstdio> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +static const int __limit = 8; + +// __stdinbuf + +template <class _CharT> +class _LIBCPP_HIDDEN __stdinbuf + : public basic_streambuf<_CharT, char_traits<_CharT> > +{ +public: + typedef _CharT char_type; + typedef char_traits<char_type> traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef typename traits_type::state_type state_type; + + __stdinbuf(FILE* __fp, state_type* __st); + +protected: + virtual int_type underflow(); + virtual int_type uflow(); + virtual int_type pbackfail(int_type __c = traits_type::eof()); + virtual void imbue(const locale& __loc); + +private: + + FILE* __file_; + const codecvt<char_type, char, state_type>* __cv_; + state_type* __st_; + int __encoding_; + int_type __last_consumed_; + bool __last_consumed_is_next_; + bool __always_noconv_; + + __stdinbuf(const __stdinbuf&); + __stdinbuf& operator=(const __stdinbuf&); + + int_type __getchar(bool __consume); +}; + +template <class _CharT> +__stdinbuf<_CharT>::__stdinbuf(FILE* __fp, state_type* __st) + : __file_(__fp), + __st_(__st), + __last_consumed_(traits_type::eof()), + __last_consumed_is_next_(false) +{ + imbue(this->getloc()); +} + +template <class _CharT> +void +__stdinbuf<_CharT>::imbue(const locale& __loc) +{ + __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc); + __encoding_ = __cv_->encoding(); + __always_noconv_ = __cv_->always_noconv(); + if (__encoding_ > __limit) + __throw_runtime_error("unsupported locale for standard input"); +} + +template <class _CharT> +typename __stdinbuf<_CharT>::int_type +__stdinbuf<_CharT>::underflow() +{ + return __getchar(false); +} + +template <class _CharT> +typename __stdinbuf<_CharT>::int_type +__stdinbuf<_CharT>::uflow() +{ + return __getchar(true); +} + +template <class _CharT> +typename __stdinbuf<_CharT>::int_type +__stdinbuf<_CharT>::__getchar(bool __consume) +{ + if (__last_consumed_is_next_) + { + int_type __result = __last_consumed_; + if (__consume) + { + __last_consumed_ = traits_type::eof(); + __last_consumed_is_next_ = false; + } + return __result; + } + char __extbuf[__limit]; + int __nread = _VSTD::max(1, __encoding_); + for (int __i = 0; __i < __nread; ++__i) + { + int __c = getc(__file_); + if (__c == EOF) + return traits_type::eof(); + __extbuf[__i] = static_cast<char>(__c); + } + char_type __1buf; + if (__always_noconv_) + __1buf = static_cast<char_type>(__extbuf[0]); + else + { + const char* __enxt; + char_type* __inxt; + codecvt_base::result __r; + do + { + state_type __sv_st = *__st_; + __r = __cv_->in(*__st_, __extbuf, __extbuf + __nread, __enxt, + &__1buf, &__1buf + 1, __inxt); + switch (__r) + { + case _VSTD::codecvt_base::ok: + break; + case codecvt_base::partial: + *__st_ = __sv_st; + if (__nread == sizeof(__extbuf)) + return traits_type::eof(); + { + int __c = getc(__file_); + if (__c == EOF) + return traits_type::eof(); + __extbuf[__nread] = static_cast<char>(__c); + } + ++__nread; + break; + case codecvt_base::error: + return traits_type::eof(); + case _VSTD::codecvt_base::noconv: + __1buf = static_cast<char_type>(__extbuf[0]); + break; + } + } while (__r == _VSTD::codecvt_base::partial); + } + if (!__consume) + { + for (int __i = __nread; __i > 0;) + { + if (ungetc(traits_type::to_int_type(__extbuf[--__i]), __file_) == EOF) + return traits_type::eof(); + } + } + else + __last_consumed_ = traits_type::to_int_type(__1buf); + return traits_type::to_int_type(__1buf); +} + +template <class _CharT> +typename __stdinbuf<_CharT>::int_type +__stdinbuf<_CharT>::pbackfail(int_type __c) +{ + if (traits_type::eq_int_type(__c, traits_type::eof())) + { + if (!__last_consumed_is_next_) + { + __c = __last_consumed_; + __last_consumed_is_next_ = !traits_type::eq_int_type(__last_consumed_, + traits_type::eof()); + } + return __c; + } + if (__last_consumed_is_next_) + { + char __extbuf[__limit]; + char* __enxt; + const char_type __ci = traits_type::to_char_type(__last_consumed_); + const char_type* __inxt; + switch (__cv_->out(*__st_, &__ci, &__ci + 1, __inxt, + __extbuf, __extbuf + sizeof(__extbuf), __enxt)) + { + case _VSTD::codecvt_base::ok: + break; + case _VSTD::codecvt_base::noconv: + __extbuf[0] = static_cast<char>(__last_consumed_); + __enxt = __extbuf + 1; + break; + case codecvt_base::partial: + case codecvt_base::error: + return traits_type::eof(); + } + while (__enxt > __extbuf) + if (ungetc(*--__enxt, __file_) == EOF) + return traits_type::eof(); + } + __last_consumed_ = __c; + __last_consumed_is_next_ = true; + return __c; +} + +// __stdoutbuf + +template <class _CharT> +class _LIBCPP_HIDDEN __stdoutbuf + : public basic_streambuf<_CharT, char_traits<_CharT> > +{ +public: + typedef _CharT char_type; + typedef char_traits<char_type> traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef typename traits_type::state_type state_type; + + __stdoutbuf(FILE* __fp, state_type* __st); + +protected: + virtual int_type overflow (int_type __c = traits_type::eof()); + virtual streamsize xsputn(const char_type* __s, streamsize __n); + virtual int sync(); + virtual void imbue(const locale& __loc); + +private: + FILE* __file_; + const codecvt<char_type, char, state_type>* __cv_; + state_type* __st_; + bool __always_noconv_; + + __stdoutbuf(const __stdoutbuf&); + __stdoutbuf& operator=(const __stdoutbuf&); +}; + +template <class _CharT> +__stdoutbuf<_CharT>::__stdoutbuf(FILE* __fp, state_type* __st) + : __file_(__fp), + __cv_(&use_facet<codecvt<char_type, char, state_type> >(this->getloc())), + __st_(__st), + __always_noconv_(__cv_->always_noconv()) +{ +} + +template <class _CharT> +typename __stdoutbuf<_CharT>::int_type +__stdoutbuf<_CharT>::overflow(int_type __c) +{ + char __extbuf[__limit]; + char_type __1buf; + if (!traits_type::eq_int_type(__c, traits_type::eof())) + { + __1buf = traits_type::to_char_type(__c); + if (__always_noconv_) + { + if (fwrite(&__1buf, sizeof(char_type), 1, __file_) != 1) + return traits_type::eof(); + } + else + { + char* __extbe = __extbuf; + codecvt_base::result __r; + char_type* pbase = &__1buf; + char_type* pptr = pbase + 1; + do + { + const char_type* __e; + __r = __cv_->out(*__st_, pbase, pptr, __e, + __extbuf, + __extbuf + sizeof(__extbuf), + __extbe); + if (__e == pbase) + return traits_type::eof(); + if (__r == codecvt_base::noconv) + { + if (fwrite(pbase, 1, 1, __file_) != 1) + return traits_type::eof(); + } + else if (__r == codecvt_base::ok || __r == codecvt_base::partial) + { + size_t __nmemb = static_cast<size_t>(__extbe - __extbuf); + if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb) + return traits_type::eof(); + if (__r == codecvt_base::partial) + { + pbase = const_cast<char_type*>(__e); + } + } + else + return traits_type::eof(); + } while (__r == codecvt_base::partial); + } + } + return traits_type::not_eof(__c); +} + +template <class _CharT> +streamsize +__stdoutbuf<_CharT>::xsputn(const char_type* __s, streamsize __n) +{ + if (__always_noconv_) + return fwrite(__s, sizeof(char_type), __n, __file_); + streamsize __i = 0; + for (; __i < __n; ++__i, ++__s) + if (overflow(traits_type::to_int_type(*__s)) == traits_type::eof()) + break; + return __i; +} + +template <class _CharT> +int +__stdoutbuf<_CharT>::sync() +{ + char __extbuf[__limit]; + codecvt_base::result __r; + do + { + char* __extbe; + __r = __cv_->unshift(*__st_, __extbuf, + __extbuf + sizeof(__extbuf), + __extbe); + size_t __nmemb = static_cast<size_t>(__extbe - __extbuf); + if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb) + return -1; + } while (__r == codecvt_base::partial); + if (__r == codecvt_base::error) + return -1; + if (fflush(__file_)) + return -1; + return 0; +} + +template <class _CharT> +void +__stdoutbuf<_CharT>::imbue(const locale& __loc) +{ + sync(); + __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc); + __always_noconv_ = __cv_->always_noconv(); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___STD_STREAM diff --git a/android/x86/include/v8/libc++/__string b/android/x86/include/v8/libc++/__string new file mode 100755 index 00000000..a88b976b --- /dev/null +++ b/android/x86/include/v8/libc++/__string @@ -0,0 +1,973 @@ +// -*- C++ -*- +//===-------------------------- __string ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___STRING +#define _LIBCPP___STRING + +/* + string synopsis + +namespace std +{ + +template <class charT> +struct char_traits +{ + typedef charT char_type; + typedef ... int_type; + typedef streamoff off_type; + typedef streampos pos_type; + typedef mbstate_t state_type; + + static constexpr void assign(char_type& c1, const char_type& c2) noexcept; + static constexpr bool eq(char_type c1, char_type c2) noexcept; + static constexpr bool lt(char_type c1, char_type c2) noexcept; + + static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); + static constexpr size_t length(const char_type* s); + static constexpr const char_type* + find(const char_type* s, size_t n, const char_type& a); + static char_type* move(char_type* s1, const char_type* s2, size_t n); + static char_type* copy(char_type* s1, const char_type* s2, size_t n); + static char_type* assign(char_type* s, size_t n, char_type a); + + static constexpr int_type not_eof(int_type c) noexcept; + static constexpr char_type to_char_type(int_type c) noexcept; + static constexpr int_type to_int_type(char_type c) noexcept; + static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; + static constexpr int_type eof() noexcept; +}; + +template <> struct char_traits<char>; +template <> struct char_traits<wchar_t>; +template <> struct char_traits<char8_t>; // c++20 + +} // std + +*/ + +#include <__config> +#include <algorithm> // for search and min +#include <cstdio> // For EOF. +#include <memory> // for __murmur2_or_cityhash + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +// char_traits + +template <class _CharT> +struct _LIBCPP_TEMPLATE_VIS char_traits +{ + typedef _CharT char_type; + typedef int int_type; + typedef streamoff off_type; + typedef streampos pos_type; + typedef mbstate_t state_type; + + static inline void _LIBCPP_CONSTEXPR_AFTER_CXX14 + assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 < __c2;} + + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + size_t length(const char_type* __s); + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a); + static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY + static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY + static char_type* assign(char_type* __s, size_t __n, char_type __a); + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type(__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(EOF);} +}; + +template <class _CharT> +_LIBCPP_CONSTEXPR_AFTER_CXX14 int +char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n) +{ + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +} + +template <class _CharT> +inline +_LIBCPP_CONSTEXPR_AFTER_CXX14 size_t +char_traits<_CharT>::length(const char_type* __s) +{ + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +} + +template <class _CharT> +inline +_LIBCPP_CONSTEXPR_AFTER_CXX14 const _CharT* +char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a) +{ + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return 0; +} + +template <class _CharT> +_CharT* +char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n) +{ + char_type* __r = __s1; + if (__s1 < __s2) + { + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + } + else if (__s2 < __s1) + { + __s1 += __n; + __s2 += __n; + for (; __n; --__n) + assign(*--__s1, *--__s2); + } + return __r; +} + +template <class _CharT> +inline +_CharT* +char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n) +{ + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + char_type* __r = __s1; + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + return __r; +} + +template <class _CharT> +inline +_CharT* +char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a) +{ + char_type* __r = __s; + for (; __n; --__n, ++__s) + assign(*__s, __a); + return __r; +} + +// char_traits<char> + +template <> +struct _LIBCPP_TEMPLATE_VIS char_traits<char> +{ + typedef char char_type; + typedef int int_type; + typedef streamoff off_type; + typedef streampos pos_type; + typedef mbstate_t state_type; + + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return (unsigned char)__c1 < (unsigned char)__c2;} + + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 + length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);} + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);} + static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n); + } + static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT + {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);} + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type((unsigned char)__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(EOF);} +}; + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +int +char_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + if (__n == 0) + return 0; +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_memcmp(__s1, __s2, __n); +#elif _LIBCPP_STD_VER <= 14 + return memcmp(__s1, __s2, __n); +#else + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +#endif +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const char* +char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + if (__n == 0) + return nullptr; +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_char_memchr(__s, to_int_type(__a), __n); +#elif _LIBCPP_STD_VER <= 14 + return (const char_type*) memchr(__s, to_int_type(__a), __n); +#else + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return nullptr; +#endif +} + + +// char_traits<wchar_t> + +template <> +struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t> +{ + typedef wchar_t char_type; + typedef wint_t int_type; + typedef streamoff off_type; + typedef streampos pos_type; + typedef mbstate_t state_type; + + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 < __c2;} + + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + size_t length(const char_type* __s) _NOEXCEPT; + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);} + static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n); + } + static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT + {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);} + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type(__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(WEOF);} +}; + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +int +char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + if (__n == 0) + return 0; +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_wmemcmp(__s1, __s2, __n); +#elif _LIBCPP_STD_VER <= 14 + return wmemcmp(__s1, __s2, __n); +#else + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +#endif +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +size_t +char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT +{ +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_wcslen(__s); +#elif _LIBCPP_STD_VER <= 14 + return wcslen(__s); +#else + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +#endif +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const wchar_t* +char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + if (__n == 0) + return nullptr; +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_wmemchr(__s, __a, __n); +#elif _LIBCPP_STD_VER <= 14 + return wmemchr(__s, __a, __n); +#else + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return nullptr; +#endif +} + + +#ifndef _LIBCPP_NO_HAS_CHAR8_T + +template <> +struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t> +{ + typedef char8_t char_type; + typedef unsigned int int_type; + typedef streamoff off_type; + typedef u8streampos pos_type; + typedef mbstate_t state_type; + + static inline constexpr void assign(char_type& __c1, const char_type& __c2) noexcept + {__c1 = __c2;} + static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept + {return __c1 == __c2;} + static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept + {return __c1 < __c2;} + + static constexpr + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + + static constexpr + size_t length(const char_type* __s) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY static constexpr + const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + + static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);} + + static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n); + } + + static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT + {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);} + + static inline constexpr int_type not_eof(int_type __c) noexcept + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline constexpr char_type to_char_type(int_type __c) noexcept + {return char_type(__c);} + static inline constexpr int_type to_int_type(char_type __c) noexcept + {return int_type(__c);} + static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept + {return __c1 == __c2;} + static inline constexpr int_type eof() noexcept + {return int_type(EOF);} +}; + +// TODO use '__builtin_strlen' if it ever supports char8_t ?? +inline constexpr +size_t +char_traits<char8_t>::length(const char_type* __s) _NOEXCEPT +{ + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +} + +inline constexpr +int +char_traits<char8_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_memcmp(__s1, __s2, __n); +#else + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +#endif +} + +// TODO use '__builtin_char_memchr' if it ever supports char8_t ?? +inline constexpr +const char8_t* +char_traits<char8_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return 0; +} + +#endif // #_LIBCPP_NO_HAS_CHAR8_T + +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS + +template <> +struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t> +{ + typedef char16_t char_type; + typedef uint_least16_t int_type; + typedef streamoff off_type; + typedef u16streampos pos_type; + typedef mbstate_t state_type; + + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 < __c2;} + + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + size_t length(const char_type* __s) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT; + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type(__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(0xFFFF);} +}; + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +int +char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +size_t +char_traits<char16_t>::length(const char_type* __s) _NOEXCEPT +{ + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const char16_t* +char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return 0; +} + +inline +char16_t* +char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + char_type* __r = __s1; + if (__s1 < __s2) + { + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + } + else if (__s2 < __s1) + { + __s1 += __n; + __s2 += __n; + for (; __n; --__n) + assign(*--__s1, *--__s2); + } + return __r; +} + +inline +char16_t* +char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + char_type* __r = __s1; + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + return __r; +} + +inline +char16_t* +char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT +{ + char_type* __r = __s; + for (; __n; --__n, ++__s) + assign(*__s, __a); + return __r; +} + +template <> +struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t> +{ + typedef char32_t char_type; + typedef uint_least32_t int_type; + typedef streamoff off_type; + typedef u32streampos pos_type; + typedef mbstate_t state_type; + + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 < __c2;} + + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + size_t length(const char_type* __s) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT; + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type(__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(0xFFFFFFFF);} +}; + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +int +char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +size_t +char_traits<char32_t>::length(const char_type* __s) _NOEXCEPT +{ + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const char32_t* +char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return 0; +} + +inline +char32_t* +char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + char_type* __r = __s1; + if (__s1 < __s2) + { + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + } + else if (__s2 < __s1) + { + __s1 += __n; + __s2 += __n; + for (; __n; --__n) + assign(*--__s1, *--__s2); + } + return __r; +} + +inline +char32_t* +char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + char_type* __r = __s1; + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + return __r; +} + +inline +char32_t* +char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT +{ + char_type* __r = __s; + for (; __n; --__n, ++__s) + assign(*__s, __a); + return __r; +} + +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +// helper fns for basic_string and string_view + +// __str_find +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__pos >= __sz) + return __npos; + const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c); + if (__r == 0) + return __npos; + return static_cast<_SizeT>(__r - __p); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _CharT * +__search_substring(const _CharT *__first1, const _CharT *__last1, + const _CharT *__first2, const _CharT *__last2) { + // Take advantage of knowing source and pattern lengths. + // Stop short when source is smaller than pattern. + const ptrdiff_t __len2 = __last2 - __first2; + if (__len2 == 0) + return __first1; + + ptrdiff_t __len1 = __last1 - __first1; + if (__len1 < __len2) + return __last1; + + // First element of __first2 is loop invariant. + _CharT __f2 = *__first2; + while (true) { + __len1 = __last1 - __first1; + // Check whether __first1 still has at least __len2 bytes. + if (__len1 < __len2) + return __last1; + + // Find __f2 the first byte matching in __first1. + __first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2); + if (__first1 == 0) + return __last1; + + // It is faster to compare from the first byte of __first1 even if we + // already know that it matches the first byte of __first2: this is because + // __first2 is most likely aligned, as it is user's "pattern" string, and + // __first1 + 1 is most likely not aligned, as the match is in the middle of + // the string. + if (_Traits::compare(__first1, __first2, __len2) == 0) + return __first1; + + ++__first1; + } +} + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos > __sz) + return __npos; + + if (__n == 0) // There is nothing to search, just return __pos. + return __pos; + + const _CharT *__r = __search_substring<_CharT, _Traits>( + __p + __pos, __p + __sz, __s, __s + __n); + + if (__r == __p + __sz) + return __npos; + return static_cast<_SizeT>(__r - __p); +} + + +// __str_rfind + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_rfind(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__sz < 1) + return __npos; + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + { + if (_Traits::eq(*--__ps, __c)) + return static_cast<_SizeT>(__ps - __p); + } + return __npos; +} + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_rfind(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + __pos = _VSTD::min(__pos, __sz); + if (__n < __sz - __pos) + __pos += __n; + else + __pos = __sz; + const _CharT* __r = _VSTD::__find_end( + __p, __p + __pos, __s, __s + __n, _Traits::eq, + random_access_iterator_tag(), random_access_iterator_tag()); + if (__n > 0 && __r == __p + __pos) + return __npos; + return static_cast<_SizeT>(__r - __p); +} + +// __str_find_first_of +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_first_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos >= __sz || __n == 0) + return __npos; + const _CharT* __r = _VSTD::__find_first_of_ce + (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq ); + if (__r == __p + __sz) + return __npos; + return static_cast<_SizeT>(__r - __p); +} + + +// __str_find_last_of +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_last_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT + { + if (__n != 0) + { + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + { + const _CharT* __r = _Traits::find(__s, __n, *--__ps); + if (__r) + return static_cast<_SizeT>(__ps - __p); + } + } + return __npos; +} + + +// __str_find_first_not_of +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_first_not_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos < __sz) + { + const _CharT* __pe = __p + __sz; + for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) + if (_Traits::find(__s, __n, *__ps) == 0) + return static_cast<_SizeT>(__ps - __p); + } + return __npos; +} + + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_first_not_of(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__pos < __sz) + { + const _CharT* __pe = __p + __sz; + for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) + if (!_Traits::eq(*__ps, __c)) + return static_cast<_SizeT>(__ps - __p); + } + return __npos; +} + + +// __str_find_last_not_of +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_last_not_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + if (_Traits::find(__s, __n, *--__ps) == 0) + return static_cast<_SizeT>(__ps - __p); + return __npos; +} + + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_last_not_of(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + if (!_Traits::eq(*--__ps, __c)) + return static_cast<_SizeT>(__ps - __p); + return __npos; +} + +template<class _Ptr> +inline _LIBCPP_INLINE_VISIBILITY +size_t __do_string_hash(_Ptr __p, _Ptr __e) +{ + typedef typename iterator_traits<_Ptr>::value_type value_type; + return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type)); +} + +template <class _CharT, class _Iter, class _Traits=char_traits<_CharT> > +struct __quoted_output_proxy +{ + _Iter __first; + _Iter __last; + _CharT __delim; + _CharT __escape; + + __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e) + : __first(__f), __last(__l), __delim(__d), __escape(__e) {} + // This would be a nice place for a string_ref +}; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___STRING diff --git a/android/x86/include/v8/libc++/__threading_support b/android/x86/include/v8/libc++/__threading_support new file mode 100755 index 00000000..baa1222c --- /dev/null +++ b/android/x86/include/v8/libc++/__threading_support @@ -0,0 +1,401 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_THREADING_SUPPORT +#define _LIBCPP_THREADING_SUPPORT + +#include <__config> +#include <chrono> +#include <errno.h> + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +#pragma GCC system_header +#endif + +#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) +# include <__external_threading> +#elif !defined(_LIBCPP_HAS_NO_THREADS) + +#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) +# include <pthread.h> +# include <sched.h> +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \ + defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL) || \ + defined(_LIBCPP_HAS_THREAD_API_WIN32) +#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS +#else +#define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY +#endif + +#if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(no_thread_safety_analysis) +#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis)) +#else +#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) +// Mutex +typedef pthread_mutex_t __libcpp_mutex_t; +#define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER + +typedef pthread_mutex_t __libcpp_recursive_mutex_t; + +// Condition Variable +typedef pthread_cond_t __libcpp_condvar_t; +#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER + +// Execute once +typedef pthread_once_t __libcpp_exec_once_flag; +#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT + +// Thread id +typedef pthread_t __libcpp_thread_id; + +// Thread +#define _LIBCPP_NULL_THREAD 0U + +typedef pthread_t __libcpp_thread_t; + +// Thread Local Storage +typedef pthread_key_t __libcpp_tls_key; + +#define _LIBCPP_TLS_DESTRUCTOR_CC +#else +// Mutex +typedef void* __libcpp_mutex_t; +#define _LIBCPP_MUTEX_INITIALIZER 0 + +#if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__) +typedef void* __libcpp_recursive_mutex_t[6]; +#elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__) +typedef void* __libcpp_recursive_mutex_t[5]; +#else +# error Unsupported architecture +#endif + +// Condition Variable +typedef void* __libcpp_condvar_t; +#define _LIBCPP_CONDVAR_INITIALIZER 0 + +// Execute Once +typedef void* __libcpp_exec_once_flag; +#define _LIBCPP_EXEC_ONCE_INITIALIZER 0 + +// Thread ID +typedef long __libcpp_thread_id; + +// Thread +#define _LIBCPP_NULL_THREAD 0U + +typedef void* __libcpp_thread_t; + +// Thread Local Storage +typedef long __libcpp_tls_key; + +#define _LIBCPP_TLS_DESTRUCTOR_CC __stdcall +#endif + +// Mutex +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_mutex_lock(__libcpp_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_mutex_unlock(__libcpp_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_mutex_destroy(__libcpp_mutex_t *__m); + +// Condition variable +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_condvar_signal(__libcpp_condvar_t* __cv); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, + timespec *__ts); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv); + +// Execute once +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_execute_once(__libcpp_exec_once_flag *flag, + void (*init_routine)(void)); + +// Thread id +_LIBCPP_THREAD_ABI_VISIBILITY +bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2); + +_LIBCPP_THREAD_ABI_VISIBILITY +bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2); + +// Thread +_LIBCPP_THREAD_ABI_VISIBILITY +bool __libcpp_thread_isnull(const __libcpp_thread_t *__t); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), + void *__arg); + +_LIBCPP_THREAD_ABI_VISIBILITY +__libcpp_thread_id __libcpp_thread_get_current_id(); + +_LIBCPP_THREAD_ABI_VISIBILITY +__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_thread_join(__libcpp_thread_t *__t); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_thread_detach(__libcpp_thread_t *__t); + +_LIBCPP_THREAD_ABI_VISIBILITY +void __libcpp_thread_yield(); + +_LIBCPP_THREAD_ABI_VISIBILITY +void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns); + +// Thread local storage +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_tls_create(__libcpp_tls_key* __key, + void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*)); + +_LIBCPP_THREAD_ABI_VISIBILITY +void *__libcpp_tls_get(__libcpp_tls_key __key); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_tls_set(__libcpp_tls_key __key, void *__p); + +#if (!defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \ + defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)) && \ + defined(_LIBCPP_HAS_THREAD_API_PTHREAD) + +int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m) +{ + pthread_mutexattr_t attr; + int __ec = pthread_mutexattr_init(&attr); + if (__ec) + return __ec; + __ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + if (__ec) { + pthread_mutexattr_destroy(&attr); + return __ec; + } + __ec = pthread_mutex_init(__m, &attr); + if (__ec) { + pthread_mutexattr_destroy(&attr); + return __ec; + } + __ec = pthread_mutexattr_destroy(&attr); + if (__ec) { + pthread_mutex_destroy(__m); + return __ec; + } + return 0; +} + +int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m) +{ + return pthread_mutex_lock(__m); +} + +bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m) +{ + return pthread_mutex_trylock(__m) == 0; +} + +int __libcpp_recursive_mutex_unlock(__libcpp_mutex_t *__m) +{ + return pthread_mutex_unlock(__m); +} + +int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m) +{ + return pthread_mutex_destroy(__m); +} + +int __libcpp_mutex_lock(__libcpp_mutex_t *__m) +{ + return pthread_mutex_lock(__m); +} + +bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m) +{ + return pthread_mutex_trylock(__m) == 0; +} + +int __libcpp_mutex_unlock(__libcpp_mutex_t *__m) +{ + return pthread_mutex_unlock(__m); +} + +int __libcpp_mutex_destroy(__libcpp_mutex_t *__m) +{ + return pthread_mutex_destroy(__m); +} + +// Condition Variable +int __libcpp_condvar_signal(__libcpp_condvar_t *__cv) +{ + return pthread_cond_signal(__cv); +} + +int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv) +{ + return pthread_cond_broadcast(__cv); +} + +int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m) +{ + return pthread_cond_wait(__cv, __m); +} + +int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, + timespec *__ts) +{ + return pthread_cond_timedwait(__cv, __m, __ts); +} + +int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) +{ + return pthread_cond_destroy(__cv); +} + +// Execute once +int __libcpp_execute_once(__libcpp_exec_once_flag *flag, + void (*init_routine)(void)) { + return pthread_once(flag, init_routine); +} + +// Thread id +// Returns non-zero if the thread ids are equal, otherwise 0 +bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2) +{ + return pthread_equal(t1, t2) != 0; +} + +// Returns non-zero if t1 < t2, otherwise 0 +bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2) +{ + return t1 < t2; +} + +// Thread +bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) { + return *__t == 0; +} + +int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), + void *__arg) +{ + return pthread_create(__t, 0, __func, __arg); +} + +__libcpp_thread_id __libcpp_thread_get_current_id() +{ + return pthread_self(); +} + +__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t) +{ + return *__t; +} + +int __libcpp_thread_join(__libcpp_thread_t *__t) +{ + return pthread_join(*__t, 0); +} + +int __libcpp_thread_detach(__libcpp_thread_t *__t) +{ + return pthread_detach(*__t); +} + +void __libcpp_thread_yield() +{ + sched_yield(); +} + +void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) +{ + using namespace chrono; + seconds __s = duration_cast<seconds>(__ns); + timespec __ts; + typedef decltype(__ts.tv_sec) ts_sec; + _LIBCPP_CONSTEXPR ts_sec __ts_sec_max = numeric_limits<ts_sec>::max(); + + if (__s.count() < __ts_sec_max) + { + __ts.tv_sec = static_cast<ts_sec>(__s.count()); + __ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count()); + } + else + { + __ts.tv_sec = __ts_sec_max; + __ts.tv_nsec = 999999999; // (10^9 - 1) + } + + while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR); +} + +// Thread local storage +int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *)) +{ + return pthread_key_create(__key, __at_exit); +} + +void *__libcpp_tls_get(__libcpp_tls_key __key) +{ + return pthread_getspecific(__key); +} + +int __libcpp_tls_set(__libcpp_tls_key __key, void *__p) +{ + return pthread_setspecific(__key, __p); +} + +#endif // !_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL || _LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // !_LIBCPP_HAS_NO_THREADS + +#endif // _LIBCPP_THREADING_SUPPORT diff --git a/android/x86/include/v8/libc++/__tree b/android/x86/include/v8/libc++/__tree new file mode 100755 index 00000000..0aa9bff6 --- /dev/null +++ b/android/x86/include/v8/libc++/__tree @@ -0,0 +1,2885 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___TREE +#define _LIBCPP___TREE + +#include <__config> +#include <iterator> +#include <memory> +#include <stdexcept> +#include <algorithm> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if defined(__GNUC__) && !defined(__clang__) // gcc.gnu.org/PR37804 +template <class, class, class, class> class _LIBCPP_TEMPLATE_VIS map; +template <class, class, class, class> class _LIBCPP_TEMPLATE_VIS multimap; +template <class, class, class> class _LIBCPP_TEMPLATE_VIS set; +template <class, class, class> class _LIBCPP_TEMPLATE_VIS multiset; +#endif + +template <class _Tp, class _Compare, class _Allocator> class __tree; +template <class _Tp, class _NodePtr, class _DiffType> + class _LIBCPP_TEMPLATE_VIS __tree_iterator; +template <class _Tp, class _ConstNodePtr, class _DiffType> + class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; + +template <class _Pointer> class __tree_end_node; +template <class _VoidPtr> class __tree_node_base; +template <class _Tp, class _VoidPtr> class __tree_node; + +template <class _Key, class _Value> +struct __value_type; + +template <class _Allocator> class __map_node_destructor; +template <class _TreeIterator> class _LIBCPP_TEMPLATE_VIS __map_iterator; +template <class _TreeIterator> class _LIBCPP_TEMPLATE_VIS __map_const_iterator; + +/* + +_NodePtr algorithms + +The algorithms taking _NodePtr are red black tree algorithms. Those +algorithms taking a parameter named __root should assume that __root +points to a proper red black tree (unless otherwise specified). + +Each algorithm herein assumes that __root->__parent_ points to a non-null +structure which has a member __left_ which points back to __root. No other +member is read or written to at __root->__parent_. + +__root->__parent_ will be referred to below (in comments only) as end_node. +end_node->__left_ is an externably accessible lvalue for __root, and can be +changed by node insertion and removal (without explicit reference to end_node). + +All nodes (with the exception of end_node), even the node referred to as +__root, have a non-null __parent_ field. + +*/ + +// Returns: true if __x is a left child of its parent, else false +// Precondition: __x != nullptr. +template <class _NodePtr> +inline _LIBCPP_INLINE_VISIBILITY +bool +__tree_is_left_child(_NodePtr __x) _NOEXCEPT +{ + return __x == __x->__parent_->__left_; +} + +// Determines if the subtree rooted at __x is a proper red black subtree. If +// __x is a proper subtree, returns the black height (null counts as 1). If +// __x is an improper subtree, returns 0. +template <class _NodePtr> +unsigned +__tree_sub_invariant(_NodePtr __x) +{ + if (__x == nullptr) + return 1; + // parent consistency checked by caller + // check __x->__left_ consistency + if (__x->__left_ != nullptr && __x->__left_->__parent_ != __x) + return 0; + // check __x->__right_ consistency + if (__x->__right_ != nullptr && __x->__right_->__parent_ != __x) + return 0; + // check __x->__left_ != __x->__right_ unless both are nullptr + if (__x->__left_ == __x->__right_ && __x->__left_ != nullptr) + return 0; + // If this is red, neither child can be red + if (!__x->__is_black_) + { + if (__x->__left_ && !__x->__left_->__is_black_) + return 0; + if (__x->__right_ && !__x->__right_->__is_black_) + return 0; + } + unsigned __h = __tree_sub_invariant(__x->__left_); + if (__h == 0) + return 0; // invalid left subtree + if (__h != __tree_sub_invariant(__x->__right_)) + return 0; // invalid or different height right subtree + return __h + __x->__is_black_; // return black height of this node +} + +// Determines if the red black tree rooted at __root is a proper red black tree. +// __root == nullptr is a proper tree. Returns true is __root is a proper +// red black tree, else returns false. +template <class _NodePtr> +bool +__tree_invariant(_NodePtr __root) +{ + if (__root == nullptr) + return true; + // check __x->__parent_ consistency + if (__root->__parent_ == nullptr) + return false; + if (!__tree_is_left_child(__root)) + return false; + // root must be black + if (!__root->__is_black_) + return false; + // do normal node checks + return __tree_sub_invariant(__root) != 0; +} + +// Returns: pointer to the left-most node under __x. +// Precondition: __x != nullptr. +template <class _NodePtr> +inline _LIBCPP_INLINE_VISIBILITY +_NodePtr +__tree_min(_NodePtr __x) _NOEXCEPT +{ + while (__x->__left_ != nullptr) + __x = __x->__left_; + return __x; +} + +// Returns: pointer to the right-most node under __x. +// Precondition: __x != nullptr. +template <class _NodePtr> +inline _LIBCPP_INLINE_VISIBILITY +_NodePtr +__tree_max(_NodePtr __x) _NOEXCEPT +{ + while (__x->__right_ != nullptr) + __x = __x->__right_; + return __x; +} + +// Returns: pointer to the next in-order node after __x. +// Precondition: __x != nullptr. +template <class _NodePtr> +_NodePtr +__tree_next(_NodePtr __x) _NOEXCEPT +{ + if (__x->__right_ != nullptr) + return __tree_min(__x->__right_); + while (!__tree_is_left_child(__x)) + __x = __x->__parent_unsafe(); + return __x->__parent_unsafe(); +} + +template <class _EndNodePtr, class _NodePtr> +inline _LIBCPP_INLINE_VISIBILITY +_EndNodePtr +__tree_next_iter(_NodePtr __x) _NOEXCEPT +{ + if (__x->__right_ != nullptr) + return static_cast<_EndNodePtr>(__tree_min(__x->__right_)); + while (!__tree_is_left_child(__x)) + __x = __x->__parent_unsafe(); + return static_cast<_EndNodePtr>(__x->__parent_); +} + +// Returns: pointer to the previous in-order node before __x. +// Precondition: __x != nullptr. +// Note: __x may be the end node. +template <class _NodePtr, class _EndNodePtr> +inline _LIBCPP_INLINE_VISIBILITY +_NodePtr +__tree_prev_iter(_EndNodePtr __x) _NOEXCEPT +{ + if (__x->__left_ != nullptr) + return __tree_max(__x->__left_); + _NodePtr __xx = static_cast<_NodePtr>(__x); + while (__tree_is_left_child(__xx)) + __xx = __xx->__parent_unsafe(); + return __xx->__parent_unsafe(); +} + +// Returns: pointer to a node which has no children +// Precondition: __x != nullptr. +template <class _NodePtr> +_NodePtr +__tree_leaf(_NodePtr __x) _NOEXCEPT +{ + while (true) + { + if (__x->__left_ != nullptr) + { + __x = __x->__left_; + continue; + } + if (__x->__right_ != nullptr) + { + __x = __x->__right_; + continue; + } + break; + } + return __x; +} + +// Effects: Makes __x->__right_ the subtree root with __x as its left child +// while preserving in-order order. +// Precondition: __x->__right_ != nullptr +template <class _NodePtr> +void +__tree_left_rotate(_NodePtr __x) _NOEXCEPT +{ + _NodePtr __y = __x->__right_; + __x->__right_ = __y->__left_; + if (__x->__right_ != nullptr) + __x->__right_->__set_parent(__x); + __y->__parent_ = __x->__parent_; + if (__tree_is_left_child(__x)) + __x->__parent_->__left_ = __y; + else + __x->__parent_unsafe()->__right_ = __y; + __y->__left_ = __x; + __x->__set_parent(__y); +} + +// Effects: Makes __x->__left_ the subtree root with __x as its right child +// while preserving in-order order. +// Precondition: __x->__left_ != nullptr +template <class _NodePtr> +void +__tree_right_rotate(_NodePtr __x) _NOEXCEPT +{ + _NodePtr __y = __x->__left_; + __x->__left_ = __y->__right_; + if (__x->__left_ != nullptr) + __x->__left_->__set_parent(__x); + __y->__parent_ = __x->__parent_; + if (__tree_is_left_child(__x)) + __x->__parent_->__left_ = __y; + else + __x->__parent_unsafe()->__right_ = __y; + __y->__right_ = __x; + __x->__set_parent(__y); +} + +// Effects: Rebalances __root after attaching __x to a leaf. +// Precondition: __root != nulptr && __x != nullptr. +// __x has no children. +// __x == __root or == a direct or indirect child of __root. +// If __x were to be unlinked from __root (setting __root to +// nullptr if __root == __x), __tree_invariant(__root) == true. +// Postcondition: __tree_invariant(end_node->__left_) == true. end_node->__left_ +// may be different than the value passed in as __root. +template <class _NodePtr> +void +__tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT +{ + __x->__is_black_ = __x == __root; + while (__x != __root && !__x->__parent_unsafe()->__is_black_) + { + // __x->__parent_ != __root because __x->__parent_->__is_black == false + if (__tree_is_left_child(__x->__parent_unsafe())) + { + _NodePtr __y = __x->__parent_unsafe()->__parent_unsafe()->__right_; + if (__y != nullptr && !__y->__is_black_) + { + __x = __x->__parent_unsafe(); + __x->__is_black_ = true; + __x = __x->__parent_unsafe(); + __x->__is_black_ = __x == __root; + __y->__is_black_ = true; + } + else + { + if (!__tree_is_left_child(__x)) + { + __x = __x->__parent_unsafe(); + __tree_left_rotate(__x); + } + __x = __x->__parent_unsafe(); + __x->__is_black_ = true; + __x = __x->__parent_unsafe(); + __x->__is_black_ = false; + __tree_right_rotate(__x); + break; + } + } + else + { + _NodePtr __y = __x->__parent_unsafe()->__parent_->__left_; + if (__y != nullptr && !__y->__is_black_) + { + __x = __x->__parent_unsafe(); + __x->__is_black_ = true; + __x = __x->__parent_unsafe(); + __x->__is_black_ = __x == __root; + __y->__is_black_ = true; + } + else + { + if (__tree_is_left_child(__x)) + { + __x = __x->__parent_unsafe(); + __tree_right_rotate(__x); + } + __x = __x->__parent_unsafe(); + __x->__is_black_ = true; + __x = __x->__parent_unsafe(); + __x->__is_black_ = false; + __tree_left_rotate(__x); + break; + } + } + } +} + +// Precondition: __root != nullptr && __z != nullptr. +// __tree_invariant(__root) == true. +// __z == __root or == a direct or indirect child of __root. +// Effects: unlinks __z from the tree rooted at __root, rebalancing as needed. +// Postcondition: __tree_invariant(end_node->__left_) == true && end_node->__left_ +// nor any of its children refer to __z. end_node->__left_ +// may be different than the value passed in as __root. +template <class _NodePtr> +void +__tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT +{ + // __z will be removed from the tree. Client still needs to destruct/deallocate it + // __y is either __z, or if __z has two children, __tree_next(__z). + // __y will have at most one child. + // __y will be the initial hole in the tree (make the hole at a leaf) + _NodePtr __y = (__z->__left_ == nullptr || __z->__right_ == nullptr) ? + __z : __tree_next(__z); + // __x is __y's possibly null single child + _NodePtr __x = __y->__left_ != nullptr ? __y->__left_ : __y->__right_; + // __w is __x's possibly null uncle (will become __x's sibling) + _NodePtr __w = nullptr; + // link __x to __y's parent, and find __w + if (__x != nullptr) + __x->__parent_ = __y->__parent_; + if (__tree_is_left_child(__y)) + { + __y->__parent_->__left_ = __x; + if (__y != __root) + __w = __y->__parent_unsafe()->__right_; + else + __root = __x; // __w == nullptr + } + else + { + __y->__parent_unsafe()->__right_ = __x; + // __y can't be root if it is a right child + __w = __y->__parent_->__left_; + } + bool __removed_black = __y->__is_black_; + // If we didn't remove __z, do so now by splicing in __y for __z, + // but copy __z's color. This does not impact __x or __w. + if (__y != __z) + { + // __z->__left_ != nulptr but __z->__right_ might == __x == nullptr + __y->__parent_ = __z->__parent_; + if (__tree_is_left_child(__z)) + __y->__parent_->__left_ = __y; + else + __y->__parent_unsafe()->__right_ = __y; + __y->__left_ = __z->__left_; + __y->__left_->__set_parent(__y); + __y->__right_ = __z->__right_; + if (__y->__right_ != nullptr) + __y->__right_->__set_parent(__y); + __y->__is_black_ = __z->__is_black_; + if (__root == __z) + __root = __y; + } + // There is no need to rebalance if we removed a red, or if we removed + // the last node. + if (__removed_black && __root != nullptr) + { + // Rebalance: + // __x has an implicit black color (transferred from the removed __y) + // associated with it, no matter what its color is. + // If __x is __root (in which case it can't be null), it is supposed + // to be black anyway, and if it is doubly black, then the double + // can just be ignored. + // If __x is red (in which case it can't be null), then it can absorb + // the implicit black just by setting its color to black. + // Since __y was black and only had one child (which __x points to), __x + // is either red with no children, else null, otherwise __y would have + // different black heights under left and right pointers. + // if (__x == __root || __x != nullptr && !__x->__is_black_) + if (__x != nullptr) + __x->__is_black_ = true; + else + { + // Else __x isn't root, and is "doubly black", even though it may + // be null. __w can not be null here, else the parent would + // see a black height >= 2 on the __x side and a black height + // of 1 on the __w side (__w must be a non-null black or a red + // with a non-null black child). + while (true) + { + if (!__tree_is_left_child(__w)) // if x is left child + { + if (!__w->__is_black_) + { + __w->__is_black_ = true; + __w->__parent_unsafe()->__is_black_ = false; + __tree_left_rotate(__w->__parent_unsafe()); + // __x is still valid + // reset __root only if necessary + if (__root == __w->__left_) + __root = __w; + // reset sibling, and it still can't be null + __w = __w->__left_->__right_; + } + // __w->__is_black_ is now true, __w may have null children + if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && + (__w->__right_ == nullptr || __w->__right_->__is_black_)) + { + __w->__is_black_ = false; + __x = __w->__parent_unsafe(); + // __x can no longer be null + if (__x == __root || !__x->__is_black_) + { + __x->__is_black_ = true; + break; + } + // reset sibling, and it still can't be null + __w = __tree_is_left_child(__x) ? + __x->__parent_unsafe()->__right_ : + __x->__parent_->__left_; + // continue; + } + else // __w has a red child + { + if (__w->__right_ == nullptr || __w->__right_->__is_black_) + { + // __w left child is non-null and red + __w->__left_->__is_black_ = true; + __w->__is_black_ = false; + __tree_right_rotate(__w); + // __w is known not to be root, so root hasn't changed + // reset sibling, and it still can't be null + __w = __w->__parent_unsafe(); + } + // __w has a right red child, left child may be null + __w->__is_black_ = __w->__parent_unsafe()->__is_black_; + __w->__parent_unsafe()->__is_black_ = true; + __w->__right_->__is_black_ = true; + __tree_left_rotate(__w->__parent_unsafe()); + break; + } + } + else + { + if (!__w->__is_black_) + { + __w->__is_black_ = true; + __w->__parent_unsafe()->__is_black_ = false; + __tree_right_rotate(__w->__parent_unsafe()); + // __x is still valid + // reset __root only if necessary + if (__root == __w->__right_) + __root = __w; + // reset sibling, and it still can't be null + __w = __w->__right_->__left_; + } + // __w->__is_black_ is now true, __w may have null children + if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && + (__w->__right_ == nullptr || __w->__right_->__is_black_)) + { + __w->__is_black_ = false; + __x = __w->__parent_unsafe(); + // __x can no longer be null + if (!__x->__is_black_ || __x == __root) + { + __x->__is_black_ = true; + break; + } + // reset sibling, and it still can't be null + __w = __tree_is_left_child(__x) ? + __x->__parent_unsafe()->__right_ : + __x->__parent_->__left_; + // continue; + } + else // __w has a red child + { + if (__w->__left_ == nullptr || __w->__left_->__is_black_) + { + // __w right child is non-null and red + __w->__right_->__is_black_ = true; + __w->__is_black_ = false; + __tree_left_rotate(__w); + // __w is known not to be root, so root hasn't changed + // reset sibling, and it still can't be null + __w = __w->__parent_unsafe(); + } + // __w has a left red child, right child may be null + __w->__is_black_ = __w->__parent_unsafe()->__is_black_; + __w->__parent_unsafe()->__is_black_ = true; + __w->__left_->__is_black_ = true; + __tree_right_rotate(__w->__parent_unsafe()); + break; + } + } + } + } + } +} + +// node traits + + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp> +struct __is_tree_value_type_imp : false_type {}; + +template <class _Key, class _Value> +struct __is_tree_value_type_imp<__value_type<_Key, _Value>> : true_type {}; + +template <class ..._Args> +struct __is_tree_value_type : false_type {}; + +template <class _One> +struct __is_tree_value_type<_One> : __is_tree_value_type_imp<typename __uncvref<_One>::type> {}; +#endif + +template <class _Tp> +struct __tree_key_value_types { + typedef _Tp key_type; + typedef _Tp __node_value_type; + typedef _Tp __container_value_type; + static const bool __is_map = false; + + _LIBCPP_INLINE_VISIBILITY + static key_type const& __get_key(_Tp const& __v) { + return __v; + } + _LIBCPP_INLINE_VISIBILITY + static __container_value_type const& __get_value(__node_value_type const& __v) { + return __v; + } + _LIBCPP_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _VSTD::addressof(__n); + } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + static __container_value_type&& __move(__node_value_type& __v) { + return _VSTD::move(__v); + } +#endif +}; + +template <class _Key, class _Tp> +struct __tree_key_value_types<__value_type<_Key, _Tp> > { + typedef _Key key_type; + typedef _Tp mapped_type; + typedef __value_type<_Key, _Tp> __node_value_type; + typedef pair<const _Key, _Tp> __container_value_type; + typedef __container_value_type __map_value_type; + static const bool __is_map = true; + + _LIBCPP_INLINE_VISIBILITY + static key_type const& + __get_key(__node_value_type const& __t) { + return __t.__get_value().first; + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, + key_type const&>::type + __get_key(_Up& __t) { + return __t.first; + } + + _LIBCPP_INLINE_VISIBILITY + static __container_value_type const& + __get_value(__node_value_type const& __t) { + return __t.__get_value(); + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, + __container_value_type const&>::type + __get_value(_Up& __t) { + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _VSTD::addressof(__n.__get_value()); + } + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) { + return __v.__move(); + } +#endif +}; + +template <class _VoidPtr> +struct __tree_node_base_types { + typedef _VoidPtr __void_pointer; + + typedef __tree_node_base<__void_pointer> __node_base_type; + typedef typename __rebind_pointer<_VoidPtr, __node_base_type>::type + __node_base_pointer; + + typedef __tree_end_node<__node_base_pointer> __end_node_type; + typedef typename __rebind_pointer<_VoidPtr, __end_node_type>::type + __end_node_pointer; +#if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB) + typedef __end_node_pointer __parent_pointer; +#else + typedef typename conditional< + is_pointer<__end_node_pointer>::value, + __end_node_pointer, + __node_base_pointer>::type __parent_pointer; +#endif + +private: + static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value), + "_VoidPtr does not point to unqualified void type"); +}; + +template <class _Tp, class _AllocPtr, class _KVTypes = __tree_key_value_types<_Tp>, + bool = _KVTypes::__is_map> +struct __tree_map_pointer_types {}; + +template <class _Tp, class _AllocPtr, class _KVTypes> +struct __tree_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { + typedef typename _KVTypes::__map_value_type _Mv; + typedef typename __rebind_pointer<_AllocPtr, _Mv>::type + __map_value_type_pointer; + typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type + __const_map_value_type_pointer; +}; + +template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type> +struct __tree_node_types; + +template <class _NodePtr, class _Tp, class _VoidPtr> +struct __tree_node_types<_NodePtr, __tree_node<_Tp, _VoidPtr> > + : public __tree_node_base_types<_VoidPtr>, + __tree_key_value_types<_Tp>, + __tree_map_pointer_types<_Tp, _VoidPtr> +{ + typedef __tree_node_base_types<_VoidPtr> __base; + typedef __tree_key_value_types<_Tp> __key_base; + typedef __tree_map_pointer_types<_Tp, _VoidPtr> __map_pointer_base; +public: + + typedef typename pointer_traits<_NodePtr>::element_type __node_type; + typedef _NodePtr __node_pointer; + + typedef _Tp __node_value_type; + typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type + __node_value_type_pointer; + typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type + __const_node_value_type_pointer; +#if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB) + typedef typename __base::__end_node_pointer __iter_pointer; +#else + typedef typename conditional< + is_pointer<__node_pointer>::value, + typename __base::__end_node_pointer, + __node_pointer>::type __iter_pointer; +#endif +private: + static_assert(!is_const<__node_type>::value, + "_NodePtr should never be a pointer to const"); + static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type, + _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); +}; + +template <class _ValueTp, class _VoidPtr> +struct __make_tree_node_types { + typedef typename __rebind_pointer<_VoidPtr, __tree_node<_ValueTp, _VoidPtr> >::type + _NodePtr; + typedef __tree_node_types<_NodePtr> type; +}; + +// node + +template <class _Pointer> +class __tree_end_node +{ +public: + typedef _Pointer pointer; + pointer __left_; + + _LIBCPP_INLINE_VISIBILITY + __tree_end_node() _NOEXCEPT : __left_() {} +}; + +template <class _VoidPtr> +class __tree_node_base + : public __tree_node_base_types<_VoidPtr>::__end_node_type +{ + typedef __tree_node_base_types<_VoidPtr> _NodeBaseTypes; + +public: + typedef typename _NodeBaseTypes::__node_base_pointer pointer; + typedef typename _NodeBaseTypes::__parent_pointer __parent_pointer; + + pointer __right_; + __parent_pointer __parent_; + bool __is_black_; + + _LIBCPP_INLINE_VISIBILITY + pointer __parent_unsafe() const { return static_cast<pointer>(__parent_);} + + _LIBCPP_INLINE_VISIBILITY + void __set_parent(pointer __p) { + __parent_ = static_cast<__parent_pointer>(__p); + } + +private: + ~__tree_node_base() _LIBCPP_EQUAL_DELETE; + __tree_node_base(__tree_node_base const&) _LIBCPP_EQUAL_DELETE; + __tree_node_base& operator=(__tree_node_base const&) _LIBCPP_EQUAL_DELETE; +}; + +template <class _Tp, class _VoidPtr> +class __tree_node + : public __tree_node_base<_VoidPtr> +{ +public: + typedef _Tp __node_value_type; + + __node_value_type __value_; + +private: + ~__tree_node() _LIBCPP_EQUAL_DELETE; + __tree_node(__tree_node const&) _LIBCPP_EQUAL_DELETE; + __tree_node& operator=(__tree_node const&) _LIBCPP_EQUAL_DELETE; +}; + + +template <class _Allocator> +class __tree_node_destructor +{ + typedef _Allocator allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + +public: + typedef typename __alloc_traits::pointer pointer; +private: + typedef __tree_node_types<pointer> _NodeTypes; + allocator_type& __na_; + + __tree_node_destructor& operator=(const __tree_node_destructor&); + +public: + bool __value_constructed; + + _LIBCPP_INLINE_VISIBILITY + explicit __tree_node_destructor(allocator_type& __na, bool __val = false) _NOEXCEPT + : __na_(__na), + __value_constructed(__val) + {} + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + if (__value_constructed) + __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } + + template <class> friend class __map_node_destructor; +}; + +#if _LIBCPP_STD_VER > 14 +template <class _NodeType, class _Alloc> +struct __generic_container_node_destructor; +template <class _Tp, class _VoidPtr, class _Alloc> +struct __generic_container_node_destructor<__tree_node<_Tp, _VoidPtr>, _Alloc> + : __tree_node_destructor<_Alloc> +{ + using __tree_node_destructor<_Alloc>::__tree_node_destructor; +}; +#endif + +template <class _Tp, class _NodePtr, class _DiffType> +class _LIBCPP_TEMPLATE_VIS __tree_iterator +{ + typedef __tree_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + typedef typename _NodeTypes::__end_node_pointer __end_node_pointer; + typedef typename _NodeTypes::__iter_pointer __iter_pointer; + typedef pointer_traits<__node_pointer> __pointer_traits; + + __iter_pointer __ptr_; + +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef _DiffType difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__node_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY __tree_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __ptr_(nullptr) +#endif + {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const + {return __get_np()->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const + {return pointer_traits<pointer>::pointer_to(__get_np()->__value_);} + + _LIBCPP_INLINE_VISIBILITY + __tree_iterator& operator++() { + __ptr_ = static_cast<__iter_pointer>( + __tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_))); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __tree_iterator operator++(int) + {__tree_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __tree_iterator& operator--() { + __ptr_ = static_cast<__iter_pointer>(__tree_prev_iter<__node_base_pointer>( + static_cast<__end_node_pointer>(__ptr_))); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __tree_iterator operator--(int) + {__tree_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __tree_iterator& __x, const __tree_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y) + {return !(__x == __y);} + +private: + _LIBCPP_INLINE_VISIBILITY + explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} + _LIBCPP_INLINE_VISIBILITY + explicit __tree_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {} + _LIBCPP_INLINE_VISIBILITY + __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } + template <class, class, class> friend class __tree; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __map_iterator; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS set; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS multiset; +}; + +template <class _Tp, class _NodePtr, class _DiffType> +class _LIBCPP_TEMPLATE_VIS __tree_const_iterator +{ + typedef __tree_node_types<_NodePtr> _NodeTypes; + typedef typename _NodeTypes::__node_pointer __node_pointer; + typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + typedef typename _NodeTypes::__end_node_pointer __end_node_pointer; + typedef typename _NodeTypes::__iter_pointer __iter_pointer; + typedef pointer_traits<__node_pointer> __pointer_traits; + + __iter_pointer __ptr_; + +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef _DiffType difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_node_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY __tree_const_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __ptr_(nullptr) +#endif + {} + +private: + typedef __tree_iterator<value_type, __node_pointer, difference_type> + __non_const_iterator; +public: + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT + : __ptr_(__p.__ptr_) {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const + {return __get_np()->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const + {return pointer_traits<pointer>::pointer_to(__get_np()->__value_);} + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator& operator++() { + __ptr_ = static_cast<__iter_pointer>( + __tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_))); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator operator++(int) + {__tree_const_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator& operator--() { + __ptr_ = static_cast<__iter_pointer>(__tree_prev_iter<__node_base_pointer>( + static_cast<__end_node_pointer>(__ptr_))); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator operator--(int) + {__tree_const_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y) + {return !(__x == __y);} + +private: + _LIBCPP_INLINE_VISIBILITY + explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT + : __ptr_(__p) {} + _LIBCPP_INLINE_VISIBILITY + explicit __tree_const_iterator(__end_node_pointer __p) _NOEXCEPT + : __ptr_(__p) {} + _LIBCPP_INLINE_VISIBILITY + __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } + + template <class, class, class> friend class __tree; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS set; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS multiset; + template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; + +}; + +template<class _Tp, class _Compare> +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_DIAGNOSE_WARNING(!std::__invokable<_Compare const&, _Tp const&, _Tp const&>::value, + "the specified comparator type does not provide a viable const call operator") +#endif +int __diagnose_non_const_comparator(); + +template <class _Tp, class _Compare, class _Allocator> +class __tree +{ +public: + typedef _Tp value_type; + typedef _Compare value_compare; + typedef _Allocator allocator_type; + +private: + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __make_tree_node_types<value_type, + typename __alloc_traits::void_pointer>::type + _NodeTypes; + typedef typename _NodeTypes::key_type key_type; +public: + typedef typename _NodeTypes::__node_value_type __node_value_type; + typedef typename _NodeTypes::__container_value_type __container_value_type; + + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + +public: + typedef typename _NodeTypes::__void_pointer __void_pointer; + + typedef typename _NodeTypes::__node_type __node; + typedef typename _NodeTypes::__node_pointer __node_pointer; + + typedef typename _NodeTypes::__node_base_type __node_base; + typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + + typedef typename _NodeTypes::__end_node_type __end_node_t; + typedef typename _NodeTypes::__end_node_pointer __end_node_ptr; + + typedef typename _NodeTypes::__parent_pointer __parent_pointer; + typedef typename _NodeTypes::__iter_pointer __iter_pointer; + + typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + +private: + // check for sane allocator pointer rebinding semantics. Rebinding the + // allocator for a new pointer type should be exactly the same as rebinding + // the pointer using 'pointer_traits'. + static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + typedef typename __rebind_alloc_helper<__node_traits, __node_base>::type + __node_base_allocator; + typedef allocator_traits<__node_base_allocator> __node_base_traits; + static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + +private: + __iter_pointer __begin_node_; + __compressed_pair<__end_node_t, __node_allocator> __pair1_; + __compressed_pair<size_type, value_compare> __pair3_; + +public: + _LIBCPP_INLINE_VISIBILITY + __iter_pointer __end_node() _NOEXCEPT + { + return static_cast<__iter_pointer>( + pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first()) + ); + } + _LIBCPP_INLINE_VISIBILITY + __iter_pointer __end_node() const _NOEXCEPT + { + return static_cast<__iter_pointer>( + pointer_traits<__end_node_ptr>::pointer_to( + const_cast<__end_node_t&>(__pair1_.first()) + ) + ); + } + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __node_alloc() _NOEXCEPT {return __pair1_.second();} +private: + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __node_alloc() const _NOEXCEPT + {return __pair1_.second();} + _LIBCPP_INLINE_VISIBILITY + __iter_pointer& __begin_node() _NOEXCEPT {return __begin_node_;} + _LIBCPP_INLINE_VISIBILITY + const __iter_pointer& __begin_node() const _NOEXCEPT {return __begin_node_;} +public: + _LIBCPP_INLINE_VISIBILITY + allocator_type __alloc() const _NOEXCEPT + {return allocator_type(__node_alloc());} +private: + _LIBCPP_INLINE_VISIBILITY + size_type& size() _NOEXCEPT {return __pair3_.first();} +public: + _LIBCPP_INLINE_VISIBILITY + const size_type& size() const _NOEXCEPT {return __pair3_.first();} + _LIBCPP_INLINE_VISIBILITY + value_compare& value_comp() _NOEXCEPT {return __pair3_.second();} + _LIBCPP_INLINE_VISIBILITY + const value_compare& value_comp() const _NOEXCEPT + {return __pair3_.second();} +public: + + _LIBCPP_INLINE_VISIBILITY + __node_pointer __root() const _NOEXCEPT + {return static_cast<__node_pointer>(__end_node()->__left_);} + + __node_base_pointer* __root_ptr() const _NOEXCEPT { + return _VSTD::addressof(__end_node()->__left_); + } + + typedef __tree_iterator<value_type, __node_pointer, difference_type> iterator; + typedef __tree_const_iterator<value_type, __node_pointer, difference_type> const_iterator; + + explicit __tree(const value_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_copy_constructible<value_compare>::value); + explicit __tree(const allocator_type& __a); + __tree(const value_compare& __comp, const allocator_type& __a); + __tree(const __tree& __t); + __tree& operator=(const __tree& __t); + template <class _InputIterator> + void __assign_unique(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + void __assign_multi(_InputIterator __first, _InputIterator __last); +#ifndef _LIBCPP_CXX03_LANG + __tree(__tree&& __t) + _NOEXCEPT_( + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible<value_compare>::value); + __tree(__tree&& __t, const allocator_type& __a); + __tree& operator=(__tree&& __t) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<value_compare>::value && + is_nothrow_move_assignable<__node_allocator>::value); +#endif // _LIBCPP_CXX03_LANG + + ~__tree(); + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return iterator(__begin_node());} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return const_iterator(__begin_node());} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return iterator(__end_node());} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return const_iterator(__end_node());} + + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + {return std::min<size_type>( + __node_traits::max_size(__node_alloc()), + numeric_limits<difference_type >::max());} + + void clear() _NOEXCEPT; + + void swap(__tree& __t) +#if _LIBCPP_STD_VER <= 11 + _NOEXCEPT_( + __is_nothrow_swappable<value_compare>::value + && (!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) + ); +#else + _NOEXCEPT_(__is_nothrow_swappable<value_compare>::value); +#endif + +#ifndef _LIBCPP_CXX03_LANG + template <class _Key, class ..._Args> + pair<iterator, bool> + __emplace_unique_key_args(_Key const&, _Args&&... __args); + template <class _Key, class ..._Args> + iterator + __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&&...); + + template <class... _Args> + pair<iterator, bool> __emplace_unique_impl(_Args&&... __args); + + template <class... _Args> + iterator __emplace_hint_unique_impl(const_iterator __p, _Args&&... __args); + + template <class... _Args> + iterator __emplace_multi(_Args&&... __args); + + template <class... _Args> + iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique(_Pp&& __x) { + return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x), + __can_extract_key<_Pp, key_type>()); + } + + template <class _First, class _Second> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + __can_extract_map_key<_First, key_type, __container_value_type>::value, + pair<iterator, bool> + >::type __emplace_unique(_First&& __f, _Second&& __s) { + return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f), + _VSTD::forward<_Second>(__s)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique(_Args&&... __args) { + return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { + return __emplace_unique_impl(_VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { + return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { + return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator __emplace_hint_unique(const_iterator __p, _Pp&& __x) { + return __emplace_hint_unique_extract_key(__p, _VSTD::forward<_Pp>(__x), + __can_extract_key<_Pp, key_type>()); + } + + template <class _First, class _Second> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + __can_extract_map_key<_First, key_type, __container_value_type>::value, + iterator + >::type __emplace_hint_unique(const_iterator __p, _First&& __f, _Second&& __s) { + return __emplace_hint_unique_key_args(__p, __f, + _VSTD::forward<_First>(__f), + _VSTD::forward<_Second>(__s)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator __emplace_hint_unique(const_iterator __p, _Args&&... __args) { + return __emplace_hint_unique_impl(__p, _VSTD::forward<_Args>(__args)...); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator + __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_fail_tag) { + return __emplace_hint_unique_impl(__p, _VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator + __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_self_tag) { + return __emplace_hint_unique_key_args(__p, __x, _VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator + __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_first_tag) { + return __emplace_hint_unique_key_args(__p, __x.first, _VSTD::forward<_Pp>(__x)); + } + +#else + template <class _Key, class _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args); + template <class _Key, class _Args> + _LIBCPP_INLINE_VISIBILITY + iterator __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&); +#endif + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __insert_unique(const __container_value_type& __v) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__v), __v); + } + + _LIBCPP_INLINE_VISIBILITY + iterator __insert_unique(const_iterator __p, const __container_value_type& __v) { + return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), __v); + } + +#ifdef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(const __container_value_type& __v); + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(const_iterator __p, const __container_value_type& __v); +#else + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __insert_unique(__container_value_type&& __v) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__v), _VSTD::move(__v)); + } + + _LIBCPP_INLINE_VISIBILITY + iterator __insert_unique(const_iterator __p, __container_value_type&& __v) { + return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), _VSTD::move(__v)); + } + + template <class _Vp, class = typename enable_if< + !is_same<typename __unconstref<_Vp>::type, + __container_value_type + >::value + >::type> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __insert_unique(_Vp&& __v) { + return __emplace_unique(_VSTD::forward<_Vp>(__v)); + } + + template <class _Vp, class = typename enable_if< + !is_same<typename __unconstref<_Vp>::type, + __container_value_type + >::value + >::type> + _LIBCPP_INLINE_VISIBILITY + iterator __insert_unique(const_iterator __p, _Vp&& __v) { + return __emplace_hint_unique(__p, _VSTD::forward<_Vp>(__v)); + } + + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(__container_value_type&& __v) { + return __emplace_multi(_VSTD::move(__v)); + } + + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(const_iterator __p, __container_value_type&& __v) { + return __emplace_hint_multi(__p, _VSTD::move(__v)); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(_Vp&& __v) { + return __emplace_multi(_VSTD::forward<_Vp>(__v)); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(const_iterator __p, _Vp&& __v) { + return __emplace_hint_multi(__p, _VSTD::forward<_Vp>(__v)); + } + +#endif // !_LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __node_insert_unique(__node_pointer __nd); + _LIBCPP_INLINE_VISIBILITY + iterator __node_insert_unique(const_iterator __p, + __node_pointer __nd); + + _LIBCPP_INLINE_VISIBILITY + iterator __node_insert_multi(__node_pointer __nd); + _LIBCPP_INLINE_VISIBILITY + iterator __node_insert_multi(const_iterator __p, __node_pointer __nd); + + + _LIBCPP_INLINE_VISIBILITY iterator + __remove_node_pointer(__node_pointer) _NOEXCEPT; + +#if _LIBCPP_STD_VER > 14 + template <class _NodeHandle, class _InsertReturnType> + _LIBCPP_INLINE_VISIBILITY + _InsertReturnType __node_handle_insert_unique(_NodeHandle&&); + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + iterator __node_handle_insert_unique(const_iterator, _NodeHandle&&); + template <class _Tree> + _LIBCPP_INLINE_VISIBILITY + void __node_handle_merge_unique(_Tree& __source); + + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + iterator __node_handle_insert_multi(_NodeHandle&&); + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + iterator __node_handle_insert_multi(const_iterator, _NodeHandle&&); + template <class _Tree> + _LIBCPP_INLINE_VISIBILITY + void __node_handle_merge_multi(_Tree& __source); + + + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(key_type const&); + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(const_iterator); +#endif + + iterator erase(const_iterator __p); + iterator erase(const_iterator __f, const_iterator __l); + template <class _Key> + size_type __erase_unique(const _Key& __k); + template <class _Key> + size_type __erase_multi(const _Key& __k); + + void __insert_node_at(__parent_pointer __parent, + __node_base_pointer& __child, + __node_base_pointer __new_node) _NOEXCEPT; + + template <class _Key> + iterator find(const _Key& __v); + template <class _Key> + const_iterator find(const _Key& __v) const; + + template <class _Key> + size_type __count_unique(const _Key& __k) const; + template <class _Key> + size_type __count_multi(const _Key& __k) const; + + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + iterator lower_bound(const _Key& __v) + {return __lower_bound(__v, __root(), __end_node());} + template <class _Key> + iterator __lower_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result); + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + const_iterator lower_bound(const _Key& __v) const + {return __lower_bound(__v, __root(), __end_node());} + template <class _Key> + const_iterator __lower_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) const; + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + iterator upper_bound(const _Key& __v) + {return __upper_bound(__v, __root(), __end_node());} + template <class _Key> + iterator __upper_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result); + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + const_iterator upper_bound(const _Key& __v) const + {return __upper_bound(__v, __root(), __end_node());} + template <class _Key> + const_iterator __upper_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) const; + template <class _Key> + pair<iterator, iterator> + __equal_range_unique(const _Key& __k); + template <class _Key> + pair<const_iterator, const_iterator> + __equal_range_unique(const _Key& __k) const; + + template <class _Key> + pair<iterator, iterator> + __equal_range_multi(const _Key& __k); + template <class _Key> + pair<const_iterator, const_iterator> + __equal_range_multi(const _Key& __k) const; + + typedef __tree_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + + __node_holder remove(const_iterator __p) _NOEXCEPT; +private: + __node_base_pointer& + __find_leaf_low(__parent_pointer& __parent, const key_type& __v); + __node_base_pointer& + __find_leaf_high(__parent_pointer& __parent, const key_type& __v); + __node_base_pointer& + __find_leaf(const_iterator __hint, + __parent_pointer& __parent, const key_type& __v); + // FIXME: Make this function const qualified. Unfortunetly doing so + // breaks existing code which uses non-const callable comparators. + template <class _Key> + __node_base_pointer& + __find_equal(__parent_pointer& __parent, const _Key& __v); + template <class _Key> + _LIBCPP_INLINE_VISIBILITY __node_base_pointer& + __find_equal(__parent_pointer& __parent, const _Key& __v) const { + return const_cast<__tree*>(this)->__find_equal(__parent, __v); + } + template <class _Key> + __node_base_pointer& + __find_equal(const_iterator __hint, __parent_pointer& __parent, + __node_base_pointer& __dummy, + const _Key& __v); + +#ifndef _LIBCPP_CXX03_LANG + template <class ..._Args> + __node_holder __construct_node(_Args&& ...__args); +#else + __node_holder __construct_node(const __container_value_type& __v); +#endif + + void destroy(__node_pointer __nd) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __tree& __t) + {__copy_assign_alloc(__t, integral_constant<bool, + __node_traits::propagate_on_container_copy_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __tree& __t, true_type) + { + if (__node_alloc() != __t.__node_alloc()) + clear(); + __node_alloc() = __t.__node_alloc(); + } + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __tree&, false_type) {} + + void __move_assign(__tree& __t, false_type); + void __move_assign(__tree& __t, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value && + is_nothrow_move_assignable<__node_allocator>::value); + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__tree& __t) + _NOEXCEPT_( + !__node_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<__node_allocator>::value) + {__move_assign_alloc(__t, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__tree& __t, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) + {__node_alloc() = _VSTD::move(__t.__node_alloc());} + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {} + + __node_pointer __detach(); + static __node_pointer __detach(__node_pointer); + + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; +}; + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_copy_constructible<value_compare>::value) + : __pair3_(0, __comp) +{ + __begin_node() = __end_node(); +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a) + : __begin_node_(__iter_pointer()), + __pair1_(__second_tag(), __node_allocator(__a)), + __pair3_(0) +{ + __begin_node() = __end_node(); +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, + const allocator_type& __a) + : __begin_node_(__iter_pointer()), + __pair1_(__second_tag(), __node_allocator(__a)), + __pair3_(0, __comp) +{ + __begin_node() = __end_node(); +} + +// Precondition: size() != 0 +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_pointer +__tree<_Tp, _Compare, _Allocator>::__detach() +{ + __node_pointer __cache = static_cast<__node_pointer>(__begin_node()); + __begin_node() = __end_node(); + __end_node()->__left_->__parent_ = nullptr; + __end_node()->__left_ = nullptr; + size() = 0; + // __cache->__left_ == nullptr + if (__cache->__right_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__right_); + // __cache->__left_ == nullptr + // __cache->__right_ == nullptr + return __cache; +} + +// Precondition: __cache != nullptr +// __cache->left_ == nullptr +// __cache->right_ == nullptr +// This is no longer a red-black tree +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_pointer +__tree<_Tp, _Compare, _Allocator>::__detach(__node_pointer __cache) +{ + if (__cache->__parent_ == nullptr) + return nullptr; + if (__tree_is_left_child(static_cast<__node_base_pointer>(__cache))) + { + __cache->__parent_->__left_ = nullptr; + __cache = static_cast<__node_pointer>(__cache->__parent_); + if (__cache->__right_ == nullptr) + return __cache; + return static_cast<__node_pointer>(__tree_leaf(__cache->__right_)); + } + // __cache is right child + __cache->__parent_unsafe()->__right_ = nullptr; + __cache = static_cast<__node_pointer>(__cache->__parent_); + if (__cache->__left_ == nullptr) + return __cache; + return static_cast<__node_pointer>(__tree_leaf(__cache->__left_)); +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>& +__tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) +{ + if (this != &__t) + { + value_comp() = __t.value_comp(); + __copy_assign_alloc(__t); + __assign_multi(__t.begin(), __t.end()); + } + return *this; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _InputIterator> +void +__tree<_Tp, _Compare, _Allocator>::__assign_unique(_InputIterator __first, _InputIterator __last) +{ + typedef iterator_traits<_InputIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value), + "__assign_unique may only be called with the containers value type"); + + if (size() != 0) + { + __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__value_ = *__first; + __node_pointer __next = __detach(__cache); + __node_insert_unique(__cache); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__cache != nullptr) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + } + } + for (; __first != __last; ++__first) + __insert_unique(*__first); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _InputIterator> +void +__tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _InputIterator __last) +{ + typedef iterator_traits<_InputIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value || + is_same<_ItValueType, __node_value_type>::value), + "__assign_multi may only be called with the containers value type" + " or the nodes value type"); + if (size() != 0) + { + __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__value_ = *__first; + __node_pointer __next = __detach(__cache); + __node_insert_multi(__cache); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__cache != nullptr) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + } + } + for (; __first != __last; ++__first) + __insert_multi(_NodeTypes::__get_value(*__first)); +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) + : __begin_node_(__iter_pointer()), + __pair1_(__second_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())), + __pair3_(0, __t.value_comp()) +{ + __begin_node() = __end_node(); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) + _NOEXCEPT_( + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible<value_compare>::value) + : __begin_node_(_VSTD::move(__t.__begin_node_)), + __pair1_(_VSTD::move(__t.__pair1_)), + __pair3_(_VSTD::move(__t.__pair3_)) +{ + if (size() == 0) + __begin_node() = __end_node(); + else + { + __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); + __t.__begin_node() = __t.__end_node(); + __t.__end_node()->__left_ = nullptr; + __t.size() = 0; + } +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a) + : __pair1_(__second_tag(), __node_allocator(__a)), + __pair3_(0, _VSTD::move(__t.value_comp())) +{ + if (__a == __t.__alloc()) + { + if (__t.size() == 0) + __begin_node() = __end_node(); + else + { + __begin_node() = __t.__begin_node(); + __end_node()->__left_ = __t.__end_node()->__left_; + __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); + size() = __t.size(); + __t.__begin_node() = __t.__end_node(); + __t.__end_node()->__left_ = nullptr; + __t.size() = 0; + } + } + else + { + __begin_node() = __end_node(); + } +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value && + is_nothrow_move_assignable<__node_allocator>::value) +{ + destroy(static_cast<__node_pointer>(__end_node()->__left_)); + __begin_node_ = __t.__begin_node_; + __pair1_.first() = __t.__pair1_.first(); + __move_assign_alloc(__t); + __pair3_ = _VSTD::move(__t.__pair3_); + if (size() == 0) + __begin_node() = __end_node(); + else + { + __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); + __t.__begin_node() = __t.__end_node(); + __t.__end_node()->__left_ = nullptr; + __t.size() = 0; + } +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) +{ + if (__node_alloc() == __t.__node_alloc()) + __move_assign(__t, true_type()); + else + { + value_comp() = _VSTD::move(__t.value_comp()); + const_iterator __e = end(); + if (size() != 0) + { + __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + while (__cache != nullptr && __t.size() != 0) + { + __cache->__value_ = _VSTD::move(__t.remove(__t.begin())->__value_); + __node_pointer __next = __detach(__cache); + __node_insert_multi(__cache); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__cache != nullptr) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + } + } + while (__t.size() != 0) + __insert_multi(__e, _NodeTypes::__move(__t.remove(__t.begin())->__value_)); + } +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>& +__tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<value_compare>::value && + is_nothrow_move_assignable<__node_allocator>::value) + +{ + __move_assign(__t, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::~__tree() +{ + static_assert((is_copy_constructible<value_compare>::value), + "Comparator must be copy-constructible."); + destroy(__root()); +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT +{ + if (__nd != nullptr) + { + destroy(static_cast<__node_pointer>(__nd->__left_)); + destroy(static_cast<__node_pointer>(__nd->__right_)); + __node_allocator& __na = __node_alloc(); + __node_traits::destroy(__na, _NodeTypes::__get_ptr(__nd->__value_)); + __node_traits::deallocate(__na, __nd, 1); + } +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) +#if _LIBCPP_STD_VER <= 11 + _NOEXCEPT_( + __is_nothrow_swappable<value_compare>::value + && (!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) + ) +#else + _NOEXCEPT_(__is_nothrow_swappable<value_compare>::value) +#endif +{ + using _VSTD::swap; + swap(__begin_node_, __t.__begin_node_); + swap(__pair1_.first(), __t.__pair1_.first()); + __swap_allocator(__node_alloc(), __t.__node_alloc()); + __pair3_.swap(__t.__pair3_); + if (size() == 0) + __begin_node() = __end_node(); + else + __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); + if (__t.size() == 0) + __t.__begin_node() = __t.__end_node(); + else + __t.__end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__t.__end_node()); +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT +{ + destroy(__root()); + size() = 0; + __begin_node() = __end_node(); + __end_node()->__left_ = nullptr; +} + +// Find lower_bound place to insert +// Set __parent to parent of null leaf +// Return reference to null leaf +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__parent_pointer& __parent, + const key_type& __v) +{ + __node_pointer __nd = __root(); + if (__nd != nullptr) + { + while (true) + { + if (value_comp()(__nd->__value_, __v)) + { + if (__nd->__right_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__right_); + else + { + __parent = static_cast<__parent_pointer>(__nd); + return __nd->__right_; + } + } + else + { + if (__nd->__left_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__left_); + else + { + __parent = static_cast<__parent_pointer>(__nd); + return __parent->__left_; + } + } + } + } + __parent = static_cast<__parent_pointer>(__end_node()); + return __parent->__left_; +} + +// Find upper_bound place to insert +// Set __parent to parent of null leaf +// Return reference to null leaf +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__parent_pointer& __parent, + const key_type& __v) +{ + __node_pointer __nd = __root(); + if (__nd != nullptr) + { + while (true) + { + if (value_comp()(__v, __nd->__value_)) + { + if (__nd->__left_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__left_); + else + { + __parent = static_cast<__parent_pointer>(__nd); + return __parent->__left_; + } + } + else + { + if (__nd->__right_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__right_); + else + { + __parent = static_cast<__parent_pointer>(__nd); + return __nd->__right_; + } + } + } + } + __parent = static_cast<__parent_pointer>(__end_node()); + return __parent->__left_; +} + +// Find leaf place to insert closest to __hint +// First check prior to __hint. +// Next check after __hint. +// Next do O(log N) search. +// Set __parent to parent of null leaf +// Return reference to null leaf +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, + __parent_pointer& __parent, + const key_type& __v) +{ + if (__hint == end() || !value_comp()(*__hint, __v)) // check before + { + // __v <= *__hint + const_iterator __prior = __hint; + if (__prior == begin() || !value_comp()(__v, *--__prior)) + { + // *prev(__hint) <= __v <= *__hint + if (__hint.__ptr_->__left_ == nullptr) + { + __parent = static_cast<__parent_pointer>(__hint.__ptr_); + return __parent->__left_; + } + else + { + __parent = static_cast<__parent_pointer>(__prior.__ptr_); + return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; + } + } + // __v < *prev(__hint) + return __find_leaf_high(__parent, __v); + } + // else __v > *__hint + return __find_leaf_low(__parent, __v); +} + +// Find place to insert if __v doesn't exist +// Set __parent to parent of null leaf +// Return reference to null leaf +// If __v exists, set parent to node of __v and return reference to node of __v +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, + const _Key& __v) +{ + __node_pointer __nd = __root(); + __node_base_pointer* __nd_ptr = __root_ptr(); + if (__nd != nullptr) + { + while (true) + { + if (value_comp()(__v, __nd->__value_)) + { + if (__nd->__left_ != nullptr) { + __nd_ptr = _VSTD::addressof(__nd->__left_); + __nd = static_cast<__node_pointer>(__nd->__left_); + } else { + __parent = static_cast<__parent_pointer>(__nd); + return __parent->__left_; + } + } + else if (value_comp()(__nd->__value_, __v)) + { + if (__nd->__right_ != nullptr) { + __nd_ptr = _VSTD::addressof(__nd->__right_); + __nd = static_cast<__node_pointer>(__nd->__right_); + } else { + __parent = static_cast<__parent_pointer>(__nd); + return __nd->__right_; + } + } + else + { + __parent = static_cast<__parent_pointer>(__nd); + return *__nd_ptr; + } + } + } + __parent = static_cast<__parent_pointer>(__end_node()); + return __parent->__left_; +} + +// Find place to insert if __v doesn't exist +// First check prior to __hint. +// Next check after __hint. +// Next do O(log N) search. +// Set __parent to parent of null leaf +// Return reference to null leaf +// If __v exists, set parent to node of __v and return reference to node of __v +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, + __parent_pointer& __parent, + __node_base_pointer& __dummy, + const _Key& __v) +{ + if (__hint == end() || value_comp()(__v, *__hint)) // check before + { + // __v < *__hint + const_iterator __prior = __hint; + if (__prior == begin() || value_comp()(*--__prior, __v)) + { + // *prev(__hint) < __v < *__hint + if (__hint.__ptr_->__left_ == nullptr) + { + __parent = static_cast<__parent_pointer>(__hint.__ptr_); + return __parent->__left_; + } + else + { + __parent = static_cast<__parent_pointer>(__prior.__ptr_); + return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; + } + } + // __v <= *prev(__hint) + return __find_equal(__parent, __v); + } + else if (value_comp()(*__hint, __v)) // check after + { + // *__hint < __v + const_iterator __next = _VSTD::next(__hint); + if (__next == end() || value_comp()(__v, *__next)) + { + // *__hint < __v < *_VSTD::next(__hint) + if (__hint.__get_np()->__right_ == nullptr) + { + __parent = static_cast<__parent_pointer>(__hint.__ptr_); + return static_cast<__node_base_pointer>(__hint.__ptr_)->__right_; + } + else + { + __parent = static_cast<__parent_pointer>(__next.__ptr_); + return __parent->__left_; + } + } + // *next(__hint) <= __v + return __find_equal(__parent, __v); + } + // else __v == *__hint + __parent = static_cast<__parent_pointer>(__hint.__ptr_); + __dummy = static_cast<__node_base_pointer>(__hint.__ptr_); + return __dummy; +} + +template <class _Tp, class _Compare, class _Allocator> +void __tree<_Tp, _Compare, _Allocator>::__insert_node_at( + __parent_pointer __parent, __node_base_pointer& __child, + __node_base_pointer __new_node) _NOEXCEPT +{ + __new_node->__left_ = nullptr; + __new_node->__right_ = nullptr; + __new_node->__parent_ = __parent; + // __new_node->__is_black_ is initialized in __tree_balance_after_insert + __child = __new_node; + if (__begin_node()->__left_ != nullptr) + __begin_node() = static_cast<__iter_pointer>(__begin_node()->__left_); + __tree_balance_after_insert(__end_node()->__left_, __child); + ++size(); +} + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp, class _Compare, class _Allocator> +template <class _Key, class... _Args> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) +#else +template <class _Tp, class _Compare, class _Allocator> +template <class _Key, class _Args> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args& __args) +#endif +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, __k); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { +#ifndef _LIBCPP_CXX03_LANG + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); +#else + __node_holder __h = __construct_node(__args); +#endif + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __r = __h.release(); + __inserted = true; + } + return pair<iterator, bool>(iterator(__r), __inserted); +} + + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp, class _Compare, class _Allocator> +template <class _Key, class... _Args> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args( + const_iterator __p, _Key const& __k, _Args&&... __args) +#else +template <class _Tp, class _Compare, class _Allocator> +template <class _Key, class _Args> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args( + const_iterator __p, _Key const& __k, _Args& __args) +#endif +{ + __parent_pointer __parent; + __node_base_pointer __dummy; + __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __k); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { +#ifndef _LIBCPP_CXX03_LANG + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); +#else + __node_holder __h = __construct_node(__args); +#endif + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __r = __h.release(); + } + return iterator(__r); +} + + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Compare, class _Allocator> +template <class ..._Args> +typename __tree<_Tp, _Compare, _Allocator>::__node_holder +__tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&& ...__args) +{ + static_assert(!__is_tree_value_type<_Args...>::value, + "Cannot construct from __value_type"); + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...); + __h.get_deleter().__value_constructed = true; + return __h; +} + + +template <class _Tp, class _Compare, class _Allocator> +template <class... _Args> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __parent_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, __h->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __r = __h.release(); + __inserted = true; + } + return pair<iterator, bool>(iterator(__r), __inserted); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class... _Args> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_impl(const_iterator __p, _Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __parent_pointer __parent; + __node_base_pointer __dummy; + __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __h->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __r = __h.release(); + } + return iterator(__r); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class... _Args> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__h->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + return iterator(static_cast<__node_pointer>(__h.release())); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class... _Args> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, + _Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__h->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + return iterator(static_cast<__node_pointer>(__h.release())); +} + + +#else // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_holder +__tree<_Tp, _Compare, _Allocator>::__construct_node(const __container_value_type& __v) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); + __h.get_deleter().__value_constructed = true; + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 +} + +#endif // _LIBCPP_CXX03_LANG + +#ifdef _LIBCPP_CXX03_LANG +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__insert_multi(const __container_value_type& __v) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__v)); + __node_holder __h = __construct_node(__v); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + return iterator(__h.release()); +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const __container_value_type& __v) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__v)); + __node_holder __h = __construct_node(__v); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + return iterator(__h.release()); +} +#endif + +template <class _Tp, class _Compare, class _Allocator> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__node_insert_unique(__node_pointer __nd) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, __nd->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); + __r = __nd; + __inserted = true; + } + return pair<iterator, bool>(iterator(__r), __inserted); +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_insert_unique(const_iterator __p, + __node_pointer __nd) +{ + __parent_pointer __parent; + __node_base_pointer __dummy; + __node_base_pointer& __child = __find_equal(__p, __parent, __nd->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); + __r = __nd; + } + return iterator(__r); +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__nd->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); + return iterator(__nd); +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p, + __node_pointer __nd) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__nd->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); + return iterator(__nd); +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__remove_node_pointer(__node_pointer __ptr) _NOEXCEPT +{ + iterator __r(__ptr); + ++__r; + if (__begin_node() == __ptr) + __begin_node() = __r.__ptr_; + --size(); + __tree_remove(__end_node()->__left_, + static_cast<__node_base_pointer>(__ptr)); + return __r; +} + +#if _LIBCPP_STD_VER > 14 +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle, class _InsertReturnType> +_LIBCPP_INLINE_VISIBILITY +_InsertReturnType +__tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique( + _NodeHandle&& __nh) +{ + if (__nh.empty()) + return _InsertReturnType{end(), false, _NodeHandle()}; + + __node_pointer __ptr = __nh.__ptr_; + __parent_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, + __ptr->__value_); + if (__child != nullptr) + return _InsertReturnType{ + iterator(static_cast<__node_pointer>(__child)), + false, _VSTD::move(__nh)}; + + __insert_node_at(__parent, __child, + static_cast<__node_base_pointer>(__ptr)); + __nh.__release(); + return _InsertReturnType{iterator(__ptr), true, _NodeHandle()}; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique( + const_iterator __hint, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + + __node_pointer __ptr = __nh.__ptr_; + __parent_pointer __parent; + __node_base_pointer __dummy; + __node_base_pointer& __child = __find_equal(__hint, __parent, __dummy, + __ptr->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __insert_node_at(__parent, __child, + static_cast<__node_base_pointer>(__ptr)); + __r = __ptr; + __nh.__release(); + } + return iterator(__r); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +_NodeHandle +__tree<_Tp, _Compare, _Allocator>::__node_handle_extract(key_type const& __key) +{ + iterator __it = find(__key); + if (__it == end()) + return _NodeHandle(); + return __node_handle_extract<_NodeHandle>(__it); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +_NodeHandle +__tree<_Tp, _Compare, _Allocator>::__node_handle_extract(const_iterator __p) +{ + __node_pointer __np = __p.__get_np(); + __remove_node_pointer(__np); + return _NodeHandle(__np, __alloc()); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Tree> +_LIBCPP_INLINE_VISIBILITY +void +__tree<_Tp, _Compare, _Allocator>::__node_handle_merge_unique(_Tree& __source) +{ + static_assert(is_same<typename _Tree::__node_pointer, __node_pointer>::value, ""); + + for (typename _Tree::iterator __i = __source.begin(); + __i != __source.end();) + { + __node_pointer __src_ptr = __i.__get_np(); + __parent_pointer __parent; + __node_base_pointer& __child = + __find_equal(__parent, _NodeTypes::__get_key(__src_ptr->__value_)); + ++__i; + if (__child != nullptr) + continue; + __source.__remove_node_pointer(__src_ptr); + __insert_node_at(__parent, __child, + static_cast<__node_base_pointer>(__src_ptr)); + } +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi(_NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + __node_pointer __ptr = __nh.__ptr_; + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf_high( + __parent, _NodeTypes::__get_key(__ptr->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); + __nh.__release(); + return iterator(__ptr); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi( + const_iterator __hint, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + + __node_pointer __ptr = __nh.__ptr_; + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf(__hint, __parent, + _NodeTypes::__get_key(__ptr->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); + __nh.__release(); + return iterator(__ptr); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Tree> +_LIBCPP_INLINE_VISIBILITY +void +__tree<_Tp, _Compare, _Allocator>::__node_handle_merge_multi(_Tree& __source) +{ + static_assert(is_same<typename _Tree::__node_pointer, __node_pointer>::value, ""); + + for (typename _Tree::iterator __i = __source.begin(); + __i != __source.end();) + { + __node_pointer __src_ptr = __i.__get_np(); + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf_high( + __parent, _NodeTypes::__get_key(__src_ptr->__value_)); + ++__i; + __source.__remove_node_pointer(__src_ptr); + __insert_node_at(__parent, __child, + static_cast<__node_base_pointer>(__src_ptr)); + } +} + +#endif // _LIBCPP_STD_VER > 14 + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) +{ + __node_pointer __np = __p.__get_np(); + iterator __r = __remove_node_pointer(__np); + __node_allocator& __na = __node_alloc(); + __node_traits::destroy(__na, _NodeTypes::__get_ptr( + const_cast<__node_value_type&>(*__p))); + __node_traits::deallocate(__na, __np, 1); + return __r; +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l) +{ + while (__f != __l) + __f = erase(__f); + return iterator(__l.__ptr_); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__erase_unique(const _Key& __k) +{ + iterator __i = find(__k); + if (__i == end()) + return 0; + erase(__i); + return 1; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__erase_multi(const _Key& __k) +{ + pair<iterator, iterator> __p = __equal_range_multi(__k); + size_type __r = 0; + for (; __p.first != __p.second; ++__r) + __p.first = erase(__p.first); + return __r; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) +{ + iterator __p = __lower_bound(__v, __root(), __end_node()); + if (__p != end() && !value_comp()(__v, *__p)) + return __p; + return end(); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) const +{ + const_iterator __p = __lower_bound(__v, __root(), __end_node()); + if (__p != end() && !value_comp()(__v, *__p)) + return __p; + return end(); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const +{ + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return 1; + } + return 0; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const +{ + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _VSTD::distance( + __lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), + __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result) + ); + } + return 0; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) +{ + while (__root != nullptr) + { + if (!value_comp()(__root->__value_, __v)) + { + __result = static_cast<__iter_pointer>(__root); + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return iterator(__result); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) const +{ + while (__root != nullptr) + { + if (!value_comp()(__root->__value_, __v)) + { + __result = static_cast<__iter_pointer>(__root); + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return const_iterator(__result); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) +{ + while (__root != nullptr) + { + if (value_comp()(__v, __root->__value_)) + { + __result = static_cast<__iter_pointer>(__root); + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return iterator(__result); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) const +{ + while (__root != nullptr) + { + if (value_comp()(__v, __root->__value_)) + { + __result = static_cast<__iter_pointer>(__root); + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return const_iterator(__result); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, + typename __tree<_Tp, _Compare, _Allocator>::iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) +{ + typedef pair<iterator, iterator> _Pp; + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _Pp(iterator(__rt), + iterator( + __rt->__right_ != nullptr ? + static_cast<__iter_pointer>(__tree_min(__rt->__right_)) + : __result)); + } + return _Pp(iterator(__result), iterator(__result)); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +pair<typename __tree<_Tp, _Compare, _Allocator>::const_iterator, + typename __tree<_Tp, _Compare, _Allocator>::const_iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const +{ + typedef pair<const_iterator, const_iterator> _Pp; + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _Pp(const_iterator(__rt), + const_iterator( + __rt->__right_ != nullptr ? + static_cast<__iter_pointer>(__tree_min(__rt->__right_)) + : __result)); + } + return _Pp(const_iterator(__result), const_iterator(__result)); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, + typename __tree<_Tp, _Compare, _Allocator>::iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) +{ + typedef pair<iterator, iterator> _Pp; + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), + __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)); + } + return _Pp(iterator(__result), iterator(__result)); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +pair<typename __tree<_Tp, _Compare, _Allocator>::const_iterator, + typename __tree<_Tp, _Compare, _Allocator>::const_iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const +{ + typedef pair<const_iterator, const_iterator> _Pp; + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), + __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)); + } + return _Pp(const_iterator(__result), const_iterator(__result)); +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_holder +__tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT +{ + __node_pointer __np = __p.__get_np(); + if (__begin_node() == __p.__ptr_) + { + if (__np->__right_ != nullptr) + __begin_node() = static_cast<__iter_pointer>(__np->__right_); + else + __begin_node() = static_cast<__iter_pointer>(__np->__parent_); + } + --size(); + __tree_remove(__end_node()->__left_, + static_cast<__node_base_pointer>(__np)); + return __node_holder(__np, _Dp(__node_alloc(), true)); +} + +template <class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__tree<_Tp, _Compare, _Allocator>& __x, + __tree<_Tp, _Compare, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___TREE diff --git a/android/x86/include/v8/libc++/__tuple b/android/x86/include/v8/libc++/__tuple new file mode 100755 index 00000000..0381031b --- /dev/null +++ b/android/x86/include/v8/libc++/__tuple @@ -0,0 +1,550 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___TUPLE +#define _LIBCPP___TUPLE + +#include <__config> +#include <cstddef> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size; + +#if !defined(_LIBCPP_CXX03_LANG) +template <class _Tp, class...> +using __enable_if_tuple_size_imp = _Tp; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< + const _Tp, + typename enable_if<!is_volatile<_Tp>::value>::type, + integral_constant<size_t, sizeof(tuple_size<_Tp>)>>> + : public integral_constant<size_t, tuple_size<_Tp>::value> {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< + volatile _Tp, + typename enable_if<!is_const<_Tp>::value>::type, + integral_constant<size_t, sizeof(tuple_size<_Tp>)>>> + : public integral_constant<size_t, tuple_size<_Tp>::value> {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< + const volatile _Tp, + integral_constant<size_t, sizeof(tuple_size<_Tp>)>>> + : public integral_constant<size_t, tuple_size<_Tp>::value> {}; + +#else +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<const _Tp> : public tuple_size<_Tp> {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<volatile _Tp> : public tuple_size<_Tp> {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<const volatile _Tp> : public tuple_size<_Tp> {}; +#endif + +template <size_t _Ip, class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_element; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> +{ + typedef typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type; +}; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> +{ + typedef typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type; +}; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> +{ + typedef typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type; +}; + +template <class _Tp> struct __tuple_like : false_type {}; + +template <class _Tp> struct __tuple_like<const _Tp> : public __tuple_like<_Tp> {}; +template <class _Tp> struct __tuple_like<volatile _Tp> : public __tuple_like<_Tp> {}; +template <class _Tp> struct __tuple_like<const volatile _Tp> : public __tuple_like<_Tp> {}; + +// tuple specializations + +#ifndef _LIBCPP_CXX03_LANG + +template <size_t...> struct __tuple_indices {}; + +template <class _IdxType, _IdxType... _Values> +struct __integer_sequence { + template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType> + using __convert = _ToIndexSeq<_ToIndexType, _Values...>; + + template <size_t _Sp> + using __to_tuple_indices = __tuple_indices<(_Values + _Sp)...>; +}; + +#if !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) +namespace __detail { + +template<typename _Tp, size_t ..._Extra> struct __repeat; +template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> { + typedef __integer_sequence<_Tp, + _Np..., + sizeof...(_Np) + _Np..., + 2 * sizeof...(_Np) + _Np..., + 3 * sizeof...(_Np) + _Np..., + 4 * sizeof...(_Np) + _Np..., + 5 * sizeof...(_Np) + _Np..., + 6 * sizeof...(_Np) + _Np..., + 7 * sizeof...(_Np) + _Np..., + _Extra...> type; +}; + +template<size_t _Np> struct __parity; +template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {}; + +template<> struct __make<0> { typedef __integer_sequence<size_t> type; }; +template<> struct __make<1> { typedef __integer_sequence<size_t, 0> type; }; +template<> struct __make<2> { typedef __integer_sequence<size_t, 0, 1> type; }; +template<> struct __make<3> { typedef __integer_sequence<size_t, 0, 1, 2> type; }; +template<> struct __make<4> { typedef __integer_sequence<size_t, 0, 1, 2, 3> type; }; +template<> struct __make<5> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4> type; }; +template<> struct __make<6> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; }; +template<> struct __make<7> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; }; + +template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; }; +template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; }; +template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; + +} // namespace detail + +#endif // !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) + +#if __has_builtin(__make_integer_seq) +template <size_t _Ep, size_t _Sp> +using __make_indices_imp = + typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template + __to_tuple_indices<_Sp>; +#else +template <size_t _Ep, size_t _Sp> +using __make_indices_imp = + typename __detail::__make<_Ep - _Sp>::type::template __to_tuple_indices<_Sp>; + +#endif + +template <size_t _Ep, size_t _Sp = 0> +struct __make_tuple_indices +{ + static_assert(_Sp <= _Ep, "__make_tuple_indices input error"); + typedef __make_indices_imp<_Ep, _Sp> type; +}; + + +template <class ..._Tp> class _LIBCPP_TEMPLATE_VIS tuple; + +template <class... _Tp> struct __tuple_like<tuple<_Tp...> > : true_type {}; + +template <class ..._Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_size<tuple<_Tp...> > + : public integral_constant<size_t, sizeof...(_Tp)> +{ +}; + +template <size_t _Ip, class ..._Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(tuple<_Tp...>&) _NOEXCEPT; + +template <size_t _Ip, class ..._Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(const tuple<_Tp...>&) _NOEXCEPT; + +template <size_t _Ip, class ..._Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(tuple<_Tp...>&&) _NOEXCEPT; + +template <size_t _Ip, class ..._Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(const tuple<_Tp...>&&) _NOEXCEPT; + +#endif // !defined(_LIBCPP_CXX03_LANG) + +// pair specializations + +template <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type {}; + +template <size_t _Ip, class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(pair<_T1, _T2>&) _NOEXCEPT; + +template <size_t _Ip, class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(const pair<_T1, _T2>&) _NOEXCEPT; + +#ifndef _LIBCPP_CXX03_LANG +template <size_t _Ip, class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(pair<_T1, _T2>&&) _NOEXCEPT; + +template <size_t _Ip, class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(const pair<_T1, _T2>&&) _NOEXCEPT; +#endif + +// array specializations + +template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array; + +template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {}; + +template <size_t _Ip, class _Tp, size_t _Size> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp& +get(array<_Tp, _Size>&) _NOEXCEPT; + +template <size_t _Ip, class _Tp, size_t _Size> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp& +get(const array<_Tp, _Size>&) _NOEXCEPT; + +#ifndef _LIBCPP_CXX03_LANG +template <size_t _Ip, class _Tp, size_t _Size> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp&& +get(array<_Tp, _Size>&&) _NOEXCEPT; + +template <size_t _Ip, class _Tp, size_t _Size> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp&& +get(const array<_Tp, _Size>&&) _NOEXCEPT; +#endif + +#ifndef _LIBCPP_CXX03_LANG + +// __tuple_types + +template <class ..._Tp> struct __tuple_types {}; + +#if !__has_builtin(__type_pack_element) + +namespace __indexer_detail { + +template <size_t _Idx, class _Tp> +struct __indexed { using type = _Tp; }; + +template <class _Types, class _Indexes> struct __indexer; + +template <class ..._Types, size_t ..._Idx> +struct __indexer<__tuple_types<_Types...>, __tuple_indices<_Idx...>> + : __indexed<_Idx, _Types>... +{}; + +template <size_t _Idx, class _Tp> +__indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&); + +} // namespace __indexer_detail + +template <size_t _Idx, class ..._Types> +using __type_pack_element = typename decltype( + __indexer_detail::__at_index<_Idx>( + __indexer_detail::__indexer< + __tuple_types<_Types...>, + typename __make_tuple_indices<sizeof...(_Types)>::type + >{}) + )::type; +#endif + +template <size_t _Ip, class ..._Types> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>> +{ + static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range"); + typedef __type_pack_element<_Ip, _Types...> type; +}; + + +template <class ..._Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_size<__tuple_types<_Tp...> > + : public integral_constant<size_t, sizeof...(_Tp)> +{ +}; + +template <class... _Tp> struct __tuple_like<__tuple_types<_Tp...> > : true_type {}; + +template <bool _ApplyLV, bool _ApplyConst, bool _ApplyVolatile> +struct __apply_cv_mf; +template <> +struct __apply_cv_mf<false, false, false> { + template <class _Tp> using __apply = _Tp; +}; +template <> +struct __apply_cv_mf<false, true, false> { + template <class _Tp> using __apply = const _Tp; +}; +template <> +struct __apply_cv_mf<false, false, true> { + template <class _Tp> using __apply = volatile _Tp; +}; +template <> +struct __apply_cv_mf<false, true, true> { + template <class _Tp> using __apply = const volatile _Tp; +}; +template <> +struct __apply_cv_mf<true, false, false> { + template <class _Tp> using __apply = _Tp&; +}; +template <> +struct __apply_cv_mf<true, true, false> { + template <class _Tp> using __apply = const _Tp&; +}; +template <> +struct __apply_cv_mf<true, false, true> { + template <class _Tp> using __apply = volatile _Tp&; +}; +template <> +struct __apply_cv_mf<true, true, true> { + template <class _Tp> using __apply = const volatile _Tp&; +}; +template <class _Tp, class _RawTp = typename remove_reference<_Tp>::type> +using __apply_cv_t = __apply_cv_mf< + is_lvalue_reference<_Tp>::value, + is_const<_RawTp>::value, + is_volatile<_RawTp>::value>; + +// __make_tuple_types + +// __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a +// __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep). +// _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>. If _Tuple is a +// lvalue_reference type, then __tuple_types<_Types&...> is the result. + +template <class _TupleTypes, class _TupleIndices> +struct __make_tuple_types_flat; + +template <template <class...> class _Tuple, class ..._Types, size_t ..._Idx> +struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> { + // Specialization for pair, tuple, and __tuple_types + template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>> + using __apply_quals = __tuple_types< + typename _ApplyFn::template __apply<__type_pack_element<_Idx, _Types...>>... + >; +}; + +template <class _Vt, size_t _Np, size_t ..._Idx> +struct __make_tuple_types_flat<array<_Vt, _Np>, __tuple_indices<_Idx...>> { + template <size_t> + using __value_type = _Vt; + template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>> + using __apply_quals = __tuple_types< + typename _ApplyFn::template __apply<__value_type<_Idx>>... + >; +}; + +template <class _Tp, size_t _Ep = tuple_size<typename remove_reference<_Tp>::type>::value, + size_t _Sp = 0, + bool _SameSize = (_Ep == tuple_size<typename remove_reference<_Tp>::type>::value)> +struct __make_tuple_types +{ + static_assert(_Sp <= _Ep, "__make_tuple_types input error"); + using _RawTp = typename remove_cv<typename remove_reference<_Tp>::type>::type; + using _Maker = __make_tuple_types_flat<_RawTp, typename __make_tuple_indices<_Ep, _Sp>::type>; + using type = typename _Maker::template __apply_quals<_Tp>; +}; + +template <class ..._Types, size_t _Ep> +struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> { + typedef __tuple_types<_Types...> type; +}; + +template <class ..._Types, size_t _Ep> +struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> { + typedef __tuple_types<_Types...> type; +}; + +template <bool ..._Preds> +struct __all_dummy; + +template <bool ..._Pred> +using __all = is_same<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>; + +struct __tuple_sfinae_base { + template <template <class, class...> class _Trait, + class ..._LArgs, class ..._RArgs> + static auto __do_test(__tuple_types<_LArgs...>, __tuple_types<_RArgs...>) + -> __all<typename enable_if<_Trait<_LArgs, _RArgs>::value, bool>::type{true}...>; + template <template <class...> class> + static auto __do_test(...) -> false_type; + + template <class _FromArgs, class _ToArgs> + using __constructible = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{})); + template <class _FromArgs, class _ToArgs> + using __convertible = decltype(__do_test<is_convertible>(_FromArgs{}, _ToArgs{})); + template <class _FromArgs, class _ToArgs> + using __assignable = decltype(__do_test<is_assignable>(_ToArgs{}, _FromArgs{})); +}; + +// __tuple_convertible + +template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value, + bool = __tuple_like<_Up>::value> +struct __tuple_convertible + : public false_type {}; + +template <class _Tp, class _Up> +struct __tuple_convertible<_Tp, _Up, true, true> + : public __tuple_sfinae_base::__convertible< + typename __make_tuple_types<_Tp>::type + , typename __make_tuple_types<_Up>::type + > +{}; + +// __tuple_constructible + +template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value, + bool = __tuple_like<_Up>::value> +struct __tuple_constructible + : public false_type {}; + +template <class _Tp, class _Up> +struct __tuple_constructible<_Tp, _Up, true, true> + : public __tuple_sfinae_base::__constructible< + typename __make_tuple_types<_Tp>::type + , typename __make_tuple_types<_Up>::type + > +{}; + +// __tuple_assignable + +template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value, + bool = __tuple_like<_Up>::value> +struct __tuple_assignable + : public false_type {}; + +template <class _Tp, class _Up> +struct __tuple_assignable<_Tp, _Up, true, true> + : public __tuple_sfinae_base::__assignable< + typename __make_tuple_types<_Tp>::type + , typename __make_tuple_types<_Up&>::type + > +{}; + + +template <size_t _Ip, class ..._Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > +{ + typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type; +}; + +#if _LIBCPP_STD_VER > 11 +template <size_t _Ip, class ..._Tp> +using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; +#endif + +template <bool _IsTuple, class _SizeTrait, size_t _Expected> +struct __tuple_like_with_size_imp : false_type {}; + +template <class _SizeTrait, size_t _Expected> +struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected> + : integral_constant<bool, _SizeTrait::value == _Expected> {}; + +template <class _Tuple, size_t _ExpectedSize, + class _RawTuple = typename __uncvref<_Tuple>::type> +using __tuple_like_with_size = __tuple_like_with_size_imp< + __tuple_like<_RawTuple>::value, + tuple_size<_RawTuple>, _ExpectedSize + >; + +struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail { + template <class ...> + static constexpr bool __enable_default() { return false; } + template <class ...> + static constexpr bool __enable_explicit() { return false; } + template <class ...> + static constexpr bool __enable_implicit() { return false; } + template <class ...> + static constexpr bool __enable_assign() { return false; } +}; +#endif // !defined(_LIBCPP_CXX03_LANG) + +#if _LIBCPP_STD_VER > 14 + +template <bool _CanCopy, bool _CanMove> +struct __sfinae_ctor_base {}; +template <> +struct __sfinae_ctor_base<false, false> { + __sfinae_ctor_base() = default; + __sfinae_ctor_base(__sfinae_ctor_base const&) = delete; + __sfinae_ctor_base(__sfinae_ctor_base &&) = delete; + __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; +}; +template <> +struct __sfinae_ctor_base<true, false> { + __sfinae_ctor_base() = default; + __sfinae_ctor_base(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base(__sfinae_ctor_base &&) = delete; + __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; +}; +template <> +struct __sfinae_ctor_base<false, true> { + __sfinae_ctor_base() = default; + __sfinae_ctor_base(__sfinae_ctor_base const&) = delete; + __sfinae_ctor_base(__sfinae_ctor_base &&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; +}; + +template <bool _CanCopy, bool _CanMove> +struct __sfinae_assign_base {}; +template <> +struct __sfinae_assign_base<false, false> { + __sfinae_assign_base() = default; + __sfinae_assign_base(__sfinae_assign_base const&) = default; + __sfinae_assign_base(__sfinae_assign_base &&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete; + __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete; +}; +template <> +struct __sfinae_assign_base<true, false> { + __sfinae_assign_base() = default; + __sfinae_assign_base(__sfinae_assign_base const&) = default; + __sfinae_assign_base(__sfinae_assign_base &&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base const&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete; +}; +template <> +struct __sfinae_assign_base<false, true> { + __sfinae_assign_base() = default; + __sfinae_assign_base(__sfinae_assign_base const&) = default; + __sfinae_assign_base(__sfinae_assign_base &&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete; + __sfinae_assign_base& operator=(__sfinae_assign_base&&) = default; +}; +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___TUPLE diff --git a/android/x86/include/v8/libc++/__undef_macros b/android/x86/include/v8/libc++/__undef_macros new file mode 100755 index 00000000..4923ee6b --- /dev/null +++ b/android/x86/include/v8/libc++/__undef_macros @@ -0,0 +1,33 @@ +// -*- C++ -*- +//===------------------------ __undef_macros ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + + +#ifdef min +#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) +#if defined(_LIBCPP_WARNING) +_LIBCPP_WARNING("macro min is incompatible with C++. Try #define NOMINMAX " + "before any Windows header. #undefing min") +#else +#warning: macro min is incompatible with C++. #undefing min +#endif +#endif +#undef min +#endif + +#ifdef max +#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) +#if defined(_LIBCPP_WARNING) +_LIBCPP_WARNING("macro max is incompatible with C++. Try #define NOMINMAX " + "before any Windows header. #undefing max") +#else +#warning: macro max is incompatible with C++. #undefing max +#endif +#endif +#undef max +#endif diff --git a/android/x86/include/v8/libc++/algorithm b/android/x86/include/v8/libc++/algorithm new file mode 100755 index 00000000..244ae2d5 --- /dev/null +++ b/android/x86/include/v8/libc++/algorithm @@ -0,0 +1,5684 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ALGORITHM +#define _LIBCPP_ALGORITHM + +/* + algorithm synopsis + +#include <initializer_list> + +namespace std +{ + +template <class InputIterator, class Predicate> + constexpr bool // constexpr in C++20 + all_of(InputIterator first, InputIterator last, Predicate pred); + +template <class InputIterator, class Predicate> + constexpr bool // constexpr in C++20 + any_of(InputIterator first, InputIterator last, Predicate pred); + +template <class InputIterator, class Predicate> + constexpr bool // constexpr in C++20 + none_of(InputIterator first, InputIterator last, Predicate pred); + +template <class InputIterator, class Function> + constexpr Function // constexpr in C++20 + for_each(InputIterator first, InputIterator last, Function f); + +template<class InputIterator, class Size, class Function> + constexpr InputIterator // constexpr in C++20 + for_each_n(InputIterator first, Size n, Function f); // C++17 + +template <class InputIterator, class T> + constexpr InputIterator // constexpr in C++20 + find(InputIterator first, InputIterator last, const T& value); + +template <class InputIterator, class Predicate> + constexpr InputIterator // constexpr in C++20 + find_if(InputIterator first, InputIterator last, Predicate pred); + +template<class InputIterator, class Predicate> + InputIterator // constexpr in C++20 + find_if_not(InputIterator first, InputIterator last, Predicate pred); + +template <class ForwardIterator1, class ForwardIterator2> + ForwardIterator1 // constexpr in C++20 + find_end(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); + +template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> + ForwardIterator1 // constexpr in C++20 + find_end(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); + +template <class ForwardIterator1, class ForwardIterator2> + constexpr ForwardIterator1 // constexpr in C++20 + find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); + +template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> + constexpr ForwardIterator1 // constexpr in C++20 + find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); + +template <class ForwardIterator> + constexpr ForwardIterator // constexpr in C++20 + adjacent_find(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class BinaryPredicate> + constexpr ForwardIterator // constexpr in C++20 + adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); + +template <class InputIterator, class T> + constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20 + count(InputIterator first, InputIterator last, const T& value); + +template <class InputIterator, class Predicate> + constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20 + count_if(InputIterator first, InputIterator last, Predicate pred); + +template <class InputIterator1, class InputIterator2> + constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20 + mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); + +template <class InputIterator1, class InputIterator2> + constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20 + mismatch(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2); // **C++14** + +template <class InputIterator1, class InputIterator2, class BinaryPredicate> + constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20 + mismatch(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, BinaryPredicate pred); + +template <class InputIterator1, class InputIterator2, class BinaryPredicate> + constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20 + mismatch(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, + BinaryPredicate pred); // **C++14** + +template <class InputIterator1, class InputIterator2> + constexpr bool // constexpr in C++20 + equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); + +template <class InputIterator1, class InputIterator2> + constexpr bool // constexpr in C++20 + equal(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2); // **C++14** + +template <class InputIterator1, class InputIterator2, class BinaryPredicate> + constexpr bool // constexpr in C++20 + equal(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, BinaryPredicate pred); + +template <class InputIterator1, class InputIterator2, class BinaryPredicate> + constexpr bool // constexpr in C++20 + equal(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, + BinaryPredicate pred); // **C++14** + +template<class ForwardIterator1, class ForwardIterator2> + constexpr bool // constexpr in C++20 + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2); + +template<class ForwardIterator1, class ForwardIterator2> + constexpr bool // constexpr in C++20 + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); // **C++14** + +template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> + constexpr bool // constexpr in C++20 + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, BinaryPredicate pred); + +template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> + constexpr bool // constexpr in C++20 + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, + BinaryPredicate pred); // **C++14** + +template <class ForwardIterator1, class ForwardIterator2> + constexpr ForwardIterator1 // constexpr in C++20 + search(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); + +template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> + constexpr ForwardIterator1 // constexpr in C++20 + search(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); + +template <class ForwardIterator, class Size, class T> + constexpr ForwardIterator // constexpr in C++20 + search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value); + +template <class ForwardIterator, class Size, class T, class BinaryPredicate> + constexpr ForwardIterator // constexpr in C++20 + search_n(ForwardIterator first, ForwardIterator last, + Size count, const T& value, BinaryPredicate pred); + +template <class InputIterator, class OutputIterator> + OutputIterator + copy(InputIterator first, InputIterator last, OutputIterator result); + +template<class InputIterator, class OutputIterator, class Predicate> + OutputIterator + copy_if(InputIterator first, InputIterator last, + OutputIterator result, Predicate pred); + +template<class InputIterator, class Size, class OutputIterator> + OutputIterator + copy_n(InputIterator first, Size n, OutputIterator result); + +template <class BidirectionalIterator1, class BidirectionalIterator2> + BidirectionalIterator2 + copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, + BidirectionalIterator2 result); + +template <class ForwardIterator1, class ForwardIterator2> + ForwardIterator2 + swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); + +template <class ForwardIterator1, class ForwardIterator2> + void + iter_swap(ForwardIterator1 a, ForwardIterator2 b); + +template <class InputIterator, class OutputIterator, class UnaryOperation> + constexpr OutputIterator // constexpr in C++20 + transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op); + +template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation> + constexpr OutputIterator // constexpr in C++20 + transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, + OutputIterator result, BinaryOperation binary_op); + +template <class ForwardIterator, class T> + constexpr void // constexpr in C++20 + replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value); + +template <class ForwardIterator, class Predicate, class T> + constexpr void // constexpr in C++20 + replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value); + +template <class InputIterator, class OutputIterator, class T> + constexpr OutputIterator // constexpr in C++20 + replace_copy(InputIterator first, InputIterator last, OutputIterator result, + const T& old_value, const T& new_value); + +template <class InputIterator, class OutputIterator, class Predicate, class T> + constexpr OutputIterator // constexpr in C++20 + replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value); + +template <class ForwardIterator, class T> + constexpr void // constexpr in C++20 + fill(ForwardIterator first, ForwardIterator last, const T& value); + +template <class OutputIterator, class Size, class T> + constexpr OutputIterator // constexpr in C++20 + fill_n(OutputIterator first, Size n, const T& value); + +template <class ForwardIterator, class Generator> + constexpr void // constexpr in C++20 + generate(ForwardIterator first, ForwardIterator last, Generator gen); + +template <class OutputIterator, class Size, class Generator> + constexpr OutputIterator // constexpr in C++20 + generate_n(OutputIterator first, Size n, Generator gen); + +template <class ForwardIterator, class T> + constexpr ForwardIterator // constexpr in C++20 + remove(ForwardIterator first, ForwardIterator last, const T& value); + +template <class ForwardIterator, class Predicate> + constexpr ForwardIterator // constexpr in C++20 + remove_if(ForwardIterator first, ForwardIterator last, Predicate pred); + +template <class InputIterator, class OutputIterator, class T> + constexpr OutputIterator // constexpr in C++20 + remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value); + +template <class InputIterator, class OutputIterator, class Predicate> + constexpr OutputIterator // constexpr in C++20 + remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred); + +template <class ForwardIterator> + ForwardIterator + unique(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class BinaryPredicate> + ForwardIterator + unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); + +template <class InputIterator, class OutputIterator> + OutputIterator + unique_copy(InputIterator first, InputIterator last, OutputIterator result); + +template <class InputIterator, class OutputIterator, class BinaryPredicate> + OutputIterator + unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred); + +template <class BidirectionalIterator> + void + reverse(BidirectionalIterator first, BidirectionalIterator last); + +template <class BidirectionalIterator, class OutputIterator> + constexpr OutputIterator // constexpr in C++20 + reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result); + +template <class ForwardIterator> + ForwardIterator + rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last); + +template <class ForwardIterator, class OutputIterator> + OutputIterator + rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result); + +template <class RandomAccessIterator> + void + random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17 + +template <class RandomAccessIterator, class RandomNumberGenerator> + void + random_shuffle(RandomAccessIterator first, RandomAccessIterator last, + RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17 + +template<class PopulationIterator, class SampleIterator, + class Distance, class UniformRandomBitGenerator> + SampleIterator sample(PopulationIterator first, PopulationIterator last, + SampleIterator out, Distance n, + UniformRandomBitGenerator&& g); // C++17 + +template<class RandomAccessIterator, class UniformRandomNumberGenerator> + void shuffle(RandomAccessIterator first, RandomAccessIterator last, + UniformRandomNumberGenerator&& g); + +template <class InputIterator, class Predicate> + constexpr bool // constexpr in C++20 + is_partitioned(InputIterator first, InputIterator last, Predicate pred); + +template <class ForwardIterator, class Predicate> + ForwardIterator + partition(ForwardIterator first, ForwardIterator last, Predicate pred); + +template <class InputIterator, class OutputIterator1, + class OutputIterator2, class Predicate> + constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20 + partition_copy(InputIterator first, InputIterator last, + OutputIterator1 out_true, OutputIterator2 out_false, + Predicate pred); + +template <class ForwardIterator, class Predicate> + ForwardIterator + stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred); + +template<class ForwardIterator, class Predicate> + constexpr ForwardIterator // constexpr in C++20 + partition_point(ForwardIterator first, ForwardIterator last, Predicate pred); + +template <class ForwardIterator> + constexpr bool // constexpr in C++20 + is_sorted(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class Compare> + bool + is_sorted(ForwardIterator first, ForwardIterator last, Compare comp); + +template<class ForwardIterator> + constexpr ForwardIterator // constexpr in C++20 + is_sorted_until(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class Compare> + constexpr ForwardIterator // constexpr in C++20 + is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp); + +template <class RandomAccessIterator> + void + sort(RandomAccessIterator first, RandomAccessIterator last); + +template <class RandomAccessIterator, class Compare> + void + sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template <class RandomAccessIterator> + void + stable_sort(RandomAccessIterator first, RandomAccessIterator last); + +template <class RandomAccessIterator, class Compare> + void + stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template <class RandomAccessIterator> + void + partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last); + +template <class RandomAccessIterator, class Compare> + void + partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp); + +template <class InputIterator, class RandomAccessIterator> + RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, + RandomAccessIterator result_first, RandomAccessIterator result_last); + +template <class InputIterator, class RandomAccessIterator, class Compare> + RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, + RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp); + +template <class RandomAccessIterator> + void + nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last); + +template <class RandomAccessIterator, class Compare> + void + nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp); + +template <class ForwardIterator, class T> + constexpr ForwardIterator // constexpr in C++20 + lower_bound(ForwardIterator first, ForwardIterator last, const T& value); + +template <class ForwardIterator, class T, class Compare> + constexpr ForwardIterator // constexpr in C++20 + lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template <class ForwardIterator, class T> + constexpr ForwardIterator // constexpr in C++20 + upper_bound(ForwardIterator first, ForwardIterator last, const T& value); + +template <class ForwardIterator, class T, class Compare> + constexpr ForwardIterator // constexpr in C++20 + upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template <class ForwardIterator, class T> + constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20 + equal_range(ForwardIterator first, ForwardIterator last, const T& value); + +template <class ForwardIterator, class T, class Compare> + constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20 + equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template <class ForwardIterator, class T> + constexpr bool // constexpr in C++20 + binary_search(ForwardIterator first, ForwardIterator last, const T& value); + +template <class ForwardIterator, class T, class Compare> + constexpr bool // constexpr in C++20 + binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template <class InputIterator1, class InputIterator2, class OutputIterator> + OutputIterator + merge(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> + OutputIterator + merge(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template <class BidirectionalIterator> + void + inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last); + +template <class BidirectionalIterator, class Compare> + void + inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp); + +template <class InputIterator1, class InputIterator2> + constexpr bool // constexpr in C++20 + includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); + +template <class InputIterator1, class InputIterator2, class Compare> + constexpr bool // constexpr in C++20 + includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp); + +template <class InputIterator1, class InputIterator2, class OutputIterator> + OutputIterator + set_union(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> + OutputIterator + set_union(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template <class InputIterator1, class InputIterator2, class OutputIterator> + constexpr OutputIterator // constexpr in C++20 + set_intersection(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> + constexpr OutputIterator // constexpr in C++20 + set_intersection(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template <class InputIterator1, class InputIterator2, class OutputIterator> + OutputIterator + set_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> + OutputIterator + set_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template <class InputIterator1, class InputIterator2, class OutputIterator> + OutputIterator + set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> + OutputIterator + set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template <class RandomAccessIterator> + void + push_heap(RandomAccessIterator first, RandomAccessIterator last); + +template <class RandomAccessIterator, class Compare> + void + push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template <class RandomAccessIterator> + void + pop_heap(RandomAccessIterator first, RandomAccessIterator last); + +template <class RandomAccessIterator, class Compare> + void + pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template <class RandomAccessIterator> + void + make_heap(RandomAccessIterator first, RandomAccessIterator last); + +template <class RandomAccessIterator, class Compare> + void + make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template <class RandomAccessIterator> + void + sort_heap(RandomAccessIterator first, RandomAccessIterator last); + +template <class RandomAccessIterator, class Compare> + void + sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template <class RandomAccessIterator> + constexpr bool // constexpr in C++20 + is_heap(RandomAccessIterator first, RandomAccessiterator last); + +template <class RandomAccessIterator, class Compare> + constexpr bool // constexpr in C++20 + is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp); + +template <class RandomAccessIterator> + constexpr RandomAccessIterator // constexpr in C++20 + is_heap_until(RandomAccessIterator first, RandomAccessiterator last); + +template <class RandomAccessIterator, class Compare> + constexpr RandomAccessIterator // constexpr in C++20 + is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp); + +template <class ForwardIterator> + ForwardIterator + min_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14 + +template <class ForwardIterator, class Compare> + ForwardIterator + min_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14 + +template <class T> + const T& + min(const T& a, const T& b); // constexpr in C++14 + +template <class T, class Compare> + const T& + min(const T& a, const T& b, Compare comp); // constexpr in C++14 + +template<class T> + T + min(initializer_list<T> t); // constexpr in C++14 + +template<class T, class Compare> + T + min(initializer_list<T> t, Compare comp); // constexpr in C++14 + +template<class T> + constexpr const T& clamp( const T& v, const T& lo, const T& hi ); // C++17 + +template<class T, class Compare> + constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp ); // C++17 + +template <class ForwardIterator> + ForwardIterator + max_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14 + +template <class ForwardIterator, class Compare> + ForwardIterator + max_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14 + +template <class T> + const T& + max(const T& a, const T& b); // constexpr in C++14 + +template <class T, class Compare> + const T& + max(const T& a, const T& b, Compare comp); // constexpr in C++14 + +template<class T> + T + max(initializer_list<T> t); // constexpr in C++14 + +template<class T, class Compare> + T + max(initializer_list<T> t, Compare comp); // constexpr in C++14 + +template<class ForwardIterator> + pair<ForwardIterator, ForwardIterator> + minmax_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14 + +template<class ForwardIterator, class Compare> + pair<ForwardIterator, ForwardIterator> + minmax_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14 + +template<class T> + pair<const T&, const T&> + minmax(const T& a, const T& b); // constexpr in C++14 + +template<class T, class Compare> + pair<const T&, const T&> + minmax(const T& a, const T& b, Compare comp); // constexpr in C++14 + +template<class T> + pair<T, T> + minmax(initializer_list<T> t); // constexpr in C++14 + +template<class T, class Compare> + pair<T, T> + minmax(initializer_list<T> t, Compare comp); // constexpr in C++14 + +template <class InputIterator1, class InputIterator2> + constexpr bool // constexpr in C++20 + lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); + +template <class InputIterator1, class InputIterator2, class Compare> + constexpr bool // constexpr in C++20 + lexicographical_compare(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, Compare comp); + +template <class BidirectionalIterator> + bool + next_permutation(BidirectionalIterator first, BidirectionalIterator last); + +template <class BidirectionalIterator, class Compare> + bool + next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); + +template <class BidirectionalIterator> + bool + prev_permutation(BidirectionalIterator first, BidirectionalIterator last); + +template <class BidirectionalIterator, class Compare> + bool + prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); + +} // std + +*/ + +#include <__config> +#include <initializer_list> +#include <type_traits> +#include <cstring> +#include <utility> // needed to provide swap_ranges. +#include <memory> +#include <functional> +#include <iterator> +#include <cstddef> +#include <bit> +#include <version> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +// I'd like to replace these with _VSTD::equal_to<void>, but can't because: +// * That only works with C++14 and later, and +// * We haven't included <functional> here. +template <class _T1, class _T2 = _T1> +struct __equal_to +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T2& __y) const {return __x == __y;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T1& __y) const {return __x == __y;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T2& __y) const {return __x == __y;} +}; + +template <class _T1> +struct __equal_to<_T1, _T1> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +}; + +template <class _T1> +struct __equal_to<const _T1, _T1> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +}; + +template <class _T1> +struct __equal_to<_T1, const _T1> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +}; + +template <class _T1, class _T2 = _T1> +struct __less +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;} +}; + +template <class _T1> +struct __less<_T1, _T1> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} +}; + +template <class _T1> +struct __less<const _T1, _T1> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} +}; + +template <class _T1> +struct __less<_T1, const _T1> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} +}; + +template <class _Predicate> +class __invert // invert the sense of a comparison +{ +private: + _Predicate __p_; +public: + _LIBCPP_INLINE_VISIBILITY __invert() {} + + _LIBCPP_INLINE_VISIBILITY + explicit __invert(_Predicate __p) : __p_(__p) {} + + template <class _T1> + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _T1& __x) {return !__p_(__x);} + + template <class _T1, class _T2> + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);} +}; + +// Perform division by two quickly for positive integers (llvm.org/PR39129) + +template <typename _Integral> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + is_integral<_Integral>::value, + _Integral +>::type +__half_positive(_Integral __value) +{ + return static_cast<_Integral>(static_cast<typename make_unsigned<_Integral>::type>(__value) / 2); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + !is_integral<_Tp>::value, + _Tp +>::type +__half_positive(_Tp __value) +{ + return __value / 2; +} + +#ifdef _LIBCPP_DEBUG + +template <class _Compare> +struct __debug_less +{ + _Compare &__comp_; + _LIBCPP_CONSTEXPR_AFTER_CXX17 + __debug_less(_Compare& __c) : __comp_(__c) {} + + template <class _Tp, class _Up> + bool operator()(const _Tp& __x, const _Up& __y) + { + bool __r = __comp_(__x, __y); + if (__r) + __do_compare_assert(0, __y, __x); + return __r; + } + + template <class _Tp, class _Up> + _LIBCPP_CONSTEXPR_AFTER_CXX17 + bool operator()(_Tp& __x, _Up& __y) + { + bool __r = __comp_(__x, __y); + if (__r) + __do_compare_assert(0, __y, __x); + return __r; + } + + template <class _LHS, class _RHS> + _LIBCPP_CONSTEXPR_AFTER_CXX17 + inline _LIBCPP_INLINE_VISIBILITY + decltype((void)_VSTD::declval<_Compare&>()( + _VSTD::declval<_LHS &>(), _VSTD::declval<_RHS &>())) + __do_compare_assert(int, _LHS & __l, _RHS & __r) { + _LIBCPP_ASSERT(!__comp_(__l, __r), + "Comparator does not induce a strict weak ordering"); + } + + template <class _LHS, class _RHS> + _LIBCPP_CONSTEXPR_AFTER_CXX17 + inline _LIBCPP_INLINE_VISIBILITY + void __do_compare_assert(long, _LHS &, _RHS &) {} +}; + +#endif // _LIBCPP_DEBUG + +template <class _Comp> +struct __comp_ref_type { + // Pass the comparator by lvalue reference. Or in debug mode, using a + // debugging wrapper that stores a reference. +#ifndef _LIBCPP_DEBUG + typedef typename add_lvalue_reference<_Comp>::type type; +#else + typedef __debug_less<_Comp> type; +#endif +}; + +// all_of + +template <class _InputIterator, class _Predicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (!__pred(*__first)) + return false; + return true; +} + +// any_of + +template <class _InputIterator, class _Predicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + return true; + return false; +} + +// none_of + +template <class _InputIterator, class _Predicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + return false; + return true; +} + +// for_each + +template <class _InputIterator, class _Function> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_Function +for_each(_InputIterator __first, _InputIterator __last, _Function __f) +{ + for (; __first != __last; ++__first) + __f(*__first); + return __f; +} + +#if _LIBCPP_STD_VER > 14 +// for_each_n + +template <class _InputIterator, class _Size, class _Function> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_InputIterator +for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) +{ + typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; + _IntegralSize __n = __orig_n; + while (__n > 0) + { + __f(*__first); + ++__first; + --__n; + } + return __first; +} +#endif + +// find + +template <class _InputIterator, class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_InputIterator +find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) +{ + for (; __first != __last; ++__first) + if (*__first == __value_) + break; + return __first; +} + +// find_if + +template <class _InputIterator, class _Predicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_InputIterator +find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + break; + return __first; +} + +// find_if_not + +template<class _InputIterator, class _Predicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_InputIterator +find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (!__pred(*__first)) + break; + return __first; +} + +// find_end + +template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 +__find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, + forward_iterator_tag, forward_iterator_tag) +{ + // modeled after search algorithm + _ForwardIterator1 __r = __last1; // __last1 is the "default" answer + if (__first2 == __last2) + return __r; + while (true) + { + while (true) + { + if (__first1 == __last1) // if source exhausted return last correct answer + return __r; // (or __last1 if never found) + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } + // *__first1 matches *__first2, now match elements after here + _ForwardIterator1 __m1 = __first1; + _ForwardIterator2 __m2 = __first2; + while (true) + { + if (++__m2 == __last2) + { // Pattern exhaused, record answer and search for another one + __r = __first1; + ++__first1; + break; + } + if (++__m1 == __last1) // Source exhausted, return last answer + return __r; + if (!__pred(*__m1, *__m2)) // mismatch, restart with a new __first + { + ++__first1; + break; + } // else there is a match, check next elements + } + } +} + +template <class _BinaryPredicate, class _BidirectionalIterator1, class _BidirectionalIterator2> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator1 +__find_end(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1, + _BidirectionalIterator2 __first2, _BidirectionalIterator2 __last2, _BinaryPredicate __pred, + bidirectional_iterator_tag, bidirectional_iterator_tag) +{ + // modeled after search algorithm (in reverse) + if (__first2 == __last2) + return __last1; // Everything matches an empty sequence + _BidirectionalIterator1 __l1 = __last1; + _BidirectionalIterator2 __l2 = __last2; + --__l2; + while (true) + { + // Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks + while (true) + { + if (__first1 == __l1) // return __last1 if no element matches *__first2 + return __last1; + if (__pred(*--__l1, *__l2)) + break; + } + // *__l1 matches *__l2, now match elements before here + _BidirectionalIterator1 __m1 = __l1; + _BidirectionalIterator2 __m2 = __l2; + while (true) + { + if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern) + return __m1; + if (__m1 == __first1) // Otherwise if source exhaused, pattern not found + return __last1; + if (!__pred(*--__m1, *--__m2)) // if there is a mismatch, restart with a new __l1 + { + break; + } // else there is a match, check next elements + } + } +} + +template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 +__find_end(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, + _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag) +{ + // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern + typename iterator_traits<_RandomAccessIterator2>::difference_type __len2 = __last2 - __first2; + if (__len2 == 0) + return __last1; + typename iterator_traits<_RandomAccessIterator1>::difference_type __len1 = __last1 - __first1; + if (__len1 < __len2) + return __last1; + const _RandomAccessIterator1 __s = __first1 + (__len2 - 1); // End of pattern match can't go before here + _RandomAccessIterator1 __l1 = __last1; + _RandomAccessIterator2 __l2 = __last2; + --__l2; + while (true) + { + while (true) + { + if (__s == __l1) + return __last1; + if (__pred(*--__l1, *__l2)) + break; + } + _RandomAccessIterator1 __m1 = __l1; + _RandomAccessIterator2 __m2 = __l2; + while (true) + { + if (__m2 == __first2) + return __m1; + // no need to check range on __m1 because __s guarantees we have enough source + if (!__pred(*--__m1, *--__m2)) + { + break; + } + } + } +} + +template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator1 +find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + return _VSTD::__find_end<typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __last2, __pred, + typename iterator_traits<_ForwardIterator1>::iterator_category(), + typename iterator_traits<_ForwardIterator2>::iterator_category()); +} + +template <class _ForwardIterator1, class _ForwardIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator1 +find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2) +{ + typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} + +// find_first_of + +template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1 +__find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + for (; __first1 != __last1; ++__first1) + for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) + if (__pred(*__first1, *__j)) + return __first1; + return __last1; +} + + +template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator1 +find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred); +} + +template <class _ForwardIterator1, class _ForwardIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator1 +find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2) +{ + typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} + +// adjacent_find + +template <class _ForwardIterator, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (__pred(*__first, *__i)) + return __first; + __first = __i; + } + } + return __last; +} + +template <class _ForwardIterator> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +adjacent_find(_ForwardIterator __first, _ForwardIterator __last) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type __v; + return _VSTD::adjacent_find(__first, __last, __equal_to<__v>()); +} + +// count + +template <class _InputIterator, class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +typename iterator_traits<_InputIterator>::difference_type +count(_InputIterator __first, _InputIterator __last, const _Tp& __value_) +{ + typename iterator_traits<_InputIterator>::difference_type __r(0); + for (; __first != __last; ++__first) + if (*__first == __value_) + ++__r; + return __r; +} + +// count_if + +template <class _InputIterator, class _Predicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +typename iterator_traits<_InputIterator>::difference_type +count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + typename iterator_traits<_InputIterator>::difference_type __r(0); + for (; __first != __last; ++__first) + if (__pred(*__first)) + ++__r; + return __r; +} + +// mismatch + +template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +pair<_InputIterator1, _InputIterator2> +mismatch(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _BinaryPredicate __pred) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) + if (!__pred(*__first1, *__first2)) + break; + return pair<_InputIterator1, _InputIterator2>(__first1, __first2); +} + +template <class _InputIterator1, class _InputIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +pair<_InputIterator1, _InputIterator2> +mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>()); +} + +#if _LIBCPP_STD_VER > 11 +template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +pair<_InputIterator1, _InputIterator2> +mismatch(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, + _BinaryPredicate __pred) +{ + for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2) + if (!__pred(*__first1, *__first2)) + break; + return pair<_InputIterator1, _InputIterator2>(__first1, __first2); +} + +template <class _InputIterator1, class _InputIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +pair<_InputIterator1, _InputIterator2> +mismatch(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return _VSTD::mismatch(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} +#endif + +// equal + +template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) + if (!__pred(*__first1, *__first2)) + return false; + return true; +} + +template <class _InputIterator1, class _InputIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>()); +} + +#if _LIBCPP_STD_VER > 11 +template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +__equal(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred, + input_iterator_tag, input_iterator_tag ) +{ + for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2) + if (!__pred(*__first1, *__first2)) + return false; + return __first1 == __last1 && __first2 == __last2; +} + +template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, + _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag ) +{ + if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2)) + return false; + return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2, + typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __pred ); +} + +template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +equal(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred ) +{ + return _VSTD::__equal<typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __last2, __pred, + typename iterator_traits<_InputIterator1>::iterator_category(), + typename iterator_traits<_InputIterator2>::iterator_category()); +} + +template <class _InputIterator1, class _InputIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +equal(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return _VSTD::__equal(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(), + typename iterator_traits<_InputIterator1>::iterator_category(), + typename iterator_traits<_InputIterator2>::iterator_category()); +} +#endif + +// is_permutation + +template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _BinaryPredicate __pred) +{ +// shorten sequences as much as possible by lopping of any equal prefix + for (; __first1 != __last1; ++__first1, (void) ++__first2) + if (!__pred(*__first1, *__first2)) + break; + if (__first1 == __last1) + return true; + +// __first1 != __last1 && *__first1 != *__first2 + typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1; + _D1 __l1 = _VSTD::distance(__first1, __last1); + if (__l1 == _D1(1)) + return false; + _ForwardIterator2 __last2 = _VSTD::next(__first2, __l1); + // For each element in [f1, l1) see if there are the same number of + // equal elements in [f2, l2) + for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i) + { + // Have we already counted the number of *__i in [f1, l1)? + _ForwardIterator1 __match = __first1; + for (; __match != __i; ++__match) + if (__pred(*__match, *__i)) + break; + if (__match == __i) { + // Count number of *__i in [f2, l2) + _D1 __c2 = 0; + for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) + if (__pred(*__i, *__j)) + ++__c2; + if (__c2 == 0) + return false; + // Count number of *__i in [__i, l1) (we can start with 1) + _D1 __c1 = 1; + for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j) + if (__pred(*__i, *__j)) + ++__c1; + if (__c1 != __c2) + return false; + } + } + return true; +} + +template<class _ForwardIterator1, class _ForwardIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2) +{ + typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>()); +} + +#if _LIBCPP_STD_VER > 11 +template<class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +__is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, + _BinaryPredicate __pred, + forward_iterator_tag, forward_iterator_tag ) +{ +// shorten sequences as much as possible by lopping of any equal prefix + for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2) + if (!__pred(*__first1, *__first2)) + break; + if (__first1 == __last1) + return __first2 == __last2; + else if (__first2 == __last2) + return false; + + typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1; + _D1 __l1 = _VSTD::distance(__first1, __last1); + + typedef typename iterator_traits<_ForwardIterator2>::difference_type _D2; + _D2 __l2 = _VSTD::distance(__first2, __last2); + if (__l1 != __l2) + return false; + + // For each element in [f1, l1) see if there are the same number of + // equal elements in [f2, l2) + for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i) + { + // Have we already counted the number of *__i in [f1, l1)? + _ForwardIterator1 __match = __first1; + for (; __match != __i; ++__match) + if (__pred(*__match, *__i)) + break; + if (__match == __i) { + // Count number of *__i in [f2, l2) + _D1 __c2 = 0; + for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) + if (__pred(*__i, *__j)) + ++__c2; + if (__c2 == 0) + return false; + // Count number of *__i in [__i, l1) (we can start with 1) + _D1 __c1 = 1; + for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j) + if (__pred(*__i, *__j)) + ++__c1; + if (__c1 != __c2) + return false; + } + } + return true; +} + +template<class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +__is_permutation(_RandomAccessIterator1 __first1, _RandomAccessIterator2 __last1, + _RandomAccessIterator1 __first2, _RandomAccessIterator2 __last2, + _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag ) +{ + if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2)) + return false; + return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2, + typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __pred ); +} + +template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, + _BinaryPredicate __pred ) +{ + return _VSTD::__is_permutation<typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __last2, __pred, + typename iterator_traits<_ForwardIterator1>::iterator_category(), + typename iterator_traits<_ForwardIterator2>::iterator_category()); +} + +template<class _ForwardIterator1, class _ForwardIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2) +{ + typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::__is_permutation(__first1, __last1, __first2, __last2, + __equal_to<__v1, __v2>(), + typename iterator_traits<_ForwardIterator1>::iterator_category(), + typename iterator_traits<_ForwardIterator2>::iterator_category()); +} +#endif + +// search +// __search is in <functional> + +template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator1 +search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + return _VSTD::__search<typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __last2, __pred, + typename iterator_traits<_ForwardIterator1>::iterator_category(), + typename iterator_traits<_ForwardIterator2>::iterator_category()) + .first; +} + +template <class _ForwardIterator1, class _ForwardIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator1 +search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2) +{ + typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} + + +#if _LIBCPP_STD_VER > 14 +template <class _ForwardIterator, class _Searcher> +_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s) +{ return __s(__f, __l).first; } +#endif + +// search_n + +template <class _BinaryPredicate, class _ForwardIterator, class _Size, class _Tp> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +__search_n(_ForwardIterator __first, _ForwardIterator __last, + _Size __count, const _Tp& __value_, _BinaryPredicate __pred, forward_iterator_tag) +{ + if (__count <= 0) + return __first; + while (true) + { + // Find first element in sequence that matchs __value_, with a mininum of loop checks + while (true) + { + if (__first == __last) // return __last if no element matches __value_ + return __last; + if (__pred(*__first, __value_)) + break; + ++__first; + } + // *__first matches __value_, now match elements after here + _ForwardIterator __m = __first; + _Size __c(0); + while (true) + { + if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern) + return __first; + if (++__m == __last) // Otherwise if source exhaused, pattern not found + return __last; + if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first + { + __first = __m; + ++__first; + break; + } // else there is a match, check next elements + } + } +} + +template <class _BinaryPredicate, class _RandomAccessIterator, class _Size, class _Tp> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator +__search_n(_RandomAccessIterator __first, _RandomAccessIterator __last, + _Size __count, const _Tp& __value_, _BinaryPredicate __pred, random_access_iterator_tag) +{ + if (__count <= 0) + return __first; + _Size __len = static_cast<_Size>(__last - __first); + if (__len < __count) + return __last; + const _RandomAccessIterator __s = __last - (__count - 1); // Start of pattern match can't go beyond here + while (true) + { + // Find first element in sequence that matchs __value_, with a mininum of loop checks + while (true) + { + if (__first >= __s) // return __last if no element matches __value_ + return __last; + if (__pred(*__first, __value_)) + break; + ++__first; + } + // *__first matches __value_, now match elements after here + _RandomAccessIterator __m = __first; + _Size __c(0); + while (true) + { + if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern) + return __first; + ++__m; // no need to check range on __m because __s guarantees we have enough source + if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first + { + __first = __m; + ++__first; + break; + } // else there is a match, check next elements + } + } +} + +template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +search_n(_ForwardIterator __first, _ForwardIterator __last, + _Size __count, const _Tp& __value_, _BinaryPredicate __pred) +{ + return _VSTD::__search_n<typename add_lvalue_reference<_BinaryPredicate>::type> + (__first, __last, __convert_to_integral(__count), __value_, __pred, + typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +template <class _ForwardIterator, class _Size, class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type __v; + return _VSTD::search_n(__first, __last, __convert_to_integral(__count), + __value_, __equal_to<__v, _Tp>()); +} + +// copy +template <class _Iter> +inline _LIBCPP_INLINE_VISIBILITY +_Iter +__unwrap_iter(_Iter __i) +{ + return __i; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + _Tp* +>::type +__unwrap_iter(move_iterator<_Tp*> __i) +{ + return __i.base(); +} + +#if _LIBCPP_DEBUG_LEVEL < 2 + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + _Tp* +>::type +__unwrap_iter(__wrap_iter<_Tp*> __i) +{ + return __i.base(); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + const _Tp* +>::type +__unwrap_iter(__wrap_iter<const _Tp*> __i) +{ + return __i.base(); +} + +#else + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + __wrap_iter<_Tp*> +>::type +__unwrap_iter(__wrap_iter<_Tp*> __i) +{ + return __i; +} + +#endif // _LIBCPP_DEBUG_LEVEL < 2 + +template <class _InputIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + for (; __first != __last; ++__first, (void) ++__result) + *__result = *__first; + return __result; +} + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same<typename remove_const<_Tp>::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__copy(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast<size_t>(__last - __first); + if (__n > 0) + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result + __n; +} + +template <class _InputIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + return _VSTD::__copy(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); +} + +// copy_backward + +template <class _BidirectionalIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) +{ + while (__first != __last) + *--__result = *--__last; + return __result; +} + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same<typename remove_const<_Tp>::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__copy_backward(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast<size_t>(__last - __first); + if (__n > 0) + { + __result -= __n; + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + } + return __result; +} + +template <class _BidirectionalIterator1, class _BidirectionalIterator2> +inline _LIBCPP_INLINE_VISIBILITY +_BidirectionalIterator2 +copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, + _BidirectionalIterator2 __result) +{ + return _VSTD::__copy_backward(__unwrap_iter(__first), + __unwrap_iter(__last), + __unwrap_iter(__result)); +} + +// copy_if + +template<class _InputIterator, class _OutputIterator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +copy_if(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Predicate __pred) +{ + for (; __first != __last; ++__first) + { + if (__pred(*__first)) + { + *__result = *__first; + ++__result; + } + } + return __result; +} + +// copy_n + +template<class _InputIterator, class _Size, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_input_iterator<_InputIterator>::value && + !__is_random_access_iterator<_InputIterator>::value, + _OutputIterator +>::type +copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) +{ + typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; + _IntegralSize __n = __orig_n; + if (__n > 0) + { + *__result = *__first; + ++__result; + for (--__n; __n > 0; --__n) + { + ++__first; + *__result = *__first; + ++__result; + } + } + return __result; +} + +template<class _InputIterator, class _Size, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_random_access_iterator<_InputIterator>::value, + _OutputIterator +>::type +copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) +{ + typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; + _IntegralSize __n = __orig_n; + return _VSTD::copy(__first, __first + __n, __result); +} + +// move + +template <class _InputIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + for (; __first != __last; ++__first, (void) ++__result) + *__result = _VSTD::move(*__first); + return __result; +} + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same<typename remove_const<_Tp>::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__move(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast<size_t>(__last - __first); + if (__n > 0) + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result + __n; +} + +template <class _InputIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + return _VSTD::__move(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); +} + +// move_backward + +template <class _InputIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__move_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + while (__first != __last) + *--__result = _VSTD::move(*--__last); + return __result; +} + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same<typename remove_const<_Tp>::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__move_backward(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast<size_t>(__last - __first); + if (__n > 0) + { + __result -= __n; + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + } + return __result; +} + +template <class _BidirectionalIterator1, class _BidirectionalIterator2> +inline _LIBCPP_INLINE_VISIBILITY +_BidirectionalIterator2 +move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, + _BidirectionalIterator2 __result) +{ + return _VSTD::__move_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); +} + +// iter_swap + +// moved to <type_traits> for better swap / noexcept support + +// transform + +template <class _InputIterator, class _OutputIterator, class _UnaryOperation> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) +{ + for (; __first != __last; ++__first, (void) ++__result) + *__result = __op(*__first); + return __result; +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _BinaryOperation> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, + _OutputIterator __result, _BinaryOperation __binary_op) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2, ++__result) + *__result = __binary_op(*__first1, *__first2); + return __result; +} + +// replace + +template <class _ForwardIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +void +replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value) +{ + for (; __first != __last; ++__first) + if (*__first == __old_value) + *__first = __new_value; +} + +// replace_if + +template <class _ForwardIterator, class _Predicate, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +void +replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + *__first = __new_value; +} + +// replace_copy + +template <class _InputIterator, class _OutputIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + const _Tp& __old_value, const _Tp& __new_value) +{ + for (; __first != __last; ++__first, (void) ++__result) + if (*__first == __old_value) + *__result = __new_value; + else + *__result = *__first; + return __result; +} + +// replace_copy_if + +template <class _InputIterator, class _OutputIterator, class _Predicate, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + _Predicate __pred, const _Tp& __new_value) +{ + for (; __first != __last; ++__first, (void) ++__result) + if (__pred(*__first)) + *__result = __new_value; + else + *__result = *__first; + return __result; +} + +// fill_n + +template <class _OutputIterator, class _Size, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) +{ + for (; __n > 0; ++__first, (void) --__n) + *__first = __value_; + return __first; +} + +template <class _OutputIterator, class _Size, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) +{ + return _VSTD::__fill_n(__first, __convert_to_integral(__n), __value_); +} + +// fill + +template <class _ForwardIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +void +__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag) +{ + for (; __first != __last; ++__first) + *__first = __value_; +} + +template <class _RandomAccessIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +void +__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag) +{ + _VSTD::fill_n(__first, __last - __first, __value_); +} + +template <class _ForwardIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +void +fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + _VSTD::__fill(__first, __last, __value_, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +// generate + +template <class _ForwardIterator, class _Generator> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +void +generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) +{ + for (; __first != __last; ++__first) + *__first = __gen(); +} + +// generate_n + +template <class _OutputIterator, class _Size, class _Generator> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) +{ + typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; + _IntegralSize __n = __orig_n; + for (; __n > 0; ++__first, (void) --__n) + *__first = __gen(); + return __first; +} + +// remove + +template <class _ForwardIterator, class _Tp> +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + __first = _VSTD::find(__first, __last, __value_); + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (!(*__i == __value_)) + { + *__first = _VSTD::move(*__i); + ++__first; + } + } + } + return __first; +} + +// remove_if + +template <class _ForwardIterator, class _Predicate> +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + __first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type> + (__first, __last, __pred); + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (!__pred(*__i)) + { + *__first = _VSTD::move(*__i); + ++__first; + } + } + } + return __first; +} + +// remove_copy + +template <class _InputIterator, class _OutputIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value_) +{ + for (; __first != __last; ++__first) + { + if (!(*__first == __value_)) + { + *__result = *__first; + ++__result; + } + } + return __result; +} + +// remove_copy_if + +template <class _InputIterator, class _OutputIterator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) +{ + for (; __first != __last; ++__first) + { + if (!__pred(*__first)) + { + *__result = *__first; + ++__result; + } + } + return __result; +} + +// unique + +template <class _ForwardIterator, class _BinaryPredicate> +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) +{ + __first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type> + (__first, __last, __pred); + if (__first != __last) + { + // ... a a ? ... + // f i + _ForwardIterator __i = __first; + for (++__i; ++__i != __last;) + if (!__pred(*__first, *__i)) + *++__first = _VSTD::move(*__i); + ++__first; + } + return __first; +} + +template <class _ForwardIterator> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +unique(_ForwardIterator __first, _ForwardIterator __last) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type __v; + return _VSTD::unique(__first, __last, __equal_to<__v>()); +} + +// unique_copy + +template <class _BinaryPredicate, class _InputIterator, class _OutputIterator> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator +__unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred, + input_iterator_tag, output_iterator_tag) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t(*__first); + *__result = __t; + ++__result; + while (++__first != __last) + { + if (!__pred(__t, *__first)) + { + __t = *__first; + *__result = __t; + ++__result; + } + } + } + return __result; +} + +template <class _BinaryPredicate, class _ForwardIterator, class _OutputIterator> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator +__unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __pred, + forward_iterator_tag, output_iterator_tag) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + *__result = *__i; + ++__result; + while (++__first != __last) + { + if (!__pred(*__i, *__first)) + { + *__result = *__first; + ++__result; + __i = __first; + } + } + } + return __result; +} + +template <class _BinaryPredicate, class _InputIterator, class _ForwardIterator> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +__unique_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result, _BinaryPredicate __pred, + input_iterator_tag, forward_iterator_tag) +{ + if (__first != __last) + { + *__result = *__first; + while (++__first != __last) + if (!__pred(*__result, *__first)) + *++__result = *__first; + ++__result; + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryPredicate> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred) +{ + return _VSTD::__unique_copy<typename add_lvalue_reference<_BinaryPredicate>::type> + (__first, __last, __result, __pred, + typename iterator_traits<_InputIterator>::iterator_category(), + typename iterator_traits<_OutputIterator>::iterator_category()); +} + +template <class _InputIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + typedef typename iterator_traits<_InputIterator>::value_type __v; + return _VSTD::unique_copy(__first, __last, __result, __equal_to<__v>()); +} + +// reverse + +template <class _BidirectionalIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +__reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) +{ + while (__first != __last) + { + if (__first == --__last) + break; + _VSTD::iter_swap(__first, __last); + ++__first; + } +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +__reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) +{ + if (__first != __last) + for (; __first < --__last; ++__first) + _VSTD::iter_swap(__first, __last); +} + +template <class _BidirectionalIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + _VSTD::__reverse(__first, __last, typename iterator_traits<_BidirectionalIterator>::iterator_category()); +} + +// reverse_copy + +template <class _BidirectionalIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) +{ + for (; __first != __last; ++__result) + *__result = *--__last; + return __result; +} + +// rotate + +template <class _ForwardIterator> +_ForwardIterator +__rotate_left(_ForwardIterator __first, _ForwardIterator __last) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; + value_type __tmp = _VSTD::move(*__first); + _ForwardIterator __lm1 = _VSTD::move(_VSTD::next(__first), __last, __first); + *__lm1 = _VSTD::move(__tmp); + return __lm1; +} + +template <class _BidirectionalIterator> +_BidirectionalIterator +__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + _BidirectionalIterator __lm1 = _VSTD::prev(__last); + value_type __tmp = _VSTD::move(*__lm1); + _BidirectionalIterator __fp1 = _VSTD::move_backward(__first, __lm1, __last); + *__first = _VSTD::move(__tmp); + return __fp1; +} + +template <class _ForwardIterator> +_ForwardIterator +__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) +{ + _ForwardIterator __i = __middle; + while (true) + { + swap(*__first, *__i); + ++__first; + if (++__i == __last) + break; + if (__first == __middle) + __middle = __i; + } + _ForwardIterator __r = __first; + if (__first != __middle) + { + __i = __middle; + while (true) + { + swap(*__first, *__i); + ++__first; + if (++__i == __last) + { + if (__first == __middle) + break; + __i = __middle; + } + else if (__first == __middle) + __middle = __i; + } + } + return __r; +} + +template<typename _Integral> +inline _LIBCPP_INLINE_VISIBILITY +_Integral +__algo_gcd(_Integral __x, _Integral __y) +{ + do + { + _Integral __t = __x % __y; + __x = __y; + __y = __t; + } while (__y); + return __x; +} + +template<typename _RandomAccessIterator> +_RandomAccessIterator +__rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + + const difference_type __m1 = __middle - __first; + const difference_type __m2 = __last - __middle; + if (__m1 == __m2) + { + _VSTD::swap_ranges(__first, __middle, __middle); + return __middle; + } + const difference_type __g = _VSTD::__algo_gcd(__m1, __m2); + for (_RandomAccessIterator __p = __first + __g; __p != __first;) + { + value_type __t(_VSTD::move(*--__p)); + _RandomAccessIterator __p1 = __p; + _RandomAccessIterator __p2 = __p1 + __m1; + do + { + *__p1 = _VSTD::move(*__p2); + __p1 = __p2; + const difference_type __d = __last - __p2; + if (__m1 < __d) + __p2 += __m1; + else + __p2 = __first + (__m1 - __d); + } while (__p2 != __p); + *__p1 = _VSTD::move(__t); + } + return __first + __m2; +} + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +__rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, + _VSTD::forward_iterator_tag) +{ + typedef typename _VSTD::iterator_traits<_ForwardIterator>::value_type value_type; + if (_VSTD::is_trivially_move_assignable<value_type>::value) + { + if (_VSTD::next(__first) == __middle) + return _VSTD::__rotate_left(__first, __last); + } + return _VSTD::__rotate_forward(__first, __middle, __last); +} + +template <class _BidirectionalIterator> +inline _LIBCPP_INLINE_VISIBILITY +_BidirectionalIterator +__rotate(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, + _VSTD::bidirectional_iterator_tag) +{ + typedef typename _VSTD::iterator_traits<_BidirectionalIterator>::value_type value_type; + if (_VSTD::is_trivially_move_assignable<value_type>::value) + { + if (_VSTD::next(__first) == __middle) + return _VSTD::__rotate_left(__first, __last); + if (_VSTD::next(__middle) == __last) + return _VSTD::__rotate_right(__first, __last); + } + return _VSTD::__rotate_forward(__first, __middle, __last); +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +_RandomAccessIterator +__rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, + _VSTD::random_access_iterator_tag) +{ + typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::value_type value_type; + if (_VSTD::is_trivially_move_assignable<value_type>::value) + { + if (_VSTD::next(__first) == __middle) + return _VSTD::__rotate_left(__first, __last); + if (_VSTD::next(__middle) == __last) + return _VSTD::__rotate_right(__first, __last); + return _VSTD::__rotate_gcd(__first, __middle, __last); + } + return _VSTD::__rotate_forward(__first, __middle, __last); +} + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) +{ + if (__first == __middle) + return __last; + if (__middle == __last) + return __first; + return _VSTD::__rotate(__first, __middle, __last, + typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category()); +} + +// rotate_copy + +template <class _ForwardIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result) +{ + return _VSTD::copy(__first, __middle, _VSTD::copy(__middle, __last, __result)); +} + +// min_element + +template <class _ForwardIterator, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_ForwardIterator +min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + static_assert(__is_forward_iterator<_ForwardIterator>::value, + "std::min_element requires a ForwardIterator"); + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + if (__comp(*__i, *__first)) + __first = __i; + } + return __first; +} + +template <class _ForwardIterator> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_ForwardIterator +min_element(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::min_element(__first, __last, + __less<typename iterator_traits<_ForwardIterator>::value_type>()); +} + +// min + +template <class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp& +min(const _Tp& __a, const _Tp& __b, _Compare __comp) +{ + return __comp(__b, __a) ? __b : __a; +} + +template <class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp& +min(const _Tp& __a, const _Tp& __b) +{ + return _VSTD::min(__a, __b, __less<_Tp>()); +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp +min(initializer_list<_Tp> __t, _Compare __comp) +{ + return *_VSTD::min_element(__t.begin(), __t.end(), __comp); +} + +template<class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp +min(initializer_list<_Tp> __t) +{ + return *_VSTD::min_element(__t.begin(), __t.end(), __less<_Tp>()); +} + +#endif // _LIBCPP_CXX03_LANG + +// max_element + +template <class _ForwardIterator, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_ForwardIterator +max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + static_assert(__is_forward_iterator<_ForwardIterator>::value, + "std::max_element requires a ForwardIterator"); + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + if (__comp(*__first, *__i)) + __first = __i; + } + return __first; +} + + +template <class _ForwardIterator> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_ForwardIterator +max_element(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::max_element(__first, __last, + __less<typename iterator_traits<_ForwardIterator>::value_type>()); +} + +// max + +template <class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp& +max(const _Tp& __a, const _Tp& __b, _Compare __comp) +{ + return __comp(__a, __b) ? __b : __a; +} + +template <class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp& +max(const _Tp& __a, const _Tp& __b) +{ + return _VSTD::max(__a, __b, __less<_Tp>()); +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp +max(initializer_list<_Tp> __t, _Compare __comp) +{ + return *_VSTD::max_element(__t.begin(), __t.end(), __comp); +} + +template<class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp +max(initializer_list<_Tp> __t) +{ + return *_VSTD::max_element(__t.begin(), __t.end(), __less<_Tp>()); +} + +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 14 +// clamp +template<class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +const _Tp& +clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp) +{ + _LIBCPP_ASSERT(!__comp(__hi, __lo), "Bad bounds passed to std::clamp"); + return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v; + +} + +template<class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +const _Tp& +clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi) +{ + return _VSTD::clamp(__v, __lo, __hi, __less<_Tp>()); +} +#endif + +// minmax_element + +template <class _ForwardIterator, class _Compare> +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX11 +std::pair<_ForwardIterator, _ForwardIterator> +minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + static_assert(__is_forward_iterator<_ForwardIterator>::value, + "std::minmax_element requires a ForwardIterator"); + std::pair<_ForwardIterator, _ForwardIterator> __result(__first, __first); + if (__first != __last) + { + if (++__first != __last) + { + if (__comp(*__first, *__result.first)) + __result.first = __first; + else + __result.second = __first; + while (++__first != __last) + { + _ForwardIterator __i = __first; + if (++__first == __last) + { + if (__comp(*__i, *__result.first)) + __result.first = __i; + else if (!__comp(*__i, *__result.second)) + __result.second = __i; + break; + } + else + { + if (__comp(*__first, *__i)) + { + if (__comp(*__first, *__result.first)) + __result.first = __first; + if (!__comp(*__i, *__result.second)) + __result.second = __i; + } + else + { + if (__comp(*__i, *__result.first)) + __result.first = __i; + if (!__comp(*__first, *__result.second)) + __result.second = __first; + } + } + } + } + } + return __result; +} + +template <class _ForwardIterator> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +std::pair<_ForwardIterator, _ForwardIterator> +minmax_element(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::minmax_element(__first, __last, + __less<typename iterator_traits<_ForwardIterator>::value_type>()); +} + +// minmax + +template<class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +pair<const _Tp&, const _Tp&> +minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) +{ + return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) : + pair<const _Tp&, const _Tp&>(__a, __b); +} + +template<class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +pair<const _Tp&, const _Tp&> +minmax(const _Tp& __a, const _Tp& __b) +{ + return _VSTD::minmax(__a, __b, __less<_Tp>()); +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +pair<_Tp, _Tp> +minmax(initializer_list<_Tp> __t, _Compare __comp) +{ + typedef typename initializer_list<_Tp>::const_iterator _Iter; + _Iter __first = __t.begin(); + _Iter __last = __t.end(); + std::pair<_Tp, _Tp> __result(*__first, *__first); + + ++__first; + if (__t.size() % 2 == 0) + { + if (__comp(*__first, __result.first)) + __result.first = *__first; + else + __result.second = *__first; + ++__first; + } + + while (__first != __last) + { + _Tp __prev = *__first++; + if (__comp(*__first, __prev)) { + if ( __comp(*__first, __result.first)) __result.first = *__first; + if (!__comp(__prev, __result.second)) __result.second = __prev; + } + else { + if ( __comp(__prev, __result.first)) __result.first = __prev; + if (!__comp(*__first, __result.second)) __result.second = *__first; + } + + __first++; + } + return __result; +} + +template<class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +pair<_Tp, _Tp> +minmax(initializer_list<_Tp> __t) +{ + return _VSTD::minmax(__t, __less<_Tp>()); +} + +#endif // _LIBCPP_CXX03_LANG + +// random_shuffle + +// __independent_bits_engine + +template <unsigned long long _Xp, size_t _Rp> +struct __log2_imp +{ + static const size_t value = _Xp & ((unsigned long long)(1) << _Rp) ? _Rp + : __log2_imp<_Xp, _Rp - 1>::value; +}; + +template <unsigned long long _Xp> +struct __log2_imp<_Xp, 0> +{ + static const size_t value = 0; +}; + +template <size_t _Rp> +struct __log2_imp<0, _Rp> +{ + static const size_t value = _Rp + 1; +}; + +template <class _UIntType, _UIntType _Xp> +struct __log2 +{ + static const size_t value = __log2_imp<_Xp, + sizeof(_UIntType) * __CHAR_BIT__ - 1>::value; +}; + +template<class _Engine, class _UIntType> +class __independent_bits_engine +{ +public: + // types + typedef _UIntType result_type; + +private: + typedef typename _Engine::result_type _Engine_result_type; + typedef typename conditional + < + sizeof(_Engine_result_type) <= sizeof(result_type), + result_type, + _Engine_result_type + >::type _Working_result_type; + + _Engine& __e_; + size_t __w_; + size_t __w0_; + size_t __n_; + size_t __n0_; + _Working_result_type __y0_; + _Working_result_type __y1_; + _Engine_result_type __mask0_; + _Engine_result_type __mask1_; + +#ifdef _LIBCPP_CXX03_LANG + static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min + + _Working_result_type(1); +#else + static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() + + _Working_result_type(1); +#endif + static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; + static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; + static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; + +public: + // constructors and seeding functions + __independent_bits_engine(_Engine& __e, size_t __w); + + // generating functions + result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} + +private: + result_type __eval(false_type); + result_type __eval(true_type); +}; + +template<class _Engine, class _UIntType> +__independent_bits_engine<_Engine, _UIntType> + ::__independent_bits_engine(_Engine& __e, size_t __w) + : __e_(__e), + __w_(__w) +{ + __n_ = __w_ / __m + (__w_ % __m != 0); + __w0_ = __w_ / __n_; + if (_Rp == 0) + __y0_ = _Rp; + else if (__w0_ < _WDt) + __y0_ = (_Rp >> __w0_) << __w0_; + else + __y0_ = 0; + if (_Rp - __y0_ > __y0_ / __n_) + { + ++__n_; + __w0_ = __w_ / __n_; + if (__w0_ < _WDt) + __y0_ = (_Rp >> __w0_) << __w0_; + else + __y0_ = 0; + } + __n0_ = __n_ - __w_ % __n_; + if (__w0_ < _WDt - 1) + __y1_ = (_Rp >> (__w0_ + 1)) << (__w0_ + 1); + else + __y1_ = 0; + __mask0_ = __w0_ > 0 ? _Engine_result_type(~0) >> (_EDt - __w0_) : + _Engine_result_type(0); + __mask1_ = __w0_ < _EDt - 1 ? + _Engine_result_type(~0) >> (_EDt - (__w0_ + 1)) : + _Engine_result_type(~0); +} + +template<class _Engine, class _UIntType> +inline +_UIntType +__independent_bits_engine<_Engine, _UIntType>::__eval(false_type) +{ + return static_cast<result_type>(__e_() & __mask0_); +} + +template<class _Engine, class _UIntType> +_UIntType +__independent_bits_engine<_Engine, _UIntType>::__eval(true_type) +{ + const size_t _WRt = numeric_limits<result_type>::digits; + result_type _Sp = 0; + for (size_t __k = 0; __k < __n0_; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y0_); + if (__w0_ < _WRt) + _Sp <<= __w0_; + else + _Sp = 0; + _Sp += __u & __mask0_; + } + for (size_t __k = __n0_; __k < __n_; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y1_); + if (__w0_ < _WRt - 1) + _Sp <<= __w0_ + 1; + else + _Sp = 0; + _Sp += __u & __mask1_; + } + return _Sp; +} + +// uniform_int_distribution + +template<class _IntType = int> +class uniform_int_distribution +{ +public: + // types + typedef _IntType result_type; + + class param_type + { + result_type __a_; + result_type __b_; + public: + typedef uniform_int_distribution distribution_type; + + explicit param_type(result_type __a = 0, + result_type __b = numeric_limits<result_type>::max()) + : __a_(__a), __b_(__b) {} + + result_type a() const {return __a_;} + result_type b() const {return __b_;} + + friend bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions + explicit uniform_int_distribution(result_type __a = 0, + result_type __b = numeric_limits<result_type>::max()) + : __p_(param_type(__a, __b)) {} + explicit uniform_int_distribution(const param_type& __p) : __p_(__p) {} + void reset() {} + + // generating functions + template<class _URNG> result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + result_type a() const {return __p_.a();} + result_type b() const {return __p_.b();} + + param_type param() const {return __p_;} + void param(const param_type& __p) {__p_ = __p;} + + result_type min() const {return a();} + result_type max() const {return b();} + + friend bool operator==(const uniform_int_distribution& __x, + const uniform_int_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend bool operator!=(const uniform_int_distribution& __x, + const uniform_int_distribution& __y) + {return !(__x == __y);} +}; + +template<class _IntType> +template<class _URNG> +typename uniform_int_distribution<_IntType>::result_type +uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) +_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ + typedef typename conditional<sizeof(result_type) <= sizeof(uint32_t), + uint32_t, uint64_t>::type _UIntType; + const _UIntType _Rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1); + if (_Rp == 1) + return __p.a(); + const size_t _Dt = numeric_limits<_UIntType>::digits; + typedef __independent_bits_engine<_URNG, _UIntType> _Eng; + if (_Rp == 0) + return static_cast<result_type>(_Eng(__g, _Dt)()); + size_t __w = _Dt - __clz(_Rp) - 1; + if ((_Rp & (std::numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0) + ++__w; + _Eng __e(__g, __w); + _UIntType __u; + do + { + __u = __e(); + } while (__u >= _Rp); + return static_cast<result_type>(__u + __p.a()); +} + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) \ + || defined(_LIBCPP_BUILDING_LIBRARY) +class _LIBCPP_TYPE_VIS __rs_default; + +_LIBCPP_FUNC_VIS __rs_default __rs_get(); + +class _LIBCPP_TYPE_VIS __rs_default +{ + static unsigned __c_; + + __rs_default(); +public: + typedef uint_fast32_t result_type; + + static const result_type _Min = 0; + static const result_type _Max = 0xFFFFFFFF; + + __rs_default(const __rs_default&); + ~__rs_default(); + + result_type operator()(); + + static _LIBCPP_CONSTEXPR result_type min() {return _Min;} + static _LIBCPP_CONSTEXPR result_type max() {return _Max;} + + friend _LIBCPP_FUNC_VIS __rs_default __rs_get(); +}; + +_LIBCPP_FUNC_VIS __rs_default __rs_get(); + +template <class _RandomAccessIterator> +_LIBCPP_DEPRECATED_IN_CXX14 void +random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef uniform_int_distribution<ptrdiff_t> _Dp; + typedef typename _Dp::param_type _Pp; + difference_type __d = __last - __first; + if (__d > 1) + { + _Dp __uid; + __rs_default __g = __rs_get(); + for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d) + { + difference_type __i = __uid(__g, _Pp(0, __d)); + if (__i != difference_type(0)) + swap(*__first, *(__first + __i)); + } + } +} + +template <class _RandomAccessIterator, class _RandomNumberGenerator> +_LIBCPP_DEPRECATED_IN_CXX14 void +random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, +#ifndef _LIBCPP_CXX03_LANG + _RandomNumberGenerator&& __rand) +#else + _RandomNumberGenerator& __rand) +#endif +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __d = __last - __first; + if (__d > 1) + { + for (--__last; __first < __last; ++__first, (void) --__d) + { + difference_type __i = __rand(__d); + if (__i != difference_type(0)) + swap(*__first, *(__first + __i)); + } + } +} +#endif + +template <class _PopulationIterator, class _SampleIterator, class _Distance, + class _UniformRandomNumberGenerator> +_LIBCPP_INLINE_VISIBILITY +_SampleIterator __sample(_PopulationIterator __first, + _PopulationIterator __last, _SampleIterator __output_iter, + _Distance __n, + _UniformRandomNumberGenerator & __g, + input_iterator_tag) { + + _Distance __k = 0; + for (; __first != __last && __k < __n; ++__first, (void)++__k) + __output_iter[__k] = *__first; + _Distance __sz = __k; + for (; __first != __last; ++__first, (void)++__k) { + _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, __k)(__g); + if (__r < __sz) + __output_iter[__r] = *__first; + } + return __output_iter + _VSTD::min(__n, __k); +} + +template <class _PopulationIterator, class _SampleIterator, class _Distance, + class _UniformRandomNumberGenerator> +_LIBCPP_INLINE_VISIBILITY +_SampleIterator __sample(_PopulationIterator __first, + _PopulationIterator __last, _SampleIterator __output_iter, + _Distance __n, + _UniformRandomNumberGenerator& __g, + forward_iterator_tag) { + _Distance __unsampled_sz = _VSTD::distance(__first, __last); + for (__n = _VSTD::min(__n, __unsampled_sz); __n != 0; ++__first) { + _Distance __r = + _VSTD::uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g); + if (__r < __n) { + *__output_iter++ = *__first; + --__n; + } + } + return __output_iter; +} + +template <class _PopulationIterator, class _SampleIterator, class _Distance, + class _UniformRandomNumberGenerator> +_LIBCPP_INLINE_VISIBILITY +_SampleIterator __sample(_PopulationIterator __first, + _PopulationIterator __last, _SampleIterator __output_iter, + _Distance __n, _UniformRandomNumberGenerator& __g) { + typedef typename iterator_traits<_PopulationIterator>::iterator_category + _PopCategory; + typedef typename iterator_traits<_PopulationIterator>::difference_type + _Difference; + static_assert(__is_forward_iterator<_PopulationIterator>::value || + __is_random_access_iterator<_SampleIterator>::value, + "SampleIterator must meet the requirements of RandomAccessIterator"); + typedef typename common_type<_Distance, _Difference>::type _CommonType; + _LIBCPP_ASSERT(__n >= 0, "N must be a positive number."); + return _VSTD::__sample( + __first, __last, __output_iter, _CommonType(__n), + __g, _PopCategory()); +} + +#if _LIBCPP_STD_VER > 14 +template <class _PopulationIterator, class _SampleIterator, class _Distance, + class _UniformRandomNumberGenerator> +inline _LIBCPP_INLINE_VISIBILITY +_SampleIterator sample(_PopulationIterator __first, + _PopulationIterator __last, _SampleIterator __output_iter, + _Distance __n, _UniformRandomNumberGenerator&& __g) { + return _VSTD::__sample(__first, __last, __output_iter, __n, __g); +} +#endif // _LIBCPP_STD_VER > 14 + +template<class _RandomAccessIterator, class _UniformRandomNumberGenerator> + void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, +#ifndef _LIBCPP_CXX03_LANG + _UniformRandomNumberGenerator&& __g) +#else + _UniformRandomNumberGenerator& __g) +#endif +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef uniform_int_distribution<ptrdiff_t> _Dp; + typedef typename _Dp::param_type _Pp; + difference_type __d = __last - __first; + if (__d > 1) + { + _Dp __uid; + for (--__last, --__d; __first < __last; ++__first, --__d) + { + difference_type __i = __uid(__g, _Pp(0, __d)); + if (__i != difference_type(0)) + swap(*__first, *(__first + __i)); + } + } +} + +template <class _InputIterator, class _Predicate> +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool +is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (!__pred(*__first)) + break; + if ( __first == __last ) + return true; + ++__first; + for (; __first != __last; ++__first) + if (__pred(*__first)) + return false; + return true; +} + +// partition + +template <class _Predicate, class _ForwardIterator> +_ForwardIterator +__partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) +{ + while (true) + { + if (__first == __last) + return __first; + if (!__pred(*__first)) + break; + ++__first; + } + for (_ForwardIterator __p = __first; ++__p != __last;) + { + if (__pred(*__p)) + { + swap(*__first, *__p); + ++__first; + } + } + return __first; +} + +template <class _Predicate, class _BidirectionalIterator> +_BidirectionalIterator +__partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, + bidirectional_iterator_tag) +{ + while (true) + { + while (true) + { + if (__first == __last) + return __first; + if (!__pred(*__first)) + break; + ++__first; + } + do + { + if (__first == --__last) + return __first; + } while (!__pred(*__last)); + swap(*__first, *__last); + ++__first; + } +} + +template <class _ForwardIterator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + return _VSTD::__partition<typename add_lvalue_reference<_Predicate>::type> + (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +// partition_copy + +template <class _InputIterator, class _OutputIterator1, + class _OutputIterator2, class _Predicate> +_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_OutputIterator1, _OutputIterator2> +partition_copy(_InputIterator __first, _InputIterator __last, + _OutputIterator1 __out_true, _OutputIterator2 __out_false, + _Predicate __pred) +{ + for (; __first != __last; ++__first) + { + if (__pred(*__first)) + { + *__out_true = *__first; + ++__out_true; + } + else + { + *__out_false = *__first; + ++__out_false; + } + } + return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false); +} + +// partition_point + +template<class _ForwardIterator, class _Predicate> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + difference_type __len = _VSTD::distance(__first, __last); + while (__len != 0) + { + difference_type __l2 = _VSTD::__half_positive(__len); + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__pred(*__m)) + { + __first = ++__m; + __len -= __l2 + 1; + } + else + __len = __l2; + } + return __first; +} + +// stable_partition + +template <class _Predicate, class _ForwardIterator, class _Distance, class _Pair> +_ForwardIterator +__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, + _Distance __len, _Pair __p, forward_iterator_tag __fit) +{ + // *__first is known to be false + // __len >= 1 + if (__len == 1) + return __first; + if (__len == 2) + { + _ForwardIterator __m = __first; + if (__pred(*++__m)) + { + swap(*__first, *__m); + return __m; + } + return __first; + } + if (__len <= __p.second) + { // The buffer is big enough to use + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; + __destruct_n __d(0); + unique_ptr<value_type, __destruct_n&> __h(__p.first, __d); + // Move the falses into the temporary buffer, and the trues to the front of the line + // Update __first to always point to the end of the trues + value_type* __t = __p.first; + ::new(__t) value_type(_VSTD::move(*__first)); + __d.__incr((value_type*)0); + ++__t; + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (__pred(*__i)) + { + *__first = _VSTD::move(*__i); + ++__first; + } + else + { + ::new(__t) value_type(_VSTD::move(*__i)); + __d.__incr((value_type*)0); + ++__t; + } + } + // All trues now at start of range, all falses in buffer + // Move falses back into range, but don't mess up __first which points to first false + __i = __first; + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) + *__i = _VSTD::move(*__t2); + // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer + return __first; + } + // Else not enough buffer, do in place + // __len >= 3 + _ForwardIterator __m = __first; + _Distance __len2 = __len / 2; // __len2 >= 2 + _VSTD::advance(__m, __len2); + // recurse on [__first, __m), *__first know to be false + // F????????????????? + // f m l + typedef typename add_lvalue_reference<_Predicate>::type _PredRef; + _ForwardIterator __first_false = __stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit); + // TTTFFFFF?????????? + // f ff m l + // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true + _ForwardIterator __m1 = __m; + _ForwardIterator __second_false = __last; + _Distance __len_half = __len - __len2; + while (__pred(*__m1)) + { + if (++__m1 == __last) + goto __second_half_done; + --__len_half; + } + // TTTFFFFFTTTF?????? + // f ff m m1 l + __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit); +__second_half_done: + // TTTFFFFFTTTTTFFFFF + // f ff m sf l + return _VSTD::rotate(__first_false, __m, __second_false); + // TTTTTTTTFFFFFFFFFF + // | +} + +struct __return_temporary_buffer +{ + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_VSTD::return_temporary_buffer(__p);} +}; + +template <class _Predicate, class _ForwardIterator> +_ForwardIterator +__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, + forward_iterator_tag) +{ + const unsigned __alloc_limit = 3; // might want to make this a function of trivial assignment + // Either prove all true and return __first or point to first false + while (true) + { + if (__first == __last) + return __first; + if (!__pred(*__first)) + break; + ++__first; + } + // We now have a reduced range [__first, __last) + // *__first is known to be false + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; + difference_type __len = _VSTD::distance(__first, __last); + pair<value_type*, ptrdiff_t> __p(0, 0); + unique_ptr<value_type, __return_temporary_buffer> __h; + if (__len >= __alloc_limit) + { + __p = _VSTD::get_temporary_buffer<value_type>(__len); + __h.reset(__p.first); + } + return __stable_partition<typename add_lvalue_reference<_Predicate>::type> + (__first, __last, __pred, __len, __p, forward_iterator_tag()); +} + +template <class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair> +_BidirectionalIterator +__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, + _Distance __len, _Pair __p, bidirectional_iterator_tag __bit) +{ + // *__first is known to be false + // *__last is known to be true + // __len >= 2 + if (__len == 2) + { + swap(*__first, *__last); + return __last; + } + if (__len == 3) + { + _BidirectionalIterator __m = __first; + if (__pred(*++__m)) + { + swap(*__first, *__m); + swap(*__m, *__last); + return __last; + } + swap(*__m, *__last); + swap(*__first, *__m); + return __m; + } + if (__len <= __p.second) + { // The buffer is big enough to use + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + __destruct_n __d(0); + unique_ptr<value_type, __destruct_n&> __h(__p.first, __d); + // Move the falses into the temporary buffer, and the trues to the front of the line + // Update __first to always point to the end of the trues + value_type* __t = __p.first; + ::new(__t) value_type(_VSTD::move(*__first)); + __d.__incr((value_type*)0); + ++__t; + _BidirectionalIterator __i = __first; + while (++__i != __last) + { + if (__pred(*__i)) + { + *__first = _VSTD::move(*__i); + ++__first; + } + else + { + ::new(__t) value_type(_VSTD::move(*__i)); + __d.__incr((value_type*)0); + ++__t; + } + } + // move *__last, known to be true + *__first = _VSTD::move(*__i); + __i = ++__first; + // All trues now at start of range, all falses in buffer + // Move falses back into range, but don't mess up __first which points to first false + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) + *__i = _VSTD::move(*__t2); + // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer + return __first; + } + // Else not enough buffer, do in place + // __len >= 4 + _BidirectionalIterator __m = __first; + _Distance __len2 = __len / 2; // __len2 >= 2 + _VSTD::advance(__m, __len2); + // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false + // F????????????????T + // f m l + _BidirectionalIterator __m1 = __m; + _BidirectionalIterator __first_false = __first; + _Distance __len_half = __len2; + while (!__pred(*--__m1)) + { + if (__m1 == __first) + goto __first_half_done; + --__len_half; + } + // F???TFFF?????????T + // f m1 m l + typedef typename add_lvalue_reference<_Predicate>::type _PredRef; + __first_false = __stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit); +__first_half_done: + // TTTFFFFF?????????T + // f ff m l + // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true + __m1 = __m; + _BidirectionalIterator __second_false = __last; + ++__second_false; + __len_half = __len - __len2; + while (__pred(*__m1)) + { + if (++__m1 == __last) + goto __second_half_done; + --__len_half; + } + // TTTFFFFFTTTF?????T + // f ff m m1 l + __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit); +__second_half_done: + // TTTFFFFFTTTTTFFFFF + // f ff m sf l + return _VSTD::rotate(__first_false, __m, __second_false); + // TTTTTTTTFFFFFFFFFF + // | +} + +template <class _Predicate, class _BidirectionalIterator> +_BidirectionalIterator +__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, + bidirectional_iterator_tag) +{ + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment + // Either prove all true and return __first or point to first false + while (true) + { + if (__first == __last) + return __first; + if (!__pred(*__first)) + break; + ++__first; + } + // __first points to first false, everything prior to __first is already set. + // Either prove [__first, __last) is all false and return __first, or point __last to last true + do + { + if (__first == --__last) + return __first; + } while (!__pred(*__last)); + // We now have a reduced range [__first, __last] + // *__first is known to be false + // *__last is known to be true + // __len >= 2 + difference_type __len = _VSTD::distance(__first, __last) + 1; + pair<value_type*, ptrdiff_t> __p(0, 0); + unique_ptr<value_type, __return_temporary_buffer> __h; + if (__len >= __alloc_limit) + { + __p = _VSTD::get_temporary_buffer<value_type>(__len); + __h.reset(__p.first); + } + return __stable_partition<typename add_lvalue_reference<_Predicate>::type> + (__first, __last, __pred, __len, __p, bidirectional_iterator_tag()); +} + +template <class _ForwardIterator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + return __stable_partition<typename add_lvalue_reference<_Predicate>::type> + (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +// is_sorted_until + +template <class _ForwardIterator, class _Compare> +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (__comp(*__i, *__first)) + return __i; + __first = __i; + } + } + return __last; +} + +template<class _ForwardIterator> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::is_sorted_until(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>()); +} + +// is_sorted + +template <class _ForwardIterator, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + return _VSTD::is_sorted_until(__first, __last, __comp) == __last; +} + +template<class _ForwardIterator> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +is_sorted(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::is_sorted(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>()); +} + +// sort + +// stable, 2-3 compares, 0-2 swaps + +template <class _Compare, class _ForwardIterator> +unsigned +__sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) +{ + unsigned __r = 0; + if (!__c(*__y, *__x)) // if x <= y + { + if (!__c(*__z, *__y)) // if y <= z + return __r; // x <= y && y <= z + // x <= y && y > z + swap(*__y, *__z); // x <= z && y < z + __r = 1; + if (__c(*__y, *__x)) // if x > y + { + swap(*__x, *__y); // x < y && y <= z + __r = 2; + } + return __r; // x <= y && y < z + } + if (__c(*__z, *__y)) // x > y, if y > z + { + swap(*__x, *__z); // x < y && y < z + __r = 1; + return __r; + } + swap(*__x, *__y); // x > y && y <= z + __r = 1; // x < y && x <= z + if (__c(*__z, *__y)) // if y > z + { + swap(*__y, *__z); // x <= y && y < z + __r = 2; + } + return __r; +} // x <= y && y <= z + +// stable, 3-6 compares, 0-5 swaps + +template <class _Compare, class _ForwardIterator> +unsigned +__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, + _ForwardIterator __x4, _Compare __c) +{ + unsigned __r = __sort3<_Compare>(__x1, __x2, __x3, __c); + if (__c(*__x4, *__x3)) + { + swap(*__x3, *__x4); + ++__r; + if (__c(*__x3, *__x2)) + { + swap(*__x2, *__x3); + ++__r; + if (__c(*__x2, *__x1)) + { + swap(*__x1, *__x2); + ++__r; + } + } + } + return __r; +} + +// stable, 4-10 compares, 0-9 swaps + +template <class _Compare, class _ForwardIterator> +_LIBCPP_HIDDEN +unsigned +__sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, + _ForwardIterator __x4, _ForwardIterator __x5, _Compare __c) +{ + unsigned __r = __sort4<_Compare>(__x1, __x2, __x3, __x4, __c); + if (__c(*__x5, *__x4)) + { + swap(*__x4, *__x5); + ++__r; + if (__c(*__x4, *__x3)) + { + swap(*__x3, *__x4); + ++__r; + if (__c(*__x3, *__x2)) + { + swap(*__x2, *__x3); + ++__r; + if (__c(*__x2, *__x1)) + { + swap(*__x1, *__x2); + ++__r; + } + } + } + } + return __r; +} + +// Assumes size > 0 +template <class _Compare, class _BirdirectionalIterator> +void +__selection_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) +{ + _BirdirectionalIterator __lm1 = __last; + for (--__lm1; __first != __lm1; ++__first) + { + _BirdirectionalIterator __i = _VSTD::min_element<_BirdirectionalIterator, + typename add_lvalue_reference<_Compare>::type> + (__first, __last, __comp); + if (__i != __first) + swap(*__first, *__i); + } +} + +template <class _Compare, class _BirdirectionalIterator> +void +__insertion_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; + if (__first != __last) + { + _BirdirectionalIterator __i = __first; + for (++__i; __i != __last; ++__i) + { + _BirdirectionalIterator __j = __i; + value_type __t(_VSTD::move(*__j)); + for (_BirdirectionalIterator __k = __i; __k != __first && __comp(__t, *--__k); --__j) + *__j = _VSTD::move(*__k); + *__j = _VSTD::move(__t); + } + } +} + +template <class _Compare, class _RandomAccessIterator> +void +__insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + _RandomAccessIterator __j = __first+2; + __sort3<_Compare>(__first, __first+1, __j, __comp); + for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) + { + if (__comp(*__i, *__j)) + { + value_type __t(_VSTD::move(*__i)); + _RandomAccessIterator __k = __j; + __j = __i; + do + { + *__j = _VSTD::move(*__k); + __j = __k; + } while (__j != __first && __comp(__t, *--__k)); + *__j = _VSTD::move(__t); + } + __j = __i; + } +} + +template <class _Compare, class _RandomAccessIterator> +bool +__insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + switch (__last - __first) + { + case 0: + case 1: + return true; + case 2: + if (__comp(*--__last, *__first)) + swap(*__first, *__last); + return true; + case 3: + _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); + return true; + case 4: + _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); + return true; + case 5: + _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); + return true; + } + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + _RandomAccessIterator __j = __first+2; + __sort3<_Compare>(__first, __first+1, __j, __comp); + const unsigned __limit = 8; + unsigned __count = 0; + for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) + { + if (__comp(*__i, *__j)) + { + value_type __t(_VSTD::move(*__i)); + _RandomAccessIterator __k = __j; + __j = __i; + do + { + *__j = _VSTD::move(*__k); + __j = __k; + } while (__j != __first && __comp(__t, *--__k)); + *__j = _VSTD::move(__t); + if (++__count == __limit) + return ++__i == __last; + } + __j = __i; + } + return true; +} + +template <class _Compare, class _BirdirectionalIterator> +void +__insertion_sort_move(_BirdirectionalIterator __first1, _BirdirectionalIterator __last1, + typename iterator_traits<_BirdirectionalIterator>::value_type* __first2, _Compare __comp) +{ + typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; + if (__first1 != __last1) + { + __destruct_n __d(0); + unique_ptr<value_type, __destruct_n&> __h(__first2, __d); + value_type* __last2 = __first2; + ::new(__last2) value_type(_VSTD::move(*__first1)); + __d.__incr((value_type*)0); + for (++__last2; ++__first1 != __last1; ++__last2) + { + value_type* __j2 = __last2; + value_type* __i2 = __j2; + if (__comp(*__first1, *--__i2)) + { + ::new(__j2) value_type(_VSTD::move(*__i2)); + __d.__incr((value_type*)0); + for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2) + *__j2 = _VSTD::move(*__i2); + *__j2 = _VSTD::move(*__first1); + } + else + { + ::new(__j2) value_type(_VSTD::move(*__first1)); + __d.__incr((value_type*)0); + } + } + __h.release(); + } +} + +template <class _Compare, class _RandomAccessIterator> +void +__sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + // _Compare is known to be a reference type + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + const difference_type __limit = is_trivially_copy_constructible<value_type>::value && + is_trivially_copy_assignable<value_type>::value ? 30 : 6; + while (true) + { + __restart: + difference_type __len = __last - __first; + switch (__len) + { + case 0: + case 1: + return; + case 2: + if (__comp(*--__last, *__first)) + swap(*__first, *__last); + return; + case 3: + _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); + return; + case 4: + _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); + return; + case 5: + _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); + return; + } + if (__len <= __limit) + { + _VSTD::__insertion_sort_3<_Compare>(__first, __last, __comp); + return; + } + // __len > 5 + _RandomAccessIterator __m = __first; + _RandomAccessIterator __lm1 = __last; + --__lm1; + unsigned __n_swaps; + { + difference_type __delta; + if (__len >= 1000) + { + __delta = __len/2; + __m += __delta; + __delta /= 2; + __n_swaps = _VSTD::__sort5<_Compare>(__first, __first + __delta, __m, __m+__delta, __lm1, __comp); + } + else + { + __delta = __len/2; + __m += __delta; + __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, __lm1, __comp); + } + } + // *__m is median + // partition [__first, __m) < *__m and *__m <= [__m, __last) + // (this inhibits tossing elements equivalent to __m around unnecessarily) + _RandomAccessIterator __i = __first; + _RandomAccessIterator __j = __lm1; + // j points beyond range to be tested, *__m is known to be <= *__lm1 + // The search going up is known to be guarded but the search coming down isn't. + // Prime the downward search with a guard. + if (!__comp(*__i, *__m)) // if *__first == *__m + { + // *__first == *__m, *__first doesn't go in first part + // manually guard downward moving __j against __i + while (true) + { + if (__i == --__j) + { + // *__first == *__m, *__m <= all other elements + // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) + ++__i; // __first + 1 + __j = __last; + if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) + { + while (true) + { + if (__i == __j) + return; // [__first, __last) all equivalent elements + if (__comp(*__first, *__i)) + { + swap(*__i, *__j); + ++__n_swaps; + ++__i; + break; + } + ++__i; + } + } + // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 + if (__i == __j) + return; + while (true) + { + while (!__comp(*__first, *__i)) + ++__i; + while (__comp(*__first, *--__j)) + ; + if (__i >= __j) + break; + swap(*__i, *__j); + ++__n_swaps; + ++__i; + } + // [__first, __i) == *__first and *__first < [__i, __last) + // The first part is sorted, sort the secod part + // _VSTD::__sort<_Compare>(__i, __last, __comp); + __first = __i; + goto __restart; + } + if (__comp(*__j, *__m)) + { + swap(*__i, *__j); + ++__n_swaps; + break; // found guard for downward moving __j, now use unguarded partition + } + } + } + // It is known that *__i < *__m + ++__i; + // j points beyond range to be tested, *__m is known to be <= *__lm1 + // if not yet partitioned... + if (__i < __j) + { + // known that *(__i - 1) < *__m + // known that __i <= __m + while (true) + { + // __m still guards upward moving __i + while (__comp(*__i, *__m)) + ++__i; + // It is now known that a guard exists for downward moving __j + while (!__comp(*--__j, *__m)) + ; + if (__i > __j) + break; + swap(*__i, *__j); + ++__n_swaps; + // It is known that __m != __j + // If __m just moved, follow it + if (__m == __i) + __m = __j; + ++__i; + } + } + // [__first, __i) < *__m and *__m <= [__i, __last) + if (__i != __m && __comp(*__m, *__i)) + { + swap(*__i, *__m); + ++__n_swaps; + } + // [__first, __i) < *__i and *__i <= [__i+1, __last) + // If we were given a perfect partition, see if insertion sort is quick... + if (__n_swaps == 0) + { + bool __fs = _VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp); + if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp)) + { + if (__fs) + return; + __last = __i; + continue; + } + else + { + if (__fs) + { + __first = ++__i; + continue; + } + } + } + // sort smaller range with recursive call and larger with tail recursion elimination + if (__i - __first < __last - __i) + { + _VSTD::__sort<_Compare>(__first, __i, __comp); + // _VSTD::__sort<_Compare>(__i+1, __last, __comp); + __first = ++__i; + } + else + { + _VSTD::__sort<_Compare>(__i+1, __last, __comp); + // _VSTD::__sort<_Compare>(__first, __i, __comp); + __last = __i; + } + } +} + +// This forwarder keeps the top call and the recursive calls using the same instantiation, forcing a reference _Compare +template <class _RandomAccessIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + _VSTD::__sort<_Comp_ref>(__first, __last, _Comp_ref(__comp)); +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +sort(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void +sort(_Tp** __first, _Tp** __last) +{ + _VSTD::sort((size_t*)__first, (size_t*)__last, __less<size_t>()); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void +sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last) +{ + _VSTD::sort(__first.base(), __last.base()); +} + +template <class _Tp, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last, _Compare __comp) +{ + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + _VSTD::sort<_Tp*, _Comp_ref>(__first.base(), __last.base(), __comp); +} + +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<char>&, char*>(char*, char*, __less<char>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<short>&, short*>(short*, short*, __less<short>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<int>&, int*>(int*, int*, __less<int>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long>&, long*>(long*, long*, __less<long>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<float>&, float*>(float*, float*, __less<float>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<double>&, double*>(double*, double*, __less<double>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&)) + +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&)) + +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&)) + +// lower_bound + +template <class _Compare, class _ForwardIterator, class _Tp> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +__lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + difference_type __len = _VSTD::distance(__first, __last); + while (__len != 0) + { + difference_type __l2 = _VSTD::__half_positive(__len); + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__comp(*__m, __value_)) + { + __first = ++__m; + __len -= __l2 + 1; + } + else + __len = __l2; + } + return __first; +} + +template <class _ForwardIterator, class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __lower_bound<_Comp_ref>(__first, __last, __value_, __comp); +} + +template <class _ForwardIterator, class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::lower_bound(__first, __last, __value_, + __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>()); +} + +// upper_bound + +template <class _Compare, class _ForwardIterator, class _Tp> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +__upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + difference_type __len = _VSTD::distance(__first, __last); + while (__len != 0) + { + difference_type __l2 = _VSTD::__half_positive(__len); + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__comp(__value_, *__m)) + __len = __l2; + else + { + __first = ++__m; + __len -= __l2 + 1; + } + } + return __first; +} + +template <class _ForwardIterator, class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __upper_bound<_Comp_ref>(__first, __last, __value_, __comp); +} + +template <class _ForwardIterator, class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_ForwardIterator +upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::upper_bound(__first, __last, __value_, + __less<_Tp, typename iterator_traits<_ForwardIterator>::value_type>()); +} + +// equal_range + +template <class _Compare, class _ForwardIterator, class _Tp> +_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator> +__equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + difference_type __len = _VSTD::distance(__first, __last); + while (__len != 0) + { + difference_type __l2 = _VSTD::__half_positive(__len); + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__comp(*__m, __value_)) + { + __first = ++__m; + __len -= __l2 + 1; + } + else if (__comp(__value_, *__m)) + { + __last = __m; + __len = __l2; + } + else + { + _ForwardIterator __mp1 = __m; + return pair<_ForwardIterator, _ForwardIterator> + ( + __lower_bound<_Compare>(__first, __m, __value_, __comp), + __upper_bound<_Compare>(++__mp1, __last, __value_, __comp) + ); + } + } + return pair<_ForwardIterator, _ForwardIterator>(__first, __first); +} + +template <class _ForwardIterator, class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +pair<_ForwardIterator, _ForwardIterator> +equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __equal_range<_Comp_ref>(__first, __last, __value_, __comp); +} + +template <class _ForwardIterator, class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +pair<_ForwardIterator, _ForwardIterator> +equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::equal_range(__first, __last, __value_, + __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>()); +} + +// binary_search + +template <class _Compare, class _ForwardIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +__binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + __first = __lower_bound<_Compare>(__first, __last, __value_, __comp); + return __first != __last && !__comp(__value_, *__first); +} + +template <class _ForwardIterator, class _Tp, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __binary_search<_Comp_ref>(__first, __last, __value_, __comp); +} + +template <class _ForwardIterator, class _Tp> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::binary_search(__first, __last, __value_, + __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>()); +} + +// merge + +template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator> +_OutputIterator +__merge(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + for (; __first1 != __last1; ++__result) + { + if (__first2 == __last2) + return _VSTD::copy(__first1, __last1, __result); + if (__comp(*__first2, *__first1)) + { + *__result = *__first2; + ++__first2; + } + else + { + *__result = *__first1; + ++__first1; + } + } + return _VSTD::copy(__first2, __last2, __result); +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +merge(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +merge(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return merge(__first1, __last1, __first2, __last2, __result, __less<__v1, __v2>()); +} + +// inplace_merge + +template <class _Compare, class _InputIterator1, class _InputIterator2, + class _OutputIterator> +void __half_inplace_merge(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, + _OutputIterator __result, _Compare __comp) +{ + for (; __first1 != __last1; ++__result) + { + if (__first2 == __last2) + { + _VSTD::move(__first1, __last1, __result); + return; + } + + if (__comp(*__first2, *__first1)) + { + *__result = _VSTD::move(*__first2); + ++__first2; + } + else + { + *__result = _VSTD::move(*__first1); + ++__first1; + } + } + // __first2 through __last2 are already in the right spot. +} + +template <class _Compare, class _BidirectionalIterator> +void +__buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, + _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1, + typename iterator_traits<_BidirectionalIterator>::difference_type __len2, + typename iterator_traits<_BidirectionalIterator>::value_type* __buff) +{ + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + __destruct_n __d(0); + unique_ptr<value_type, __destruct_n&> __h2(__buff, __d); + if (__len1 <= __len2) + { + value_type* __p = __buff; + for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, ++__p) + ::new(__p) value_type(_VSTD::move(*__i)); + __half_inplace_merge(__buff, __p, __middle, __last, __first, __comp); + } + else + { + value_type* __p = __buff; + for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, ++__p) + ::new(__p) value_type(_VSTD::move(*__i)); + typedef reverse_iterator<_BidirectionalIterator> _RBi; + typedef reverse_iterator<value_type*> _Rv; + __half_inplace_merge(_Rv(__p), _Rv(__buff), + _RBi(__middle), _RBi(__first), + _RBi(__last), __invert<_Compare>(__comp)); + } +} + +template <class _Compare, class _BidirectionalIterator> +void +__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, + _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1, + typename iterator_traits<_BidirectionalIterator>::difference_type __len2, + typename iterator_traits<_BidirectionalIterator>::value_type* __buff, ptrdiff_t __buff_size) +{ + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + while (true) + { + // if __middle == __last, we're done + if (__len2 == 0) + return; + if (__len1 <= __buff_size || __len2 <= __buff_size) + return __buffered_inplace_merge<_Compare> + (__first, __middle, __last, __comp, __len1, __len2, __buff); + // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0 + for (; true; ++__first, (void) --__len1) + { + if (__len1 == 0) + return; + if (__comp(*__middle, *__first)) + break; + } + // __first < __middle < __last + // *__first > *__middle + // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that + // all elements in: + // [__first, __m1) <= [__middle, __m2) + // [__middle, __m2) < [__m1, __middle) + // [__m1, __middle) <= [__m2, __last) + // and __m1 or __m2 is in the middle of its range + _BidirectionalIterator __m1; // "median" of [__first, __middle) + _BidirectionalIterator __m2; // "median" of [__middle, __last) + difference_type __len11; // distance(__first, __m1) + difference_type __len21; // distance(__middle, __m2) + // binary search smaller range + if (__len1 < __len2) + { // __len >= 1, __len2 >= 2 + __len21 = __len2 / 2; + __m2 = __middle; + _VSTD::advance(__m2, __len21); + __m1 = __upper_bound<_Compare>(__first, __middle, *__m2, __comp); + __len11 = _VSTD::distance(__first, __m1); + } + else + { + if (__len1 == 1) + { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1 + // It is known *__first > *__middle + swap(*__first, *__middle); + return; + } + // __len1 >= 2, __len2 >= 1 + __len11 = __len1 / 2; + __m1 = __first; + _VSTD::advance(__m1, __len11); + __m2 = __lower_bound<_Compare>(__middle, __last, *__m1, __comp); + __len21 = _VSTD::distance(__middle, __m2); + } + difference_type __len12 = __len1 - __len11; // distance(__m1, __middle) + difference_type __len22 = __len2 - __len21; // distance(__m2, __last) + // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) + // swap middle two partitions + __middle = _VSTD::rotate(__m1, __middle, __m2); + // __len12 and __len21 now have swapped meanings + // merge smaller range with recurisve call and larger with tail recursion elimination + if (__len11 + __len21 < __len12 + __len22) + { + __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); +// __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); + __first = __middle; + __middle = __m2; + __len1 = __len12; + __len2 = __len22; + } + else + { + __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); +// __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); + __last = __middle; + __middle = __m1; + __len1 = __len11; + __len2 = __len21; + } + } +} + +template <class _BidirectionalIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, + _Compare __comp) +{ + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + difference_type __len1 = _VSTD::distance(__first, __middle); + difference_type __len2 = _VSTD::distance(__middle, __last); + difference_type __buf_size = _VSTD::min(__len1, __len2); + pair<value_type*, ptrdiff_t> __buf = _VSTD::get_temporary_buffer<value_type>(__buf_size); + unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first); + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2, + __buf.first, __buf.second); +} + +template <class _BidirectionalIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) +{ + _VSTD::inplace_merge(__first, __middle, __last, + __less<typename iterator_traits<_BidirectionalIterator>::value_type>()); +} + +// stable_sort + +template <class _Compare, class _InputIterator1, class _InputIterator2> +void +__merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, + typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp) +{ + typedef typename iterator_traits<_InputIterator1>::value_type value_type; + __destruct_n __d(0); + unique_ptr<value_type, __destruct_n&> __h(__result, __d); + for (; true; ++__result) + { + if (__first1 == __last1) + { + for (; __first2 != __last2; ++__first2, ++__result, __d.__incr((value_type*)0)) + ::new (__result) value_type(_VSTD::move(*__first2)); + __h.release(); + return; + } + if (__first2 == __last2) + { + for (; __first1 != __last1; ++__first1, ++__result, __d.__incr((value_type*)0)) + ::new (__result) value_type(_VSTD::move(*__first1)); + __h.release(); + return; + } + if (__comp(*__first2, *__first1)) + { + ::new (__result) value_type(_VSTD::move(*__first2)); + __d.__incr((value_type*)0); + ++__first2; + } + else + { + ::new (__result) value_type(_VSTD::move(*__first1)); + __d.__incr((value_type*)0); + ++__first1; + } + } +} + +template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator> +void +__merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, + _OutputIterator __result, _Compare __comp) +{ + for (; __first1 != __last1; ++__result) + { + if (__first2 == __last2) + { + for (; __first1 != __last1; ++__first1, ++__result) + *__result = _VSTD::move(*__first1); + return; + } + if (__comp(*__first2, *__first1)) + { + *__result = _VSTD::move(*__first2); + ++__first2; + } + else + { + *__result = _VSTD::move(*__first1); + ++__first1; + } + } + for (; __first2 != __last2; ++__first2, ++__result) + *__result = _VSTD::move(*__first2); +} + +template <class _Compare, class _RandomAccessIterator> +void +__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size); + +template <class _Compare, class _RandomAccessIterator> +void +__stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __first2) +{ + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + switch (__len) + { + case 0: + return; + case 1: + ::new(__first2) value_type(_VSTD::move(*__first1)); + return; + case 2: + __destruct_n __d(0); + unique_ptr<value_type, __destruct_n&> __h2(__first2, __d); + if (__comp(*--__last1, *__first1)) + { + ::new(__first2) value_type(_VSTD::move(*__last1)); + __d.__incr((value_type*)0); + ++__first2; + ::new(__first2) value_type(_VSTD::move(*__first1)); + } + else + { + ::new(__first2) value_type(_VSTD::move(*__first1)); + __d.__incr((value_type*)0); + ++__first2; + ::new(__first2) value_type(_VSTD::move(*__last1)); + } + __h2.release(); + return; + } + if (__len <= 8) + { + __insertion_sort_move<_Compare>(__first1, __last1, __first2, __comp); + return; + } + typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; + _RandomAccessIterator __m = __first1 + __l2; + __stable_sort<_Compare>(__first1, __m, __comp, __l2, __first2, __l2); + __stable_sort<_Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2); + __merge_move_construct<_Compare>(__first1, __m, __m, __last1, __first2, __comp); +} + +template <class _Tp> +struct __stable_sort_switch +{ + static const unsigned value = 128*is_trivially_copy_assignable<_Tp>::value; +}; + +template <class _Compare, class _RandomAccessIterator> +void +__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size) +{ + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + switch (__len) + { + case 0: + case 1: + return; + case 2: + if (__comp(*--__last, *__first)) + swap(*__first, *__last); + return; + } + if (__len <= static_cast<difference_type>(__stable_sort_switch<value_type>::value)) + { + __insertion_sort<_Compare>(__first, __last, __comp); + return; + } + typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; + _RandomAccessIterator __m = __first + __l2; + if (__len <= __buff_size) + { + __destruct_n __d(0); + unique_ptr<value_type, __destruct_n&> __h2(__buff, __d); + __stable_sort_move<_Compare>(__first, __m, __comp, __l2, __buff); + __d.__set(__l2, (value_type*)0); + __stable_sort_move<_Compare>(__m, __last, __comp, __len - __l2, __buff + __l2); + __d.__set(__len, (value_type*)0); + __merge_move_assign<_Compare>(__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp); +// __merge<_Compare>(move_iterator<value_type*>(__buff), +// move_iterator<value_type*>(__buff + __l2), +// move_iterator<_RandomAccessIterator>(__buff + __l2), +// move_iterator<_RandomAccessIterator>(__buff + __len), +// __first, __comp); + return; + } + __stable_sort<_Compare>(__first, __m, __comp, __l2, __buff, __buff_size); + __stable_sort<_Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size); + __inplace_merge<_Compare>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size); +} + +template <class _RandomAccessIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __len = __last - __first; + pair<value_type*, ptrdiff_t> __buf(0, 0); + unique_ptr<value_type, __return_temporary_buffer> __h; + if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value)) + { + __buf = _VSTD::get_temporary_buffer<value_type>(__len); + __h.reset(__buf.first); + } + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + __stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second); +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::stable_sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// is_heap_until + +template <class _RandomAccessIterator, class _Compare> +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator +is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __len = __last - __first; + difference_type __p = 0; + difference_type __c = 1; + _RandomAccessIterator __pp = __first; + while (__c < __len) + { + _RandomAccessIterator __cp = __first + __c; + if (__comp(*__pp, *__cp)) + return __cp; + ++__c; + ++__cp; + if (__c == __len) + return __last; + if (__comp(*__pp, *__cp)) + return __cp; + ++__p; + ++__pp; + __c = 2 * __p + 1; + } + return __last; +} + +template<class _RandomAccessIterator> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_RandomAccessIterator +is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + return _VSTD::is_heap_until(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// is_heap + +template <class _RandomAccessIterator, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + return _VSTD::is_heap_until(__first, __last, __comp) == __last; +} + +template<class _RandomAccessIterator> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + return _VSTD::is_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// push_heap + +template <class _Compare, class _RandomAccessIterator> +void +__sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len) +{ + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + if (__len > 1) + { + __len = (__len - 2) / 2; + _RandomAccessIterator __ptr = __first + __len; + if (__comp(*__ptr, *--__last)) + { + value_type __t(_VSTD::move(*__last)); + do + { + *__last = _VSTD::move(*__ptr); + __last = __ptr; + if (__len == 0) + break; + __len = (__len - 1) / 2; + __ptr = __first + __len; + } while (__comp(*__ptr, __t)); + *__last = _VSTD::move(__t); + } + } +} + +template <class _RandomAccessIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + __sift_up<_Comp_ref>(__first, __last, __comp, __last - __first); +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::push_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// pop_heap + +template <class _Compare, class _RandomAccessIterator> +void +__sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/, + _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + _RandomAccessIterator __start) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + // left-child of __start is at 2 * __start + 1 + // right-child of __start is at 2 * __start + 2 + difference_type __child = __start - __first; + + if (__len < 2 || (__len - 2) / 2 < __child) + return; + + __child = 2 * __child + 1; + _RandomAccessIterator __child_i = __first + __child; + + if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) { + // right-child exists and is greater than left-child + ++__child_i; + ++__child; + } + + // check if we are in heap-order + if (__comp(*__child_i, *__start)) + // we are, __start is larger than it's largest child + return; + + value_type __top(_VSTD::move(*__start)); + do + { + // we are not in heap-order, swap the parent with it's largest child + *__start = _VSTD::move(*__child_i); + __start = __child_i; + + if ((__len - 2) / 2 < __child) + break; + + // recompute the child based off of the updated parent + __child = 2 * __child + 1; + __child_i = __first + __child; + + if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) { + // right-child exists and is greater than left-child + ++__child_i; + ++__child; + } + + // check if we are in heap-order + } while (!__comp(*__child_i, __top)); + *__start = _VSTD::move(__top); +} + +template <class _Compare, class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len) +{ + if (__len > 1) + { + swap(*__first, *--__last); + __sift_down<_Compare>(__first, __last, __comp, __len - 1, __first); + } +} + +template <class _RandomAccessIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + __pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first); +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::pop_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// make_heap + +template <class _Compare, class _RandomAccessIterator> +void +__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __n = __last - __first; + if (__n > 1) + { + // start from the first parent, there is no need to consider children + for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start) + { + __sift_down<_Compare>(__first, __last, __comp, __n, __first + __start); + } + } +} + +template <class _RandomAccessIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + __make_heap<_Comp_ref>(__first, __last, __comp); +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::make_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// sort_heap + +template <class _Compare, class _RandomAccessIterator> +void +__sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + for (difference_type __n = __last - __first; __n > 1; --__last, --__n) + __pop_heap<_Compare>(__first, __last, __comp, __n); +} + +template <class _RandomAccessIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + __sort_heap<_Comp_ref>(__first, __last, __comp); +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::sort_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// partial_sort + +template <class _Compare, class _RandomAccessIterator> +void +__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, + _Compare __comp) +{ + __make_heap<_Compare>(__first, __middle, __comp); + typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first; + for (_RandomAccessIterator __i = __middle; __i != __last; ++__i) + { + if (__comp(*__i, *__first)) + { + swap(*__i, *__first); + __sift_down<_Compare>(__first, __middle, __comp, __len, __first); + } + } + __sort_heap<_Compare>(__first, __middle, __comp); +} + +template <class _RandomAccessIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, + _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + __partial_sort<_Comp_ref>(__first, __middle, __last, __comp); +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) +{ + _VSTD::partial_sort(__first, __middle, __last, + __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// partial_sort_copy + +template <class _Compare, class _InputIterator, class _RandomAccessIterator> +_RandomAccessIterator +__partial_sort_copy(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) +{ + _RandomAccessIterator __r = __result_first; + if (__r != __result_last) + { + for (; __first != __last && __r != __result_last; (void) ++__first, ++__r) + *__r = *__first; + __make_heap<_Compare>(__result_first, __r, __comp); + typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first; + for (; __first != __last; ++__first) + if (__comp(*__first, *__result_first)) + { + *__result_first = *__first; + __sift_down<_Compare>(__result_first, __r, __comp, __len, __result_first); + } + __sort_heap<_Compare>(__result_first, __r, __comp); + } + return __r; +} + +template <class _InputIterator, class _RandomAccessIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +_RandomAccessIterator +partial_sort_copy(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __comp); +} + +template <class _InputIterator, class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +_RandomAccessIterator +partial_sort_copy(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __result_first, _RandomAccessIterator __result_last) +{ + return _VSTD::partial_sort_copy(__first, __last, __result_first, __result_last, + __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// nth_element + +template <class _Compare, class _RandomAccessIterator> +void +__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) +{ + // _Compare is known to be a reference type + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + const difference_type __limit = 7; + while (true) + { + __restart: + if (__nth == __last) + return; + difference_type __len = __last - __first; + switch (__len) + { + case 0: + case 1: + return; + case 2: + if (__comp(*--__last, *__first)) + swap(*__first, *__last); + return; + case 3: + { + _RandomAccessIterator __m = __first; + _VSTD::__sort3<_Compare>(__first, ++__m, --__last, __comp); + return; + } + } + if (__len <= __limit) + { + __selection_sort<_Compare>(__first, __last, __comp); + return; + } + // __len > __limit >= 3 + _RandomAccessIterator __m = __first + __len/2; + _RandomAccessIterator __lm1 = __last; + unsigned __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, --__lm1, __comp); + // *__m is median + // partition [__first, __m) < *__m and *__m <= [__m, __last) + // (this inhibits tossing elements equivalent to __m around unnecessarily) + _RandomAccessIterator __i = __first; + _RandomAccessIterator __j = __lm1; + // j points beyond range to be tested, *__lm1 is known to be <= *__m + // The search going up is known to be guarded but the search coming down isn't. + // Prime the downward search with a guard. + if (!__comp(*__i, *__m)) // if *__first == *__m + { + // *__first == *__m, *__first doesn't go in first part + // manually guard downward moving __j against __i + while (true) + { + if (__i == --__j) + { + // *__first == *__m, *__m <= all other elements + // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) + ++__i; // __first + 1 + __j = __last; + if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) + { + while (true) + { + if (__i == __j) + return; // [__first, __last) all equivalent elements + if (__comp(*__first, *__i)) + { + swap(*__i, *__j); + ++__n_swaps; + ++__i; + break; + } + ++__i; + } + } + // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 + if (__i == __j) + return; + while (true) + { + while (!__comp(*__first, *__i)) + ++__i; + while (__comp(*__first, *--__j)) + ; + if (__i >= __j) + break; + swap(*__i, *__j); + ++__n_swaps; + ++__i; + } + // [__first, __i) == *__first and *__first < [__i, __last) + // The first part is sorted, + if (__nth < __i) + return; + // __nth_element the secod part + // __nth_element<_Compare>(__i, __nth, __last, __comp); + __first = __i; + goto __restart; + } + if (__comp(*__j, *__m)) + { + swap(*__i, *__j); + ++__n_swaps; + break; // found guard for downward moving __j, now use unguarded partition + } + } + } + ++__i; + // j points beyond range to be tested, *__lm1 is known to be <= *__m + // if not yet partitioned... + if (__i < __j) + { + // known that *(__i - 1) < *__m + while (true) + { + // __m still guards upward moving __i + while (__comp(*__i, *__m)) + ++__i; + // It is now known that a guard exists for downward moving __j + while (!__comp(*--__j, *__m)) + ; + if (__i >= __j) + break; + swap(*__i, *__j); + ++__n_swaps; + // It is known that __m != __j + // If __m just moved, follow it + if (__m == __i) + __m = __j; + ++__i; + } + } + // [__first, __i) < *__m and *__m <= [__i, __last) + if (__i != __m && __comp(*__m, *__i)) + { + swap(*__i, *__m); + ++__n_swaps; + } + // [__first, __i) < *__i and *__i <= [__i+1, __last) + if (__nth == __i) + return; + if (__n_swaps == 0) + { + // We were given a perfectly partitioned sequence. Coincidence? + if (__nth < __i) + { + // Check for [__first, __i) already sorted + __j = __m = __first; + while (++__j != __i) + { + if (__comp(*__j, *__m)) + // not yet sorted, so sort + goto not_sorted; + __m = __j; + } + // [__first, __i) sorted + return; + } + else + { + // Check for [__i, __last) already sorted + __j = __m = __i; + while (++__j != __last) + { + if (__comp(*__j, *__m)) + // not yet sorted, so sort + goto not_sorted; + __m = __j; + } + // [__i, __last) sorted + return; + } + } +not_sorted: + // __nth_element on range containing __nth + if (__nth < __i) + { + // __nth_element<_Compare>(__first, __nth, __i, __comp); + __last = __i; + } + else + { + // __nth_element<_Compare>(__i+1, __nth, __last, __comp); + __first = ++__i; + } + } +} + +template <class _RandomAccessIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +void +nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + __nth_element<_Comp_ref>(__first, __nth, __last, __comp); +} + +template <class _RandomAccessIterator> +inline _LIBCPP_INLINE_VISIBILITY +void +nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) +{ + _VSTD::nth_element(__first, __nth, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); +} + +// includes + +template <class _Compare, class _InputIterator1, class _InputIterator2> +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +__includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, + _Compare __comp) +{ + for (; __first2 != __last2; ++__first1) + { + if (__first1 == __last1 || __comp(*__first2, *__first1)) + return false; + if (!__comp(*__first1, *__first2)) + ++__first2; + } + return true; +} + +template <class _InputIterator1, class _InputIterator2, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, + _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); +} + +template <class _InputIterator1, class _InputIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) +{ + return _VSTD::includes(__first1, __last1, __first2, __last2, + __less<typename iterator_traits<_InputIterator1>::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_union + +template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator> +_OutputIterator +__set_union(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + for (; __first1 != __last1; ++__result) + { + if (__first2 == __last2) + return _VSTD::copy(__first1, __last1, __result); + if (__comp(*__first2, *__first1)) + { + *__result = *__first2; + ++__first2; + } + else + { + if (!__comp(*__first1, *__first2)) + ++__first2; + *__result = *__first1; + ++__first1; + } + } + return _VSTD::copy(__first2, __last2, __result); +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_union(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_union(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + return _VSTD::set_union(__first1, __last1, __first2, __last2, __result, + __less<typename iterator_traits<_InputIterator1>::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_intersection + +template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator> +_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator +__set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + while (__first1 != __last1 && __first2 != __last2) + { + if (__comp(*__first1, *__first2)) + ++__first1; + else + { + if (!__comp(*__first2, *__first1)) + { + *__result = *__first1; + ++__result; + ++__first1; + } + ++__first2; + } + } + return __result; +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + return _VSTD::set_intersection(__first1, __last1, __first2, __last2, __result, + __less<typename iterator_traits<_InputIterator1>::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_difference + +template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator> +_OutputIterator +__set_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + while (__first1 != __last1) + { + if (__first2 == __last2) + return _VSTD::copy(__first1, __last1, __result); + if (__comp(*__first1, *__first2)) + { + *__result = *__first1; + ++__result; + ++__first1; + } + else + { + if (!__comp(*__first2, *__first1)) + ++__first1; + ++__first2; + } + } + return __result; +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + return _VSTD::set_difference(__first1, __last1, __first2, __last2, __result, + __less<typename iterator_traits<_InputIterator1>::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_symmetric_difference + +template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator> +_OutputIterator +__set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + while (__first1 != __last1) + { + if (__first2 == __last2) + return _VSTD::copy(__first1, __last1, __result); + if (__comp(*__first1, *__first2)) + { + *__result = *__first1; + ++__result; + ++__first1; + } + else + { + if (__comp(*__first2, *__first1)) + { + *__result = *__first2; + ++__result; + } + else + ++__first1; + ++__first2; + } + } + return _VSTD::copy(__first2, __last2, __result); +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +} + +template <class _InputIterator1, class _InputIterator2, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + return _VSTD::set_symmetric_difference(__first1, __last1, __first2, __last2, __result, + __less<typename iterator_traits<_InputIterator1>::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// lexicographical_compare + +template <class _Compare, class _InputIterator1, class _InputIterator2> +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +__lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) +{ + for (; __first2 != __last2; ++__first1, (void) ++__first2) + { + if (__first1 == __last1 || __comp(*__first1, *__first2)) + return true; + if (__comp(*__first2, *__first1)) + return false; + } + return false; +} + +template <class _InputIterator1, class _InputIterator2, class _Compare> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); +} + +template <class _InputIterator1, class _InputIterator2> +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +bool +lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2) +{ + return _VSTD::lexicographical_compare(__first1, __last1, __first2, __last2, + __less<typename iterator_traits<_InputIterator1>::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// next_permutation + +template <class _Compare, class _BidirectionalIterator> +bool +__next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ + _BidirectionalIterator __i = __last; + if (__first == __last || __first == --__i) + return false; + while (true) + { + _BidirectionalIterator __ip1 = __i; + if (__comp(*--__i, *__ip1)) + { + _BidirectionalIterator __j = __last; + while (!__comp(*__i, *--__j)) + ; + swap(*__i, *__j); + _VSTD::reverse(__ip1, __last); + return true; + } + if (__i == __first) + { + _VSTD::reverse(__first, __last); + return false; + } + } +} + +template <class _BidirectionalIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +bool +next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __next_permutation<_Comp_ref>(__first, __last, __comp); +} + +template <class _BidirectionalIterator> +inline _LIBCPP_INLINE_VISIBILITY +bool +next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + return _VSTD::next_permutation(__first, __last, + __less<typename iterator_traits<_BidirectionalIterator>::value_type>()); +} + +// prev_permutation + +template <class _Compare, class _BidirectionalIterator> +bool +__prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ + _BidirectionalIterator __i = __last; + if (__first == __last || __first == --__i) + return false; + while (true) + { + _BidirectionalIterator __ip1 = __i; + if (__comp(*__ip1, *--__i)) + { + _BidirectionalIterator __j = __last; + while (!__comp(*--__j, *__i)) + ; + swap(*__i, *__j); + _VSTD::reverse(__ip1, __last); + return true; + } + if (__i == __first) + { + _VSTD::reverse(__first, __last); + return false; + } + } +} + +template <class _BidirectionalIterator, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +bool +prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + return __prev_permutation<_Comp_ref>(__first, __last, __comp); +} + +template <class _BidirectionalIterator> +inline _LIBCPP_INLINE_VISIBILITY +bool +prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + return _VSTD::prev_permutation(__first, __last, + __less<typename iterator_traits<_BidirectionalIterator>::value_type>()); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_ALGORITHM diff --git a/android/x86/include/v8/libc++/any b/android/x86/include/v8/libc++/any new file mode 100755 index 00000000..f3518c34 --- /dev/null +++ b/android/x86/include/v8/libc++/any @@ -0,0 +1,671 @@ +// -*- C++ -*- +//===------------------------------ any -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ANY +#define _LIBCPP_ANY + +/* + any synopsis + +namespace std { + + class bad_any_cast : public bad_cast + { + public: + virtual const char* what() const noexcept; + }; + + class any + { + public: + + // 6.3.1 any construct/destruct + any() noexcept; + + any(const any& other); + any(any&& other) noexcept; + + template <class ValueType> + any(ValueType&& value); + + ~any(); + + // 6.3.2 any assignments + any& operator=(const any& rhs); + any& operator=(any&& rhs) noexcept; + + template <class ValueType> + any& operator=(ValueType&& rhs); + + // 6.3.3 any modifiers + template <class ValueType, class... Args> + decay_t<ValueType>& emplace(Args&&... args); + template <class ValueType, class U, class... Args> + decay_t<ValueType>& emplace(initializer_list<U>, Args&&...); + void reset() noexcept; + void swap(any& rhs) noexcept; + + // 6.3.4 any observers + bool has_value() const noexcept; + const type_info& type() const noexcept; + }; + + // 6.4 Non-member functions + void swap(any& x, any& y) noexcept; + + template <class T, class ...Args> + any make_any(Args&& ...args); + template <class T, class U, class ...Args> + any make_any(initializer_list<U>, Args&& ...args); + + template<class ValueType> + ValueType any_cast(const any& operand); + template<class ValueType> + ValueType any_cast(any& operand); + template<class ValueType> + ValueType any_cast(any&& operand); + + template<class ValueType> + const ValueType* any_cast(const any* operand) noexcept; + template<class ValueType> + ValueType* any_cast(any* operand) noexcept; + +} // namespace std + +*/ + +#include <experimental/__config> +#include <memory> +#include <new> +#include <typeinfo> +#include <type_traits> +#include <cstdlib> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace std { +class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast +{ +public: + virtual const char* what() const _NOEXCEPT; +}; +} // namespace std + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST +void __throw_bad_any_cast() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_any_cast(); +#else + _VSTD::abort(); +#endif +} + +// Forward declarations +class _LIBCPP_TEMPLATE_VIS any; + +template <class _ValueType> +_LIBCPP_INLINE_VISIBILITY +add_pointer_t<add_const_t<_ValueType>> +any_cast(any const *) _NOEXCEPT; + +template <class _ValueType> +_LIBCPP_INLINE_VISIBILITY +add_pointer_t<_ValueType> any_cast(any *) _NOEXCEPT; + +namespace __any_imp +{ + using _Buffer = aligned_storage_t<3*sizeof(void*), alignment_of<void*>::value>; + + template <class _Tp> + using _IsSmallObject = integral_constant<bool + , sizeof(_Tp) <= sizeof(_Buffer) + && alignment_of<_Buffer>::value + % alignment_of<_Tp>::value == 0 + && is_nothrow_move_constructible<_Tp>::value + >; + + enum class _Action { + _Destroy, + _Copy, + _Move, + _Get, + _TypeInfo + }; + + template <class _Tp> struct _SmallHandler; + template <class _Tp> struct _LargeHandler; + + template <class _Tp> + struct _LIBCPP_TEMPLATE_VIS __unique_typeinfo { static constexpr int __id = 0; }; + template <class _Tp> constexpr int __unique_typeinfo<_Tp>::__id; + + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY + constexpr const void* __get_fallback_typeid() { + return &__unique_typeinfo<decay_t<_Tp>>::__id; + } + + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY + bool __compare_typeid(type_info const* __id, const void* __fallback_id) + { +#if !defined(_LIBCPP_NO_RTTI) + if (__id && *__id == typeid(_Tp)) + return true; +#endif + if (!__id && __fallback_id == __any_imp::__get_fallback_typeid<_Tp>()) + return true; + return false; + } + + template <class _Tp> + using _Handler = conditional_t< + _IsSmallObject<_Tp>::value, _SmallHandler<_Tp>, _LargeHandler<_Tp>>; + +} // namespace __any_imp + +class _LIBCPP_TEMPLATE_VIS any +{ +public: + // construct/destruct + _LIBCPP_INLINE_VISIBILITY + constexpr any() _NOEXCEPT : __h(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + any(any const & __other) : __h(nullptr) + { + if (__other.__h) __other.__call(_Action::_Copy, this); + } + + _LIBCPP_INLINE_VISIBILITY + any(any && __other) _NOEXCEPT : __h(nullptr) + { + if (__other.__h) __other.__call(_Action::_Move, this); + } + + template < + class _ValueType + , class _Tp = decay_t<_ValueType> + , class = enable_if_t< + !is_same<_Tp, any>::value && + !__is_inplace_type<_ValueType>::value && + is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + any(_ValueType && __value); + + template <class _ValueType, class ..._Args, + class _Tp = decay_t<_ValueType>, + class = enable_if_t< + is_constructible<_Tp, _Args...>::value && + is_copy_constructible<_Tp>::value + > + > + _LIBCPP_INLINE_VISIBILITY + explicit any(in_place_type_t<_ValueType>, _Args&&... __args); + + template <class _ValueType, class _Up, class ..._Args, + class _Tp = decay_t<_ValueType>, + class = enable_if_t< + is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value && + is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + explicit any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&... __args); + + _LIBCPP_INLINE_VISIBILITY + ~any() { this->reset(); } + + // assignments + _LIBCPP_INLINE_VISIBILITY + any & operator=(any const & __rhs) { + any(__rhs).swap(*this); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + any & operator=(any && __rhs) _NOEXCEPT { + any(_VSTD::move(__rhs)).swap(*this); + return *this; + } + + template < + class _ValueType + , class _Tp = decay_t<_ValueType> + , class = enable_if_t< + !is_same<_Tp, any>::value + && is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + any & operator=(_ValueType && __rhs); + + template <class _ValueType, class ..._Args, + class _Tp = decay_t<_ValueType>, + class = enable_if_t< + is_constructible<_Tp, _Args...>::value && + is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(_Args&&... args); + + template <class _ValueType, class _Up, class ..._Args, + class _Tp = decay_t<_ValueType>, + class = enable_if_t< + is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value && + is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(initializer_list<_Up>, _Args&&...); + + // 6.3.3 any modifiers + _LIBCPP_INLINE_VISIBILITY + void reset() _NOEXCEPT { if (__h) this->__call(_Action::_Destroy); } + + _LIBCPP_INLINE_VISIBILITY + void swap(any & __rhs) _NOEXCEPT; + + // 6.3.4 any observers + _LIBCPP_INLINE_VISIBILITY + bool has_value() const _NOEXCEPT { return __h != nullptr; } + +#if !defined(_LIBCPP_NO_RTTI) + _LIBCPP_INLINE_VISIBILITY + const type_info & type() const _NOEXCEPT { + if (__h) { + return *static_cast<type_info const *>(this->__call(_Action::_TypeInfo)); + } else { + return typeid(void); + } + } +#endif + +private: + typedef __any_imp::_Action _Action; + using _HandleFuncPtr = void* (*)(_Action, any const *, any *, const type_info *, + const void* __fallback_info); + + union _Storage { + constexpr _Storage() : __ptr(nullptr) {} + void * __ptr; + __any_imp::_Buffer __buf; + }; + + _LIBCPP_INLINE_VISIBILITY + void * __call(_Action __a, any * __other = nullptr, + type_info const * __info = nullptr, + const void* __fallback_info = nullptr) const + { + return __h(__a, this, __other, __info, __fallback_info); + } + + _LIBCPP_INLINE_VISIBILITY + void * __call(_Action __a, any * __other = nullptr, + type_info const * __info = nullptr, + const void* __fallback_info = nullptr) + { + return __h(__a, this, __other, __info, __fallback_info); + } + + template <class> + friend struct __any_imp::_SmallHandler; + template <class> + friend struct __any_imp::_LargeHandler; + + template <class _ValueType> + friend add_pointer_t<add_const_t<_ValueType>> + any_cast(any const *) _NOEXCEPT; + + template <class _ValueType> + friend add_pointer_t<_ValueType> + any_cast(any *) _NOEXCEPT; + + _HandleFuncPtr __h = nullptr; + _Storage __s; +}; + +namespace __any_imp +{ + template <class _Tp> + struct _LIBCPP_TEMPLATE_VIS _SmallHandler + { + _LIBCPP_INLINE_VISIBILITY + static void* __handle(_Action __act, any const * __this, any * __other, + type_info const * __info, const void* __fallback_info) + { + switch (__act) + { + case _Action::_Destroy: + __destroy(const_cast<any &>(*__this)); + return nullptr; + case _Action::_Copy: + __copy(*__this, *__other); + return nullptr; + case _Action::_Move: + __move(const_cast<any &>(*__this), *__other); + return nullptr; + case _Action::_Get: + return __get(const_cast<any &>(*__this), __info, __fallback_info); + case _Action::_TypeInfo: + return __type_info(); + } + } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + static _Tp& __create(any & __dest, _Args&&... __args) { + _Tp* __ret = ::new (static_cast<void*>(&__dest.__s.__buf)) _Tp(_VSTD::forward<_Args>(__args)...); + __dest.__h = &_SmallHandler::__handle; + return *__ret; + } + + private: + _LIBCPP_INLINE_VISIBILITY + static void __destroy(any & __this) { + _Tp & __value = *static_cast<_Tp *>(static_cast<void*>(&__this.__s.__buf)); + __value.~_Tp(); + __this.__h = nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + static void __copy(any const & __this, any & __dest) { + _SmallHandler::__create(__dest, *static_cast<_Tp const *>( + static_cast<void const *>(&__this.__s.__buf))); + } + + _LIBCPP_INLINE_VISIBILITY + static void __move(any & __this, any & __dest) { + _SmallHandler::__create(__dest, _VSTD::move( + *static_cast<_Tp*>(static_cast<void*>(&__this.__s.__buf)))); + __destroy(__this); + } + + _LIBCPP_INLINE_VISIBILITY + static void* __get(any & __this, + type_info const * __info, + const void* __fallback_id) + { + if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_id)) + return static_cast<void*>(&__this.__s.__buf); + return nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + static void* __type_info() + { +#if !defined(_LIBCPP_NO_RTTI) + return const_cast<void*>(static_cast<void const *>(&typeid(_Tp))); +#else + return nullptr; +#endif + } + }; + + template <class _Tp> + struct _LIBCPP_TEMPLATE_VIS _LargeHandler + { + _LIBCPP_INLINE_VISIBILITY + static void* __handle(_Action __act, any const * __this, + any * __other, type_info const * __info, + void const* __fallback_info) + { + switch (__act) + { + case _Action::_Destroy: + __destroy(const_cast<any &>(*__this)); + return nullptr; + case _Action::_Copy: + __copy(*__this, *__other); + return nullptr; + case _Action::_Move: + __move(const_cast<any &>(*__this), *__other); + return nullptr; + case _Action::_Get: + return __get(const_cast<any &>(*__this), __info, __fallback_info); + case _Action::_TypeInfo: + return __type_info(); + } + } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + static _Tp& __create(any & __dest, _Args&&... __args) { + typedef allocator<_Tp> _Alloc; + typedef __allocator_destructor<_Alloc> _Dp; + _Alloc __a; + unique_ptr<_Tp, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + _Tp* __ret = ::new ((void*)__hold.get()) _Tp(_VSTD::forward<_Args>(__args)...); + __dest.__s.__ptr = __hold.release(); + __dest.__h = &_LargeHandler::__handle; + return *__ret; + } + + private: + + _LIBCPP_INLINE_VISIBILITY + static void __destroy(any & __this){ + delete static_cast<_Tp*>(__this.__s.__ptr); + __this.__h = nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + static void __copy(any const & __this, any & __dest) { + _LargeHandler::__create(__dest, *static_cast<_Tp const *>(__this.__s.__ptr)); + } + + _LIBCPP_INLINE_VISIBILITY + static void __move(any & __this, any & __dest) { + __dest.__s.__ptr = __this.__s.__ptr; + __dest.__h = &_LargeHandler::__handle; + __this.__h = nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + static void* __get(any & __this, type_info const * __info, + void const* __fallback_info) + { + if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_info)) + return static_cast<void*>(__this.__s.__ptr); + return nullptr; + + } + + _LIBCPP_INLINE_VISIBILITY + static void* __type_info() + { +#if !defined(_LIBCPP_NO_RTTI) + return const_cast<void*>(static_cast<void const *>(&typeid(_Tp))); +#else + return nullptr; +#endif + } + }; + +} // namespace __any_imp + + +template <class _ValueType, class _Tp, class> +any::any(_ValueType && __v) : __h(nullptr) +{ + __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_ValueType>(__v)); +} + +template <class _ValueType, class ..._Args, class _Tp, class> +any::any(in_place_type_t<_ValueType>, _Args&&... __args) { + __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...); +}; + +template <class _ValueType, class _Up, class ..._Args, class _Tp, class> +any::any(in_place_type_t<_ValueType>, initializer_list<_Up> __il, _Args&&... __args) { + __any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...); +} + +template <class _ValueType, class, class> +inline _LIBCPP_INLINE_VISIBILITY +any & any::operator=(_ValueType && __v) +{ + any(_VSTD::forward<_ValueType>(__v)).swap(*this); + return *this; +} + +template <class _ValueType, class ..._Args, class _Tp, class> +inline _LIBCPP_INLINE_VISIBILITY +_Tp& any::emplace(_Args&&... __args) { + reset(); + return __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...); +} + +template <class _ValueType, class _Up, class ..._Args, class _Tp, class> +inline _LIBCPP_INLINE_VISIBILITY +_Tp& any::emplace(initializer_list<_Up> __il, _Args&&... __args) { + reset(); + return __any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...); +} + +inline _LIBCPP_INLINE_VISIBILITY +void any::swap(any & __rhs) _NOEXCEPT +{ + if (this == &__rhs) + return; + if (__h && __rhs.__h) { + any __tmp; + __rhs.__call(_Action::_Move, &__tmp); + this->__call(_Action::_Move, &__rhs); + __tmp.__call(_Action::_Move, this); + } + else if (__h) { + this->__call(_Action::_Move, &__rhs); + } + else if (__rhs.__h) { + __rhs.__call(_Action::_Move, this); + } +} + +// 6.4 Non-member functions + +inline _LIBCPP_INLINE_VISIBILITY +void swap(any & __lhs, any & __rhs) _NOEXCEPT +{ + __lhs.swap(__rhs); +} + +template <class _Tp, class ..._Args> +inline _LIBCPP_INLINE_VISIBILITY +any make_any(_Args&&... __args) { + return any(in_place_type<_Tp>, _VSTD::forward<_Args>(__args)...); +} + +template <class _Tp, class _Up, class ..._Args> +inline _LIBCPP_INLINE_VISIBILITY +any make_any(initializer_list<_Up> __il, _Args&&... __args) { + return any(in_place_type<_Tp>, __il, _VSTD::forward<_Args>(__args)...); +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST +_ValueType any_cast(any const & __v) +{ + using _RawValueType = __uncvref_t<_ValueType>; + static_assert(is_constructible<_ValueType, _RawValueType const &>::value, + "ValueType is required to be a const lvalue reference " + "or a CopyConstructible type"); + auto __tmp = _VSTD::any_cast<add_const_t<_RawValueType>>(&__v); + if (__tmp == nullptr) + __throw_bad_any_cast(); + return static_cast<_ValueType>(*__tmp); +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST +_ValueType any_cast(any & __v) +{ + using _RawValueType = __uncvref_t<_ValueType>; + static_assert(is_constructible<_ValueType, _RawValueType &>::value, + "ValueType is required to be an lvalue reference " + "or a CopyConstructible type"); + auto __tmp = _VSTD::any_cast<_RawValueType>(&__v); + if (__tmp == nullptr) + __throw_bad_any_cast(); + return static_cast<_ValueType>(*__tmp); +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST +_ValueType any_cast(any && __v) +{ + using _RawValueType = __uncvref_t<_ValueType>; + static_assert(is_constructible<_ValueType, _RawValueType>::value, + "ValueType is required to be an rvalue reference " + "or a CopyConstructible type"); + auto __tmp = _VSTD::any_cast<_RawValueType>(&__v); + if (__tmp == nullptr) + __throw_bad_any_cast(); + return static_cast<_ValueType>(_VSTD::move(*__tmp)); +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +add_pointer_t<add_const_t<_ValueType>> +any_cast(any const * __any) _NOEXCEPT +{ + static_assert(!is_reference<_ValueType>::value, + "_ValueType may not be a reference."); + return _VSTD::any_cast<_ValueType>(const_cast<any *>(__any)); +} + +template <class _RetType> +inline _LIBCPP_INLINE_VISIBILITY +_RetType __pointer_or_func_cast(void* __p, /*IsFunction*/false_type) noexcept { + return static_cast<_RetType>(__p); +} + +template <class _RetType> +inline _LIBCPP_INLINE_VISIBILITY +_RetType __pointer_or_func_cast(void*, /*IsFunction*/true_type) noexcept { + return nullptr; +} + +template <class _ValueType> +add_pointer_t<_ValueType> +any_cast(any * __any) _NOEXCEPT +{ + using __any_imp::_Action; + static_assert(!is_reference<_ValueType>::value, + "_ValueType may not be a reference."); + typedef typename add_pointer<_ValueType>::type _ReturnType; + if (__any && __any->__h) { + void *__p = __any->__call(_Action::_Get, nullptr, +#if !defined(_LIBCPP_NO_RTTI) + &typeid(_ValueType), +#else + nullptr, +#endif + __any_imp::__get_fallback_typeid<_ValueType>()); + return _VSTD::__pointer_or_func_cast<_ReturnType>( + __p, is_function<_ValueType>{}); + } + return nullptr; +} + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ANY diff --git a/android/x86/include/v8/libc++/array b/android/x86/include/v8/libc++/array new file mode 100755 index 00000000..88e9d57f --- /dev/null +++ b/android/x86/include/v8/libc++/array @@ -0,0 +1,484 @@ +// -*- C++ -*- +//===---------------------------- array -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ARRAY +#define _LIBCPP_ARRAY + +/* + array synopsis + +namespace std +{ +template <class T, size_t N > +struct array +{ + // types: + typedef T & reference; + typedef const T & const_reference; + typedef implementation defined iterator; + typedef implementation defined const_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + // No explicit construct/copy/destroy for aggregate type + void fill(const T& u); + void swap(array& a) noexcept(is_nothrow_swappable_v<T>); + + // iterators: + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + constexpr size_type size() const noexcept; + constexpr size_type max_size() const noexcept; + constexpr bool empty() const noexcept; + + // element access: + reference operator[](size_type n); + const_reference operator[](size_type n) const; // constexpr in C++14 + const_reference at(size_type n) const; // constexpr in C++14 + reference at(size_type n); + + reference front(); + const_reference front() const; // constexpr in C++14 + reference back(); + const_reference back() const; // constexpr in C++14 + + T* data() noexcept; + const T* data() const noexcept; +}; + + template <class T, class... U> + array(T, U...) -> array<T, 1 + sizeof...(U)>; + +template <class T, size_t N> + bool operator==(const array<T,N>& x, const array<T,N>& y); +template <class T, size_t N> + bool operator!=(const array<T,N>& x, const array<T,N>& y); +template <class T, size_t N> + bool operator<(const array<T,N>& x, const array<T,N>& y); +template <class T, size_t N> + bool operator>(const array<T,N>& x, const array<T,N>& y); +template <class T, size_t N> + bool operator<=(const array<T,N>& x, const array<T,N>& y); +template <class T, size_t N> + bool operator>=(const array<T,N>& x, const array<T,N>& y); + +template <class T, size_t N > + void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17 + +template <class T> struct tuple_size; +template <size_t I, class T> struct tuple_element; +template <class T, size_t N> struct tuple_size<array<T, N>>; +template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; +template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 +template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 +template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 +template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 + +} // std + +*/ + +#include <__config> +#include <__tuple> +#include <type_traits> +#include <utility> +#include <iterator> +#include <algorithm> +#include <stdexcept> +#include <cstdlib> // for _LIBCPP_UNREACHABLE +#include <version> +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + + + +_LIBCPP_BEGIN_NAMESPACE_STD + + +template <class _Tp, size_t _Size> +struct _LIBCPP_TEMPLATE_VIS array +{ + // types: + typedef array __self; + typedef _Tp value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + _Tp __elems_[_Size]; + + // No explicit construct/copy/destroy for aggregate type + _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) { + _VSTD::fill_n(__elems_, _Size, __u); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) { + std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_); + } + + // iterators: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + iterator begin() _NOEXCEPT {return iterator(data());} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + const_iterator begin() const _NOEXCEPT {return const_iterator(data());} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + iterator end() _NOEXCEPT {return iterator(data() + _Size);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + const_iterator cbegin() const _NOEXCEPT {return begin();} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + const_iterator cend() const _NOEXCEPT {return end();} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + const_reverse_iterator crend() const _NOEXCEPT {return rend();} + + // capacity: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; } + + // element access: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator[](size_type __n) _NOEXCEPT {return __elems_[__n];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];} + + _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n); + _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return __elems_[0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return __elems_[_Size - 1];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return __elems_[_Size - 1];} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + value_type* data() _NOEXCEPT {return __elems_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + const value_type* data() const _NOEXCEPT {return __elems_;} +}; + + +template <class _Tp, size_t _Size> +_LIBCPP_CONSTEXPR_AFTER_CXX14 +typename array<_Tp, _Size>::reference +array<_Tp, _Size>::at(size_type __n) +{ + if (__n >= _Size) + __throw_out_of_range("array::at"); + + return __elems_[__n]; +} + +template <class _Tp, size_t _Size> +_LIBCPP_CONSTEXPR_AFTER_CXX11 +typename array<_Tp, _Size>::const_reference +array<_Tp, _Size>::at(size_type __n) const +{ + if (__n >= _Size) + __throw_out_of_range("array::at"); + return __elems_[__n]; +} + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> +{ + // types: + typedef array __self; + typedef _Tp value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + typedef typename conditional<is_const<_Tp>::value, const char, + char>::type _CharType; + + struct _ArrayInStructT { _Tp __data_[1]; }; + _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)]; + + // No explicit construct/copy/destroy for aggregate type + _LIBCPP_INLINE_VISIBILITY void fill(const value_type&) { + static_assert(!is_const<_Tp>::value, + "cannot fill zero-sized array of type 'const T'"); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(array&) _NOEXCEPT { + static_assert(!is_const<_Tp>::value, + "cannot swap zero-sized array of type 'const T'"); + } + + // iterators: + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return iterator(data());} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return const_iterator(data());} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return iterator(data());} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return const_iterator(data());} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT {return rend();} + + // capacity: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; } + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;} + + // element access: + _LIBCPP_INLINE_VISIBILITY + reference operator[](size_type) _NOEXCEPT { + _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + const_reference operator[](size_type) const _NOEXCEPT { + _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + reference at(size_type) { + __throw_out_of_range("array<T, 0>::at"); + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + const_reference at(size_type) const { + __throw_out_of_range("array<T, 0>::at"); + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + reference front() _NOEXCEPT { + _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + const_reference front() const _NOEXCEPT { + _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + reference back() _NOEXCEPT { + _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + const_reference back() const _NOEXCEPT { + _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);} + _LIBCPP_INLINE_VISIBILITY + const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);} +}; + + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _Tp, class... _Args, + class = typename enable_if<(is_same_v<_Tp, _Args> && ...), void>::type + > +array(_Tp, _Args...) + -> array<_Tp, 1 + sizeof...(_Args)>; +#endif + +template <class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template <class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), + __y.begin(), __y.end()); +} + +template <class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return __y < __x; +} + +template <class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return !(__x < __y); +} + +template <class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + _Size == 0 || + __is_swappable<_Tp>::value, + void +>::type +swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) + _NOEXCEPT_(noexcept(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Tp, size_t _Size> +struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > + : public integral_constant<size_t, _Size> {}; + +template <size_t _Ip, class _Tp, size_t _Size> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > +{ + static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); + typedef _Tp type; +}; + +template <size_t _Ip, class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp& +get(array<_Tp, _Size>& __a) _NOEXCEPT +{ + static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)"); + return __a.__elems_[_Ip]; +} + +template <size_t _Ip, class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp& +get(const array<_Tp, _Size>& __a) _NOEXCEPT +{ + static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); + return __a.__elems_[_Ip]; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <size_t _Ip, class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp&& +get(array<_Tp, _Size>&& __a) _NOEXCEPT +{ + static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)"); + return _VSTD::move(__a.__elems_[_Ip]); +} + +template <size_t _Ip, class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp&& +get(const array<_Tp, _Size>&& __a) _NOEXCEPT +{ + static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); + return _VSTD::move(__a.__elems_[_Ip]); +} + +#endif // !_LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ARRAY diff --git a/android/x86/include/v8/libc++/atomic b/android/x86/include/v8/libc++/atomic new file mode 100755 index 00000000..711c78a4 --- /dev/null +++ b/android/x86/include/v8/libc++/atomic @@ -0,0 +1,2442 @@ +// -*- C++ -*- +//===--------------------------- atomic -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ATOMIC +#define _LIBCPP_ATOMIC + +/* + atomic synopsis + +namespace std +{ + +// feature test macro + +#define __cpp_lib_atomic_is_always_lock_free // as specified by SG10 + + // order and consistency + + enum memory_order: unspecified // enum class in C++20 + { + relaxed, + consume, // load-consume + acquire, // load-acquire + release, // store-release + acq_rel, // store-release load-acquire + seq_cst // store-release load-acquire + }; + + inline constexpr auto memory_order_relaxed = memory_order::relaxed; + inline constexpr auto memory_order_consume = memory_order::consume; + inline constexpr auto memory_order_acquire = memory_order::acquire; + inline constexpr auto memory_order_release = memory_order::release; + inline constexpr auto memory_order_acq_rel = memory_order::acq_rel; + inline constexpr auto memory_order_seq_cst = memory_order::seq_cst; + +template <class T> T kill_dependency(T y) noexcept; + +// lock-free property + +#define ATOMIC_BOOL_LOCK_FREE unspecified +#define ATOMIC_CHAR_LOCK_FREE unspecified +#define ATOMIC_CHAR16_T_LOCK_FREE unspecified +#define ATOMIC_CHAR32_T_LOCK_FREE unspecified +#define ATOMIC_WCHAR_T_LOCK_FREE unspecified +#define ATOMIC_SHORT_LOCK_FREE unspecified +#define ATOMIC_INT_LOCK_FREE unspecified +#define ATOMIC_LONG_LOCK_FREE unspecified +#define ATOMIC_LLONG_LOCK_FREE unspecified +#define ATOMIC_POINTER_LOCK_FREE unspecified + +// flag type and operations + +typedef struct atomic_flag +{ + bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept; + bool test_and_set(memory_order m = memory_order_seq_cst) noexcept; + void clear(memory_order m = memory_order_seq_cst) volatile noexcept; + void clear(memory_order m = memory_order_seq_cst) noexcept; + atomic_flag() noexcept = default; + atomic_flag(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) volatile = delete; +} atomic_flag; + +bool + atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept; + +bool + atomic_flag_test_and_set(atomic_flag* obj) noexcept; + +bool + atomic_flag_test_and_set_explicit(volatile atomic_flag* obj, + memory_order m) noexcept; + +bool + atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept; + +void + atomic_flag_clear(volatile atomic_flag* obj) noexcept; + +void + atomic_flag_clear(atomic_flag* obj) noexcept; + +void + atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept; + +void + atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept; + +#define ATOMIC_FLAG_INIT see below +#define ATOMIC_VAR_INIT(value) see below + +template <class T> +struct atomic +{ + static constexpr bool is_always_lock_free; + bool is_lock_free() const volatile noexcept; + bool is_lock_free() const noexcept; + void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; + void store(T desr, memory_order m = memory_order_seq_cst) noexcept; + T load(memory_order m = memory_order_seq_cst) const volatile noexcept; + T load(memory_order m = memory_order_seq_cst) const noexcept; + operator T() const volatile noexcept; + operator T() const noexcept; + T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; + T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_weak(T& expc, T desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept; + bool compare_exchange_strong(T& expc, T desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_strong(T& expc, T desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_weak(T& expc, T desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_weak(T& expc, T desr, + memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_strong(T& expc, T desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_strong(T& expc, T desr, + memory_order m = memory_order_seq_cst) noexcept; + + atomic() noexcept = default; + constexpr atomic(T desr) noexcept; + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + T operator=(T) volatile noexcept; + T operator=(T) noexcept; +}; + +template <> +struct atomic<integral> +{ + static constexpr bool is_always_lock_free; + bool is_lock_free() const volatile noexcept; + bool is_lock_free() const noexcept; + void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept; + void store(integral desr, memory_order m = memory_order_seq_cst) noexcept; + integral load(memory_order m = memory_order_seq_cst) const volatile noexcept; + integral load(memory_order m = memory_order_seq_cst) const noexcept; + operator integral() const volatile noexcept; + operator integral() const noexcept; + integral exchange(integral desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) noexcept; + + integral + fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept; + integral + fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept; + integral + fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept; + integral + fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept; + integral + fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept; + + atomic() noexcept = default; + constexpr atomic(integral desr) noexcept; + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + integral operator=(integral desr) volatile noexcept; + integral operator=(integral desr) noexcept; + + integral operator++(int) volatile noexcept; + integral operator++(int) noexcept; + integral operator--(int) volatile noexcept; + integral operator--(int) noexcept; + integral operator++() volatile noexcept; + integral operator++() noexcept; + integral operator--() volatile noexcept; + integral operator--() noexcept; + integral operator+=(integral op) volatile noexcept; + integral operator+=(integral op) noexcept; + integral operator-=(integral op) volatile noexcept; + integral operator-=(integral op) noexcept; + integral operator&=(integral op) volatile noexcept; + integral operator&=(integral op) noexcept; + integral operator|=(integral op) volatile noexcept; + integral operator|=(integral op) noexcept; + integral operator^=(integral op) volatile noexcept; + integral operator^=(integral op) noexcept; +}; + +template <class T> +struct atomic<T*> +{ + static constexpr bool is_always_lock_free; + bool is_lock_free() const volatile noexcept; + bool is_lock_free() const noexcept; + void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; + void store(T* desr, memory_order m = memory_order_seq_cst) noexcept; + T* load(memory_order m = memory_order_seq_cst) const volatile noexcept; + T* load(memory_order m = memory_order_seq_cst) const noexcept; + operator T*() const volatile noexcept; + operator T*() const noexcept; + T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; + T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) noexcept; + T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; + T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; + T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; + T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; + + atomic() noexcept = default; + constexpr atomic(T* desr) noexcept; + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + + T* operator=(T*) volatile noexcept; + T* operator=(T*) noexcept; + T* operator++(int) volatile noexcept; + T* operator++(int) noexcept; + T* operator--(int) volatile noexcept; + T* operator--(int) noexcept; + T* operator++() volatile noexcept; + T* operator++() noexcept; + T* operator--() volatile noexcept; + T* operator--() noexcept; + T* operator+=(ptrdiff_t op) volatile noexcept; + T* operator+=(ptrdiff_t op) noexcept; + T* operator-=(ptrdiff_t op) volatile noexcept; + T* operator-=(ptrdiff_t op) noexcept; +}; + + +template <class T> + bool + atomic_is_lock_free(const volatile atomic<T>* obj) noexcept; + +template <class T> + bool + atomic_is_lock_free(const atomic<T>* obj) noexcept; + +template <class T> + void + atomic_init(volatile atomic<T>* obj, T desr) noexcept; + +template <class T> + void + atomic_init(atomic<T>* obj, T desr) noexcept; + +template <class T> + void + atomic_store(volatile atomic<T>* obj, T desr) noexcept; + +template <class T> + void + atomic_store(atomic<T>* obj, T desr) noexcept; + +template <class T> + void + atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept; + +template <class T> + void + atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept; + +template <class T> + T + atomic_load(const volatile atomic<T>* obj) noexcept; + +template <class T> + T + atomic_load(const atomic<T>* obj) noexcept; + +template <class T> + T + atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept; + +template <class T> + T + atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept; + +template <class T> + T + atomic_exchange(volatile atomic<T>* obj, T desr) noexcept; + +template <class T> + T + atomic_exchange(atomic<T>* obj, T desr) noexcept; + +template <class T> + T + atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept; + +template <class T> + T + atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept; + +template <class T> + bool + atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept; + +template <class T> + bool + atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept; + +template <class T> + bool + atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept; + +template <class T> + bool + atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept; + +template <class T> + bool + atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc, + T desr, + memory_order s, memory_order f) noexcept; + +template <class T> + bool + atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr, + memory_order s, memory_order f) noexcept; + +template <class T> + bool + atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj, + T* expc, T desr, + memory_order s, memory_order f) noexcept; + +template <class T> + bool + atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc, + T desr, + memory_order s, memory_order f) noexcept; + +template <class Integral> + Integral + atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op, + memory_order m) noexcept; +template <class Integral> + Integral + atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op, + memory_order m) noexcept; +template <class Integral> + Integral + atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op, + memory_order m) noexcept; +template <class Integral> + Integral + atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op, + memory_order m) noexcept; +template <class Integral> + Integral + atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op, + memory_order m) noexcept; +template <class Integral> + Integral + atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op, + memory_order m) noexcept; +template <class Integral> + Integral + atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op, + memory_order m) noexcept; +template <class Integral> + Integral + atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op, + memory_order m) noexcept; +template <class Integral> + Integral + atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept; + +template <class Integral> + Integral + atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op, + memory_order m) noexcept; +template <class Integral> + Integral + atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op, + memory_order m) noexcept; + +template <class T> + T* + atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept; + +template <class T> + T* + atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept; + +template <class T> + T* + atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op, + memory_order m) noexcept; +template <class T> + T* + atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept; + +template <class T> + T* + atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept; + +template <class T> + T* + atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept; + +template <class T> + T* + atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op, + memory_order m) noexcept; +template <class T> + T* + atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept; + +// Atomics for standard typedef types + +typedef atomic<bool> atomic_bool; +typedef atomic<char> atomic_char; +typedef atomic<signed char> atomic_schar; +typedef atomic<unsigned char> atomic_uchar; +typedef atomic<short> atomic_short; +typedef atomic<unsigned short> atomic_ushort; +typedef atomic<int> atomic_int; +typedef atomic<unsigned int> atomic_uint; +typedef atomic<long> atomic_long; +typedef atomic<unsigned long> atomic_ulong; +typedef atomic<long long> atomic_llong; +typedef atomic<unsigned long long> atomic_ullong; +typedef atomic<char16_t> atomic_char16_t; +typedef atomic<char32_t> atomic_char32_t; +typedef atomic<wchar_t> atomic_wchar_t; + +typedef atomic<int_least8_t> atomic_int_least8_t; +typedef atomic<uint_least8_t> atomic_uint_least8_t; +typedef atomic<int_least16_t> atomic_int_least16_t; +typedef atomic<uint_least16_t> atomic_uint_least16_t; +typedef atomic<int_least32_t> atomic_int_least32_t; +typedef atomic<uint_least32_t> atomic_uint_least32_t; +typedef atomic<int_least64_t> atomic_int_least64_t; +typedef atomic<uint_least64_t> atomic_uint_least64_t; + +typedef atomic<int_fast8_t> atomic_int_fast8_t; +typedef atomic<uint_fast8_t> atomic_uint_fast8_t; +typedef atomic<int_fast16_t> atomic_int_fast16_t; +typedef atomic<uint_fast16_t> atomic_uint_fast16_t; +typedef atomic<int_fast32_t> atomic_int_fast32_t; +typedef atomic<uint_fast32_t> atomic_uint_fast32_t; +typedef atomic<int_fast64_t> atomic_int_fast64_t; +typedef atomic<uint_fast64_t> atomic_uint_fast64_t; + +typedef atomic<int8_t> atomic_int8_t; +typedef atomic<uint8_t> atomic_uint8_t; +typedef atomic<int16_t> atomic_int16_t; +typedef atomic<uint16_t> atomic_uint16_t; +typedef atomic<int32_t> atomic_int32_t; +typedef atomic<uint32_t> atomic_uint32_t; +typedef atomic<int64_t> atomic_int64_t; +typedef atomic<uint64_t> atomic_uint64_t; + +typedef atomic<intptr_t> atomic_intptr_t; +typedef atomic<uintptr_t> atomic_uintptr_t; +typedef atomic<size_t> atomic_size_t; +typedef atomic<ptrdiff_t> atomic_ptrdiff_t; +typedef atomic<intmax_t> atomic_intmax_t; +typedef atomic<uintmax_t> atomic_uintmax_t; + +// fences + +void atomic_thread_fence(memory_order m) noexcept; +void atomic_signal_fence(memory_order m) noexcept; + +} // std + +*/ + +#include <__config> +#include <cstddef> +#include <cstdint> +#include <type_traits> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_THREADS +# error <atomic> is not supported on this single threaded system +#endif +#ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER +# error <atomic> is not implemented +#endif +#ifdef kill_dependency +# error C++ standard library is incompatible with <stdatomic.h> +#endif + +#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \ + _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \ + __m == memory_order_acquire || \ + __m == memory_order_acq_rel, \ + "memory order argument to atomic operation is invalid") + +#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \ + _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \ + __m == memory_order_acq_rel, \ + "memory order argument to atomic operation is invalid") + +#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \ + _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \ + __f == memory_order_acq_rel, \ + "memory order argument to atomic operation is invalid") + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Figure out what the underlying type for `memory_order` would be if it were +// declared as an unscoped enum (accounting for -fshort-enums). Use this result +// to pin the underlying type in C++20. +enum __legacy_memory_order { + __mo_relaxed, + __mo_consume, + __mo_acquire, + __mo_release, + __mo_acq_rel, + __mo_seq_cst +}; + +typedef underlying_type<__legacy_memory_order>::type __memory_order_underlying_t; + +#if _LIBCPP_STD_VER > 17 + +enum class memory_order : __memory_order_underlying_t { + relaxed = __mo_relaxed, + consume = __mo_consume, + acquire = __mo_acquire, + release = __mo_release, + acq_rel = __mo_acq_rel, + seq_cst = __mo_seq_cst +}; + +inline constexpr auto memory_order_relaxed = memory_order::relaxed; +inline constexpr auto memory_order_consume = memory_order::consume; +inline constexpr auto memory_order_acquire = memory_order::acquire; +inline constexpr auto memory_order_release = memory_order::release; +inline constexpr auto memory_order_acq_rel = memory_order::acq_rel; +inline constexpr auto memory_order_seq_cst = memory_order::seq_cst; + +#else + +typedef enum memory_order { + memory_order_relaxed = __mo_relaxed, + memory_order_consume = __mo_consume, + memory_order_acquire = __mo_acquire, + memory_order_release = __mo_release, + memory_order_acq_rel = __mo_acq_rel, + memory_order_seq_cst = __mo_seq_cst, +} memory_order; + +#endif // _LIBCPP_STD_VER > 17 + +static_assert((is_same<underlying_type<memory_order>::type, __memory_order_underlying_t>::value), + "unexpected underlying type for std::memory_order"); + +#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) || \ + defined(_LIBCPP_ATOMIC_ONLY_USE_BUILTINS) + +// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because +// the default operator= in an object is not volatile, a byte-by-byte copy +// is required. +template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY +typename enable_if<is_assignable<_Tp&, _Tv>::value>::type +__cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) { + __a_value = __val; +} +template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY +typename enable_if<is_assignable<_Tp&, _Tv>::value>::type +__cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) { + volatile char* __to = reinterpret_cast<volatile char*>(&__a_value); + volatile char* __end = __to + sizeof(_Tp); + volatile const char* __from = reinterpret_cast<volatile const char*>(&__val); + while (__to != __end) + *__to++ = *__from++; +} + +#endif + +#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) + +template <typename _Tp> +struct __cxx_atomic_base_impl { + + _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_CXX03_LANG + __cxx_atomic_base_impl() _NOEXCEPT = default; +#else + __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT + : __a_value(value) {} + _Tp __a_value; +}; + +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) { + // Avoid switch statement to make this a constexpr. + return __order == memory_order_relaxed ? __ATOMIC_RELAXED: + (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: + (__order == memory_order_release ? __ATOMIC_RELEASE: + (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST: + (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL: + __ATOMIC_CONSUME)))); +} + +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) { + // Avoid switch statement to make this a constexpr. + return __order == memory_order_relaxed ? __ATOMIC_RELAXED: + (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: + (__order == memory_order_release ? __ATOMIC_RELAXED: + (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST: + (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE: + __ATOMIC_CONSUME)))); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { + __cxx_atomic_assign_volatile(__a->__a_value, __val); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { + __a->__a_value = __val; +} + +_LIBCPP_INLINE_VISIBILITY inline +void __cxx_atomic_thread_fence(memory_order __order) { + __atomic_thread_fence(__to_gcc_order(__order)); +} + +_LIBCPP_INLINE_VISIBILITY inline +void __cxx_atomic_signal_fence(memory_order __order) { + __atomic_signal_fence(__to_gcc_order(__order)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, + memory_order __order) { + __atomic_store(&__a->__a_value, &__val, + __to_gcc_order(__order)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, + memory_order __order) { + __atomic_store(&__a->__a_value, &__val, + __to_gcc_order(__order)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, + memory_order __order) { + _Tp __ret; + __atomic_load(&__a->__a_value, &__ret, + __to_gcc_order(__order)); + return __ret; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { + _Tp __ret; + __atomic_load(&__a->__a_value, &__ret, + __to_gcc_order(__order)); + return __ret; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp __value, memory_order __order) { + _Tp __ret; + __atomic_exchange(&__a->__a_value, &__value, &__ret, + __to_gcc_order(__order)); + return __ret; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, + memory_order __order) { + _Tp __ret; + __atomic_exchange(&__a->__a_value, &__value, &__ret, + __to_gcc_order(__order)); + return __ret; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong( + volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, + memory_order __success, memory_order __failure) { + return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, + false, + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong( + __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, + memory_order __failure) { + return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, + false, + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak( + volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, + memory_order __success, memory_order __failure) { + return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, + true, + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak( + __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, + memory_order __failure) { + return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, + true, + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); +} + +template <typename _Tp> +struct __skip_amt { enum {value = 1}; }; + +template <typename _Tp> +struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; }; + +// FIXME: Haven't figured out what the spec says about using arrays with +// atomic_fetch_add. Force a failure rather than creating bad behavior. +template <typename _Tp> +struct __skip_amt<_Tp[]> { }; +template <typename _Tp, int n> +struct __skip_amt<_Tp[n]> { }; + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Td __delta, memory_order __order) { + return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value, + __to_gcc_order(__order)); +} + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, + memory_order __order) { + return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value, + __to_gcc_order(__order)); +} + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Td __delta, memory_order __order) { + return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value, + __to_gcc_order(__order)); +} + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, + memory_order __order) { + return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value, + __to_gcc_order(__order)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp __pattern, memory_order __order) { + return __atomic_fetch_and(&__a->__a_value, __pattern, + __to_gcc_order(__order)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, + _Tp __pattern, memory_order __order) { + return __atomic_fetch_and(&__a->__a_value, __pattern, + __to_gcc_order(__order)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp __pattern, memory_order __order) { + return __atomic_fetch_or(&__a->__a_value, __pattern, + __to_gcc_order(__order)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, + memory_order __order) { + return __atomic_fetch_or(&__a->__a_value, __pattern, + __to_gcc_order(__order)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp __pattern, memory_order __order) { + return __atomic_fetch_xor(&__a->__a_value, __pattern, + __to_gcc_order(__order)); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, + memory_order __order) { + return __atomic_fetch_xor(&__a->__a_value, __pattern, + __to_gcc_order(__order)); +} + +#define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0) + +#elif defined(_LIBCPP_HAS_C_ATOMIC_IMP) + +template <typename _Tp> +struct __cxx_atomic_base_impl { + + _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_CXX03_LANG + __cxx_atomic_base_impl() _NOEXCEPT = default; +#else + __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT + : __a_value(value) {} + _Atomic(_Tp) __a_value; +}; + +#define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s) + +_LIBCPP_INLINE_VISIBILITY inline +void __cxx_atomic_thread_fence(memory_order __order) { + __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order)); +} + +_LIBCPP_INLINE_VISIBILITY inline +void __cxx_atomic_signal_fence(memory_order __order) { + __c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) { + __c11_atomic_init(&__a->__a_value, __val); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val) { + __c11_atomic_init(&__a->__a_value, __val); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) { + __c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val, memory_order __order) { + __c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) { + using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*; + return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) { + using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*; + return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) { + return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> * __a, _Tp __value, memory_order __order) { + return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { + return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { + return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { + return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { + return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) { + return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) { + return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) { + return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) { + return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) { + return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) { + return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) { + return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) { + return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) { + return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) { + return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) { + return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) { + return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) { + return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) { + return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} + +#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp kill_dependency(_Tp __y) _NOEXCEPT +{ + return __y; +} + +#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE) +# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE +# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE +# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE +# define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE +# define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE +# define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE +# define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE +# define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE +# define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE +# define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE +#elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE) +# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE +# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE +# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE +# define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE +# define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE +# define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE +# define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE +# define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE +# define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE +# define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE +#endif + +#ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS + +template<typename _Tp> +struct __cxx_atomic_lock_impl { + + _LIBCPP_INLINE_VISIBILITY + __cxx_atomic_lock_impl() _NOEXCEPT + : __a_value(), __a_lock(0) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit + __cxx_atomic_lock_impl(_Tp value) _NOEXCEPT + : __a_value(value), __a_lock(0) {} + + _Tp __a_value; + mutable __cxx_atomic_base_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_lock; + + _LIBCPP_INLINE_VISIBILITY void __lock() const volatile { + while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire)) + /*spin*/; + } + _LIBCPP_INLINE_VISIBILITY void __lock() const { + while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire)) + /*spin*/; + } + _LIBCPP_INLINE_VISIBILITY void __unlock() const volatile { + __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release); + } + _LIBCPP_INLINE_VISIBILITY void __unlock() const { + __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release); + } + _LIBCPP_INLINE_VISIBILITY _Tp __read() const volatile { + __lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a_value); + __unlock(); + return __old; + } + _LIBCPP_INLINE_VISIBILITY _Tp __read() const { + __lock(); + _Tp __old = __a_value; + __unlock(); + return __old; + } +}; + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) { + __cxx_atomic_assign_volatile(__a->__a_value, __val); +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) { + __a->__a_value = __val; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) { + __a->__lock(); + __cxx_atomic_assign_volatile(__a->__a_value, __val); + __a->__unlock(); +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) { + __a->__lock(); + __a->__a_value = __val; + __a->__unlock(); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(const volatile __cxx_atomic_lock_impl<_Tp>* __a, memory_order) { + return __a->__read(); +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(const __cxx_atomic_lock_impl<_Tp>* __a, memory_order) { + return __a->__read(); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, __value); + __a->__unlock(); + return __old; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value = __value; + __a->__unlock(); + return __old; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp* __expected, _Tp __value, memory_order, memory_order) { + __a->__lock(); + _Tp temp; + __cxx_atomic_assign_volatile(temp, __a->__a_value); + bool __ret = temp == *__expected; + if(__ret) + __cxx_atomic_assign_volatile(__a->__a_value, __value); + else + __cxx_atomic_assign_volatile(*__expected, __a->__a_value); + __a->__unlock(); + return __ret; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp* __expected, _Tp __value, memory_order, memory_order) { + __a->__lock(); + bool __ret = __a->__a_value == *__expected; + if(__ret) + __a->__a_value = __value; + else + *__expected = __a->__a_value; + __a->__unlock(); + return __ret; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp* __expected, _Tp __value, memory_order, memory_order) { + __a->__lock(); + _Tp temp; + __cxx_atomic_assign_volatile(temp, __a->__a_value); + bool __ret = temp == *__expected; + if(__ret) + __cxx_atomic_assign_volatile(__a->__a_value, __value); + else + __cxx_atomic_assign_volatile(*__expected, __a->__a_value); + __a->__unlock(); + return __ret; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp* __expected, _Tp __value, memory_order, memory_order) { + __a->__lock(); + bool __ret = __a->__a_value == *__expected; + if(__ret) + __a->__a_value = __value; + else + *__expected = __a->__a_value; + __a->__unlock(); + return __ret; +} + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Td __delta, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old + __delta)); + __a->__unlock(); + return __old; +} +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp>* __a, + _Td __delta, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value += __delta; + __a->__unlock(); + return __old; +} + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp*>* __a, + ptrdiff_t __delta, memory_order) { + __a->__lock(); + _Tp* __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, __old + __delta); + __a->__unlock(); + return __old; +} +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp*>* __a, + ptrdiff_t __delta, memory_order) { + __a->__lock(); + _Tp* __old = __a->__a_value; + __a->__a_value += __delta; + __a->__unlock(); + return __old; +} + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Td __delta, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old - __delta)); + __a->__unlock(); + return __old; +} +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(__cxx_atomic_lock_impl<_Tp>* __a, + _Td __delta, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value -= __delta; + __a->__unlock(); + return __old; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old & __pattern)); + __a->__unlock(); + return __old; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value &= __pattern; + __a->__unlock(); + return __old; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old | __pattern)); + __a->__unlock(); + return __old; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value |= __pattern; + __a->__unlock(); + return __old; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old ^ __pattern)); + __a->__unlock(); + return __old; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value ^= __pattern; + __a->__unlock(); + return __old; +} + +#ifdef __cpp_lib_atomic_is_always_lock_free + +template<typename _Tp> struct __cxx_is_always_lock_free { + enum { __value = __atomic_always_lock_free(sizeof(_Tp), 0) }; }; + +#else + +template<typename _Tp> struct __cxx_is_always_lock_free { enum { __value = false }; }; +// Implementations must match the C ATOMIC_*_LOCK_FREE macro values. +template<> struct __cxx_is_always_lock_free<bool> { enum { __value = 2 == ATOMIC_BOOL_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<signed char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<char16_t> { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<char32_t> { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<wchar_t> { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; }; +template<typename _Tp> struct __cxx_is_always_lock_free<_Tp*> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<std::nullptr_t> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; }; + +#endif //__cpp_lib_atomic_is_always_lock_free + +template <typename _Tp, + typename _Base = typename conditional<__cxx_is_always_lock_free<_Tp>::__value, + __cxx_atomic_base_impl<_Tp>, + __cxx_atomic_lock_impl<_Tp> >::type> +#else +template <typename _Tp, + typename _Base = __cxx_atomic_base_impl<_Tp> > +#endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS +struct __cxx_atomic_impl : public _Base { + +#if _GNUC_VER >= 501 + static_assert(is_trivially_copyable<_Tp>::value, + "std::atomic<Tp> requires that 'Tp' be a trivially copyable type"); +#endif + + _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT _LIBCPP_DEFAULT + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT + : _Base(value) {} +}; + +// general atomic<T> + +template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value> +struct __atomic_base // false +{ + mutable __cxx_atomic_impl<_Tp> __a_; + +#if defined(__cpp_lib_atomic_is_always_lock_free) + static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0); +#endif + + _LIBCPP_INLINE_VISIBILITY + bool is_lock_free() const volatile _NOEXCEPT + {return __cxx_atomic_is_lock_free(sizeof(_Tp));} + _LIBCPP_INLINE_VISIBILITY + bool is_lock_free() const _NOEXCEPT + {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();} + _LIBCPP_INLINE_VISIBILITY + void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) + {__cxx_atomic_store(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) + {__cxx_atomic_store(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) + {return __cxx_atomic_load(&__a_, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) + {return __cxx_atomic_load(&__a_, __m);} + _LIBCPP_INLINE_VISIBILITY + operator _Tp() const volatile _NOEXCEPT {return load();} + _LIBCPP_INLINE_VISIBILITY + operator _Tp() const _NOEXCEPT {return load();} + _LIBCPP_INLINE_VISIBILITY + _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __cxx_atomic_exchange(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_exchange(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) volatile _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) + {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) + {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) volatile _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) + {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) + {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} + + _LIBCPP_INLINE_VISIBILITY + __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} + +#ifndef _LIBCPP_CXX03_LANG + __atomic_base(const __atomic_base&) = delete; + __atomic_base& operator=(const __atomic_base&) = delete; + __atomic_base& operator=(const __atomic_base&) volatile = delete; +#else +private: + __atomic_base(const __atomic_base&); + __atomic_base& operator=(const __atomic_base&); + __atomic_base& operator=(const __atomic_base&) volatile; +#endif +}; + +#if defined(__cpp_lib_atomic_is_always_lock_free) +template <class _Tp, bool __b> +_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free; +#endif + +// atomic<Integral> + +template <class _Tp> +struct __atomic_base<_Tp, true> + : public __atomic_base<_Tp, false> +{ + typedef __atomic_base<_Tp, false> __base; + _LIBCPP_INLINE_VISIBILITY + __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);} + + _LIBCPP_INLINE_VISIBILITY + _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;} +}; + +// atomic<T> + +template <class _Tp> +struct atomic + : public __atomic_base<_Tp> +{ + typedef __atomic_base<_Tp> __base; + _LIBCPP_INLINE_VISIBILITY + atomic() _NOEXCEPT _LIBCPP_DEFAULT + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp operator=(_Tp __d) volatile _NOEXCEPT + {__base::store(__d); return __d;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator=(_Tp __d) _NOEXCEPT + {__base::store(__d); return __d;} +}; + +// atomic<T*> + +template <class _Tp> +struct atomic<_Tp*> + : public __atomic_base<_Tp*> +{ + typedef __atomic_base<_Tp*> __base; + _LIBCPP_INLINE_VISIBILITY + atomic() _NOEXCEPT _LIBCPP_DEFAULT + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp* operator=(_Tp* __d) volatile _NOEXCEPT + {__base::store(__d); return __d;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator=(_Tp* __d) _NOEXCEPT + {__base::store(__d); return __d;} + + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + volatile _NOEXCEPT + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + volatile _NOEXCEPT + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} + + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;} +}; + +// atomic_is_lock_free + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT +{ + return __o->is_lock_free(); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT +{ + return __o->is_lock_free(); +} + +// atomic_init + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +void +atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + __cxx_atomic_init(&__o->__a_, __d); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +void +atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + __cxx_atomic_init(&__o->__a_, __d); +} + +// atomic_store + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +void +atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + __o->store(__d); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +void +atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + __o->store(__d); +} + +// atomic_store_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +void +atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) +{ + __o->store(__d, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +void +atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) +{ + __o->store(__d, __m); +} + +// atomic_load + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT +{ + return __o->load(); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load(const atomic<_Tp>* __o) _NOEXCEPT +{ + return __o->load(); +} + +// atomic_load_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) +{ + return __o->load(__m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) +{ + return __o->load(__m); +} + +// atomic_exchange + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + return __o->exchange(__d); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + return __o->exchange(__d); +} + +// atomic_exchange_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT +{ + return __o->exchange(__d, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT +{ + return __o->exchange(__d, __m); +} + +// atomic_compare_exchange_weak + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT +{ + return __o->compare_exchange_weak(*__e, __d); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT +{ + return __o->compare_exchange_weak(*__e, __d); +} + +// atomic_compare_exchange_strong + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT +{ + return __o->compare_exchange_strong(*__e, __d); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT +{ + return __o->compare_exchange_strong(*__e, __d); +} + +// atomic_compare_exchange_weak_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, + _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) +{ + return __o->compare_exchange_weak(*__e, __d, __s, __f); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) +{ + return __o->compare_exchange_weak(*__e, __d, __s, __f); +} + +// atomic_compare_exchange_strong_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, + _Tp* __e, _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) +{ + return __o->compare_exchange_strong(*__e, __d, __s, __f); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, + _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) +{ + return __o->compare_exchange_strong(*__e, __d, __s, __f); +} + +// atomic_fetch_add + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_add(__op); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_add(__op); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT +{ + return __o->fetch_add(__op); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT +{ + return __o->fetch_add(__op); +} + +// atomic_fetch_add_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_add(__op, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_add(__op, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, + memory_order __m) _NOEXCEPT +{ + return __o->fetch_add(__op, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_add(__op, __m); +} + +// atomic_fetch_sub + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_sub(__op); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_sub(__op); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT +{ + return __o->fetch_sub(__op); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT +{ + return __o->fetch_sub(__op); +} + +// atomic_fetch_sub_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_sub(__op, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_sub(__op, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, + memory_order __m) _NOEXCEPT +{ + return __o->fetch_sub(__op, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_sub(__op, __m); +} + +// atomic_fetch_and + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_and(__op); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_and(__op); +} + +// atomic_fetch_and_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_and(__op, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_and(__op, __m); +} + +// atomic_fetch_or + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_or(__op); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_or(__op); +} + +// atomic_fetch_or_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_or(__op, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_or(__op, __m); +} + +// atomic_fetch_xor + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_xor(__op); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_xor(__op); +} + +// atomic_fetch_xor_explicit + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_xor(__op, __m); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_xor(__op, __m); +} + +// flag type and operations + +typedef struct atomic_flag +{ + __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_; + + _LIBCPP_INLINE_VISIBILITY + bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);} + _LIBCPP_INLINE_VISIBILITY + bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);} + _LIBCPP_INLINE_VISIBILITY + void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);} + _LIBCPP_INLINE_VISIBILITY + void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT + {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);} + + _LIBCPP_INLINE_VISIBILITY + atomic_flag() _NOEXCEPT _LIBCPP_DEFAULT + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION + +#ifndef _LIBCPP_CXX03_LANG + atomic_flag(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) volatile = delete; +#else +private: + atomic_flag(const atomic_flag&); + atomic_flag& operator=(const atomic_flag&); + atomic_flag& operator=(const atomic_flag&) volatile; +#endif +} atomic_flag; + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT +{ + return __o->test_and_set(); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT +{ + return __o->test_and_set(); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT +{ + return __o->test_and_set(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT +{ + return __o->test_and_set(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT +{ + __o->clear(); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear(atomic_flag* __o) _NOEXCEPT +{ + __o->clear(); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT +{ + __o->clear(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT +{ + __o->clear(__m); +} + +// fences + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_thread_fence(memory_order __m) _NOEXCEPT +{ + __cxx_atomic_thread_fence(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_signal_fence(memory_order __m) _NOEXCEPT +{ + __cxx_atomic_signal_fence(__m); +} + +// Atomics for standard typedef types + +typedef atomic<bool> atomic_bool; +typedef atomic<char> atomic_char; +typedef atomic<signed char> atomic_schar; +typedef atomic<unsigned char> atomic_uchar; +typedef atomic<short> atomic_short; +typedef atomic<unsigned short> atomic_ushort; +typedef atomic<int> atomic_int; +typedef atomic<unsigned int> atomic_uint; +typedef atomic<long> atomic_long; +typedef atomic<unsigned long> atomic_ulong; +typedef atomic<long long> atomic_llong; +typedef atomic<unsigned long long> atomic_ullong; +typedef atomic<char16_t> atomic_char16_t; +typedef atomic<char32_t> atomic_char32_t; +typedef atomic<wchar_t> atomic_wchar_t; + +typedef atomic<int_least8_t> atomic_int_least8_t; +typedef atomic<uint_least8_t> atomic_uint_least8_t; +typedef atomic<int_least16_t> atomic_int_least16_t; +typedef atomic<uint_least16_t> atomic_uint_least16_t; +typedef atomic<int_least32_t> atomic_int_least32_t; +typedef atomic<uint_least32_t> atomic_uint_least32_t; +typedef atomic<int_least64_t> atomic_int_least64_t; +typedef atomic<uint_least64_t> atomic_uint_least64_t; + +typedef atomic<int_fast8_t> atomic_int_fast8_t; +typedef atomic<uint_fast8_t> atomic_uint_fast8_t; +typedef atomic<int_fast16_t> atomic_int_fast16_t; +typedef atomic<uint_fast16_t> atomic_uint_fast16_t; +typedef atomic<int_fast32_t> atomic_int_fast32_t; +typedef atomic<uint_fast32_t> atomic_uint_fast32_t; +typedef atomic<int_fast64_t> atomic_int_fast64_t; +typedef atomic<uint_fast64_t> atomic_uint_fast64_t; + +typedef atomic< int8_t> atomic_int8_t; +typedef atomic<uint8_t> atomic_uint8_t; +typedef atomic< int16_t> atomic_int16_t; +typedef atomic<uint16_t> atomic_uint16_t; +typedef atomic< int32_t> atomic_int32_t; +typedef atomic<uint32_t> atomic_uint32_t; +typedef atomic< int64_t> atomic_int64_t; +typedef atomic<uint64_t> atomic_uint64_t; + +typedef atomic<intptr_t> atomic_intptr_t; +typedef atomic<uintptr_t> atomic_uintptr_t; +typedef atomic<size_t> atomic_size_t; +typedef atomic<ptrdiff_t> atomic_ptrdiff_t; +typedef atomic<intmax_t> atomic_intmax_t; +typedef atomic<uintmax_t> atomic_uintmax_t; + +#define ATOMIC_FLAG_INIT {false} +#define ATOMIC_VAR_INIT(__v) {__v} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ATOMIC diff --git a/android/x86/include/v8/libc++/bit b/android/x86/include/v8/libc++/bit new file mode 100755 index 00000000..a2ca3bc8 --- /dev/null +++ b/android/x86/include/v8/libc++/bit @@ -0,0 +1,157 @@ +// -*- C++ -*- +//===------------------------------ bit ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP_BIT +#define _LIBCPP_BIT + +/* + bit synopsis + +namespace std { + +} // namespace std + +*/ + +#include <__config> +#include <version> + +#if defined(__IBMCPP__) +#include "support/ibm/support.h" +#endif +#if defined(_LIBCPP_COMPILER_MSVC) +#include <intrin.h> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_COMPILER_MSVC + +inline _LIBCPP_INLINE_VISIBILITY +int __ctz(unsigned __x) { return __builtin_ctz(__x); } + +inline _LIBCPP_INLINE_VISIBILITY +int __ctz(unsigned long __x) { return __builtin_ctzl(__x); } + +inline _LIBCPP_INLINE_VISIBILITY +int __ctz(unsigned long long __x) { return __builtin_ctzll(__x); } + + +inline _LIBCPP_INLINE_VISIBILITY +int __clz(unsigned __x) { return __builtin_clz(__x); } + +inline _LIBCPP_INLINE_VISIBILITY +int __clz(unsigned long __x) { return __builtin_clzl(__x); } + +inline _LIBCPP_INLINE_VISIBILITY +int __clz(unsigned long long __x) { return __builtin_clzll(__x); } + + +inline _LIBCPP_INLINE_VISIBILITY +int __popcount(unsigned __x) { return __builtin_popcount(__x); } + +inline _LIBCPP_INLINE_VISIBILITY +int __popcount(unsigned long __x) { return __builtin_popcountl(__x); } + +inline _LIBCPP_INLINE_VISIBILITY +int __popcount(unsigned long long __x) { return __builtin_popcountll(__x); } + +#else // _LIBCPP_COMPILER_MSVC + +// Precondition: __x != 0 +inline _LIBCPP_INLINE_VISIBILITY +int __ctz(unsigned __x) { + static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); + static_assert(sizeof(unsigned long) == 4, ""); + unsigned long __where; + if (_BitScanForward(&__where, __x)) + return static_cast<int>(__where); + return 32; +} + +inline _LIBCPP_INLINE_VISIBILITY +int __ctz(unsigned long __x) { + static_assert(sizeof(unsigned long) == sizeof(unsigned), ""); + return __ctz(static_cast<unsigned>(__x)); +} + +inline _LIBCPP_INLINE_VISIBILITY +int __ctz(unsigned long long __x) { + unsigned long __where; +#if defined(_LIBCPP_HAS_BITSCAN64) + (defined(_M_AMD64) || defined(__x86_64__)) + if (_BitScanForward64(&__where, __x)) + return static_cast<int>(__where); +#else + // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls. + if (_BitScanForward(&__where, static_cast<unsigned long>(__x))) + return static_cast<int>(__where); + if (_BitScanForward(&__where, static_cast<unsigned long>(__x >> 32))) + return static_cast<int>(__where + 32); +#endif + return 64; +} + +// Precondition: __x != 0 +inline _LIBCPP_INLINE_VISIBILITY +int __clz(unsigned __x) { + static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); + static_assert(sizeof(unsigned long) == 4, ""); + unsigned long __where; + if (_BitScanReverse(&__where, __x)) + return static_cast<int>(31 - __where); + return 32; // Undefined Behavior. +} + +inline _LIBCPP_INLINE_VISIBILITY +int __clz(unsigned long __x) { + static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); + return __clz(static_cast<unsigned>(__x)); +} + +inline _LIBCPP_INLINE_VISIBILITY +int __clz(unsigned long long __x) { + unsigned long __where; +#if defined(_LIBCPP_HAS_BITSCAN64) + if (_BitScanReverse64(&__where, __x)) + return static_cast<int>(63 - __where); +#else + // Win32 doesn't have _BitScanReverse64 so emulate it with two 32 bit calls. + if (_BitScanReverse(&__where, static_cast<unsigned long>(__x >> 32))) + return static_cast<int>(63 - (__where + 32)); + if (_BitScanReverse(&__where, static_cast<unsigned long>(__x))) + return static_cast<int>(63 - __where); +#endif + return 64; // Undefined Behavior. +} + +inline _LIBCPP_INLINE_VISIBILITY int __popcount(unsigned __x) { + static_assert(sizeof(unsigned) == 4, ""); + return __popcnt(__x); +} + +inline _LIBCPP_INLINE_VISIBILITY int __popcount(unsigned long __x) { + static_assert(sizeof(unsigned long) == 4, ""); + return __popcnt(__x); +} + +inline _LIBCPP_INLINE_VISIBILITY int __popcount(unsigned long long __x) { + static_assert(sizeof(unsigned long long) == 8, ""); + return __popcnt64(__x); +} + +#endif // _LIBCPP_COMPILER_MSVC + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_BIT diff --git a/android/x86/include/v8/libc++/bitset b/android/x86/include/v8/libc++/bitset new file mode 100755 index 00000000..9fb91e9b --- /dev/null +++ b/android/x86/include/v8/libc++/bitset @@ -0,0 +1,1109 @@ +// -*- C++ -*- +//===---------------------------- bitset ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_BITSET +#define _LIBCPP_BITSET + +/* + bitset synopsis + +namespace std +{ + +namespace std { + +template <size_t N> +class bitset +{ +public: + // bit reference: + class reference + { + friend class bitset; + reference() noexcept; + public: + ~reference() noexcept; + reference& operator=(bool x) noexcept; // for b[i] = x; + reference& operator=(const reference&) noexcept; // for b[i] = b[j]; + bool operator~() const noexcept; // flips the bit + operator bool() const noexcept; // for x = b[i]; + reference& flip() noexcept; // for b[i].flip(); + }; + + // 23.3.5.1 constructors: + constexpr bitset() noexcept; + constexpr bitset(unsigned long long val) noexcept; + template <class charT> + explicit bitset(const charT* str, + typename basic_string<charT>::size_type n = basic_string<charT>::npos, + charT zero = charT('0'), charT one = charT('1')); + template<class charT, class traits, class Allocator> + explicit bitset(const basic_string<charT,traits,Allocator>& str, + typename basic_string<charT,traits,Allocator>::size_type pos = 0, + typename basic_string<charT,traits,Allocator>::size_type n = + basic_string<charT,traits,Allocator>::npos, + charT zero = charT('0'), charT one = charT('1')); + + // 23.3.5.2 bitset operations: + bitset& operator&=(const bitset& rhs) noexcept; + bitset& operator|=(const bitset& rhs) noexcept; + bitset& operator^=(const bitset& rhs) noexcept; + bitset& operator<<=(size_t pos) noexcept; + bitset& operator>>=(size_t pos) noexcept; + bitset& set() noexcept; + bitset& set(size_t pos, bool val = true); + bitset& reset() noexcept; + bitset& reset(size_t pos); + bitset operator~() const noexcept; + bitset& flip() noexcept; + bitset& flip(size_t pos); + + // element access: + constexpr bool operator[](size_t pos) const; // for b[i]; + reference operator[](size_t pos); // for b[i]; + unsigned long to_ulong() const; + unsigned long long to_ullong() const; + template <class charT, class traits, class Allocator> + basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; + template <class charT, class traits> + basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; + template <class charT> + basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; + basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; + size_t count() const noexcept; + constexpr size_t size() const noexcept; + bool operator==(const bitset& rhs) const noexcept; + bool operator!=(const bitset& rhs) const noexcept; + bool test(size_t pos) const; + bool all() const noexcept; + bool any() const noexcept; + bool none() const noexcept; + bitset operator<<(size_t pos) const noexcept; + bitset operator>>(size_t pos) const noexcept; +}; + +// 23.3.5.3 bitset operators: +template <size_t N> +bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; + +template <size_t N> +bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; + +template <size_t N> +bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; + +template <class charT, class traits, size_t N> +basic_istream<charT, traits>& +operator>>(basic_istream<charT, traits>& is, bitset<N>& x); + +template <class charT, class traits, size_t N> +basic_ostream<charT, traits>& +operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); + +template <size_t N> struct hash<std::bitset<N>>; + +} // std + +*/ + +#include <__config> +#include <__bit_reference> +#include <cstddef> +#include <climits> +#include <string> +#include <stdexcept> +#include <iosfwd> +#include <__functional_base> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <size_t _N_words, size_t _Size> +class __bitset; + +template <size_t _N_words, size_t _Size> +struct __has_storage_type<__bitset<_N_words, _Size> > +{ + static const bool value = true; +}; + +template <size_t _N_words, size_t _Size> +class __bitset +{ +public: + typedef ptrdiff_t difference_type; + typedef size_t size_type; + typedef size_type __storage_type; +protected: + typedef __bitset __self; + typedef __storage_type* __storage_pointer; + typedef const __storage_type* __const_storage_pointer; + static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); + + friend class __bit_reference<__bitset>; + friend class __bit_const_reference<__bitset>; + friend class __bit_iterator<__bitset, false>; + friend class __bit_iterator<__bitset, true>; + friend struct __bit_array<__bitset>; + + __storage_type __first_[_N_words]; + + typedef __bit_reference<__bitset> reference; + typedef __bit_const_reference<__bitset> const_reference; + typedef __bit_iterator<__bitset, false> iterator; + typedef __bit_iterator<__bitset, true> const_iterator; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT + {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT + {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT + {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT + {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + + _LIBCPP_INLINE_VISIBILITY + void operator&=(const __bitset& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void operator|=(const __bitset& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void operator^=(const __bitset& __v) _NOEXCEPT; + + void flip() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const + {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());} + _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const + {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());} + + bool all() const _NOEXCEPT; + bool any() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_t __hash_code() const _NOEXCEPT; +private: +#ifdef _LIBCPP_CXX03_LANG + void __init(unsigned long long __v, false_type) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void __init(unsigned long long __v, true_type) _NOEXCEPT; +#endif // _LIBCPP_CXX03_LANG + unsigned long to_ulong(false_type) const; + _LIBCPP_INLINE_VISIBILITY + unsigned long to_ulong(true_type) const; + unsigned long long to_ullong(false_type) const; + _LIBCPP_INLINE_VISIBILITY + unsigned long long to_ullong(true_type) const; + _LIBCPP_INLINE_VISIBILITY + unsigned long long to_ullong(true_type, false_type) const; + unsigned long long to_ullong(true_type, true_type) const; +}; + +template <size_t _N_words, size_t _Size> +inline +_LIBCPP_CONSTEXPR +__bitset<_N_words, _Size>::__bitset() _NOEXCEPT +#ifndef _LIBCPP_CXX03_LANG + : __first_{0} +#endif +{ +#ifdef _LIBCPP_CXX03_LANG + _VSTD::fill_n(__first_, _N_words, __storage_type(0)); +#endif +} + +#ifdef _LIBCPP_CXX03_LANG + +template <size_t _N_words, size_t _Size> +void +__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT +{ + __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; + size_t __sz = _Size; + for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) + if ( __sz < __bits_per_word) + __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; + else + __t[__i] = static_cast<__storage_type>(__v); + + _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); + _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), + __storage_type(0)); +} + +template <size_t _N_words, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +void +__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT +{ + __first_[0] = __v; + if (_Size < __bits_per_word) + __first_[0] &= ( 1ULL << _Size ) - 1; + + _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); +} + +#endif // _LIBCPP_CXX03_LANG + +template <size_t _N_words, size_t _Size> +inline +_LIBCPP_CONSTEXPR +__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT +#ifndef _LIBCPP_CXX03_LANG +#if __SIZEOF_SIZE_T__ == 8 + : __first_{__v} +#elif __SIZEOF_SIZE_T__ == 4 + : __first_{static_cast<__storage_type>(__v), + _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) + : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} +#else +#error This constructor has not been ported to this platform +#endif +#endif +{ +#ifdef _LIBCPP_CXX03_LANG + __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); +#endif +} + +template <size_t _N_words, size_t _Size> +inline +void +__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT +{ + for (size_type __i = 0; __i < _N_words; ++__i) + __first_[__i] &= __v.__first_[__i]; +} + +template <size_t _N_words, size_t _Size> +inline +void +__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT +{ + for (size_type __i = 0; __i < _N_words; ++__i) + __first_[__i] |= __v.__first_[__i]; +} + +template <size_t _N_words, size_t _Size> +inline +void +__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT +{ + for (size_type __i = 0; __i < _N_words; ++__i) + __first_[__i] ^= __v.__first_[__i]; +} + +template <size_t _N_words, size_t _Size> +void +__bitset<_N_words, _Size>::flip() _NOEXCEPT +{ + // do middle whole words + size_type __n = _Size; + __storage_pointer __p = __first_; + for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) + *__p = ~*__p; + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__p & __m; + *__p &= ~__m; + *__p |= ~__b & __m; + } +} + +template <size_t _N_words, size_t _Size> +unsigned long +__bitset<_N_words, _Size>::to_ulong(false_type) const +{ + const_iterator __e = __make_iter(_Size); + const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); + if (__i != __e) + __throw_overflow_error("bitset to_ulong overflow error"); + + return __first_[0]; +} + +template <size_t _N_words, size_t _Size> +inline +unsigned long +__bitset<_N_words, _Size>::to_ulong(true_type) const +{ + return __first_[0]; +} + +template <size_t _N_words, size_t _Size> +unsigned long long +__bitset<_N_words, _Size>::to_ullong(false_type) const +{ + const_iterator __e = __make_iter(_Size); + const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); + if (__i != __e) + __throw_overflow_error("bitset to_ullong overflow error"); + + return to_ullong(true_type()); +} + +template <size_t _N_words, size_t _Size> +inline +unsigned long long +__bitset<_N_words, _Size>::to_ullong(true_type) const +{ + return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); +} + +template <size_t _N_words, size_t _Size> +inline +unsigned long long +__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const +{ + return __first_[0]; +} + +template <size_t _N_words, size_t _Size> +unsigned long long +__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const +{ + unsigned long long __r = __first_[0]; + for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) + __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); + return __r; +} + +template <size_t _N_words, size_t _Size> +bool +__bitset<_N_words, _Size>::all() const _NOEXCEPT +{ + // do middle whole words + size_type __n = _Size; + __const_storage_pointer __p = __first_; + for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) + if (~*__p) + return false; + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + if (~*__p & __m) + return false; + } + return true; +} + +template <size_t _N_words, size_t _Size> +bool +__bitset<_N_words, _Size>::any() const _NOEXCEPT +{ + // do middle whole words + size_type __n = _Size; + __const_storage_pointer __p = __first_; + for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) + if (*__p) + return true; + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + if (*__p & __m) + return true; + } + return false; +} + +template <size_t _N_words, size_t _Size> +inline +size_t +__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT +{ + size_t __h = 0; + for (size_type __i = 0; __i < _N_words; ++__i) + __h ^= __first_[__i]; + return __h; +} + +template <size_t _Size> +class __bitset<1, _Size> +{ +public: + typedef ptrdiff_t difference_type; + typedef size_t size_type; + typedef size_type __storage_type; +protected: + typedef __bitset __self; + typedef __storage_type* __storage_pointer; + typedef const __storage_type* __const_storage_pointer; + static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); + + friend class __bit_reference<__bitset>; + friend class __bit_const_reference<__bitset>; + friend class __bit_iterator<__bitset, false>; + friend class __bit_iterator<__bitset, true>; + friend struct __bit_array<__bitset>; + + __storage_type __first_; + + typedef __bit_reference<__bitset> reference; + typedef __bit_const_reference<__bitset> const_reference; + typedef __bit_iterator<__bitset, false> iterator; + typedef __bit_iterator<__bitset, true> const_iterator; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT + {return reference(&__first_, __storage_type(1) << __pos);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT + {return const_reference(&__first_, __storage_type(1) << __pos);} + _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT + {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT + {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + + _LIBCPP_INLINE_VISIBILITY + void operator&=(const __bitset& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void operator|=(const __bitset& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void operator^=(const __bitset& __v) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + void flip() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + unsigned long to_ulong() const; + _LIBCPP_INLINE_VISIBILITY + unsigned long long to_ullong() const; + + _LIBCPP_INLINE_VISIBILITY + bool all() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bool any() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + size_t __hash_code() const _NOEXCEPT; +}; + +template <size_t _Size> +inline +_LIBCPP_CONSTEXPR +__bitset<1, _Size>::__bitset() _NOEXCEPT + : __first_(0) +{ +} + +template <size_t _Size> +inline +_LIBCPP_CONSTEXPR +__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT + : __first_( + _Size == __bits_per_word ? static_cast<__storage_type>(__v) + : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) + ) +{ +} + +template <size_t _Size> +inline +void +__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT +{ + __first_ &= __v.__first_; +} + +template <size_t _Size> +inline +void +__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT +{ + __first_ |= __v.__first_; +} + +template <size_t _Size> +inline +void +__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT +{ + __first_ ^= __v.__first_; +} + +template <size_t _Size> +inline +void +__bitset<1, _Size>::flip() _NOEXCEPT +{ + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); + __first_ = ~__first_; + __first_ &= __m; +} + +template <size_t _Size> +inline +unsigned long +__bitset<1, _Size>::to_ulong() const +{ + return __first_; +} + +template <size_t _Size> +inline +unsigned long long +__bitset<1, _Size>::to_ullong() const +{ + return __first_; +} + +template <size_t _Size> +inline +bool +__bitset<1, _Size>::all() const _NOEXCEPT +{ + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); + return !(~__first_ & __m); +} + +template <size_t _Size> +inline +bool +__bitset<1, _Size>::any() const _NOEXCEPT +{ + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); + return __first_ & __m; +} + +template <size_t _Size> +inline +size_t +__bitset<1, _Size>::__hash_code() const _NOEXCEPT +{ + return __first_; +} + +template <> +class __bitset<0, 0> +{ +public: + typedef ptrdiff_t difference_type; + typedef size_t size_type; + typedef size_type __storage_type; +protected: + typedef __bitset __self; + typedef __storage_type* __storage_pointer; + typedef const __storage_type* __const_storage_pointer; + static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); + + friend class __bit_reference<__bitset>; + friend class __bit_const_reference<__bitset>; + friend class __bit_iterator<__bitset, false>; + friend class __bit_iterator<__bitset, true>; + friend struct __bit_array<__bitset>; + + typedef __bit_reference<__bitset> reference; + typedef __bit_const_reference<__bitset> const_reference; + typedef __bit_iterator<__bitset, false> iterator; + typedef __bit_iterator<__bitset, true> const_iterator; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT + {return reference(0, 1);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT + {return const_reference(0, 1);} + _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT + {return iterator(0, 0);} + _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT + {return const_iterator(0, 0);} + + _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;} + _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;} + + _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;} + _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;} + + _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} +}; + +inline +_LIBCPP_CONSTEXPR +__bitset<0, 0>::__bitset() _NOEXCEPT +{ +} + +inline +_LIBCPP_CONSTEXPR +__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT +{ +} + +template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset; +template <size_t _Size> struct hash<bitset<_Size> >; + +template <size_t _Size> +class _LIBCPP_TEMPLATE_VIS bitset + : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> +{ +public: + static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; + typedef __bitset<__n_words, _Size> base; + +public: + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + + // 23.3.5.1 constructors: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} + template<class _CharT> + explicit bitset(const _CharT* __str, + typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, + _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); + template<class _CharT, class _Traits, class _Allocator> + explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, + typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, + typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = + (basic_string<_CharT,_Traits,_Allocator>::npos), + _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); + + // 23.3.5.2 bitset operations: + _LIBCPP_INLINE_VISIBILITY + bitset& operator&=(const bitset& __rhs) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bitset& operator|=(const bitset& __rhs) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bitset& operator^=(const bitset& __rhs) _NOEXCEPT; + bitset& operator<<=(size_t __pos) _NOEXCEPT; + bitset& operator>>=(size_t __pos) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bitset& set() _NOEXCEPT; + bitset& set(size_t __pos, bool __val = true); + _LIBCPP_INLINE_VISIBILITY + bitset& reset() _NOEXCEPT; + bitset& reset(size_t __pos); + _LIBCPP_INLINE_VISIBILITY + bitset operator~() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bitset& flip() _NOEXCEPT; + bitset& flip(size_t __pos); + + // element access: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + const_reference operator[](size_t __p) const {return base::__make_ref(__p);} + _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} + _LIBCPP_INLINE_VISIBILITY + unsigned long to_ulong() const; + _LIBCPP_INLINE_VISIBILITY + unsigned long long to_ullong() const; + template <class _CharT, class _Traits, class _Allocator> + basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), + _CharT __one = _CharT('1')) const; + template <class _CharT, class _Traits> + _LIBCPP_INLINE_VISIBILITY + basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), + _CharT __one = _CharT('1')) const; + template <class _CharT> + _LIBCPP_INLINE_VISIBILITY + basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), + _CharT __one = _CharT('1')) const; + _LIBCPP_INLINE_VISIBILITY + basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', + char __one = '1') const; + _LIBCPP_INLINE_VISIBILITY + size_t count() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} + _LIBCPP_INLINE_VISIBILITY + bool operator==(const bitset& __rhs) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const bitset& __rhs) const _NOEXCEPT; + bool test(size_t __pos) const; + _LIBCPP_INLINE_VISIBILITY + bool all() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bool any() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} + _LIBCPP_INLINE_VISIBILITY + bitset operator<<(size_t __pos) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bitset operator>>(size_t __pos) const _NOEXCEPT; + +private: + + _LIBCPP_INLINE_VISIBILITY + size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} + + friend struct hash<bitset>; +}; + +template <size_t _Size> +template<class _CharT> +bitset<_Size>::bitset(const _CharT* __str, + typename basic_string<_CharT>::size_type __n, + _CharT __zero, _CharT __one) +{ + size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); + for (size_t __i = 0; __i < __rlen; ++__i) + if (__str[__i] != __zero && __str[__i] != __one) + __throw_invalid_argument("bitset string ctor has invalid argument"); + + size_t _Mp = _VSTD::min(__rlen, _Size); + size_t __i = 0; + for (; __i < _Mp; ++__i) + { + _CharT __c = __str[_Mp - 1 - __i]; + if (__c == __zero) + (*this)[__i] = false; + else + (*this)[__i] = true; + } + _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); +} + +template <size_t _Size> +template<class _CharT, class _Traits, class _Allocator> +bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, + typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, + typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, + _CharT __zero, _CharT __one) +{ + if (__pos > __str.size()) + __throw_out_of_range("bitset string pos out of range"); + + size_t __rlen = _VSTD::min(__n, __str.size() - __pos); + for (size_t __i = __pos; __i < __pos + __rlen; ++__i) + if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) + __throw_invalid_argument("bitset string ctor has invalid argument"); + + size_t _Mp = _VSTD::min(__rlen, _Size); + size_t __i = 0; + for (; __i < _Mp; ++__i) + { + _CharT __c = __str[__pos + _Mp - 1 - __i]; + if (_Traits::eq(__c, __zero)) + (*this)[__i] = false; + else + (*this)[__i] = true; + } + _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); +} + +template <size_t _Size> +inline +bitset<_Size>& +bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT +{ + base::operator&=(__rhs); + return *this; +} + +template <size_t _Size> +inline +bitset<_Size>& +bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT +{ + base::operator|=(__rhs); + return *this; +} + +template <size_t _Size> +inline +bitset<_Size>& +bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT +{ + base::operator^=(__rhs); + return *this; +} + +template <size_t _Size> +bitset<_Size>& +bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT +{ + __pos = _VSTD::min(__pos, _Size); + _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); + _VSTD::fill_n(base::__make_iter(0), __pos, false); + return *this; +} + +template <size_t _Size> +bitset<_Size>& +bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT +{ + __pos = _VSTD::min(__pos, _Size); + _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); + _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); + return *this; +} + +template <size_t _Size> +inline +bitset<_Size>& +bitset<_Size>::set() _NOEXCEPT +{ + _VSTD::fill_n(base::__make_iter(0), _Size, true); + return *this; +} + +template <size_t _Size> +bitset<_Size>& +bitset<_Size>::set(size_t __pos, bool __val) +{ + if (__pos >= _Size) + __throw_out_of_range("bitset set argument out of range"); + + (*this)[__pos] = __val; + return *this; +} + +template <size_t _Size> +inline +bitset<_Size>& +bitset<_Size>::reset() _NOEXCEPT +{ + _VSTD::fill_n(base::__make_iter(0), _Size, false); + return *this; +} + +template <size_t _Size> +bitset<_Size>& +bitset<_Size>::reset(size_t __pos) +{ + if (__pos >= _Size) + __throw_out_of_range("bitset reset argument out of range"); + + (*this)[__pos] = false; + return *this; +} + +template <size_t _Size> +inline +bitset<_Size> +bitset<_Size>::operator~() const _NOEXCEPT +{ + bitset __x(*this); + __x.flip(); + return __x; +} + +template <size_t _Size> +inline +bitset<_Size>& +bitset<_Size>::flip() _NOEXCEPT +{ + base::flip(); + return *this; +} + +template <size_t _Size> +bitset<_Size>& +bitset<_Size>::flip(size_t __pos) +{ + if (__pos >= _Size) + __throw_out_of_range("bitset flip argument out of range"); + + reference r = base::__make_ref(__pos); + r = ~r; + return *this; +} + +template <size_t _Size> +inline +unsigned long +bitset<_Size>::to_ulong() const +{ + return base::to_ulong(); +} + +template <size_t _Size> +inline +unsigned long long +bitset<_Size>::to_ullong() const +{ + return base::to_ullong(); +} + +template <size_t _Size> +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +bitset<_Size>::to_string(_CharT __zero, _CharT __one) const +{ + basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); + for (size_t __i = 0; __i < _Size; ++__i) + { + if ((*this)[__i]) + __r[_Size - 1 - __i] = __one; + } + return __r; +} + +template <size_t _Size> +template <class _CharT, class _Traits> +inline +basic_string<_CharT, _Traits, allocator<_CharT> > +bitset<_Size>::to_string(_CharT __zero, _CharT __one) const +{ + return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); +} + +template <size_t _Size> +template <class _CharT> +inline +basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > +bitset<_Size>::to_string(_CharT __zero, _CharT __one) const +{ + return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); +} + +template <size_t _Size> +inline +basic_string<char, char_traits<char>, allocator<char> > +bitset<_Size>::to_string(char __zero, char __one) const +{ + return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); +} + +template <size_t _Size> +inline +size_t +bitset<_Size>::count() const _NOEXCEPT +{ + return static_cast<size_t>(__count_bool_true(base::__make_iter(0), _Size)); +} + +template <size_t _Size> +inline +bool +bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT +{ + return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); +} + +template <size_t _Size> +inline +bool +bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT +{ + return !(*this == __rhs); +} + +template <size_t _Size> +bool +bitset<_Size>::test(size_t __pos) const +{ + if (__pos >= _Size) + __throw_out_of_range("bitset test argument out of range"); + + return (*this)[__pos]; +} + +template <size_t _Size> +inline +bool +bitset<_Size>::all() const _NOEXCEPT +{ + return base::all(); +} + +template <size_t _Size> +inline +bool +bitset<_Size>::any() const _NOEXCEPT +{ + return base::any(); +} + +template <size_t _Size> +inline +bitset<_Size> +bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT +{ + bitset __r = *this; + __r <<= __pos; + return __r; +} + +template <size_t _Size> +inline +bitset<_Size> +bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT +{ + bitset __r = *this; + __r >>= __pos; + return __r; +} + +template <size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size> +operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT +{ + bitset<_Size> __r = __x; + __r &= __y; + return __r; +} + +template <size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size> +operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT +{ + bitset<_Size> __r = __x; + __r |= __y; + return __r; +} + +template <size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size> +operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT +{ + bitset<_Size> __r = __x; + __r ^= __y; + return __r; +} + +template <size_t _Size> +struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > + : public unary_function<bitset<_Size>, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT + {return __bs.__hash_code();} +}; + +template <class _CharT, class _Traits, size_t _Size> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); + +template <class _CharT, class _Traits, size_t _Size> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_BITSET diff --git a/android/x86/include/v8/libc++/cassert b/android/x86/include/v8/libc++/cassert new file mode 100755 index 00000000..25a0a746 --- /dev/null +++ b/android/x86/include/v8/libc++/cassert @@ -0,0 +1,24 @@ +// -*- C++ -*- +//===-------------------------- cassert -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +/* + cassert synopsis + +Macros: + + assert + +*/ + +#include <__config> +#include <assert.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif diff --git a/android/x86/include/v8/libc++/ccomplex b/android/x86/include/v8/libc++/ccomplex new file mode 100755 index 00000000..0d2e0f5a --- /dev/null +++ b/android/x86/include/v8/libc++/ccomplex @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===--------------------------- ccomplex ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CCOMPLEX +#define _LIBCPP_CCOMPLEX + +/* + ccomplex synopsis + +#include <complex> + +*/ + +#include <complex> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +// hh 080623 Created + +#endif // _LIBCPP_CCOMPLEX diff --git a/android/x86/include/v8/libc++/cctype b/android/x86/include/v8/libc++/cctype new file mode 100755 index 00000000..55fc9ebc --- /dev/null +++ b/android/x86/include/v8/libc++/cctype @@ -0,0 +1,120 @@ +// -*- C++ -*- +//===---------------------------- cctype ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CCTYPE +#define _LIBCPP_CCTYPE + +/* + cctype synopsis + +namespace std +{ + +int isalnum(int c); +int isalpha(int c); +int isblank(int c); // C99 +int iscntrl(int c); +int isdigit(int c); +int isgraph(int c); +int islower(int c); +int isprint(int c); +int ispunct(int c); +int isspace(int c); +int isupper(int c); +int isxdigit(int c); +int tolower(int c); +int toupper(int c); + +} // std +*/ + +#include <__config> +#include <ctype.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef isalnum +#undef isalnum +#endif + +#ifdef isalpha +#undef isalpha +#endif + +#ifdef isblank +#undef isblank +#endif + +#ifdef iscntrl +#undef iscntrl +#endif + +#ifdef isdigit +#undef isdigit +#endif + +#ifdef isgraph +#undef isgraph +#endif + +#ifdef islower +#undef islower +#endif + +#ifdef isprint +#undef isprint +#endif + +#ifdef ispunct +#undef ispunct +#endif + +#ifdef isspace +#undef isspace +#endif + +#ifdef isupper +#undef isupper +#endif + +#ifdef isxdigit +#undef isxdigit +#endif + +#ifdef tolower +#undef tolower +#endif + +#ifdef toupper +#undef toupper +#endif + + +using ::isalnum; +using ::isalpha; +using ::isblank; +using ::iscntrl; +using ::isdigit; +using ::isgraph; +using ::islower; +using ::isprint; +using ::ispunct; +using ::isspace; +using ::isupper; +using ::isxdigit; +using ::tolower; +using ::toupper; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CCTYPE diff --git a/android/x86/include/v8/libc++/cerrno b/android/x86/include/v8/libc++/cerrno new file mode 100755 index 00000000..a9268a28 --- /dev/null +++ b/android/x86/include/v8/libc++/cerrno @@ -0,0 +1,32 @@ +// -*- C++ -*- +//===-------------------------- cerrno ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CERRNO +#define _LIBCPP_CERRNO + +/* + cerrno synopsis + +Macros: + + EDOM + EILSEQ // C99 + ERANGE + errno + +*/ + +#include <__config> +#include <errno.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#endif // _LIBCPP_CERRNO diff --git a/android/x86/include/v8/libc++/cfenv b/android/x86/include/v8/libc++/cfenv new file mode 100755 index 00000000..6cd91db5 --- /dev/null +++ b/android/x86/include/v8/libc++/cfenv @@ -0,0 +1,81 @@ +// -*- C++ -*- +//===---------------------------- cfenv -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CFENV +#define _LIBCPP_CFENV + +/* + cfenv synopsis + +This entire header is C99 / C++0X + +Macros: + + FE_DIVBYZERO + FE_INEXACT + FE_INVALID + FE_OVERFLOW + FE_UNDERFLOW + FE_ALL_EXCEPT + FE_DOWNWARD + FE_TONEAREST + FE_TOWARDZERO + FE_UPWARD + FE_DFL_ENV + +namespace std +{ + +Types: + + fenv_t + fexcept_t + +int feclearexcept(int excepts); +int fegetexceptflag(fexcept_t* flagp, int excepts); +int feraiseexcept(int excepts); +int fesetexceptflag(const fexcept_t* flagp, int excepts); +int fetestexcept(int excepts); +int fegetround(); +int fesetround(int round); +int fegetenv(fenv_t* envp); +int feholdexcept(fenv_t* envp); +int fesetenv(const fenv_t* envp); +int feupdateenv(const fenv_t* envp); + +} // std +*/ + +#include <__config> +#include <fenv.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::fenv_t; +using ::fexcept_t; + +using ::feclearexcept; +using ::fegetexceptflag; +using ::feraiseexcept; +using ::fesetexceptflag; +using ::fetestexcept; +using ::fegetround; +using ::fesetround; +using ::fegetenv; +using ::feholdexcept; +using ::fesetenv; +using ::feupdateenv; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CFENV diff --git a/android/x86/include/v8/libc++/cfloat b/android/x86/include/v8/libc++/cfloat new file mode 100755 index 00000000..da22c6f6 --- /dev/null +++ b/android/x86/include/v8/libc++/cfloat @@ -0,0 +1,79 @@ +// -*- C++ -*- +//===--------------------------- cfloat -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CFLOAT +#define _LIBCPP_CFLOAT + +/* + cfloat synopsis + +Macros: + + FLT_ROUNDS + FLT_EVAL_METHOD // C99 + FLT_RADIX + + FLT_HAS_SUBNORM // C11 + DBL_HAS_SUBNORM // C11 + LDBL_HAS_SUBNORM // C11 + + FLT_MANT_DIG + DBL_MANT_DIG + LDBL_MANT_DIG + + DECIMAL_DIG // C99 + FLT_DECIMAL_DIG // C11 + DBL_DECIMAL_DIG // C11 + LDBL_DECIMAL_DIG // C11 + + FLT_DIG + DBL_DIG + LDBL_DIG + + FLT_MIN_EXP + DBL_MIN_EXP + LDBL_MIN_EXP + + FLT_MIN_10_EXP + DBL_MIN_10_EXP + LDBL_MIN_10_EXP + + FLT_MAX_EXP + DBL_MAX_EXP + LDBL_MAX_EXP + + FLT_MAX_10_EXP + DBL_MAX_10_EXP + LDBL_MAX_10_EXP + + FLT_MAX + DBL_MAX + LDBL_MAX + + FLT_EPSILON + DBL_EPSILON + LDBL_EPSILON + + FLT_MIN + DBL_MIN + LDBL_MIN + + FLT_TRUE_MIN // C11 + DBL_TRUE_MIN // C11 + LDBL_TRUE_MIN // C11 +*/ + +#include <__config> +#include <float.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#endif // _LIBCPP_CFLOAT diff --git a/android/x86/include/v8/libc++/charconv b/android/x86/include/v8/libc++/charconv new file mode 100755 index 00000000..4e84ef68 --- /dev/null +++ b/android/x86/include/v8/libc++/charconv @@ -0,0 +1,616 @@ +// -*- C++ -*- +//===------------------------------ charconv ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CHARCONV +#define _LIBCPP_CHARCONV + +/* + charconv synopsis + +namespace std { + + // floating-point format for primitive numerical conversion + enum class chars_format { + scientific = unspecified, + fixed = unspecified, + hex = unspecified, + general = fixed | scientific + }; + + // 23.20.2, primitive numerical output conversion + struct to_chars_result { + char* ptr; + errc ec; + }; + + to_chars_result to_chars(char* first, char* last, see below value, + int base = 10); + + to_chars_result to_chars(char* first, char* last, float value); + to_chars_result to_chars(char* first, char* last, double value); + to_chars_result to_chars(char* first, char* last, long double value); + + to_chars_result to_chars(char* first, char* last, float value, + chars_format fmt); + to_chars_result to_chars(char* first, char* last, double value, + chars_format fmt); + to_chars_result to_chars(char* first, char* last, long double value, + chars_format fmt); + + to_chars_result to_chars(char* first, char* last, float value, + chars_format fmt, int precision); + to_chars_result to_chars(char* first, char* last, double value, + chars_format fmt, int precision); + to_chars_result to_chars(char* first, char* last, long double value, + chars_format fmt, int precision); + + // 23.20.3, primitive numerical input conversion + struct from_chars_result { + const char* ptr; + errc ec; + }; + + from_chars_result from_chars(const char* first, const char* last, + see below& value, int base = 10); + + from_chars_result from_chars(const char* first, const char* last, + float& value, + chars_format fmt = chars_format::general); + from_chars_result from_chars(const char* first, const char* last, + double& value, + chars_format fmt = chars_format::general); + from_chars_result from_chars(const char* first, const char* last, + long double& value, + chars_format fmt = chars_format::general); + +} // namespace std + +*/ + +#include <__errc> +#include <type_traits> +#include <limits> +#include <stdint.h> +#include <string.h> +#include <math.h> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace __itoa { +_LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer); +_LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer); +} + +#ifndef _LIBCPP_CXX03_LANG + +enum class _LIBCPP_ENUM_VIS chars_format +{ + scientific = 0x1, + fixed = 0x2, + hex = 0x4, + general = fixed | scientific +}; + +struct _LIBCPP_TYPE_VIS to_chars_result +{ + char* ptr; + errc ec; +}; + +struct _LIBCPP_TYPE_VIS from_chars_result +{ + const char* ptr; + errc ec; +}; + +void to_chars(char*, char*, bool, int = 10) = delete; +void from_chars(const char*, const char*, bool, int = 10) = delete; + +namespace __itoa +{ + +static _LIBCPP_CONSTEXPR uint64_t __pow10_64[] = { + UINT64_C(0), + UINT64_C(10), + UINT64_C(100), + UINT64_C(1000), + UINT64_C(10000), + UINT64_C(100000), + UINT64_C(1000000), + UINT64_C(10000000), + UINT64_C(100000000), + UINT64_C(1000000000), + UINT64_C(10000000000), + UINT64_C(100000000000), + UINT64_C(1000000000000), + UINT64_C(10000000000000), + UINT64_C(100000000000000), + UINT64_C(1000000000000000), + UINT64_C(10000000000000000), + UINT64_C(100000000000000000), + UINT64_C(1000000000000000000), + UINT64_C(10000000000000000000), +}; + +static _LIBCPP_CONSTEXPR uint32_t __pow10_32[] = { + UINT32_C(0), UINT32_C(10), UINT32_C(100), + UINT32_C(1000), UINT32_C(10000), UINT32_C(100000), + UINT32_C(1000000), UINT32_C(10000000), UINT32_C(100000000), + UINT32_C(1000000000), +}; + +template <typename _Tp, typename = void> +struct _LIBCPP_HIDDEN __traits_base +{ + using type = uint64_t; + +#if !defined(_LIBCPP_COMPILER_MSVC) + static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v) + { + auto __t = (64 - __builtin_clzll(__v | 1)) * 1233 >> 12; + return __t - (__v < __pow10_64[__t]) + 1; + } +#endif + + static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p) + { + return __u64toa(__v, __p); + } + + static _LIBCPP_INLINE_VISIBILITY decltype(__pow10_64)& __pow() { return __pow10_64; } +}; + +template <typename _Tp> +struct _LIBCPP_HIDDEN + __traits_base<_Tp, decltype(void(uint32_t{declval<_Tp>()}))> +{ + using type = uint32_t; + +#if !defined(_LIBCPP_COMPILER_MSVC) + static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v) + { + auto __t = (32 - __builtin_clz(__v | 1)) * 1233 >> 12; + return __t - (__v < __pow10_32[__t]) + 1; + } +#endif + + static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p) + { + return __u32toa(__v, __p); + } + + static _LIBCPP_INLINE_VISIBILITY decltype(__pow10_32)& __pow() { return __pow10_32; } +}; + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY bool +__mul_overflowed(unsigned char __a, _Tp __b, unsigned char& __r) +{ + auto __c = __a * __b; + __r = __c; + return __c > (numeric_limits<unsigned char>::max)(); +} + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY bool +__mul_overflowed(unsigned short __a, _Tp __b, unsigned short& __r) +{ + auto __c = __a * __b; + __r = __c; + return __c > (numeric_limits<unsigned short>::max)(); +} + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY bool +__mul_overflowed(_Tp __a, _Tp __b, _Tp& __r) +{ + static_assert(is_unsigned<_Tp>::value, ""); +#if !defined(_LIBCPP_COMPILER_MSVC) + return __builtin_mul_overflow(__a, __b, &__r); +#else + bool __did = __b && ((numeric_limits<_Tp>::max)() / __b) < __a; + __r = __a * __b; + return __did; +#endif +} + +template <typename _Tp, typename _Up> +inline _LIBCPP_INLINE_VISIBILITY bool +__mul_overflowed(_Tp __a, _Up __b, _Tp& __r) +{ + return __mul_overflowed(__a, static_cast<_Tp>(__b), __r); +} + +template <typename _Tp> +struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp> +{ + static _LIBCPP_CONSTEXPR int digits = numeric_limits<_Tp>::digits10 + 1; + using __traits_base<_Tp>::__pow; + using typename __traits_base<_Tp>::type; + + // precondition: at least one non-zero character available + static _LIBCPP_INLINE_VISIBILITY char const* + __read(char const* __p, char const* __ep, type& __a, type& __b) + { + type __cprod[digits]; + int __j = digits - 1; + int __i = digits; + do + { + if (!('0' <= *__p && *__p <= '9')) + break; + __cprod[--__i] = *__p++ - '0'; + } while (__p != __ep && __i != 0); + + __a = __inner_product(__cprod + __i + 1, __cprod + __j, __pow() + 1, + __cprod[__i]); + if (__mul_overflowed(__cprod[__j], __pow()[__j - __i], __b)) + --__p; + return __p; + } + + template <typename _It1, typename _It2, class _Up> + static _LIBCPP_INLINE_VISIBILITY _Up + __inner_product(_It1 __first1, _It1 __last1, _It2 __first2, _Up __init) + { + for (; __first1 < __last1; ++__first1, ++__first2) + __init = __init + *__first1 * *__first2; + return __init; + } +}; + +} // namespace __itoa + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY _Tp +__complement(_Tp __x) +{ + static_assert(is_unsigned<_Tp>::value, "cast to unsigned first"); + return _Tp(~__x + 1); +} + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY typename make_unsigned<_Tp>::type +__to_unsigned(_Tp __x) +{ + return static_cast<typename make_unsigned<_Tp>::type>(__x); +} + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY to_chars_result +__to_chars_itoa(char* __first, char* __last, _Tp __value, true_type) +{ + auto __x = __to_unsigned(__value); + if (__value < 0 && __first != __last) + { + *__first++ = '-'; + __x = __complement(__x); + } + + return __to_chars_itoa(__first, __last, __x, false_type()); +} + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY to_chars_result +__to_chars_itoa(char* __first, char* __last, _Tp __value, false_type) +{ + using __tx = __itoa::__traits<_Tp>; + auto __diff = __last - __first; + +#if !defined(_LIBCPP_COMPILER_MSVC) + if (__tx::digits <= __diff || __tx::__width(__value) <= __diff) + return {__tx::__convert(__value, __first), {}}; + else + return {__last, errc::value_too_large}; +#else + if (__tx::digits <= __diff) + return {__tx::__convert(__value, __first), {}}; + else + { + char __buf[__tx::digits]; + auto __p = __tx::__convert(__value, __buf); + auto __len = __p - __buf; + if (__len <= __diff) + { + memcpy(__first, __buf, __len); + return {__first + __len, {}}; + } + else + return {__last, errc::value_too_large}; + } +#endif +} + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY to_chars_result +__to_chars_integral(char* __first, char* __last, _Tp __value, int __base, + true_type) +{ + auto __x = __to_unsigned(__value); + if (__value < 0 && __first != __last) + { + *__first++ = '-'; + __x = __complement(__x); + } + + return __to_chars_integral(__first, __last, __x, __base, false_type()); +} + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY to_chars_result +__to_chars_integral(char* __first, char* __last, _Tp __value, int __base, + false_type) +{ + if (__base == 10) + return __to_chars_itoa(__first, __last, __value, false_type()); + + auto __p = __last; + while (__p != __first) + { + auto __c = __value % __base; + __value /= __base; + *--__p = "0123456789abcdefghijklmnopqrstuvwxyz"[__c]; + if (__value == 0) + break; + } + + auto __len = __last - __p; + if (__value != 0 || !__len) + return {__last, errc::value_too_large}; + else + { + memmove(__first, __p, __len); + return {__first + __len, {}}; + } +} + +template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0> +inline _LIBCPP_INLINE_VISIBILITY to_chars_result +to_chars(char* __first, char* __last, _Tp __value) +{ + return __to_chars_itoa(__first, __last, __value, is_signed<_Tp>()); +} + +template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0> +inline _LIBCPP_INLINE_VISIBILITY to_chars_result +to_chars(char* __first, char* __last, _Tp __value, int __base) +{ + _LIBCPP_ASSERT(2 <= __base && __base <= 36, "base not in [2, 36]"); + return __to_chars_integral(__first, __last, __value, __base, + is_signed<_Tp>()); +} + +template <typename _It, typename _Tp, typename _Fn, typename... _Ts> +inline _LIBCPP_INLINE_VISIBILITY from_chars_result +__sign_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, _Ts... __args) +{ + using __tl = numeric_limits<_Tp>; + decltype(__to_unsigned(__value)) __x; + + bool __neg = (__first != __last && *__first == '-'); + auto __r = __f(__neg ? __first + 1 : __first, __last, __x, __args...); + switch (__r.ec) + { + case errc::invalid_argument: + return {__first, __r.ec}; + case errc::result_out_of_range: + return __r; + default: + break; + } + + if (__neg) + { + if (__x <= __complement(__to_unsigned(__tl::min()))) + { + __x = __complement(__x); + memcpy(&__value, &__x, sizeof(__x)); + return __r; + } + } + else + { + if (__x <= (__tl::max)()) + { + __value = __x; + return __r; + } + } + + return {__r.ptr, errc::result_out_of_range}; +} + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY bool +__in_pattern(_Tp __c) +{ + return '0' <= __c && __c <= '9'; +} + +struct _LIBCPP_HIDDEN __in_pattern_result +{ + bool __ok; + int __val; + + explicit _LIBCPP_INLINE_VISIBILITY operator bool() const { return __ok; } +}; + +template <typename _Tp> +inline _LIBCPP_INLINE_VISIBILITY __in_pattern_result +__in_pattern(_Tp __c, int __base) +{ + if (__base <= 10) + return {'0' <= __c && __c < '0' + __base, __c - '0'}; + else if (__in_pattern(__c)) + return {true, __c - '0'}; + else if ('a' <= __c && __c < 'a' + __base - 10) + return {true, __c - 'a' + 10}; + else + return {'A' <= __c && __c < 'A' + __base - 10, __c - 'A' + 10}; +} + +template <typename _It, typename _Tp, typename _Fn, typename... _Ts> +inline _LIBCPP_INLINE_VISIBILITY from_chars_result +__subject_seq_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, + _Ts... __args) +{ + auto __find_non_zero = [](_It __first, _It __last) { + for (; __first != __last; ++__first) + if (*__first != '0') + break; + return __first; + }; + + auto __p = __find_non_zero(__first, __last); + if (__p == __last || !__in_pattern(*__p, __args...)) + { + if (__p == __first) + return {__first, errc::invalid_argument}; + else + { + __value = 0; + return {__p, {}}; + } + } + + auto __r = __f(__p, __last, __value, __args...); + if (__r.ec == errc::result_out_of_range) + { + for (; __r.ptr != __last; ++__r.ptr) + { + if (!__in_pattern(*__r.ptr, __args...)) + break; + } + } + + return __r; +} + +template <typename _Tp, typename enable_if<is_unsigned<_Tp>::value, int>::type = 0> +inline _LIBCPP_INLINE_VISIBILITY from_chars_result +__from_chars_atoi(const char* __first, const char* __last, _Tp& __value) +{ + using __tx = __itoa::__traits<_Tp>; + using __output_type = typename __tx::type; + + return __subject_seq_combinator( + __first, __last, __value, + [](const char* __first, const char* __last, + _Tp& __value) -> from_chars_result { + __output_type __a, __b; + auto __p = __tx::__read(__first, __last, __a, __b); + if (__p == __last || !__in_pattern(*__p)) + { + __output_type __m = (numeric_limits<_Tp>::max)(); + if (__m >= __a && __m - __a >= __b) + { + __value = __a + __b; + return {__p, {}}; + } + } + return {__p, errc::result_out_of_range}; + }); +} + +template <typename _Tp, typename enable_if<is_signed<_Tp>::value, int>::type = 0> +inline _LIBCPP_INLINE_VISIBILITY from_chars_result +__from_chars_atoi(const char* __first, const char* __last, _Tp& __value) +{ + using __t = decltype(__to_unsigned(__value)); + return __sign_combinator(__first, __last, __value, __from_chars_atoi<__t>); +} + +template <typename _Tp, typename enable_if<is_unsigned<_Tp>::value, int>::type = 0> +inline _LIBCPP_INLINE_VISIBILITY from_chars_result +__from_chars_integral(const char* __first, const char* __last, _Tp& __value, + int __base) +{ + if (__base == 10) + return __from_chars_atoi(__first, __last, __value); + + return __subject_seq_combinator( + __first, __last, __value, + [](const char* __p, const char* __last, _Tp& __value, + int __base) -> from_chars_result { + using __tl = numeric_limits<_Tp>; + auto __digits = __tl::digits / log2f(float(__base)); + _Tp __a = __in_pattern(*__p++, __base).__val, __b = 0; + + for (int __i = 1; __p != __last; ++__i, ++__p) + { + if (auto __c = __in_pattern(*__p, __base)) + { + if (__i < __digits - 1) + __a = __a * __base + __c.__val; + else + { + if (!__itoa::__mul_overflowed(__a, __base, __a)) + ++__p; + __b = __c.__val; + break; + } + } + else + break; + } + + if (__p == __last || !__in_pattern(*__p, __base)) + { + if ((__tl::max)() - __a >= __b) + { + __value = __a + __b; + return {__p, {}}; + } + } + return {__p, errc::result_out_of_range}; + }, + __base); +} + +template <typename _Tp, typename enable_if<is_signed<_Tp>::value, int>::type = 0> +inline _LIBCPP_INLINE_VISIBILITY from_chars_result +__from_chars_integral(const char* __first, const char* __last, _Tp& __value, + int __base) +{ + using __t = decltype(__to_unsigned(__value)); + return __sign_combinator(__first, __last, __value, + __from_chars_integral<__t>, __base); +} + +template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0> +inline _LIBCPP_INLINE_VISIBILITY from_chars_result +from_chars(const char* __first, const char* __last, _Tp& __value) +{ + return __from_chars_atoi(__first, __last, __value); +} + +template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0> +inline _LIBCPP_INLINE_VISIBILITY from_chars_result +from_chars(const char* __first, const char* __last, _Tp& __value, int __base) +{ + _LIBCPP_ASSERT(2 <= __base && __base <= 36, "base not in [2, 36]"); + return __from_chars_integral(__first, __last, __value, __base); +} + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_CHARCONV diff --git a/android/x86/include/v8/libc++/chrono b/android/x86/include/v8/libc++/chrono new file mode 100755 index 00000000..0ee8c32d --- /dev/null +++ b/android/x86/include/v8/libc++/chrono @@ -0,0 +1,2850 @@ +// -*- C++ -*- +//===---------------------------- chrono ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CHRONO +#define _LIBCPP_CHRONO + +/* + chrono synopsis + +namespace std +{ +namespace chrono +{ + +template <class ToDuration, class Rep, class Period> +constexpr +ToDuration +duration_cast(const duration<Rep, Period>& fd); + +template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; + +template <class Rep> inline constexpr bool treat_as_floating_point_v + = treat_as_floating_point<Rep>::value; // C++17 + +template <class Rep> +struct duration_values +{ +public: + static constexpr Rep zero(); // noexcept in C++20 + static constexpr Rep max(); // noexcept in C++20 + static constexpr Rep min(); // noexcept in C++20 +}; + +// duration + +template <class Rep, class Period = ratio<1>> +class duration +{ + static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration"); + static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio"); + static_assert(Period::num > 0, "duration period must be positive"); +public: + typedef Rep rep; + typedef typename _Period::type period; + + constexpr duration() = default; + template <class Rep2> + constexpr explicit duration(const Rep2& r, + typename enable_if + < + is_convertible<Rep2, rep>::value && + (treat_as_floating_point<rep>::value || + !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value) + >::type* = 0); + + // conversions + template <class Rep2, class Period2> + constexpr duration(const duration<Rep2, Period2>& d, + typename enable_if + < + treat_as_floating_point<rep>::value || + ratio_divide<Period2, period>::type::den == 1 + >::type* = 0); + + // observer + + constexpr rep count() const; + + // arithmetic + + constexpr common_type<duration>::type operator+() const; + constexpr common_type<duration>::type operator-() const; + constexpr duration& operator++(); // constexpr in C++17 + constexpr duration operator++(int); // constexpr in C++17 + constexpr duration& operator--(); // constexpr in C++17 + constexpr duration operator--(int); // constexpr in C++17 + + constexpr duration& operator+=(const duration& d); // constexpr in C++17 + constexpr duration& operator-=(const duration& d); // constexpr in C++17 + + duration& operator*=(const rep& rhs); // constexpr in C++17 + duration& operator/=(const rep& rhs); // constexpr in C++17 + duration& operator%=(const rep& rhs); // constexpr in C++17 + duration& operator%=(const duration& rhs); // constexpr in C++17 + + // special values + + static constexpr duration zero(); // noexcept in C++20 + static constexpr duration min(); // noexcept in C++20 + static constexpr duration max(); // noexcept in C++20 +}; + +typedef duration<long long, nano> nanoseconds; +typedef duration<long long, micro> microseconds; +typedef duration<long long, milli> milliseconds; +typedef duration<long long > seconds; +typedef duration< long, ratio< 60> > minutes; +typedef duration< long, ratio<3600> > hours; + +template <class Clock, class Duration = typename Clock::duration> +class time_point +{ +public: + typedef Clock clock; + typedef Duration duration; + typedef typename duration::rep rep; + typedef typename duration::period period; +private: + duration d_; // exposition only + +public: + time_point(); // has value "epoch" // constexpr in C++14 + explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 + + // conversions + template <class Duration2> + time_point(const time_point<clock, Duration2>& t); // constexpr in C++14 + + // observer + + duration time_since_epoch() const; // constexpr in C++14 + + // arithmetic + + time_point& operator+=(const duration& d); // constexpr in C++17 + time_point& operator-=(const duration& d); // constexpr in C++17 + + // special values + + static constexpr time_point min(); // noexcept in C++20 + static constexpr time_point max(); // noexcept in C++20 +}; + +} // chrono + +// common_type traits +template <class Rep1, class Period1, class Rep2, class Period2> + struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>; + +template <class Clock, class Duration1, class Duration2> + struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>; + +namespace chrono { + + +template<class T> struct is_clock; // C++20 +template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20 + + +// duration arithmetic +template <class Rep1, class Period1, class Rep2, class Period2> + constexpr + typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type + operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); +template <class Rep1, class Period1, class Rep2, class Period2> + constexpr + typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type + operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); +template <class Rep1, class Period, class Rep2> + constexpr + duration<typename common_type<Rep1, Rep2>::type, Period> + operator*(const duration<Rep1, Period>& d, const Rep2& s); +template <class Rep1, class Period, class Rep2> + constexpr + duration<typename common_type<Rep1, Rep2>::type, Period> + operator*(const Rep1& s, const duration<Rep2, Period>& d); +template <class Rep1, class Period, class Rep2> + constexpr + duration<typename common_type<Rep1, Rep2>::type, Period> + operator/(const duration<Rep1, Period>& d, const Rep2& s); +template <class Rep1, class Period1, class Rep2, class Period2> + constexpr + typename common_type<Rep1, Rep2>::type + operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// duration comparisons +template <class Rep1, class Period1, class Rep2, class Period2> + constexpr + bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); +template <class Rep1, class Period1, class Rep2, class Period2> + constexpr + bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); +template <class Rep1, class Period1, class Rep2, class Period2> + constexpr + bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); +template <class Rep1, class Period1, class Rep2, class Period2> + constexpr + bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); +template <class Rep1, class Period1, class Rep2, class Period2> + constexpr + bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); +template <class Rep1, class Period1, class Rep2, class Period2> + constexpr + bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// duration_cast +template <class ToDuration, class Rep, class Period> + ToDuration duration_cast(const duration<Rep, Period>& d); + +template <class ToDuration, class Rep, class Period> + constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17 +template <class ToDuration, class Rep, class Period> + constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17 +template <class ToDuration, class Rep, class Period> + constexpr ToDuration round(const duration<Rep, Period>& d); // C++17 + +// duration I/O is elsewhere + +// time_point arithmetic (all constexpr in C++14) +template <class Clock, class Duration1, class Rep2, class Period2> + time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> + operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); +template <class Rep1, class Period1, class Clock, class Duration2> + time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> + operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); +template <class Clock, class Duration1, class Rep2, class Period2> + time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> + operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); +template <class Clock, class Duration1, class Duration2> + typename common_type<Duration1, Duration2>::type + operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// time_point comparisons (all constexpr in C++14) +template <class Clock, class Duration1, class Duration2> + bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); +template <class Clock, class Duration1, class Duration2> + bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); +template <class Clock, class Duration1, class Duration2> + bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); +template <class Clock, class Duration1, class Duration2> + bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); +template <class Clock, class Duration1, class Duration2> + bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); +template <class Clock, class Duration1, class Duration2> + bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// time_point_cast (constexpr in C++14) + +template <class ToDuration, class Clock, class Duration> + time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); + +template <class ToDuration, class Clock, class Duration> + constexpr time_point<Clock, ToDuration> + floor(const time_point<Clock, Duration>& tp); // C++17 + +template <class ToDuration, class Clock, class Duration> + constexpr time_point<Clock, ToDuration> + ceil(const time_point<Clock, Duration>& tp); // C++17 + +template <class ToDuration, class Clock, class Duration> + constexpr time_point<Clock, ToDuration> + round(const time_point<Clock, Duration>& tp); // C++17 + +template <class Rep, class Period> + constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17 + +// Clocks + +class system_clock +{ +public: + typedef microseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point<system_clock> time_point; + static const bool is_steady = false; // constexpr in C++14 + + static time_point now() noexcept; + static time_t to_time_t (const time_point& __t) noexcept; + static time_point from_time_t(time_t __t) noexcept; +}; + +template <class Duration> + using sys_time = time_point<system_clock, Duration>; // C++20 +using sys_seconds = sys_time<seconds>; // C++20 +using sys_days = sys_time<days>; // C++20 + +class utc_clock; // C++20 + +template <class Duration> + using utc_time = time_point<utc_clock, Duration>; // C++20 +using utc_seconds = utc_time<seconds>; // C++20 + +class tai_clock; // C++20 + +template <class Duration> + using tai_time = time_point<tai_clock, Duration>; // C++20 +using tai_seconds = tai_time<seconds>; // C++20 + +class file_clock; // C++20 + +template<class Duration> + using file_time = time_point<file_clock, Duration>; // C++20 + +class steady_clock +{ +public: + typedef nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point<steady_clock, duration> time_point; + static const bool is_steady = true; // constexpr in C++14 + + static time_point now() noexcept; +}; + +typedef steady_clock high_resolution_clock; + +// 25.7.8, local time // C++20 +struct local_t {}; +template<class Duration> + using local_time = time_point<local_t, Duration>; +using local_seconds = local_time<seconds>; +using local_days = local_time<days>; + +// 25.7.9, time_point conversions template<class DestClock, class SourceClock> // C++20 +struct clock_time_conversion; + +template<class DestClock, class SourceClock, class Duration> + auto clock_cast(const time_point<SourceClock, Duration>& t); + +// 25.8.2, class last_spec // C++20 +struct last_spec; + +// 25.8.3, class day // C++20 + +class day; +constexpr bool operator==(const day& x, const day& y) noexcept; +constexpr bool operator!=(const day& x, const day& y) noexcept; +constexpr bool operator< (const day& x, const day& y) noexcept; +constexpr bool operator> (const day& x, const day& y) noexcept; +constexpr bool operator<=(const day& x, const day& y) noexcept; +constexpr bool operator>=(const day& x, const day& y) noexcept; +constexpr day operator+(const day& x, const days& y) noexcept; +constexpr day operator+(const days& x, const day& y) noexcept; +constexpr day operator-(const day& x, const days& y) noexcept; +constexpr days operator-(const day& x, const day& y) noexcept; + +// 25.8.4, class month // C++20 +class month; +constexpr bool operator==(const month& x, const month& y) noexcept; +constexpr bool operator!=(const month& x, const month& y) noexcept; +constexpr bool operator< (const month& x, const month& y) noexcept; +constexpr bool operator> (const month& x, const month& y) noexcept; +constexpr bool operator<=(const month& x, const month& y) noexcept; +constexpr bool operator>=(const month& x, const month& y) noexcept; +constexpr month operator+(const month& x, const months& y) noexcept; +constexpr month operator+(const months& x, const month& y) noexcept; +constexpr month operator-(const month& x, const months& y) noexcept; +constexpr months operator-(const month& x, const month& y) noexcept; + +// 25.8.5, class year // C++20 +class year; +constexpr bool operator==(const year& x, const year& y) noexcept; +constexpr bool operator!=(const year& x, const year& y) noexcept; +constexpr bool operator< (const year& x, const year& y) noexcept; +constexpr bool operator> (const year& x, const year& y) noexcept; +constexpr bool operator<=(const year& x, const year& y) noexcept; +constexpr bool operator>=(const year& x, const year& y) noexcept; +constexpr year operator+(const year& x, const years& y) noexcept; +constexpr year operator+(const years& x, const year& y) noexcept; +constexpr year operator-(const year& x, const years& y) noexcept; +constexpr years operator-(const year& x, const year& y) noexcept; + +// 25.8.6, class weekday // C++20 +class weekday; + +constexpr bool operator==(const weekday& x, const weekday& y) noexcept; +constexpr bool operator!=(const weekday& x, const weekday& y) noexcept; +constexpr weekday operator+(const weekday& x, const days& y) noexcept; +constexpr weekday operator+(const days& x, const weekday& y) noexcept; +constexpr weekday operator-(const weekday& x, const days& y) noexcept; +constexpr days operator-(const weekday& x, const weekday& y) noexcept; + +// 25.8.7, class weekday_indexed // C++20 + +class weekday_indexed; +constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; +constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept; + +// 25.8.8, class weekday_last // C++20 +class weekday_last; + +constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept; +constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept; + +// 25.8.9, class month_day // C++20 +class month_day; + +constexpr bool operator==(const month_day& x, const month_day& y) noexcept; +constexpr bool operator!=(const month_day& x, const month_day& y) noexcept; +constexpr bool operator< (const month_day& x, const month_day& y) noexcept; +constexpr bool operator> (const month_day& x, const month_day& y) noexcept; +constexpr bool operator<=(const month_day& x, const month_day& y) noexcept; +constexpr bool operator>=(const month_day& x, const month_day& y) noexcept; + + +// 25.8.10, class month_day_last // C++20 +class month_day_last; + +constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept; +constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept; +constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept; +constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept; +constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept; +constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept; + +// 25.8.11, class month_weekday // C++20 +class month_weekday; + +constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; +constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept; + +// 25.8.12, class month_weekday_last // C++20 +class month_weekday_last; + +constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; +constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept; + + +// 25.8.13, class year_month // C++20 +class year_month; + +constexpr bool operator==(const year_month& x, const year_month& y) noexcept; +constexpr bool operator!=(const year_month& x, const year_month& y) noexcept; +constexpr bool operator< (const year_month& x, const year_month& y) noexcept; +constexpr bool operator> (const year_month& x, const year_month& y) noexcept; +constexpr bool operator<=(const year_month& x, const year_month& y) noexcept; +constexpr bool operator>=(const year_month& x, const year_month& y) noexcept; + +constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; +constexpr year_month operator+(const months& dm, const year_month& ym) noexcept; +constexpr year_month operator-(const year_month& ym, const months& dm) noexcept; +constexpr months operator-(const year_month& x, const year_month& y) noexcept; +constexpr year_month operator+(const year_month& ym, const years& dy) noexcept; +constexpr year_month operator+(const years& dy, const year_month& ym) noexcept; +constexpr year_month operator-(const year_month& ym, const years& dy) noexcept; + +// 25.8.14, class year_month_day class // C++20 +year_month_day; + +constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept; +constexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept; +constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept; +constexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept; +constexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept; +constexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept; + +constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; +constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; +constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; +constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; +constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; +constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; + + +// 25.8.15, class year_month_day_last // C++20 +class year_month_day_last; + +constexpr bool operator==(const year_month_day_last& x, + const year_month_day_last& y) noexcept; +constexpr bool operator!=(const year_month_day_last& x, + const year_month_day_last& y) noexcept; +constexpr bool operator< (const year_month_day_last& x, + const year_month_day_last& y) noexcept; +constexpr bool operator> (const year_month_day_last& x, + const year_month_day_last& y) noexcept; +constexpr bool operator<=(const year_month_day_last& x, + const year_month_day_last& y) noexcept; +constexpr bool operator>=(const year_month_day_last& x, + const year_month_day_last& y) noexcept; + +constexpr year_month_day_last + operator+(const year_month_day_last& ymdl, const months& dm) noexcept; +constexpr year_month_day_last + operator+(const months& dm, const year_month_day_last& ymdl) noexcept; +constexpr year_month_day_last + operator+(const year_month_day_last& ymdl, const years& dy) noexcept; +constexpr year_month_day_last + operator+(const years& dy, const year_month_day_last& ymdl) noexcept; +constexpr year_month_day_last + operator-(const year_month_day_last& ymdl, const months& dm) noexcept; +constexpr year_month_day_last + operator-(const year_month_day_last& ymdl, const years& dy) noexcept; + +// 25.8.16, class year_month_weekday // C++20 +class year_month_weekday; + +constexpr bool operator==(const year_month_weekday& x, + const year_month_weekday& y) noexcept; +constexpr bool operator!=(const year_month_weekday& x, + const year_month_weekday& y) noexcept; + +constexpr year_month_weekday + operator+(const year_month_weekday& ymwd, const months& dm) noexcept; +constexpr year_month_weekday + operator+(const months& dm, const year_month_weekday& ymwd) noexcept; +constexpr year_month_weekday + operator+(const year_month_weekday& ymwd, const years& dy) noexcept; +constexpr year_month_weekday + operator+(const years& dy, const year_month_weekday& ymwd) noexcept; +constexpr year_month_weekday + operator-(const year_month_weekday& ymwd, const months& dm) noexcept; +constexpr year_month_weekday + operator-(const year_month_weekday& ymwd, const years& dy) noexcept; + +// 25.8.17, class year_month_weekday_last // C++20 +class year_month_weekday_last; + +constexpr bool operator==(const year_month_weekday_last& x, + const year_month_weekday_last& y) noexcept; +constexpr bool operator!=(const year_month_weekday_last& x, + const year_month_weekday_last& y) noexcept; +constexpr year_month_weekday_last + operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept; +constexpr year_month_weekday_last + operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept; +constexpr year_month_weekday_last + operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; +constexpr year_month_weekday_last + operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; +constexpr year_month_weekday_last + operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; +constexpr year_month_weekday_last + operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; + +// 25.8.18, civil calendar conventional syntax operators // C++20 +constexpr year_month + operator/(const year& y, const month& m) noexcept; +constexpr year_month + operator/(const year& y, int m) noexcept; +constexpr month_day + operator/(const month& m, const day& d) noexcept; +constexpr month_day + operator/(const month& m, int d) noexcept; +constexpr month_day + operator/(int m, const day& d) noexcept; +constexpr month_day + operator/(const day& d, const month& m) noexcept; +constexpr month_day + operator/(const day& d, int m) noexcept; +constexpr month_day_last + operator/(const month& m, last_spec) noexcept; +constexpr month_day_last + operator/(int m, last_spec) noexcept; +constexpr month_day_last + operator/(last_spec, const month& m) noexcept; +constexpr month_day_last + operator/(last_spec, int m) noexcept; +constexpr month_weekday + operator/(const month& m, const weekday_indexed& wdi) noexcept; +constexpr month_weekday + operator/(int m, const weekday_indexed& wdi) noexcept; +constexpr month_weekday + operator/(const weekday_indexed& wdi, const month& m) noexcept; +constexpr month_weekday + operator/(const weekday_indexed& wdi, int m) noexcept; +constexpr month_weekday_last + operator/(const month& m, const weekday_last& wdl) noexcept; +constexpr month_weekday_last + operator/(int m, const weekday_last& wdl) noexcept; +constexpr month_weekday_last + operator/(const weekday_last& wdl, const month& m) noexcept; +constexpr month_weekday_last + operator/(const weekday_last& wdl, int m) noexcept; +constexpr year_month_day + operator/(const year_month& ym, const day& d) noexcept; +constexpr year_month_day + operator/(const year_month& ym, int d) noexcept; +constexpr year_month_day + operator/(const year& y, const month_day& md) noexcept; +constexpr year_month_day + operator/(int y, const month_day& md) noexcept; +constexpr year_month_day + operator/(const month_day& md, const year& y) noexcept; +constexpr year_month_day + operator/(const month_day& md, int y) noexcept; +constexpr year_month_day_last + operator/(const year_month& ym, last_spec) noexcept; +constexpr year_month_day_last + operator/(const year& y, const month_day_last& mdl) noexcept; +constexpr year_month_day_last + operator/(int y, const month_day_last& mdl) noexcept; +constexpr year_month_day_last + operator/(const month_day_last& mdl, const year& y) noexcept; +constexpr year_month_day_last + operator/(const month_day_last& mdl, int y) noexcept; +constexpr year_month_weekday + operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; +constexpr year_month_weekday + operator/(const year& y, const month_weekday& mwd) noexcept; +constexpr year_month_weekday + operator/(int y, const month_weekday& mwd) noexcept; +constexpr year_month_weekday + operator/(const month_weekday& mwd, const year& y) noexcept; +constexpr year_month_weekday + operator/(const month_weekday& mwd, int y) noexcept; +constexpr year_month_weekday_last + operator/(const year_month& ym, const weekday_last& wdl) noexcept; +constexpr year_month_weekday_last + operator/(const year& y, const month_weekday_last& mwdl) noexcept; +constexpr year_month_weekday_last + operator/(int y, const month_weekday_last& mwdl) noexcept; +constexpr year_month_weekday_last + operator/(const month_weekday_last& mwdl, const year& y) noexcept; +constexpr year_month_weekday_last + operator/(const month_weekday_last& mwdl, int y) noexcept; + +// 25.9, class template time_of_day // C++20 +template<class Duration> class time_of_day; + +template<> class time_of_day<hours>; +template<> class time_of_day<minutes>; +template<> class time_of_day<seconds>; +template<class Rep, class Period> class time_of_day<duration<Rep, Period>>; + +// 25.10.2, time zone database // C++20 +struct tzdb; +class tzdb_list; + +// 25.10.2.3, time zone database access // C++20 +const tzdb& get_tzdb(); +tzdb_list& get_tzdb_list(); +const time_zone* locate_zone(string_view tz_name); +const time_zone* current_zone(); + +// 25.10.2.4, remote time zone database support // C++20 +const tzdb& reload_tzdb(); +string remote_version(); + +// 25.10.3, exception classes // C++20 +class nonexistent_local_time; +class ambiguous_local_time; + +// 25.10.4, information classes // C++20 +struct sys_info; +struct local_info; + +// 25.10.5, class time_zone // C++20 +enum class choose {earliest, latest}; +class time_zone; +bool operator==(const time_zone& x, const time_zone& y) noexcept; +bool operator!=(const time_zone& x, const time_zone& y) noexcept; +bool operator<(const time_zone& x, const time_zone& y) noexcept; +bool operator>(const time_zone& x, const time_zone& y) noexcept; +bool operator<=(const time_zone& x, const time_zone& y) noexcept; +bool operator>=(const time_zone& x, const time_zone& y) noexcept; + +// 25.10.6, class template zoned_traits // C++20 +template<class T> struct zoned_traits; + +// 25.10.7, class template zoned_time // C++20 +template<class Duration, class TimeZonePtr = const time_zone*> class zoned_time; +using zoned_seconds = zoned_time<seconds>; + +template<class Duration1, class Duration2, class TimeZonePtr> + bool operator==(const zoned_time<Duration1, TimeZonePtr>& x, + const zoned_time<Duration2, TimeZonePtr>& y); +template<class Duration1, class Duration2, class TimeZonePtr> + bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x, + const zoned_time<Duration2, TimeZonePtr>& y); + +// 25.10.8, leap second support // C++20 +class leap; + +bool operator==(const leap& x, const leap& y); +bool operator!=(const leap& x, const leap& y); +bool operator< (const leap& x, const leap& y); +bool operator> (const leap& x, const leap& y); +bool operator<=(const leap& x, const leap& y); +bool operator>=(const leap& x, const leap& y); +template<class Duration> + bool operator==(const leap& x, const sys_time<Duration>& y); +template<class Duration> + bool operator==(const sys_time<Duration>& x, const leap& y); +template<class Duration> + bool operator!=(const leap& x, const sys_time<Duration>& y); +template<class Duration> + bool operator!=(const sys_time<Duration>& x, const leap& y); +template<class Duration> + bool operator< (const leap& x, const sys_time<Duration>& y); +template<class Duration> + bool operator< (const sys_time<Duration>& x, const leap& y); +template<class Duration> + bool operator> (const leap& x, const sys_time<Duration>& y); +template<class Duration> + bool operator> (const sys_time<Duration>& x, const leap& y); +template<class Duration> + bool operator<=(const leap& x, const sys_time<Duration>& y); +template<class Duration> + bool operator<=(const sys_time<Duration>& x, const leap& y); +template<class Duration> + bool operator>=(const leap& x, const sys_time<Duration>& y); +template<class Duration> + bool operator>=(const sys_time<Duration>& x, const leap& y); + +// 25.10.9, class link // C++20 +class link; +bool operator==(const link& x, const link& y); +bool operator!=(const link& x, const link& y); +bool operator< (const link& x, const link& y); +bool operator> (const link& x, const link& y); +bool operator<=(const link& x, const link& y); +bool operator>=(const link& x, const link& y); + +// 25.11, formatting // C++20 +template<class charT, class Streamable> + basic_string<charT> + format(const charT* fmt, const Streamable& s); + +template<class charT, class Streamable> + basic_string<charT> + format(const locale& loc, const charT* fmt, const Streamable& s); + +template<class charT, class traits, class Alloc, class Streamable> + basic_string<charT, traits, Alloc> + format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s); + +template<class charT, class traits, class Alloc, class Streamable> + basic_string<charT, traits, Alloc> + format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt, + const Streamable& s); + +// 25.12, parsing // C++20 +template<class charT, class traits, class Alloc, class Parsable> +unspecified + parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp); + +template<class charT, class traits, class Alloc, class Parsable> +unspecified + parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, + basic_string<charT, traits, Alloc>& abbrev); + +template<class charT, class traits, class Alloc, class Parsable> +unspecified + parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, + minutes& offset); + +template<class charT, class traits, class Alloc, class Parsable> +unspecified + parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, + basic_string<charT, traits, Alloc>& abbrev, minutes& offset); + +// calendrical constants +inline constexpr last_spec last{}; // C++20 +inline constexpr chrono::weekday Sunday{0}; // C++20 +inline constexpr chrono::weekday Monday{1}; // C++20 +inline constexpr chrono::weekday Tuesday{2}; // C++20 +inline constexpr chrono::weekday Wednesday{3}; // C++20 +inline constexpr chrono::weekday Thursday{4}; // C++20 +inline constexpr chrono::weekday Friday{5}; // C++20 +inline constexpr chrono::weekday Saturday{6}; // C++20 + +inline constexpr chrono::month January{1}; // C++20 +inline constexpr chrono::month February{2}; // C++20 +inline constexpr chrono::month March{3}; // C++20 +inline constexpr chrono::month April{4}; // C++20 +inline constexpr chrono::month May{5}; // C++20 +inline constexpr chrono::month June{6}; // C++20 +inline constexpr chrono::month July{7}; // C++20 +inline constexpr chrono::month August{8}; // C++20 +inline constexpr chrono::month September{9}; // C++20 +inline constexpr chrono::month October{10}; // C++20 +inline constexpr chrono::month November{11}; // C++20 +inline constexpr chrono::month December{12}; // C++20 +} // chrono + +inline namespace literals { + inline namespace chrono_literals { +constexpr chrono::hours operator ""h(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14 +constexpr chrono::minutes operator ""min(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14 +constexpr chrono::seconds operator ""s(unsigned long long); // C++14 +constexpr chrono::duration<unspecified > operator ""s(long double); // C++14 +constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14 +constexpr chrono::microseconds operator ""us(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14 +constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14 +constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20 +constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20 +} // chrono_literals +} // literals + +} // std +*/ + +#include <__config> +#include <ctime> +#include <type_traits> +#include <ratio> +#include <limits> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#ifndef _LIBCPP_CXX03_LANG +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +struct _FilesystemClock; +_LIBCPP_END_NAMESPACE_FILESYSTEM +#endif // !_LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace chrono +{ + +template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration; + +template <class _Tp> +struct __is_duration : false_type {}; + +template <class _Rep, class _Period> +struct __is_duration<duration<_Rep, _Period> > : true_type {}; + +template <class _Rep, class _Period> +struct __is_duration<const duration<_Rep, _Period> > : true_type {}; + +template <class _Rep, class _Period> +struct __is_duration<volatile duration<_Rep, _Period> > : true_type {}; + +template <class _Rep, class _Period> +struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {}; + +} // chrono + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, + chrono::duration<_Rep2, _Period2> > +{ + typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, + typename __ratio_gcd<_Period1, _Period2>::type> type; +}; + +namespace chrono { + +// duration_cast + +template <class _FromDuration, class _ToDuration, + class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type, + bool = _Period::num == 1, + bool = _Period::den == 1> +struct __duration_cast; + +template <class _FromDuration, class _ToDuration, class _Period> +struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + _ToDuration operator()(const _FromDuration& __fd) const + { + return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count())); + } +}; + +template <class _FromDuration, class _ToDuration, class _Period> +struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + _ToDuration operator()(const _FromDuration& __fd) const + { + typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; + return _ToDuration(static_cast<typename _ToDuration::rep>( + static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); + } +}; + +template <class _FromDuration, class _ToDuration, class _Period> +struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + _ToDuration operator()(const _FromDuration& __fd) const + { + typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; + return _ToDuration(static_cast<typename _ToDuration::rep>( + static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); + } +}; + +template <class _FromDuration, class _ToDuration, class _Period> +struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + _ToDuration operator()(const _FromDuration& __fd) const + { + typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; + return _ToDuration(static_cast<typename _ToDuration::rep>( + static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) + / static_cast<_Ct>(_Period::den))); + } +}; + +template <class _ToDuration, class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +duration_cast(const duration<_Rep, _Period>& __fd) +{ + return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd); +} + +template <class _Rep> +struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Rep> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v + = treat_as_floating_point<_Rep>::value; +#endif + +template <class _Rep> +struct _LIBCPP_TEMPLATE_VIS duration_values +{ +public: + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT {return numeric_limits<_Rep>::max();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT {return numeric_limits<_Rep>::lowest();} +}; + +#if _LIBCPP_STD_VER > 14 +template <class _ToDuration, class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +floor(const duration<_Rep, _Period>& __d) +{ + _ToDuration __t = duration_cast<_ToDuration>(__d); + if (__t > __d) + __t = __t - _ToDuration{1}; + return __t; +} + +template <class _ToDuration, class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +ceil(const duration<_Rep, _Period>& __d) +{ + _ToDuration __t = duration_cast<_ToDuration>(__d); + if (__t < __d) + __t = __t + _ToDuration{1}; + return __t; +} + +template <class _ToDuration, class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +round(const duration<_Rep, _Period>& __d) +{ + _ToDuration __lower = floor<_ToDuration>(__d); + _ToDuration __upper = __lower + _ToDuration{1}; + auto __lowerDiff = __d - __lower; + auto __upperDiff = __upper - __d; + if (__lowerDiff < __upperDiff) + return __lower; + if (__lowerDiff > __upperDiff) + return __upper; + return __lower.count() & 1 ? __upper : __lower; +} +#endif + +// duration + +template <class _Rep, class _Period> +class _LIBCPP_TEMPLATE_VIS duration +{ + static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); + static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); + static_assert(_Period::num > 0, "duration period must be positive"); + + template <class _R1, class _R2> + struct __no_overflow + { + private: + static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; + static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; + static const intmax_t __n1 = _R1::num / __gcd_n1_n2; + static const intmax_t __d1 = _R1::den / __gcd_d1_d2; + static const intmax_t __n2 = _R2::num / __gcd_n1_n2; + static const intmax_t __d2 = _R2::den / __gcd_d1_d2; + static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); + + template <intmax_t _Xp, intmax_t _Yp, bool __overflow> + struct __mul // __overflow == false + { + static const intmax_t value = _Xp * _Yp; + }; + + template <intmax_t _Xp, intmax_t _Yp> + struct __mul<_Xp, _Yp, true> + { + static const intmax_t value = 1; + }; + + public: + static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); + typedef ratio<__mul<__n1, __d2, !value>::value, + __mul<__n2, __d1, !value>::value> type; + }; + +public: + typedef _Rep rep; + typedef typename _Period::type period; +private: + rep __rep_; +public: + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +#ifndef _LIBCPP_CXX03_LANG + duration() = default; +#else + duration() {} +#endif + + template <class _Rep2> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + explicit duration(const _Rep2& __r, + typename enable_if + < + is_convertible<_Rep2, rep>::value && + (treat_as_floating_point<rep>::value || + !treat_as_floating_point<_Rep2>::value) + >::type* = 0) + : __rep_(__r) {} + + // conversions + template <class _Rep2, class _Period2> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + duration(const duration<_Rep2, _Period2>& __d, + typename enable_if + < + __no_overflow<_Period2, period>::value && ( + treat_as_floating_point<rep>::value || + (__no_overflow<_Period2, period>::type::den == 1 && + !treat_as_floating_point<_Rep2>::value)) + >::type* = 0) + : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {} + + // observer + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;} + + // arithmetic + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} + + // special values + + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {return duration(duration_values<rep>::min());} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {return duration(duration_values<rep>::max());} +}; + +typedef duration<long long, nano> nanoseconds; +typedef duration<long long, micro> microseconds; +typedef duration<long long, milli> milliseconds; +typedef duration<long long > seconds; +typedef duration< long, ratio< 60> > minutes; +typedef duration< long, ratio<3600> > hours; +#if _LIBCPP_STD_VER > 17 +typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days; +typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks; +typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years; +typedef duration< int, ratio_divide<years::period, ratio<12>>> months; +#endif +// Duration == + +template <class _LhsDuration, class _RhsDuration> +struct __duration_eq +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const + { + typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; + return _Ct(__lhs).count() == _Ct(__rhs).count(); + } +}; + +template <class _LhsDuration> +struct __duration_eq<_LhsDuration, _LhsDuration> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const + {return __lhs.count() == __rhs.count();} +}; + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +bool +operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); +} + +// Duration != + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +bool +operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return !(__lhs == __rhs); +} + +// Duration < + +template <class _LhsDuration, class _RhsDuration> +struct __duration_lt +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const + { + typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; + return _Ct(__lhs).count() < _Ct(__rhs).count(); + } +}; + +template <class _LhsDuration> +struct __duration_lt<_LhsDuration, _LhsDuration> +{ + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const + {return __lhs.count() < __rhs.count();} +}; + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +bool +operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); +} + +// Duration > + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +bool +operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return __rhs < __lhs; +} + +// Duration <= + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +bool +operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return !(__rhs < __lhs); +} + +// Duration >= + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +bool +operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return !(__lhs < __rhs); +} + +// Duration + + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type +operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; + return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); +} + +// Duration - + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type +operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; + return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); +} + +// Duration * + +template <class _Rep1, class _Period, class _Rep2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +typename enable_if +< + is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> +>::type +operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) +{ + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + typedef duration<_Cr, _Period> _Cd; + return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); +} + +template <class _Rep1, class _Period, class _Rep2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +typename enable_if +< + is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> +>::type +operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) +{ + return __d * __s; +} + +// Duration / + +template <class _Rep1, class _Period, class _Rep2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +typename enable_if +< + !__is_duration<_Rep2>::value && + is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> +>::type +operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) +{ + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + typedef duration<_Cr, _Period> _Cd; + return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); +} + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +typename common_type<_Rep1, _Rep2>::type +operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct; + return _Ct(__lhs).count() / _Ct(__rhs).count(); +} + +// Duration % + +template <class _Rep1, class _Period, class _Rep2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +typename enable_if +< + !__is_duration<_Rep2>::value && + is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> +>::type +operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) +{ + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + typedef duration<_Cr, _Period> _Cd; + return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); +} + +template <class _Rep1, class _Period1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type +operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; + return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); +} + +////////////////////////////////////////////////////////// +///////////////////// time_point ///////////////////////// +////////////////////////////////////////////////////////// + +template <class _Clock, class _Duration = typename _Clock::duration> +class _LIBCPP_TEMPLATE_VIS time_point +{ + static_assert(__is_duration<_Duration>::value, + "Second template parameter of time_point must be a std::chrono::duration"); +public: + typedef _Clock clock; + typedef _Duration duration; + typedef typename duration::rep rep; + typedef typename duration::period period; +private: + duration __d_; + +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {} + + // conversions + template <class _Duration2> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + time_point(const time_point<clock, _Duration2>& t, + typename enable_if + < + is_convertible<_Duration2, duration>::value + >::type* = 0) + : __d_(t.time_since_epoch()) {} + + // observer + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;} + + // arithmetic + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} + + // special values + + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());} +}; + +} // chrono + +template <class _Clock, class _Duration1, class _Duration2> +struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>, + chrono::time_point<_Clock, _Duration2> > +{ + typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; +}; + +namespace chrono { + +template <class _ToDuration, class _Clock, class _Duration> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +time_point<_Clock, _ToDuration> +time_point_cast(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); +} + +#if _LIBCPP_STD_VER > 14 +template <class _ToDuration, class _Clock, class _Duration> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration> +>::type +floor(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; +} + +template <class _ToDuration, class _Clock, class _Duration> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration> +>::type +ceil(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; +} + +template <class _ToDuration, class _Clock, class _Duration> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration> +>::type +round(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; +} + +template <class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + numeric_limits<_Rep>::is_signed, + duration<_Rep, _Period> +>::type +abs(duration<_Rep, _Period> __d) +{ + return __d >= __d.zero() ? __d : -__d; +} +#endif + +// time_point == + +template <class _Clock, class _Duration1, class _Duration2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __lhs.time_since_epoch() == __rhs.time_since_epoch(); +} + +// time_point != + +template <class _Clock, class _Duration1, class _Duration2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return !(__lhs == __rhs); +} + +// time_point < + +template <class _Clock, class _Duration1, class _Duration2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __lhs.time_since_epoch() < __rhs.time_since_epoch(); +} + +// time_point > + +template <class _Clock, class _Duration1, class _Duration2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __rhs < __lhs; +} + +// time_point <= + +template <class _Clock, class _Duration1, class _Duration2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return !(__rhs < __lhs); +} + +// time_point >= + +template <class _Clock, class _Duration1, class _Duration2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return !(__lhs < __rhs); +} + +// time_point operator+(time_point x, duration y); + +template <class _Clock, class _Duration1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> +operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; + return _Tr (__lhs.time_since_epoch() + __rhs); +} + +// time_point operator+(duration x, time_point y); + +template <class _Rep1, class _Period1, class _Clock, class _Duration2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> +operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __rhs + __lhs; +} + +// time_point operator-(time_point x, duration y); + +template <class _Clock, class _Duration1, class _Rep2, class _Period2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> +operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; + return _Ret(__lhs.time_since_epoch() -__rhs); +} + +// duration operator-(time_point x, time_point y); + +template <class _Clock, class _Duration1, class _Duration2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename common_type<_Duration1, _Duration2>::type +operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __lhs.time_since_epoch() - __rhs.time_since_epoch(); +} + +////////////////////////////////////////////////////////// +/////////////////////// clocks /////////////////////////// +////////////////////////////////////////////////////////// + +class _LIBCPP_TYPE_VIS system_clock +{ +public: + typedef microseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point<system_clock> time_point; + static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; + + static time_point now() _NOEXCEPT; + static time_t to_time_t (const time_point& __t) _NOEXCEPT; + static time_point from_time_t(time_t __t) _NOEXCEPT; +}; + +#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK +class _LIBCPP_TYPE_VIS steady_clock +{ +public: + typedef nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point<steady_clock, duration> time_point; + static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true; + + static time_point now() _NOEXCEPT; +}; + +typedef steady_clock high_resolution_clock; +#else +typedef system_clock high_resolution_clock; +#endif + +#if _LIBCPP_STD_VER > 17 +// [time.clock.file], type file_clock +using file_clock = _VSTD_FS::_FilesystemClock; + +template<class _Duration> +using file_time = time_point<file_clock, _Duration>; + + +template <class _Duration> +using sys_time = time_point<system_clock, _Duration>; +using sys_seconds = sys_time<seconds>; +using sys_days = sys_time<days>; + +struct local_t {}; +template<class Duration> +using local_time = time_point<local_t, Duration>; +using local_seconds = local_time<seconds>; +using local_days = local_time<days>; + + +struct last_spec { explicit last_spec() = default; }; + +class day { +private: + unsigned char __d; +public: + day() = default; + explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {} + inline constexpr day& operator++() noexcept { ++__d; return *this; } + inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } + inline constexpr day& operator--() noexcept { --__d; return *this; } + inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } + constexpr day& operator+=(const days& __dd) noexcept; + constexpr day& operator-=(const days& __dd) noexcept; + explicit inline constexpr operator unsigned() const noexcept { return __d; } + inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; } + }; + + +inline constexpr +bool operator==(const day& __lhs, const day& __rhs) noexcept +{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } + +inline constexpr +bool operator!=(const day& __lhs, const day& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const day& __lhs, const day& __rhs) noexcept +{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } + +inline constexpr +bool operator> (const day& __lhs, const day& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const day& __lhs, const day& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const day& __lhs, const day& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +day operator+ (const day& __lhs, const days& __rhs) noexcept +{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); } + +inline constexpr +day operator+ (const days& __lhs, const day& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +day operator- (const day& __lhs, const days& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr +days operator-(const day& __lhs, const day& __rhs) noexcept +{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) - + static_cast<int>(static_cast<unsigned>(__rhs))); } + +inline constexpr day& day::operator+=(const days& __dd) noexcept +{ *this = *this + __dd; return *this; } + +inline constexpr day& day::operator-=(const days& __dd) noexcept +{ *this = *this - __dd; return *this; } + + +class month { +private: + unsigned char __m; +public: + month() = default; + explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {} + inline constexpr month& operator++() noexcept { ++__m; return *this; } + inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; } + inline constexpr month& operator--() noexcept { --__m; return *this; } + inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; } + constexpr month& operator+=(const months& __m1) noexcept; + constexpr month& operator-=(const months& __m1) noexcept; + explicit inline constexpr operator unsigned() const noexcept { return __m; } + inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; } +}; + + +inline constexpr +bool operator==(const month& __lhs, const month& __rhs) noexcept +{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } + +inline constexpr +bool operator!=(const month& __lhs, const month& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const month& __lhs, const month& __rhs) noexcept +{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } + +inline constexpr +bool operator> (const month& __lhs, const month& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const month& __lhs, const month& __rhs) noexcept +{ return !(__rhs < __lhs); } + +inline constexpr +bool operator>=(const month& __lhs, const month& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +month operator+ (const month& __lhs, const months& __rhs) noexcept +{ + auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1); + auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; + return month{static_cast<unsigned>(__mu - __yr * 12 + 1)}; +} + +inline constexpr +month operator+ (const months& __lhs, const month& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +month operator- (const month& __lhs, const months& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr +months operator-(const month& __lhs, const month& __rhs) noexcept +{ + auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs); + return months(__dm <= 11 ? __dm : __dm + 12); +} + +inline constexpr month& month::operator+=(const months& __dm) noexcept +{ *this = *this + __dm; return *this; } + +inline constexpr month& month::operator-=(const months& __dm) noexcept +{ *this = *this - __dm; return *this; } + + +class year { +private: + short __y; +public: + year() = default; + explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {} + + inline constexpr year& operator++() noexcept { ++__y; return *this; } + inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; } + inline constexpr year& operator--() noexcept { --__y; return *this; } + inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; } + constexpr year& operator+=(const years& __dy) noexcept; + constexpr year& operator-=(const years& __dy) noexcept; + inline constexpr year operator+() const noexcept { return *this; } + inline constexpr year operator-() const noexcept { return year{-__y}; } + + inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); } + explicit inline constexpr operator int() const noexcept { return __y; } + constexpr bool ok() const noexcept; + static inline constexpr year min() noexcept { return year{-32767}; } + static inline constexpr year max() noexcept { return year{ 32767}; } +}; + + +inline constexpr +bool operator==(const year& __lhs, const year& __rhs) noexcept +{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); } + +inline constexpr +bool operator!=(const year& __lhs, const year& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const year& __lhs, const year& __rhs) noexcept +{ return static_cast<int>(__lhs) < static_cast<int>(__rhs); } + +inline constexpr +bool operator> (const year& __lhs, const year& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const year& __lhs, const year& __rhs) noexcept +{ return !(__rhs < __lhs); } + +inline constexpr +bool operator>=(const year& __lhs, const year& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +year operator+ (const year& __lhs, const years& __rhs) noexcept +{ return year(static_cast<int>(__lhs) + __rhs.count()); } + +inline constexpr +year operator+ (const years& __lhs, const year& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year operator- (const year& __lhs, const years& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr +years operator-(const year& __lhs, const year& __rhs) noexcept +{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; } + + +inline constexpr year& year::operator+=(const years& __dy) noexcept +{ *this = *this + __dy; return *this; } + +inline constexpr year& year::operator-=(const years& __dy) noexcept +{ *this = *this - __dy; return *this; } + +inline constexpr bool year::ok() const noexcept +{ return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); } + +class weekday_indexed; +class weekday_last; + +class weekday { +private: + unsigned char __wd; +public: + weekday() = default; + inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val)) {} + inline constexpr weekday(const sys_days& __sysd) noexcept + : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {} + inline explicit constexpr weekday(const local_days& __locd) noexcept + : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {} + + inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; } + inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; } + inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; } + inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; } + constexpr weekday& operator+=(const days& __dd) noexcept; + constexpr weekday& operator-=(const days& __dd) noexcept; + inline explicit constexpr operator unsigned() const noexcept { return __wd; } + inline constexpr bool ok() const noexcept { return __wd <= 6; } + constexpr weekday_indexed operator[](unsigned __index) const noexcept; + constexpr weekday_last operator[](last_spec) const noexcept; + + static constexpr unsigned char __weekday_from_days(int __days) noexcept; +}; + + +// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days +inline constexpr +unsigned char weekday::__weekday_from_days(int __days) noexcept +{ + return static_cast<unsigned char>( + static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6) + ); +} + +inline constexpr +bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept +{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } + +inline constexpr +bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept +{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } + +inline constexpr +bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept +{ return !(__lhs < __rhs); } + +constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept +{ + auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + __rhs.count(); + auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; + return weekday{static_cast<unsigned>(__mu - __yr * 7)}; +} + +constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept +{ return __rhs + __lhs; } + +constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept +{ return __lhs + -__rhs; } + +constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept +{ + const int __wdu = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs); + const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7; + return days{__wdu - __wk * 7}; +} + +inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept +{ *this = *this + __dd; return *this; } + +inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept +{ *this = *this - __dd; return *this; } + + +class weekday_indexed { +private: + _VSTD::chrono::weekday __wd; + unsigned char __idx; +public: + weekday_indexed() = default; + inline constexpr weekday_indexed(const _VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept + : __wd{__wdval}, __idx(__idxval) {} + inline constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; } + inline constexpr unsigned index() const noexcept { return __idx; } + inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; } +}; + +inline constexpr +bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept +{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); } + +inline constexpr +bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept +{ return !(__lhs == __rhs); } + + +class weekday_last { +private: + _VSTD::chrono::weekday __wd; +public: + explicit constexpr weekday_last(const _VSTD::chrono::weekday& __val) noexcept + : __wd{__val} {} + constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; } + constexpr bool ok() const noexcept { return __wd.ok(); } +}; + +inline constexpr +bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept +{ return __lhs.weekday() == __rhs.weekday(); } + +inline constexpr +bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; } + +inline constexpr +weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; } + + +inline constexpr last_spec last{}; +inline constexpr weekday Sunday{0}; +inline constexpr weekday Monday{1}; +inline constexpr weekday Tuesday{2}; +inline constexpr weekday Wednesday{3}; +inline constexpr weekday Thursday{4}; +inline constexpr weekday Friday{5}; +inline constexpr weekday Saturday{6}; + +inline constexpr month January{1}; +inline constexpr month February{2}; +inline constexpr month March{3}; +inline constexpr month April{4}; +inline constexpr month May{5}; +inline constexpr month June{6}; +inline constexpr month July{7}; +inline constexpr month August{8}; +inline constexpr month September{9}; +inline constexpr month October{10}; +inline constexpr month November{11}; +inline constexpr month December{12}; + + +class month_day { +private: + chrono::month __m; + chrono::day __d; +public: + month_day() = default; + constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept + : __m{__mval}, __d{__dval} {} + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::day day() const noexcept { return __d; } + constexpr bool ok() const noexcept; +}; + +inline constexpr +bool month_day::ok() const noexcept +{ + if (!__m.ok()) return false; + const unsigned __dval = static_cast<unsigned>(__d); + if (__dval < 1 || __dval > 31) return false; + if (__dval <= 29) return true; +// Now we've got either 30 or 31 + const unsigned __mval = static_cast<unsigned>(__m); + if (__mval == 2) return false; + if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) + return __dval == 30; + return true; +} + +inline constexpr +bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept +{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } + +inline constexpr +bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +month_day operator/(const month& __lhs, const day& __rhs) noexcept +{ return month_day{__lhs, __rhs}; } + +constexpr +month_day operator/(const day& __lhs, const month& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr +month_day operator/(const month& __lhs, int __rhs) noexcept +{ return __lhs / day(__rhs); } + +constexpr +month_day operator/(int __lhs, const day& __rhs) noexcept +{ return month(__lhs) / __rhs; } + +constexpr +month_day operator/(const day& __lhs, int __rhs) noexcept +{ return month(__rhs) / __lhs; } + + +inline constexpr +bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept +{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); } + +inline constexpr +bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept +{ return !(__lhs < __rhs); } + + + +class month_day_last { +private: + chrono::month __m; +public: + explicit constexpr month_day_last(const chrono::month& __val) noexcept + : __m{__val} {} + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr bool ok() const noexcept { return __m.ok(); } +}; + +inline constexpr +bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return __lhs.month() == __rhs.month(); } + +inline constexpr +bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return __lhs.month() < __rhs.month(); } + +inline constexpr +bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +month_day_last operator/(const month& __lhs, last_spec) noexcept +{ return month_day_last{__lhs}; } + +inline constexpr +month_day_last operator/(last_spec, const month& __rhs) noexcept +{ return month_day_last{__rhs}; } + +inline constexpr +month_day_last operator/(int __lhs, last_spec) noexcept +{ return month_day_last{month(__lhs)}; } + +inline constexpr +month_day_last operator/(last_spec, int __rhs) noexcept +{ return month_day_last{month(__rhs)}; } + + +class month_weekday { +private: + chrono::month __m; + chrono::weekday_indexed __wdi; +public: + month_weekday() = default; + constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept + : __m{__mval}, __wdi{__wdival} {} + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } + inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); } +}; + +inline constexpr +bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept +{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } + +inline constexpr +bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept +{ return month_weekday{__lhs, __rhs}; } + +inline constexpr +month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept +{ return month_weekday{month(__lhs), __rhs}; } + +inline constexpr +month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept +{ return month_weekday{__rhs, __lhs}; } + +inline constexpr +month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept +{ return month_weekday{month(__rhs), __lhs}; } + + +class month_weekday_last { + chrono::month __m; + chrono::weekday_last __wdl; + public: + constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept + : __m{__mval}, __wdl{__wdlval} {} + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } + inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); } +}; + +inline constexpr +bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept +{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } + +inline constexpr +bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + + +inline constexpr +month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept +{ return month_weekday_last{__lhs, __rhs}; } + +inline constexpr +month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept +{ return month_weekday_last{month(__lhs), __rhs}; } + +inline constexpr +month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept +{ return month_weekday_last{__rhs, __lhs}; } + +inline constexpr +month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept +{ return month_weekday_last{month(__rhs), __lhs}; } + + +class year_month { + chrono::year __y; + chrono::month __m; +public: + year_month() = default; + constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept + : __y{__yval}, __m{__mval} {} + inline constexpr chrono::year year() const noexcept { return __y; } + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; } + inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; } + inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; } + inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; } + inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); } +}; + +inline constexpr +year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; } + +inline constexpr +year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; } + +inline constexpr +bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); } + +inline constexpr +bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept +{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); } + +inline constexpr +bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept +{ return !(__lhs < __rhs); } + +constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept +{ + int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count(); + const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12; + __dmi = __dmi - __dy * 12 + 1; + return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi)); +} + +constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept +{ return __rhs + __lhs; } + +constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept +{ return (__lhs.year() + __rhs) / __lhs.month(); } + +constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept +{ return __rhs + __lhs; } + +constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept +{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); } + +constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept +{ return __lhs + -__rhs; } + +constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept +{ return __lhs + -__rhs; } + +class year_month_day_last; + +class year_month_day { +private: + chrono::year __y; + chrono::month __m; + chrono::day __d; +public: + year_month_day() = default; + inline constexpr year_month_day( + const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept + : __y{__yval}, __m{__mval}, __d{__dval} {} + constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; + inline constexpr year_month_day(const sys_days& __sysd) noexcept + : year_month_day(__from_days(__sysd.time_since_epoch())) {} + inline explicit constexpr year_month_day(const local_days& __locd) noexcept + : year_month_day(__from_days(__locd.time_since_epoch())) {} + + constexpr year_month_day& operator+=(const months& __dm) noexcept; + constexpr year_month_day& operator-=(const months& __dm) noexcept; + constexpr year_month_day& operator+=(const years& __dy) noexcept; + constexpr year_month_day& operator-=(const years& __dy) noexcept; + + inline constexpr chrono::year year() const noexcept { return __y; } + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::day day() const noexcept { return __d; } + inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } + inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } + + constexpr bool ok() const noexcept; + + static constexpr year_month_day __from_days(days __d) noexcept; + constexpr days __to_days() const noexcept; +}; + + +// https://howardhinnant.github.io/date_algorithms.html#civil_from_days +inline constexpr +year_month_day +year_month_day::__from_days(days __d) noexcept +{ + static_assert(std::numeric_limits<unsigned>::digits >= 18, ""); + static_assert(std::numeric_limits<int>::digits >= 20 , ""); + const int __z = __d.count() + 719468; + const int __era = (__z >= 0 ? __z : __z - 146096) / 146097; + const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096] + const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399] + const int __yr = static_cast<int>(__yoe) + __era * 400; + const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365] + const unsigned __mp = (5 * __doy + 2)/153; // [0, 11] + const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31] + const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12] + return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}}; +} + +// https://howardhinnant.github.io/date_algorithms.html#days_from_civil +inline constexpr days year_month_day::__to_days() const noexcept +{ + static_assert(std::numeric_limits<unsigned>::digits >= 18, ""); + static_assert(std::numeric_limits<int>::digits >= 20 , ""); + + const int __yr = static_cast<int>(__y) - (__m <= February); + const unsigned __mth = static_cast<unsigned>(__m); + const unsigned __dy = static_cast<unsigned>(__d); + + const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400; + const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399] + const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365] + const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096] + return days{__era * 146097 + static_cast<int>(__doe) - 719468}; +} + +inline constexpr +bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } + +inline constexpr +bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ + if (__lhs.year() < __rhs.year()) return true; + if (__lhs.year() > __rhs.year()) return false; + if (__lhs.month() < __rhs.month()) return true; + if (__lhs.month() > __rhs.month()) return false; + return __lhs.day() < __rhs.day(); +} + +inline constexpr +bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept +{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; } + +inline constexpr +year_month_day operator/(const year_month& __lhs, int __rhs) noexcept +{ return __lhs / day(__rhs); } + +inline constexpr +year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept +{ return __lhs / __rhs.month() / __rhs.day(); } + +inline constexpr +year_month_day operator/(int __lhs, const month_day& __rhs) noexcept +{ return year(__lhs) / __rhs; } + +inline constexpr +year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr +year_month_day operator/(const month_day& __lhs, int __rhs) noexcept +{ return year(__rhs) / __lhs; } + + +inline constexpr +year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept +{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); } + +inline constexpr +year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr +year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept +{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); } + +inline constexpr +year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } +inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } +inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } +inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } + +class year_month_day_last { +private: + chrono::year __y; + chrono::month_day_last __mdl; +public: + constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept + : __y{__yval}, __mdl{__mdlval} {} + + constexpr year_month_day_last& operator+=(const months& __m) noexcept; + constexpr year_month_day_last& operator-=(const months& __m) noexcept; + constexpr year_month_day_last& operator+=(const years& __y) noexcept; + constexpr year_month_day_last& operator-=(const years& __y) noexcept; + + inline constexpr chrono::year year() const noexcept { return __y; } + inline constexpr chrono::month month() const noexcept { return __mdl.month(); } + inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; } + constexpr chrono::day day() const noexcept; + inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; } + inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; } + inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); } +}; + +inline constexpr +chrono::day year_month_day_last::day() const noexcept +{ + constexpr chrono::day __d[] = + { + chrono::day(31), chrono::day(28), chrono::day(31), + chrono::day(30), chrono::day(31), chrono::day(30), + chrono::day(31), chrono::day(31), chrono::day(30), + chrono::day(31), chrono::day(30), chrono::day(31) + }; + return month() != February || !__y.is_leap() ? + __d[static_cast<unsigned>(month()) - 1] : chrono::day{29}; +} + +inline constexpr +bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); } + +inline constexpr +bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ + if (__lhs.year() < __rhs.year()) return true; + if (__lhs.year() > __rhs.year()) return false; + return __lhs.month_day_last() < __rhs.month_day_last(); +} + +inline constexpr +bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept +{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; } + +inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept +{ return year_month_day_last{__lhs, __rhs}; } + +inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept +{ return year_month_day_last{year{__lhs}, __rhs}; } + +inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept +{ return year{__rhs} / __lhs; } + + +inline constexpr +year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept +{ return (__lhs.year() / __lhs.month() + __rhs) / last; } + +inline constexpr +year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr +year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept +{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; } + +inline constexpr +year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } +inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } +inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } +inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } + +inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept + : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {} + +inline constexpr bool year_month_day::ok() const noexcept +{ + if (!__y.ok() || !__m.ok()) return false; + return chrono::day{1} <= __d && __d <= (__y / __m / last).day(); +} + +class year_month_weekday { + chrono::year __y; + chrono::month __m; + chrono::weekday_indexed __wdi; +public: + year_month_weekday() = default; + constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval, + const chrono::weekday_indexed& __wdival) noexcept + : __y{__yval}, __m{__mval}, __wdi{__wdival} {} + constexpr year_month_weekday(const sys_days& __sysd) noexcept + : year_month_weekday(__from_days(__sysd.time_since_epoch())) {} + inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept + : year_month_weekday(__from_days(__locd.time_since_epoch())) {} + constexpr year_month_weekday& operator+=(const months& m) noexcept; + constexpr year_month_weekday& operator-=(const months& m) noexcept; + constexpr year_month_weekday& operator+=(const years& y) noexcept; + constexpr year_month_weekday& operator-=(const years& y) noexcept; + + inline constexpr chrono::year year() const noexcept { return __y; } + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); } + inline constexpr unsigned index() const noexcept { return __wdi.index(); } + inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } + + inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } + inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } + inline constexpr bool ok() const noexcept + { + if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false; + // TODO: make sure it's a valid date + return true; + } + + static constexpr year_month_weekday __from_days(days __d) noexcept; + constexpr days __to_days() const noexcept; +}; + +inline constexpr +year_month_weekday year_month_weekday::__from_days(days __d) noexcept +{ + const sys_days __sysd{__d}; + const chrono::weekday __wd = chrono::weekday(__sysd); + const year_month_day __ymd = year_month_day(__sysd); + return year_month_weekday{__ymd.year(), __ymd.month(), + __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]}; +} + +inline constexpr +days year_month_weekday::__to_days() const noexcept +{ + const sys_days __sysd = sys_days(__y/__m/1); + return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7})) + .time_since_epoch(); +} + +inline constexpr +bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } + +inline constexpr +bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept +{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; } + +inline constexpr +year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept +{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; } + +inline constexpr +year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept +{ return year(__lhs) / __rhs; } + +inline constexpr +year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr +year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept +{ return year(__rhs) / __lhs; } + + +inline constexpr +year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept +{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); } + +inline constexpr +year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr +year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept +{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; } + +inline constexpr +year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept +{ return __lhs + (-__rhs); } + + +inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } +inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } +inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } +inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } + +class year_month_weekday_last { +private: + chrono::year __y; + chrono::month __m; + chrono::weekday_last __wdl; +public: + constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval, + const chrono::weekday_last& __wdlval) noexcept + : __y{__yval}, __m{__mval}, __wdl{__wdlval} {} + constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept; + constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept; + constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept; + constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept; + + inline constexpr chrono::year year() const noexcept { return __y; } + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); } + inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } + inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } + inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } + inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); } + + constexpr days __to_days() const noexcept; + +}; + +inline constexpr +days year_month_weekday_last::__to_days() const noexcept +{ + const sys_days __last = sys_days{__y/__m/last}; + return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch(); + +} + +inline constexpr +bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } + +inline constexpr +bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + + +inline constexpr +year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept +{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; } + +inline constexpr +year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept +{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; } + +inline constexpr +year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept +{ return year(__lhs) / __rhs; } + +inline constexpr +year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr +year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept +{ return year(__rhs) / __lhs; } + + +inline constexpr +year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept +{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); } + +inline constexpr +year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr +year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept +{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; } + +inline constexpr +year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } +inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } +inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } +inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } + +#endif // _LIBCPP_STD_VER > 17 +} // chrono + +#if _LIBCPP_STD_VER > 11 +// Suffixes for duration literals [time.duration.literals] +inline namespace literals +{ + inline namespace chrono_literals + { + + constexpr chrono::hours operator""h(unsigned long long __h) + { + return chrono::hours(static_cast<chrono::hours::rep>(__h)); + } + + constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h) + { + return chrono::duration<long double, ratio<3600,1>>(__h); + } + + + constexpr chrono::minutes operator""min(unsigned long long __m) + { + return chrono::minutes(static_cast<chrono::minutes::rep>(__m)); + } + + constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m) + { + return chrono::duration<long double, ratio<60,1>> (__m); + } + + + constexpr chrono::seconds operator""s(unsigned long long __s) + { + return chrono::seconds(static_cast<chrono::seconds::rep>(__s)); + } + + constexpr chrono::duration<long double> operator""s(long double __s) + { + return chrono::duration<long double> (__s); + } + + + constexpr chrono::milliseconds operator""ms(unsigned long long __ms) + { + return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms)); + } + + constexpr chrono::duration<long double, milli> operator""ms(long double __ms) + { + return chrono::duration<long double, milli>(__ms); + } + + + constexpr chrono::microseconds operator""us(unsigned long long __us) + { + return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us)); + } + + constexpr chrono::duration<long double, micro> operator""us(long double __us) + { + return chrono::duration<long double, micro> (__us); + } + + + constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) + { + return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns)); + } + + constexpr chrono::duration<long double, nano> operator""ns(long double __ns) + { + return chrono::duration<long double, nano> (__ns); + } + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS) + constexpr chrono::day operator ""d(unsigned long long __d) noexcept + { + return chrono::day(static_cast<unsigned>(__d)); + } + + constexpr chrono::year operator ""y(unsigned long long __y) noexcept + { + return chrono::year(static_cast<int>(__y)); + } +#endif +}} + +namespace chrono { // hoist the literals into namespace std::chrono + using namespace literals::chrono_literals; +} + +#endif + +_LIBCPP_END_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +struct _FilesystemClock { +#if !defined(_LIBCPP_HAS_NO_INT128) + typedef __int128_t rep; + typedef nano period; +#else + typedef long long rep; + typedef nano period; +#endif + + typedef chrono::duration<rep, period> duration; + typedef chrono::time_point<_FilesystemClock> time_point; + + static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; + + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept; + + _LIBCPP_INLINE_VISIBILITY + static time_t to_time_t(const time_point& __t) noexcept { + typedef chrono::duration<rep> __secs; + return time_t( + chrono::duration_cast<__secs>(__t.time_since_epoch()).count()); + } + + _LIBCPP_INLINE_VISIBILITY + static time_point from_time_t(time_t __t) noexcept { + typedef chrono::duration<rep> __secs; + return time_point(__secs(__t)); + } +}; +_LIBCPP_END_NAMESPACE_FILESYSTEM +#endif // !_LIBCPP_CXX03_LANG + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_CHRONO diff --git a/android/x86/include/v8/libc++/cinttypes b/android/x86/include/v8/libc++/cinttypes new file mode 100755 index 00000000..55af85cc --- /dev/null +++ b/android/x86/include/v8/libc++/cinttypes @@ -0,0 +1,257 @@ +// -*- C++ -*- +//===--------------------------- cinttypes --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CINTTYPES +#define _LIBCPP_CINTTYPES + +/* + cinttypes synopsis + +This entire header is C99 / C++0X + +#include <cstdint> // <cinttypes> includes <cstdint> + +Macros: + + PRId8 + PRId16 + PRId32 + PRId64 + + PRIdLEAST8 + PRIdLEAST16 + PRIdLEAST32 + PRIdLEAST64 + + PRIdFAST8 + PRIdFAST16 + PRIdFAST32 + PRIdFAST64 + + PRIdMAX + PRIdPTR + + PRIi8 + PRIi16 + PRIi32 + PRIi64 + + PRIiLEAST8 + PRIiLEAST16 + PRIiLEAST32 + PRIiLEAST64 + + PRIiFAST8 + PRIiFAST16 + PRIiFAST32 + PRIiFAST64 + + PRIiMAX + PRIiPTR + + PRIo8 + PRIo16 + PRIo32 + PRIo64 + + PRIoLEAST8 + PRIoLEAST16 + PRIoLEAST32 + PRIoLEAST64 + + PRIoFAST8 + PRIoFAST16 + PRIoFAST32 + PRIoFAST64 + + PRIoMAX + PRIoPTR + + PRIu8 + PRIu16 + PRIu32 + PRIu64 + + PRIuLEAST8 + PRIuLEAST16 + PRIuLEAST32 + PRIuLEAST64 + + PRIuFAST8 + PRIuFAST16 + PRIuFAST32 + PRIuFAST64 + + PRIuMAX + PRIuPTR + + PRIx8 + PRIx16 + PRIx32 + PRIx64 + + PRIxLEAST8 + PRIxLEAST16 + PRIxLEAST32 + PRIxLEAST64 + + PRIxFAST8 + PRIxFAST16 + PRIxFAST32 + PRIxFAST64 + + PRIxMAX + PRIxPTR + + PRIX8 + PRIX16 + PRIX32 + PRIX64 + + PRIXLEAST8 + PRIXLEAST16 + PRIXLEAST32 + PRIXLEAST64 + + PRIXFAST8 + PRIXFAST16 + PRIXFAST32 + PRIXFAST64 + + PRIXMAX + PRIXPTR + + SCNd8 + SCNd16 + SCNd32 + SCNd64 + + SCNdLEAST8 + SCNdLEAST16 + SCNdLEAST32 + SCNdLEAST64 + + SCNdFAST8 + SCNdFAST16 + SCNdFAST32 + SCNdFAST64 + + SCNdMAX + SCNdPTR + + SCNi8 + SCNi16 + SCNi32 + SCNi64 + + SCNiLEAST8 + SCNiLEAST16 + SCNiLEAST32 + SCNiLEAST64 + + SCNiFAST8 + SCNiFAST16 + SCNiFAST32 + SCNiFAST64 + + SCNiMAX + SCNiPTR + + SCNo8 + SCNo16 + SCNo32 + SCNo64 + + SCNoLEAST8 + SCNoLEAST16 + SCNoLEAST32 + SCNoLEAST64 + + SCNoFAST8 + SCNoFAST16 + SCNoFAST32 + SCNoFAST64 + + SCNoMAX + SCNoPTR + + SCNu8 + SCNu16 + SCNu32 + SCNu64 + + SCNuLEAST8 + SCNuLEAST16 + SCNuLEAST32 + SCNuLEAST64 + + SCNuFAST8 + SCNuFAST16 + SCNuFAST32 + SCNuFAST64 + + SCNuMAX + SCNuPTR + + SCNx8 + SCNx16 + SCNx32 + SCNx64 + + SCNxLEAST8 + SCNxLEAST16 + SCNxLEAST32 + SCNxLEAST64 + + SCNxFAST8 + SCNxFAST16 + SCNxFAST32 + SCNxFAST64 + + SCNxMAX + SCNxPTR + +namespace std +{ + +Types: + + imaxdiv_t + +intmax_t imaxabs(intmax_t j); +imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom); +intmax_t strtoimax(const char* restrict nptr, char** restrict endptr, int base); +uintmax_t strtoumax(const char* restrict nptr, char** restrict endptr, int base); +intmax_t wcstoimax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); +uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); + +} // std +*/ + +#include <__config> +#include <cstdint> +#include <inttypes.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using::imaxdiv_t; +using::imaxabs; +using::imaxdiv; +using::strtoimax; +using::strtoumax; +using::wcstoimax; +using::wcstoumax; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CINTTYPES diff --git a/android/x86/include/v8/libc++/ciso646 b/android/x86/include/v8/libc++/ciso646 new file mode 100755 index 00000000..172f1676 --- /dev/null +++ b/android/x86/include/v8/libc++/ciso646 @@ -0,0 +1,24 @@ +// -*- C++ -*- +//===--------------------------- ciso646 ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CISO646 +#define _LIBCPP_CISO646 + +/* + ciso646 synopsis + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#endif // _LIBCPP_CISO646 diff --git a/android/x86/include/v8/libc++/climits b/android/x86/include/v8/libc++/climits new file mode 100755 index 00000000..43eb2d3f --- /dev/null +++ b/android/x86/include/v8/libc++/climits @@ -0,0 +1,47 @@ +// -*- C++ -*- +//===--------------------------- climits ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CLIMITS +#define _LIBCPP_CLIMITS + +/* + climits synopsis + +Macros: + + CHAR_BIT + SCHAR_MIN + SCHAR_MAX + UCHAR_MAX + CHAR_MIN + CHAR_MAX + MB_LEN_MAX + SHRT_MIN + SHRT_MAX + USHRT_MAX + INT_MIN + INT_MAX + UINT_MAX + LONG_MIN + LONG_MAX + ULONG_MAX + LLONG_MIN // C99 + LLONG_MAX // C99 + ULLONG_MAX // C99 + +*/ + +#include <__config> +#include <limits.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#endif // _LIBCPP_CLIMITS diff --git a/android/x86/include/v8/libc++/clocale b/android/x86/include/v8/libc++/clocale new file mode 100755 index 00000000..bff4e92f --- /dev/null +++ b/android/x86/include/v8/libc++/clocale @@ -0,0 +1,54 @@ +// -*- C++ -*- +//===--------------------------- clocale ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CLOCALE +#define _LIBCPP_CLOCALE + +/* + clocale synopsis + +Macros: + + LC_ALL + LC_COLLATE + LC_CTYPE + LC_MONETARY + LC_NUMERIC + LC_TIME + NULL + +namespace std +{ + +struct lconv; +char* setlocale(int category, const char* locale); +lconv* localeconv(); + +} // std + +*/ + +#include <__config> +#include <locale.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::lconv; +#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +using ::setlocale; +#endif +using ::localeconv; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CLOCALE diff --git a/android/x86/include/v8/libc++/cmath b/android/x86/include/v8/libc++/cmath new file mode 100755 index 00000000..3af9f548 --- /dev/null +++ b/android/x86/include/v8/libc++/cmath @@ -0,0 +1,611 @@ +// -*- C++ -*- +//===---------------------------- cmath -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CMATH +#define _LIBCPP_CMATH + +/* + cmath synopsis + +Macros: + + HUGE_VAL + HUGE_VALF // C99 + HUGE_VALL // C99 + INFINITY // C99 + NAN // C99 + FP_INFINITE // C99 + FP_NAN // C99 + FP_NORMAL // C99 + FP_SUBNORMAL // C99 + FP_ZERO // C99 + FP_FAST_FMA // C99 + FP_FAST_FMAF // C99 + FP_FAST_FMAL // C99 + FP_ILOGB0 // C99 + FP_ILOGBNAN // C99 + MATH_ERRNO // C99 + MATH_ERREXCEPT // C99 + math_errhandling // C99 + +namespace std +{ + +Types: + + float_t // C99 + double_t // C99 + +// C90 + +floating_point abs(floating_point x); + +floating_point acos (arithmetic x); +float acosf(float x); +long double acosl(long double x); + +floating_point asin (arithmetic x); +float asinf(float x); +long double asinl(long double x); + +floating_point atan (arithmetic x); +float atanf(float x); +long double atanl(long double x); + +floating_point atan2 (arithmetic y, arithmetic x); +float atan2f(float y, float x); +long double atan2l(long double y, long double x); + +floating_point ceil (arithmetic x); +float ceilf(float x); +long double ceill(long double x); + +floating_point cos (arithmetic x); +float cosf(float x); +long double cosl(long double x); + +floating_point cosh (arithmetic x); +float coshf(float x); +long double coshl(long double x); + +floating_point exp (arithmetic x); +float expf(float x); +long double expl(long double x); + +floating_point fabs (arithmetic x); +float fabsf(float x); +long double fabsl(long double x); + +floating_point floor (arithmetic x); +float floorf(float x); +long double floorl(long double x); + +floating_point fmod (arithmetic x, arithmetic y); +float fmodf(float x, float y); +long double fmodl(long double x, long double y); + +floating_point frexp (arithmetic value, int* exp); +float frexpf(float value, int* exp); +long double frexpl(long double value, int* exp); + +floating_point ldexp (arithmetic value, int exp); +float ldexpf(float value, int exp); +long double ldexpl(long double value, int exp); + +floating_point log (arithmetic x); +float logf(float x); +long double logl(long double x); + +floating_point log10 (arithmetic x); +float log10f(float x); +long double log10l(long double x); + +floating_point modf (floating_point value, floating_point* iptr); +float modff(float value, float* iptr); +long double modfl(long double value, long double* iptr); + +floating_point pow (arithmetic x, arithmetic y); +float powf(float x, float y); +long double powl(long double x, long double y); + +floating_point sin (arithmetic x); +float sinf(float x); +long double sinl(long double x); + +floating_point sinh (arithmetic x); +float sinhf(float x); +long double sinhl(long double x); + +floating_point sqrt (arithmetic x); +float sqrtf(float x); +long double sqrtl(long double x); + +floating_point tan (arithmetic x); +float tanf(float x); +long double tanl(long double x); + +floating_point tanh (arithmetic x); +float tanhf(float x); +long double tanhl(long double x); + +// C99 + +bool signbit(arithmetic x); + +int fpclassify(arithmetic x); + +bool isfinite(arithmetic x); +bool isinf(arithmetic x); +bool isnan(arithmetic x); +bool isnormal(arithmetic x); + +bool isgreater(arithmetic x, arithmetic y); +bool isgreaterequal(arithmetic x, arithmetic y); +bool isless(arithmetic x, arithmetic y); +bool islessequal(arithmetic x, arithmetic y); +bool islessgreater(arithmetic x, arithmetic y); +bool isunordered(arithmetic x, arithmetic y); + +floating_point acosh (arithmetic x); +float acoshf(float x); +long double acoshl(long double x); + +floating_point asinh (arithmetic x); +float asinhf(float x); +long double asinhl(long double x); + +floating_point atanh (arithmetic x); +float atanhf(float x); +long double atanhl(long double x); + +floating_point cbrt (arithmetic x); +float cbrtf(float x); +long double cbrtl(long double x); + +floating_point copysign (arithmetic x, arithmetic y); +float copysignf(float x, float y); +long double copysignl(long double x, long double y); + +floating_point erf (arithmetic x); +float erff(float x); +long double erfl(long double x); + +floating_point erfc (arithmetic x); +float erfcf(float x); +long double erfcl(long double x); + +floating_point exp2 (arithmetic x); +float exp2f(float x); +long double exp2l(long double x); + +floating_point expm1 (arithmetic x); +float expm1f(float x); +long double expm1l(long double x); + +floating_point fdim (arithmetic x, arithmetic y); +float fdimf(float x, float y); +long double fdiml(long double x, long double y); + +floating_point fma (arithmetic x, arithmetic y, arithmetic z); +float fmaf(float x, float y, float z); +long double fmal(long double x, long double y, long double z); + +floating_point fmax (arithmetic x, arithmetic y); +float fmaxf(float x, float y); +long double fmaxl(long double x, long double y); + +floating_point fmin (arithmetic x, arithmetic y); +float fminf(float x, float y); +long double fminl(long double x, long double y); + +floating_point hypot (arithmetic x, arithmetic y); +float hypotf(float x, float y); +long double hypotl(long double x, long double y); + +double hypot(double x, double y, double z); // C++17 +float hypot(float x, float y, float z); // C++17 +long double hypot(long double x, long double y, long double z); // C++17 + +int ilogb (arithmetic x); +int ilogbf(float x); +int ilogbl(long double x); + +floating_point lgamma (arithmetic x); +float lgammaf(float x); +long double lgammal(long double x); + +long long llrint (arithmetic x); +long long llrintf(float x); +long long llrintl(long double x); + +long long llround (arithmetic x); +long long llroundf(float x); +long long llroundl(long double x); + +floating_point log1p (arithmetic x); +float log1pf(float x); +long double log1pl(long double x); + +floating_point log2 (arithmetic x); +float log2f(float x); +long double log2l(long double x); + +floating_point logb (arithmetic x); +float logbf(float x); +long double logbl(long double x); + +long lrint (arithmetic x); +long lrintf(float x); +long lrintl(long double x); + +long lround (arithmetic x); +long lroundf(float x); +long lroundl(long double x); + +double nan (const char* str); +float nanf(const char* str); +long double nanl(const char* str); + +floating_point nearbyint (arithmetic x); +float nearbyintf(float x); +long double nearbyintl(long double x); + +floating_point nextafter (arithmetic x, arithmetic y); +float nextafterf(float x, float y); +long double nextafterl(long double x, long double y); + +floating_point nexttoward (arithmetic x, long double y); +float nexttowardf(float x, long double y); +long double nexttowardl(long double x, long double y); + +floating_point remainder (arithmetic x, arithmetic y); +float remainderf(float x, float y); +long double remainderl(long double x, long double y); + +floating_point remquo (arithmetic x, arithmetic y, int* pquo); +float remquof(float x, float y, int* pquo); +long double remquol(long double x, long double y, int* pquo); + +floating_point rint (arithmetic x); +float rintf(float x); +long double rintl(long double x); + +floating_point round (arithmetic x); +float roundf(float x); +long double roundl(long double x); + +floating_point scalbln (arithmetic x, long ex); +float scalblnf(float x, long ex); +long double scalblnl(long double x, long ex); + +floating_point scalbn (arithmetic x, int ex); +float scalbnf(float x, int ex); +long double scalbnl(long double x, int ex); + +floating_point tgamma (arithmetic x); +float tgammaf(float x); +long double tgammal(long double x); + +floating_point trunc (arithmetic x); +float truncf(float x); +long double truncl(long double x); + +} // std + +*/ + +#include <__config> +#include <math.h> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::signbit; +using ::fpclassify; +using ::isfinite; +using ::isinf; +using ::isnan; +using ::isnormal; +using ::isgreater; +using ::isgreaterequal; +using ::isless; +using ::islessequal; +using ::islessgreater; +using ::isunordered; +using ::isunordered; + +using ::float_t; +using ::double_t; + +#ifndef _AIX +using ::abs; +#endif + +using ::acos; +using ::acosf; +using ::asin; +using ::asinf; +using ::atan; +using ::atanf; +using ::atan2; +using ::atan2f; +using ::ceil; +using ::ceilf; +using ::cos; +using ::cosf; +using ::cosh; +using ::coshf; + +using ::exp; +using ::expf; + +using ::fabs; +using ::fabsf; +using ::floor; +using ::floorf; + +using ::fmod; +using ::fmodf; + +using ::frexp; +using ::frexpf; +using ::ldexp; +using ::ldexpf; + +using ::log; +using ::logf; + +using ::log10; +using ::log10f; +using ::modf; +using ::modff; + +using ::pow; +using ::powf; + +using ::sin; +using ::sinf; +using ::sinh; +using ::sinhf; + +using ::sqrt; +using ::sqrtf; +using ::tan; +using ::tanf; + +using ::tanh; +using ::tanhf; + +using ::acosh; +using ::acoshf; +using ::asinh; +using ::asinhf; +using ::atanh; +using ::atanhf; +using ::cbrt; +using ::cbrtf; + +using ::copysign; +using ::copysignf; + +using ::erf; +using ::erff; +using ::erfc; +using ::erfcf; +using ::exp2; +using ::exp2f; +using ::expm1; +using ::expm1f; +using ::fdim; +using ::fdimf; +using ::fmaf; +using ::fma; +using ::fmax; +using ::fmaxf; +using ::fmin; +using ::fminf; +using ::hypot; +using ::hypotf; +using ::ilogb; +using ::ilogbf; +using ::lgamma; +using ::lgammaf; +using ::llrint; +using ::llrintf; +using ::llround; +using ::llroundf; +using ::log1p; +using ::log1pf; +using ::log2; +using ::log2f; +using ::logb; +using ::logbf; +using ::lrint; +using ::lrintf; +using ::lround; +using ::lroundf; + +using ::nan; +using ::nanf; + +using ::nearbyint; +using ::nearbyintf; +using ::nextafter; +using ::nextafterf; +using ::nexttoward; +using ::nexttowardf; +using ::remainder; +using ::remainderf; +using ::remquo; +using ::remquof; +using ::rint; +using ::rintf; +using ::round; +using ::roundf; +using ::scalbln; +using ::scalblnf; +using ::scalbn; +using ::scalbnf; +using ::tgamma; +using ::tgammaf; +using ::trunc; +using ::truncf; + +using ::acosl; +using ::asinl; +using ::atanl; +using ::atan2l; +using ::ceill; +using ::cosl; +using ::coshl; +using ::expl; +using ::fabsl; +using ::floorl; +using ::fmodl; +using ::frexpl; +using ::ldexpl; +using ::logl; +using ::log10l; +using ::modfl; +using ::powl; +using ::sinl; +using ::sinhl; +using ::sqrtl; +using ::tanl; + +using ::tanhl; +using ::acoshl; +using ::asinhl; +using ::atanhl; +using ::cbrtl; + +using ::copysignl; + +using ::erfl; +using ::erfcl; +using ::exp2l; +using ::expm1l; +using ::fdiml; +using ::fmal; +using ::fmaxl; +using ::fminl; +using ::hypotl; +using ::ilogbl; +using ::lgammal; +using ::llrintl; +using ::llroundl; +using ::log1pl; +using ::log2l; +using ::logbl; +using ::lrintl; +using ::lroundl; +using ::nanl; +using ::nearbyintl; +using ::nextafterl; +using ::nexttowardl; +using ::remainderl; +using ::remquol; +using ::rintl; +using ::roundl; +using ::scalblnl; +using ::scalbnl; +using ::tgammal; +using ::truncl; + +#if _LIBCPP_STD_VER > 14 +inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); } +inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); } +inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); } + +template <class _A1, class _A2, class _A3> +inline _LIBCPP_INLINE_VISIBILITY +typename __lazy_enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value && + is_arithmetic<_A3>::value, + __promote<_A1, _A2, _A3> +>::type +hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT +{ + typedef typename __promote<_A1, _A2, _A3>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value && + is_same<_A3, __result_type>::value)), ""); + return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); +} +#endif + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type +__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ +#if __has_builtin(__builtin_isnan) + return __builtin_isnan(__lcpp_x); +#else + return isnan(__lcpp_x); +#endif +} + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type +__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ + return isnan(__lcpp_x); +} + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type +__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ +#if __has_builtin(__builtin_isinf) + return __builtin_isinf(__lcpp_x); +#else + return isinf(__lcpp_x); +#endif +} + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type +__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ + return isinf(__lcpp_x); +} + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type +__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ +#if __has_builtin(__builtin_isfinite) + return __builtin_isfinite(__lcpp_x); +#else + return isfinite(__lcpp_x); +#endif +} + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type +__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ + return isfinite(__lcpp_x); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CMATH diff --git a/android/x86/include/v8/libc++/codecvt b/android/x86/include/v8/libc++/codecvt new file mode 100755 index 00000000..5ea411ea --- /dev/null +++ b/android/x86/include/v8/libc++/codecvt @@ -0,0 +1,549 @@ +// -*- C++ -*- +//===-------------------------- codecvt -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CODECVT +#define _LIBCPP_CODECVT + +/* + codecvt synopsis + +namespace std +{ + +enum codecvt_mode +{ + consume_header = 4, + generate_header = 2, + little_endian = 1 +}; + +template <class Elem, unsigned long Maxcode = 0x10ffff, + codecvt_mode Mode = (codecvt_mode)0> +class codecvt_utf8 + : public codecvt<Elem, char, mbstate_t> +{ + explicit codecvt_utf8(size_t refs = 0); + ~codecvt_utf8(); +}; + +template <class Elem, unsigned long Maxcode = 0x10ffff, + codecvt_mode Mode = (codecvt_mode)0> +class codecvt_utf16 + : public codecvt<Elem, char, mbstate_t> +{ + explicit codecvt_utf16(size_t refs = 0); + ~codecvt_utf16(); +}; + +template <class Elem, unsigned long Maxcode = 0x10ffff, + codecvt_mode Mode = (codecvt_mode)0> +class codecvt_utf8_utf16 + : public codecvt<Elem, char, mbstate_t> +{ + explicit codecvt_utf8_utf16(size_t refs = 0); + ~codecvt_utf8_utf16(); +}; + +} // std + +*/ + +#include <__config> +#include <__locale> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +enum codecvt_mode +{ + consume_header = 4, + generate_header = 2, + little_endian = 1 +}; + +// codecvt_utf8 + +template <class _Elem> class __codecvt_utf8; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t> + : public codecvt<wchar_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8<char16_t> + : public codecvt<char16_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8<char32_t> + : public codecvt<char32_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <class _Elem, unsigned long _Maxcode = 0x10ffff, + codecvt_mode _Mode = (codecvt_mode)0> +class _LIBCPP_TEMPLATE_VIS codecvt_utf8 + : public __codecvt_utf8<_Elem> +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit codecvt_utf8(size_t __refs = 0) + : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {} + + _LIBCPP_INLINE_VISIBILITY + ~codecvt_utf8() {} +}; + +// codecvt_utf16 + +template <class _Elem, bool _LittleEndian> class __codecvt_utf16; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false> + : public codecvt<wchar_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, true> + : public codecvt<wchar_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, false> + : public codecvt<char16_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, true> + : public codecvt<char16_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, false> + : public codecvt<char32_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, true> + : public codecvt<char32_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <class _Elem, unsigned long _Maxcode = 0x10ffff, + codecvt_mode _Mode = (codecvt_mode)0> +class _LIBCPP_TEMPLATE_VIS codecvt_utf16 + : public __codecvt_utf16<_Elem, _Mode & little_endian> +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit codecvt_utf16(size_t __refs = 0) + : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {} + + _LIBCPP_INLINE_VISIBILITY + ~codecvt_utf16() {} +}; + +// codecvt_utf8_utf16 + +template <class _Elem> class __codecvt_utf8_utf16; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t> + : public codecvt<wchar_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char32_t> + : public codecvt<char32_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char16_t> + : public codecvt<char16_t, char, mbstate_t> +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <class _Elem, unsigned long _Maxcode = 0x10ffff, + codecvt_mode _Mode = (codecvt_mode)0> +class _LIBCPP_TEMPLATE_VIS codecvt_utf8_utf16 + : public __codecvt_utf8_utf16<_Elem> +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit codecvt_utf8_utf16(size_t __refs = 0) + : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {} + + _LIBCPP_INLINE_VISIBILITY + ~codecvt_utf8_utf16() {} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CODECVT diff --git a/android/x86/include/v8/libc++/compare b/android/x86/include/v8/libc++/compare new file mode 100755 index 00000000..e05257be --- /dev/null +++ b/android/x86/include/v8/libc++/compare @@ -0,0 +1,678 @@ +// -*- C++ -*- +//===-------------------------- compare -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_COMPARE +#define _LIBCPP_COMPARE + +/* + compare synopsis + +namespace std { + // [cmp.categories], comparison category types + class weak_equality; + class strong_equality; + class partial_ordering; + class weak_ordering; + class strong_ordering; + + // named comparison functions + constexpr bool is_eq (weak_equality cmp) noexcept { return cmp == 0; } + constexpr bool is_neq (weak_equality cmp) noexcept { return cmp != 0; } + constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; } + constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; } + constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; } + constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; } + + // [cmp.common], common comparison category type + template<class... Ts> + struct common_comparison_category { + using type = see below; + }; + template<class... Ts> + using common_comparison_category_t = typename common_comparison_category<Ts...>::type; + + // [cmp.alg], comparison algorithms + template<class T> constexpr strong_ordering strong_order(const T& a, const T& b); + template<class T> constexpr weak_ordering weak_order(const T& a, const T& b); + template<class T> constexpr partial_ordering partial_order(const T& a, const T& b); + template<class T> constexpr strong_equality strong_equal(const T& a, const T& b); + template<class T> constexpr weak_equality weak_equal(const T& a, const T& b); +} +*/ + +#include <__config> +#include <type_traits> +#include <array> + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 + +// exposition only +enum class _LIBCPP_ENUM_VIS _EqResult : unsigned char { + __zero = 0, + __equal = __zero, + __equiv = __equal, + __nonequal = 1, + __nonequiv = __nonequal +}; + +enum class _LIBCPP_ENUM_VIS _OrdResult : signed char { + __less = -1, + __greater = 1 +}; + +enum class _LIBCPP_ENUM_VIS _NCmpResult : signed char { + __unordered = -127 +}; + +struct _CmpUnspecifiedType; +using _CmpUnspecifiedParam = void (_CmpUnspecifiedType::*)(); + +class weak_equality { + _LIBCPP_INLINE_VISIBILITY + constexpr explicit weak_equality(_EqResult __val) noexcept : __value_(__val) {} + +public: + static const weak_equality equivalent; + static const weak_equality nonequivalent; + + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_equality __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, weak_equality __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(weak_equality __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, weak_equality __v) noexcept; + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + _LIBCPP_INLINE_VISIBILITY friend constexpr weak_equality operator<=>(weak_equality __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr weak_equality operator<=>(_CmpUnspecifiedParam, weak_equality __v) noexcept; +#endif + +private: + _EqResult __value_; +}; + +_LIBCPP_INLINE_VAR constexpr weak_equality weak_equality::equivalent(_EqResult::__equiv); +_LIBCPP_INLINE_VAR constexpr weak_equality weak_equality::nonequivalent(_EqResult::__nonequiv); + +_LIBCPP_INLINE_VISIBILITY +inline constexpr bool operator==(weak_equality __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ == _EqResult::__zero; +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr bool operator==(_CmpUnspecifiedParam, weak_equality __v) noexcept { + return __v.__value_ == _EqResult::__zero; +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr bool operator!=(weak_equality __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ != _EqResult::__zero; +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr bool operator!=(_CmpUnspecifiedParam, weak_equality __v) noexcept { + return __v.__value_ != _EqResult::__zero; +} + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR +_LIBCPP_INLINE_VISIBILITY +inline constexpr weak_equality operator<=>(weak_equality __v, _CmpUnspecifiedParam) noexcept { + return __v; +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr weak_equality operator<=>(_CmpUnspecifiedParam, weak_equality __v) noexcept { + return __v; +} +#endif + +class strong_equality { + _LIBCPP_INLINE_VISIBILITY + explicit constexpr strong_equality(_EqResult __val) noexcept : __value_(__val) {} + +public: + static const strong_equality equal; + static const strong_equality nonequal; + static const strong_equality equivalent; + static const strong_equality nonequivalent; + + // conversion + _LIBCPP_INLINE_VISIBILITY constexpr operator weak_equality() const noexcept { + return __value_ == _EqResult::__zero ? weak_equality::equivalent + : weak_equality::nonequivalent; + } + + // comparisons + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_equality __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(strong_equality __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, strong_equality __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, strong_equality __v) noexcept; + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + _LIBCPP_INLINE_VISIBILITY friend constexpr strong_equality operator<=>(strong_equality __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr strong_equality operator<=>(_CmpUnspecifiedParam, strong_equality __v) noexcept; +#endif +private: + _EqResult __value_; +}; + +_LIBCPP_INLINE_VAR constexpr strong_equality strong_equality::equal(_EqResult::__equal); +_LIBCPP_INLINE_VAR constexpr strong_equality strong_equality::nonequal(_EqResult::__nonequal); +_LIBCPP_INLINE_VAR constexpr strong_equality strong_equality::equivalent(_EqResult::__equiv); +_LIBCPP_INLINE_VAR constexpr strong_equality strong_equality::nonequivalent(_EqResult::__nonequiv); + +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(strong_equality __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ == _EqResult::__zero; +} + +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(_CmpUnspecifiedParam, strong_equality __v) noexcept { + return __v.__value_ == _EqResult::__zero; +} + +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(strong_equality __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ != _EqResult::__zero; +} + +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(_CmpUnspecifiedParam, strong_equality __v) noexcept { + return __v.__value_ != _EqResult::__zero; +} + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR +_LIBCPP_INLINE_VISIBILITY +constexpr strong_equality operator<=>(strong_equality __v, _CmpUnspecifiedParam) noexcept { + return __v; +} + +_LIBCPP_INLINE_VISIBILITY +constexpr strong_equality operator<=>(_CmpUnspecifiedParam, strong_equality __v) noexcept { + return __v; +} +#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + +class partial_ordering { + using _ValueT = signed char; + + _LIBCPP_INLINE_VISIBILITY + explicit constexpr partial_ordering(_EqResult __v) noexcept + : __value_(_ValueT(__v)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit constexpr partial_ordering(_OrdResult __v) noexcept + : __value_(_ValueT(__v)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit constexpr partial_ordering(_NCmpResult __v) noexcept + : __value_(_ValueT(__v)) {} + + constexpr bool __is_ordered() const noexcept { + return __value_ != _ValueT(_NCmpResult::__unordered); + } +public: + // valid values + static const partial_ordering less; + static const partial_ordering equivalent; + static const partial_ordering greater; + static const partial_ordering unordered; + + // conversion + constexpr operator weak_equality() const noexcept { + return __value_ == 0 ? weak_equality::equivalent : weak_equality::nonequivalent; + } + + // comparisons + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept; + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept; +#endif + +private: + _ValueT __value_; +}; + +_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::less(_OrdResult::__less); +_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::equivalent(_EqResult::__equiv); +_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater); +_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered); + +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__is_ordered() && __v.__value_ == 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__is_ordered() && __v.__value_ < 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__is_ordered() && __v.__value_ <= 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__is_ordered() && __v.__value_ > 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__is_ordered() && __v.__value_ >= 0; +} + +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept { + return __v.__is_ordered() && 0 == __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept { + return __v.__is_ordered() && 0 < __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept { + return __v.__is_ordered() && 0 <= __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept { + return __v.__is_ordered() && 0 > __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept { + return __v.__is_ordered() && 0 >= __v.__value_; +} + +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept { + return !__v.__is_ordered() || __v.__value_ != 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept { + return !__v.__is_ordered() || __v.__value_ != 0; +} + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR +_LIBCPP_INLINE_VISIBILITY +constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v; +} +_LIBCPP_INLINE_VISIBILITY +constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept { + return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v); +} +#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + +class weak_ordering { + using _ValueT = signed char; + + _LIBCPP_INLINE_VISIBILITY + explicit constexpr weak_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {} + _LIBCPP_INLINE_VISIBILITY + explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {} + +public: + static const weak_ordering less; + static const weak_ordering equivalent; + static const weak_ordering greater; + + // conversions + _LIBCPP_INLINE_VISIBILITY + constexpr operator weak_equality() const noexcept { + return __value_ == 0 ? weak_equality::equivalent + : weak_equality::nonequivalent; + } + + _LIBCPP_INLINE_VISIBILITY + constexpr operator partial_ordering() const noexcept { + return __value_ == 0 ? partial_ordering::equivalent + : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater); + } + + // comparisons + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept; + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept; +#endif + +private: + _ValueT __value_; +}; + +_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::less(_OrdResult::__less); +_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::equivalent(_EqResult::__equiv); +_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater); + +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ == 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ != 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ < 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ <= 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ > 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ >= 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept { + return 0 == __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept { + return 0 != __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept { + return 0 < __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept { + return 0 <= __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept { + return 0 > __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept { + return 0 >= __v.__value_; +} + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR +_LIBCPP_INLINE_VISIBILITY +constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v; +} +_LIBCPP_INLINE_VISIBILITY +constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept { + return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v); +} +#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + +class strong_ordering { + using _ValueT = signed char; + + _LIBCPP_INLINE_VISIBILITY + explicit constexpr strong_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {} + _LIBCPP_INLINE_VISIBILITY + explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {} + +public: + static const strong_ordering less; + static const strong_ordering equal; + static const strong_ordering equivalent; + static const strong_ordering greater; + + // conversions + _LIBCPP_INLINE_VISIBILITY + constexpr operator weak_equality() const noexcept { + return __value_ == 0 ? weak_equality::equivalent + : weak_equality::nonequivalent; + } + + _LIBCPP_INLINE_VISIBILITY + constexpr operator strong_equality() const noexcept { + return __value_ == 0 ? strong_equality::equal + : strong_equality::nonequal; + } + + _LIBCPP_INLINE_VISIBILITY + constexpr operator partial_ordering() const noexcept { + return __value_ == 0 ? partial_ordering::equivalent + : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr operator weak_ordering() const noexcept { + return __value_ == 0 ? weak_ordering::equivalent + : (__value_ < 0 ? weak_ordering::less : weak_ordering::greater); + } + + // comparisons + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept; + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept; + _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept; +#endif + +private: + _ValueT __value_; +}; + +_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::less(_OrdResult::__less); +_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equal(_EqResult::__equal); +_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equivalent(_EqResult::__equiv); +_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater); + +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ == 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ != 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ < 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ <= 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ > 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v.__value_ >= 0; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept { + return 0 == __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept { + return 0 != __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept { + return 0 < __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept { + return 0 <= __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept { + return 0 > __v.__value_; +} +_LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept { + return 0 >= __v.__value_; +} + +#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR +_LIBCPP_INLINE_VISIBILITY +constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept { + return __v; +} +_LIBCPP_INLINE_VISIBILITY +constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept { + return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v); +} +#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + +// named comparison functions +_LIBCPP_INLINE_VISIBILITY +constexpr bool is_eq(weak_equality __cmp) noexcept { return __cmp == 0; } + +_LIBCPP_INLINE_VISIBILITY +constexpr bool is_neq(weak_equality __cmp) noexcept { return __cmp != 0; } + +_LIBCPP_INLINE_VISIBILITY +constexpr bool is_lt(partial_ordering __cmp) noexcept { return __cmp < 0; } + +_LIBCPP_INLINE_VISIBILITY +constexpr bool is_lteq(partial_ordering __cmp) noexcept { return __cmp <= 0; } + +_LIBCPP_INLINE_VISIBILITY +constexpr bool is_gt(partial_ordering __cmp) noexcept { return __cmp > 0; } + +_LIBCPP_INLINE_VISIBILITY +constexpr bool is_gteq(partial_ordering __cmp) noexcept { return __cmp >= 0; } + +namespace __comp_detail { + +enum _ClassifyCompCategory : unsigned{ + _None, + _WeakEq, + _StrongEq, + _PartialOrd, + _WeakOrd, + _StrongOrd, + _CCC_Size +}; + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +constexpr _ClassifyCompCategory __type_to_enum() noexcept { + if (is_same_v<_Tp, weak_equality>) + return _WeakEq; + if (is_same_v<_Tp, strong_equality>) + return _StrongEq; + if (is_same_v<_Tp, partial_ordering>) + return _PartialOrd; + if (is_same_v<_Tp, weak_ordering>) + return _WeakOrd; + if (is_same_v<_Tp, strong_ordering>) + return _StrongOrd; + return _None; +} + +template <size_t _Size> +constexpr _ClassifyCompCategory +__compute_comp_type(std::array<_ClassifyCompCategory, _Size> __types) { + std::array<int, _CCC_Size> __seen = {}; + for (auto __type : __types) + ++__seen[__type]; + if (__seen[_None]) + return _None; + if (__seen[_WeakEq]) + return _WeakEq; + if (__seen[_StrongEq] && (__seen[_PartialOrd] || __seen[_WeakOrd])) + return _WeakEq; + if (__seen[_StrongEq]) + return _StrongEq; + if (__seen[_PartialOrd]) + return _PartialOrd; + if (__seen[_WeakOrd]) + return _WeakOrd; + return _StrongOrd; +} + +template <class ..._Ts> +constexpr auto __get_comp_type() { + using _CCC = _ClassifyCompCategory; + constexpr array<_CCC, sizeof...(_Ts)> __type_kinds{{__comp_detail::__type_to_enum<_Ts>()...}}; + constexpr _CCC _Cat = sizeof...(_Ts) == 0 ? _StrongOrd + : __compute_comp_type(__type_kinds); + if constexpr (_Cat == _None) + return void(); + else if constexpr (_Cat == _WeakEq) + return weak_equality::equivalent; + else if constexpr (_Cat == _StrongEq) + return strong_equality::equivalent; + else if constexpr (_Cat == _PartialOrd) + return partial_ordering::equivalent; + else if constexpr (_Cat == _WeakOrd) + return weak_ordering::equivalent; + else if constexpr (_Cat == _StrongOrd) + return strong_ordering::equivalent; + else + static_assert(_Cat != _Cat, "unhandled case"); +} +} // namespace __comp_detail + +// [cmp.common], common comparison category type +template<class... _Ts> +struct _LIBCPP_TEMPLATE_VIS common_comparison_category { + using type = decltype(__comp_detail::__get_comp_type<_Ts...>()); +}; + +template<class... _Ts> +using common_comparison_category_t = typename common_comparison_category<_Ts...>::type; + +// [cmp.alg], comparison algorithms +// TODO: unimplemented +template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs); +template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs); +template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs); +template<class _Tp> constexpr strong_equality strong_equal(const _Tp& __lhs, const _Tp& __rhs); +template<class _Tp> constexpr weak_equality weak_equal(const _Tp& __lhs, const _Tp& __rhs); + +#endif // _LIBCPP_STD_VER > 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_COMPARE diff --git a/android/x86/include/v8/libc++/complex b/android/x86/include/v8/libc++/complex new file mode 100755 index 00000000..ff702b4f --- /dev/null +++ b/android/x86/include/v8/libc++/complex @@ -0,0 +1,1495 @@ +// -*- C++ -*- +//===--------------------------- complex ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_COMPLEX +#define _LIBCPP_COMPLEX + +/* + complex synopsis + +namespace std +{ + +template<class T> +class complex +{ +public: + typedef T value_type; + + complex(const T& re = T(), const T& im = T()); // constexpr in C++14 + complex(const complex&); // constexpr in C++14 + template<class X> complex(const complex<X>&); // constexpr in C++14 + + T real() const; // constexpr in C++14 + T imag() const; // constexpr in C++14 + + void real(T); + void imag(T); + + complex<T>& operator= (const T&); + complex<T>& operator+=(const T&); + complex<T>& operator-=(const T&); + complex<T>& operator*=(const T&); + complex<T>& operator/=(const T&); + + complex& operator=(const complex&); + template<class X> complex<T>& operator= (const complex<X>&); + template<class X> complex<T>& operator+=(const complex<X>&); + template<class X> complex<T>& operator-=(const complex<X>&); + template<class X> complex<T>& operator*=(const complex<X>&); + template<class X> complex<T>& operator/=(const complex<X>&); +}; + +template<> +class complex<float> +{ +public: + typedef float value_type; + + constexpr complex(float re = 0.0f, float im = 0.0f); + explicit constexpr complex(const complex<double>&); + explicit constexpr complex(const complex<long double>&); + + constexpr float real() const; + void real(float); + constexpr float imag() const; + void imag(float); + + complex<float>& operator= (float); + complex<float>& operator+=(float); + complex<float>& operator-=(float); + complex<float>& operator*=(float); + complex<float>& operator/=(float); + + complex<float>& operator=(const complex<float>&); + template<class X> complex<float>& operator= (const complex<X>&); + template<class X> complex<float>& operator+=(const complex<X>&); + template<class X> complex<float>& operator-=(const complex<X>&); + template<class X> complex<float>& operator*=(const complex<X>&); + template<class X> complex<float>& operator/=(const complex<X>&); +}; + +template<> +class complex<double> +{ +public: + typedef double value_type; + + constexpr complex(double re = 0.0, double im = 0.0); + constexpr complex(const complex<float>&); + explicit constexpr complex(const complex<long double>&); + + constexpr double real() const; + void real(double); + constexpr double imag() const; + void imag(double); + + complex<double>& operator= (double); + complex<double>& operator+=(double); + complex<double>& operator-=(double); + complex<double>& operator*=(double); + complex<double>& operator/=(double); + complex<double>& operator=(const complex<double>&); + + template<class X> complex<double>& operator= (const complex<X>&); + template<class X> complex<double>& operator+=(const complex<X>&); + template<class X> complex<double>& operator-=(const complex<X>&); + template<class X> complex<double>& operator*=(const complex<X>&); + template<class X> complex<double>& operator/=(const complex<X>&); +}; + +template<> +class complex<long double> +{ +public: + typedef long double value_type; + + constexpr complex(long double re = 0.0L, long double im = 0.0L); + constexpr complex(const complex<float>&); + constexpr complex(const complex<double>&); + + constexpr long double real() const; + void real(long double); + constexpr long double imag() const; + void imag(long double); + + complex<long double>& operator=(const complex<long double>&); + complex<long double>& operator= (long double); + complex<long double>& operator+=(long double); + complex<long double>& operator-=(long double); + complex<long double>& operator*=(long double); + complex<long double>& operator/=(long double); + + template<class X> complex<long double>& operator= (const complex<X>&); + template<class X> complex<long double>& operator+=(const complex<X>&); + template<class X> complex<long double>& operator-=(const complex<X>&); + template<class X> complex<long double>& operator*=(const complex<X>&); + template<class X> complex<long double>& operator/=(const complex<X>&); +}; + +// 26.3.6 operators: +template<class T> complex<T> operator+(const complex<T>&, const complex<T>&); +template<class T> complex<T> operator+(const complex<T>&, const T&); +template<class T> complex<T> operator+(const T&, const complex<T>&); +template<class T> complex<T> operator-(const complex<T>&, const complex<T>&); +template<class T> complex<T> operator-(const complex<T>&, const T&); +template<class T> complex<T> operator-(const T&, const complex<T>&); +template<class T> complex<T> operator*(const complex<T>&, const complex<T>&); +template<class T> complex<T> operator*(const complex<T>&, const T&); +template<class T> complex<T> operator*(const T&, const complex<T>&); +template<class T> complex<T> operator/(const complex<T>&, const complex<T>&); +template<class T> complex<T> operator/(const complex<T>&, const T&); +template<class T> complex<T> operator/(const T&, const complex<T>&); +template<class T> complex<T> operator+(const complex<T>&); +template<class T> complex<T> operator-(const complex<T>&); +template<class T> bool operator==(const complex<T>&, const complex<T>&); // constexpr in C++14 +template<class T> bool operator==(const complex<T>&, const T&); // constexpr in C++14 +template<class T> bool operator==(const T&, const complex<T>&); // constexpr in C++14 +template<class T> bool operator!=(const complex<T>&, const complex<T>&); // constexpr in C++14 +template<class T> bool operator!=(const complex<T>&, const T&); // constexpr in C++14 +template<class T> bool operator!=(const T&, const complex<T>&); // constexpr in C++14 + +template<class T, class charT, class traits> + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>&, complex<T>&); +template<class T, class charT, class traits> + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>&, const complex<T>&); + +// 26.3.7 values: + +template<class T> T real(const complex<T>&); // constexpr in C++14 + long double real(long double); // constexpr in C++14 + double real(double); // constexpr in C++14 +template<Integral T> double real(T); // constexpr in C++14 + float real(float); // constexpr in C++14 + +template<class T> T imag(const complex<T>&); // constexpr in C++14 + long double imag(long double); // constexpr in C++14 + double imag(double); // constexpr in C++14 +template<Integral T> double imag(T); // constexpr in C++14 + float imag(float); // constexpr in C++14 + +template<class T> T abs(const complex<T>&); + +template<class T> T arg(const complex<T>&); + long double arg(long double); + double arg(double); +template<Integral T> double arg(T); + float arg(float); + +template<class T> T norm(const complex<T>&); + long double norm(long double); + double norm(double); +template<Integral T> double norm(T); + float norm(float); + +template<class T> complex<T> conj(const complex<T>&); + complex<long double> conj(long double); + complex<double> conj(double); +template<Integral T> complex<double> conj(T); + complex<float> conj(float); + +template<class T> complex<T> proj(const complex<T>&); + complex<long double> proj(long double); + complex<double> proj(double); +template<Integral T> complex<double> proj(T); + complex<float> proj(float); + +template<class T> complex<T> polar(const T&, const T& = T()); + +// 26.3.8 transcendentals: +template<class T> complex<T> acos(const complex<T>&); +template<class T> complex<T> asin(const complex<T>&); +template<class T> complex<T> atan(const complex<T>&); +template<class T> complex<T> acosh(const complex<T>&); +template<class T> complex<T> asinh(const complex<T>&); +template<class T> complex<T> atanh(const complex<T>&); +template<class T> complex<T> cos (const complex<T>&); +template<class T> complex<T> cosh (const complex<T>&); +template<class T> complex<T> exp (const complex<T>&); +template<class T> complex<T> log (const complex<T>&); +template<class T> complex<T> log10(const complex<T>&); + +template<class T> complex<T> pow(const complex<T>&, const T&); +template<class T> complex<T> pow(const complex<T>&, const complex<T>&); +template<class T> complex<T> pow(const T&, const complex<T>&); + +template<class T> complex<T> sin (const complex<T>&); +template<class T> complex<T> sinh (const complex<T>&); +template<class T> complex<T> sqrt (const complex<T>&); +template<class T> complex<T> tan (const complex<T>&); +template<class T> complex<T> tanh (const complex<T>&); + +template<class T, class charT, class traits> + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, complex<T>& x); + +template<class T, class charT, class traits> + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& o, const complex<T>& x); + +} // std + +*/ + +#include <__config> +#include <type_traits> +#include <stdexcept> +#include <cmath> +#include <sstream> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _Tp> class _LIBCPP_TEMPLATE_VIS complex; + +template<class _Tp> complex<_Tp> operator*(const complex<_Tp>& __z, const complex<_Tp>& __w); +template<class _Tp> complex<_Tp> operator/(const complex<_Tp>& __x, const complex<_Tp>& __y); + +template<class _Tp> +class _LIBCPP_TEMPLATE_VIS complex +{ +public: + typedef _Tp value_type; +private: + value_type __re_; + value_type __im_; +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + complex(const value_type& __re = value_type(), const value_type& __im = value_type()) + : __re_(__re), __im_(__im) {} + template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + complex(const complex<_Xp>& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (const value_type& __re) + {__re_ = __re; __im_ = value_type(); return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(const value_type& __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(const value_type& __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(const value_type& __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(const value_type& __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * complex(__c.real(), __c.imag()); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / complex(__c.real(), __c.imag()); + return *this; + } +}; + +template<> class _LIBCPP_TEMPLATE_VIS complex<double>; +template<> class _LIBCPP_TEMPLATE_VIS complex<long double>; + +template<> +class _LIBCPP_TEMPLATE_VIS complex<float> +{ + float __re_; + float __im_; +public: + typedef float value_type; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(float __re = 0.0f, float __im = 0.0f) + : __re_(__re), __im_(__im) {} + _LIBCPP_INLINE_VISIBILITY + explicit _LIBCPP_CONSTEXPR complex(const complex<double>& __c); + _LIBCPP_INLINE_VISIBILITY + explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c); + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (float __re) + {__re_ = __re; __im_ = value_type(); return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(float __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(float __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(float __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(float __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * complex(__c.real(), __c.imag()); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / complex(__c.real(), __c.imag()); + return *this; + } +}; + +template<> +class _LIBCPP_TEMPLATE_VIS complex<double> +{ + double __re_; + double __im_; +public: + typedef double value_type; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(double __re = 0.0, double __im = 0.0) + : __re_(__re), __im_(__im) {} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR complex(const complex<float>& __c); + _LIBCPP_INLINE_VISIBILITY + explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c); + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (double __re) + {__re_ = __re; __im_ = value_type(); return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(double __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(double __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(double __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(double __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * complex(__c.real(), __c.imag()); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / complex(__c.real(), __c.imag()); + return *this; + } +}; + +template<> +class _LIBCPP_TEMPLATE_VIS complex<long double> +{ + long double __re_; + long double __im_; +public: + typedef long double value_type; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(long double __re = 0.0L, long double __im = 0.0L) + : __re_(__re), __im_(__im) {} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR complex(const complex<float>& __c); + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR complex(const complex<double>& __c); + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (long double __re) + {__re_ = __re; __im_ = value_type(); return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(long double __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(long double __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(long double __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(long double __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * complex(__c.real(), __c.imag()); + return *this; + } + template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / complex(__c.real(), __c.imag()); + return *this; + } +}; + +inline +_LIBCPP_CONSTEXPR +complex<float>::complex(const complex<double>& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +inline +_LIBCPP_CONSTEXPR +complex<float>::complex(const complex<long double>& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +inline +_LIBCPP_CONSTEXPR +complex<double>::complex(const complex<float>& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +inline +_LIBCPP_CONSTEXPR +complex<double>::complex(const complex<long double>& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +inline +_LIBCPP_CONSTEXPR +complex<long double>::complex(const complex<float>& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +inline +_LIBCPP_CONSTEXPR +complex<long double>::complex(const complex<double>& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +// 26.3.6 operators: + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__x); + __t += __y; + return __t; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const complex<_Tp>& __x, const _Tp& __y) +{ + complex<_Tp> __t(__x); + __t += __y; + return __t; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__y); + __t += __x; + return __t; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__x); + __t -= __y; + return __t; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const complex<_Tp>& __x, const _Tp& __y) +{ + complex<_Tp> __t(__x); + __t -= __y; + return __t; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(-__y); + __t += __x; + return __t; +} + +template<class _Tp> +complex<_Tp> +operator*(const complex<_Tp>& __z, const complex<_Tp>& __w) +{ + _Tp __a = __z.real(); + _Tp __b = __z.imag(); + _Tp __c = __w.real(); + _Tp __d = __w.imag(); + _Tp __ac = __a * __c; + _Tp __bd = __b * __d; + _Tp __ad = __a * __d; + _Tp __bc = __b * __c; + _Tp __x = __ac - __bd; + _Tp __y = __ad + __bc; + if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y)) + { + bool __recalc = false; + if (__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b)) + { + __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b); + if (__libcpp_isnan_or_builtin(__c)) + __c = copysign(_Tp(0), __c); + if (__libcpp_isnan_or_builtin(__d)) + __d = copysign(_Tp(0), __d); + __recalc = true; + } + if (__libcpp_isinf_or_builtin(__c) || __libcpp_isinf_or_builtin(__d)) + { + __c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d); + if (__libcpp_isnan_or_builtin(__a)) + __a = copysign(_Tp(0), __a); + if (__libcpp_isnan_or_builtin(__b)) + __b = copysign(_Tp(0), __b); + __recalc = true; + } + if (!__recalc && (__libcpp_isinf_or_builtin(__ac) || __libcpp_isinf_or_builtin(__bd) || + __libcpp_isinf_or_builtin(__ad) || __libcpp_isinf_or_builtin(__bc))) + { + if (__libcpp_isnan_or_builtin(__a)) + __a = copysign(_Tp(0), __a); + if (__libcpp_isnan_or_builtin(__b)) + __b = copysign(_Tp(0), __b); + if (__libcpp_isnan_or_builtin(__c)) + __c = copysign(_Tp(0), __c); + if (__libcpp_isnan_or_builtin(__d)) + __d = copysign(_Tp(0), __d); + __recalc = true; + } + if (__recalc) + { + __x = _Tp(INFINITY) * (__a * __c - __b * __d); + __y = _Tp(INFINITY) * (__a * __d + __b * __c); + } + } + return complex<_Tp>(__x, __y); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator*(const complex<_Tp>& __x, const _Tp& __y) +{ + complex<_Tp> __t(__x); + __t *= __y; + return __t; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator*(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__y); + __t *= __x; + return __t; +} + +template<class _Tp> +complex<_Tp> +operator/(const complex<_Tp>& __z, const complex<_Tp>& __w) +{ + int __ilogbw = 0; + _Tp __a = __z.real(); + _Tp __b = __z.imag(); + _Tp __c = __w.real(); + _Tp __d = __w.imag(); + _Tp __logbw = logb(fmax(fabs(__c), fabs(__d))); + if (__libcpp_isfinite_or_builtin(__logbw)) + { + __ilogbw = static_cast<int>(__logbw); + __c = scalbn(__c, -__ilogbw); + __d = scalbn(__d, -__ilogbw); + } + _Tp __denom = __c * __c + __d * __d; + _Tp __x = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); + _Tp __y = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); + if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y)) + { + if ((__denom == _Tp(0)) && (!__libcpp_isnan_or_builtin(__a) || !__libcpp_isnan_or_builtin(__b))) + { + __x = copysign(_Tp(INFINITY), __c) * __a; + __y = copysign(_Tp(INFINITY), __c) * __b; + } + else if ((__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b)) && __libcpp_isfinite_or_builtin(__c) && __libcpp_isfinite_or_builtin(__d)) + { + __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b); + __x = _Tp(INFINITY) * (__a * __c + __b * __d); + __y = _Tp(INFINITY) * (__b * __c - __a * __d); + } + else if (__libcpp_isinf_or_builtin(__logbw) && __logbw > _Tp(0) && __libcpp_isfinite_or_builtin(__a) && __libcpp_isfinite_or_builtin(__b)) + { + __c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d); + __x = _Tp(0) * (__a * __c + __b * __d); + __y = _Tp(0) * (__b * __c - __a * __d); + } + } + return complex<_Tp>(__x, __y); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator/(const complex<_Tp>& __x, const _Tp& __y) +{ + return complex<_Tp>(__x.real() / __y, __x.imag() / __y); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator/(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__x); + __t /= __y; + return __t; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const complex<_Tp>& __x) +{ + return __x; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const complex<_Tp>& __x) +{ + return complex<_Tp>(-__x.real(), -__x.imag()); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + return __x.real() == __y.real() && __x.imag() == __y.imag(); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const complex<_Tp>& __x, const _Tp& __y) +{ + return __x.real() == __y && __x.imag() == 0; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const _Tp& __x, const complex<_Tp>& __y) +{ + return __x == __y.real() && 0 == __y.imag(); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + return !(__x == __y); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const complex<_Tp>& __x, const _Tp& __y) +{ + return !(__x == __y); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const _Tp& __x, const complex<_Tp>& __y) +{ + return !(__x == __y); +} + +// 26.3.7 values: + +template <class _Tp, bool = is_integral<_Tp>::value, + bool = is_floating_point<_Tp>::value + > +struct __libcpp_complex_overload_traits {}; + +// Integral Types +template <class _Tp> +struct __libcpp_complex_overload_traits<_Tp, true, false> +{ + typedef double _ValueType; + typedef complex<double> _ComplexType; +}; + +// Floating point types +template <class _Tp> +struct __libcpp_complex_overload_traits<_Tp, false, true> +{ + typedef _Tp _ValueType; + typedef complex<_Tp> _ComplexType; +}; + +// real + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp +real(const complex<_Tp>& __c) +{ + return __c.real(); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename __libcpp_complex_overload_traits<_Tp>::_ValueType +real(_Tp __re) +{ + return __re; +} + +// imag + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp +imag(const complex<_Tp>& __c) +{ + return __c.imag(); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename __libcpp_complex_overload_traits<_Tp>::_ValueType +imag(_Tp) +{ + return 0; +} + +// abs + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +abs(const complex<_Tp>& __c) +{ + return hypot(__c.real(), __c.imag()); +} + +// arg + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +arg(const complex<_Tp>& __c) +{ + return atan2(__c.imag(), __c.real()); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + is_same<_Tp, long double>::value, + long double +>::type +arg(_Tp __re) +{ + return atan2l(0.L, __re); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value || is_same<_Tp, double>::value, + double +>::type +arg(_Tp __re) +{ + return atan2(0., __re); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + is_same<_Tp, float>::value, + float +>::type +arg(_Tp __re) +{ + return atan2f(0.F, __re); +} + +// norm + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +norm(const complex<_Tp>& __c) +{ + if (__libcpp_isinf_or_builtin(__c.real())) + return abs(__c.real()); + if (__libcpp_isinf_or_builtin(__c.imag())) + return abs(__c.imag()); + return __c.real() * __c.real() + __c.imag() * __c.imag(); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename __libcpp_complex_overload_traits<_Tp>::_ValueType +norm(_Tp __re) +{ + typedef typename __libcpp_complex_overload_traits<_Tp>::_ValueType _ValueType; + return static_cast<_ValueType>(__re) * __re; +} + +// conj + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +conj(const complex<_Tp>& __c) +{ + return complex<_Tp>(__c.real(), -__c.imag()); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename __libcpp_complex_overload_traits<_Tp>::_ComplexType +conj(_Tp __re) +{ + typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType; + return _ComplexType(__re); +} + + + +// proj + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +proj(const complex<_Tp>& __c) +{ + std::complex<_Tp> __r = __c; + if (__libcpp_isinf_or_builtin(__c.real()) || __libcpp_isinf_or_builtin(__c.imag())) + __r = complex<_Tp>(INFINITY, copysign(_Tp(0), __c.imag())); + return __r; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_floating_point<_Tp>::value, + typename __libcpp_complex_overload_traits<_Tp>::_ComplexType +>::type +proj(_Tp __re) +{ + if (__libcpp_isinf_or_builtin(__re)) + __re = abs(__re); + return complex<_Tp>(__re); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + typename __libcpp_complex_overload_traits<_Tp>::_ComplexType +>::type +proj(_Tp __re) +{ + typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType; + return _ComplexType(__re); +} + +// polar + +template<class _Tp> +complex<_Tp> +polar(const _Tp& __rho, const _Tp& __theta = _Tp()) +{ + if (__libcpp_isnan_or_builtin(__rho) || signbit(__rho)) + return complex<_Tp>(_Tp(NAN), _Tp(NAN)); + if (__libcpp_isnan_or_builtin(__theta)) + { + if (__libcpp_isinf_or_builtin(__rho)) + return complex<_Tp>(__rho, __theta); + return complex<_Tp>(__theta, __theta); + } + if (__libcpp_isinf_or_builtin(__theta)) + { + if (__libcpp_isinf_or_builtin(__rho)) + return complex<_Tp>(__rho, _Tp(NAN)); + return complex<_Tp>(_Tp(NAN), _Tp(NAN)); + } + _Tp __x = __rho * cos(__theta); + if (__libcpp_isnan_or_builtin(__x)) + __x = 0; + _Tp __y = __rho * sin(__theta); + if (__libcpp_isnan_or_builtin(__y)) + __y = 0; + return complex<_Tp>(__x, __y); +} + +// log + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +log(const complex<_Tp>& __x) +{ + return complex<_Tp>(log(abs(__x)), arg(__x)); +} + +// log10 + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +log10(const complex<_Tp>& __x) +{ + return log(__x) / log(_Tp(10)); +} + +// sqrt + +template<class _Tp> +complex<_Tp> +sqrt(const complex<_Tp>& __x) +{ + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(_Tp(INFINITY), __x.imag()); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__x.real() > _Tp(0)) + return complex<_Tp>(__x.real(), __libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : copysign(_Tp(0), __x.imag())); + return complex<_Tp>(__libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : _Tp(0), copysign(__x.real(), __x.imag())); + } + return polar(sqrt(abs(__x)), arg(__x) / _Tp(2)); +} + +// exp + +template<class _Tp> +complex<_Tp> +exp(const complex<_Tp>& __x) +{ + _Tp __i = __x.imag(); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__x.real() < _Tp(0)) + { + if (!__libcpp_isfinite_or_builtin(__i)) + __i = _Tp(1); + } + else if (__i == 0 || !__libcpp_isfinite_or_builtin(__i)) + { + if (__libcpp_isinf_or_builtin(__i)) + __i = _Tp(NAN); + return complex<_Tp>(__x.real(), __i); + } + } + else if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0) + return __x; + _Tp __e = exp(__x.real()); + return complex<_Tp>(__e * cos(__i), __e * sin(__i)); +} + +// pow + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +pow(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + return exp(__y * log(__x)); +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +complex<typename __promote<_Tp, _Up>::type> +pow(const complex<_Tp>& __x, const complex<_Up>& __y) +{ + typedef complex<typename __promote<_Tp, _Up>::type> result_type; + return _VSTD::pow(result_type(__x), result_type(__y)); +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_Up>::value, + complex<typename __promote<_Tp, _Up>::type> +>::type +pow(const complex<_Tp>& __x, const _Up& __y) +{ + typedef complex<typename __promote<_Tp, _Up>::type> result_type; + return _VSTD::pow(result_type(__x), result_type(__y)); +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_Tp>::value, + complex<typename __promote<_Tp, _Up>::type> +>::type +pow(const _Tp& __x, const complex<_Up>& __y) +{ + typedef complex<typename __promote<_Tp, _Up>::type> result_type; + return _VSTD::pow(result_type(__x), result_type(__y)); +} + +// __sqr, computes pow(x, 2) + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +__sqr(const complex<_Tp>& __x) +{ + return complex<_Tp>((__x.real() - __x.imag()) * (__x.real() + __x.imag()), + _Tp(2) * __x.real() * __x.imag()); +} + +// asinh + +template<class _Tp> +complex<_Tp> +asinh(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__libcpp_isnan_or_builtin(__x.imag())) + return __x; + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); + return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); + } + if (__libcpp_isnan_or_builtin(__x.real())) + { + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(__x.imag(), __x.real()); + if (__x.imag() == 0) + return __x; + return complex<_Tp>(__x.real(), __x.real()); + } + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(copysign(__x.imag(), __x.real()), copysign(__pi/_Tp(2), __x.imag())); + complex<_Tp> __z = log(__x + sqrt(__sqr(__x) + _Tp(1))); + return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag())); +} + +// acosh + +template<class _Tp> +complex<_Tp> +acosh(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__libcpp_isnan_or_builtin(__x.imag())) + return complex<_Tp>(abs(__x.real()), __x.imag()); + if (__libcpp_isinf_or_builtin(__x.imag())) + { + if (__x.real() > 0) + return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); + else + return complex<_Tp>(-__x.real(), copysign(__pi * _Tp(0.75), __x.imag())); + } + if (__x.real() < 0) + return complex<_Tp>(-__x.real(), copysign(__pi, __x.imag())); + return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); + } + if (__libcpp_isnan_or_builtin(__x.real())) + { + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(abs(__x.imag()), __x.real()); + return complex<_Tp>(__x.real(), __x.real()); + } + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(abs(__x.imag()), copysign(__pi/_Tp(2), __x.imag())); + complex<_Tp> __z = log(__x + sqrt(__sqr(__x) - _Tp(1))); + return complex<_Tp>(copysign(__z.real(), _Tp(0)), copysign(__z.imag(), __x.imag())); +} + +// atanh + +template<class _Tp> +complex<_Tp> +atanh(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (__libcpp_isinf_or_builtin(__x.imag())) + { + return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); + } + if (__libcpp_isnan_or_builtin(__x.imag())) + { + if (__libcpp_isinf_or_builtin(__x.real()) || __x.real() == 0) + return complex<_Tp>(copysign(_Tp(0), __x.real()), __x.imag()); + return complex<_Tp>(__x.imag(), __x.imag()); + } + if (__libcpp_isnan_or_builtin(__x.real())) + { + return complex<_Tp>(__x.real(), __x.real()); + } + if (__libcpp_isinf_or_builtin(__x.real())) + { + return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); + } + if (abs(__x.real()) == _Tp(1) && __x.imag() == _Tp(0)) + { + return complex<_Tp>(copysign(_Tp(INFINITY), __x.real()), copysign(_Tp(0), __x.imag())); + } + complex<_Tp> __z = log((_Tp(1) + __x) / (_Tp(1) - __x)) / _Tp(2); + return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag())); +} + +// sinh + +template<class _Tp> +complex<_Tp> +sinh(const complex<_Tp>& __x) +{ + if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(__x.real(), _Tp(NAN)); + if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(__x.real(), _Tp(NAN)); + if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real())) + return __x; + return complex<_Tp>(sinh(__x.real()) * cos(__x.imag()), cosh(__x.real()) * sin(__x.imag())); +} + +// cosh + +template<class _Tp> +complex<_Tp> +cosh(const complex<_Tp>& __x) +{ + if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(abs(__x.real()), _Tp(NAN)); + if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(_Tp(NAN), __x.real()); + if (__x.real() == 0 && __x.imag() == 0) + return complex<_Tp>(_Tp(1), __x.imag()); + if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real())) + return complex<_Tp>(abs(__x.real()), __x.imag()); + return complex<_Tp>(cosh(__x.real()) * cos(__x.imag()), sinh(__x.real()) * sin(__x.imag())); +} + +// tanh + +template<class _Tp> +complex<_Tp> +tanh(const complex<_Tp>& __x) +{ + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (!__libcpp_isfinite_or_builtin(__x.imag())) + return complex<_Tp>(_Tp(1), _Tp(0)); + return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag()))); + } + if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0) + return __x; + _Tp __2r(_Tp(2) * __x.real()); + _Tp __2i(_Tp(2) * __x.imag()); + _Tp __d(cosh(__2r) + cos(__2i)); + _Tp __2rsh(sinh(__2r)); + if (__libcpp_isinf_or_builtin(__2rsh) && __libcpp_isinf_or_builtin(__d)) + return complex<_Tp>(__2rsh > _Tp(0) ? _Tp(1) : _Tp(-1), + __2i > _Tp(0) ? _Tp(0) : _Tp(-0.)); + return complex<_Tp>(__2rsh/__d, sin(__2i)/__d); +} + +// asin + +template<class _Tp> +complex<_Tp> +asin(const complex<_Tp>& __x) +{ + complex<_Tp> __z = asinh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +// acos + +template<class _Tp> +complex<_Tp> +acos(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (__libcpp_isinf_or_builtin(__x.real())) + { + if (__libcpp_isnan_or_builtin(__x.imag())) + return complex<_Tp>(__x.imag(), __x.real()); + if (__libcpp_isinf_or_builtin(__x.imag())) + { + if (__x.real() < _Tp(0)) + return complex<_Tp>(_Tp(0.75) * __pi, -__x.imag()); + return complex<_Tp>(_Tp(0.25) * __pi, -__x.imag()); + } + if (__x.real() < _Tp(0)) + return complex<_Tp>(__pi, signbit(__x.imag()) ? -__x.real() : __x.real()); + return complex<_Tp>(_Tp(0), signbit(__x.imag()) ? __x.real() : -__x.real()); + } + if (__libcpp_isnan_or_builtin(__x.real())) + { + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(__x.real(), -__x.imag()); + return complex<_Tp>(__x.real(), __x.real()); + } + if (__libcpp_isinf_or_builtin(__x.imag())) + return complex<_Tp>(__pi/_Tp(2), -__x.imag()); + if (__x.real() == 0 && (__x.imag() == 0 || isnan(__x.imag()))) + return complex<_Tp>(__pi/_Tp(2), -__x.imag()); + complex<_Tp> __z = log(__x + sqrt(__sqr(__x) - _Tp(1))); + if (signbit(__x.imag())) + return complex<_Tp>(abs(__z.imag()), abs(__z.real())); + return complex<_Tp>(abs(__z.imag()), -abs(__z.real())); +} + +// atan + +template<class _Tp> +complex<_Tp> +atan(const complex<_Tp>& __x) +{ + complex<_Tp> __z = atanh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +// sin + +template<class _Tp> +complex<_Tp> +sin(const complex<_Tp>& __x) +{ + complex<_Tp> __z = sinh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +// cos + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +cos(const complex<_Tp>& __x) +{ + return cosh(complex<_Tp>(-__x.imag(), __x.real())); +} + +// tan + +template<class _Tp> +complex<_Tp> +tan(const complex<_Tp>& __x) +{ + complex<_Tp> __z = tanh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +template<class _Tp, class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x) +{ + if (__is.good()) + { + ws(__is); + if (__is.peek() == _CharT('(')) + { + __is.get(); + _Tp __r; + __is >> __r; + if (!__is.fail()) + { + ws(__is); + _CharT __c = __is.peek(); + if (__c == _CharT(',')) + { + __is.get(); + _Tp __i; + __is >> __i; + if (!__is.fail()) + { + ws(__is); + __c = __is.peek(); + if (__c == _CharT(')')) + { + __is.get(); + __x = complex<_Tp>(__r, __i); + } + else + __is.setstate(ios_base::failbit); + } + else + __is.setstate(ios_base::failbit); + } + else if (__c == _CharT(')')) + { + __is.get(); + __x = complex<_Tp>(__r, _Tp(0)); + } + else + __is.setstate(ios_base::failbit); + } + else + __is.setstate(ios_base::failbit); + } + else + { + _Tp __r; + __is >> __r; + if (!__is.fail()) + __x = complex<_Tp>(__r, _Tp(0)); + else + __is.setstate(ios_base::failbit); + } + } + else + __is.setstate(ios_base::failbit); + return __is; +} + +template<class _Tp, class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) +{ + basic_ostringstream<_CharT, _Traits> __s; + __s.flags(__os.flags()); + __s.imbue(__os.getloc()); + __s.precision(__os.precision()); + __s << '(' << __x.real() << ',' << __x.imag() << ')'; + return __os << __s.str(); +} + +#if _LIBCPP_STD_VER > 11 +// Literal suffix for complex number literals [complex.literals] +inline namespace literals +{ + inline namespace complex_literals + { + constexpr complex<long double> operator""il(long double __im) + { + return { 0.0l, __im }; + } + + constexpr complex<long double> operator""il(unsigned long long __im) + { + return { 0.0l, static_cast<long double>(__im) }; + } + + + constexpr complex<double> operator""i(long double __im) + { + return { 0.0, static_cast<double>(__im) }; + } + + constexpr complex<double> operator""i(unsigned long long __im) + { + return { 0.0, static_cast<double>(__im) }; + } + + + constexpr complex<float> operator""if(long double __im) + { + return { 0.0f, static_cast<float>(__im) }; + } + + constexpr complex<float> operator""if(unsigned long long __im) + { + return { 0.0f, static_cast<float>(__im) }; + } + } +} +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_COMPLEX diff --git a/android/x86/include/v8/libc++/complex.h b/android/x86/include/v8/libc++/complex.h new file mode 100755 index 00000000..b78733b8 --- /dev/null +++ b/android/x86/include/v8/libc++/complex.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===--------------------------- complex.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_COMPLEX_H +#define _LIBCPP_COMPLEX_H + +/* + complex.h synopsis + +#include <ccomplex> + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef __cplusplus + +#include <ccomplex> + +#else // __cplusplus + +#include_next <complex.h> + +#endif // __cplusplus + +#endif // _LIBCPP_COMPLEX_H diff --git a/android/x86/include/v8/libc++/condition_variable b/android/x86/include/v8/libc++/condition_variable new file mode 100755 index 00000000..8c733448 --- /dev/null +++ b/android/x86/include/v8/libc++/condition_variable @@ -0,0 +1,268 @@ +// -*- C++ -*- +//===---------------------- condition_variable ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CONDITION_VARIABLE +#define _LIBCPP_CONDITION_VARIABLE + +/* + condition_variable synopsis + +namespace std +{ + +enum class cv_status { no_timeout, timeout }; + +class condition_variable +{ +public: + condition_variable(); + ~condition_variable(); + + condition_variable(const condition_variable&) = delete; + condition_variable& operator=(const condition_variable&) = delete; + + void notify_one() noexcept; + void notify_all() noexcept; + + void wait(unique_lock<mutex>& lock); + template <class Predicate> + void wait(unique_lock<mutex>& lock, Predicate pred); + + template <class Clock, class Duration> + cv_status + wait_until(unique_lock<mutex>& lock, + const chrono::time_point<Clock, Duration>& abs_time); + + template <class Clock, class Duration, class Predicate> + bool + wait_until(unique_lock<mutex>& lock, + const chrono::time_point<Clock, Duration>& abs_time, + Predicate pred); + + template <class Rep, class Period> + cv_status + wait_for(unique_lock<mutex>& lock, + const chrono::duration<Rep, Period>& rel_time); + + template <class Rep, class Period, class Predicate> + bool + wait_for(unique_lock<mutex>& lock, + const chrono::duration<Rep, Period>& rel_time, + Predicate pred); + + typedef pthread_cond_t* native_handle_type; + native_handle_type native_handle(); +}; + +void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk); + +class condition_variable_any +{ +public: + condition_variable_any(); + ~condition_variable_any(); + + condition_variable_any(const condition_variable_any&) = delete; + condition_variable_any& operator=(const condition_variable_any&) = delete; + + void notify_one() noexcept; + void notify_all() noexcept; + + template <class Lock> + void wait(Lock& lock); + template <class Lock, class Predicate> + void wait(Lock& lock, Predicate pred); + + template <class Lock, class Clock, class Duration> + cv_status + wait_until(Lock& lock, + const chrono::time_point<Clock, Duration>& abs_time); + + template <class Lock, class Clock, class Duration, class Predicate> + bool + wait_until(Lock& lock, + const chrono::time_point<Clock, Duration>& abs_time, + Predicate pred); + + template <class Lock, class Rep, class Period> + cv_status + wait_for(Lock& lock, + const chrono::duration<Rep, Period>& rel_time); + + template <class Lock, class Rep, class Period, class Predicate> + bool + wait_for(Lock& lock, + const chrono::duration<Rep, Period>& rel_time, + Predicate pred); +}; + +} // std + +*/ + +#include <__config> +#include <__mutex_base> +#include <memory> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifndef _LIBCPP_HAS_NO_THREADS + +_LIBCPP_BEGIN_NAMESPACE_STD + +class _LIBCPP_TYPE_VIS condition_variable_any +{ + condition_variable __cv_; + shared_ptr<mutex> __mut_; +public: + _LIBCPP_INLINE_VISIBILITY + condition_variable_any(); + + _LIBCPP_INLINE_VISIBILITY + void notify_one() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void notify_all() _NOEXCEPT; + + template <class _Lock> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + void wait(_Lock& __lock); + template <class _Lock, class _Predicate> + _LIBCPP_INLINE_VISIBILITY + void wait(_Lock& __lock, _Predicate __pred); + + template <class _Lock, class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + cv_status + wait_until(_Lock& __lock, + const chrono::time_point<_Clock, _Duration>& __t); + + template <class _Lock, class _Clock, class _Duration, class _Predicate> + bool + _LIBCPP_INLINE_VISIBILITY + wait_until(_Lock& __lock, + const chrono::time_point<_Clock, _Duration>& __t, + _Predicate __pred); + + template <class _Lock, class _Rep, class _Period> + cv_status + _LIBCPP_INLINE_VISIBILITY + wait_for(_Lock& __lock, + const chrono::duration<_Rep, _Period>& __d); + + template <class _Lock, class _Rep, class _Period, class _Predicate> + bool + _LIBCPP_INLINE_VISIBILITY + wait_for(_Lock& __lock, + const chrono::duration<_Rep, _Period>& __d, + _Predicate __pred); +}; + +inline +condition_variable_any::condition_variable_any() + : __mut_(make_shared<mutex>()) {} + +inline +void +condition_variable_any::notify_one() _NOEXCEPT +{ + {lock_guard<mutex> __lx(*__mut_);} + __cv_.notify_one(); +} + +inline +void +condition_variable_any::notify_all() _NOEXCEPT +{ + {lock_guard<mutex> __lx(*__mut_);} + __cv_.notify_all(); +} + +struct __lock_external +{ + template <class _Lock> + void operator()(_Lock* __m) {__m->lock();} +}; + +template <class _Lock> +void +condition_variable_any::wait(_Lock& __lock) +{ + shared_ptr<mutex> __mut = __mut_; + unique_lock<mutex> __lk(*__mut); + __lock.unlock(); + unique_ptr<_Lock, __lock_external> __lxx(&__lock); + lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock); + __cv_.wait(__lk); +} // __mut_.unlock(), __lock.lock() + +template <class _Lock, class _Predicate> +inline +void +condition_variable_any::wait(_Lock& __lock, _Predicate __pred) +{ + while (!__pred()) + wait(__lock); +} + +template <class _Lock, class _Clock, class _Duration> +cv_status +condition_variable_any::wait_until(_Lock& __lock, + const chrono::time_point<_Clock, _Duration>& __t) +{ + shared_ptr<mutex> __mut = __mut_; + unique_lock<mutex> __lk(*__mut); + __lock.unlock(); + unique_ptr<_Lock, __lock_external> __lxx(&__lock); + lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock); + return __cv_.wait_until(__lk, __t); +} // __mut_.unlock(), __lock.lock() + +template <class _Lock, class _Clock, class _Duration, class _Predicate> +inline +bool +condition_variable_any::wait_until(_Lock& __lock, + const chrono::time_point<_Clock, _Duration>& __t, + _Predicate __pred) +{ + while (!__pred()) + if (wait_until(__lock, __t) == cv_status::timeout) + return __pred(); + return true; +} + +template <class _Lock, class _Rep, class _Period> +inline +cv_status +condition_variable_any::wait_for(_Lock& __lock, + const chrono::duration<_Rep, _Period>& __d) +{ + return wait_until(__lock, chrono::steady_clock::now() + __d); +} + +template <class _Lock, class _Rep, class _Period, class _Predicate> +inline +bool +condition_variable_any::wait_for(_Lock& __lock, + const chrono::duration<_Rep, _Period>& __d, + _Predicate __pred) +{ + return wait_until(__lock, chrono::steady_clock::now() + __d, + _VSTD::move(__pred)); +} + +_LIBCPP_FUNC_VIS +void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk); + +_LIBCPP_END_NAMESPACE_STD + +#endif // !_LIBCPP_HAS_NO_THREADS + +#endif // _LIBCPP_CONDITION_VARIABLE diff --git a/android/x86/include/v8/libc++/csetjmp b/android/x86/include/v8/libc++/csetjmp new file mode 100755 index 00000000..ed94b50d --- /dev/null +++ b/android/x86/include/v8/libc++/csetjmp @@ -0,0 +1,47 @@ +// -*- C++ -*- +//===--------------------------- csetjmp ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSETJMP +#define _LIBCPP_CSETJMP + +/* + csetjmp synopsis + +Macros: + + setjmp + +namespace std +{ + +Types: + + jmp_buf + +void longjmp(jmp_buf env, int val); + +} // std + +*/ + +#include <__config> +#include <setjmp.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::jmp_buf; +using ::longjmp; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSETJMP diff --git a/android/x86/include/v8/libc++/csignal b/android/x86/include/v8/libc++/csignal new file mode 100755 index 00000000..99abd02d --- /dev/null +++ b/android/x86/include/v8/libc++/csignal @@ -0,0 +1,57 @@ +// -*- C++ -*- +//===--------------------------- csignal ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSIGNAL +#define _LIBCPP_CSIGNAL + +/* + csignal synopsis + +Macros: + + SIG_DFL + SIG_ERR + SIG_IGN + SIGABRT + SIGFPE + SIGILL + SIGINT + SIGSEGV + SIGTERM + +namespace std +{ + +Types: + + sig_atomic_t + +void (*signal(int sig, void (*func)(int)))(int); +int raise(int sig); + +} // std + +*/ + +#include <__config> +#include <signal.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::sig_atomic_t; +using ::signal; +using ::raise; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSIGNAL diff --git a/android/x86/include/v8/libc++/cstdarg b/android/x86/include/v8/libc++/cstdarg new file mode 100755 index 00000000..e8147d49 --- /dev/null +++ b/android/x86/include/v8/libc++/cstdarg @@ -0,0 +1,47 @@ +// -*- C++ -*- +//===--------------------------- cstdarg ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDARG +#define _LIBCPP_CSTDARG + +/* + cstdarg synopsis + +Macros: + + type va_arg(va_list ap, type); + void va_copy(va_list dest, va_list src); // C99 + void va_end(va_list ap); + void va_start(va_list ap, parmN); + +namespace std +{ + +Types: + + va_list + +} // std + +*/ + +#include <__config> +#include <stdarg.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::va_list; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTDARG diff --git a/android/x86/include/v8/libc++/cstdbool b/android/x86/include/v8/libc++/cstdbool new file mode 100755 index 00000000..fad47141 --- /dev/null +++ b/android/x86/include/v8/libc++/cstdbool @@ -0,0 +1,31 @@ +// -*- C++ -*- +//===--------------------------- cstdbool ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDBOOL +#define _LIBCPP_CSTDBOOL + +/* + cstdbool synopsis + +Macros: + + __bool_true_false_are_defined + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#undef __bool_true_false_are_defined +#define __bool_true_false_are_defined 1 + +#endif // _LIBCPP_CSTDBOOL diff --git a/android/x86/include/v8/libc++/cstddef b/android/x86/include/v8/libc++/cstddef new file mode 100755 index 00000000..bd62d6db --- /dev/null +++ b/android/x86/include/v8/libc++/cstddef @@ -0,0 +1,113 @@ +// -*- C++ -*- +//===--------------------------- cstddef ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDDEF +#define _LIBCPP_CSTDDEF + +/* + cstddef synopsis + +Macros: + + offsetof(type,member-designator) + NULL + +namespace std +{ + +Types: + + ptrdiff_t + size_t + max_align_t + nullptr_t + byte // C++17 + +} // std + +*/ + +#include <__config> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t. +#include_next <stddef.h> +#include <__nullptr> + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::ptrdiff_t; +using ::size_t; + +#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \ + defined(__DEFINED_max_align_t) || defined(__NetBSD__) +// Re-use the compiler's <stddef.h> max_align_t where possible. +using ::max_align_t; +#else +typedef long double max_align_t; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 +namespace std // purposefully not versioned +{ +enum class byte : unsigned char {}; + +constexpr byte operator| (byte __lhs, byte __rhs) noexcept +{ + return static_cast<byte>( + static_cast<unsigned char>( + static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs) + )); +} + +constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs | __rhs; } + +constexpr byte operator& (byte __lhs, byte __rhs) noexcept +{ + return static_cast<byte>( + static_cast<unsigned char>( + static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs) + )); +} + +constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs & __rhs; } + +constexpr byte operator^ (byte __lhs, byte __rhs) noexcept +{ + return static_cast<byte>( + static_cast<unsigned char>( + static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs) + )); +} + +constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs ^ __rhs; } + +constexpr byte operator~ (byte __b) noexcept +{ + return static_cast<byte>( + static_cast<unsigned char>( + ~static_cast<unsigned int>(__b) + )); +} + +} + +#include <type_traits> // rest of byte +#endif + +#endif // _LIBCPP_CSTDDEF diff --git a/android/x86/include/v8/libc++/cstdint b/android/x86/include/v8/libc++/cstdint new file mode 100755 index 00000000..f72fa067 --- /dev/null +++ b/android/x86/include/v8/libc++/cstdint @@ -0,0 +1,190 @@ +// -*- C++ -*- +//===--------------------------- cstdint ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDINT +#define _LIBCPP_CSTDINT + +/* + cstdint synopsis + +Macros: + + INT8_MIN + INT16_MIN + INT32_MIN + INT64_MIN + + INT8_MAX + INT16_MAX + INT32_MAX + INT64_MAX + + UINT8_MAX + UINT16_MAX + UINT32_MAX + UINT64_MAX + + INT_LEAST8_MIN + INT_LEAST16_MIN + INT_LEAST32_MIN + INT_LEAST64_MIN + + INT_LEAST8_MAX + INT_LEAST16_MAX + INT_LEAST32_MAX + INT_LEAST64_MAX + + UINT_LEAST8_MAX + UINT_LEAST16_MAX + UINT_LEAST32_MAX + UINT_LEAST64_MAX + + INT_FAST8_MIN + INT_FAST16_MIN + INT_FAST32_MIN + INT_FAST64_MIN + + INT_FAST8_MAX + INT_FAST16_MAX + INT_FAST32_MAX + INT_FAST64_MAX + + UINT_FAST8_MAX + UINT_FAST16_MAX + UINT_FAST32_MAX + UINT_FAST64_MAX + + INTPTR_MIN + INTPTR_MAX + UINTPTR_MAX + + INTMAX_MIN + INTMAX_MAX + + UINTMAX_MAX + + PTRDIFF_MIN + PTRDIFF_MAX + + SIG_ATOMIC_MIN + SIG_ATOMIC_MAX + + SIZE_MAX + + WCHAR_MIN + WCHAR_MAX + + WINT_MIN + WINT_MAX + + INT8_C(value) + INT16_C(value) + INT32_C(value) + INT64_C(value) + + UINT8_C(value) + UINT16_C(value) + UINT32_C(value) + UINT64_C(value) + + INTMAX_C(value) + UINTMAX_C(value) + +namespace std +{ + +Types: + + int8_t + int16_t + int32_t + int64_t + + uint8_t + uint16_t + uint32_t + uint64_t + + int_least8_t + int_least16_t + int_least32_t + int_least64_t + + uint_least8_t + uint_least16_t + uint_least32_t + uint_least64_t + + int_fast8_t + int_fast16_t + int_fast32_t + int_fast64_t + + uint_fast8_t + uint_fast16_t + uint_fast32_t + uint_fast64_t + + intptr_t + uintptr_t + + intmax_t + uintmax_t + +} // std +*/ + +#include <__config> +#include <stdint.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using::int8_t; +using::int16_t; +using::int32_t; +using::int64_t; + +using::uint8_t; +using::uint16_t; +using::uint32_t; +using::uint64_t; + +using::int_least8_t; +using::int_least16_t; +using::int_least32_t; +using::int_least64_t; + +using::uint_least8_t; +using::uint_least16_t; +using::uint_least32_t; +using::uint_least64_t; + +using::int_fast8_t; +using::int_fast16_t; +using::int_fast32_t; +using::int_fast64_t; + +using::uint_fast8_t; +using::uint_fast16_t; +using::uint_fast32_t; +using::uint_fast64_t; + +using::intptr_t; +using::uintptr_t; + +using::intmax_t; +using::uintmax_t; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTDINT diff --git a/android/x86/include/v8/libc++/cstdio b/android/x86/include/v8/libc++/cstdio new file mode 100755 index 00000000..67556938 --- /dev/null +++ b/android/x86/include/v8/libc++/cstdio @@ -0,0 +1,171 @@ +// -*- C++ -*- +//===---------------------------- cstdio ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDIO +#define _LIBCPP_CSTDIO + +/* + cstdio synopsis + +Macros: + + BUFSIZ + EOF + FILENAME_MAX + FOPEN_MAX + L_tmpnam + NULL + SEEK_CUR + SEEK_END + SEEK_SET + TMP_MAX + _IOFBF + _IOLBF + _IONBF + stderr + stdin + stdout + +namespace std +{ + +Types: + +FILE +fpos_t +size_t + +int remove(const char* filename); +int rename(const char* old, const char* new); +FILE* tmpfile(void); +char* tmpnam(char* s); +int fclose(FILE* stream); +int fflush(FILE* stream); +FILE* fopen(const char* restrict filename, const char* restrict mode); +FILE* freopen(const char* restrict filename, const char * restrict mode, + FILE * restrict stream); +void setbuf(FILE* restrict stream, char* restrict buf); +int setvbuf(FILE* restrict stream, char* restrict buf, int mode, size_t size); +int fprintf(FILE* restrict stream, const char* restrict format, ...); +int fscanf(FILE* restrict stream, const char * restrict format, ...); +int printf(const char* restrict format, ...); +int scanf(const char* restrict format, ...); +int snprintf(char* restrict s, size_t n, const char* restrict format, ...); // C99 +int sprintf(char* restrict s, const char* restrict format, ...); +int sscanf(const char* restrict s, const char* restrict format, ...); +int vfprintf(FILE* restrict stream, const char* restrict format, va_list arg); +int vfscanf(FILE* restrict stream, const char* restrict format, va_list arg); // C99 +int vprintf(const char* restrict format, va_list arg); +int vscanf(const char* restrict format, va_list arg); // C99 +int vsnprintf(char* restrict s, size_t n, const char* restrict format, // C99 + va_list arg); +int vsprintf(char* restrict s, const char* restrict format, va_list arg); +int vsscanf(const char* restrict s, const char* restrict format, va_list arg); // C99 +int fgetc(FILE* stream); +char* fgets(char* restrict s, int n, FILE* restrict stream); +int fputc(int c, FILE* stream); +int fputs(const char* restrict s, FILE* restrict stream); +int getc(FILE* stream); +int getchar(void); +char* gets(char* s); // removed in C++14 +int putc(int c, FILE* stream); +int putchar(int c); +int puts(const char* s); +int ungetc(int c, FILE* stream); +size_t fread(void* restrict ptr, size_t size, size_t nmemb, + FILE* restrict stream); +size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb, + FILE* restrict stream); +int fgetpos(FILE* restrict stream, fpos_t* restrict pos); +int fseek(FILE* stream, long offset, int whence); +int fsetpos(FILE*stream, const fpos_t* pos); +long ftell(FILE* stream); +void rewind(FILE* stream); +void clearerr(FILE* stream); +int feof(FILE* stream); +int ferror(FILE* stream); +void perror(const char* s); + +} // std +*/ + +#include <__config> +#include <stdio.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::FILE; +using ::fpos_t; +using ::size_t; + +using ::fclose; +using ::fflush; +using ::setbuf; +using ::setvbuf; +using ::fprintf; +using ::fscanf; +using ::snprintf; +using ::sprintf; +using ::sscanf; +using ::vfprintf; +using ::vfscanf; +using ::vsscanf; +using ::vsnprintf; +using ::vsprintf; +using ::fgetc; +using ::fgets; +using ::fputc; +using ::fputs; +using ::getc; +using ::putc; +using ::ungetc; +using ::fread; +using ::fwrite; +using ::fgetpos; +using ::fseek; +using ::fsetpos; +using ::ftell; +using ::rewind; +using ::clearerr; +using ::feof; +using ::ferror; +using ::perror; + +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +using ::fopen; +using ::freopen; +using ::remove; +using ::rename; +using ::tmpfile; +using ::tmpnam; +#endif + +#ifndef _LIBCPP_HAS_NO_STDIN +using ::getchar; +#if _LIBCPP_STD_VER <= 11 && !defined(_LIBCPP_MSVCRT) +using ::gets; +#endif +using ::scanf; +using ::vscanf; +#endif + +#ifndef _LIBCPP_HAS_NO_STDOUT +using ::printf; +using ::putchar; +using ::puts; +using ::vprintf; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTDIO diff --git a/android/x86/include/v8/libc++/cstdlib b/android/x86/include/v8/libc++/cstdlib new file mode 100755 index 00000000..68b3ded3 --- /dev/null +++ b/android/x86/include/v8/libc++/cstdlib @@ -0,0 +1,163 @@ +// -*- C++ -*- +//===--------------------------- cstdlib ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDLIB +#define _LIBCPP_CSTDLIB + +/* + cstdlib synopsis + +Macros: + + EXIT_FAILURE + EXIT_SUCCESS + MB_CUR_MAX + NULL + RAND_MAX + +namespace std +{ + +Types: + + size_t + div_t + ldiv_t + lldiv_t // C99 + +double atof (const char* nptr); +int atoi (const char* nptr); +long atol (const char* nptr); +long long atoll(const char* nptr); // C99 +double strtod (const char* restrict nptr, char** restrict endptr); +float strtof (const char* restrict nptr, char** restrict endptr); // C99 +long double strtold (const char* restrict nptr, char** restrict endptr); // C99 +long strtol (const char* restrict nptr, char** restrict endptr, int base); +long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99 +unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base); +unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99 +int rand(void); +void srand(unsigned int seed); +void* calloc(size_t nmemb, size_t size); +void free(void* ptr); +void* malloc(size_t size); +void* realloc(void* ptr, size_t size); +void abort(void); +int atexit(void (*func)(void)); +void exit(int status); +void _Exit(int status); +char* getenv(const char* name); +int system(const char* string); +void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); +void qsort(void* base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); +int abs( int j); +long abs( long j); +long long abs(long long j); // C++0X +long labs( long j); +long long llabs(long long j); // C99 +div_t div( int numer, int denom); +ldiv_t div( long numer, long denom); +lldiv_t div(long long numer, long long denom); // C++0X +ldiv_t ldiv( long numer, long denom); +lldiv_t lldiv(long long numer, long long denom); // C99 +int mblen(const char* s, size_t n); +int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n); +int wctomb(char* s, wchar_t wchar); +size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n); +size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n); +int at_quick_exit(void (*func)(void)) // C++11 +void quick_exit(int status); // C++11 +void *aligned_alloc(size_t alignment, size_t size); // C11 + +} // std + +*/ + +#include <__config> +#include <stdlib.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef __GNUC__ +#define _LIBCPP_UNREACHABLE() __builtin_unreachable() +#else +#define _LIBCPP_UNREACHABLE() _VSTD::abort() +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::size_t; +using ::div_t; +using ::ldiv_t; +#ifndef _LIBCPP_HAS_NO_LONG_LONG +using ::lldiv_t; +#endif // _LIBCPP_HAS_NO_LONG_LONG +using ::atof; +using ::atoi; +using ::atol; +#ifndef _LIBCPP_HAS_NO_LONG_LONG +using ::atoll; +#endif // _LIBCPP_HAS_NO_LONG_LONG +using ::strtod; +using ::strtof; +using ::strtold; +using ::strtol; +#ifndef _LIBCPP_HAS_NO_LONG_LONG +using ::strtoll; +#endif // _LIBCPP_HAS_NO_LONG_LONG +using ::strtoul; +#ifndef _LIBCPP_HAS_NO_LONG_LONG +using ::strtoull; +#endif // _LIBCPP_HAS_NO_LONG_LONG +using ::rand; +using ::srand; +using ::calloc; +using ::free; +using ::malloc; +using ::realloc; +using ::abort; +using ::atexit; +using ::exit; +using ::_Exit; +#ifndef _LIBCPP_WINDOWS_STORE_APP +using ::getenv; +using ::system; +#endif +using ::bsearch; +using ::qsort; +using ::abs; +using ::labs; +#ifndef _LIBCPP_HAS_NO_LONG_LONG +using ::llabs; +#endif // _LIBCPP_HAS_NO_LONG_LONG +using ::div; +using ::ldiv; +#ifndef _LIBCPP_HAS_NO_LONG_LONG +using ::lldiv; +#endif // _LIBCPP_HAS_NO_LONG_LONG +using ::mblen; +using ::mbtowc; +using ::wctomb; +using ::mbstowcs; +using ::wcstombs; +#if !defined(_LIBCPP_CXX03_LANG) && defined(_LIBCPP_HAS_QUICK_EXIT) +using ::at_quick_exit; +using ::quick_exit; +#endif +#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_C11_FEATURES) +using ::aligned_alloc; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTDLIB diff --git a/android/x86/include/v8/libc++/cstring b/android/x86/include/v8/libc++/cstring new file mode 100755 index 00000000..8bc96a02 --- /dev/null +++ b/android/x86/include/v8/libc++/cstring @@ -0,0 +1,96 @@ +// -*- C++ -*- +//===--------------------------- cstring ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTRING +#define _LIBCPP_CSTRING + +/* + cstring synopsis + +Macros: + + NULL + +namespace std +{ + +Types: + + size_t + +void* memcpy(void* restrict s1, const void* restrict s2, size_t n); +void* memmove(void* s1, const void* s2, size_t n); +char* strcpy (char* restrict s1, const char* restrict s2); +char* strncpy(char* restrict s1, const char* restrict s2, size_t n); +char* strcat (char* restrict s1, const char* restrict s2); +char* strncat(char* restrict s1, const char* restrict s2, size_t n); +int memcmp(const void* s1, const void* s2, size_t n); +int strcmp (const char* s1, const char* s2); +int strncmp(const char* s1, const char* s2, size_t n); +int strcoll(const char* s1, const char* s2); +size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n); +const void* memchr(const void* s, int c, size_t n); + void* memchr( void* s, int c, size_t n); +const char* strchr(const char* s, int c); + char* strchr( char* s, int c); +size_t strcspn(const char* s1, const char* s2); +const char* strpbrk(const char* s1, const char* s2); + char* strpbrk( char* s1, const char* s2); +const char* strrchr(const char* s, int c); + char* strrchr( char* s, int c); +size_t strspn(const char* s1, const char* s2); +const char* strstr(const char* s1, const char* s2); + char* strstr( char* s1, const char* s2); +char* strtok(char* restrict s1, const char* restrict s2); +void* memset(void* s, int c, size_t n); +char* strerror(int errnum); +size_t strlen(const char* s); + +} // std + +*/ + +#include <__config> +#include <string.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::size_t; +using ::memcpy; +using ::memmove; +using ::strcpy; +using ::strncpy; +using ::strcat; +using ::strncat; +using ::memcmp; +using ::strcmp; +using ::strncmp; +using ::strcoll; +using ::strxfrm; +using ::memchr; +using ::strchr; +using ::strcspn; +using ::strpbrk; +using ::strrchr; +using ::strspn; +using ::strstr; +#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +using ::strtok; +#endif +using ::memset; +using ::strerror; +using ::strlen; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTRING diff --git a/android/x86/include/v8/libc++/ctgmath b/android/x86/include/v8/libc++/ctgmath new file mode 100755 index 00000000..ba1eeeac --- /dev/null +++ b/android/x86/include/v8/libc++/ctgmath @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===-------------------------- ctgmath -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CTGMATH +#define _LIBCPP_CTGMATH + +/* + ctgmath synopsis + +#include <ccomplex> +#include <cmath> + +*/ + +#include <ccomplex> +#include <cmath> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#endif // _LIBCPP_CTGMATH diff --git a/android/x86/include/v8/libc++/ctime b/android/x86/include/v8/libc++/ctime new file mode 100755 index 00000000..cb8474f8 --- /dev/null +++ b/android/x86/include/v8/libc++/ctime @@ -0,0 +1,81 @@ +// -*- C++ -*- +//===---------------------------- ctime -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CTIME +#define _LIBCPP_CTIME + +/* + ctime synopsis + +Macros: + + NULL + CLOCKS_PER_SEC + TIME_UTC // C++17 + +namespace std +{ + +Types: + + clock_t + size_t + time_t + tm + timespec // C++17 + +clock_t clock(); +double difftime(time_t time1, time_t time0); +time_t mktime(tm* timeptr); +time_t time(time_t* timer); +char* asctime(const tm* timeptr); +char* ctime(const time_t* timer); +tm* gmtime(const time_t* timer); +tm* localtime(const time_t* timer); +size_t strftime(char* restrict s, size_t maxsize, const char* restrict format, + const tm* restrict timeptr); +int timespec_get( struct timespec *ts, int base); // C++17 +} // std + +*/ + +#include <__config> +#include <time.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::clock_t; +using ::size_t; +using ::time_t; +using ::tm; +#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_C11_FEATURES) +using ::timespec; +#endif +using ::clock; +using ::difftime; +using ::mktime; +using ::time; +#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +using ::asctime; +using ::ctime; +using ::gmtime; +using ::localtime; +#endif +using ::strftime; +#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) +using ::timespec_get; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CTIME diff --git a/android/x86/include/v8/libc++/ctype.h b/android/x86/include/v8/libc++/ctype.h new file mode 100755 index 00000000..dcc7935a --- /dev/null +++ b/android/x86/include/v8/libc++/ctype.h @@ -0,0 +1,59 @@ +// -*- C++ -*- +//===---------------------------- ctype.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CTYPE_H +#define _LIBCPP_CTYPE_H + +/* + ctype.h synopsis + +int isalnum(int c); +int isalpha(int c); +int isblank(int c); // C99 +int iscntrl(int c); +int isdigit(int c); +int isgraph(int c); +int islower(int c); +int isprint(int c); +int ispunct(int c); +int isspace(int c); +int isupper(int c); +int isxdigit(int c); +int tolower(int c); +int toupper(int c); +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <ctype.h> + +#ifdef __cplusplus + +#undef isalnum +#undef isalpha +#undef isblank +#undef iscntrl +#undef isdigit +#undef isgraph +#undef islower +#undef isprint +#undef ispunct +#undef isspace +#undef isupper +#undef isxdigit +#undef tolower +#undef toupper + +#endif + +#endif // _LIBCPP_CTYPE_H diff --git a/android/x86/include/v8/libc++/cwchar b/android/x86/include/v8/libc++/cwchar new file mode 100755 index 00000000..451c621f --- /dev/null +++ b/android/x86/include/v8/libc++/cwchar @@ -0,0 +1,192 @@ +// -*- C++ -*- +//===--------------------------- cwchar -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CWCHAR +#define _LIBCPP_CWCHAR + +/* + cwchar synopsis + +Macros: + + NULL + WCHAR_MAX + WCHAR_MIN + WEOF + +namespace std +{ + +Types: + + mbstate_t + size_t + tm + wint_t + +int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...); +int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...); +int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, ...); +int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...); +int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); +int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); // C99 +int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, va_list arg); +int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, va_list arg); // C99 +int vwprintf(const wchar_t* restrict format, va_list arg); +int vwscanf(const wchar_t* restrict format, va_list arg); // C99 +int wprintf(const wchar_t* restrict format, ...); +int wscanf(const wchar_t* restrict format, ...); +wint_t fgetwc(FILE* stream); +wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream); +wint_t fputwc(wchar_t c, FILE* stream); +int fputws(const wchar_t* restrict s, FILE* restrict stream); +int fwide(FILE* stream, int mode); +wint_t getwc(FILE* stream); +wint_t getwchar(); +wint_t putwc(wchar_t c, FILE* stream); +wint_t putwchar(wchar_t c); +wint_t ungetwc(wint_t c, FILE* stream); +double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr); +float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99 +long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99 +long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); +long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99 +unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); +unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99 +wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2); +wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +wchar_t* wcscat(wchar_t* restrict s1, const wchar_t* restrict s2); +wchar_t* wcsncat(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +int wcscmp(const wchar_t* s1, const wchar_t* s2); +int wcscoll(const wchar_t* s1, const wchar_t* s2); +int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n); +size_t wcsxfrm(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +const wchar_t* wcschr(const wchar_t* s, wchar_t c); + wchar_t* wcschr( wchar_t* s, wchar_t c); +size_t wcscspn(const wchar_t* s1, const wchar_t* s2); +size_t wcslen(const wchar_t* s); +const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2); + wchar_t* wcspbrk( wchar_t* s1, const wchar_t* s2); +const wchar_t* wcsrchr(const wchar_t* s, wchar_t c); + wchar_t* wcsrchr( wchar_t* s, wchar_t c); +size_t wcsspn(const wchar_t* s1, const wchar_t* s2); +const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2); + wchar_t* wcsstr( wchar_t* s1, const wchar_t* s2); +wchar_t* wcstok(wchar_t* restrict s1, const wchar_t* restrict s2, wchar_t** restrict ptr); +const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n); + wchar_t* wmemchr( wchar_t* s, wchar_t c, size_t n); +int wmemcmp(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +wchar_t* wmemcpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n); +wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n); +size_t wcsftime(wchar_t* restrict s, size_t maxsize, const wchar_t* restrict format, + const tm* restrict timeptr); +wint_t btowc(int c); +int wctob(wint_t c); +int mbsinit(const mbstate_t* ps); +size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps); +size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, mbstate_t* restrict ps); +size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps); +size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src, size_t len, + mbstate_t* restrict ps); +size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, + mbstate_t* restrict ps); + +} // std + +*/ + +#include <__config> +#include <cwctype> +#include <wchar.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::mbstate_t; +using ::size_t; +using ::tm; +using ::wint_t; +using ::FILE; +using ::fwprintf; +using ::fwscanf; +using ::swprintf; +using ::vfwprintf; +using ::vswprintf; +using ::swscanf; +using ::vfwscanf; +using ::vswscanf; +using ::fgetwc; +using ::fgetws; +using ::fputwc; +using ::fputws; +using ::fwide; +using ::getwc; +using ::putwc; +using ::ungetwc; +using ::wcstod; +using ::wcstof; +using ::wcstold; +using ::wcstol; +#ifndef _LIBCPP_HAS_NO_LONG_LONG +using ::wcstoll; +#endif // _LIBCPP_HAS_NO_LONG_LONG +using ::wcstoul; +#ifndef _LIBCPP_HAS_NO_LONG_LONG +using ::wcstoull; +#endif // _LIBCPP_HAS_NO_LONG_LONG +using ::wcscpy; +using ::wcsncpy; +using ::wcscat; +using ::wcsncat; +using ::wcscmp; +using ::wcscoll; +using ::wcsncmp; +using ::wcsxfrm; +using ::wcschr; +using ::wcspbrk; +using ::wcsrchr; +using ::wcsstr; +using ::wmemchr; +using ::wcscspn; +using ::wcslen; +using ::wcsspn; +using ::wcstok; +using ::wmemcmp; +using ::wmemcpy; +using ::wmemmove; +using ::wmemset; +using ::wcsftime; +using ::btowc; +using ::wctob; +using ::mbsinit; +using ::mbrlen; +using ::mbrtowc; +using ::wcrtomb; +using ::mbsrtowcs; +using ::wcsrtombs; + +#ifndef _LIBCPP_HAS_NO_STDIN +using ::getwchar; +using ::vwscanf; +using ::wscanf; +#endif + +#ifndef _LIBCPP_HAS_NO_STDOUT +using ::putwchar; +using ::vwprintf; +using ::wprintf; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CWCHAR diff --git a/android/x86/include/v8/libc++/cwctype b/android/x86/include/v8/libc++/cwctype new file mode 100755 index 00000000..575fd566 --- /dev/null +++ b/android/x86/include/v8/libc++/cwctype @@ -0,0 +1,86 @@ +// -*- C++ -*- +//===--------------------------- cwctype ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CWCTYPE +#define _LIBCPP_CWCTYPE + +/* + cwctype synopsis + +Macros: + + WEOF + +namespace std +{ + +Types: + + wint_t + wctrans_t + wctype_t + +int iswalnum(wint_t wc); +int iswalpha(wint_t wc); +int iswblank(wint_t wc); // C99 +int iswcntrl(wint_t wc); +int iswdigit(wint_t wc); +int iswgraph(wint_t wc); +int iswlower(wint_t wc); +int iswprint(wint_t wc); +int iswpunct(wint_t wc); +int iswspace(wint_t wc); +int iswupper(wint_t wc); +int iswxdigit(wint_t wc); +int iswctype(wint_t wc, wctype_t desc); +wctype_t wctype(const char* property); +wint_t towlower(wint_t wc); +wint_t towupper(wint_t wc); +wint_t towctrans(wint_t wc, wctrans_t desc); +wctrans_t wctrans(const char* property); + +} // std + +*/ + +#include <__config> +#include <cctype> +#include <wctype.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::wint_t; +using ::wctrans_t; +using ::wctype_t; +using ::iswalnum; +using ::iswalpha; +using ::iswblank; +using ::iswcntrl; +using ::iswdigit; +using ::iswgraph; +using ::iswlower; +using ::iswprint; +using ::iswpunct; +using ::iswspace; +using ::iswupper; +using ::iswxdigit; +using ::iswctype; +using ::wctype; +using ::towlower; +using ::towupper; +using ::towctrans; +using ::wctrans; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CWCTYPE diff --git a/android/x86/include/v8/libc++/deque b/android/x86/include/v8/libc++/deque new file mode 100755 index 00000000..d3ccf2ef --- /dev/null +++ b/android/x86/include/v8/libc++/deque @@ -0,0 +1,2952 @@ +// -*- C++ -*- +//===---------------------------- deque -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_DEQUE +#define _LIBCPP_DEQUE + +/* + deque synopsis + +namespace std +{ + +template <class T, class Allocator = allocator<T> > +class deque +{ +public: + // types: + typedef T value_type; + typedef Allocator allocator_type; + + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + // construct/copy/destroy: + deque() noexcept(is_nothrow_default_constructible<allocator_type>::value); + explicit deque(const allocator_type& a); + explicit deque(size_type n); + explicit deque(size_type n, const allocator_type& a); // C++14 + deque(size_type n, const value_type& v); + deque(size_type n, const value_type& v, const allocator_type& a); + template <class InputIterator> + deque(InputIterator f, InputIterator l); + template <class InputIterator> + deque(InputIterator f, InputIterator l, const allocator_type& a); + deque(const deque& c); + deque(deque&& c) + noexcept(is_nothrow_move_constructible<allocator_type>::value); + deque(initializer_list<value_type> il, const Allocator& a = allocator_type()); + deque(const deque& c, const allocator_type& a); + deque(deque&& c, const allocator_type& a); + ~deque(); + + deque& operator=(const deque& c); + deque& operator=(deque&& c) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value); + deque& operator=(initializer_list<value_type> il); + + template <class InputIterator> + void assign(InputIterator f, InputIterator l); + void assign(size_type n, const value_type& v); + void assign(initializer_list<value_type> il); + + allocator_type get_allocator() const noexcept; + + // iterators: + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + size_type size() const noexcept; + size_type max_size() const noexcept; + void resize(size_type n); + void resize(size_type n, const value_type& v); + void shrink_to_fit(); + bool empty() const noexcept; + + // element access: + reference operator[](size_type i); + const_reference operator[](size_type i) const; + reference at(size_type i); + const_reference at(size_type i) const; + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + // modifiers: + void push_front(const value_type& v); + void push_front(value_type&& v); + void push_back(const value_type& v); + void push_back(value_type&& v); + template <class... Args> reference emplace_front(Args&&... args); // reference in C++17 + template <class... Args> reference emplace_back(Args&&... args); // reference in C++17 + template <class... Args> iterator emplace(const_iterator p, Args&&... args); + iterator insert(const_iterator p, const value_type& v); + iterator insert(const_iterator p, value_type&& v); + iterator insert(const_iterator p, size_type n, const value_type& v); + template <class InputIterator> + iterator insert(const_iterator p, InputIterator f, InputIterator l); + iterator insert(const_iterator p, initializer_list<value_type> il); + void pop_front(); + void pop_back(); + iterator erase(const_iterator p); + iterator erase(const_iterator f, const_iterator l); + void swap(deque& c) + noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17 + void clear() noexcept; +}; + +template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> + deque(InputIterator, InputIterator, Allocator = Allocator()) + -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; + +template <class T, class Allocator> + bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); +template <class T, class Allocator> + bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); +template <class T, class Allocator> + bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); +template <class T, class Allocator> + bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); +template <class T, class Allocator> + bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); +template <class T, class Allocator> + bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); + +// specialized algorithms: +template <class T, class Allocator> + void swap(deque<T,Allocator>& x, deque<T,Allocator>& y) + noexcept(noexcept(x.swap(y))); + +template <class T, class Allocator, class U> + void erase(deque<T, Allocator>& c, const U& value); // C++20 +template <class T, class Allocator, class Predicate> + void erase_if(deque<T, Allocator>& c, Predicate pred); // C++20 + +} // std + +*/ + +#include <__config> +#include <__split_buffer> +#include <type_traits> +#include <initializer_list> +#include <iterator> +#include <algorithm> +#include <stdexcept> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp, class _Allocator> class __deque_base; +template <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS deque; + +template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, + class _DiffType, _DiffType _BlockSize> +class _LIBCPP_TEMPLATE_VIS __deque_iterator; + +template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> +_OutputIterator +copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + +template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> +_OutputIterator +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + +template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> +_OutputIterator +move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + +template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> +_OutputIterator +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + +template <class _ValueType, class _DiffType> +struct __deque_block_size { + static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16; +}; + +template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, + class _DiffType, _DiffType _BS = +#ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE +// Keep template parameter to avoid changing all template declarations thoughout +// this file. + 0 +#else + __deque_block_size<_ValueType, _DiffType>::value +#endif + > +class _LIBCPP_TEMPLATE_VIS __deque_iterator +{ + typedef _MapPointer __map_iterator; +public: + typedef _Pointer pointer; + typedef _DiffType difference_type; +private: + __map_iterator __m_iter_; + pointer __ptr_; + + static const difference_type __block_size; +public: + typedef _ValueType value_type; + typedef random_access_iterator_tag iterator_category; + typedef _Reference reference; + + _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __m_iter_(nullptr), __ptr_(nullptr) +#endif + {} + + template <class _Pp, class _Rp, class _MP> + _LIBCPP_INLINE_VISIBILITY + __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it, + typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT + : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;} + + _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++() + { + if (++__ptr_ - *__m_iter_ == __block_size) + { + ++__m_iter_; + __ptr_ = *__m_iter_; + } + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int) + { + __deque_iterator __tmp = *this; + ++(*this); + return __tmp; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--() + { + if (__ptr_ == *__m_iter_) + { + --__m_iter_; + __ptr_ = *__m_iter_ + __block_size; + } + --__ptr_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int) + { + __deque_iterator __tmp = *this; + --(*this); + return __tmp; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n) + { + if (__n != 0) + { + __n += __ptr_ - *__m_iter_; + if (__n > 0) + { + __m_iter_ += __n / __block_size; + __ptr_ = *__m_iter_ + __n % __block_size; + } + else // (__n < 0) + { + difference_type __z = __block_size - 1 - __n; + __m_iter_ -= __z / __block_size; + __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size); + } + } + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n) + { + return *this += -__n; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const + { + __deque_iterator __t(*this); + __t += __n; + return __t; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const + { + __deque_iterator __t(*this); + __t -= __n; + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) + {return __it + __n;} + + _LIBCPP_INLINE_VISIBILITY + friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) + { + if (__x != __y) + return (__x.__m_iter_ - __y.__m_iter_) * __block_size + + (__x.__ptr_ - *__x.__m_iter_) + - (__y.__ptr_ - *__y.__m_iter_); + return 0; + } + + _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const + {return *(*this + __n);} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) + {return !(__x == __y);} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) + {return __x.__m_iter_ < __y.__m_iter_ || + (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) + {return __y < __x;} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) + {return !(__y < __x);} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) + {return !(__x < __y);} + +private: + _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT + : __m_iter_(__m), __ptr_(__p) {} + + template <class _Tp, class _Ap> friend class __deque_base; + template <class _Tp, class _Ap> friend class _LIBCPP_TEMPLATE_VIS deque; + template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp> + friend class _LIBCPP_TEMPLATE_VIS __deque_iterator; + + template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + copy(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); + + template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> + friend + _OutputIterator + copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + + template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + + template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + copy_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); + + template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> + friend + _OutputIterator + copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + + template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + + template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + move(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); + + template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> + friend + _OutputIterator + move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + + template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + + template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + move_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); + + template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> + friend + _OutputIterator + move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + + template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); +}; + +template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, + class _DiffType, _DiffType _BlockSize> +const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, + _DiffType, _BlockSize>::__block_size = + __deque_block_size<_ValueType, _DiffType>::value; + +// copy + +template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; + while (__f != __l) + { + pointer __rb = __r.__ptr_; + pointer __re = *__r.__m_iter_ + __block_size; + difference_type __bs = __re - __rb; + difference_type __n = __l - __f; + _RAIter __m = __l; + if (__n > __bs) + { + __n = __bs; + __m = __f + __n; + } + _VSTD::copy(__f, __m, __rb); + __f = __m; + __r += __n; + } + return __r; +} + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> +_OutputIterator +copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + __block_size; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + __r = _VSTD::copy(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + __block_size; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + __r = _VSTD::copy(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +// copy_backward + +template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + while (__f != __l) + { + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); + pointer __rb = *__rp.__m_iter_; + pointer __re = __rp.__ptr_ + 1; + difference_type __bs = __re - __rb; + difference_type __n = __l - __f; + _RAIter __m = __f; + if (__n > __bs) + { + __n = __bs; + __m = __l - __n; + } + _VSTD::copy_backward(__m, __l, __re); + __l = __m; + __r -= __n; + } + return __r; +} + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> +_OutputIterator +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + __r = _VSTD::copy_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + __r = _VSTD::copy_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +// move + +template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; + while (__f != __l) + { + pointer __rb = __r.__ptr_; + pointer __re = *__r.__m_iter_ + __block_size; + difference_type __bs = __re - __rb; + difference_type __n = __l - __f; + _RAIter __m = __l; + if (__n > __bs) + { + __n = __bs; + __m = __f + __n; + } + _VSTD::move(__f, __m, __rb); + __f = __m; + __r += __n; + } + return __r; +} + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> +_OutputIterator +move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + __block_size; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + __r = _VSTD::move(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + __block_size; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + __r = _VSTD::move(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +// move_backward + +template <class _RAIter, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + while (__f != __l) + { + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); + pointer __rb = *__rp.__m_iter_; + pointer __re = __rp.__ptr_ + 1; + difference_type __bs = __re - __rb; + difference_type __n = __l - __f; + _RAIter __m = __f; + if (__n > __bs) + { + __n = __bs; + __m = __l - __n; + } + _VSTD::move_backward(__m, __l, __re); + __l = __m; + __r -= __n; + } + return __r; +} + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _OutputIterator> +_OutputIterator +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + __r = _VSTD::move_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, + class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + __r = _VSTD::move_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +template <bool> +class __deque_base_common +{ +protected: + _LIBCPP_NORETURN void __throw_length_error() const; + _LIBCPP_NORETURN void __throw_out_of_range() const; +}; + +template <bool __b> +void +__deque_base_common<__b>::__throw_length_error() const +{ + _VSTD::__throw_length_error("deque"); +} + +template <bool __b> +void +__deque_base_common<__b>::__throw_out_of_range() const +{ + _VSTD::__throw_out_of_range("deque"); +} + +template <class _Tp, class _Allocator> +class __deque_base + : protected __deque_base_common<true> +{ + __deque_base(const __deque_base& __c); + __deque_base& operator=(const __deque_base& __c); +public: + typedef _Allocator allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __alloc_traits::size_type size_type; +protected: + typedef _Tp value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::difference_type difference_type; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + + static const difference_type __block_size; + + typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator; + typedef allocator_traits<__pointer_allocator> __map_traits; + typedef typename __map_traits::pointer __map_pointer; + typedef typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type __const_pointer_allocator; + typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer; + typedef __split_buffer<pointer, __pointer_allocator> __map; + + typedef __deque_iterator<value_type, pointer, reference, __map_pointer, + difference_type> iterator; + typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, + difference_type> const_iterator; + +protected: + __map __map_; + size_type __start_; + __compressed_pair<size_type, allocator_type> __size_; + + iterator begin() _NOEXCEPT; + const_iterator begin() const _NOEXCEPT; + iterator end() _NOEXCEPT; + const_iterator end() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();} + _LIBCPP_INLINE_VISIBILITY + const size_type& size() const _NOEXCEPT {return __size_.first();} + _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();} + _LIBCPP_INLINE_VISIBILITY + const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} + + _LIBCPP_INLINE_VISIBILITY + __deque_base() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY + explicit __deque_base(const allocator_type& __a); +public: + ~__deque_base(); + +#ifndef _LIBCPP_CXX03_LANG + __deque_base(__deque_base&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); + __deque_base(__deque_base&& __c, const allocator_type& __a); +#endif // _LIBCPP_CXX03_LANG + + void swap(__deque_base& __c) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT; +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value); +#endif +protected: + void clear() _NOEXCEPT; + + bool __invariants() const; + + _LIBCPP_INLINE_VISIBILITY + void __move_assign(__deque_base& __c) + _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value) + { + __map_ = _VSTD::move(__c.__map_); + __start_ = __c.__start_; + size() = __c.size(); + __move_assign_alloc(__c); + __c.__start_ = __c.size() = 0; + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__deque_base& __c) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<allocator_type>::value) + {__move_assign_alloc(__c, integral_constant<bool, + __alloc_traits::propagate_on_container_move_assignment::value>());} + +private: + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__deque_base& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) + { + __alloc() = _VSTD::move(__c.__alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT + {} +}; + +template <class _Tp, class _Allocator> +const typename __deque_base<_Tp, _Allocator>::difference_type + __deque_base<_Tp, _Allocator>::__block_size = + __deque_block_size<value_type, difference_type>::value; + +template <class _Tp, class _Allocator> +bool +__deque_base<_Tp, _Allocator>::__invariants() const +{ + if (!__map_.__invariants()) + return false; + if (__map_.size() >= size_type(-1) / __block_size) + return false; + for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end(); + __i != __e; ++__i) + if (*__i == nullptr) + return false; + if (__map_.size() != 0) + { + if (size() >= __map_.size() * __block_size) + return false; + if (__start_ >= __map_.size() * __block_size - size()) + return false; + } + else + { + if (size() != 0) + return false; + if (__start_ != 0) + return false; + } + return true; +} + +template <class _Tp, class _Allocator> +typename __deque_base<_Tp, _Allocator>::iterator +__deque_base<_Tp, _Allocator>::begin() _NOEXCEPT +{ + __map_pointer __mp = __map_.begin() + __start_ / __block_size; + return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); +} + +template <class _Tp, class _Allocator> +typename __deque_base<_Tp, _Allocator>::const_iterator +__deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT +{ + __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size); + return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); +} + +template <class _Tp, class _Allocator> +typename __deque_base<_Tp, _Allocator>::iterator +__deque_base<_Tp, _Allocator>::end() _NOEXCEPT +{ + size_type __p = size() + __start_; + __map_pointer __mp = __map_.begin() + __p / __block_size; + return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); +} + +template <class _Tp, class _Allocator> +typename __deque_base<_Tp, _Allocator>::const_iterator +__deque_base<_Tp, _Allocator>::end() const _NOEXCEPT +{ + size_type __p = size() + __start_; + __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size); + return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); +} + +template <class _Tp, class _Allocator> +inline +__deque_base<_Tp, _Allocator>::__deque_base() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + : __start_(0), __size_(0) {} + +template <class _Tp, class _Allocator> +inline +__deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) + : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} + +template <class _Tp, class _Allocator> +__deque_base<_Tp, _Allocator>::~__deque_base() +{ + clear(); + typename __map::iterator __i = __map_.begin(); + typename __map::iterator __e = __map_.end(); + for (; __i != __e; ++__i) + __alloc_traits::deallocate(__alloc(), *__i, __block_size); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) + : __map_(_VSTD::move(__c.__map_)), + __start_(_VSTD::move(__c.__start_)), + __size_(_VSTD::move(__c.__size_)) +{ + __c.__start_ = 0; + __c.size() = 0; +} + +template <class _Tp, class _Allocator> +__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a) + : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)), + __start_(_VSTD::move(__c.__start_)), + __size_(_VSTD::move(__c.size()), __a) +{ + if (__a == __c.__alloc()) + { + __c.__start_ = 0; + __c.size() = 0; + } + else + { + __map_.clear(); + __start_ = 0; + size() = 0; + } +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +void +__deque_base<_Tp, _Allocator>::swap(__deque_base& __c) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value) +#endif +{ + __map_.swap(__c.__map_); + _VSTD::swap(__start_, __c.__start_); + _VSTD::swap(size(), __c.size()); + __swap_allocator(__alloc(), __c.__alloc()); +} + +template <class _Tp, class _Allocator> +void +__deque_base<_Tp, _Allocator>::clear() _NOEXCEPT +{ + allocator_type& __a = __alloc(); + for (iterator __i = begin(), __e = end(); __i != __e; ++__i) + __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); + size() = 0; + while (__map_.size() > 2) + { + __alloc_traits::deallocate(__a, __map_.front(), __block_size); + __map_.pop_front(); + } + switch (__map_.size()) + { + case 1: + __start_ = __block_size / 2; + break; + case 2: + __start_ = __block_size; + break; + } +} + +template <class _Tp, class _Allocator /*= allocator<_Tp>*/> +class _LIBCPP_TEMPLATE_VIS deque + : private __deque_base<_Tp, _Allocator> +{ +public: + // types: + + typedef _Tp value_type; + typedef _Allocator allocator_type; + + static_assert((is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + + typedef __deque_base<value_type, allocator_type> __base; + + typedef typename __base::__alloc_traits __alloc_traits; + typedef typename __base::reference reference; + typedef typename __base::const_reference const_reference; + typedef typename __base::iterator iterator; + typedef typename __base::const_iterator const_iterator; + typedef typename __base::size_type size_type; + typedef typename __base::difference_type difference_type; + + typedef typename __base::pointer pointer; + typedef typename __base::const_pointer const_pointer; + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + + // construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY + deque() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + {} + _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {} + explicit deque(size_type __n); +#if _LIBCPP_STD_VER > 11 + explicit deque(size_type __n, const _Allocator& __a); +#endif + deque(size_type __n, const value_type& __v); + deque(size_type __n, const value_type& __v, const allocator_type& __a); + template <class _InputIter> + deque(_InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); + template <class _InputIter> + deque(_InputIter __f, _InputIter __l, const allocator_type& __a, + typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); + deque(const deque& __c); + deque(const deque& __c, const allocator_type& __a); + + deque& operator=(const deque& __c); + +#ifndef _LIBCPP_CXX03_LANG + deque(initializer_list<value_type> __il); + deque(initializer_list<value_type> __il, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;} + + _LIBCPP_INLINE_VISIBILITY + deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); + _LIBCPP_INLINE_VISIBILITY + deque(deque&& __c, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + deque& operator=(deque&& __c) + _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value); + + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + + template <class _InputIter> + void assign(_InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value && + !__is_random_access_iterator<_InputIter>::value>::type* = 0); + template <class _RAIter> + void assign(_RAIter __f, _RAIter __l, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + void assign(size_type __n, const value_type& __v); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT; + + // iterators: + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __base::begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __base::begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __base::end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __base::end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(__base::end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(__base::end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(__base::begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(__base::begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT + {return __base::begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT + {return __base::end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT + {return const_reverse_iterator(__base::end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT + {return const_reverse_iterator(__base::begin());} + + // capacity: + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __base::size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + {return std::min<size_type>( + __alloc_traits::max_size(__base::__alloc()), + numeric_limits<difference_type>::max());} + void resize(size_type __n); + void resize(size_type __n, const value_type& __v); + void shrink_to_fit() _NOEXCEPT; + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __base::size() == 0;} + + // element access: + _LIBCPP_INLINE_VISIBILITY + reference operator[](size_type __i) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + const_reference operator[](size_type __i) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + reference at(size_type __i); + _LIBCPP_INLINE_VISIBILITY + const_reference at(size_type __i) const; + _LIBCPP_INLINE_VISIBILITY + reference front() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + const_reference front() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + reference back() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + const_reference back() const _NOEXCEPT; + + // 23.2.2.3 modifiers: + void push_front(const value_type& __v); + void push_back(const value_type& __v); +#ifndef _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 14 + template <class... _Args> reference emplace_front(_Args&&... __args); + template <class... _Args> reference emplace_back (_Args&&... __args); +#else + template <class... _Args> void emplace_front(_Args&&... __args); + template <class... _Args> void emplace_back (_Args&&... __args); +#endif + template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args); + + void push_front(value_type&& __v); + void push_back(value_type&& __v); + iterator insert(const_iterator __p, value_type&& __v); + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, initializer_list<value_type> __il) + {return insert(__p, __il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + iterator insert(const_iterator __p, const value_type& __v); + iterator insert(const_iterator __p, size_type __n, const value_type& __v); + template <class _InputIter> + iterator insert(const_iterator __p, _InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value + &&!__is_forward_iterator<_InputIter>::value>::type* = 0); + template <class _ForwardIterator> + iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value + &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type* = 0); + template <class _BiIter> + iterator insert(const_iterator __p, _BiIter __f, _BiIter __l, + typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0); + + void pop_front(); + void pop_back(); + iterator erase(const_iterator __p); + iterator erase(const_iterator __f, const_iterator __l); + + _LIBCPP_INLINE_VISIBILITY + void swap(deque& __c) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT; +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value); +#endif + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + bool __invariants() const {return __base::__invariants();} +private: + typedef typename __base::__map_const_pointer __map_const_pointer; + + _LIBCPP_INLINE_VISIBILITY + static size_type __recommend_blocks(size_type __n) + { + return __n / __base::__block_size + (__n % __base::__block_size != 0); + } + _LIBCPP_INLINE_VISIBILITY + size_type __capacity() const + { + return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1; + } + _LIBCPP_INLINE_VISIBILITY + size_type __front_spare() const + { + return __base::__start_; + } + _LIBCPP_INLINE_VISIBILITY + size_type __back_spare() const + { + return __capacity() - (__base::__start_ + __base::size()); + } + + template <class _InpIter> + void __append(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value && + !__is_forward_iterator<_InpIter>::value>::type* = 0); + template <class _ForIter> + void __append(_ForIter __f, _ForIter __l, + typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0); + void __append(size_type __n); + void __append(size_type __n, const value_type& __v); + void __erase_to_end(const_iterator __f); + void __add_front_capacity(); + void __add_front_capacity(size_type __n); + void __add_back_capacity(); + void __add_back_capacity(size_type __n); + iterator __move_and_check(iterator __f, iterator __l, iterator __r, + const_pointer& __vt); + iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r, + const_pointer& __vt); + void __move_construct_and_check(iterator __f, iterator __l, + iterator __r, const_pointer& __vt); + void __move_construct_backward_and_check(iterator __f, iterator __l, + iterator __r, const_pointer& __vt); + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const deque& __c) + {__copy_assign_alloc(__c, integral_constant<bool, + __alloc_traits::propagate_on_container_copy_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const deque& __c, true_type) + { + if (__base::__alloc() != __c.__alloc()) + { + clear(); + shrink_to_fit(); + } + __base::__alloc() = __c.__alloc(); + __base::__map_.__alloc() = __c.__map_.__alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const deque&, false_type) + {} + + void __move_assign(deque& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); + void __move_assign(deque& __c, false_type); +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +deque(_InputIterator, _InputIterator) + -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>; + +template<class _InputIterator, + class _Alloc, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +deque(_InputIterator, _InputIterator, _Alloc) + -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>; +#endif + + +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>::deque(size_type __n) +{ + if (__n > 0) + __append(__n); +} + +#if _LIBCPP_STD_VER > 11 +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) + : __base(__a) +{ + if (__n > 0) + __append(__n); +} +#endif + +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) +{ + if (__n > 0) + __append(__n, __v); +} + +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a) + : __base(__a) +{ + if (__n > 0) + __append(__n, __v); +} + +template <class _Tp, class _Allocator> +template <class _InputIter> +deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value>::type*) +{ + __append(__f, __l); +} + +template <class _Tp, class _Allocator> +template <class _InputIter> +deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a, + typename enable_if<__is_input_iterator<_InputIter>::value>::type*) + : __base(__a) +{ + __append(__f, __l); +} + +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>::deque(const deque& __c) + : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc())) +{ + __append(__c.begin(), __c.end()); +} + +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a) + : __base(__a) +{ + __append(__c.begin(), __c.end()); +} + +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>& +deque<_Tp, _Allocator>::operator=(const deque& __c) +{ + if (this != &__c) + { + __copy_assign_alloc(__c); + assign(__c.begin(), __c.end()); + } + return *this; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) +{ + __append(__il.begin(), __il.end()); +} + +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a) + : __base(__a) +{ + __append(__il.begin(), __il.end()); +} + +template <class _Tp, class _Allocator> +inline +deque<_Tp, _Allocator>::deque(deque&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) + : __base(_VSTD::move(__c)) +{ +} + +template <class _Tp, class _Allocator> +inline +deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) + : __base(_VSTD::move(__c), __a) +{ + if (__a != __c.__alloc()) + { + typedef move_iterator<iterator> _Ip; + assign(_Ip(__c.begin()), _Ip(__c.end())); + } +} + +template <class _Tp, class _Allocator> +inline +deque<_Tp, _Allocator>& +deque<_Tp, _Allocator>::operator=(deque&& __c) + _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value) +{ + __move_assign(__c, integral_constant<bool, + __alloc_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) +{ + if (__base::__alloc() != __c.__alloc()) + { + typedef move_iterator<iterator> _Ip; + assign(_Ip(__c.begin()), _Ip(__c.end())); + } + else + __move_assign(__c, true_type()); +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) +{ + clear(); + shrink_to_fit(); + __base::__move_assign(__c); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +template <class _InputIter> +void +deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value && + !__is_random_access_iterator<_InputIter>::value>::type*) +{ + iterator __i = __base::begin(); + iterator __e = __base::end(); + for (; __f != __l && __i != __e; ++__f, (void) ++__i) + *__i = *__f; + if (__f != __l) + __append(__f, __l); + else + __erase_to_end(__i); +} + +template <class _Tp, class _Allocator> +template <class _RAIter> +void +deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + if (static_cast<size_type>(__l - __f) > __base::size()) + { + _RAIter __m = __f + __base::size(); + _VSTD::copy(__f, __m, __base::begin()); + __append(__m, __l); + } + else + __erase_to_end(_VSTD::copy(__f, __l, __base::begin())); +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) +{ + if (__n > __base::size()) + { + _VSTD::fill_n(__base::begin(), __base::size(), __v); + __n -= __base::size(); + __append(__n, __v); + } + else + __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v)); +} + +template <class _Tp, class _Allocator> +inline +_Allocator +deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT +{ + return __base::__alloc(); +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::resize(size_type __n) +{ + if (__n > __base::size()) + __append(__n - __base::size()); + else if (__n < __base::size()) + __erase_to_end(__base::begin() + __n); +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) +{ + if (__n > __base::size()) + __append(__n - __base::size(), __v); + else if (__n < __base::size()) + __erase_to_end(__base::begin() + __n); +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT +{ + allocator_type& __a = __base::__alloc(); + if (empty()) + { + while (__base::__map_.size() > 0) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + __base::__start_ = 0; + } + else + { + if (__front_spare() >= __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); + __base::__map_.pop_front(); + __base::__start_ -= __base::__block_size; + } + if (__back_spare() >= __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + } + __base::__map_.shrink_to_fit(); +} + +template <class _Tp, class _Allocator> +inline +typename deque<_Tp, _Allocator>::reference +deque<_Tp, _Allocator>::operator[](size_type __i) _NOEXCEPT +{ + size_type __p = __base::__start_ + __i; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template <class _Tp, class _Allocator> +inline +typename deque<_Tp, _Allocator>::const_reference +deque<_Tp, _Allocator>::operator[](size_type __i) const _NOEXCEPT +{ + size_type __p = __base::__start_ + __i; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template <class _Tp, class _Allocator> +inline +typename deque<_Tp, _Allocator>::reference +deque<_Tp, _Allocator>::at(size_type __i) +{ + if (__i >= __base::size()) + __base::__throw_out_of_range(); + size_type __p = __base::__start_ + __i; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template <class _Tp, class _Allocator> +inline +typename deque<_Tp, _Allocator>::const_reference +deque<_Tp, _Allocator>::at(size_type __i) const +{ + if (__i >= __base::size()) + __base::__throw_out_of_range(); + size_type __p = __base::__start_ + __i; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template <class _Tp, class _Allocator> +inline +typename deque<_Tp, _Allocator>::reference +deque<_Tp, _Allocator>::front() _NOEXCEPT +{ + return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) + + __base::__start_ % __base::__block_size); +} + +template <class _Tp, class _Allocator> +inline +typename deque<_Tp, _Allocator>::const_reference +deque<_Tp, _Allocator>::front() const _NOEXCEPT +{ + return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) + + __base::__start_ % __base::__block_size); +} + +template <class _Tp, class _Allocator> +inline +typename deque<_Tp, _Allocator>::reference +deque<_Tp, _Allocator>::back() _NOEXCEPT +{ + size_type __p = __base::size() + __base::__start_ - 1; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template <class _Tp, class _Allocator> +inline +typename deque<_Tp, _Allocator>::const_reference +deque<_Tp, _Allocator>::back() const _NOEXCEPT +{ + size_type __p = __base::size() + __base::__start_ - 1; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::push_back(const value_type& __v) +{ + allocator_type& __a = __base::__alloc(); + if (__back_spare() == 0) + __add_back_capacity(); + // __back_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); + ++__base::size(); +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::push_front(const value_type& __v) +{ + allocator_type& __a = __base::__alloc(); + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); + --__base::__start_; + ++__base::size(); +} + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::push_back(value_type&& __v) +{ + allocator_type& __a = __base::__alloc(); + if (__back_spare() == 0) + __add_back_capacity(); + // __back_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); + ++__base::size(); +} + +template <class _Tp, class _Allocator> +template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename deque<_Tp, _Allocator>::reference +#else +void +#endif +deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) +{ + allocator_type& __a = __base::__alloc(); + if (__back_spare() == 0) + __add_back_capacity(); + // __back_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), + _VSTD::forward<_Args>(__args)...); + ++__base::size(); +#if _LIBCPP_STD_VER > 14 + return *--__base::end(); +#endif +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::push_front(value_type&& __v) +{ + allocator_type& __a = __base::__alloc(); + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); + --__base::__start_; + ++__base::size(); +} + + +template <class _Tp, class _Allocator> +template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename deque<_Tp, _Allocator>::reference +#else +void +#endif +deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) +{ + allocator_type& __a = __base::__alloc(); + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); + --__base::__start_; + ++__base::size(); +#if _LIBCPP_STD_VER > 14 + return *__base::begin(); +#endif +} + +template <class _Tp, class _Allocator> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) +{ + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + if (__pos == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); + --__base::__start_; + ++__base::size(); + } + else + { + iterator __b = __base::begin(); + iterator __bm1 = _VSTD::prev(__b); + __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); + --__base::__start_; + ++__base::size(); + if (__pos > 1) + __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); + *__b = _VSTD::move(__v); + } + } + else + { // insert by shifting things forward + if (__back_spare() == 0) + __add_back_capacity(); + // __back_capacity >= 1 + size_type __de = __base::size() - __pos; + if (__de == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); + ++__base::size(); + } + else + { + iterator __e = __base::end(); + iterator __em1 = _VSTD::prev(__e); + __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); + ++__base::size(); + if (__de > 1) + __e = _VSTD::move_backward(__e - __de, __em1, __e); + *--__e = _VSTD::move(__v); + } + } + return __base::begin() + __pos; +} + +template <class _Tp, class _Allocator> +template <class... _Args> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) +{ + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + if (__pos == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); + --__base::__start_; + ++__base::size(); + } + else + { + __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); + iterator __b = __base::begin(); + iterator __bm1 = _VSTD::prev(__b); + __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); + --__base::__start_; + ++__base::size(); + if (__pos > 1) + __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); + *__b = _VSTD::move(__tmp.get()); + } + } + else + { // insert by shifting things forward + if (__back_spare() == 0) + __add_back_capacity(); + // __back_capacity >= 1 + size_type __de = __base::size() - __pos; + if (__de == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); + ++__base::size(); + } + else + { + __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); + iterator __e = __base::end(); + iterator __em1 = _VSTD::prev(__e); + __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); + ++__base::size(); + if (__de > 1) + __e = _VSTD::move_backward(__e - __de, __em1, __e); + *--__e = _VSTD::move(__tmp.get()); + } + } + return __base::begin() + __pos; +} + +#endif // _LIBCPP_CXX03_LANG + + +template <class _Tp, class _Allocator> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) +{ + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + if (__pos == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); + --__base::__start_; + ++__base::size(); + } + else + { + const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); + iterator __b = __base::begin(); + iterator __bm1 = _VSTD::prev(__b); + if (__vt == pointer_traits<const_pointer>::pointer_to(*__b)) + __vt = pointer_traits<const_pointer>::pointer_to(*__bm1); + __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); + --__base::__start_; + ++__base::size(); + if (__pos > 1) + __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); + *__b = *__vt; + } + } + else + { // insert by shifting things forward + if (__back_spare() == 0) + __add_back_capacity(); + // __back_capacity >= 1 + size_type __de = __base::size() - __pos; + if (__de == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); + ++__base::size(); + } + else + { + const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); + iterator __e = __base::end(); + iterator __em1 = _VSTD::prev(__e); + if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1)) + __vt = pointer_traits<const_pointer>::pointer_to(*__e); + __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); + ++__base::size(); + if (__de > 1) + __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); + *--__e = *__vt; + } + } + return __base::begin() + __pos; +} + +template <class _Tp, class _Allocator> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) +{ + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__n > __front_spare()) + __add_front_capacity(__n - __front_spare()); + // __n <= __front_spare() + iterator __old_begin = __base::begin(); + iterator __i = __old_begin; + if (__n > __pos) + { + for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v); + __n = __pos; + } + if (__n > 0) + { + const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); + iterator __obn = __old_begin + __n; + __move_construct_backward_and_check(__old_begin, __obn, __i, __vt); + if (__n < __pos) + __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt); + _VSTD::fill_n(__old_begin, __n, *__vt); + } + } + else + { // insert by shifting things forward + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + iterator __old_end = __base::end(); + iterator __i = __old_end; + size_type __de = __base::size() - __pos; + if (__n > __de) + { + for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); + __n = __de; + } + if (__n > 0) + { + const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); + iterator __oen = __old_end - __n; + __move_construct_and_check(__oen, __old_end, __i, __vt); + if (__n < __de) + __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt); + _VSTD::fill_n(__old_end - __n, __n, *__vt); + } + } + return __base::begin() + __pos; +} + +template <class _Tp, class _Allocator> +template <class _InputIter> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value + &&!__is_forward_iterator<_InputIter>::value>::type*) +{ + __split_buffer<value_type, allocator_type&> __buf(__base::__alloc()); + __buf.__construct_at_end(__f, __l); + typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi; + return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end())); +} + +template <class _Tp, class _Allocator> +template <class _ForwardIterator> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value + &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type*) +{ + size_type __n = _VSTD::distance(__f, __l); + __split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc()); + __buf.__construct_at_end(__f, __l); + typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd; + return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end())); +} + +template <class _Tp, class _Allocator> +template <class _BiIter> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, + typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*) +{ + size_type __n = _VSTD::distance(__f, __l); + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__n > __front_spare()) + __add_front_capacity(__n - __front_spare()); + // __n <= __front_spare() + iterator __old_begin = __base::begin(); + iterator __i = __old_begin; + _BiIter __m = __f; + if (__n > __pos) + { + __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos); + for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j); + __n = __pos; + } + if (__n > 0) + { + iterator __obn = __old_begin + __n; + for (iterator __j = __obn; __j != __old_begin;) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j)); + --__base::__start_; + ++__base::size(); + } + if (__n < __pos) + __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin); + _VSTD::copy(__m, __l, __old_begin); + } + } + else + { // insert by shifting things forward + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + iterator __old_end = __base::end(); + iterator __i = __old_end; + _BiIter __m = __l; + size_type __de = __base::size() - __pos; + if (__n > __de) + { + __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de); + for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j); + __n = __de; + } + if (__n > 0) + { + iterator __oen = __old_end - __n; + for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j)); + if (__n < __de) + __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end); + _VSTD::copy_backward(__f, __m, __old_end); + } + } + return __base::begin() + __pos; +} + +template <class _Tp, class _Allocator> +template <class _InpIter> +void +deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value && + !__is_forward_iterator<_InpIter>::value>::type*) +{ + for (; __f != __l; ++__f) +#ifdef _LIBCPP_CXX03_LANG + push_back(*__f); +#else + emplace_back(*__f); +#endif +} + +template <class _Tp, class _Allocator> +template <class _ForIter> +void +deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l, + typename enable_if<__is_forward_iterator<_ForIter>::value>::type*) +{ + size_type __n = _VSTD::distance(__f, __l); + allocator_type& __a = __base::__alloc(); + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + for (iterator __i = __base::end(); __f != __l; ++__i, (void) ++__f, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f); +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__append(size_type __n) +{ + allocator_type& __a = __base::__alloc(); + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i)); +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) +{ + allocator_type& __a = __base::__alloc(); + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); +} + +// Create front capacity for one block of elements. +// Strong guarantee. Either do it or don't touch anything. +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__add_front_capacity() +{ + allocator_type& __a = __base::__alloc(); + if (__back_spare() >= __base::__block_size) + { + __base::__start_ += __base::__block_size; + pointer __pt = __base::__map_.back(); + __base::__map_.pop_back(); + __base::__map_.push_front(__pt); + } + // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer + else if (__base::__map_.size() < __base::__map_.capacity()) + { // we can put the new buffer into the map, but don't shift things around + // until all buffers are allocated. If we throw, we don't need to fix + // anything up (any added buffers are undetectible) + if (__base::__map_.__front_spare() > 0) + __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); + else + { + __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); + // Done allocating, reorder capacity + pointer __pt = __base::__map_.back(); + __base::__map_.pop_back(); + __base::__map_.push_front(__pt); + } + __base::__start_ = __base::__map_.size() == 1 ? + __base::__block_size / 2 : + __base::__start_ + __base::__block_size; + } + // Else need to allocate 1 buffer, *and* we need to reallocate __map_. + else + { + __split_buffer<pointer, typename __base::__pointer_allocator&> + __buf(max<size_type>(2 * __base::__map_.capacity(), 1), + 0, __base::__map_.__alloc()); + + typedef __allocator_destructor<_Allocator> _Dp; + unique_ptr<pointer, _Dp> __hold( + __alloc_traits::allocate(__a, __base::__block_size), + _Dp(__a, __base::__block_size)); + __buf.push_back(__hold.get()); + __hold.release(); + + for (typename __base::__map_pointer __i = __base::__map_.begin(); + __i != __base::__map_.end(); ++__i) + __buf.push_back(*__i); + _VSTD::swap(__base::__map_.__first_, __buf.__first_); + _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); + _VSTD::swap(__base::__map_.__end_, __buf.__end_); + _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); + __base::__start_ = __base::__map_.size() == 1 ? + __base::__block_size / 2 : + __base::__start_ + __base::__block_size; + } +} + +// Create front capacity for __n elements. +// Strong guarantee. Either do it or don't touch anything. +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) +{ + allocator_type& __a = __base::__alloc(); + size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); + // Number of unused blocks at back: + size_type __back_capacity = __back_spare() / __base::__block_size; + __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need + __nb -= __back_capacity; // number of blocks need to allocate + // If __nb == 0, then we have sufficient capacity. + if (__nb == 0) + { + __base::__start_ += __base::__block_size * __back_capacity; + for (; __back_capacity > 0; --__back_capacity) + { + pointer __pt = __base::__map_.back(); + __base::__map_.pop_back(); + __base::__map_.push_front(__pt); + } + } + // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers + else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) + { // we can put the new buffers into the map, but don't shift things around + // until all buffers are allocated. If we throw, we don't need to fix + // anything up (any added buffers are undetectible) + for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1)) + { + if (__base::__map_.__front_spare() == 0) + break; + __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); + } + for (; __nb > 0; --__nb, ++__back_capacity) + __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); + // Done allocating, reorder capacity + __base::__start_ += __back_capacity * __base::__block_size; + for (; __back_capacity > 0; --__back_capacity) + { + pointer __pt = __base::__map_.back(); + __base::__map_.pop_back(); + __base::__map_.push_front(__pt); + } + } + // Else need to allocate __nb buffers, *and* we need to reallocate __map_. + else + { + size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty(); + __split_buffer<pointer, typename __base::__pointer_allocator&> + __buf(max<size_type>(2* __base::__map_.capacity(), + __nb + __base::__map_.size()), + 0, __base::__map_.__alloc()); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __nb > 0; --__nb) + __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (typename __base::__map_pointer __i = __buf.begin(); + __i != __buf.end(); ++__i) + __alloc_traits::deallocate(__a, *__i, __base::__block_size); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __back_capacity > 0; --__back_capacity) + { + __buf.push_back(__base::__map_.back()); + __base::__map_.pop_back(); + } + for (typename __base::__map_pointer __i = __base::__map_.begin(); + __i != __base::__map_.end(); ++__i) + __buf.push_back(*__i); + _VSTD::swap(__base::__map_.__first_, __buf.__first_); + _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); + _VSTD::swap(__base::__map_.__end_, __buf.__end_); + _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); + __base::__start_ += __ds; + } +} + +// Create back capacity for one block of elements. +// Strong guarantee. Either do it or don't touch anything. +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__add_back_capacity() +{ + allocator_type& __a = __base::__alloc(); + if (__front_spare() >= __base::__block_size) + { + __base::__start_ -= __base::__block_size; + pointer __pt = __base::__map_.front(); + __base::__map_.pop_front(); + __base::__map_.push_back(__pt); + } + // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers + else if (__base::__map_.size() < __base::__map_.capacity()) + { // we can put the new buffer into the map, but don't shift things around + // until it is allocated. If we throw, we don't need to fix + // anything up (any added buffers are undetectible) + if (__base::__map_.__back_spare() != 0) + __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); + else + { + __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); + // Done allocating, reorder capacity + pointer __pt = __base::__map_.front(); + __base::__map_.pop_front(); + __base::__map_.push_back(__pt); + } + } + // Else need to allocate 1 buffer, *and* we need to reallocate __map_. + else + { + __split_buffer<pointer, typename __base::__pointer_allocator&> + __buf(max<size_type>(2* __base::__map_.capacity(), 1), + __base::__map_.size(), + __base::__map_.__alloc()); + + typedef __allocator_destructor<_Allocator> _Dp; + unique_ptr<pointer, _Dp> __hold( + __alloc_traits::allocate(__a, __base::__block_size), + _Dp(__a, __base::__block_size)); + __buf.push_back(__hold.get()); + __hold.release(); + + for (typename __base::__map_pointer __i = __base::__map_.end(); + __i != __base::__map_.begin();) + __buf.push_front(*--__i); + _VSTD::swap(__base::__map_.__first_, __buf.__first_); + _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); + _VSTD::swap(__base::__map_.__end_, __buf.__end_); + _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); + } +} + +// Create back capacity for __n elements. +// Strong guarantee. Either do it or don't touch anything. +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) +{ + allocator_type& __a = __base::__alloc(); + size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); + // Number of unused blocks at front: + size_type __front_capacity = __front_spare() / __base::__block_size; + __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need + __nb -= __front_capacity; // number of blocks need to allocate + // If __nb == 0, then we have sufficient capacity. + if (__nb == 0) + { + __base::__start_ -= __base::__block_size * __front_capacity; + for (; __front_capacity > 0; --__front_capacity) + { + pointer __pt = __base::__map_.front(); + __base::__map_.pop_front(); + __base::__map_.push_back(__pt); + } + } + // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers + else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) + { // we can put the new buffers into the map, but don't shift things around + // until all buffers are allocated. If we throw, we don't need to fix + // anything up (any added buffers are undetectible) + for (; __nb > 0; --__nb) + { + if (__base::__map_.__back_spare() == 0) + break; + __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); + } + for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ += + __base::__block_size - (__base::__map_.size() == 1)) + __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); + // Done allocating, reorder capacity + __base::__start_ -= __base::__block_size * __front_capacity; + for (; __front_capacity > 0; --__front_capacity) + { + pointer __pt = __base::__map_.front(); + __base::__map_.pop_front(); + __base::__map_.push_back(__pt); + } + } + // Else need to allocate __nb buffers, *and* we need to reallocate __map_. + else + { + size_type __ds = __front_capacity * __base::__block_size; + __split_buffer<pointer, typename __base::__pointer_allocator&> + __buf(max<size_type>(2* __base::__map_.capacity(), + __nb + __base::__map_.size()), + __base::__map_.size() - __front_capacity, + __base::__map_.__alloc()); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __nb > 0; --__nb) + __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (typename __base::__map_pointer __i = __buf.begin(); + __i != __buf.end(); ++__i) + __alloc_traits::deallocate(__a, *__i, __base::__block_size); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __front_capacity > 0; --__front_capacity) + { + __buf.push_back(__base::__map_.front()); + __base::__map_.pop_front(); + } + for (typename __base::__map_pointer __i = __base::__map_.end(); + __i != __base::__map_.begin();) + __buf.push_front(*--__i); + _VSTD::swap(__base::__map_.__first_, __buf.__first_); + _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); + _VSTD::swap(__base::__map_.__end_, __buf.__end_); + _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); + __base::__start_ -= __ds; + } +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::pop_front() +{ + allocator_type& __a = __base::__alloc(); + __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + + __base::__start_ / __base::__block_size) + + __base::__start_ % __base::__block_size)); + --__base::size(); + if (++__base::__start_ >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); + __base::__map_.pop_front(); + __base::__start_ -= __base::__block_size; + } +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::pop_back() +{ + _LIBCPP_ASSERT(!empty(), "deque::pop_back called for empty deque"); + allocator_type& __a = __base::__alloc(); + size_type __p = __base::size() + __base::__start_ - 1; + __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + + __p / __base::__block_size) + + __p % __base::__block_size)); + --__base::size(); + if (__back_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } +} + +// move assign [__f, __l) to [__r, __r + (__l-__f)). +// If __vt points into [__f, __l), then subtract (__f - __r) from __vt. +template <class _Tp, class _Allocator> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r, + const_pointer& __vt) +{ + // as if + // for (; __f != __l; ++__f, ++__r) + // *__r = _VSTD::move(*__f); + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + __base::__block_size; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + if (__fb <= __vt && __vt < __fe) + __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_; + __r = _VSTD::move(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +// move assign [__f, __l) to [__r - (__l-__f), __r) backwards. +// If __vt points into [__f, __l), then add (__r - __l) to __vt. +template <class _Tp, class _Allocator> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r, + const_pointer& __vt) +{ + // as if + // while (__f != __l) + // *--__r = _VSTD::move(*--__l); + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + if (__lb <= __vt && __vt < __le) + __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_; + __r = _VSTD::move_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +// move construct [__f, __l) to [__r, __r + (__l-__f)). +// If __vt points into [__f, __l), then add (__r - __f) to __vt. +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, + iterator __r, const_pointer& __vt) +{ + allocator_type& __a = __base::__alloc(); + // as if + // for (; __f != __l; ++__r, ++__f, ++__base::size()) + // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f)); + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + __base::__block_size; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + if (__fb <= __vt && __vt < __fe) + __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_; + for (; __fb != __fe; ++__fb, ++__r, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); + __n -= __bs; + __f += __bs; + } +} + +// move construct [__f, __l) to [__r - (__l-__f), __r) backwards. +// If __vt points into [__f, __l), then subtract (__l - __r) from __vt. +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l, + iterator __r, const_pointer& __vt) +{ + allocator_type& __a = __base::__alloc(); + // as if + // for (iterator __j = __l; __j != __f;) + // { + // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j)); + // --__base::__start_; + // ++__base::size(); + // } + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + if (__lb <= __vt && __vt < __le) + __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_; + while (__le != __lb) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); + --__base::__start_; + ++__base::size(); + } + __n -= __bs; + __l -= __bs - 1; + } +} + +template <class _Tp, class _Allocator> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::erase(const_iterator __f) +{ + iterator __b = __base::begin(); + difference_type __pos = __f - __b; + iterator __p = __b + __pos; + allocator_type& __a = __base::__alloc(); + if (static_cast<size_t>(__pos) <= (__base::size() - 1) / 2) + { // erase from front + _VSTD::move_backward(__b, __p, _VSTD::next(__p)); + __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); + --__base::size(); + ++__base::__start_; + if (__front_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); + __base::__map_.pop_front(); + __base::__start_ -= __base::__block_size; + } + } + else + { // erase from back + iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p); + __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); + --__base::size(); + if (__back_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + } + return __base::begin() + __pos; +} + +template <class _Tp, class _Allocator> +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) +{ + difference_type __n = __l - __f; + iterator __b = __base::begin(); + difference_type __pos = __f - __b; + iterator __p = __b + __pos; + if (__n > 0) + { + allocator_type& __a = __base::__alloc(); + if (static_cast<size_t>(__pos) <= (__base::size() - __n) / 2) + { // erase from front + iterator __i = _VSTD::move_backward(__b, __p, __p + __n); + for (; __b != __i; ++__b) + __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); + __base::size() -= __n; + __base::__start_ += __n; + while (__front_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); + __base::__map_.pop_front(); + __base::__start_ -= __base::__block_size; + } + } + else + { // erase from back + iterator __i = _VSTD::move(__p + __n, __base::end(), __p); + for (iterator __e = __base::end(); __i != __e; ++__i) + __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); + __base::size() -= __n; + while (__back_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + } + } + return __base::begin() + __pos; +} + +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) +{ + iterator __e = __base::end(); + difference_type __n = __e - __f; + if (__n > 0) + { + allocator_type& __a = __base::__alloc(); + iterator __b = __base::begin(); + difference_type __pos = __f - __b; + for (iterator __p = __b + __pos; __p != __e; ++__p) + __alloc_traits::destroy(__a, _VSTD::addressof(*__p)); + __base::size() -= __n; + while (__back_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + } +} + +template <class _Tp, class _Allocator> +inline +void +deque<_Tp, _Allocator>::swap(deque& __c) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value) +#endif +{ + __base::swap(__c); +} + +template <class _Tp, class _Allocator> +inline +void +deque<_Tp, _Allocator>::clear() _NOEXCEPT +{ + __base::clear(); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + const typename deque<_Tp, _Allocator>::size_type __sz = __x.size(); + return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return !(__x < __y); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Tp, class _Allocator, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +void erase(deque<_Tp, _Allocator>& __c, const _Up& __v) +{ __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); } + +template <class _Tp, class _Allocator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred) +{ __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); } +#endif + + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_DEQUE diff --git a/android/x86/include/v8/libc++/errno.h b/android/x86/include/v8/libc++/errno.h new file mode 100755 index 00000000..447319ef --- /dev/null +++ b/android/x86/include/v8/libc++/errno.h @@ -0,0 +1,397 @@ +// -*- C++ -*- +//===-------------------------- errno.h -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ERRNO_H +#define _LIBCPP_ERRNO_H + +/* + errno.h synopsis + +Macros: + + EDOM + EILSEQ // C99 + ERANGE + errno + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <errno.h> + +#ifdef __cplusplus + +#if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE) + +#ifdef ELAST + +static const int __elast1 = ELAST+1; +static const int __elast2 = ELAST+2; + +#else + +static const int __elast1 = 104; +static const int __elast2 = 105; + +#endif + +#ifdef ENOTRECOVERABLE + +#define EOWNERDEAD __elast1 + +#ifdef ELAST +#undef ELAST +#define ELAST EOWNERDEAD +#endif + +#elif defined(EOWNERDEAD) + +#define ENOTRECOVERABLE __elast1 +#ifdef ELAST +#undef ELAST +#define ELAST ENOTRECOVERABLE +#endif + +#else // defined(EOWNERDEAD) + +#define EOWNERDEAD __elast1 +#define ENOTRECOVERABLE __elast2 +#ifdef ELAST +#undef ELAST +#define ELAST ENOTRECOVERABLE +#endif + +#endif // defined(EOWNERDEAD) + +#endif // !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE) + +// supply errno values likely to be missing, particularly on Windows + +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT 9901 +#endif + +#ifndef EADDRINUSE +#define EADDRINUSE 9902 +#endif + +#ifndef EADDRNOTAVAIL +#define EADDRNOTAVAIL 9903 +#endif + +#ifndef EISCONN +#define EISCONN 9904 +#endif + +#ifndef EBADMSG +#define EBADMSG 9905 +#endif + +#ifndef ECONNABORTED +#define ECONNABORTED 9906 +#endif + +#ifndef EALREADY +#define EALREADY 9907 +#endif + +#ifndef ECONNREFUSED +#define ECONNREFUSED 9908 +#endif + +#ifndef ECONNRESET +#define ECONNRESET 9909 +#endif + +#ifndef EDESTADDRREQ +#define EDESTADDRREQ 9910 +#endif + +#ifndef EHOSTUNREACH +#define EHOSTUNREACH 9911 +#endif + +#ifndef EIDRM +#define EIDRM 9912 +#endif + +#ifndef EMSGSIZE +#define EMSGSIZE 9913 +#endif + +#ifndef ENETDOWN +#define ENETDOWN 9914 +#endif + +#ifndef ENETRESET +#define ENETRESET 9915 +#endif + +#ifndef ENETUNREACH +#define ENETUNREACH 9916 +#endif + +#ifndef ENOBUFS +#define ENOBUFS 9917 +#endif + +#ifndef ENOLINK +#define ENOLINK 9918 +#endif + +#ifndef ENODATA +#define ENODATA 9919 +#endif + +#ifndef ENOMSG +#define ENOMSG 9920 +#endif + +#ifndef ENOPROTOOPT +#define ENOPROTOOPT 9921 +#endif + +#ifndef ENOSR +#define ENOSR 9922 +#endif + +#ifndef ENOTSOCK +#define ENOTSOCK 9923 +#endif + +#ifndef ENOSTR +#define ENOSTR 9924 +#endif + +#ifndef ENOTCONN +#define ENOTCONN 9925 +#endif + +#ifndef ENOTSUP +#define ENOTSUP 9926 +#endif + +#ifndef ECANCELED +#define ECANCELED 9927 +#endif + +#ifndef EINPROGRESS +#define EINPROGRESS 9928 +#endif + +#ifndef EOPNOTSUPP +#define EOPNOTSUPP 9929 +#endif + +#ifndef EWOULDBLOCK +#define EWOULDBLOCK 9930 +#endif + +#ifndef EOWNERDEAD +#define EOWNERDEAD 9931 +#endif + +#ifndef EPROTO +#define EPROTO 9932 +#endif + +#ifndef EPROTONOSUPPORT +#define EPROTONOSUPPORT 9933 +#endif + +#ifndef ENOTRECOVERABLE +#define ENOTRECOVERABLE 9934 +#endif + +#ifndef ETIME +#define ETIME 9935 +#endif + +#ifndef ETXTBSY +#define ETXTBSY 9936 +#endif + +#ifndef ETIMEDOUT +#define ETIMEDOUT 9938 +#endif + +#ifndef ELOOP +#define ELOOP 9939 +#endif + +#ifndef EOVERFLOW +#define EOVERFLOW 9940 +#endif + +#ifndef EPROTOTYPE +#define EPROTOTYPE 9941 +#endif + +#ifndef ENOSYS +#define ENOSYS 9942 +#endif + +#ifndef EINVAL +#define EINVAL 9943 +#endif + +#ifndef ERANGE +#define ERANGE 9944 +#endif + +#ifndef EILSEQ +#define EILSEQ 9945 +#endif + +// Windows Mobile doesn't appear to define these: + +#ifndef E2BIG +#define E2BIG 9946 +#endif + +#ifndef EDOM +#define EDOM 9947 +#endif + +#ifndef EFAULT +#define EFAULT 9948 +#endif + +#ifndef EBADF +#define EBADF 9949 +#endif + +#ifndef EPIPE +#define EPIPE 9950 +#endif + +#ifndef EXDEV +#define EXDEV 9951 +#endif + +#ifndef EBUSY +#define EBUSY 9952 +#endif + +#ifndef ENOTEMPTY +#define ENOTEMPTY 9953 +#endif + +#ifndef ENOEXEC +#define ENOEXEC 9954 +#endif + +#ifndef EEXIST +#define EEXIST 9955 +#endif + +#ifndef EFBIG +#define EFBIG 9956 +#endif + +#ifndef ENAMETOOLONG +#define ENAMETOOLONG 9957 +#endif + +#ifndef ENOTTY +#define ENOTTY 9958 +#endif + +#ifndef EINTR +#define EINTR 9959 +#endif + +#ifndef ESPIPE +#define ESPIPE 9960 +#endif + +#ifndef EIO +#define EIO 9961 +#endif + +#ifndef EISDIR +#define EISDIR 9962 +#endif + +#ifndef ECHILD +#define ECHILD 9963 +#endif + +#ifndef ENOLCK +#define ENOLCK 9964 +#endif + +#ifndef ENOSPC +#define ENOSPC 9965 +#endif + +#ifndef ENXIO +#define ENXIO 9966 +#endif + +#ifndef ENODEV +#define ENODEV 9967 +#endif + +#ifndef ENOENT +#define ENOENT 9968 +#endif + +#ifndef ESRCH +#define ESRCH 9969 +#endif + +#ifndef ENOTDIR +#define ENOTDIR 9970 +#endif + +#ifndef ENOMEM +#define ENOMEM 9971 +#endif + +#ifndef EPERM +#define EPERM 9972 +#endif + +#ifndef EACCES +#define EACCES 9973 +#endif + +#ifndef EROFS +#define EROFS 9974 +#endif + +#ifndef EDEADLK +#define EDEADLK 9975 +#endif + +#ifndef EAGAIN +#define EAGAIN 9976 +#endif + +#ifndef ENFILE +#define ENFILE 9977 +#endif + +#ifndef EMFILE +#define EMFILE 9978 +#endif + +#ifndef EMLINK +#define EMLINK 9979 +#endif + +#endif // __cplusplus + +#endif // _LIBCPP_ERRNO_H diff --git a/android/x86/include/v8/libc++/exception b/android/x86/include/v8/libc++/exception new file mode 100755 index 00000000..05ff6015 --- /dev/null +++ b/android/x86/include/v8/libc++/exception @@ -0,0 +1,337 @@ +// -*- C++ -*- +//===-------------------------- exception ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXCEPTION +#define _LIBCPP_EXCEPTION + +/* + exception synopsis + +namespace std +{ + +class exception +{ +public: + exception() noexcept; + exception(const exception&) noexcept; + exception& operator=(const exception&) noexcept; + virtual ~exception() noexcept; + virtual const char* what() const noexcept; +}; + +class bad_exception + : public exception +{ +public: + bad_exception() noexcept; + bad_exception(const bad_exception&) noexcept; + bad_exception& operator=(const bad_exception&) noexcept; + virtual ~bad_exception() noexcept; + virtual const char* what() const noexcept; +}; + +typedef void (*unexpected_handler)(); +unexpected_handler set_unexpected(unexpected_handler f ) noexcept; +unexpected_handler get_unexpected() noexcept; +[[noreturn]] void unexpected(); + +typedef void (*terminate_handler)(); +terminate_handler set_terminate(terminate_handler f ) noexcept; +terminate_handler get_terminate() noexcept; +[[noreturn]] void terminate() noexcept; + +bool uncaught_exception() noexcept; +int uncaught_exceptions() noexcept; // C++17 + +typedef unspecified exception_ptr; + +exception_ptr current_exception() noexcept; +void rethrow_exception [[noreturn]] (exception_ptr p); +template<class E> exception_ptr make_exception_ptr(E e) noexcept; + +class nested_exception +{ +public: + nested_exception() noexcept; + nested_exception(const nested_exception&) noexcept = default; + nested_exception& operator=(const nested_exception&) noexcept = default; + virtual ~nested_exception() = default; + + // access functions + [[noreturn]] void rethrow_nested() const; + exception_ptr nested_ptr() const noexcept; +}; + +template <class T> [[noreturn]] void throw_with_nested(T&& t); +template <class E> void rethrow_if_nested(const E& e); + +} // std + +*/ + +#include <__config> +#include <cstddef> +#include <cstdlib> +#include <type_traits> +#include <version> + +#if defined(_LIBCPP_ABI_VCRUNTIME) +#include <vcruntime_exception.h> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace std // purposefully not using versioning namespace +{ + +#if !defined(_LIBCPP_ABI_VCRUNTIME) +class _LIBCPP_EXCEPTION_ABI exception +{ +public: + _LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {} + virtual ~exception() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +class _LIBCPP_EXCEPTION_ABI bad_exception + : public exception +{ +public: + _LIBCPP_INLINE_VISIBILITY bad_exception() _NOEXCEPT {} + virtual ~bad_exception() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; +#endif // !_LIBCPP_ABI_VCRUNTIME + +#if _LIBCPP_STD_VER <= 14 \ + || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \ + || defined(_LIBCPP_BUILDING_LIBRARY) +typedef void (*unexpected_handler)(); +_LIBCPP_FUNC_VIS unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT; +_LIBCPP_FUNC_VIS unexpected_handler get_unexpected() _NOEXCEPT; +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void unexpected(); +#endif + +typedef void (*terminate_handler)(); +_LIBCPP_FUNC_VIS terminate_handler set_terminate(terminate_handler) _NOEXCEPT; +_LIBCPP_FUNC_VIS terminate_handler get_terminate() _NOEXCEPT; +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void terminate() _NOEXCEPT; + +_LIBCPP_FUNC_VIS bool uncaught_exception() _NOEXCEPT; +_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS int uncaught_exceptions() _NOEXCEPT; + +class _LIBCPP_TYPE_VIS exception_ptr; + +_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr); + +#ifndef _LIBCPP_ABI_MICROSOFT + +class _LIBCPP_TYPE_VIS exception_ptr +{ + void* __ptr_; +public: + _LIBCPP_INLINE_VISIBILITY exception_ptr() _NOEXCEPT : __ptr_() {} + _LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {} + + exception_ptr(const exception_ptr&) _NOEXCEPT; + exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; + ~exception_ptr() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT + {return __ptr_ != nullptr;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT + {return __x.__ptr_ == __y.__ptr_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT + {return !(__x == __y);} + + friend _LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; + friend _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr); +}; + +template<class _Ep> +_LIBCPP_INLINE_VISIBILITY exception_ptr +make_exception_ptr(_Ep __e) _NOEXCEPT +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { + throw __e; + } + catch (...) + { + return current_exception(); + } +#else + ((void)__e); + _VSTD::abort(); +#endif +} + +#else // _LIBCPP_ABI_MICROSOFT + +class _LIBCPP_TYPE_VIS exception_ptr +{ +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-private-field" +#endif + void* __ptr1_; + void* __ptr2_; +#if defined(__clang__) +#pragma clang diagnostic pop +#endif +public: + exception_ptr() _NOEXCEPT; + exception_ptr(nullptr_t) _NOEXCEPT; + exception_ptr(const exception_ptr& __other) _NOEXCEPT; + exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT; + exception_ptr& operator=(nullptr_t) _NOEXCEPT; + ~exception_ptr() _NOEXCEPT; + _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT; +}; + +_LIBCPP_FUNC_VIS +bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT; + +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT + {return !(__x == __y);} + +_LIBCPP_FUNC_VIS void swap(exception_ptr&, exception_ptr&) _NOEXCEPT; + +_LIBCPP_FUNC_VIS exception_ptr __copy_exception_ptr(void *__except, const void* __ptr); +_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr p); + +// This is a built-in template function which automagically extracts the required +// information. +template <class _E> void *__GetExceptionInfo(_E); + +template<class _Ep> +_LIBCPP_INLINE_VISIBILITY exception_ptr +make_exception_ptr(_Ep __e) _NOEXCEPT +{ + return __copy_exception_ptr(_VSTD::addressof(__e), __GetExceptionInfo(__e)); +} + +#endif // _LIBCPP_ABI_MICROSOFT +// nested_exception + +class _LIBCPP_EXCEPTION_ABI nested_exception +{ + exception_ptr __ptr_; +public: + nested_exception() _NOEXCEPT; +// nested_exception(const nested_exception&) noexcept = default; +// nested_exception& operator=(const nested_exception&) noexcept = default; + virtual ~nested_exception() _NOEXCEPT; + + // access functions + _LIBCPP_NORETURN void rethrow_nested() const; + _LIBCPP_INLINE_VISIBILITY exception_ptr nested_ptr() const _NOEXCEPT {return __ptr_;} +}; + +template <class _Tp> +struct __nested + : public _Tp, + public nested_exception +{ + _LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {} +}; + +#ifndef _LIBCPP_NO_EXCEPTIONS +template <class _Tp, class _Up, bool> +struct __throw_with_nested; + +template <class _Tp, class _Up> +struct __throw_with_nested<_Tp, _Up, true> { + _LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void +#ifndef _LIBCPP_CXX03_LANG + __do_throw(_Tp&& __t) +#else + __do_throw (_Tp& __t) +#endif // _LIBCPP_CXX03_LANG + { + throw __nested<_Up>(_VSTD::forward<_Tp>(__t)); + } +}; + +template <class _Tp, class _Up> +struct __throw_with_nested<_Tp, _Up, false> { + _LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void +#ifndef _LIBCPP_CXX03_LANG + __do_throw(_Tp&& __t) +#else + __do_throw (_Tp& __t) +#endif // _LIBCPP_CXX03_LANG + { + throw _VSTD::forward<_Tp>(__t); + } +}; +#endif + +template <class _Tp> +_LIBCPP_NORETURN +void +#ifndef _LIBCPP_CXX03_LANG +throw_with_nested(_Tp&& __t) +#else +throw_with_nested (_Tp& __t) +#endif // _LIBCPP_CXX03_LANG +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + typedef typename decay<_Tp>::type _Up; + static_assert( is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible"); + __throw_with_nested<_Tp, _Up, + is_class<_Up>::value && + !is_base_of<nested_exception, _Up>::value && + !__libcpp_is_final<_Up>::value>:: + __do_throw(_VSTD::forward<_Tp>(__t)); +#else + ((void)__t); + // FIXME: Make this abort +#endif +} + +template <class _From, class _To> +struct __can_dynamic_cast : public _LIBCPP_BOOL_CONSTANT( + is_polymorphic<_From>::value && + (!is_base_of<_To, _From>::value || + is_convertible<const _From*, const _To*>::value)) {}; + +template <class _Ep> +inline _LIBCPP_INLINE_VISIBILITY +void +rethrow_if_nested(const _Ep& __e, + typename enable_if< __can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0) +{ + const nested_exception* __nep = dynamic_cast<const nested_exception*>(_VSTD::addressof(__e)); + if (__nep) + __nep->rethrow_nested(); +} + +template <class _Ep> +inline _LIBCPP_INLINE_VISIBILITY +void +rethrow_if_nested(const _Ep&, + typename enable_if<!__can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0) +{ +} + +} // std + +#endif // _LIBCPP_EXCEPTION diff --git a/android/x86/include/v8/libc++/experimental/__config b/android/x86/include/v8/libc++/experimental/__config new file mode 100755 index 00000000..d3667b52 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/__config @@ -0,0 +1,73 @@ +// -*- C++ -*- +//===--------------------------- __config ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_CONFIG +#define _LIBCPP_EXPERIMENTAL_CONFIG + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental { +#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } } +#define _VSTD_EXPERIMENTAL std::experimental + +#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 { +#define _LIBCPP_END_NAMESPACE_LFTS } } } +#define _VSTD_LFTS _VSTD_EXPERIMENTAL::fundamentals_v1 + +#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 { +#define _LIBCPP_END_NAMESPACE_LFTS_V2 } } } +#define _VSTD_LFTS_V2 _VSTD_EXPERIMENTAL::fundamentals_v2 + +#define _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR _LIBCPP_BEGIN_NAMESPACE_LFTS namespace pmr { +#define _LIBCPP_END_NAMESPACE_LFTS_PMR _LIBCPP_END_NAMESPACE_LFTS } +#define _VSTD_LFTS_PMR _VSTD_LFTS::pmr + +#define _LIBCPP_BEGIN_NAMESPACE_CHRONO_LFTS _LIBCPP_BEGIN_NAMESPACE_STD \ + namespace chrono { namespace experimental { inline namespace fundamentals_v1 { +#define _LIBCPP_END_NAMESPACE_CHRONO_LFTS _LIBCPP_END_NAMESPACE_STD } } } + +#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM \ + _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace filesystem { \ + inline namespace v1 { + +#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM \ + } } _LIBCPP_END_NAMESPACE_EXPERIMENTAL + +#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES \ + _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace coroutines_v1 { + +#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_COROUTINES \ + } _LIBCPP_END_NAMESPACE_EXPERIMENTAL + +#define _VSTD_CORO _VSTD_EXPERIMENTAL::coroutines_v1 + +#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD \ + _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace parallelism_v2 { + +#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD \ + } _LIBCPP_END_NAMESPACE_EXPERIMENTAL + +#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD_ABI \ + _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD namespace simd_abi { + +#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD_ABI \ + } _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD + +// TODO: support more targets +#if defined(__AVX__) +#define _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES 32 +#else +#define _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES 16 +#endif + +#endif diff --git a/android/x86/include/v8/libc++/experimental/__memory b/android/x86/include/v8/libc++/experimental/__memory new file mode 100755 index 00000000..4cf89784 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/__memory @@ -0,0 +1,89 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL___MEMORY +#define _LIBCPP_EXPERIMENTAL___MEMORY + +#include <experimental/__config> +#include <experimental/utility> // for erased_type +#include <__functional_base> +#include <type_traits> + +_LIBCPP_BEGIN_NAMESPACE_LFTS + +template < + class _Tp, class _Alloc + , bool = uses_allocator<_Tp, _Alloc>::value + , bool = __has_allocator_type<_Tp>::value + > +struct __lfts_uses_allocator : public false_type {}; + +template <class _Tp, class _Alloc> +struct __lfts_uses_allocator<_Tp, _Alloc, false, false> : public false_type {}; + +template <class _Tp, class _Alloc, bool HasAlloc> +struct __lfts_uses_allocator<_Tp, _Alloc, true, HasAlloc> : public true_type {}; + +template <class _Tp, class _Alloc> +struct __lfts_uses_allocator<_Tp, _Alloc, false, true> + : public integral_constant<bool + , is_convertible<_Alloc, typename _Tp::allocator_type>::value + || is_same<erased_type, typename _Tp::allocator_type>::value + > +{}; + +template <bool _UsesAlloc, class _Tp, class _Alloc, class ..._Args> +struct __lfts_uses_alloc_ctor_imp +{ + static const int value = 0; +}; + +template <class _Tp, class _Alloc, class ..._Args> +struct __lfts_uses_alloc_ctor_imp<true, _Tp, _Alloc, _Args...> +{ + static const bool __ic_first + = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; + + static const bool __ic_second = + conditional< + __ic_first, + false_type, + is_constructible<_Tp, _Args..., _Alloc> + >::type::value; + + static_assert(__ic_first || __ic_second, + "Request for uses allocator construction is ill-formed"); + + static const int value = __ic_first ? 1 : 2; +}; + +template <class _Tp, class _Alloc, class ..._Args> +struct __lfts_uses_alloc_ctor + : integral_constant<int, + __lfts_uses_alloc_ctor_imp< + __lfts_uses_allocator<_Tp, _Alloc>::value + , _Tp, _Alloc, _Args... + >::value + > +{}; + +template <class _Tp, class _Alloc, class ..._Args> +inline _LIBCPP_INLINE_VISIBILITY +void __lfts_user_alloc_construct( + _Tp * __store, const _Alloc & __a, _Args &&... __args) +{ + _VSTD::__user_alloc_construct_impl( + typename __lfts_uses_alloc_ctor<_Tp, _Alloc, _Args...>::type() + , __store, __a, _VSTD::forward<_Args>(__args)... + ); +} + +_LIBCPP_END_NAMESPACE_LFTS + +#endif /* _LIBCPP_EXPERIMENTAL___MEMORY */ diff --git a/android/x86/include/v8/libc++/experimental/algorithm b/android/x86/include/v8/libc++/experimental/algorithm new file mode 100755 index 00000000..79fd7b1b --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/algorithm @@ -0,0 +1,59 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_ALGORITHM +#define _LIBCPP_EXPERIMENTAL_ALGORITHM + +/* + experimental/algorithm synopsis + +#include <algorithm> + +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { + +template <class ForwardIterator, class Searcher> +ForwardIterator search(ForwardIterator first, ForwardIterator last, + const Searcher &searcher); + +// sample removed because it's now part of C++17 + +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + +*/ + +#include <experimental/__config> +#include <algorithm> +#include <type_traits> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_LFTS + +template <class _ForwardIterator, class _Searcher> +_LIBCPP_INLINE_VISIBILITY +_ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s) +{ return __s(__f, __l).first; } + +_LIBCPP_END_NAMESPACE_LFTS + +_LIBCPP_POP_MACROS + +#endif /* _LIBCPP_EXPERIMENTAL_ALGORITHM */ diff --git a/android/x86/include/v8/libc++/experimental/any b/android/x86/include/v8/libc++/experimental/any new file mode 100755 index 00000000..c8050e33 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/any @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===------------------------------- any ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_ANY +#define _LIBCPP_EXPERIMENTAL_ANY + +#include <__config> + +#ifdef _LIBCPP_WARNING +_LIBCPP_WARNING("<experimental/any> has been removed. Use <any> instead.") +#else +# warning "<experimental/any> has been removed. Use <any> instead." +#endif + +#endif // _LIBCPP_EXPERIMENTAL_ANY diff --git a/android/x86/include/v8/libc++/experimental/chrono b/android/x86/include/v8/libc++/experimental/chrono new file mode 100755 index 00000000..f3ceaaea --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/chrono @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===---------------------------- chrono ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_CHRONO +#define _LIBCPP_EXPERIMENTAL_CHRONO + +#include <__config> + +#ifdef _LIBCPP_WARNING +_LIBCPP_WARNING("<experimental/chrono> has been removed. Use <chrono> instead.") +#else +# warning "<experimental/chrono> has been removed. Use <chrono> instead." +#endif + +#endif // _LIBCPP_EXPERIMENTAL_CHRONO diff --git a/android/x86/include/v8/libc++/experimental/coroutine b/android/x86/include/v8/libc++/experimental/coroutine new file mode 100755 index 00000000..13e32625 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/coroutine @@ -0,0 +1,335 @@ +// -*- C++ -*- +//===----------------------------- coroutine -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_COROUTINE +#define _LIBCPP_EXPERIMENTAL_COROUTINE + +/** + experimental/coroutine synopsis + +// C++next + +namespace std { +namespace experimental { +inline namespace coroutines_v1 { + + // 18.11.1 coroutine traits +template <typename R, typename... ArgTypes> +class coroutine_traits; +// 18.11.2 coroutine handle +template <typename Promise = void> +class coroutine_handle; +// 18.11.2.7 comparison operators: +bool operator==(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator!=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator<(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator<=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator>=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator>(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +// 18.11.3 trivial awaitables +struct suspend_never; +struct suspend_always; +// 18.11.2.8 hash support: +template <class T> struct hash; +template <class P> struct hash<coroutine_handle<P>>; + +} // namespace coroutines_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <new> +#include <type_traits> +#include <functional> +#include <memory> // for hash<T*> +#include <cstddef> +#include <cassert> +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_COROUTINES +# if defined(_LIBCPP_WARNING) + _LIBCPP_WARNING("<experimental/coroutine> cannot be used with this compiler") +# else +# warning <experimental/coroutine> cannot be used with this compiler +# endif +#endif + +#ifndef _LIBCPP_HAS_NO_COROUTINES + +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES + +template <class _Tp, class = void> +struct __coroutine_traits_sfinae {}; + +template <class _Tp> +struct __coroutine_traits_sfinae< + _Tp, typename __void_t<typename _Tp::promise_type>::type> +{ + using promise_type = typename _Tp::promise_type; +}; + +template <typename _Ret, typename... _Args> +struct _LIBCPP_TEMPLATE_VIS coroutine_traits + : public __coroutine_traits_sfinae<_Ret> +{ +}; + +template <typename _Promise = void> +class _LIBCPP_TEMPLATE_VIS coroutine_handle; + +template <> +class _LIBCPP_TEMPLATE_VIS coroutine_handle<void> { +public: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR coroutine_handle() _NOEXCEPT : __handle_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR coroutine_handle(nullptr_t) _NOEXCEPT : __handle_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + coroutine_handle& operator=(nullptr_t) _NOEXCEPT { + __handle_ = nullptr; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR void* address() const _NOEXCEPT { return __handle_; } + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR explicit operator bool() const _NOEXCEPT { return __handle_; } + + _LIBCPP_INLINE_VISIBILITY + void operator()() { resume(); } + + _LIBCPP_INLINE_VISIBILITY + void resume() { + _LIBCPP_ASSERT(__is_suspended(), + "resume() can only be called on suspended coroutines"); + _LIBCPP_ASSERT(!done(), + "resume() has undefined behavior when the coroutine is done"); + __builtin_coro_resume(__handle_); + } + + _LIBCPP_INLINE_VISIBILITY + void destroy() { + _LIBCPP_ASSERT(__is_suspended(), + "destroy() can only be called on suspended coroutines"); + __builtin_coro_destroy(__handle_); + } + + _LIBCPP_INLINE_VISIBILITY + bool done() const { + _LIBCPP_ASSERT(__is_suspended(), + "done() can only be called on suspended coroutines"); + return __builtin_coro_done(__handle_); + } + +public: + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_address(void* __addr) _NOEXCEPT { + coroutine_handle __tmp; + __tmp.__handle_ = __addr; + return __tmp; + } + + // FIXME: Should from_address(nullptr) be allowed? + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_address(nullptr_t) _NOEXCEPT { + return coroutine_handle(nullptr); + } + + template <class _Tp, bool _CallIsValid = false> + static coroutine_handle from_address(_Tp*) { + static_assert(_CallIsValid, + "coroutine_handle<void>::from_address cannot be called with " + "non-void pointers"); + } + +private: + bool __is_suspended() const _NOEXCEPT { + // FIXME actually implement a check for if the coro is suspended. + return __handle_; + } + + template <class _PromiseT> friend class coroutine_handle; + void* __handle_; +}; + +// 18.11.2.7 comparison operators: +inline _LIBCPP_INLINE_VISIBILITY +bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return __x.address() == __y.address(); +} +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return !(__x == __y); +} +inline _LIBCPP_INLINE_VISIBILITY +bool operator<(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return less<void*>()(__x.address(), __y.address()); +} +inline _LIBCPP_INLINE_VISIBILITY +bool operator>(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return __y < __x; +} +inline _LIBCPP_INLINE_VISIBILITY +bool operator<=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return !(__x > __y); +} +inline _LIBCPP_INLINE_VISIBILITY +bool operator>=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return !(__x < __y); +} + +template <typename _Promise> +class _LIBCPP_TEMPLATE_VIS coroutine_handle : public coroutine_handle<> { + using _Base = coroutine_handle<>; +public: +#ifndef _LIBCPP_CXX03_LANG + // 18.11.2.1 construct/reset + using coroutine_handle<>::coroutine_handle; +#else + _LIBCPP_INLINE_VISIBILITY coroutine_handle() _NOEXCEPT : _Base() {} + _LIBCPP_INLINE_VISIBILITY coroutine_handle(nullptr_t) _NOEXCEPT : _Base(nullptr) {} +#endif + _LIBCPP_INLINE_VISIBILITY + coroutine_handle& operator=(nullptr_t) _NOEXCEPT { + _Base::operator=(nullptr); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + _Promise& promise() const { + return *static_cast<_Promise*>( + __builtin_coro_promise(this->__handle_, _LIBCPP_ALIGNOF(_Promise), false)); + } + +public: + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_address(void* __addr) _NOEXCEPT { + coroutine_handle __tmp; + __tmp.__handle_ = __addr; + return __tmp; + } + + // NOTE: this overload isn't required by the standard but is needed so + // the deleted _Promise* overload doesn't make from_address(nullptr) + // ambiguous. + // FIXME: should from_address work with nullptr? + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_address(nullptr_t) _NOEXCEPT { + return coroutine_handle(nullptr); + } + + template <class _Tp, bool _CallIsValid = false> + static coroutine_handle from_address(_Tp*) { + static_assert(_CallIsValid, + "coroutine_handle<promise_type>::from_address cannot be called with " + "non-void pointers"); + } + + template <bool _CallIsValid = false> + static coroutine_handle from_address(_Promise*) { + static_assert(_CallIsValid, + "coroutine_handle<promise_type>::from_address cannot be used with " + "pointers to the coroutine's promise type; use 'from_promise' instead"); + } + + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_promise(_Promise& __promise) _NOEXCEPT { + typedef typename remove_cv<_Promise>::type _RawPromise; + coroutine_handle __tmp; + __tmp.__handle_ = __builtin_coro_promise( + _VSTD::addressof(const_cast<_RawPromise&>(__promise)), + _LIBCPP_ALIGNOF(_Promise), true); + return __tmp; + } +}; + +#if __has_builtin(__builtin_coro_noop) +struct noop_coroutine_promise {}; + +template <> +class _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise> + : public coroutine_handle<> { + using _Base = coroutine_handle<>; + using _Promise = noop_coroutine_promise; +public: + + _LIBCPP_INLINE_VISIBILITY + _Promise& promise() const { + return *static_cast<_Promise*>( + __builtin_coro_promise(this->__handle_, _LIBCPP_ALIGNOF(_Promise), false)); + } + + _LIBCPP_CONSTEXPR explicit operator bool() const _NOEXCEPT { return true; } + _LIBCPP_CONSTEXPR bool done() const _NOEXCEPT { return false; } + + _LIBCPP_CONSTEXPR_AFTER_CXX17 void operator()() const _NOEXCEPT {} + _LIBCPP_CONSTEXPR_AFTER_CXX17 void resume() const _NOEXCEPT {} + _LIBCPP_CONSTEXPR_AFTER_CXX17 void destroy() const _NOEXCEPT {} + +private: + _LIBCPP_INLINE_VISIBILITY + friend coroutine_handle<noop_coroutine_promise> noop_coroutine() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY coroutine_handle() _NOEXCEPT { + this->__handle_ = __builtin_coro_noop(); + } +}; + +using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>; + +inline _LIBCPP_INLINE_VISIBILITY +noop_coroutine_handle noop_coroutine() _NOEXCEPT { + return noop_coroutine_handle(); +} +#endif // __has_builtin(__builtin_coro_noop) + +struct _LIBCPP_TYPE_VIS suspend_never { + _LIBCPP_INLINE_VISIBILITY + bool await_ready() const _NOEXCEPT { return true; } + _LIBCPP_INLINE_VISIBILITY + void await_suspend(coroutine_handle<>) const _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + void await_resume() const _NOEXCEPT {} +}; + +struct _LIBCPP_TYPE_VIS suspend_always { + _LIBCPP_INLINE_VISIBILITY + bool await_ready() const _NOEXCEPT { return false; } + _LIBCPP_INLINE_VISIBILITY + void await_suspend(coroutine_handle<>) const _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + void await_resume() const _NOEXCEPT {} +}; + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_COROUTINES + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> +struct hash<_VSTD_CORO::coroutine_handle<_Tp> > { + using __arg_type = _VSTD_CORO::coroutine_handle<_Tp>; + _LIBCPP_INLINE_VISIBILITY + size_t operator()(__arg_type const& __v) const _NOEXCEPT + {return hash<void*>()(__v.address());} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // !defined(_LIBCPP_HAS_NO_COROUTINES) + +#endif /* _LIBCPP_EXPERIMENTAL_COROUTINE */ diff --git a/android/x86/include/v8/libc++/experimental/deque b/android/x86/include/v8/libc++/experimental/deque new file mode 100755 index 00000000..73c2787c --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/deque @@ -0,0 +1,46 @@ +// -*- C++ -*- +//===--------------------------- deque ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_DEQUE +#define _LIBCPP_EXPERIMENTAL_DEQUE +/* + experimental/deque synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + template <class T> + using deque = std::deque<T,polymorphic_allocator<T>>; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <deque> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _ValueT> +using deque = _VSTD::deque<_ValueT, polymorphic_allocator<_ValueT>>; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_DEQUE */ diff --git a/android/x86/include/v8/libc++/experimental/filesystem b/android/x86/include/v8/libc++/experimental/filesystem new file mode 100755 index 00000000..d2e6237d --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/filesystem @@ -0,0 +1,256 @@ +// -*- C++ -*- +//===--------------------------- filesystem -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_FILESYSTEM +#define _LIBCPP_EXPERIMENTAL_FILESYSTEM +/* + filesystem synopsis + + namespace std { namespace experimental { namespace filesystem { inline namespace v1 { + + class path; + + void swap(path& lhs, path& rhs) noexcept; + size_t hash_value(const path& p) noexcept; + + bool operator==(const path& lhs, const path& rhs) noexcept; + bool operator!=(const path& lhs, const path& rhs) noexcept; + bool operator< (const path& lhs, const path& rhs) noexcept; + bool operator<=(const path& lhs, const path& rhs) noexcept; + bool operator> (const path& lhs, const path& rhs) noexcept; + bool operator>=(const path& lhs, const path& rhs) noexcept; + + path operator/ (const path& lhs, const path& rhs); + + // fs.path.io operators are friends of path. + template <class charT, class traits> + friend basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, const path& p); + + template <class charT, class traits> + friend basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, path& p); + + template <class Source> + path u8path(const Source& source); + template <class InputIterator> + path u8path(InputIterator first, InputIterator last); + + class filesystem_error; + class directory_entry; + + class directory_iterator; + + // enable directory_iterator range-based for statements + directory_iterator begin(directory_iterator iter) noexcept; + directory_iterator end(const directory_iterator&) noexcept; + + class recursive_directory_iterator; + + // enable recursive_directory_iterator range-based for statements + recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept; + recursive_directory_iterator end(const recursive_directory_iterator&) noexcept; + + class file_status; + + struct space_info + { + uintmax_t capacity; + uintmax_t free; + uintmax_t available; + }; + + enum class file_type; + enum class perms; + enum class perm_options; + enum class copy_options; + enum class directory_options; + + typedef chrono::time_point<trivial-clock> file_time_type; + + // operational functions + + path absolute(const path& p); + path absolute(const path& p, error_code &ec); + + path canonical(const path& p); + path canonical(const path& p, error_code& ec); + + void copy(const path& from, const path& to); + void copy(const path& from, const path& to, error_code& ec); + void copy(const path& from, const path& to, copy_options options); + void copy(const path& from, const path& to, copy_options options, + error_code& ec); + + bool copy_file(const path& from, const path& to); + bool copy_file(const path& from, const path& to, error_code& ec); + bool copy_file(const path& from, const path& to, copy_options option); + bool copy_file(const path& from, const path& to, copy_options option, + error_code& ec); + + void copy_symlink(const path& existing_symlink, const path& new_symlink); + void copy_symlink(const path& existing_symlink, const path& new_symlink, + error_code& ec) noexcept; + + bool create_directories(const path& p); + bool create_directories(const path& p, error_code& ec); + + bool create_directory(const path& p); + bool create_directory(const path& p, error_code& ec) noexcept; + + bool create_directory(const path& p, const path& attributes); + bool create_directory(const path& p, const path& attributes, + error_code& ec) noexcept; + + void create_directory_symlink(const path& to, const path& new_symlink); + void create_directory_symlink(const path& to, const path& new_symlink, + error_code& ec) noexcept; + + void create_hard_link(const path& to, const path& new_hard_link); + void create_hard_link(const path& to, const path& new_hard_link, + error_code& ec) noexcept; + + void create_symlink(const path& to, const path& new_symlink); + void create_symlink(const path& to, const path& new_symlink, + error_code& ec) noexcept; + + path current_path(); + path current_path(error_code& ec); + void current_path(const path& p); + void current_path(const path& p, error_code& ec) noexcept; + + bool exists(file_status s) noexcept; + bool exists(const path& p); + bool exists(const path& p, error_code& ec) noexcept; + + bool equivalent(const path& p1, const path& p2); + bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept; + + uintmax_t file_size(const path& p); + uintmax_t file_size(const path& p, error_code& ec) noexcept; + + uintmax_t hard_link_count(const path& p); + uintmax_t hard_link_count(const path& p, error_code& ec) noexcept; + + bool is_block_file(file_status s) noexcept; + bool is_block_file(const path& p); + bool is_block_file(const path& p, error_code& ec) noexcept; + + bool is_character_file(file_status s) noexcept; + bool is_character_file(const path& p); + bool is_character_file(const path& p, error_code& ec) noexcept; + + bool is_directory(file_status s) noexcept; + bool is_directory(const path& p); + bool is_directory(const path& p, error_code& ec) noexcept; + + bool is_empty(const path& p); + bool is_empty(const path& p, error_code& ec) noexcept; + + bool is_fifo(file_status s) noexcept; + bool is_fifo(const path& p); + bool is_fifo(const path& p, error_code& ec) noexcept; + + bool is_other(file_status s) noexcept; + bool is_other(const path& p); + bool is_other(const path& p, error_code& ec) noexcept; + + bool is_regular_file(file_status s) noexcept; + bool is_regular_file(const path& p); + bool is_regular_file(const path& p, error_code& ec) noexcept; + + bool is_socket(file_status s) noexcept; + bool is_socket(const path& p); + bool is_socket(const path& p, error_code& ec) noexcept; + + bool is_symlink(file_status s) noexcept; + bool is_symlink(const path& p); + bool is_symlink(const path& p, error_code& ec) noexcept; + + file_time_type last_write_time(const path& p); + file_time_type last_write_time(const path& p, error_code& ec) noexcept; + void last_write_time(const path& p, file_time_type new_time); + void last_write_time(const path& p, file_time_type new_time, + error_code& ec) noexcept; + + void permissions(const path& p, perms prms, + perm_options opts=perm_options::replace); + void permissions(const path& p, perms prms, error_code& ec) noexcept; + void permissions(const path& p, perms prms, perm_options opts, + error_code& ec); + + path proximate(const path& p, error_code& ec); + path proximate(const path& p, const path& base = current_path()); + path proximate(const path& p, const path& base, error_code &ec); + + path read_symlink(const path& p); + path read_symlink(const path& p, error_code& ec); + + path relative(const path& p, error_code& ec); + path relative(const path& p, const path& base=current_path()); + path relative(const path& p, const path& base, error_code& ec); + + bool remove(const path& p); + bool remove(const path& p, error_code& ec) noexcept; + + uintmax_t remove_all(const path& p); + uintmax_t remove_all(const path& p, error_code& ec); + + void rename(const path& from, const path& to); + void rename(const path& from, const path& to, error_code& ec) noexcept; + + void resize_file(const path& p, uintmax_t size); + void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept; + + space_info space(const path& p); + space_info space(const path& p, error_code& ec) noexcept; + + file_status status(const path& p); + file_status status(const path& p, error_code& ec) noexcept; + + bool status_known(file_status s) noexcept; + + file_status symlink_status(const path& p); + file_status symlink_status(const path& p, error_code& ec) noexcept; + + path temp_directory_path(); + path temp_directory_path(error_code& ec); + + path weakly_canonical(path const& p); + path weakly_canonical(path const& p, error_code& ec); + + +} } } } // namespaces std::experimental::filesystem::v1 + +*/ + +#include <experimental/__config> +#include <filesystem> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#ifndef _LIBCPP_CXX03_LANG + +#define __cpp_lib_experimental_filesystem 201406 + +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM + +using namespace _VSTD_FS; + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM + +#endif // !_LIBCPP_CXX03_LANG + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM diff --git a/android/x86/include/v8/libc++/experimental/forward_list b/android/x86/include/v8/libc++/experimental/forward_list new file mode 100755 index 00000000..93f6debe --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/forward_list @@ -0,0 +1,46 @@ +// -*- C++ -*- +//===--------------------------- forward_list -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_FORWARD_LIST +#define _LIBCPP_EXPERIMENTAL_FORWARD_LIST +/* + experimental/forward_list synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + template <class T> + using forward_list = std::forward_list<T,polymorphic_allocator<T>>; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <forward_list> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _ValueT> +using forward_list = _VSTD::forward_list<_ValueT, polymorphic_allocator<_ValueT>>; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_FORWARD_LIST */ diff --git a/android/x86/include/v8/libc++/experimental/functional b/android/x86/include/v8/libc++/experimental/functional new file mode 100755 index 00000000..755eda64 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/functional @@ -0,0 +1,458 @@ +// -*- C++ -*- +//===-------------------------- functional --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_FUNCTIONAL +#define _LIBCPP_EXPERIMENTAL_FUNCTIONAL + +/* + experimental/functional synopsis + +#include <algorithm> + +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { + + // See C++14 20.9.9, Function object binders + template <class T> constexpr bool is_bind_expression_v + = is_bind_expression<T>::value; + template <class T> constexpr int is_placeholder_v + = is_placeholder<T>::value; + + // 4.2, Class template function + template<class> class function; // undefined + template<class R, class... ArgTypes> class function<R(ArgTypes...)>; + + template<class R, class... ArgTypes> + void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&); + + template<class R, class... ArgTypes> + bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; + template<class R, class... ArgTypes> + bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; + template<class R, class... ArgTypes> + bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; + template<class R, class... ArgTypes> + bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; + + // 4.3, Searchers + template<class ForwardIterator, class BinaryPredicate = equal_to<>> + class default_searcher; + + template<class RandomAccessIterator, + class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, + class BinaryPredicate = equal_to<>> + class boyer_moore_searcher; + + template<class RandomAccessIterator, + class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, + class BinaryPredicate = equal_to<>> + class boyer_moore_horspool_searcher; + + template<class ForwardIterator, class BinaryPredicate = equal_to<>> + default_searcher<ForwardIterator, BinaryPredicate> + make_default_searcher(ForwardIterator pat_first, ForwardIterator pat_last, + BinaryPredicate pred = BinaryPredicate()); + + template<class RandomAccessIterator, + class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, + class BinaryPredicate = equal_to<>> + boyer_moore_searcher<RandomAccessIterator, Hash, BinaryPredicate> + make_boyer_moore_searcher( + RandomAccessIterator pat_first, RandomAccessIterator pat_last, + Hash hf = Hash(), BinaryPredicate pred = BinaryPredicate()); + + template<class RandomAccessIterator, + class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, + class BinaryPredicate = equal_to<>> + boyer_moore_horspool_searcher<RandomAccessIterator, Hash, BinaryPredicate> + make_boyer_moore_horspool_searcher( + RandomAccessIterator pat_first, RandomAccessIterator pat_last, + Hash hf = Hash(), BinaryPredicate pred = BinaryPredicate()); + + } // namespace fundamentals_v1 + } // namespace experimental + + template<class R, class... ArgTypes, class Alloc> + struct uses_allocator<experimental::function<R(ArgTypes...)>, Alloc>; + +} // namespace std + +*/ + +#include <experimental/__config> +#include <functional> +#include <algorithm> +#include <type_traits> +#include <vector> +#include <array> +#include <unordered_map> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_LFTS + +#if _LIBCPP_STD_VER > 11 +// default searcher +template<class _ForwardIterator, class _BinaryPredicate = equal_to<>> +class _LIBCPP_TYPE_VIS default_searcher { +public: + _LIBCPP_INLINE_VISIBILITY + default_searcher(_ForwardIterator __f, _ForwardIterator __l, + _BinaryPredicate __p = _BinaryPredicate()) + : __first_(__f), __last_(__l), __pred_(__p) {} + + template <typename _ForwardIterator2> + _LIBCPP_INLINE_VISIBILITY + pair<_ForwardIterator2, _ForwardIterator2> + operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const + { + return _VSTD::__search(__f, __l, __first_, __last_, __pred_, + typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(), + typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category()); + } + +private: + _ForwardIterator __first_; + _ForwardIterator __last_; + _BinaryPredicate __pred_; + }; + +template<class _ForwardIterator, class _BinaryPredicate = equal_to<>> +_LIBCPP_INLINE_VISIBILITY +default_searcher<_ForwardIterator, _BinaryPredicate> +make_default_searcher( _ForwardIterator __f, _ForwardIterator __l, _BinaryPredicate __p = _BinaryPredicate ()) +{ + return default_searcher<_ForwardIterator, _BinaryPredicate>(__f, __l, __p); +} + +template<class _Key, class _Value, class _Hash, class _BinaryPredicate, bool /*useArray*/> class _BMSkipTable; + +// General case for BM data searching; use a map +template<class _Key, typename _Value, class _Hash, class _BinaryPredicate> +class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, false> { +public: // TODO private: + typedef _Value value_type; + typedef _Key key_type; + + const _Value __default_value_; + std::unordered_map<_Key, _Value, _Hash, _BinaryPredicate> __table; + +public: + _LIBCPP_INLINE_VISIBILITY + _BMSkipTable(std::size_t __sz, _Value __default, _Hash __hf, _BinaryPredicate __pred) + : __default_value_(__default), __table(__sz, __hf, __pred) {} + + _LIBCPP_INLINE_VISIBILITY + void insert(const key_type &__key, value_type __val) + { + __table [__key] = __val; // Would skip_.insert (val) be better here? + } + + _LIBCPP_INLINE_VISIBILITY + value_type operator [](const key_type & __key) const + { + auto __it = __table.find (__key); + return __it == __table.end() ? __default_value_ : __it->second; + } +}; + + +// Special case small numeric values; use an array +template<class _Key, typename _Value, class _Hash, class _BinaryPredicate> +class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, true> { +private: + typedef _Value value_type; + typedef _Key key_type; + + typedef typename std::make_unsigned<key_type>::type unsigned_key_type; + typedef std::array<value_type, _VSTD::numeric_limits<unsigned_key_type>::max()> skip_map; + skip_map __table; + +public: + _LIBCPP_INLINE_VISIBILITY + _BMSkipTable(std::size_t /*__sz*/, _Value __default, _Hash /*__hf*/, _BinaryPredicate /*__pred*/) + { + std::fill_n(__table.begin(), __table.size(), __default); + } + + _LIBCPP_INLINE_VISIBILITY + void insert(key_type __key, value_type __val) + { + __table[static_cast<unsigned_key_type>(__key)] = __val; + } + + _LIBCPP_INLINE_VISIBILITY + value_type operator [](key_type __key) const + { + return __table[static_cast<unsigned_key_type>(__key)]; + } +}; + + +template <class _RandomAccessIterator1, + class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>, + class _BinaryPredicate = equal_to<>> +class _LIBCPP_TYPE_VIS boyer_moore_searcher { +private: + typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type difference_type; + typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type value_type; + typedef _BMSkipTable<value_type, difference_type, _Hash, _BinaryPredicate, + _VSTD::is_integral<value_type>::value && // what about enums? + sizeof(value_type) == 1 && + is_same<_Hash, hash<value_type>>::value && + is_same<_BinaryPredicate, equal_to<>>::value + > skip_table_type; + +public: + boyer_moore_searcher(_RandomAccessIterator1 __f, _RandomAccessIterator1 __l, + _Hash __hf = _Hash(), _BinaryPredicate __pred = _BinaryPredicate()) + : __first_(__f), __last_(__l), __pred_(__pred), + __pattern_length_(_VSTD::distance(__first_, __last_)), + __skip_{make_shared<skip_table_type>(__pattern_length_, -1, __hf, __pred_)}, + __suffix_{make_shared<vector<difference_type>>(__pattern_length_ + 1)} + { + // build the skip table + for ( difference_type __i = 0; __f != __l; ++__f, (void) ++__i ) + __skip_->insert(*__f, __i); + + this->__build_suffix_table ( __first_, __last_, __pred_ ); + } + + template <typename _RandomAccessIterator2> + pair<_RandomAccessIterator2, _RandomAccessIterator2> + operator ()(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const + { + static_assert ( std::is_same< + typename std::__uncvref<typename std::iterator_traits<_RandomAccessIterator1>::value_type>::type, + typename std::__uncvref<typename std::iterator_traits<_RandomAccessIterator2>::value_type>::type + >::value, + "Corpus and Pattern iterators must point to the same type" ); + + if (__f == __l ) return make_pair(__l, __l); // empty corpus + if (__first_ == __last_) return make_pair(__f, __f); // empty pattern + + // If the pattern is larger than the corpus, we can't find it! + if ( __pattern_length_ > _VSTD::distance (__f, __l)) + return make_pair(__l, __l); + + // Do the search + return this->__search(__f, __l); + } + +public: // TODO private: + _RandomAccessIterator1 __first_; + _RandomAccessIterator1 __last_; + _BinaryPredicate __pred_; + difference_type __pattern_length_; + shared_ptr<skip_table_type> __skip_; + shared_ptr<vector<difference_type>> __suffix_; + + template <typename _RandomAccessIterator2> + pair<_RandomAccessIterator2, _RandomAccessIterator2> + __search(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const + { + _RandomAccessIterator2 __cur = __f; + const _RandomAccessIterator2 __last = __l - __pattern_length_; + const skip_table_type & __skip = *__skip_.get(); + const vector<difference_type> & __suffix = *__suffix_.get(); + + while (__cur <= __last) + { + + // Do we match right where we are? + difference_type __j = __pattern_length_; + while (__pred_(__first_ [__j-1], __cur [__j-1])) { + __j--; + // We matched - we're done! + if ( __j == 0 ) + return make_pair(__cur, __cur + __pattern_length_); + } + + // Since we didn't match, figure out how far to skip forward + difference_type __k = __skip[__cur [ __j - 1 ]]; + difference_type __m = __j - __k - 1; + if (__k < __j && __m > __suffix[ __j ]) + __cur += __m; + else + __cur += __suffix[ __j ]; + } + + return make_pair(__l, __l); // We didn't find anything + } + + + template<typename _Iterator, typename _Container> + void __compute_bm_prefix ( _Iterator __f, _Iterator __l, _BinaryPredicate __pred, _Container &__prefix ) + { + const std::size_t __count = _VSTD::distance(__f, __l); + + __prefix[0] = 0; + std::size_t __k = 0; + for ( std::size_t __i = 1; __i < __count; ++__i ) + { + while ( __k > 0 && !__pred ( __f[__k], __f[__i] )) + __k = __prefix [ __k - 1 ]; + + if ( __pred ( __f[__k], __f[__i] )) + __k++; + __prefix [ __i ] = __k; + } + } + + void __build_suffix_table(_RandomAccessIterator1 __f, _RandomAccessIterator1 __l, + _BinaryPredicate __pred) + { + const std::size_t __count = _VSTD::distance(__f, __l); + vector<difference_type> & __suffix = *__suffix_.get(); + if (__count > 0) + { + _VSTD::vector<value_type> __scratch(__count); + + __compute_bm_prefix(__f, __l, __pred, __scratch); + for ( std::size_t __i = 0; __i <= __count; __i++ ) + __suffix[__i] = __count - __scratch[__count-1]; + + typedef _VSTD::reverse_iterator<_RandomAccessIterator1> _RevIter; + __compute_bm_prefix(_RevIter(__l), _RevIter(__f), __pred, __scratch); + + for ( std::size_t __i = 0; __i < __count; __i++ ) + { + const std::size_t __j = __count - __scratch[__i]; + const difference_type __k = __i - __scratch[__i] + 1; + + if (__suffix[__j] > __k) + __suffix[__j] = __k; + } + } + } + +}; + +template<class _RandomAccessIterator, + class _Hash = hash<typename iterator_traits<_RandomAccessIterator>::value_type>, + class _BinaryPredicate = equal_to<>> +_LIBCPP_INLINE_VISIBILITY +boyer_moore_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate> +make_boyer_moore_searcher( _RandomAccessIterator __f, _RandomAccessIterator __l, + _Hash __hf = _Hash(), _BinaryPredicate __p = _BinaryPredicate ()) +{ + return boyer_moore_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate>(__f, __l, __hf, __p); +} + +// boyer-moore-horspool +template <class _RandomAccessIterator1, + class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>, + class _BinaryPredicate = equal_to<>> +class _LIBCPP_TYPE_VIS boyer_moore_horspool_searcher { +private: + typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type difference_type; + typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type value_type; + typedef _BMSkipTable<value_type, difference_type, _Hash, _BinaryPredicate, + _VSTD::is_integral<value_type>::value && // what about enums? + sizeof(value_type) == 1 && + is_same<_Hash, hash<value_type>>::value && + is_same<_BinaryPredicate, equal_to<>>::value + > skip_table_type; + +public: + boyer_moore_horspool_searcher(_RandomAccessIterator1 __f, _RandomAccessIterator1 __l, + _Hash __hf = _Hash(), _BinaryPredicate __pred = _BinaryPredicate()) + : __first_(__f), __last_(__l), __pred_(__pred), + __pattern_length_(_VSTD::distance(__first_, __last_)), + __skip_{_VSTD::make_shared<skip_table_type>(__pattern_length_, __pattern_length_, __hf, __pred_)} + { + // build the skip table + if ( __f != __l ) + { + __l = __l - 1; + for ( difference_type __i = 0; __f != __l; ++__f, (void) ++__i ) + __skip_->insert(*__f, __pattern_length_ - 1 - __i); + } + } + + template <typename _RandomAccessIterator2> + pair<_RandomAccessIterator2, _RandomAccessIterator2> + operator ()(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const + { + static_assert ( std::is_same< + typename std::__uncvref<typename std::iterator_traits<_RandomAccessIterator1>::value_type>::type, + typename std::__uncvref<typename std::iterator_traits<_RandomAccessIterator2>::value_type>::type + >::value, + "Corpus and Pattern iterators must point to the same type" ); + + if (__f == __l ) return make_pair(__l, __l); // empty corpus + if (__first_ == __last_) return make_pair(__f, __f); // empty pattern + + // If the pattern is larger than the corpus, we can't find it! + if ( __pattern_length_ > _VSTD::distance (__f, __l)) + return make_pair(__l, __l); + + // Do the search + return this->__search(__f, __l); + } + +private: + _RandomAccessIterator1 __first_; + _RandomAccessIterator1 __last_; + _BinaryPredicate __pred_; + difference_type __pattern_length_; + shared_ptr<skip_table_type> __skip_; + + template <typename _RandomAccessIterator2> + pair<_RandomAccessIterator2, _RandomAccessIterator2> + __search ( _RandomAccessIterator2 __f, _RandomAccessIterator2 __l ) const { + _RandomAccessIterator2 __cur = __f; + const _RandomAccessIterator2 __last = __l - __pattern_length_; + const skip_table_type & __skip = *__skip_.get(); + + while (__cur <= __last) + { + // Do we match right where we are? + difference_type __j = __pattern_length_; + while (__pred_(__first_[__j-1], __cur[__j-1])) + { + __j--; + // We matched - we're done! + if ( __j == 0 ) + return make_pair(__cur, __cur + __pattern_length_); + } + __cur += __skip[__cur[__pattern_length_-1]]; + } + + return make_pair(__l, __l); + } +}; + +template<class _RandomAccessIterator, + class _Hash = hash<typename iterator_traits<_RandomAccessIterator>::value_type>, + class _BinaryPredicate = equal_to<>> +_LIBCPP_INLINE_VISIBILITY +boyer_moore_horspool_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate> +make_boyer_moore_horspool_searcher( _RandomAccessIterator __f, _RandomAccessIterator __l, + _Hash __hf = _Hash(), _BinaryPredicate __p = _BinaryPredicate ()) +{ + return boyer_moore_horspool_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate>(__f, __l, __hf, __p); +} + +#endif // _LIBCPP_STD_VER > 11 + +_LIBCPP_END_NAMESPACE_LFTS + +_LIBCPP_POP_MACROS + +#endif /* _LIBCPP_EXPERIMENTAL_FUNCTIONAL */ diff --git a/android/x86/include/v8/libc++/experimental/iterator b/android/x86/include/v8/libc++/experimental/iterator new file mode 100755 index 00000000..6a6e51d8 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/iterator @@ -0,0 +1,113 @@ +// -*- C++ -*- +//===----------------------------- iterator -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_ITERATOR +#define _LIBCPP_EXPERIMENTAL_ITERATOR + +/* +namespace std { + namespace experimental { + inline namespace fundamentals_v2 { + + template <class DelimT, class charT = char, class traits = char_traits<charT>> + class ostream_joiner { + public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_ostream<charT, traits> ostream_type; + typedef output_iterator_tag iterator_category; + typedef void value_type; + typedef void difference_type; + typedef void pointer; + typedef void reference; + + ostream_joiner(ostream_type& s, const DelimT& delimiter); + ostream_joiner(ostream_type& s, DelimT&& delimiter); + + template<typename T> + ostream_joiner& operator=(const T& value); + + ostream_joiner& operator*() noexcept; + ostream_joiner& operator++() noexcept; + ostream_joiner& operator++(int) noexcept; + private: + ostream_type* out_stream; // exposition only + DelimT delim; // exposition only + bool first_element; // exposition only + }; + + template <class charT, class traits, class DelimT> + ostream_joiner<decay_t<DelimT>, charT, traits> + make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter); + + } // inline namespace fundamentals_v2 + } // namespace experimental +} // namespace std + +*/ + +#include <experimental/__config> + +#if _LIBCPP_STD_VER > 11 + +#include <iterator> + +_LIBCPP_BEGIN_NAMESPACE_LFTS + +template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>> +class ostream_joiner { +public: + + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_ostream<char_type,traits_type> ostream_type; + typedef output_iterator_tag iterator_category; + typedef void value_type; + typedef void difference_type; + typedef void pointer; + typedef void reference; + + ostream_joiner(ostream_type& __os, _Delim&& __d) + : __output_iter(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {} + + ostream_joiner(ostream_type& __os, const _Delim& __d) + : __output_iter(_VSTD::addressof(__os)), __delim(__d), __first(true) {} + + + template<typename _Tp> + ostream_joiner& operator=(const _Tp& __v) + { + if (!__first) + *__output_iter << __delim; + __first = false; + *__output_iter << __v; + return *this; + } + + ostream_joiner& operator*() _NOEXCEPT { return *this; } + ostream_joiner& operator++() _NOEXCEPT { return *this; } + ostream_joiner& operator++(int) _NOEXCEPT { return *this; } + +private: + ostream_type* __output_iter; + _Delim __delim; + bool __first; +}; + + +template <class _CharT, class _Traits, class _Delim> +ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits> +make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d) +{ return ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); } + +_LIBCPP_END_NAMESPACE_LFTS + +#endif /* _LIBCPP_STD_VER > 11 */ + +#endif // _LIBCPP_EXPERIMENTAL_ITERATOR diff --git a/android/x86/include/v8/libc++/experimental/list b/android/x86/include/v8/libc++/experimental/list new file mode 100755 index 00000000..adc64a8b --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/list @@ -0,0 +1,46 @@ +// -*- C++ -*- +//===--------------------------- list ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_LIST +#define _LIBCPP_EXPERIMENTAL_LIST +/* + experimental/list synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + template <class T> + using list = std::list<T,polymorphic_allocator<T>>; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <list> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _ValueT> +using list = _VSTD::list<_ValueT, polymorphic_allocator<_ValueT>>; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_LIST */ diff --git a/android/x86/include/v8/libc++/experimental/map b/android/x86/include/v8/libc++/experimental/map new file mode 100755 index 00000000..965d7582 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/map @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------- map ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_MAP +#define _LIBCPP_EXPERIMENTAL_MAP +/* + experimental/map synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + template <class Key, class T, class Compare = less<Key>> + using map = std::map<Key, T, Compare, + polymorphic_allocator<pair<const Key,T>>>; + + template <class Key, class T, class Compare = less<Key>> + using multimap = std::multimap<Key, T, Compare, + polymorphic_allocator<pair<const Key,T>>>; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <map> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _Key, class _Value, class _Compare = less<_Key>> +using map = _VSTD::map<_Key, _Value, _Compare, + polymorphic_allocator<pair<const _Key, _Value>>>; + +template <class _Key, class _Value, class _Compare = less<_Key>> +using multimap = _VSTD::multimap<_Key, _Value, _Compare, + polymorphic_allocator<pair<const _Key, _Value>>>; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_MAP */ diff --git a/android/x86/include/v8/libc++/experimental/memory_resource b/android/x86/include/v8/libc++/experimental/memory_resource new file mode 100755 index 00000000..f999fb9b --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/memory_resource @@ -0,0 +1,426 @@ +// -*- C++ -*- +//===------------------------ memory_resource -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_MEMORY_RESOURCE +#define _LIBCPP_EXPERIMENTAL_MEMORY_RESOURCE + +/** + experimental/memory_resource synopsis + +// C++1y + +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + class memory_resource; + + bool operator==(const memory_resource& a, + const memory_resource& b) noexcept; + bool operator!=(const memory_resource& a, + const memory_resource& b) noexcept; + + template <class Tp> class polymorphic_allocator; + + template <class T1, class T2> + bool operator==(const polymorphic_allocator<T1>& a, + const polymorphic_allocator<T2>& b) noexcept; + template <class T1, class T2> + bool operator!=(const polymorphic_allocator<T1>& a, + const polymorphic_allocator<T2>& b) noexcept; + + // The name resource_adaptor_imp is for exposition only. + template <class Allocator> class resource_adaptor_imp; + + template <class Allocator> + using resource_adaptor = resource_adaptor_imp< + allocator_traits<Allocator>::rebind_alloc<char>>; + + // Global memory resources + memory_resource* new_delete_resource() noexcept; + memory_resource* null_memory_resource() noexcept; + + // The default memory resource + memory_resource* set_default_resource(memory_resource* r) noexcept; + memory_resource* get_default_resource() noexcept; + + // Standard memory resources + struct pool_options; + class synchronized_pool_resource; + class unsynchronized_pool_resource; + class monotonic_buffer_resource; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <experimental/__memory> +#include <limits> +#include <memory> +#include <new> +#include <stdexcept> +#include <__tuple> +#include <type_traits> +#include <utility> +#include <cstddef> +#include <cstdlib> +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +// Round __s up to next multiple of __a. +inline _LIBCPP_INLINE_VISIBILITY +size_t __aligned_allocation_size(size_t __s, size_t __a) _NOEXCEPT +{ + _LIBCPP_ASSERT(__s + __a > __s, "aligned allocation size overflows"); + return (__s + __a - 1) & ~(__a - 1); +} + +// 8.5, memory.resource +class _LIBCPP_TYPE_VIS memory_resource +{ + static const size_t __max_align = _LIBCPP_ALIGNOF(max_align_t); + +// 8.5.2, memory.resource.public +public: + virtual ~memory_resource() = default; + + _LIBCPP_INLINE_VISIBILITY + void* allocate(size_t __bytes, size_t __align = __max_align) + { return do_allocate(__bytes, __align); } + + _LIBCPP_INLINE_VISIBILITY + void deallocate(void * __p, size_t __bytes, size_t __align = __max_align) + { do_deallocate(__p, __bytes, __align); } + + _LIBCPP_INLINE_VISIBILITY + bool is_equal(memory_resource const & __other) const _NOEXCEPT + { return do_is_equal(__other); } + +// 8.5.3, memory.resource.priv +protected: + virtual void* do_allocate(size_t, size_t) = 0; + virtual void do_deallocate(void*, size_t, size_t) = 0; + virtual bool do_is_equal(memory_resource const &) const _NOEXCEPT = 0; +}; + +// 8.5.4, memory.resource.eq +inline _LIBCPP_INLINE_VISIBILITY +bool operator==(memory_resource const & __lhs, + memory_resource const & __rhs) _NOEXCEPT +{ + return &__lhs == &__rhs || __lhs.is_equal(__rhs); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(memory_resource const & __lhs, + memory_resource const & __rhs) _NOEXCEPT +{ + return !(__lhs == __rhs); +} + +_LIBCPP_FUNC_VIS +memory_resource * new_delete_resource() _NOEXCEPT; + +_LIBCPP_FUNC_VIS +memory_resource * null_memory_resource() _NOEXCEPT; + +_LIBCPP_FUNC_VIS +memory_resource * get_default_resource() _NOEXCEPT; + +_LIBCPP_FUNC_VIS +memory_resource * set_default_resource(memory_resource * __new_res) _NOEXCEPT; + +// 8.6, memory.polymorphic.allocator.class + +// 8.6.1, memory.polymorphic.allocator.overview +template <class _ValueType> +class _LIBCPP_TEMPLATE_VIS polymorphic_allocator +{ +public: + typedef _ValueType value_type; + + // 8.6.2, memory.polymorphic.allocator.ctor + _LIBCPP_INLINE_VISIBILITY + polymorphic_allocator() _NOEXCEPT + : __res_(_VSTD_LFTS_PMR::get_default_resource()) + {} + + _LIBCPP_INLINE_VISIBILITY + polymorphic_allocator(memory_resource * __r) _NOEXCEPT + : __res_(__r) + {} + + polymorphic_allocator(polymorphic_allocator const &) = default; + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + polymorphic_allocator(polymorphic_allocator<_Tp> const & __other) _NOEXCEPT + : __res_(__other.resource()) + {} + + polymorphic_allocator & + operator=(polymorphic_allocator const &) = delete; + + // 8.6.3, memory.polymorphic.allocator.mem + _LIBCPP_INLINE_VISIBILITY + _ValueType* allocate(size_t __n) { + if (__n > __max_size()) { + __throw_length_error( + "std::experimental::pmr::polymorphic_allocator<T>::allocate(size_t n)" + " 'n' exceeds maximum supported size"); + } + return static_cast<_ValueType*>( + __res_->allocate(__n * sizeof(_ValueType), _LIBCPP_ALIGNOF(_ValueType)) + ); + } + + _LIBCPP_INLINE_VISIBILITY + void deallocate(_ValueType * __p, size_t __n) _NOEXCEPT { + _LIBCPP_ASSERT(__n <= __max_size(), + "deallocate called for size which exceeds max_size()"); + __res_->deallocate(__p, __n * sizeof(_ValueType), _LIBCPP_ALIGNOF(_ValueType)); + } + + template <class _Tp, class ..._Ts> + _LIBCPP_INLINE_VISIBILITY + void construct(_Tp* __p, _Ts &&... __args) + { + _VSTD_LFTS::__lfts_user_alloc_construct( + __p, *this, _VSTD::forward<_Ts>(__args)... + ); + } + + template <class _T1, class _T2, class ..._Args1, class ..._Args2> + _LIBCPP_INLINE_VISIBILITY + void construct(pair<_T1, _T2>* __p, piecewise_construct_t, + tuple<_Args1...> __x, tuple<_Args2...> __y) + { + ::new ((void*)__p) pair<_T1, _T2>(piecewise_construct + , __transform_tuple( + typename __lfts_uses_alloc_ctor< + _T1, polymorphic_allocator&, _Args1... + >::type() + , _VSTD::move(__x) + , typename __make_tuple_indices<sizeof...(_Args1)>::type{} + ) + , __transform_tuple( + typename __lfts_uses_alloc_ctor< + _T2, polymorphic_allocator&, _Args2... + >::type() + , _VSTD::move(__y) + , typename __make_tuple_indices<sizeof...(_Args2)>::type{} + ) + ); + } + + template <class _T1, class _T2> + _LIBCPP_INLINE_VISIBILITY + void construct(pair<_T1, _T2>* __p) { + construct(__p, piecewise_construct, tuple<>(), tuple<>()); + } + + template <class _T1, class _T2, class _Up, class _Vp> + _LIBCPP_INLINE_VISIBILITY + void construct(pair<_T1, _T2> * __p, _Up && __u, _Vp && __v) { + construct(__p, piecewise_construct + , _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__u)) + , _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__v))); + } + + template <class _T1, class _T2, class _U1, class _U2> + _LIBCPP_INLINE_VISIBILITY + void construct(pair<_T1, _T2> * __p, pair<_U1, _U2> const & __pr) { + construct(__p, piecewise_construct + , _VSTD::forward_as_tuple(__pr.first) + , _VSTD::forward_as_tuple(__pr.second)); + } + + template <class _T1, class _T2, class _U1, class _U2> + _LIBCPP_INLINE_VISIBILITY + void construct(pair<_T1, _T2> * __p, pair<_U1, _U2> && __pr){ + construct(__p, piecewise_construct + , _VSTD::forward_as_tuple(_VSTD::forward<_U1>(__pr.first)) + , _VSTD::forward_as_tuple(_VSTD::forward<_U2>(__pr.second))); + } + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + void destroy(_Tp * __p) _NOEXCEPT + { __p->~_Tp(); } + + _LIBCPP_INLINE_VISIBILITY + polymorphic_allocator + select_on_container_copy_construction() const _NOEXCEPT + { return polymorphic_allocator(); } + + _LIBCPP_INLINE_VISIBILITY + memory_resource * resource() const _NOEXCEPT + { return __res_; } + +private: + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<_Args&&...> + __transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t, + __tuple_indices<_Idx...>) const + { + return _VSTD::forward_as_tuple(_VSTD::get<_Idx>(_VSTD::move(__t))...); + } + + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<allocator_arg_t const&, polymorphic_allocator&, _Args&&...> + __transform_tuple(integral_constant<int, 1>, tuple<_Args...> && __t, + __tuple_indices<_Idx...>) + { + using _Tup = tuple<allocator_arg_t const&, polymorphic_allocator&, _Args&&...>; + return _Tup(allocator_arg, *this, + _VSTD::get<_Idx>(_VSTD::move(__t))...); + } + + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<_Args&&..., polymorphic_allocator&> + __transform_tuple(integral_constant<int, 2>, tuple<_Args...> && __t, + __tuple_indices<_Idx...>) + { + using _Tup = tuple<_Args&&..., polymorphic_allocator&>; + return _Tup(_VSTD::get<_Idx>(_VSTD::move(__t))..., *this); + } + + _LIBCPP_INLINE_VISIBILITY + size_t __max_size() const _NOEXCEPT + { return numeric_limits<size_t>::max() / sizeof(value_type); } + + memory_resource * __res_; +}; + +// 8.6.4, memory.polymorphic.allocator.eq + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool operator==(polymorphic_allocator<_Tp> const & __lhs, + polymorphic_allocator<_Up> const & __rhs) _NOEXCEPT +{ + return *__lhs.resource() == *__rhs.resource(); +} + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(polymorphic_allocator<_Tp> const & __lhs, + polymorphic_allocator<_Up> const & __rhs) _NOEXCEPT +{ + return !(__lhs == __rhs); +} + +// 8.7, memory.resource.adaptor + +// 8.7.1, memory.resource.adaptor.overview +template <class _CharAlloc> +class _LIBCPP_TEMPLATE_VIS __resource_adaptor_imp + : public memory_resource +{ + using _CTraits = allocator_traits<_CharAlloc>; + static_assert(is_same<typename _CTraits::value_type, char>::value + && is_same<typename _CTraits::pointer, char*>::value + && is_same<typename _CTraits::void_pointer, void*>::value, ""); + + static const size_t _MaxAlign = _LIBCPP_ALIGNOF(max_align_t); + + using _Alloc = typename _CTraits::template rebind_alloc< + typename aligned_storage<_MaxAlign, _MaxAlign>::type + >; + + using _ValueType = typename _Alloc::value_type; + + _Alloc __alloc_; + +public: + typedef _CharAlloc allocator_type; + + __resource_adaptor_imp() = default; + __resource_adaptor_imp(__resource_adaptor_imp const &) = default; + __resource_adaptor_imp(__resource_adaptor_imp &&) = default; + + // 8.7.2, memory.resource.adaptor.ctor + + _LIBCPP_INLINE_VISIBILITY + explicit __resource_adaptor_imp(allocator_type const & __a) + : __alloc_(__a) + {} + + _LIBCPP_INLINE_VISIBILITY + explicit __resource_adaptor_imp(allocator_type && __a) + : __alloc_(_VSTD::move(__a)) + {} + + __resource_adaptor_imp & + operator=(__resource_adaptor_imp const &) = default; + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const + { return __alloc_; } + +// 8.7.3, memory.resource.adaptor.mem +protected: + virtual void * do_allocate(size_t __bytes, size_t) + { + if (__bytes > __max_size()) { + __throw_length_error( + "std::experimental::pmr::resource_adaptor<T>::do_allocate(size_t bytes, size_t align)" + " 'bytes' exceeds maximum supported size"); + } + size_t __s = __aligned_allocation_size(__bytes, _MaxAlign) / _MaxAlign; + return __alloc_.allocate(__s); + } + + virtual void do_deallocate(void * __p, size_t __bytes, size_t) + { + _LIBCPP_ASSERT(__bytes <= __max_size(), + "do_deallocate called for size which exceeds the maximum allocation size"); + size_t __s = __aligned_allocation_size(__bytes, _MaxAlign) / _MaxAlign; + __alloc_.deallocate((_ValueType*)__p, __s); + } + + virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT { + __resource_adaptor_imp const * __p + = dynamic_cast<__resource_adaptor_imp const *>(&__other); + return __p ? __alloc_ == __p->__alloc_ : false; + } + +private: + _LIBCPP_INLINE_VISIBILITY + size_t __max_size() const _NOEXCEPT { + return numeric_limits<size_t>::max() - _MaxAlign; + } +}; + +template <class _Alloc> +using resource_adaptor = __resource_adaptor_imp< + typename allocator_traits<_Alloc>::template rebind_alloc<char> + >; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +_LIBCPP_POP_MACROS + +#endif /* _LIBCPP_EXPERIMENTAL_MEMORY_RESOURCE */ diff --git a/android/x86/include/v8/libc++/experimental/numeric b/android/x86/include/v8/libc++/experimental/numeric new file mode 100755 index 00000000..4ea1306b --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/numeric @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===--------------------------- numeric ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_NUMERIC +#define _LIBCPP_EXPERIMENTAL_NUMERIC + +#include <__config> + +#ifdef _LIBCPP_WARNING +_LIBCPP_WARNING("<experimental/numeric> has been removed. Use <numeric> instead.") +#else +# warning "<experimental/numeric> has been removed. Use <numeric> instead." +#endif + +#endif // _LIBCPP_EXPERIMENTAL_NUMERIC diff --git a/android/x86/include/v8/libc++/experimental/optional b/android/x86/include/v8/libc++/experimental/optional new file mode 100755 index 00000000..1749cd6a --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/optional @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===-------------------------- optional ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_OPTIONAL +#define _LIBCPP_EXPERIMENTAL_OPTIONAL + +#include <__config> + +#ifdef _LIBCPP_WARNING +_LIBCPP_WARNING("<experimental/optional> has been removed. Use <optional> instead.") +#else +# warning "<experimental/optional> has been removed. Use <optional> instead." +#endif + +#endif // _LIBCPP_EXPERIMENTAL_OPTIONAL diff --git a/android/x86/include/v8/libc++/experimental/propagate_const b/android/x86/include/v8/libc++/experimental/propagate_const new file mode 100755 index 00000000..092b013b --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/propagate_const @@ -0,0 +1,578 @@ +// -*- C++ -*- +//===------------------------ propagate_const -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST +#define _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST +/* + propagate_const synopsis + + namespace std { namespace experimental { inline namespace fundamentals_v2 { + + // [propagate_const] + template <class T> class propagate_const; + + // [propagate_const.underlying], underlying pointer access + constexpr const _Tp& _VSTD_LFTS_V2::get_underlying(const propagate_const<T>& pt) noexcept; + constexpr T& _VSTD_LFTS_V2::get_underlying(propagate_const<T>& pt) noexcept; + + // [propagate_const.relational], relational operators + template <class T> constexpr bool operator==(const propagate_const<T>& pt, nullptr_t); + template <class T> constexpr bool operator==(nullptr_t, const propagate_const<T>& pu); + template <class T> constexpr bool operator!=(const propagate_const<T>& pt, nullptr_t); + template <class T> constexpr bool operator!=(nullptr_t, const propagate_const<T>& pu); + template <class T, class U> constexpr bool operator==(const propagate_const<T>& pt, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator!=(const propagate_const<T>& pt, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator<(const propagate_const<T>& pt, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator>(const propagate_const<T>& pt, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator<=(const propagate_const<T>& pt, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator>=(const propagate_const<T>& pt, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator==(const propagate_const<T>& pt, const _Up& u); + template <class T, class U> constexpr bool operator!=(const propagate_const<T>& pt, const _Up& u); + template <class T, class U> constexpr bool operator<(const propagate_const<T>& pt, const _Up& u); + template <class T, class U> constexpr bool operator>(const propagate_const<T>& pt, const _Up& u); + template <class T, class U> constexpr bool operator<=(const propagate_const<T>& pt, const _Up& u); + template <class T, class U> constexpr bool operator>=(const propagate_const<T>& pt, const _Up& u); + template <class T, class U> constexpr bool operator==(const _Tp& t, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator!=(const _Tp& t, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator<(const _Tp& t, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator>(const _Tp& t, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator<=(const _Tp& t, const propagate_const<_Up>& pu); + template <class T, class U> constexpr bool operator>=(const _Tp& t, const propagate_const<_Up>& pu); + + // [propagate_const.algorithms], specialized algorithms + template <class T> constexpr void swap(propagate_const<T>& pt, propagate_const<T>& pu) noexcept(see below); + + template <class T> + class propagate_const + { + + public: + typedef remove_reference_t<decltype(*declval<T&>())> element_type; + + // [propagate_const.ctor], constructors + constexpr propagate_const() = default; + propagate_const(const propagate_const& p) = delete; + constexpr propagate_const(propagate_const&& p) = default; + template <class U> EXPLICIT constexpr propagate_const(propagate_const<_Up>&& pu); // see below + template <class U> EXPLICIT constexpr propagate_const(U&& u); // see below + + // [propagate_const.assignment], assignment + propagate_const& operator=(const propagate_const& p) = delete; + constexpr propagate_const& operator=(propagate_const&& p) = default; + template <class U> constexpr propagate_const& operator=(propagate_const<_Up>&& pu); + template <class U> constexpr propagate_const& operator=(U&& u); // see below + + // [propagate_const.const_observers], const observers + explicit constexpr operator bool() const; + constexpr const element_type* operator->() const; + constexpr operator const element_type*() const; // Not always defined + constexpr const element_type& operator*() const; + constexpr const element_type* get() const; + + // [propagate_const.non_const_observers], non-const observers + constexpr element_type* operator->(); + constexpr operator element_type*(); // Not always defined + constexpr element_type& operator*(); + constexpr element_type* get(); + + // [propagate_const.modifiers], modifiers + constexpr void swap(propagate_const& pt) noexcept(see below) + + private: + T t_; // exposition only + }; + + } // namespace fundamentals_v2 + } // namespace experimental + + // [propagate_const.hash], hash support + template <class T> struct hash<experimental::fundamentals_v2::propagate_const<T>>; + + // [propagate_const.comparison_function_objects], comparison function objects + template <class T> struct equal_to<experimental::fundamentals_v2::propagate_const<T>>; + template <class T> struct not_equal_to<experimental::fundamentals_v2::propagate_const<T>>; + template <class T> struct less<experimental::fundamentals_v2::propagate_const<T>>; + template <class T> struct greater<experimental::fundamentals_v2::propagate_const<T>>; + template <class T> struct less_equal<experimental::fundamentals_v2::propagate_const<T>>; + template <class T> struct greater_equal<experimental::fundamentals_v2::propagate_const<T>>; + +} // namespace std + +*/ + +#include <experimental/__config> +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 11 + +#include <type_traits> +#include <utility> +#include <functional> + +_LIBCPP_BEGIN_NAMESPACE_LFTS_V2 + + +template <class _Tp> +class propagate_const; + +template <class _Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +const _Up& get_underlying(const propagate_const<_Up>& __pu) _NOEXCEPT; + +template <class _Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +_Up& get_underlying(propagate_const<_Up>& __pu) _NOEXCEPT; + +template <class _Tp> +class propagate_const +{ +public: + typedef remove_reference_t<decltype(*_VSTD::declval<_Tp&>())> element_type; + + static_assert(!is_array<_Tp>::value, + "Instantiation of propagate_const with an array type is ill-formed."); + static_assert(!is_reference<_Tp>::value, + "Instantiation of propagate_const with a reference type is ill-formed."); + static_assert(!(is_pointer<_Tp>::value && is_function<typename remove_pointer<_Tp>::type>::value), + "Instantiation of propagate_const with a function-pointer type is ill-formed."); + static_assert(!(is_pointer<_Tp>::value && is_same<typename remove_cv<typename remove_pointer<_Tp>::type>::type, void>::value), + "Instantiation of propagate_const with a pointer to (possibly cv-qualified) void is ill-formed."); + +private: + template <class _Up> + static _LIBCPP_CONSTEXPR element_type* __get_pointer(_Up* __u) + { + return __u; + } + + template <class _Up> + static _LIBCPP_CONSTEXPR element_type* __get_pointer(_Up& __u) + { + return __get_pointer(__u.get()); + } + + template <class _Up> + static _LIBCPP_CONSTEXPR const element_type* __get_pointer(const _Up* __u) + { + return __u; + } + + template <class _Up> + static _LIBCPP_CONSTEXPR const element_type* __get_pointer(const _Up& __u) + { + return __get_pointer(__u.get()); + } + + template <class _Up> + struct __is_propagate_const : false_type + { + }; + + template <class _Up> + struct __is_propagate_const<propagate_const<_Up>> : true_type + { + }; + + _Tp __t_; + +public: + + template <class _Up> friend _LIBCPP_CONSTEXPR const _Up& ::_VSTD_LFTS_V2::get_underlying(const propagate_const<_Up>& __pu) _NOEXCEPT; + template <class _Up> friend _LIBCPP_CONSTEXPR _Up& ::_VSTD_LFTS_V2::get_underlying(propagate_const<_Up>& __pu) _NOEXCEPT; + + _LIBCPP_CONSTEXPR propagate_const() = default; + + propagate_const(const propagate_const&) = delete; + + _LIBCPP_CONSTEXPR propagate_const(propagate_const&&) = default; + + template <class _Up, enable_if_t<!is_convertible<_Up, _Tp>::value && + is_constructible<_Tp, _Up&&>::value,bool> = true> + explicit _LIBCPP_CONSTEXPR propagate_const(propagate_const<_Up>&& __pu) + : __t_(std::move(_VSTD_LFTS_V2::get_underlying(__pu))) + { + } + + template <class _Up, enable_if_t<is_convertible<_Up&&, _Tp>::value && + is_constructible<_Tp, _Up&&>::value,bool> = false> + _LIBCPP_CONSTEXPR propagate_const(propagate_const<_Up>&& __pu) + : __t_(std::move(_VSTD_LFTS_V2::get_underlying(__pu))) + { + } + + template <class _Up, enable_if_t<!is_convertible<_Up&&, _Tp>::value && + is_constructible<_Tp, _Up&&>::value && + !__is_propagate_const<decay_t<_Up>>::value,bool> = true> + explicit _LIBCPP_CONSTEXPR propagate_const(_Up&& __u) + : __t_(std::forward<_Up>(__u)) + { + } + + template <class _Up, enable_if_t<is_convertible<_Up&&, _Tp>::value && + is_constructible<_Tp, _Up&&>::value && + !__is_propagate_const<decay_t<_Up>>::value,bool> = false> + _LIBCPP_CONSTEXPR propagate_const(_Up&& __u) + : __t_(std::forward<_Up>(__u)) + { + } + + propagate_const& operator=(const propagate_const&) = delete; + + _LIBCPP_CONSTEXPR propagate_const& operator=(propagate_const&&) = default; + + template <class _Up> + _LIBCPP_CONSTEXPR propagate_const& operator=(propagate_const<_Up>&& __pu) + { + __t_ = std::move(_VSTD_LFTS_V2::get_underlying(__pu)); + return *this; + } + + template <class _Up, class _Vp = enable_if_t<!__is_propagate_const<decay_t<_Up>>::value>> + _LIBCPP_CONSTEXPR propagate_const& operator=(_Up&& __u) + { + __t_ = std::forward<_Up>(__u); + return *this; + } + + _LIBCPP_CONSTEXPR const element_type* get() const + { + return __get_pointer(__t_); + } + + _LIBCPP_CONSTEXPR element_type* get() + { + return __get_pointer(__t_); + } + + explicit _LIBCPP_CONSTEXPR operator bool() const + { + return get() != nullptr; + } + + _LIBCPP_CONSTEXPR const element_type* operator->() const + { + return get(); + } + + template <class _Tp_ = _Tp, class _Up = enable_if_t<is_convertible< + const _Tp_, const element_type *>::value>> + _LIBCPP_CONSTEXPR operator const element_type *() const { + return get(); + } + + _LIBCPP_CONSTEXPR const element_type& operator*() const + { + return *get(); + } + + _LIBCPP_CONSTEXPR element_type* operator->() + { + return get(); + } + + template <class _Tp_ = _Tp, class _Up = enable_if_t< + is_convertible<_Tp_, element_type *>::value>> + _LIBCPP_CONSTEXPR operator element_type *() { + return get(); + } + + _LIBCPP_CONSTEXPR element_type& operator*() + { + return *get(); + } + + _LIBCPP_CONSTEXPR void swap(propagate_const& __pt) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) + { + using _VSTD::swap; + swap(__t_, __pt.__t_); + } +}; + + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(const propagate_const<_Tp>& __pt, nullptr_t) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) == nullptr; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(nullptr_t, const propagate_const<_Tp>& __pt) +{ + return nullptr == _VSTD_LFTS_V2::get_underlying(__pt); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(const propagate_const<_Tp>& __pt, nullptr_t) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) != nullptr; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(nullptr_t, const propagate_const<_Tp>& __pt) +{ + return nullptr != _VSTD_LFTS_V2::get_underlying(__pt); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) == _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) != _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) < _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) > _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<=(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) <= _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>=(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) >= _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) == __u; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) != __u; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) < __u; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) > __u; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<=(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) <= __u; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>=(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return _VSTD_LFTS_V2::get_underlying(__pt) >= __u; +} + + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t == _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t != _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t < _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t > _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<=(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t <= _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>=(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t >= _VSTD_LFTS_V2::get_underlying(__pu); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR void swap(propagate_const<_Tp>& __pc1, propagate_const<_Tp>& __pc2) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) +{ + __pc1.swap(__pc2); +} + +template <class _Tp> +_LIBCPP_CONSTEXPR const _Tp& get_underlying(const propagate_const<_Tp>& __pt) _NOEXCEPT +{ + return __pt.__t_; +} + +template <class _Tp> +_LIBCPP_CONSTEXPR _Tp& get_underlying(propagate_const<_Tp>& __pt) _NOEXCEPT +{ + return __pt.__t_; +} + +_LIBCPP_END_NAMESPACE_LFTS_V2 + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> +struct hash<experimental::fundamentals_v2::propagate_const<_Tp>> +{ + typedef size_t result_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> argument_type; + + size_t operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1) const + { + return std::hash<_Tp>()(_VSTD_LFTS_V2::get_underlying(__pc1)); + } +}; + +template <class _Tp> +struct equal_to<experimental::fundamentals_v2::propagate_const<_Tp>> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::equal_to<_Tp>()(_VSTD_LFTS_V2::get_underlying(__pc1), _VSTD_LFTS_V2::get_underlying(__pc2)); + } +}; + +template <class _Tp> +struct not_equal_to<experimental::fundamentals_v2::propagate_const<_Tp>> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::not_equal_to<_Tp>()(_VSTD_LFTS_V2::get_underlying(__pc1), _VSTD_LFTS_V2::get_underlying(__pc2)); + } +}; + +template <class _Tp> +struct less<experimental::fundamentals_v2::propagate_const<_Tp>> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::less<_Tp>()(_VSTD_LFTS_V2::get_underlying(__pc1), _VSTD_LFTS_V2::get_underlying(__pc2)); + } +}; + +template <class _Tp> +struct greater<experimental::fundamentals_v2::propagate_const<_Tp>> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::greater<_Tp>()(_VSTD_LFTS_V2::get_underlying(__pc1), _VSTD_LFTS_V2::get_underlying(__pc2)); + } +}; + +template <class _Tp> +struct less_equal<experimental::fundamentals_v2::propagate_const<_Tp>> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::less_equal<_Tp>()(_VSTD_LFTS_V2::get_underlying(__pc1), _VSTD_LFTS_V2::get_underlying(__pc2)); + } +}; + +template <class _Tp> +struct greater_equal<experimental::fundamentals_v2::propagate_const<_Tp>> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::greater_equal<_Tp>()(_VSTD_LFTS_V2::get_underlying(__pc1), _VSTD_LFTS_V2::get_underlying(__pc2)); + } +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 11 +#endif // _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST + diff --git a/android/x86/include/v8/libc++/experimental/ratio b/android/x86/include/v8/libc++/experimental/ratio new file mode 100755 index 00000000..4cd4fa00 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/ratio @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===----------------------------- ratio ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_RATIO +#define _LIBCPP_EXPERIMENTAL_RATIO + +#include <__config> + +#ifdef _LIBCPP_WARNING +_LIBCPP_WARNING("<experimental/ratio> has been removed. Use <ratio> instead.") +#else +# warning "<experimental/ratio> has been removed. Use <ratio> instead." +#endif + +#endif // _LIBCPP_EXPERIMENTAL_RATIO diff --git a/android/x86/include/v8/libc++/experimental/regex b/android/x86/include/v8/libc++/experimental/regex new file mode 100755 index 00000000..17193cf2 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/regex @@ -0,0 +1,61 @@ +// -*- C++ -*- +//===----------------------------- regex ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_REGEX +#define _LIBCPP_EXPERIMENTAL_REGEX +/* + experimental/regex synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + template <class BidirectionalIterator> + using match_results = + std::match_results<BidirectionalIterator, + polymorphic_allocator<sub_match<BidirectionalIterator>>>; + + typedef match_results<const char*> cmatch; + typedef match_results<const wchar_t*> wcmatch; + typedef match_results<string::const_iterator> smatch; + typedef match_results<wstring::const_iterator> wsmatch; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <regex> +#include <experimental/string> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _BiDirIter> +using match_results = + _VSTD::match_results<_BiDirIter, + polymorphic_allocator<_VSTD::sub_match<_BiDirIter>>>; + +typedef match_results<const char*> cmatch; +typedef match_results<const wchar_t*> wcmatch; +typedef match_results<_VSTD_LFTS_PMR::string::const_iterator> smatch; +typedef match_results<_VSTD_LFTS_PMR::wstring::const_iterator> wsmatch; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_REGEX */ diff --git a/android/x86/include/v8/libc++/experimental/set b/android/x86/include/v8/libc++/experimental/set new file mode 100755 index 00000000..52f4df38 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/set @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===--------------------------- list ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_SET +#define _LIBCPP_EXPERIMENTAL_SET +/* + experimental/set synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + template <class Key, class T, class Compare = less<Key>> + using set = std::set<Key, T, Compare, + polymorphic_allocator<pair<const Key,T>>>; + + template <class Key, class T, class Compare = less<Key>> + using multiset = std::multiset<Key, T, Compare, + polymorphic_allocator<pair<const Key,T>>>; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <set> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _Value, class _Compare = less<_Value>> +using set = _VSTD::set<_Value, _Compare, + polymorphic_allocator<_Value>>; + +template <class _Value, class _Compare = less<_Value>> +using multiset = _VSTD::multiset<_Value, _Compare, + polymorphic_allocator<_Value>>; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_SET */ diff --git a/android/x86/include/v8/libc++/experimental/simd b/android/x86/include/v8/libc++/experimental/simd new file mode 100755 index 00000000..39ac35e4 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/simd @@ -0,0 +1,1569 @@ +// -*- C++ -*- +//===------------------------------- simd ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_SIMD +#define _LIBCPP_EXPERIMENTAL_SIMD + +/* + experimental/simd synopsis + +namespace std::experimental { + +inline namespace parallelism_v2 { + +namespace simd_abi { + +struct scalar {}; +template <int N> struct fixed_size {}; +template <typename T> inline constexpr int max_fixed_size = implementation-defined; +template <typename T> using compatible = implementation-defined; +template <typename T> using native = implementation-defined; + +} // simd_abi + +struct element_aligned_tag {}; +struct vector_aligned_tag {}; +template <size_t> struct overaligned_tag {}; +inline constexpr element_aligned_tag element_aligned{}; +inline constexpr vector_aligned_tag vector_aligned{}; +template <size_t N> inline constexpr overaligned_tag<N> overaligned{}; + +// traits [simd.traits] +template <class T> struct is_abi_tag; +template <class T> inline constexpr bool is_abi_tag_v = is_abi_tag<T>::value; + +template <class T> struct is_simd; +template <class T> inline constexpr bool is_simd_v = is_simd<T>::value; + +template <class T> struct is_simd_mask; +template <class T> inline constexpr bool is_simd_mask_v = is_simd_mask<T>::value; + +template <class T> struct is_simd_flag_type; +template <class T> inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<T>::value; + +template <class T, size_t N> struct abi_for_size { using type = see below; }; +template <class T, size_t N> using abi_for_size_t = typename abi_for_size<T, N>::type; + +template <class T, class Abi = simd_abi::compatible<T>> struct simd_size; +template <class T, class Abi = simd_abi::compatible<T>> +inline constexpr size_t simd_size_v = simd_size<T, Abi>::value; + +template <class T, class U = typename T::value_type> struct memory_alignment; +template <class T, class U = typename T::value_type> +inline constexpr size_t memory_alignment_v = memory_alignment<T, U>::value; + +// class template simd [simd.class] +template <class T, class Abi = simd_abi::compatible<T>> class simd; +template <class T> using native_simd = simd<T, simd_abi::native<T>>; +template <class T, int N> using fixed_size_simd = simd<T, simd_abi::fixed_size<N>>; + +// class template simd_mask [simd.mask.class] +template <class T, class Abi = simd_abi::compatible<T>> class simd_mask; +template <class T> using native_simd_mask = simd_mask<T, simd_abi::native<T>>; +template <class T, int N> using fixed_size_simd_mask = simd_mask<T, simd_abi::fixed_size<N>>; + +// casts [simd.casts] +template <class T, class U, class Abi> see below simd_cast(const simd<U, Abi>&); +template <class T, class U, class Abi> see below static_simd_cast(const simd<U, Abi>&); + +template <class T, class Abi> +fixed_size_simd<T, simd_size_v<T, Abi>> to_fixed_size(const simd<T, Abi>&) noexcept; +template <class T, class Abi> +fixed_size_simd_mask<T, simd_size_v<T, Abi>> to_fixed_size(const simd_mask<T, Abi>&) noexcept; +template <class T, size_t N> native_simd<T> to_native(const fixed_size_simd<T, N>&) noexcept; +template <class T, size_t N> +native_simd_mask<T> to_native(const fixed_size_simd_mask<T, N>> &) noexcept; +template <class T, size_t N> simd<T> to_compatible(const fixed_size_simd<T, N>&) noexcept; +template <class T, size_t N> simd_mask<T> to_compatible(const fixed_size_simd_mask<T, N>&) noexcept; + +template <size_t... Sizes, class T, class Abi> +tuple<simd<T, abi_for_size_t<Sizes>>...> split(const simd<T, Abi>&); +template <size_t... Sizes, class T, class Abi> +tuple<simd_mask<T, abi_for_size_t<Sizes>>...> split(const simd_mask<T, Abi>&); +template <class V, class Abi> +array<V, simd_size_v<typename V::value_type, Abi> / V::size()> split( +const simd<typename V::value_type, Abi>&); +template <class V, class Abi> +array<V, simd_size_v<typename V::value_type, Abi> / V::size()> split( +const simd_mask<typename V::value_type, Abi>&); + +template <class T, class... Abis> +simd<T, abi_for_size_t<T, (simd_size_v<T, Abis> + ...)>> concat(const simd<T, Abis>&...); +template <class T, class... Abis> +simd_mask<T, abi_for_size_t<T, (simd_size_v<T, Abis> + ...)>> concat(const simd_mask<T, Abis>&...); + +// reductions [simd.mask.reductions] +template <class T, class Abi> bool all_of(const simd_mask<T, Abi>&) noexcept; +template <class T, class Abi> bool any_of(const simd_mask<T, Abi>&) noexcept; +template <class T, class Abi> bool none_of(const simd_mask<T, Abi>&) noexcept; +template <class T, class Abi> bool some_of(const simd_mask<T, Abi>&) noexcept; +template <class T, class Abi> int popcount(const simd_mask<T, Abi>&) noexcept; +template <class T, class Abi> int find_first_set(const simd_mask<T, Abi>&); +template <class T, class Abi> int find_last_set(const simd_mask<T, Abi>&); + +bool all_of(see below) noexcept; +bool any_of(see below) noexcept; +bool none_of(see below) noexcept; +bool some_of(see below) noexcept; +int popcount(see below) noexcept; +int find_first_set(see below) noexcept; +int find_last_set(see below) noexcept; + +// masked assignment [simd.whereexpr] +template <class M, class T> class const_where_expression; +template <class M, class T> class where_expression; + +// masked assignment [simd.mask.where] +template <class T> struct nodeduce { using type = T; }; // exposition only + +template <class T> using nodeduce_t = typename nodeduce<T>::type; // exposition only + +template <class T, class Abi> +where_expression<simd_mask<T, Abi>, simd<T, Abi>> +where(const typename simd<T, Abi>::mask_type&, simd<T, Abi>&) noexcept; + +template <class T, class Abi> +const_where_expression<simd_mask<T, Abi>, const simd<T, Abi>> +where(const typename simd<T, Abi>::mask_type&, const simd<T, Abi>&) noexcept; + +template <class T, class Abi> +where_expression<simd_mask<T, Abi>, simd_mask<T, Abi>> +where(const nodeduce_t<simd_mask<T, Abi>>&, simd_mask<T, Abi>&) noexcept; + +template <class T, class Abi> +const_where_expression<simd_mask<T, Abi>, const simd_mask<T, Abi>> +where(const nodeduce_t<simd_mask<T, Abi>>&, const simd_mask<T, Abi>&) noexcept; + +template <class T> where_expression<bool, T> where(see below k, T& d) noexcept; + +template <class T> +const_where_expression<bool, const T> where(see below k, const T& d) noexcept; + +// reductions [simd.reductions] +template <class T, class Abi, class BinaryOperation = std::plus<>> +T reduce(const simd<T, Abi>&, BinaryOperation = BinaryOperation()); + +template <class M, class V, class BinaryOperation> +typename V::value_type reduce(const const_where_expression<M, V>& x, +typename V::value_type neutral_element, BinaryOperation binary_op); + +template <class M, class V> +typename V::value_type reduce(const const_where_expression<M, V>& x, plus<> binary_op = plus<>()); + +template <class M, class V> +typename V::value_type reduce(const const_where_expression<M, V>& x, multiplies<> binary_op); + +template <class M, class V> +typename V::value_type reduce(const const_where_expression<M, V>& x, bit_and<> binary_op); + +template <class M, class V> +typename V::value_type reduce(const const_where_expression<M, V>& x, bit_or<> binary_op); + +template <class M, class V> +typename V::value_type reduce(const const_where_expression<M, V>& x, bit_xor<> binary_op); + +template <class T, class Abi> T hmin(const simd<T, Abi>&); +template <class M, class V> T hmin(const const_where_expression<M, V>&); +template <class T, class Abi> T hmax(const simd<T, Abi>&); +template <class M, class V> T hmax(const const_where_expression<M, V>&); + +// algorithms [simd.alg] +template <class T, class Abi> simd<T, Abi> min(const simd<T, Abi>&, const simd<T, Abi>&) noexcept; + +template <class T, class Abi> simd<T, Abi> max(const simd<T, Abi>&, const simd<T, Abi>&) noexcept; + +template <class T, class Abi> +std::pair<simd<T, Abi>, simd<T, Abi>> minmax(const simd<T, Abi>&, const simd<T, Abi>&) noexcept; + +template <class T, class Abi> +simd<T, Abi> clamp(const simd<T, Abi>& v, const simd<T, Abi>& lo, const simd<T, Abi>& hi); + +// [simd.whereexpr] +template <class M, class T> +class const_where_expression { + const M& mask; // exposition only + T& data; // exposition only +public: + const_where_expression(const const_where_expression&) = delete; + const_where_expression& operator=(const const_where_expression&) = delete; + remove_const_t<T> operator-() const &&; + template <class U, class Flags> void copy_to(U* mem, Flags f) const &&; +}; + +template <class M, class T> +class where_expression : public const_where_expression<M, T> { +public: + where_expression(const where_expression&) = delete; + where_expression& operator=(const where_expression&) = delete; + template <class U> void operator=(U&& x); + template <class U> void operator+=(U&& x); + template <class U> void operator-=(U&& x); + template <class U> void operator*=(U&& x); + template <class U> void operator/=(U&& x); + template <class U> void operator%=(U&& x); + template <class U> void operator&=(U&& x); + template <class U> void operator|=(U&& x); + template <class U> void operator^=(U&& x); + template <class U> void operator<<=(U&& x); + template <class U> void operator>>=(U&& x); + void operator++(); + void operator++(int); + void operator--(); + void operator--(int); + template <class U, class Flags> void copy_from(const U* mem, Flags); +}; + +// [simd.class] +template <class T, class Abi> class simd { +public: + using value_type = T; + using reference = see below; + using mask_type = simd_mask<T, Abi>; + + using abi_type = Abi; + static constexpr size_t size() noexcept; + simd() = default; + + // implicit type conversion constructor + template <class U> simd(const simd<U, simd_abi::fixed_size<size()>>&); + + // implicit broadcast constructor (see below for constraints) + template <class U> simd(U&& value); + + // generator constructor (see below for constraints) + template <class G> explicit simd(G&& gen); + + // load constructor + template <class U, class Flags> simd(const U* mem, Flags f); + + // loads [simd.load] + template <class U, class Flags> void copy_from(const U* mem, Flags f); + + // stores [simd.store] + template <class U, class Flags> void copy_to(U* mem, Flags f) const; + + // scalar access [simd.subscr] + reference operator[](size_t); + value_type operator[](size_t) const; + + // unary operators [simd.unary] + simd& operator++(); + simd operator++(int); + simd& operator--(); + simd operator--(int); + mask_type operator!() const; + simd operator~() const; // see below + simd operator+() const; + simd operator-() const; + + // binary operators [simd.binary] + friend simd operator+ (const simd&, const simd&); + friend simd operator- (const simd&, const simd&); + friend simd operator* (const simd&, const simd&); + friend simd operator/ (const simd&, const simd&); + friend simd operator% (const simd&, const simd&); + friend simd operator& (const simd&, const simd&); + friend simd operator| (const simd&, const simd&); + friend simd operator^ (const simd&, const simd&); + friend simd operator<<(const simd&, const simd&); + friend simd operator>>(const simd&, const simd&); + friend simd operator<<(const simd&, int); + friend simd operator>>(const simd&, int); + + // compound assignment [simd.cassign] + friend simd& operator+= (simd&, const simd&); + friend simd& operator-= (simd&, const simd&); + friend simd& operator*= (simd&, const simd&); + friend simd& operator/= (simd&, const simd&); + friend simd& operator%= (simd&, const simd&); + + friend simd& operator&= (simd&, const simd&); + friend simd& operator|= (simd&, const simd&); + friend simd& operator^= (simd&, const simd&); + friend simd& operator<<=(simd&, const simd&); + friend simd& operator>>=(simd&, const simd&); + friend simd& operator<<=(simd&, int); + friend simd& operator>>=(simd&, int); + + // compares [simd.comparison] + friend mask_type operator==(const simd&, const simd&); + friend mask_type operator!=(const simd&, const simd&); + friend mask_type operator>=(const simd&, const simd&); + friend mask_type operator<=(const simd&, const simd&); + friend mask_type operator> (const simd&, const simd&); + friend mask_type operator< (const simd&, const simd&); +}; + +// [simd.math] +template <class Abi> using scharv = simd<signed char, Abi>; // exposition only +template <class Abi> using shortv = simd<short, Abi>; // exposition only +template <class Abi> using intv = simd<int, Abi>; // exposition only +template <class Abi> using longv = simd<long int, Abi>; // exposition only +template <class Abi> using llongv = simd<long long int, Abi>; // exposition only +template <class Abi> using floatv = simd<float, Abi>; // exposition only +template <class Abi> using doublev = simd<double, Abi>; // exposition only +template <class Abi> using ldoublev = simd<long double, Abi>; // exposition only +template <class T, class V> using samesize = fixed_size_simd<T, V::size()>; // exposition only + +template <class Abi> floatv<Abi> acos(floatv<Abi> x); +template <class Abi> doublev<Abi> acos(doublev<Abi> x); +template <class Abi> ldoublev<Abi> acos(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> asin(floatv<Abi> x); +template <class Abi> doublev<Abi> asin(doublev<Abi> x); +template <class Abi> ldoublev<Abi> asin(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> atan(floatv<Abi> x); +template <class Abi> doublev<Abi> atan(doublev<Abi> x); +template <class Abi> ldoublev<Abi> atan(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> atan2(floatv<Abi> y, floatv<Abi> x); +template <class Abi> doublev<Abi> atan2(doublev<Abi> y, doublev<Abi> x); +template <class Abi> ldoublev<Abi> atan2(ldoublev<Abi> y, ldoublev<Abi> x); + +template <class Abi> floatv<Abi> cos(floatv<Abi> x); +template <class Abi> doublev<Abi> cos(doublev<Abi> x); +template <class Abi> ldoublev<Abi> cos(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> sin(floatv<Abi> x); +template <class Abi> doublev<Abi> sin(doublev<Abi> x); +template <class Abi> ldoublev<Abi> sin(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> tan(floatv<Abi> x); +template <class Abi> doublev<Abi> tan(doublev<Abi> x); +template <class Abi> ldoublev<Abi> tan(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> acosh(floatv<Abi> x); +template <class Abi> doublev<Abi> acosh(doublev<Abi> x); +template <class Abi> ldoublev<Abi> acosh(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> asinh(floatv<Abi> x); +template <class Abi> doublev<Abi> asinh(doublev<Abi> x); +template <class Abi> ldoublev<Abi> asinh(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> atanh(floatv<Abi> x); +template <class Abi> doublev<Abi> atanh(doublev<Abi> x); +template <class Abi> ldoublev<Abi> atanh(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> cosh(floatv<Abi> x); +template <class Abi> doublev<Abi> cosh(doublev<Abi> x); +template <class Abi> ldoublev<Abi> cosh(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> sinh(floatv<Abi> x); +template <class Abi> doublev<Abi> sinh(doublev<Abi> x); +template <class Abi> ldoublev<Abi> sinh(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> tanh(floatv<Abi> x); +template <class Abi> doublev<Abi> tanh(doublev<Abi> x); +template <class Abi> ldoublev<Abi> tanh(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> exp(floatv<Abi> x); +template <class Abi> doublev<Abi> exp(doublev<Abi> x); +template <class Abi> ldoublev<Abi> exp(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> exp2(floatv<Abi> x); +template <class Abi> doublev<Abi> exp2(doublev<Abi> x); +template <class Abi> ldoublev<Abi> exp2(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> expm1(floatv<Abi> x); +template <class Abi> doublev<Abi> expm1(doublev<Abi> x); +template <class Abi> ldoublev<Abi> expm1(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> frexp(floatv<Abi> value, samesize<int, floatv<Abi>>* exp); +template <class Abi> doublev<Abi> frexp(doublev<Abi> value, samesize<int, doublev<Abi>>* exp); +template <class Abi> ldoublev<Abi> frexp(ldoublev<Abi> value, samesize<int, ldoublev<Abi>>* exp); + +template <class Abi> samesize<int, floatv<Abi>> ilogb(floatv<Abi> x); +template <class Abi> samesize<int, doublev<Abi>> ilogb(doublev<Abi> x); +template <class Abi> samesize<int, ldoublev<Abi>> ilogb(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> ldexp(floatv<Abi> x, samesize<int, floatv<Abi>> exp); +template <class Abi> doublev<Abi> ldexp(doublev<Abi> x, samesize<int, doublev<Abi>> exp); +template <class Abi> ldoublev<Abi> ldexp(ldoublev<Abi> x, samesize<int, ldoublev<Abi>> exp); + +template <class Abi> floatv<Abi> log(floatv<Abi> x); +template <class Abi> doublev<Abi> log(doublev<Abi> x); +template <class Abi> ldoublev<Abi> log(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> log10(floatv<Abi> x); +template <class Abi> doublev<Abi> log10(doublev<Abi> x); +template <class Abi> ldoublev<Abi> log10(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> log1p(floatv<Abi> x); +template <class Abi> doublev<Abi> log1p(doublev<Abi> x); +template <class Abi> ldoublev<Abi> log1p(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> log2(floatv<Abi> x); +template <class Abi> doublev<Abi> log2(doublev<Abi> x); +template <class Abi> ldoublev<Abi> log2(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> logb(floatv<Abi> x); +template <class Abi> doublev<Abi> logb(doublev<Abi> x); +template <class Abi> ldoublev<Abi> logb(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> modf(floatv<Abi> value, floatv<Abi>* iptr); +template <class Abi> doublev<Abi> modf(doublev<Abi> value, doublev<Abi>* iptr); +template <class Abi> ldoublev<Abi> modf(ldoublev<Abi> value, ldoublev<Abi>* iptr); + +template <class Abi> floatv<Abi> scalbn(floatv<Abi> x, samesize<int, floatv<Abi>> n); +template <class Abi> doublev<Abi> scalbn(doublev<Abi> x, samesize<int, doublev<Abi>> n); +template <class Abi> ldoublev<Abi> scalbn(ldoublev<Abi> x, samesize<int, ldoublev<Abi>> n); +template <class Abi> floatv<Abi> scalbln(floatv<Abi> x, samesize<long int, floatv<Abi>> n); +template <class Abi> doublev<Abi> scalbln(doublev<Abi> x, samesize<long int, doublev<Abi>> n); +template <class Abi> ldoublev<Abi> scalbln(ldoublev<Abi> x, samesize<long int, ldoublev<Abi>> n); + +template <class Abi> floatv<Abi> cbrt(floatv<Abi> x); +template <class Abi> doublev<Abi> cbrt(doublev<Abi> x); +template <class Abi> ldoublev<Abi> cbrt(ldoublev<Abi> x); + +template <class Abi> scharv<Abi> abs(scharv<Abi> j); +template <class Abi> shortv<Abi> abs(shortv<Abi> j); +template <class Abi> intv<Abi> abs(intv<Abi> j); +template <class Abi> longv<Abi> abs(longv<Abi> j); +template <class Abi> llongv<Abi> abs(llongv<Abi> j); +template <class Abi> floatv<Abi> abs(floatv<Abi> j); +template <class Abi> doublev<Abi> abs(doublev<Abi> j); +template <class Abi> ldoublev<Abi> abs(ldoublev<Abi> j); + +template <class Abi> floatv<Abi> hypot(floatv<Abi> x, floatv<Abi> y); +template <class Abi> doublev<Abi> hypot(doublev<Abi> x, doublev<Abi> y); +template <class Abi> ldoublev<Abi> hypot(doublev<Abi> x, doublev<Abi> y); +template <class Abi> floatv<Abi> hypot(floatv<Abi> x, floatv<Abi> y, floatv<Abi> z); +template <class Abi> doublev<Abi> hypot(doublev<Abi> x, doublev<Abi> y, doublev<Abi> z); +template <class Abi> ldoublev<Abi> hypot(ldoublev<Abi> x, ldoublev<Abi> y, ldoublev<Abi> z); + +template <class Abi> floatv<Abi> pow(floatv<Abi> x, floatv<Abi> y); +template <class Abi> doublev<Abi> pow(doublev<Abi> x, doublev<Abi> y); +template <class Abi> ldoublev<Abi> pow(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> floatv<Abi> sqrt(floatv<Abi> x); +template <class Abi> doublev<Abi> sqrt(doublev<Abi> x); +template <class Abi> ldoublev<Abi> sqrt(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> erf(floatv<Abi> x); +template <class Abi> doublev<Abi> erf(doublev<Abi> x); +template <class Abi> ldoublev<Abi> erf(ldoublev<Abi> x); +template <class Abi> floatv<Abi> erfc(floatv<Abi> x); +template <class Abi> doublev<Abi> erfc(doublev<Abi> x); +template <class Abi> ldoublev<Abi> erfc(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> lgamma(floatv<Abi> x); +template <class Abi> doublev<Abi> lgamma(doublev<Abi> x); +template <class Abi> ldoublev<Abi> lgamma(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> tgamma(floatv<Abi> x); +template <class Abi> doublev<Abi> tgamma(doublev<Abi> x); +template <class Abi> ldoublev<Abi> tgamma(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> ceil(floatv<Abi> x); +template <class Abi> doublev<Abi> ceil(doublev<Abi> x); +template <class Abi> ldoublev<Abi> ceil(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> floor(floatv<Abi> x); +template <class Abi> doublev<Abi> floor(doublev<Abi> x); +template <class Abi> ldoublev<Abi> floor(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> nearbyint(floatv<Abi> x); +template <class Abi> doublev<Abi> nearbyint(doublev<Abi> x); +template <class Abi> ldoublev<Abi> nearbyint(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> rint(floatv<Abi> x); +template <class Abi> doublev<Abi> rint(doublev<Abi> x); +template <class Abi> ldoublev<Abi> rint(ldoublev<Abi> x); + +template <class Abi> samesize<long int, floatv<Abi>> lrint(floatv<Abi> x); +template <class Abi> samesize<long int, doublev<Abi>> lrint(doublev<Abi> x); +template <class Abi> samesize<long int, ldoublev<Abi>> lrint(ldoublev<Abi> x); +template <class Abi> samesize<long long int, floatv<Abi>> llrint(floatv<Abi> x); +template <class Abi> samesize<long long int, doublev<Abi>> llrint(doublev<Abi> x); +template <class Abi> samesize<long long int, ldoublev<Abi>> llrint(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> round(floatv<Abi> x); +template <class Abi> doublev<Abi> round(doublev<Abi> x); +template <class Abi> ldoublev<Abi> round(ldoublev<Abi> x); +template <class Abi> samesize<long int, floatv<Abi>> lround(floatv<Abi> x); +template <class Abi> samesize<long int, doublev<Abi>> lround(doublev<Abi> x); +template <class Abi> samesize<long int, ldoublev<Abi>> lround(ldoublev<Abi> x); +template <class Abi> samesize<long long int, floatv<Abi>> llround(floatv<Abi> x); +template <class Abi> samesize<long long int, doublev<Abi>> llround(doublev<Abi> x); +template <class Abi> samesize<long long int, ldoublev<Abi>> llround(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> trunc(floatv<Abi> x); +template <class Abi> doublev<Abi> trunc(doublev<Abi> x); +template <class Abi> ldoublev<Abi> trunc(ldoublev<Abi> x); + +template <class Abi> floatv<Abi> fmod(floatv<Abi> x, floatv<Abi> y); +template <class Abi> doublev<Abi> fmod(doublev<Abi> x, doublev<Abi> y); +template <class Abi> ldoublev<Abi> fmod(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> floatv<Abi> remainder(floatv<Abi> x, floatv<Abi> y); +template <class Abi> doublev<Abi> remainder(doublev<Abi> x, doublev<Abi> y); +template <class Abi> ldoublev<Abi> remainder(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> floatv<Abi> remquo(floatv<Abi> x, floatv<Abi> y, samesize<int, floatv<Abi>>* quo); +template <class Abi> doublev<Abi> remquo(doublev<Abi> x, doublev<Abi> y, samesize<int, doublev<Abi>>* quo); +template <class Abi> ldoublev<Abi> remquo(ldoublev<Abi> x, ldoublev<Abi> y, samesize<int, ldoublev<Abi>>* quo); + +template <class Abi> floatv<Abi> copysign(floatv<Abi> x, floatv<Abi> y); +template <class Abi> doublev<Abi> copysign(doublev<Abi> x, doublev<Abi> y); +template <class Abi> ldoublev<Abi> copysign(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> doublev<Abi> nan(const char* tagp); +template <class Abi> floatv<Abi> nanf(const char* tagp); +template <class Abi> ldoublev<Abi> nanl(const char* tagp); + +template <class Abi> floatv<Abi> nextafter(floatv<Abi> x, floatv<Abi> y); +template <class Abi> doublev<Abi> nextafter(doublev<Abi> x, doublev<Abi> y); +template <class Abi> ldoublev<Abi> nextafter(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> floatv<Abi> nexttoward(floatv<Abi> x, ldoublev<Abi> y); +template <class Abi> doublev<Abi> nexttoward(doublev<Abi> x, ldoublev<Abi> y); +template <class Abi> ldoublev<Abi> nexttoward(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> floatv<Abi> fdim(floatv<Abi> x, floatv<Abi> y); +template <class Abi> doublev<Abi> fdim(doublev<Abi> x, doublev<Abi> y); +template <class Abi> ldoublev<Abi> fdim(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> floatv<Abi> fmax(floatv<Abi> x, floatv<Abi> y); +template <class Abi> doublev<Abi> fmax(doublev<Abi> x, doublev<Abi> y); +template <class Abi> ldoublev<Abi> fmax(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> floatv<Abi> fmin(floatv<Abi> x, floatv<Abi> y); +template <class Abi> doublev<Abi> fmin(doublev<Abi> x, doublev<Abi> y); +template <class Abi> ldoublev<Abi> fmin(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> floatv<Abi> fma(floatv<Abi> x, floatv<Abi> y, floatv<Abi> z); +template <class Abi> doublev<Abi> fma(doublev<Abi> x, doublev<Abi> y, doublev<Abi> z); +template <class Abi> ldoublev<Abi> fma(ldoublev<Abi> x, ldoublev<Abi> y, ldoublev<Abi> z); + +template <class Abi> samesize<int, floatv<Abi>> fpclassify(floatv<Abi> x); +template <class Abi> samesize<int, doublev<Abi>> fpclassify(doublev<Abi> x); +template <class Abi> samesize<int, ldoublev<Abi>> fpclassify(ldoublev<Abi> x); + +template <class Abi> simd_mask<float, Abi> isfinite(floatv<Abi> x); +template <class Abi> simd_mask<double, Abi> isfinite(doublev<Abi> x); +template <class Abi> simd_mask<long double, Abi> isfinite(ldoublev<Abi> x); + +template <class Abi> simd_mask<float, Abi> isinf(floatv<Abi> x); +template <class Abi> simd_mask<double, Abi> isinf(doublev<Abi> x); +template <class Abi> simd_mask<long double, Abi> isinf(ldoublev<Abi> x); + +template <class Abi> simd_mask<float, Abi> isnan(floatv<Abi> x); +template <class Abi> simd_mask<double, Abi> isnan(doublev<Abi> x); +template <class Abi> simd_mask<long double, Abi> isnan(ldoublev<Abi> x); + +template <class Abi> simd_mask<float, Abi> isnormal(floatv<Abi> x); +template <class Abi> simd_mask<double, Abi> isnormal(doublev<Abi> x); +template <class Abi> simd_mask<long double, Abi> isnormal(ldoublev<Abi> x); + +template <class Abi> simd_mask<float, Abi> signbit(floatv<Abi> x); +template <class Abi> simd_mask<double, Abi> signbit(doublev<Abi> x); +template <class Abi> simd_mask<long double, Abi> signbit(ldoublev<Abi> x); + +template <class Abi> simd_mask<float, Abi> isgreater(floatv<Abi> x, floatv<Abi> y); +template <class Abi> simd_mask<double, Abi> isgreater(doublev<Abi> x, doublev<Abi> y); +template <class Abi> simd_mask<long double, Abi> isgreater(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> simd_mask<float, Abi> isgreaterequal(floatv<Abi> x, floatv<Abi> y); +template <class Abi> simd_mask<double, Abi> isgreaterequal(doublev<Abi> x, doublev<Abi> y); +template <class Abi> simd_mask<long double, Abi> isgreaterequal(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> simd_mask<float, Abi> isless(floatv<Abi> x, floatv<Abi> y); +template <class Abi> simd_mask<double, Abi> isless(doublev<Abi> x, doublev<Abi> y); +template <class Abi> simd_mask<long double, Abi> isless(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> simd_mask<float, Abi> islessequal(floatv<Abi> x, floatv<Abi> y); +template <class Abi> simd_mask<double, Abi> islessequal(doublev<Abi> x, doublev<Abi> y); +template <class Abi> simd_mask<long double, Abi> islessequal(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> simd_mask<float, Abi> islessgreater(floatv<Abi> x, floatv<Abi> y); +template <class Abi> simd_mask<double, Abi> islessgreater(doublev<Abi> x, doublev<Abi> y); +template <class Abi> simd_mask<long double, Abi> islessgreater(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class Abi> simd_mask<float, Abi> isunordered(floatv<Abi> x, floatv<Abi> y); +template <class Abi> simd_mask<double, Abi> isunordered(doublev<Abi> x, doublev<Abi> y); +template <class Abi> simd_mask<long double, Abi> isunordered(ldoublev<Abi> x, ldoublev<Abi> y); + +template <class V> struct simd_div_t { V quot, rem; }; +template <class Abi> simd_div_t<scharv<Abi>> div(scharv<Abi> numer, scharv<Abi> denom); +template <class Abi> simd_div_t<shortv<Abi>> div(shortv<Abi> numer, shortv<Abi> denom); +template <class Abi> simd_div_t<intv<Abi>> div(intv<Abi> numer, intv<Abi> denom); +template <class Abi> simd_div_t<longv<Abi>> div(longv<Abi> numer, longv<Abi> denom); +template <class Abi> simd_div_t<llongv<Abi>> div(llongv<Abi> numer, llongv<Abi> denom); + +// [simd.mask.class] +template <class T, class Abi> +class simd_mask { +public: + using value_type = bool; + using reference = see below; + using simd_type = simd<T, Abi>; + using abi_type = Abi; + static constexpr size_t size() noexcept; + simd_mask() = default; + + // broadcast constructor + explicit simd_mask(value_type) noexcept; + + // implicit type conversion constructor + template <class U> simd_mask(const simd_mask<U, simd_abi::fixed_size<size()>>&) noexcept; + + // load constructor + template <class Flags> simd_mask(const value_type* mem, Flags); + + // loads [simd.mask.copy] + template <class Flags> void copy_from(const value_type* mem, Flags); + template <class Flags> void copy_to(value_type* mem, Flags) const; + + // scalar access [simd.mask.subscr] + reference operator[](size_t); + value_type operator[](size_t) const; + + // unary operators [simd.mask.unary] + simd_mask operator!() const noexcept; + + // simd_mask binary operators [simd.mask.binary] + friend simd_mask operator&&(const simd_mask&, const simd_mask&) noexcept; + friend simd_mask operator||(const simd_mask&, const simd_mask&) noexcept; + friend simd_mask operator& (const simd_mask&, const simd_mask&) noexcept; + friend simd_mask operator| (const simd_mask&, const simd_mask&) noexcept; + friend simd_mask operator^ (const simd_mask&, const simd_mask&) noexcept; + + // simd_mask compound assignment [simd.mask.cassign] + friend simd_mask& operator&=(simd_mask&, const simd_mask&) noexcept; + friend simd_mask& operator|=(simd_mask&, const simd_mask&) noexcept; + friend simd_mask& operator^=(simd_mask&, const simd_mask&) noexcept; + + // simd_mask compares [simd.mask.comparison] + friend simd_mask operator==(const simd_mask&, const simd_mask&) noexcept; + friend simd_mask operator!=(const simd_mask&, const simd_mask&) noexcept; +}; + +} // parallelism_v2 +} // std::experimental + +*/ + +#include <experimental/__config> +#include <algorithm> +#include <array> +#include <cstddef> +#include <functional> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD + +#if _LIBCPP_STD_VER >= 17 + +enum class _StorageKind { + _Scalar, + _Array, + _VecExt, +}; + +template <_StorageKind __kind, int _Np> +struct __simd_abi {}; + +template <class _Tp, class _Abi> +class __simd_storage {}; + +template <class _Tp, int __num_element> +class __simd_storage<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> { + std::array<_Tp, __num_element> __storage_; + + template <class, class> + friend struct simd; + + template <class, class> + friend struct simd_mask; + +public: + _Tp __get(size_t __index) const noexcept { return __storage_[__index]; }; + void __set(size_t __index, _Tp __val) noexcept { + __storage_[__index] = __val; + } +}; + +template <class _Tp> +class __simd_storage<_Tp, __simd_abi<_StorageKind::_Scalar, 1>> { + _Tp __storage_; + + template <class, class> + friend struct simd; + + template <class, class> + friend struct simd_mask; + +public: + _Tp __get(size_t __index) const noexcept { return (&__storage_)[__index]; }; + void __set(size_t __index, _Tp __val) noexcept { + (&__storage_)[__index] = __val; + } +}; + +#ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION + +constexpr size_t __floor_pow_of_2(size_t __val) { + return ((__val - 1) & __val) == 0 ? __val + : __floor_pow_of_2((__val - 1) & __val); +} + +constexpr size_t __ceil_pow_of_2(size_t __val) { + return __val == 1 ? 1 : __floor_pow_of_2(__val - 1) << 1; +} + +template <class _Tp, size_t __bytes> +struct __vec_ext_traits { +#if !defined(_LIBCPP_COMPILER_CLANG) + typedef _Tp type __attribute__((vector_size(__ceil_pow_of_2(__bytes)))); +#endif +}; + +#if defined(_LIBCPP_COMPILER_CLANG) +#define _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, _NUM_ELEMENT) \ + template <> \ + struct __vec_ext_traits<_TYPE, sizeof(_TYPE) * _NUM_ELEMENT> { \ + using type = \ + _TYPE __attribute__((vector_size(sizeof(_TYPE) * _NUM_ELEMENT))); \ + } + +#define _LIBCPP_SPECIALIZE_VEC_EXT_32(_TYPE) \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 1); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 2); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 3); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 4); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 5); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 6); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 7); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 8); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 9); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 10); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 11); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 12); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 13); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 14); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 15); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 16); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 17); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 18); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 19); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 20); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 21); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 22); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 23); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 24); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 25); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 26); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 27); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 28); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 29); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 30); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 31); \ + _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 32); + +_LIBCPP_SPECIALIZE_VEC_EXT_32(char); +_LIBCPP_SPECIALIZE_VEC_EXT_32(char16_t); +_LIBCPP_SPECIALIZE_VEC_EXT_32(char32_t); +_LIBCPP_SPECIALIZE_VEC_EXT_32(wchar_t); +_LIBCPP_SPECIALIZE_VEC_EXT_32(signed char); +_LIBCPP_SPECIALIZE_VEC_EXT_32(signed short); +_LIBCPP_SPECIALIZE_VEC_EXT_32(signed int); +_LIBCPP_SPECIALIZE_VEC_EXT_32(signed long); +_LIBCPP_SPECIALIZE_VEC_EXT_32(signed long long); +_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned char); +_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned short); +_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned int); +_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned long); +_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned long long); +_LIBCPP_SPECIALIZE_VEC_EXT_32(float); +_LIBCPP_SPECIALIZE_VEC_EXT_32(double); +_LIBCPP_SPECIALIZE_VEC_EXT_32(long double); + +#undef _LIBCPP_SPECIALIZE_VEC_EXT_32 +#undef _LIBCPP_SPECIALIZE_VEC_EXT +#endif + +template <class _Tp, int __num_element> +class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> { + using _StorageType = + typename __vec_ext_traits<_Tp, sizeof(_Tp) * __num_element>::type; + + _StorageType __storage_; + + template <class, class> + friend struct simd; + + template <class, class> + friend struct simd_mask; + +public: + _Tp __get(size_t __index) const noexcept { return __storage_[__index]; }; + void __set(size_t __index, _Tp __val) noexcept { + __storage_[__index] = __val; + } +}; + +#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION + +template <class _Vp, class _Tp, class _Abi> +class __simd_reference { + static_assert(std::is_same<_Vp, _Tp>::value, ""); + + template <class, class> + friend struct simd; + + template <class, class> + friend struct simd_mask; + + __simd_storage<_Tp, _Abi>* __ptr_; + size_t __index_; + + __simd_reference(__simd_storage<_Tp, _Abi>* __ptr, size_t __index) + : __ptr_(__ptr), __index_(__index) {} + + __simd_reference(const __simd_reference&) = default; + +public: + __simd_reference() = delete; + __simd_reference& operator=(const __simd_reference&) = delete; + + operator _Vp() const { return __ptr_->__get(__index_); } + + __simd_reference operator=(_Vp __value) && { + __ptr_->__set(__index_, __value); + return *this; + } + + __simd_reference operator++() && { + return std::move(*this) = __ptr_->__get(__index_) + 1; + } + + _Vp operator++(int) && { + auto __val = __ptr_->__get(__index_); + __ptr_->__set(__index_, __val + 1); + return __val; + } + + __simd_reference operator--() && { + return std::move(*this) = __ptr_->__get(__index_) - 1; + } + + _Vp operator--(int) && { + auto __val = __ptr_->__get(__index_); + __ptr_->__set(__index_, __val - 1); + return __val; + } + + __simd_reference operator+=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) + __value; + } + + __simd_reference operator-=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) - __value; + } + + __simd_reference operator*=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) * __value; + } + + __simd_reference operator/=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) / __value; + } + + __simd_reference operator%=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) % __value; + } + + __simd_reference operator>>=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) >> __value; + } + + __simd_reference operator<<=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) << __value; + } + + __simd_reference operator&=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) & __value; + } + + __simd_reference operator|=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) | __value; + } + + __simd_reference operator^=(_Vp __value) && { + return std::move(*this) = __ptr_->__get(__index_) ^ __value; + } +}; + +template <class _To, class _From> +constexpr decltype(_To{std::declval<_From>()}, true) +__is_non_narrowing_convertible_impl(_From) { + return true; +} + +template <class _To> +constexpr bool __is_non_narrowing_convertible_impl(...) { + return false; +} + +template <class _From, class _To> +constexpr typename std::enable_if<std::is_arithmetic<_To>::value && + std::is_arithmetic<_From>::value, + bool>::type +__is_non_narrowing_arithmetic_convertible() { + return __is_non_narrowing_convertible_impl<_To>(_From{}); +} + +template <class _From, class _To> +constexpr typename std::enable_if<!(std::is_arithmetic<_To>::value && + std::is_arithmetic<_From>::value), + bool>::type +__is_non_narrowing_arithmetic_convertible() { + return false; +} + +template <class _Tp> +constexpr _Tp __variadic_sum() { + return _Tp{}; +} + +template <class _Tp, class _Up, class... _Args> +constexpr _Tp __variadic_sum(_Up __first, _Args... __rest) { + return static_cast<_Tp>(__first) + __variadic_sum<_Tp>(__rest...); +} + +template <class _Tp> +struct __nodeduce { + using type = _Tp; +}; + +template <class _Tp> +constexpr bool __vectorizable() { + return std::is_arithmetic<_Tp>::value && !std::is_const<_Tp>::value && + !std::is_volatile<_Tp>::value && !std::is_same<_Tp, bool>::value; +} + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD_ABI + +using scalar = __simd_abi<_StorageKind::_Scalar, 1>; + +template <int _Np> +using fixed_size = __simd_abi<_StorageKind::_Array, _Np>; + +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t max_fixed_size = 32; + +template <class _Tp> +using compatible = fixed_size<16 / sizeof(_Tp)>; + +#ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION +template <class _Tp> +using native = __simd_abi<_StorageKind::_VecExt, + _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>; +#else +template <class _Tp> +using native = + fixed_size<_Tp, _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>; +#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD_ABI +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD + +template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> +class simd; +template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> +class simd_mask; + +struct element_aligned_tag {}; +struct vector_aligned_tag {}; +template <size_t> +struct overaligned_tag {}; +_LIBCPP_INLINE_VAR constexpr element_aligned_tag element_aligned{}; +_LIBCPP_INLINE_VAR constexpr vector_aligned_tag vector_aligned{}; +template <size_t _Np> +_LIBCPP_INLINE_VAR constexpr overaligned_tag<_Np> overaligned{}; + +// traits [simd.traits] +template <class _Tp> +struct is_abi_tag : std::integral_constant<bool, false> {}; + +template <_StorageKind __kind, int _Np> +struct is_abi_tag<__simd_abi<__kind, _Np>> + : std::integral_constant<bool, true> {}; + +template <class _Tp> +struct is_simd : std::integral_constant<bool, false> {}; + +template <class _Tp, class _Abi> +struct is_simd<simd<_Tp, _Abi>> : std::integral_constant<bool, true> {}; + +template <class _Tp> +struct is_simd_mask : std::integral_constant<bool, false> {}; + +template <class _Tp, class _Abi> +struct is_simd_mask<simd_mask<_Tp, _Abi>> : std::integral_constant<bool, true> { +}; + +template <class _Tp> +struct is_simd_flag_type : std::integral_constant<bool, false> {}; + +template <> +struct is_simd_flag_type<element_aligned_tag> + : std::integral_constant<bool, true> {}; + +template <> +struct is_simd_flag_type<vector_aligned_tag> + : std::integral_constant<bool, true> {}; + +template <size_t _Align> +struct is_simd_flag_type<overaligned_tag<_Align>> + : std::integral_constant<bool, true> {}; + +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value; +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr bool is_simd_v = is_simd<_Tp>::value; +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value; +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr bool is_simd_flag_type_v = + is_simd_flag_type<_Tp>::value; +template <class _Tp, size_t _Np> +struct abi_for_size { + using type = simd_abi::fixed_size<_Np>; +}; +template <class _Tp, size_t _Np> +using abi_for_size_t = typename abi_for_size<_Tp, _Np>::type; + +template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> +struct simd_size; + +template <class _Tp, _StorageKind __kind, int _Np> +struct simd_size<_Tp, __simd_abi<__kind, _Np>> + : std::integral_constant<size_t, _Np> { + static_assert( + std::is_arithmetic<_Tp>::value && + !std::is_same<typename std::remove_const<_Tp>::type, bool>::value, + "Element type should be vectorizable"); +}; + +// TODO: implement it. +template <class _Tp, class _Up = typename _Tp::value_type> +struct memory_alignment; + +template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> +_LIBCPP_INLINE_VAR constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value; + +template <class _Tp, class _Up = typename _Tp::value_type> +_LIBCPP_INLINE_VAR constexpr size_t memory_alignment_v = + memory_alignment<_Tp, _Up>::value; + +// class template simd [simd.class] +template <class _Tp> +using native_simd = simd<_Tp, simd_abi::native<_Tp>>; +template <class _Tp, int _Np> +using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>; + +// class template simd_mask [simd.mask.class] +template <class _Tp> +using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>; + +template <class _Tp, int _Np> +using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>; + +// casts [simd.casts] +template <class _Tp> +struct __static_simd_cast_traits { + template <class _Up, class _Abi> + static simd<_Tp, _Abi> __apply(const simd<_Up, _Abi>& __v); +}; + +template <class _Tp, class _NewAbi> +struct __static_simd_cast_traits<simd<_Tp, _NewAbi>> { + template <class _Up, class _Abi> + static typename std::enable_if<simd<_Up, _Abi>::size() == + simd<_Tp, _NewAbi>::size(), + simd<_Tp, _NewAbi>>::type + __apply(const simd<_Up, _Abi>& __v); +}; + +template <class _Tp> +struct __simd_cast_traits { + template <class _Up, class _Abi> + static typename std::enable_if< + __is_non_narrowing_arithmetic_convertible<_Up, _Tp>(), + simd<_Tp, _Abi>>::type + __apply(const simd<_Up, _Abi>& __v); +}; + +template <class _Tp, class _NewAbi> +struct __simd_cast_traits<simd<_Tp, _NewAbi>> { + template <class _Up, class _Abi> + static typename std::enable_if< + __is_non_narrowing_arithmetic_convertible<_Up, _Tp>() && + simd<_Up, _Abi>::size() == simd<_Tp, _NewAbi>::size(), + simd<_Tp, _NewAbi>>::type + __apply(const simd<_Up, _Abi>& __v); +}; + +template <class _Tp, class _Up, class _Abi> +auto simd_cast(const simd<_Up, _Abi>& __v) + -> decltype(__simd_cast_traits<_Tp>::__apply(__v)) { + return __simd_cast_traits<_Tp>::__apply(__v); +} + +template <class _Tp, class _Up, class _Abi> +auto static_simd_cast(const simd<_Up, _Abi>& __v) + -> decltype(__static_simd_cast_traits<_Tp>::__apply(__v)) { + return __static_simd_cast_traits<_Tp>::__apply(__v); +} + +template <class _Tp, class _Abi> +fixed_size_simd<_Tp, simd_size<_Tp, _Abi>::value> +to_fixed_size(const simd<_Tp, _Abi>&) noexcept; + +template <class _Tp, class _Abi> +fixed_size_simd_mask<_Tp, simd_size<_Tp, _Abi>::value> +to_fixed_size(const simd_mask<_Tp, _Abi>&) noexcept; + +template <class _Tp, size_t _Np> +native_simd<_Tp> to_native(const fixed_size_simd<_Tp, _Np>&) noexcept; + +template <class _Tp, size_t _Np> +native_simd_mask<_Tp> to_native(const fixed_size_simd_mask<_Tp, _Np>&) noexcept; + +template <class _Tp, size_t _Np> +simd<_Tp> to_compatible(const fixed_size_simd<_Tp, _Np>&) noexcept; + +template <class _Tp, size_t _Np> +simd_mask<_Tp> to_compatible(const fixed_size_simd_mask<_Tp, _Np>&) noexcept; + +template <size_t... __sizes, class _Tp, class _Abi> +tuple<simd<_Tp, abi_for_size_t<_Tp, __sizes>>...> split(const simd<_Tp, _Abi>&); + +template <size_t... __sizes, class _Tp, class _Abi> +tuple<simd_mask<_Tp, abi_for_size_t<_Tp, __sizes>>...> +split(const simd_mask<_Tp, _Abi>&); + +template <class _SimdType, class _Abi> +array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / + _SimdType::size()> +split(const simd<typename _SimdType::value_type, _Abi>&); + +template <class _SimdType, class _Abi> +array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / + _SimdType::size()> +split(const simd_mask<typename _SimdType::value_type, _Abi>&); + +template <class _Tp, class... _Abis> +simd<_Tp, abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> +concat(const simd<_Tp, _Abis>&...); + +template <class _Tp, class... _Abis> +simd_mask<_Tp, + abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> +concat(const simd_mask<_Tp, _Abis>&...); + +// reductions [simd.mask.reductions] +template <class _Tp, class _Abi> +bool all_of(const simd_mask<_Tp, _Abi>&) noexcept; +template <class _Tp, class _Abi> +bool any_of(const simd_mask<_Tp, _Abi>&) noexcept; +template <class _Tp, class _Abi> +bool none_of(const simd_mask<_Tp, _Abi>&) noexcept; +template <class _Tp, class _Abi> +bool some_of(const simd_mask<_Tp, _Abi>&) noexcept; +template <class _Tp, class _Abi> +int popcount(const simd_mask<_Tp, _Abi>&) noexcept; +template <class _Tp, class _Abi> +int find_first_set(const simd_mask<_Tp, _Abi>&); +template <class _Tp, class _Abi> +int find_last_set(const simd_mask<_Tp, _Abi>&); +bool all_of(bool) noexcept; +bool any_of(bool) noexcept; +bool none_of(bool) noexcept; +bool some_of(bool) noexcept; +int popcount(bool) noexcept; +int find_first_set(bool) noexcept; +int find_last_set(bool) noexcept; + +// masked assignment [simd.whereexpr] +template <class _MaskType, class _Tp> +class const_where_expression; +template <class _MaskType, class _Tp> +class where_expression; + +// masked assignment [simd.mask.where] +template <class _Tp, class _Abi> +where_expression<simd_mask<_Tp, _Abi>, simd<_Tp, _Abi>> +where(const typename simd<_Tp, _Abi>::mask_type&, simd<_Tp, _Abi>&) noexcept; + +template <class _Tp, class _Abi> +const_where_expression<simd_mask<_Tp, _Abi>, const simd<_Tp, _Abi>> +where(const typename simd<_Tp, _Abi>::mask_type&, + const simd<_Tp, _Abi>&) noexcept; + +template <class _Tp, class _Abi> +where_expression<simd_mask<_Tp, _Abi>, simd_mask<_Tp, _Abi>> +where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, + simd_mask<_Tp, _Abi>&) noexcept; + +template <class _Tp, class _Abi> +const_where_expression<simd_mask<_Tp, _Abi>, const simd_mask<_Tp, _Abi>> +where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, + const simd_mask<_Tp, _Abi>&) noexcept; + +template <class _Tp> +where_expression<bool, _Tp> where(bool, _Tp&) noexcept; + +template <class _Tp> +const_where_expression<bool, const _Tp> where(bool, const _Tp&) noexcept; + +// reductions [simd.reductions] +template <class _Tp, class _Abi, class _BinaryOp = std::plus<_Tp>> +_Tp reduce(const simd<_Tp, _Abi>&, _BinaryOp = _BinaryOp()); + +template <class _MaskType, class _SimdType, class _BinaryOp> +typename _SimdType::value_type +reduce(const const_where_expression<_MaskType, _SimdType>&, + typename _SimdType::value_type neutral_element, _BinaryOp binary_op); + +template <class _MaskType, class _SimdType> +typename _SimdType::value_type +reduce(const const_where_expression<_MaskType, _SimdType>&, + plus<typename _SimdType::value_type> binary_op = {}); + +template <class _MaskType, class _SimdType> +typename _SimdType::value_type +reduce(const const_where_expression<_MaskType, _SimdType>&, + multiplies<typename _SimdType::value_type> binary_op); + +template <class _MaskType, class _SimdType> +typename _SimdType::value_type +reduce(const const_where_expression<_MaskType, _SimdType>&, + bit_and<typename _SimdType::value_type> binary_op); + +template <class _MaskType, class _SimdType> +typename _SimdType::value_type +reduce(const const_where_expression<_MaskType, _SimdType>&, + bit_or<typename _SimdType::value_type> binary_op); + +template <class _MaskType, class _SimdType> +typename _SimdType::value_type +reduce(const const_where_expression<_MaskType, _SimdType>&, + bit_xor<typename _SimdType::value_type> binary_op); + +template <class _Tp, class _Abi> +_Tp hmin(const simd<_Tp, _Abi>&); +template <class _MaskType, class _SimdType> +typename _SimdType::value_type +hmin(const const_where_expression<_MaskType, _SimdType>&); +template <class _Tp, class _Abi> +_Tp hmax(const simd<_Tp, _Abi>&); +template <class _MaskType, class _SimdType> +typename _SimdType::value_type +hmax(const const_where_expression<_MaskType, _SimdType>&); + +// algorithms [simd.alg] +template <class _Tp, class _Abi> +simd<_Tp, _Abi> min(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; + +template <class _Tp, class _Abi> +simd<_Tp, _Abi> max(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; + +template <class _Tp, class _Abi> +std::pair<simd<_Tp, _Abi>, simd<_Tp, _Abi>> +minmax(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; + +template <class _Tp, class _Abi> +simd<_Tp, _Abi> clamp(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&, + const simd<_Tp, _Abi>&); + +// [simd.whereexpr] +// TODO implement where expressions. +template <class _MaskType, class _Tp> +class const_where_expression { +public: + const_where_expression(const const_where_expression&) = delete; + const_where_expression& operator=(const const_where_expression&) = delete; + typename remove_const<_Tp>::type operator-() const&&; + template <class _Up, class _Flags> + void copy_to(_Up*, _Flags) const&&; +}; + +template <class _MaskType, class _Tp> +class where_expression : public const_where_expression<_MaskType, _Tp> { +public: + where_expression(const where_expression&) = delete; + where_expression& operator=(const where_expression&) = delete; + template <class _Up> + void operator=(_Up&&); + template <class _Up> + void operator+=(_Up&&); + template <class _Up> + void operator-=(_Up&&); + template <class _Up> + void operator*=(_Up&&); + template <class _Up> + void operator/=(_Up&&); + template <class _Up> + void operator%=(_Up&&); + template <class _Up> + void operator&=(_Up&&); + template <class _Up> + void operator|=(_Up&&); + template <class _Up> + void operator^=(_Up&&); + template <class _Up> + void operator<<=(_Up&&); + template <class _Up> + void operator>>=(_Up&&); + void operator++(); + void operator++(int); + void operator--(); + void operator--(int); + template <class _Up, class _Flags> + void copy_from(const _Up*, _Flags); +}; + +// [simd.class] +// TODO: implement simd +template <class _Tp, class _Abi> +class simd { +public: + using value_type = _Tp; + using reference = __simd_reference<_Tp, _Tp, _Abi>; + using mask_type = simd_mask<_Tp, _Abi>; + using abi_type = _Abi; + + simd() = default; + simd(const simd&) = default; + simd& operator=(const simd&) = default; + + static constexpr size_t size() noexcept { + return simd_size<_Tp, _Abi>::value; + } + +private: + __simd_storage<_Tp, _Abi> __s_; + + template <class _Up> + static constexpr bool __can_broadcast() { + return (std::is_arithmetic<_Up>::value && + __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()) || + (!std::is_arithmetic<_Up>::value && + std::is_convertible<_Up, _Tp>::value) || + std::is_same<typename std::remove_const<_Up>::type, int>::value || + (std::is_same<typename std::remove_const<_Up>::type, + unsigned int>::value && + std::is_unsigned<_Tp>::value); + } + + template <class _Generator, size_t... __indicies> + static constexpr decltype( + std::forward_as_tuple(std::declval<_Generator>()( + std::integral_constant<size_t, __indicies>())...), + bool()) + __can_generate(std::index_sequence<__indicies...>) { + return !__variadic_sum<bool>( + !__can_broadcast<decltype(std::declval<_Generator>()( + std::integral_constant<size_t, __indicies>()))>()...); + } + + template <class _Generator> + static bool __can_generate(...) { + return false; + } + + template <class _Generator, size_t... __indicies> + void __generator_init(_Generator&& __g, std::index_sequence<__indicies...>) { + int __not_used[]{((*this)[__indicies] = + __g(std::integral_constant<size_t, __indicies>()), + 0)...}; + (void)__not_used; + } + +public: + // implicit type conversion constructor + template <class _Up, + class = typename std::enable_if< + std::is_same<_Abi, simd_abi::fixed_size<size()>>::value && + __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()>::type> + simd(const simd<_Up, simd_abi::fixed_size<size()>>& __v) { + for (size_t __i = 0; __i < size(); __i++) { + (*this)[__i] = static_cast<_Tp>(__v[__i]); + } + } + + // implicit broadcast constructor + template <class _Up, + class = typename std::enable_if<__can_broadcast<_Up>()>::type> + simd(_Up&& __rv) { + auto __v = static_cast<_Tp>(__rv); + for (size_t __i = 0; __i < size(); __i++) { + (*this)[__i] = __v; + } + } + + // generator constructor + template <class _Generator, + int = typename std::enable_if< + __can_generate<_Generator>(std::make_index_sequence<size()>()), + int>::type()> + explicit simd(_Generator&& __g) { + __generator_init(std::forward<_Generator>(__g), + std::make_index_sequence<size()>()); + } + + // load constructor + template < + class _Up, class _Flags, + class = typename std::enable_if<__vectorizable<_Up>()>::type, + class = typename std::enable_if<is_simd_flag_type<_Flags>::value>::type> + simd(const _Up* __buffer, _Flags) { + // TODO: optimize for overaligned flags + for (size_t __i = 0; __i < size(); __i++) { + (*this)[__i] = static_cast<_Tp>(__buffer[__i]); + } + } + + // loads [simd.load] + template <class _Up, class _Flags> + typename std::enable_if<__vectorizable<_Up>() && + is_simd_flag_type<_Flags>::value>::type + copy_from(const _Up* __buffer, _Flags) { + *this = simd(__buffer, _Flags()); + } + + // stores [simd.store] + template <class _Up, class _Flags> + typename std::enable_if<__vectorizable<_Up>() && + is_simd_flag_type<_Flags>::value>::type + copy_to(_Up* __buffer, _Flags) const { + // TODO: optimize for overaligned flags + for (size_t __i = 0; __i < size(); __i++) { + __buffer[__i] = static_cast<_Up>((*this)[__i]); + } + } + + // scalar access [simd.subscr] + reference operator[](size_t __i) { return reference(&__s_, __i); } + + value_type operator[](size_t __i) const { return __s_.__get(__i); } + + // unary operators [simd.unary] + simd& operator++(); + simd operator++(int); + simd& operator--(); + simd operator--(int); + mask_type operator!() const; + simd operator~() const; + simd operator+() const; + simd operator-() const; + + // binary operators [simd.binary] + friend simd operator+(const simd&, const simd&); + friend simd operator-(const simd&, const simd&); + friend simd operator*(const simd&, const simd&); + friend simd operator/(const simd&, const simd&); + friend simd operator%(const simd&, const simd&); + friend simd operator&(const simd&, const simd&); + friend simd operator|(const simd&, const simd&); + friend simd operator^(const simd&, const simd&); + friend simd operator<<(const simd&, const simd&); + friend simd operator>>(const simd&, const simd&); + friend simd operator<<(const simd&, int); + friend simd operator>>(const simd&, int); + + // compound assignment [simd.cassign] + friend simd& operator+=(simd&, const simd&); + friend simd& operator-=(simd&, const simd&); + friend simd& operator*=(simd&, const simd&); + friend simd& operator/=(simd&, const simd&); + friend simd& operator%=(simd&, const simd&); + + friend simd& operator&=(simd&, const simd&); + friend simd& operator|=(simd&, const simd&); + friend simd& operator^=(simd&, const simd&); + friend simd& operator<<=(simd&, const simd&); + friend simd& operator>>=(simd&, const simd&); + friend simd& operator<<=(simd&, int); + friend simd& operator>>=(simd&, int); + + // compares [simd.comparison] + friend mask_type operator==(const simd&, const simd&); + friend mask_type operator!=(const simd&, const simd&); + friend mask_type operator>=(const simd&, const simd&); + friend mask_type operator<=(const simd&, const simd&); + friend mask_type operator>(const simd&, const simd&); + friend mask_type operator<(const simd&, const simd&); +}; + +// [simd.mask.class] +template <class _Tp, class _Abi> +// TODO: implement simd_mask +class simd_mask { +public: + using value_type = bool; + // TODO: this is strawman implementation. Turn it into a proxy type. + using reference = bool&; + using simd_type = simd<_Tp, _Abi>; + using abi_type = _Abi; + static constexpr size_t size() noexcept; + simd_mask() = default; + + // broadcast constructor + explicit simd_mask(value_type) noexcept; + + // implicit type conversion constructor + template <class _Up> + simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>&) noexcept; + + // load constructor + template <class _Flags> + simd_mask(const value_type*, _Flags); + + // loads [simd.mask.copy] + template <class _Flags> + void copy_from(const value_type*, _Flags); + template <class _Flags> + void copy_to(value_type*, _Flags) const; + + // scalar access [simd.mask.subscr] + reference operator[](size_t); + value_type operator[](size_t) const; + + // unary operators [simd.mask.unary] + simd_mask operator!() const noexcept; + + // simd_mask binary operators [simd.mask.binary] + friend simd_mask operator&&(const simd_mask&, const simd_mask&) noexcept; + friend simd_mask operator||(const simd_mask&, const simd_mask&) noexcept; + friend simd_mask operator&(const simd_mask&, const simd_mask&)noexcept; + friend simd_mask operator|(const simd_mask&, const simd_mask&) noexcept; + friend simd_mask operator^(const simd_mask&, const simd_mask&) noexcept; + + // simd_mask compound assignment [simd.mask.cassign] + friend simd_mask& operator&=(simd_mask&, const simd_mask&) noexcept; + friend simd_mask& operator|=(simd_mask&, const simd_mask&) noexcept; + friend simd_mask& operator^=(simd_mask&, const simd_mask&) noexcept; + + // simd_mask compares [simd.mask.comparison] + friend simd_mask operator==(const simd_mask&, const simd_mask&) noexcept; + friend simd_mask operator!=(const simd_mask&, const simd_mask&) noexcept; +}; + +#endif // _LIBCPP_STD_VER >= 17 + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD + +#endif /* _LIBCPP_EXPERIMENTAL_SIMD */ diff --git a/android/x86/include/v8/libc++/experimental/string b/android/x86/include/v8/libc++/experimental/string new file mode 100755 index 00000000..264ff923 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/string @@ -0,0 +1,61 @@ +// -*- C++ -*- +//===--------------------------- string ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_STRING +#define _LIBCPP_EXPERIMENTAL_STRING +/* + experimental/string synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + // basic_string using polymorphic allocator in namespace pmr + template <class charT, class traits = char_traits<charT>> + using basic_string = + std::basic_string<charT, traits, polymorphic_allocator<charT>>; + + // basic_string typedef names using polymorphic allocator in namespace + // std::experimental::pmr + typedef basic_string<char> string; + typedef basic_string<char16_t> u16string; + typedef basic_string<char32_t> u32string; + typedef basic_string<wchar_t> wstring; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <string> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _CharT, class _Traits = char_traits<_CharT>> +using basic_string = + _VSTD::basic_string<_CharT, _Traits, polymorphic_allocator<_CharT>>; + +typedef basic_string<char> string; +typedef basic_string<char16_t> u16string; +typedef basic_string<char32_t> u32string; +typedef basic_string<wchar_t> wstring; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_STRING */ diff --git a/android/x86/include/v8/libc++/experimental/string_view b/android/x86/include/v8/libc++/experimental/string_view new file mode 100755 index 00000000..4b59e6d0 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/string_view @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===------------------------ string_view ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_STRING_VIEW +#define _LIBCPP_EXPERIMENTAL_STRING_VIEW + +#include <__config> + +#ifdef _LIBCPP_WARNING +_LIBCPP_WARNING("<experimental/string_view> has been removed. Use <string_view> instead.") +#else +# warning "<experimental/string_view> has been removed. Use <string_view> instead." +#endif + +#endif // _LIBCPP_EXPERIMENTAL_STRING_VIEW diff --git a/android/x86/include/v8/libc++/experimental/system_error b/android/x86/include/v8/libc++/experimental/system_error new file mode 100755 index 00000000..094e6d36 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/system_error @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===-------------------------- system_error ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_SYSTEM_ERROR +#define _LIBCPP_EXPERIMENTAL_SYSTEM_ERROR + +#include <__config> + +#ifdef _LIBCPP_WARNING +_LIBCPP_WARNING("<experimental/system_error> has been removed. Use <system_error> instead.") +#else +# warning "<experimental/system_error> has been removed. Use <system_error> instead." +#endif + +#endif // _LIBCPP_EXPERIMENTAL_SYSTEM_ERROR diff --git a/android/x86/include/v8/libc++/experimental/tuple b/android/x86/include/v8/libc++/experimental/tuple new file mode 100755 index 00000000..827ef37a --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/tuple @@ -0,0 +1,20 @@ +// -*- C++ -*- +//===----------------------------- tuple ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_EXPERIMENTAL_TUPLE +#define _LIBCPP_EXPERIMENTAL_TUPLE + +#include <__config> + +#ifdef _LIBCPP_WARNING +_LIBCPP_WARNING("<experimental/tuple> has been removed. Use <tuple> instead.") +#else +# warning "<experimental/tuple> has been removed. Use <tuple> instead." +#endif + +#endif // _LIBCPP_EXPERIMENTAL_TUPLE diff --git a/android/x86/include/v8/libc++/experimental/type_traits b/android/x86/include/v8/libc++/experimental/type_traits new file mode 100755 index 00000000..3127c0ea --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/type_traits @@ -0,0 +1,154 @@ +// -*- C++ -*- +//===-------------------------- type_traits -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_TYPE_TRAITS +#define _LIBCPP_EXPERIMENTAL_TYPE_TRAITS + +/** + experimental/type_traits synopsis + +// C++1y +#include <type_traits> + +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { + + // 3.3.2, Other type transformations + template <class> class invocation_type; // not defined + template <class F, class... ArgTypes> class invocation_type<F(ArgTypes...)>; + template <class> class raw_invocation_type; // not defined + template <class F, class... ArgTypes> class raw_invocation_type<F(ArgTypes...)>; + + template <class T> + using invocation_type_t = typename invocation_type<T>::type; + template <class T> + using raw_invocation_type_t = typename raw_invocation_type<T>::type; + + // 3.3.4, Detection idiom + template <class...> using void_t = void; + + struct nonesuch { + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + void operator=(nonesuch const&) = delete; + }; + + template <template<class...> class Op, class... Args> + using is_detected = see below; + template <template<class...> class Op, class... Args> + constexpr bool is_detected_v = is_detected<Op, Args...>::value; + template <template<class...> class Op, class... Args> + using detected_t = see below; + template <class Default, template<class...> class Op, class... Args> + using detected_or = see below; + template <class Default, template<class...> class Op, class... Args> + using detected_or_t = typename detected_or<Default, Op, Args...>::type; + template <class Expected, template<class...> class Op, class... Args> + using is_detected_exact = is_same<Expected, detected_t<Op, Args...>>; + template <class Expected, template<class...> class Op, class... Args> + constexpr bool is_detected_exact_v + = is_detected_exact<Expected, Op, Args...>::value; + template <class To, template<class...> class Op, class... Args> + using is_detected_convertible = is_convertible<detected_t<Op, Args...>, To>; + template <class To, template<class...> class Op, class... Args> + constexpr bool is_detected_convertible_v + = is_detected_convertible<To, Op, Args...>::value; + +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> + +#if _LIBCPP_STD_VER > 11 + +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS + +// 3.3.2, Other type transformations +/* +template <class> +class _LIBCPP_TEMPLATE_VIS raw_invocation_type; + +template <class _Fn, class ..._Args> +class _LIBCPP_TEMPLATE_VIS raw_invocation_type<_Fn(_Args...)>; + +template <class> +class _LIBCPP_TEMPLATE_VIS invokation_type; + +template <class _Fn, class ..._Args> +class _LIBCPP_TEMPLATE_VIS invokation_type<_Fn(_Args...)>; + +template <class _Tp> +using invokation_type_t = typename invokation_type<_Tp>::type; + +template <class _Tp> +using raw_invocation_type_t = typename raw_invocation_type<_Tp>::type; +*/ + +// 3.3.4, Detection idiom +template <class...> using void_t = void; + +struct nonesuch { + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch (nonesuch const&) = delete; + void operator=(nonesuch const&) = delete; + }; + +template <class _Default, class _AlwaysVoid, template <class...> class _Op, class... _Args> +struct _DETECTOR { + using value_t = false_type; + using type = _Default; + }; + +template <class _Default, template <class...> class _Op, class... _Args> +struct _DETECTOR<_Default, void_t<_Op<_Args...>>, _Op, _Args...> { + using value_t = true_type; + using type = _Op<_Args...>; + }; + + +template <template<class...> class _Op, class... _Args> + using is_detected = typename _DETECTOR<nonesuch, void, _Op, _Args...>::value_t; +template <template<class...> class _Op, class... _Args> + using detected_t = typename _DETECTOR<nonesuch, void, _Op, _Args...>::type; +template <template<class...> class _Op, class... _Args> + _LIBCPP_CONSTEXPR bool is_detected_v = is_detected<_Op, _Args...>::value; + +template <class Default, template<class...> class _Op, class... _Args> + using detected_or = _DETECTOR<Default, void, _Op, _Args...>; +template <class Default, template<class...> class _Op, class... _Args> + using detected_or_t = typename detected_or<Default, _Op, _Args...>::type; + +template <class Expected, template<class...> class _Op, class... _Args> + using is_detected_exact = is_same<Expected, detected_t<_Op, _Args...>>; +template <class Expected, template<class...> class _Op, class... _Args> + _LIBCPP_CONSTEXPR bool is_detected_exact_v = is_detected_exact<Expected, _Op, _Args...>::value; + +template <class To, template<class...> class _Op, class... _Args> + using is_detected_convertible = is_convertible<detected_t<_Op, _Args...>, To>; +template <class To, template<class...> class _Op, class... _Args> + _LIBCPP_CONSTEXPR bool is_detected_convertible_v = is_detected_convertible<To, _Op, _Args...>::value; + + +_LIBCPP_END_NAMESPACE_LFTS + +#endif /* _LIBCPP_STD_VER > 11 */ + +#endif /* _LIBCPP_EXPERIMENTAL_TYPE_TRAITS */ diff --git a/android/x86/include/v8/libc++/experimental/unordered_map b/android/x86/include/v8/libc++/experimental/unordered_map new file mode 100755 index 00000000..eca9cea7 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/unordered_map @@ -0,0 +1,64 @@ +// -*- C++ -*- +//===------------------------- unordered_map ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_UNORDERED_MAP +#define _LIBCPP_EXPERIMENTAL_UNORDERED_MAP +/* + experimental/unordered_map synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + template <class Key, class T, + class Hash = hash<Key>, + class Pred = equal_to<Key>> + using unordered_map = + std::unordered_map<Key, T, Hash, Pred, + polymorphic_allocator<pair<const Key,T>>>; + + template <class Key, class T, + class Hash = hash<Key>, + class Pred = equal_to<Key>> + using unordered_multimap = + std::unordered_multimap<Key, T, Hash, Pred, + polymorphic_allocator<pair<const Key,T>>>; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <unordered_map> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _Key, class _Value, + class _Hash = hash<_Key>, class _Pred = equal_to<_Key>> +using unordered_map = _VSTD::unordered_map<_Key, _Value, _Hash, _Pred, + polymorphic_allocator<pair<const _Key, _Value>>>; + +template <class _Key, class _Value, + class _Hash = hash<_Key>, class _Pred = equal_to<_Key>> +using unordered_multimap = _VSTD::unordered_multimap<_Key, _Value, _Hash, _Pred, + polymorphic_allocator<pair<const _Key, _Value>>>; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_UNORDERED_MAP */ diff --git a/android/x86/include/v8/libc++/experimental/unordered_set b/android/x86/include/v8/libc++/experimental/unordered_set new file mode 100755 index 00000000..323868f7 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/unordered_set @@ -0,0 +1,58 @@ +// -*- C++ -*- +//===------------------------- unordered_set ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_UNORDERED_SET +#define _LIBCPP_EXPERIMENTAL_UNORDERED_SET +/* + experimental/unordered_set synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + template <class T, class Hash = hash<T>, class Pred = equal_to<T>> + using unordered_set = std::unordered_set<T, Hash, Pred, + polymorphic_allocator<T>>; + + template <class T, class Hash = hash<T>, class Pred = equal_to<T>> + using unordered_multiset = std::unordered_multiset<T, Hash, Pred, + polymorphic_allocator<T>>; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <unordered_set> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _Value, + class _Hash = hash<_Value>, class _Pred = equal_to<_Value>> +using unordered_set = _VSTD::unordered_set<_Value, _Hash, _Pred, + polymorphic_allocator<_Value>>; + +template <class _Value, + class _Hash = hash<_Value>, class _Pred = equal_to<_Value>> +using unordered_multiset = _VSTD::unordered_multiset<_Value, _Hash, _Pred, + polymorphic_allocator<_Value>>; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_UNORDERED_SET */ diff --git a/android/x86/include/v8/libc++/experimental/utility b/android/x86/include/v8/libc++/experimental/utility new file mode 100755 index 00000000..0bca0f7c --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/utility @@ -0,0 +1,46 @@ +// -*- C++ -*- +//===-------------------------- utility ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_UTILITY +#define _LIBCPP_EXPERIMENTAL_UTILITY + +/* + experimental/utility synopsis + +// C++1y + +#include <utility> + +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { + + 3.1.2, erased-type placeholder + struct erased_type { }; + +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <utility> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS + + struct _LIBCPP_TEMPLATE_VIS erased_type { }; + +_LIBCPP_END_NAMESPACE_LFTS + +#endif /* _LIBCPP_EXPERIMENTAL_UTILITY */ diff --git a/android/x86/include/v8/libc++/experimental/vector b/android/x86/include/v8/libc++/experimental/vector new file mode 100755 index 00000000..9b810120 --- /dev/null +++ b/android/x86/include/v8/libc++/experimental/vector @@ -0,0 +1,46 @@ +// -*- C++ -*- +//===--------------------------- vector ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_VECTOR +#define _LIBCPP_EXPERIMENTAL_VECTOR +/* + experimental/vector synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { +namespace pmr { + + template <class T> + using vector = std::vector<T, polymorphic_allocator<T>>; + +} // namespace pmr +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <vector> +#include <experimental/memory_resource> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR + +template <class _ValueT> +using vector = _VSTD::vector<_ValueT, polymorphic_allocator<_ValueT>>; + +_LIBCPP_END_NAMESPACE_LFTS_PMR + +#endif /* _LIBCPP_EXPERIMENTAL_VECTOR */ diff --git a/android/x86/include/v8/libc++/ext/__hash b/android/x86/include/v8/libc++/ext/__hash new file mode 100755 index 00000000..98a95448 --- /dev/null +++ b/android/x86/include/v8/libc++/ext/__hash @@ -0,0 +1,134 @@ +// -*- C++ -*- +//===------------------------- hash_set ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXT_HASH +#define _LIBCPP_EXT_HASH + +#pragma GCC system_header + +#include <string> +#include <cstring> + +namespace __gnu_cxx { +using namespace std; + +template <typename _Tp> struct _LIBCPP_TEMPLATE_VIS hash { }; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<const char*> + : public unary_function<const char*, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const char *__c) const _NOEXCEPT + { + return __do_string_hash(__c, __c + strlen(__c)); + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<char *> + : public unary_function<char*, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char *__c) const _NOEXCEPT + { + return __do_string_hash<const char *>(__c, __c + strlen(__c)); + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<char> + : public unary_function<char, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char __c) const _NOEXCEPT + { + return __c; + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<signed char> + : public unary_function<signed char, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(signed char __c) const _NOEXCEPT + { + return __c; + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> + : public unary_function<unsigned char, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned char __c) const _NOEXCEPT + { + return __c; + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<short> + : public unary_function<short, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(short __c) const _NOEXCEPT + { + return __c; + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> + : public unary_function<unsigned short, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned short __c) const _NOEXCEPT + { + return __c; + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<int> + : public unary_function<int, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(int __c) const _NOEXCEPT + { + return __c; + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> + : public unary_function<unsigned int, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned int __c) const _NOEXCEPT + { + return __c; + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<long> + : public unary_function<long, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(long __c) const _NOEXCEPT + { + return __c; + } +}; + +template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> + : public unary_function<unsigned long, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned long __c) const _NOEXCEPT + { + return __c; + } +}; +} + +#endif // _LIBCPP_EXT_HASH diff --git a/android/x86/include/v8/libc++/ext/hash_map b/android/x86/include/v8/libc++/ext/hash_map new file mode 100755 index 00000000..d06a9e36 --- /dev/null +++ b/android/x86/include/v8/libc++/ext/hash_map @@ -0,0 +1,983 @@ +// -*- C++ -*- +//===-------------------------- hash_map ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_HASH_MAP +#define _LIBCPP_HASH_MAP + +/* + + hash_map synopsis + +namespace __gnu_cxx +{ + +template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, + class Alloc = allocator<pair<const Key, T>>> +class hash_map +{ +public: + // types + typedef Key key_type; + typedef T mapped_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef pair<const key_type, mapped_type> value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + + explicit hash_map(size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template <class InputIterator> + hash_map(InputIterator f, InputIterator l, + size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + hash_map(const hash_map&); + ~hash_map(); + hash_map& operator=(const hash_map&); + + allocator_type get_allocator() const; + + bool empty() const; + size_type size() const; + size_type max_size() const; + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + pair<iterator, bool> insert(const value_type& obj); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + + void erase(const_iterator position); + size_type erase(const key_type& k); + void erase(const_iterator first, const_iterator last); + void clear(); + + void swap(hash_map&); + + hasher hash_funct() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair<iterator, iterator> equal_range(const key_type& k); + pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + + mapped_type& operator[](const key_type& k); + + size_type bucket_count() const; + size_type max_bucket_count() const; + + size_type elems_in_bucket(size_type n) const; + + void resize(size_type n); +}; + +template <class Key, class T, class Hash, class Pred, class Alloc> + void swap(hash_map<Key, T, Hash, Pred, Alloc>& x, + hash_map<Key, T, Hash, Pred, Alloc>& y); + +template <class Key, class T, class Hash, class Pred, class Alloc> + bool + operator==(const hash_map<Key, T, Hash, Pred, Alloc>& x, + const hash_map<Key, T, Hash, Pred, Alloc>& y); + +template <class Key, class T, class Hash, class Pred, class Alloc> + bool + operator!=(const hash_map<Key, T, Hash, Pred, Alloc>& x, + const hash_map<Key, T, Hash, Pred, Alloc>& y); + +template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, + class Alloc = allocator<pair<const Key, T>>> +class hash_multimap +{ +public: + // types + typedef Key key_type; + typedef T mapped_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef pair<const key_type, mapped_type> value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + + explicit hash_multimap(size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template <class InputIterator> + hash_multimap(InputIterator f, InputIterator l, + size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + explicit hash_multimap(const allocator_type&); + hash_multimap(const hash_multimap&); + ~hash_multimap(); + hash_multimap& operator=(const hash_multimap&); + + allocator_type get_allocator() const; + + bool empty() const; + size_type size() const; + size_type max_size() const; + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + iterator insert(const value_type& obj); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + + void erase(const_iterator position); + size_type erase(const key_type& k); + void erase(const_iterator first, const_iterator last); + void clear(); + + void swap(hash_multimap&); + + hasher hash_funct() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair<iterator, iterator> equal_range(const key_type& k); + pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + + size_type bucket_count() const; + size_type max_bucket_count() const; + + size_type elems_in_bucket(size_type n) const; + + void resize(size_type n); +}; + +template <class Key, class T, class Hash, class Pred, class Alloc> + void swap(hash_multimap<Key, T, Hash, Pred, Alloc>& x, + hash_multimap<Key, T, Hash, Pred, Alloc>& y); + +template <class Key, class T, class Hash, class Pred, class Alloc> + bool + operator==(const hash_multimap<Key, T, Hash, Pred, Alloc>& x, + const hash_multimap<Key, T, Hash, Pred, Alloc>& y); + +template <class Key, class T, class Hash, class Pred, class Alloc> + bool + operator!=(const hash_multimap<Key, T, Hash, Pred, Alloc>& x, + const hash_multimap<Key, T, Hash, Pred, Alloc>& y); + +} // __gnu_cxx + +*/ + +#include <__config> +#include <__hash_table> +#include <functional> +#include <stdexcept> +#include <type_traits> +#include <ext/__hash> + +#if __DEPRECATED +#if defined(_LIBCPP_WARNING) + _LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>") +#else +# warning Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map> +#endif +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace __gnu_cxx { + +using namespace std; + +template <class _Tp, class _Hash, + bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value + > +class __hash_map_hasher + : private _Hash +{ +public: + _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : _Hash() {} + _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : _Hash(__h) {} + _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return *this;} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const _Tp& __x) const + {return static_cast<const _Hash&>(*this)(__x.first);} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const typename _Tp::first_type& __x) const + {return static_cast<const _Hash&>(*this)(__x);} +}; + +template <class _Tp, class _Hash> +class __hash_map_hasher<_Tp, _Hash, false> +{ + _Hash __hash_; +public: + _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : __hash_() {} + _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : __hash_(__h) {} + _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return __hash_;} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const _Tp& __x) const + {return __hash_(__x.first);} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const typename _Tp::first_type& __x) const + {return __hash_(__x);} +}; + +template <class _Tp, class _Pred, + bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value + > +class __hash_map_equal + : private _Pred +{ +public: + _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : _Pred() {} + _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : _Pred(__p) {} + _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return *this;} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return static_cast<const _Pred&>(*this)(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const + {return static_cast<const _Pred&>(*this)(__x, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const + {return static_cast<const _Pred&>(*this)(__x.first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Tp::first_type& __x, + const typename _Tp::first_type& __y) const + {return static_cast<const _Pred&>(*this)(__x, __y);} +}; + +template <class _Tp, class _Pred> +class __hash_map_equal<_Tp, _Pred, false> +{ + _Pred __pred_; +public: + _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : __pred_() {} + _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : __pred_(__p) {} + _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return __pred_;} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __pred_(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const + {return __pred_(__x, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const + {return __pred_(__x.first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Tp::first_type& __x, + const typename _Tp::first_type& __y) const + {return __pred_(__x, __y);} +}; + +template <class _Alloc> +class __hash_map_node_destructor +{ + typedef _Alloc allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __alloc_traits::value_type::__node_value_type value_type; +public: + typedef typename __alloc_traits::pointer pointer; +private: + typedef typename value_type::first_type first_type; + typedef typename value_type::second_type second_type; + + allocator_type& __na_; + + __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); + +public: + bool __first_constructed; + bool __second_constructed; + + _LIBCPP_INLINE_VISIBILITY + explicit __hash_map_node_destructor(allocator_type& __na) + : __na_(__na), + __first_constructed(false), + __second_constructed(false) + {} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) + : __na_(__x.__na_), + __first_constructed(__x.__value_constructed), + __second_constructed(__x.__value_constructed) + { + __x.__value_constructed = false; + } +#else // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) + : __na_(__x.__na_), + __first_constructed(__x.__value_constructed), + __second_constructed(__x.__value_constructed) + { + const_cast<bool&>(__x.__value_constructed) = false; + } +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) + { + if (__second_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); + if (__first_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } +}; + +template <class _HashIterator> +class _LIBCPP_TEMPLATE_VIS __hash_map_iterator +{ + _HashIterator __i_; + + typedef const typename _HashIterator::value_type::first_type key_type; + typedef typename _HashIterator::value_type::second_type mapped_type; +public: + typedef forward_iterator_tag iterator_category; + typedef pair<key_type, mapped_type> value_type; + typedef typename _HashIterator::difference_type difference_type; + typedef value_type& reference; + typedef typename __rebind_pointer<typename _HashIterator::pointer, value_type>::type + pointer; + + _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {} + + _LIBCPP_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();} + + _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __hash_map_iterator operator++(int) + { + __hash_map_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; +}; + +template <class _HashIterator> +class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator +{ + _HashIterator __i_; + + typedef const typename _HashIterator::value_type::first_type key_type; + typedef typename _HashIterator::value_type::second_type mapped_type; +public: + typedef forward_iterator_tag iterator_category; + typedef pair<key_type, mapped_type> value_type; + typedef typename _HashIterator::difference_type difference_type; + typedef const value_type& reference; + typedef typename __rebind_pointer<typename _HashIterator::pointer, const value_type>::type + pointer; + + _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {} + + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {} + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator( + __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) + : __i_(__i.__i_) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return *operator->();} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return (pointer)__i_.operator->();} + + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator operator++(int) + { + __hash_map_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; +}; + +template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, + class _Alloc = allocator<pair<const _Key, _Tp> > > +class _LIBCPP_TEMPLATE_VIS hash_map +{ +public: + // types + typedef _Key key_type; + typedef _Tp mapped_type; + typedef _Tp data_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef pair<const key_type, mapped_type> value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + +private: + typedef pair<key_type, mapped_type> __value_type; + typedef __hash_map_hasher<__value_type, hasher> __hasher; + typedef __hash_map_equal<__value_type, key_equal> __key_equal; + typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type; + + typedef __hash_table<__value_type, __hasher, + __key_equal, __allocator_type> __table; + + __table __table_; + + typedef typename __table::__node_pointer __node_pointer; + typedef typename __table::__node_const_pointer __node_const_pointer; + typedef typename __table::__node_traits __node_traits; + typedef typename __table::__node_allocator __node_allocator; + typedef typename __table::__node __node; + typedef __hash_map_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + typedef allocator_traits<allocator_type> __alloc_traits; +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + + typedef __hash_map_iterator<typename __table::iterator> iterator; + typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; + + _LIBCPP_INLINE_VISIBILITY hash_map() {__table_.rehash(193);} + explicit hash_map(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + hash_map(size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + template <class _InputIterator> + hash_map(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + hash_map(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template <class _InputIterator> + hash_map(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + hash_map(const hash_map& __u); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert(const value_type& __x) + {return __table_.__insert_unique(__x);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __p) {__table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __first, const_iterator __last) + {__table_.erase(__first.__i_, __last.__i_);} + _LIBCPP_INLINE_VISIBILITY + void clear() {__table_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(hash_map& __u) {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_funct() const + {return __table_.hash_function().hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const + {return __table_.key_eq().key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<iterator, iterator> equal_range(const key_type& __k) + {return __table_.__equal_range_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + {return __table_.__equal_range_unique(__k);} + + mapped_type& operator[](const key_type& __k); + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type elems_in_bucket(size_type __n) const + {return __table_.bucket_size(__n);} + + _LIBCPP_INLINE_VISIBILITY + void resize(size_type __n) {__table_.rehash(__n);} + +private: + __node_holder __construct_node(const key_type& __k); +}; + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + size_type __n, const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + _InputIterator __first, _InputIterator __last) +{ + __table_.rehash(193); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + const hash_map& __u) + : __table_(__u.__table_) +{ + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k) +{ + __node_allocator& __na = __table_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __h.get_deleter().__second_constructed = true; + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +inline +void +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_unique(*__first); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +_Tp& +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) +{ + iterator __i = find(__k); + if (__i != end()) + return __i->second; + __node_holder __h = __construct_node(__k); + pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); + __h.release(); + return __r.first->second; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + __x.swap(__y); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +bool +operator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); + __i != __ex; ++__i) + { + const_iterator __j = __y.find(__i->first); + if (__j == __ey || !(*__i == *__j)) + return false; + } + return true; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, + class _Alloc = allocator<pair<const _Key, _Tp> > > +class _LIBCPP_TEMPLATE_VIS hash_multimap +{ +public: + // types + typedef _Key key_type; + typedef _Tp mapped_type; + typedef _Tp data_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef pair<const key_type, mapped_type> value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + +private: + typedef pair<key_type, mapped_type> __value_type; + typedef __hash_map_hasher<__value_type, hasher> __hasher; + typedef __hash_map_equal<__value_type, key_equal> __key_equal; + typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type; + + typedef __hash_table<__value_type, __hasher, + __key_equal, __allocator_type> __table; + + __table __table_; + + typedef typename __table::__node_traits __node_traits; + typedef typename __table::__node_allocator __node_allocator; + typedef typename __table::__node __node; + typedef __hash_map_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + typedef allocator_traits<allocator_type> __alloc_traits; +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + + typedef __hash_map_iterator<typename __table::iterator> iterator; + typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; + + _LIBCPP_INLINE_VISIBILITY + hash_multimap() {__table_.rehash(193);} + explicit hash_multimap(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + hash_multimap(size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + template <class _InputIterator> + hash_multimap(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + hash_multimap(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template <class _InputIterator> + hash_multimap(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + hash_multimap(const hash_multimap& __u); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator, const value_type& __x) {return insert(__x);} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __p) {__table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __first, const_iterator __last) + {__table_.erase(__first.__i_, __last.__i_);} + _LIBCPP_INLINE_VISIBILITY + void clear() {__table_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(hash_multimap& __u) {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_funct() const + {return __table_.hash_function().hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const + {return __table_.key_eq().key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<iterator, iterator> equal_range(const key_type& __k) + {return __table_.__equal_range_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + {return __table_.__equal_range_multi(__k);} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type elems_in_bucket(size_type __n) const + {return __table_.bucket_size(__n);} + + _LIBCPP_INLINE_VISIBILITY + void resize(size_type __n) {__table_.rehash(__n);} +}; + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + size_type __n, const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + _InputIterator __first, _InputIterator __last) +{ + __table_.rehash(193); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + const hash_multimap& __u) + : __table_(__u.__table_) +{ + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +inline +void +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_multi(*__first); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + __x.swap(__y); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +bool +operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + typedef pair<const_iterator, const_iterator> _EqRng; + for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) + { + _EqRng __xeq = __x.equal_range(__i->first); + _EqRng __yeq = __y.equal_range(__i->first); + if (_VSTD::distance(__xeq.first, __xeq.second) != + _VSTD::distance(__yeq.first, __yeq.second) || + !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) + return false; + __i = __xeq.second; + } + return true; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +} // __gnu_cxx + +#endif // _LIBCPP_HASH_MAP diff --git a/android/x86/include/v8/libc++/ext/hash_set b/android/x86/include/v8/libc++/ext/hash_set new file mode 100755 index 00000000..21e66877 --- /dev/null +++ b/android/x86/include/v8/libc++/ext/hash_set @@ -0,0 +1,662 @@ +// -*- C++ -*- +//===------------------------- hash_set ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_HASH_SET +#define _LIBCPP_HASH_SET + +/* + + hash_set synopsis + +namespace __gnu_cxx +{ + +template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, + class Alloc = allocator<Value>> +class hash_set +{ +public: + // types + typedef Value key_type; + typedef key_type value_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + + explicit hash_set(size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template <class InputIterator> + hash_set(InputIterator f, InputIterator l, + size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + hash_set(const hash_set&); + ~hash_set(); + hash_set& operator=(const hash_set&); + + allocator_type get_allocator() const; + + bool empty() const; + size_type size() const; + size_type max_size() const; + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + pair<iterator, bool> insert(const value_type& obj); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + + void erase(const_iterator position); + size_type erase(const key_type& k); + void erase(const_iterator first, const_iterator last); + void clear(); + + void swap(hash_set&); + + hasher hash_funct() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair<iterator, iterator> equal_range(const key_type& k); + pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + + size_type bucket_count() const; + size_type max_bucket_count() const; + + size_type elems_in_bucket(size_type n) const; + + void resize(size_type n); +}; + +template <class Value, class Hash, class Pred, class Alloc> + void swap(hash_set<Value, Hash, Pred, Alloc>& x, + hash_set<Value, Hash, Pred, Alloc>& y); + +template <class Value, class Hash, class Pred, class Alloc> + bool + operator==(const hash_set<Value, Hash, Pred, Alloc>& x, + const hash_set<Value, Hash, Pred, Alloc>& y); + +template <class Value, class Hash, class Pred, class Alloc> + bool + operator!=(const hash_set<Value, Hash, Pred, Alloc>& x, + const hash_set<Value, Hash, Pred, Alloc>& y); + +template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, + class Alloc = allocator<Value>> +class hash_multiset +{ +public: + // types + typedef Value key_type; + typedef key_type value_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + + explicit hash_multiset(size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template <class InputIterator> + hash_multiset(InputIterator f, InputIterator l, + size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + hash_multiset(const hash_multiset&); + ~hash_multiset(); + hash_multiset& operator=(const hash_multiset&); + + allocator_type get_allocator() const; + + bool empty() const; + size_type size() const; + size_type max_size() const; + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + iterator insert(const value_type& obj); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + + void erase(const_iterator position); + size_type erase(const key_type& k); + void erase(const_iterator first, const_iterator last); + void clear(); + + void swap(hash_multiset&); + + hasher hash_funct() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair<iterator, iterator> equal_range(const key_type& k); + pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + + size_type bucket_count() const; + size_type max_bucket_count() const; + + size_type elems_in_bucket(size_type n) const; + + void resize(size_type n); +}; + +template <class Value, class Hash, class Pred, class Alloc> + void swap(hash_multiset<Value, Hash, Pred, Alloc>& x, + hash_multiset<Value, Hash, Pred, Alloc>& y); + +template <class Value, class Hash, class Pred, class Alloc> + bool + operator==(const hash_multiset<Value, Hash, Pred, Alloc>& x, + const hash_multiset<Value, Hash, Pred, Alloc>& y); + +template <class Value, class Hash, class Pred, class Alloc> + bool + operator!=(const hash_multiset<Value, Hash, Pred, Alloc>& x, + const hash_multiset<Value, Hash, Pred, Alloc>& y); +} // __gnu_cxx + +*/ + +#include <__config> +#include <__hash_table> +#include <functional> +#include <ext/__hash> + +#if __DEPRECATED +#if defined(_LIBCPP_WARNING) + _LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>") +#else +# warning Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set> +#endif +#endif + +namespace __gnu_cxx { + +using namespace std; + +template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, + class _Alloc = allocator<_Value> > +class _LIBCPP_TEMPLATE_VIS hash_set +{ +public: + // types + typedef _Value key_type; + typedef key_type value_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + +private: + typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; + + __table __table_; + +public: + typedef typename __table::pointer pointer; + typedef typename __table::const_pointer const_pointer; + typedef typename __table::size_type size_type; + typedef typename __table::difference_type difference_type; + + typedef typename __table::const_iterator iterator; + typedef typename __table::const_iterator const_iterator; + + _LIBCPP_INLINE_VISIBILITY + hash_set() {__table_.rehash(193);} + explicit hash_set(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + hash_set(size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); + template <class _InputIterator> + hash_set(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + hash_set(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template <class _InputIterator> + hash_set(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); + hash_set(const hash_set& __u); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert(const value_type& __x) + {return __table_.__insert_unique(__x);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __p) {__table_.erase(__p);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __first, const_iterator __last) + {__table_.erase(__first, __last);} + _LIBCPP_INLINE_VISIBILITY + void clear() {__table_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(hash_set& __u) {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_funct() const {return __table_.hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const {return __table_.key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<iterator, iterator> equal_range(const key_type& __k) + {return __table_.__equal_range_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + {return __table_.__equal_range_unique(__k);} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} + + _LIBCPP_INLINE_VISIBILITY + void resize(size_type __n) {__table_.rehash(__n);} +}; + +template <class _Value, class _Hash, class _Pred, class _Alloc> +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( + _InputIterator __first, _InputIterator __last) +{ + __table_.rehash(193); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( + const hash_set& __u) + : __table_(__u.__table_) +{ + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +inline +void +hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_unique(*__first); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x, + hash_set<_Value, _Hash, _Pred, _Alloc>& __y) +{ + __x.swap(__y); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +bool +operator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, + const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); + __i != __ex; ++__i) + { + const_iterator __j = __y.find(*__i); + if (__j == __ey || !(*__i == *__j)) + return false; + } + return true; +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, + const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, + class _Alloc = allocator<_Value> > +class _LIBCPP_TEMPLATE_VIS hash_multiset +{ +public: + // types + typedef _Value key_type; + typedef key_type value_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + +private: + typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; + + __table __table_; + +public: + typedef typename __table::pointer pointer; + typedef typename __table::const_pointer const_pointer; + typedef typename __table::size_type size_type; + typedef typename __table::difference_type difference_type; + + typedef typename __table::const_iterator iterator; + typedef typename __table::const_iterator const_iterator; + + _LIBCPP_INLINE_VISIBILITY + hash_multiset() {__table_.rehash(193);} + explicit hash_multiset(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + hash_multiset(size_type __n, const hasher& __hf, + const key_equal& __eql, const allocator_type& __a); + template <class _InputIterator> + hash_multiset(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + hash_multiset(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template <class _InputIterator> + hash_multiset(_InputIterator __first, _InputIterator __last, + size_type __n , const hasher& __hf, + const key_equal& __eql, const allocator_type& __a); + hash_multiset(const hash_multiset& __u); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator, const value_type& __x) {return insert(__x);} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __p) {__table_.erase(__p);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __first, const_iterator __last) + {__table_.erase(__first, __last);} + _LIBCPP_INLINE_VISIBILITY + void clear() {__table_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(hash_multiset& __u) {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_funct() const {return __table_.hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const {return __table_.key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<iterator, iterator> equal_range(const key_type& __k) + {return __table_.__equal_range_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + {return __table_.__equal_range_multi(__k);} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} + + _LIBCPP_INLINE_VISIBILITY + void resize(size_type __n) {__table_.rehash(__n);} +}; + +template <class _Value, class _Hash, class _Pred, class _Alloc> +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + size_type __n, const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + _InputIterator __first, _InputIterator __last) +{ + __table_.rehash(193); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + const hash_multiset& __u) + : __table_(__u.__table_) +{ + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +inline +void +hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_multi(*__first); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) +{ + __x.swap(__y); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +bool +operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + typedef pair<const_iterator, const_iterator> _EqRng; + for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) + { + _EqRng __xeq = __x.equal_range(*__i); + _EqRng __yeq = __y.equal_range(*__i); + if (_VSTD::distance(__xeq.first, __xeq.second) != + _VSTD::distance(__yeq.first, __yeq.second) || + !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) + return false; + __i = __xeq.second; + } + return true; +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +} // __gnu_cxx + +#endif // _LIBCPP_HASH_SET diff --git a/android/x86/include/v8/libc++/fenv.h b/android/x86/include/v8/libc++/fenv.h new file mode 100755 index 00000000..988cd9b1 --- /dev/null +++ b/android/x86/include/v8/libc++/fenv.h @@ -0,0 +1,116 @@ +// -*- C++ -*- +//===---------------------------- math.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FENV_H +#define _LIBCPP_FENV_H + + +/* + fenv.h synopsis + +This entire header is C99 / C++0X + +Macros: + + FE_DIVBYZERO + FE_INEXACT + FE_INVALID + FE_OVERFLOW + FE_UNDERFLOW + FE_ALL_EXCEPT + FE_DOWNWARD + FE_TONEAREST + FE_TOWARDZERO + FE_UPWARD + FE_DFL_ENV + +Types: + + fenv_t + fexcept_t + +int feclearexcept(int excepts); +int fegetexceptflag(fexcept_t* flagp, int excepts); +int feraiseexcept(int excepts); +int fesetexceptflag(const fexcept_t* flagp, int excepts); +int fetestexcept(int excepts); +int fegetround(); +int fesetround(int round); +int fegetenv(fenv_t* envp); +int feholdexcept(fenv_t* envp); +int fesetenv(const fenv_t* envp); +int feupdateenv(const fenv_t* envp); + + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <fenv.h> + +#ifdef __cplusplus + +extern "C++" { + +#ifdef feclearexcept +#undef feclearexcept +#endif + +#ifdef fegetexceptflag +#undef fegetexceptflag +#endif + + +#ifdef feraiseexcept +#undef feraiseexcept +#endif + +#ifdef fesetexceptflag +#undef fesetexceptflag +#endif + + +#ifdef fetestexcept +#undef fetestexcept +#endif + +#ifdef fegetround +#undef fegetround +#endif + +#ifdef fesetround +#undef fesetround +#endif + +#ifdef fegetenv +#undef fegetenv +#endif + +#ifdef feholdexcept +#undef feholdexcept +#endif + + +#ifdef fesetenv +#undef fesetenv +#endif + +#ifdef feupdateenv +#undef feupdateenv +#endif + +} // extern "C++" + +#endif // defined(__cplusplus) + +#endif // _LIBCPP_FENV_H diff --git a/android/x86/include/v8/libc++/filesystem b/android/x86/include/v8/libc++/filesystem new file mode 100755 index 00000000..3aaa7988 --- /dev/null +++ b/android/x86/include/v8/libc++/filesystem @@ -0,0 +1,2643 @@ +// -*- C++ -*- +//===--------------------------- filesystem -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_FILESYSTEM +#define _LIBCPP_FILESYSTEM +/* + filesystem synopsis + + namespace std { namespace filesystem { + + class path; + + void swap(path& lhs, path& rhs) noexcept; + size_t hash_value(const path& p) noexcept; + + bool operator==(const path& lhs, const path& rhs) noexcept; + bool operator!=(const path& lhs, const path& rhs) noexcept; + bool operator< (const path& lhs, const path& rhs) noexcept; + bool operator<=(const path& lhs, const path& rhs) noexcept; + bool operator> (const path& lhs, const path& rhs) noexcept; + bool operator>=(const path& lhs, const path& rhs) noexcept; + + path operator/ (const path& lhs, const path& rhs); + + // fs.path.io operators are friends of path. + template <class charT, class traits> + friend basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, const path& p); + + template <class charT, class traits> + friend basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, path& p); + + template <class Source> + path u8path(const Source& source); + template <class InputIterator> + path u8path(InputIterator first, InputIterator last); + + class filesystem_error; + class directory_entry; + + class directory_iterator; + + // enable directory_iterator range-based for statements + directory_iterator begin(directory_iterator iter) noexcept; + directory_iterator end(const directory_iterator&) noexcept; + + class recursive_directory_iterator; + + // enable recursive_directory_iterator range-based for statements + recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept; + recursive_directory_iterator end(const recursive_directory_iterator&) noexcept; + + class file_status; + + struct space_info + { + uintmax_t capacity; + uintmax_t free; + uintmax_t available; + }; + + enum class file_type; + enum class perms; + enum class perm_options; + enum class copy_options; + enum class directory_options; + + typedef chrono::time_point<trivial-clock> file_time_type; + + // operational functions + + path absolute(const path& p); + path absolute(const path& p, error_code &ec); + + path canonical(const path& p); + path canonical(const path& p, error_code& ec); + + void copy(const path& from, const path& to); + void copy(const path& from, const path& to, error_code& ec); + void copy(const path& from, const path& to, copy_options options); + void copy(const path& from, const path& to, copy_options options, + error_code& ec); + + bool copy_file(const path& from, const path& to); + bool copy_file(const path& from, const path& to, error_code& ec); + bool copy_file(const path& from, const path& to, copy_options option); + bool copy_file(const path& from, const path& to, copy_options option, + error_code& ec); + + void copy_symlink(const path& existing_symlink, const path& new_symlink); + void copy_symlink(const path& existing_symlink, const path& new_symlink, + error_code& ec) noexcept; + + bool create_directories(const path& p); + bool create_directories(const path& p, error_code& ec); + + bool create_directory(const path& p); + bool create_directory(const path& p, error_code& ec) noexcept; + + bool create_directory(const path& p, const path& attributes); + bool create_directory(const path& p, const path& attributes, + error_code& ec) noexcept; + + void create_directory_symlink(const path& to, const path& new_symlink); + void create_directory_symlink(const path& to, const path& new_symlink, + error_code& ec) noexcept; + + void create_hard_link(const path& to, const path& new_hard_link); + void create_hard_link(const path& to, const path& new_hard_link, + error_code& ec) noexcept; + + void create_symlink(const path& to, const path& new_symlink); + void create_symlink(const path& to, const path& new_symlink, + error_code& ec) noexcept; + + path current_path(); + path current_path(error_code& ec); + void current_path(const path& p); + void current_path(const path& p, error_code& ec) noexcept; + + bool exists(file_status s) noexcept; + bool exists(const path& p); + bool exists(const path& p, error_code& ec) noexcept; + + bool equivalent(const path& p1, const path& p2); + bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept; + + uintmax_t file_size(const path& p); + uintmax_t file_size(const path& p, error_code& ec) noexcept; + + uintmax_t hard_link_count(const path& p); + uintmax_t hard_link_count(const path& p, error_code& ec) noexcept; + + bool is_block_file(file_status s) noexcept; + bool is_block_file(const path& p); + bool is_block_file(const path& p, error_code& ec) noexcept; + + bool is_character_file(file_status s) noexcept; + bool is_character_file(const path& p); + bool is_character_file(const path& p, error_code& ec) noexcept; + + bool is_directory(file_status s) noexcept; + bool is_directory(const path& p); + bool is_directory(const path& p, error_code& ec) noexcept; + + bool is_empty(const path& p); + bool is_empty(const path& p, error_code& ec) noexcept; + + bool is_fifo(file_status s) noexcept; + bool is_fifo(const path& p); + bool is_fifo(const path& p, error_code& ec) noexcept; + + bool is_other(file_status s) noexcept; + bool is_other(const path& p); + bool is_other(const path& p, error_code& ec) noexcept; + + bool is_regular_file(file_status s) noexcept; + bool is_regular_file(const path& p); + bool is_regular_file(const path& p, error_code& ec) noexcept; + + bool is_socket(file_status s) noexcept; + bool is_socket(const path& p); + bool is_socket(const path& p, error_code& ec) noexcept; + + bool is_symlink(file_status s) noexcept; + bool is_symlink(const path& p); + bool is_symlink(const path& p, error_code& ec) noexcept; + + file_time_type last_write_time(const path& p); + file_time_type last_write_time(const path& p, error_code& ec) noexcept; + void last_write_time(const path& p, file_time_type new_time); + void last_write_time(const path& p, file_time_type new_time, + error_code& ec) noexcept; + + void permissions(const path& p, perms prms, + perm_options opts=perm_options::replace); + void permissions(const path& p, perms prms, error_code& ec) noexcept; + void permissions(const path& p, perms prms, perm_options opts, + error_code& ec); + + path proximate(const path& p, error_code& ec); + path proximate(const path& p, const path& base = current_path()); + path proximate(const path& p, const path& base, error_code &ec); + + path read_symlink(const path& p); + path read_symlink(const path& p, error_code& ec); + + path relative(const path& p, error_code& ec); + path relative(const path& p, const path& base=current_path()); + path relative(const path& p, const path& base, error_code& ec); + + bool remove(const path& p); + bool remove(const path& p, error_code& ec) noexcept; + + uintmax_t remove_all(const path& p); + uintmax_t remove_all(const path& p, error_code& ec); + + void rename(const path& from, const path& to); + void rename(const path& from, const path& to, error_code& ec) noexcept; + + void resize_file(const path& p, uintmax_t size); + void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept; + + space_info space(const path& p); + space_info space(const path& p, error_code& ec) noexcept; + + file_status status(const path& p); + file_status status(const path& p, error_code& ec) noexcept; + + bool status_known(file_status s) noexcept; + + file_status symlink_status(const path& p); + file_status symlink_status(const path& p, error_code& ec) noexcept; + + path temp_directory_path(); + path temp_directory_path(error_code& ec); + + path weakly_canonical(path const& p); + path weakly_canonical(path const& p, error_code& ec); + + +} } // namespaces std::filesystem + +*/ + +#include <__config> +#include <cstddef> +#include <cstdlib> +#include <chrono> +#include <iterator> +#include <iosfwd> +#include <locale> +#include <memory> +#include <stack> +#include <string> +#include <system_error> +#include <utility> +#include <iomanip> // for quoted +#include <string_view> +#include <version> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +typedef chrono::time_point<_FilesystemClock> file_time_type; + +struct _LIBCPP_TYPE_VIS space_info { + uintmax_t capacity; + uintmax_t free; + uintmax_t available; +}; + +enum class _LIBCPP_ENUM_VIS file_type : signed char { + none = 0, + not_found = -1, + regular = 1, + directory = 2, + symlink = 3, + block = 4, + character = 5, + fifo = 6, + socket = 7, + unknown = 8 +}; + +enum class _LIBCPP_ENUM_VIS perms : unsigned { + none = 0, + + owner_read = 0400, + owner_write = 0200, + owner_exec = 0100, + owner_all = 0700, + + group_read = 040, + group_write = 020, + group_exec = 010, + group_all = 070, + + others_read = 04, + others_write = 02, + others_exec = 01, + others_all = 07, + + all = 0777, + + set_uid = 04000, + set_gid = 02000, + sticky_bit = 01000, + mask = 07777, + unknown = 0xFFFF, +}; + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perms operator&(perms _LHS, perms _RHS) { + return static_cast<perms>(static_cast<unsigned>(_LHS) & + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perms operator|(perms _LHS, perms _RHS) { + return static_cast<perms>(static_cast<unsigned>(_LHS) | + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perms operator^(perms _LHS, perms _RHS) { + return static_cast<perms>(static_cast<unsigned>(_LHS) ^ + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perms operator~(perms _LHS) { + return static_cast<perms>(~static_cast<unsigned>(_LHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; } + +_LIBCPP_INLINE_VISIBILITY +inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; } + +_LIBCPP_INLINE_VISIBILITY +inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; } + +enum class _LIBCPP_ENUM_VIS perm_options : unsigned char { + replace = 1, + add = 2, + remove = 4, + nofollow = 8 +}; + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS) { + return static_cast<perm_options>(static_cast<unsigned>(_LHS) & + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS) { + return static_cast<perm_options>(static_cast<unsigned>(_LHS) | + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS) { + return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^ + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perm_options operator~(perm_options _LHS) { + return static_cast<perm_options>(~static_cast<unsigned>(_LHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) { + return _LHS = _LHS & _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) { + return _LHS = _LHS | _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) { + return _LHS = _LHS ^ _RHS; +} + +enum class _LIBCPP_ENUM_VIS copy_options : unsigned short { + none = 0, + skip_existing = 1, + overwrite_existing = 2, + update_existing = 4, + recursive = 8, + copy_symlinks = 16, + skip_symlinks = 32, + directories_only = 64, + create_symlinks = 128, + create_hard_links = 256, + __in_recursive_copy = 512, +}; + +_LIBCPP_INLINE_VISIBILITY +inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS) { + return static_cast<copy_options>(static_cast<unsigned short>(_LHS) & + static_cast<unsigned short>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS) { + return static_cast<copy_options>(static_cast<unsigned short>(_LHS) | + static_cast<unsigned short>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS) { + return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^ + static_cast<unsigned short>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr copy_options operator~(copy_options _LHS) { + return static_cast<copy_options>(~static_cast<unsigned short>(_LHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) { + return _LHS = _LHS & _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) { + return _LHS = _LHS | _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) { + return _LHS = _LHS ^ _RHS; +} + +enum class _LIBCPP_ENUM_VIS directory_options : unsigned char { + none = 0, + follow_directory_symlink = 1, + skip_permission_denied = 2 +}; + +_LIBCPP_INLINE_VISIBILITY +inline constexpr directory_options operator&(directory_options _LHS, + directory_options _RHS) { + return static_cast<directory_options>(static_cast<unsigned char>(_LHS) & + static_cast<unsigned char>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr directory_options operator|(directory_options _LHS, + directory_options _RHS) { + return static_cast<directory_options>(static_cast<unsigned char>(_LHS) | + static_cast<unsigned char>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr directory_options operator^(directory_options _LHS, + directory_options _RHS) { + return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^ + static_cast<unsigned char>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr directory_options operator~(directory_options _LHS) { + return static_cast<directory_options>(~static_cast<unsigned char>(_LHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline directory_options& operator&=(directory_options& _LHS, + directory_options _RHS) { + return _LHS = _LHS & _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline directory_options& operator|=(directory_options& _LHS, + directory_options _RHS) { + return _LHS = _LHS | _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline directory_options& operator^=(directory_options& _LHS, + directory_options _RHS) { + return _LHS = _LHS ^ _RHS; +} + +class _LIBCPP_TYPE_VIS file_status { +public: + // constructors + _LIBCPP_INLINE_VISIBILITY + file_status() noexcept : file_status(file_type::none) {} + _LIBCPP_INLINE_VISIBILITY + explicit file_status(file_type __ft, perms __prms = perms::unknown) noexcept + : __ft_(__ft), + __prms_(__prms) {} + + file_status(const file_status&) noexcept = default; + file_status(file_status&&) noexcept = default; + + _LIBCPP_INLINE_VISIBILITY + ~file_status() {} + + file_status& operator=(const file_status&) noexcept = default; + file_status& operator=(file_status&&) noexcept = default; + + // observers + _LIBCPP_INLINE_VISIBILITY + file_type type() const noexcept { return __ft_; } + + _LIBCPP_INLINE_VISIBILITY + perms permissions() const noexcept { return __prms_; } + + // modifiers + _LIBCPP_INLINE_VISIBILITY + void type(file_type __ft) noexcept { __ft_ = __ft; } + + _LIBCPP_INLINE_VISIBILITY + void permissions(perms __p) noexcept { __prms_ = __p; } + +private: + file_type __ft_; + perms __prms_; +}; + +class _LIBCPP_TYPE_VIS directory_entry; + +template <class _Tp> +struct __can_convert_char { + static const bool value = false; +}; +template <class _Tp> +struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {}; +template <> +struct __can_convert_char<char> { + static const bool value = true; + using __char_type = char; +}; +template <> +struct __can_convert_char<wchar_t> { + static const bool value = true; + using __char_type = wchar_t; +}; +template <> +struct __can_convert_char<char16_t> { + static const bool value = true; + using __char_type = char16_t; +}; +template <> +struct __can_convert_char<char32_t> { + static const bool value = true; + using __char_type = char32_t; +}; + +template <class _ECharT> +typename enable_if<__can_convert_char<_ECharT>::value, bool>::type +__is_separator(_ECharT __e) { + return __e == _ECharT('/'); +} + +struct _NullSentinal {}; + +template <class _Tp> +using _Void = void; + +template <class _Tp, class = void> +struct __is_pathable_string : public false_type {}; + +template <class _ECharT, class _Traits, class _Alloc> +struct __is_pathable_string< + basic_string<_ECharT, _Traits, _Alloc>, + _Void<typename __can_convert_char<_ECharT>::__char_type> > + : public __can_convert_char<_ECharT> { + using _Str = basic_string<_ECharT, _Traits, _Alloc>; + using _Base = __can_convert_char<_ECharT>; + static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } + static _ECharT const* __range_end(_Str const& __s) { + return __s.data() + __s.length(); + } + static _ECharT __first_or_null(_Str const& __s) { + return __s.empty() ? _ECharT{} : __s[0]; + } +}; + +template <class _ECharT, class _Traits> +struct __is_pathable_string< + basic_string_view<_ECharT, _Traits>, + _Void<typename __can_convert_char<_ECharT>::__char_type> > + : public __can_convert_char<_ECharT> { + using _Str = basic_string_view<_ECharT, _Traits>; + using _Base = __can_convert_char<_ECharT>; + static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } + static _ECharT const* __range_end(_Str const& __s) { + return __s.data() + __s.length(); + } + static _ECharT __first_or_null(_Str const& __s) { + return __s.empty() ? _ECharT{} : __s[0]; + } +}; + +template <class _Source, class _DS = typename decay<_Source>::type, + class _UnqualPtrType = + typename remove_const<typename remove_pointer<_DS>::type>::type, + bool _IsCharPtr = is_pointer<_DS>::value&& + __can_convert_char<_UnqualPtrType>::value> +struct __is_pathable_char_array : false_type {}; + +template <class _Source, class _ECharT, class _UPtr> +struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true> + : __can_convert_char<typename remove_const<_ECharT>::type> { + using _Base = __can_convert_char<typename remove_const<_ECharT>::type>; + + static _ECharT const* __range_begin(const _ECharT* __b) { return __b; } + static _ECharT const* __range_end(const _ECharT* __b) { + using _Iter = const _ECharT*; + const _ECharT __sentinal = _ECharT{}; + _Iter __e = __b; + for (; *__e != __sentinal; ++__e) + ; + return __e; + } + + static _ECharT __first_or_null(const _ECharT* __b) { return *__b; } +}; + +template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value, + class = void> +struct __is_pathable_iter : false_type {}; + +template <class _Iter> +struct __is_pathable_iter< + _Iter, true, + _Void<typename __can_convert_char< + typename iterator_traits<_Iter>::value_type>::__char_type> > + : __can_convert_char<typename iterator_traits<_Iter>::value_type> { + using _ECharT = typename iterator_traits<_Iter>::value_type; + using _Base = __can_convert_char<_ECharT>; + + static _Iter __range_begin(_Iter __b) { return __b; } + static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; } + + static _ECharT __first_or_null(_Iter __b) { return *__b; } +}; + +template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value, + bool _IsCharIterT = __is_pathable_char_array<_Tp>::value, + bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value> +struct __is_pathable : false_type { + static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false"); +}; + +template <class _Tp> +struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {}; + +template <class _Tp> +struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> { +}; + +template <class _Tp> +struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {}; + +template <class _ECharT> +struct _PathCVT { + static_assert(__can_convert_char<_ECharT>::value, + "Char type not convertible"); + + typedef __narrow_to_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Narrower; + + static void __append_range(string& __dest, _ECharT const* __b, + _ECharT const* __e) { + _Narrower()(back_inserter(__dest), __b, __e); + } + + template <class _Iter> + static void __append_range(string& __dest, _Iter __b, _Iter __e) { + static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload"); + if (__b == __e) + return; + basic_string<_ECharT> __tmp(__b, __e); + _Narrower()(back_inserter(__dest), __tmp.data(), + __tmp.data() + __tmp.length()); + } + + template <class _Iter> + static void __append_range(string& __dest, _Iter __b, _NullSentinal) { + static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload"); + const _ECharT __sentinal = _ECharT{}; + if (*__b == __sentinal) + return; + basic_string<_ECharT> __tmp; + for (; *__b != __sentinal; ++__b) + __tmp.push_back(*__b); + _Narrower()(back_inserter(__dest), __tmp.data(), + __tmp.data() + __tmp.length()); + } + + template <class _Source> + static void __append_source(string& __dest, _Source const& __s) { + using _Traits = __is_pathable<_Source>; + __append_range(__dest, _Traits::__range_begin(__s), + _Traits::__range_end(__s)); + } +}; + +template <> +struct _PathCVT<char> { + + template <class _Iter> + static typename enable_if<__is_exactly_input_iterator<_Iter>::value>::type + __append_range(string& __dest, _Iter __b, _Iter __e) { + for (; __b != __e; ++__b) + __dest.push_back(*__b); + } + + template <class _Iter> + static typename enable_if<__is_forward_iterator<_Iter>::value>::type + __append_range(string& __dest, _Iter __b, _Iter __e) { + __dest.__append_forward_unsafe(__b, __e); + } + + template <class _Iter> + static void __append_range(string& __dest, _Iter __b, _NullSentinal) { + const char __sentinal = char{}; + for (; *__b != __sentinal; ++__b) + __dest.push_back(*__b); + } + + template <class _Source> + static void __append_source(string& __dest, _Source const& __s) { + using _Traits = __is_pathable<_Source>; + __append_range(__dest, _Traits::__range_begin(__s), + _Traits::__range_end(__s)); + } +}; + +class _LIBCPP_TYPE_VIS path { + template <class _SourceOrIter, class _Tp = path&> + using _EnableIfPathable = + typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type; + + template <class _Tp> + using _SourceChar = typename __is_pathable<_Tp>::__char_type; + + template <class _Tp> + using _SourceCVT = _PathCVT<_SourceChar<_Tp> >; + +public: + typedef char value_type; + typedef basic_string<value_type> string_type; + typedef _VSTD::string_view __string_view; + static constexpr value_type preferred_separator = '/'; + + enum class _LIBCPP_ENUM_VIS format : unsigned char { + auto_format, + native_format, + generic_format + }; + + // constructors and destructor + _LIBCPP_INLINE_VISIBILITY path() noexcept {} + _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {} + _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept + : __pn_(_VSTD::move(__p.__pn_)) {} + + _LIBCPP_INLINE_VISIBILITY + path(string_type&& __s, format = format::auto_format) noexcept + : __pn_(_VSTD::move(__s)) {} + + template <class _Source, class = _EnableIfPathable<_Source, void> > + path(const _Source& __src, format = format::auto_format) { + _SourceCVT<_Source>::__append_source(__pn_, __src); + } + + template <class _InputIt> + path(_InputIt __first, _InputIt __last, format = format::auto_format) { + typedef typename iterator_traits<_InputIt>::value_type _ItVal; + _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); + } + + // TODO Implement locale conversions. + template <class _Source, class = _EnableIfPathable<_Source, void> > + path(const _Source& __src, const locale& __loc, format = format::auto_format); + template <class _InputIt> + path(_InputIt __first, _InputIt _last, const locale& __loc, + format = format::auto_format); + + _LIBCPP_INLINE_VISIBILITY + ~path() = default; + + // assignments + _LIBCPP_INLINE_VISIBILITY + path& operator=(const path& __p) { + __pn_ = __p.__pn_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator=(path&& __p) noexcept { + __pn_ = _VSTD::move(__p.__pn_); + return *this; + } + + template <class = void> + _LIBCPP_INLINE_VISIBILITY path& operator=(string_type&& __s) noexcept { + __pn_ = _VSTD::move(__s); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& assign(string_type&& __s) noexcept { + __pn_ = _VSTD::move(__s); + return *this; + } + + template <class _Source> + _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source> + operator=(const _Source& __src) { + return this->assign(__src); + } + + template <class _Source> + _EnableIfPathable<_Source> assign(const _Source& __src) { + __pn_.clear(); + _SourceCVT<_Source>::__append_source(__pn_, __src); + return *this; + } + + template <class _InputIt> + path& assign(_InputIt __first, _InputIt __last) { + typedef typename iterator_traits<_InputIt>::value_type _ItVal; + __pn_.clear(); + _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); + return *this; + } + +private: + template <class _ECharT> + static bool __source_is_absolute(_ECharT __first_or_null) { + return __is_separator(__first_or_null); + } + +public: + // appends + path& operator/=(const path& __p) { + if (__p.is_absolute()) { + __pn_ = __p.__pn_; + return *this; + } + if (has_filename()) + __pn_ += preferred_separator; + __pn_ += __p.native(); + return *this; + } + + // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src + // is known at compile time to be "/' since the user almost certainly intended + // to append a separator instead of overwriting the path with "/" + template <class _Source> + _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source> + operator/=(const _Source& __src) { + return this->append(__src); + } + + template <class _Source> + _EnableIfPathable<_Source> append(const _Source& __src) { + using _Traits = __is_pathable<_Source>; + using _CVT = _PathCVT<_SourceChar<_Source> >; + if (__source_is_absolute(_Traits::__first_or_null(__src))) + __pn_.clear(); + else if (has_filename()) + __pn_ += preferred_separator; + _CVT::__append_source(__pn_, __src); + return *this; + } + + template <class _InputIt> + path& append(_InputIt __first, _InputIt __last) { + typedef typename iterator_traits<_InputIt>::value_type _ItVal; + static_assert(__can_convert_char<_ItVal>::value, "Must convertible"); + using _CVT = _PathCVT<_ItVal>; + if (__first != __last && __source_is_absolute(*__first)) + __pn_.clear(); + else if (has_filename()) + __pn_ += preferred_separator; + _CVT::__append_range(__pn_, __first, __last); + return *this; + } + + // concatenation + _LIBCPP_INLINE_VISIBILITY + path& operator+=(const path& __x) { + __pn_ += __x.__pn_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator+=(const string_type& __x) { + __pn_ += __x; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator+=(__string_view __x) { + __pn_ += __x; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator+=(const value_type* __x) { + __pn_ += __x; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator+=(value_type __x) { + __pn_ += __x; + return *this; + } + + template <class _ECharT> + typename enable_if<__can_convert_char<_ECharT>::value, path&>::type + operator+=(_ECharT __x) { + basic_string<_ECharT> __tmp; + __tmp += __x; + _PathCVT<_ECharT>::__append_source(__pn_, __tmp); + return *this; + } + + template <class _Source> + _EnableIfPathable<_Source> operator+=(const _Source& __x) { + return this->concat(__x); + } + + template <class _Source> + _EnableIfPathable<_Source> concat(const _Source& __x) { + _SourceCVT<_Source>::__append_source(__pn_, __x); + return *this; + } + + template <class _InputIt> + path& concat(_InputIt __first, _InputIt __last) { + typedef typename iterator_traits<_InputIt>::value_type _ItVal; + _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); + return *this; + } + + // modifiers + _LIBCPP_INLINE_VISIBILITY + void clear() noexcept { __pn_.clear(); } + + path& make_preferred() { return *this; } + + _LIBCPP_INLINE_VISIBILITY + path& remove_filename() { + auto __fname = __filename(); + if (!__fname.empty()) + __pn_.erase(__fname.data() - __pn_.data()); + return *this; + } + + path& replace_filename(const path& __replacement) { + remove_filename(); + return (*this /= __replacement); + } + + path& replace_extension(const path& __replacement = path()); + + _LIBCPP_INLINE_VISIBILITY + void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); } + + // private helper to allow reserving memory in the path + _LIBCPP_INLINE_VISIBILITY + void __reserve(size_t __s) { __pn_.reserve(__s); } + + // native format observers + _LIBCPP_INLINE_VISIBILITY + const string_type& native() const noexcept { return __pn_; } + + _LIBCPP_INLINE_VISIBILITY + const value_type* c_str() const noexcept { return __pn_.c_str(); } + + _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; } + + template <class _ECharT, class _Traits = char_traits<_ECharT>, + class _Allocator = allocator<_ECharT> > + basic_string<_ECharT, _Traits, _Allocator> + string(const _Allocator& __a = _Allocator()) const { + using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>; + using _Str = basic_string<_ECharT, _Traits, _Allocator>; + _Str __s(__a); + __s.reserve(__pn_.size()); + _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size()); + return __s; + } + + _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; } + _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { + return string<wchar_t>(); + } + _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; } + _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { + return string<char16_t>(); + } + _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { + return string<char32_t>(); + } + + // generic format observers + template <class _ECharT, class _Traits = char_traits<_ECharT>, + class _Allocator = allocator<_ECharT> > + basic_string<_ECharT, _Traits, _Allocator> + generic_string(const _Allocator& __a = _Allocator()) const { + return string<_ECharT, _Traits, _Allocator>(__a); + } + + std::string generic_string() const { return __pn_; } + std::wstring generic_wstring() const { return string<wchar_t>(); } + std::string generic_u8string() const { return __pn_; } + std::u16string generic_u16string() const { return string<char16_t>(); } + std::u32string generic_u32string() const { return string<char32_t>(); } + +private: + int __compare(__string_view) const; + __string_view __root_name() const; + __string_view __root_directory() const; + __string_view __root_path_raw() const; + __string_view __relative_path() const; + __string_view __parent_path() const; + __string_view __filename() const; + __string_view __stem() const; + __string_view __extension() const; + +public: + // compare + _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept { + return __compare(__p.__pn_); + } + _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { + return __compare(__s); + } + _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { + return __compare(__s); + } + _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { + return __compare(__s); + } + + // decomposition + _LIBCPP_INLINE_VISIBILITY path root_name() const { + return string_type(__root_name()); + } + _LIBCPP_INLINE_VISIBILITY path root_directory() const { + return string_type(__root_directory()); + } + _LIBCPP_INLINE_VISIBILITY path root_path() const { + return root_name().append(string_type(__root_directory())); + } + _LIBCPP_INLINE_VISIBILITY path relative_path() const { + return string_type(__relative_path()); + } + _LIBCPP_INLINE_VISIBILITY path parent_path() const { + return string_type(__parent_path()); + } + _LIBCPP_INLINE_VISIBILITY path filename() const { + return string_type(__filename()); + } + _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); } + _LIBCPP_INLINE_VISIBILITY path extension() const { + return string_type(__extension()); + } + + // query + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool + empty() const noexcept { + return __pn_.empty(); + } + + _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { + return !__root_name().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { + return !__root_directory().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { + return !__root_path_raw().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { + return !__relative_path().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { + return !__parent_path().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_filename() const { + return !__filename().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); } + _LIBCPP_INLINE_VISIBILITY bool has_extension() const { + return !__extension().empty(); + } + + _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { + return has_root_directory(); + } + _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); } + + // relative paths + path lexically_normal() const; + path lexically_relative(const path& __base) const; + + _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const { + path __result = this->lexically_relative(__base); + if (__result.native().empty()) + return *this; + return __result; + } + + // iterators + class _LIBCPP_TYPE_VIS iterator; + typedef iterator const_iterator; + + iterator begin() const; + iterator end() const; + + template <class _CharT, class _Traits> + _LIBCPP_INLINE_VISIBILITY friend + typename enable_if<is_same<_CharT, char>::value && + is_same<_Traits, char_traits<char> >::value, + basic_ostream<_CharT, _Traits>&>::type + operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { + __os << std::__quoted(__p.native()); + return __os; + } + + template <class _CharT, class _Traits> + _LIBCPP_INLINE_VISIBILITY friend + typename enable_if<!is_same<_CharT, char>::value || + !is_same<_Traits, char_traits<char> >::value, + basic_ostream<_CharT, _Traits>&>::type + operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { + __os << std::__quoted(__p.string<_CharT, _Traits>()); + return __os; + } + + template <class _CharT, class _Traits> + _LIBCPP_INLINE_VISIBILITY friend basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) { + basic_string<_CharT, _Traits> __tmp; + __is >> __quoted(__tmp); + __p = __tmp; + return __is; + } + + friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept { + return __lhs.compare(__rhs) == 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept { + return __lhs.compare(__rhs) != 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept { + return __lhs.compare(__rhs) < 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept { + return __lhs.compare(__rhs) <= 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept { + return __lhs.compare(__rhs) > 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept { + return __lhs.compare(__rhs) >= 0; + } + + friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs, + const path& __rhs) { + path __result(__lhs); + __result /= __rhs; + return __result; + } +private: + inline _LIBCPP_INLINE_VISIBILITY path& + __assign_view(__string_view const& __s) noexcept { + __pn_ = string_type(__s); + return *this; + } + string_type __pn_; +}; + +inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept { + __lhs.swap(__rhs); +} + +_LIBCPP_FUNC_VIS +size_t hash_value(const path& __p) noexcept; + +template <class _Source> +_LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_pathable<_Source>::value, path>::type + u8path(const _Source& __s) { + static_assert( + is_same<typename __is_pathable<_Source>::__char_type, char>::value, + "u8path(Source const&) requires Source have a character type of type " + "'char'"); + return path(__s); +} + +template <class _InputIt> +_LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_pathable<_InputIt>::value, path>::type + u8path(_InputIt __f, _InputIt __l) { + static_assert( + is_same<typename __is_pathable<_InputIt>::__char_type, char>::value, + "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"); + return path(__f, __l); +} + +class _LIBCPP_TYPE_VIS path::iterator { +public: + enum _ParserState : unsigned char { + _Singular, + _BeforeBegin, + _InRootName, + _InRootDir, + _InFilenames, + _InTrailingSep, + _AtEnd + }; + +public: + typedef bidirectional_iterator_tag iterator_category; + + typedef path value_type; + typedef std::ptrdiff_t difference_type; + typedef const path* pointer; + typedef const path& reference; + + typedef void + __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator + +public: + _LIBCPP_INLINE_VISIBILITY + iterator() + : __stashed_elem_(), __path_ptr_(nullptr), __entry_(), + __state_(_Singular) {} + + iterator(const iterator&) = default; + ~iterator() = default; + + iterator& operator=(const iterator&) = default; + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const { return __stashed_elem_; } + + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const { return &__stashed_elem_; } + + _LIBCPP_INLINE_VISIBILITY + iterator& operator++() { + _LIBCPP_ASSERT(__state_ != _Singular, + "attempting to increment a singular iterator"); + _LIBCPP_ASSERT(__state_ != _AtEnd, + "attempting to increment the end iterator"); + return __increment(); + } + + _LIBCPP_INLINE_VISIBILITY + iterator operator++(int) { + iterator __it(*this); + this->operator++(); + return __it; + } + + _LIBCPP_INLINE_VISIBILITY + iterator& operator--() { + _LIBCPP_ASSERT(__state_ != _Singular, + "attempting to decrement a singular iterator"); + _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(), + "attempting to decrement the begin iterator"); + return __decrement(); + } + + _LIBCPP_INLINE_VISIBILITY + iterator operator--(int) { + iterator __it(*this); + this->operator--(); + return __it; + } + +private: + friend class path; + + inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&, + const iterator&); + + iterator& __increment(); + iterator& __decrement(); + + path __stashed_elem_; + const path* __path_ptr_; + path::__string_view __entry_; + _ParserState __state_; +}; + +inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs, + const path::iterator& __rhs) { + return __lhs.__path_ptr_ == __rhs.__path_ptr_ && + __lhs.__entry_.data() == __rhs.__entry_.data(); +} + +inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs, + const path::iterator& __rhs) { + return !(__lhs == __rhs); +} + +// TODO(ldionne): We need to pop the pragma and push it again after +// filesystem_error to work around PR41078. +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error { +public: + _LIBCPP_INLINE_VISIBILITY + filesystem_error(const string& __what, error_code __ec) + : system_error(__ec, __what), + __storage_(make_shared<_Storage>(path(), path())) { + __create_what(0); + } + + _LIBCPP_INLINE_VISIBILITY + filesystem_error(const string& __what, const path& __p1, error_code __ec) + : system_error(__ec, __what), + __storage_(make_shared<_Storage>(__p1, path())) { + __create_what(1); + } + + _LIBCPP_INLINE_VISIBILITY + filesystem_error(const string& __what, const path& __p1, const path& __p2, + error_code __ec) + : system_error(__ec, __what), + __storage_(make_shared<_Storage>(__p1, __p2)) { + __create_what(2); + } + + _LIBCPP_INLINE_VISIBILITY + const path& path1() const noexcept { return __storage_->__p1_; } + + _LIBCPP_INLINE_VISIBILITY + const path& path2() const noexcept { return __storage_->__p2_; } + + ~filesystem_error() override; // key function + + _LIBCPP_INLINE_VISIBILITY + const char* what() const noexcept override { + return __storage_->__what_.c_str(); + } + + void __create_what(int __num_paths); + +private: + struct _LIBCPP_HIDDEN _Storage { + _LIBCPP_INLINE_VISIBILITY + _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {} + + path __p1_; + path __p2_; + string __what_; + }; + shared_ptr<_Storage> __storage_; +}; + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +template <class... _Args> +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_NO_EXCEPTIONS +void __throw_filesystem_error(_Args&&... __args) { + throw filesystem_error(std::forward<_Args>(__args)...); +} +#else +void __throw_filesystem_error(_Args&&...) { + _VSTD::abort(); +} +#endif + +// operational functions + +_LIBCPP_FUNC_VIS +path __absolute(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +path __canonical(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +void __copy(const path& __from, const path& __to, copy_options __opt, + error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +bool __copy_file(const path& __from, const path& __to, copy_options __opt, + error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +void __copy_symlink(const path& __existing_symlink, const path& __new_symlink, + error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +bool __create_directories(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +bool __create_directory(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +bool __create_directory(const path& p, const path& attributes, + error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +void __create_directory_symlink(const path& __to, const path& __new_symlink, + error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +void __create_hard_link(const path& __to, const path& __new_hard_link, + error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +void __create_symlink(const path& __to, const path& __new_symlink, + error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +path __current_path(error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +void __current_path(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +bool __equivalent(const path&, const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +uintmax_t __file_size(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +bool __fs_is_empty(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +file_time_type __last_write_time(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +void __last_write_time(const path& p, file_time_type new_time, + error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +void __permissions(const path&, perms, perm_options, error_code* = nullptr); +_LIBCPP_FUNC_VIS +path __read_symlink(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +bool __remove(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +uintmax_t __remove_all(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +void __rename(const path& from, const path& to, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +void __resize_file(const path& p, uintmax_t size, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS +space_info __space(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +file_status __status(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +file_status __symlink_status(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +path __system_complete(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +path __temp_directory_path(error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS +path __weakly_canonical(path const& __p, error_code* __ec = nullptr); + +inline _LIBCPP_INLINE_VISIBILITY path current_path() { + return __current_path(); +} + +inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) { + return __current_path(&__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) { + __current_path(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p, + error_code& __ec) noexcept { + __current_path(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p) { + return __absolute(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p, + error_code& __ec) { + return __absolute(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p) { + return __canonical(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p, + error_code& __ec) { + return __canonical(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, + const path& __to) { + __copy(__from, __to, copy_options::none); +} + +inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, + error_code& __ec) { + __copy(__from, __to, copy_options::none, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, + copy_options __opt) { + __copy(__from, __to, __opt); +} + +inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, + copy_options __opt, + error_code& __ec) { + __copy(__from, __to, __opt, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, + const path& __to) { + return __copy_file(__from, __to, copy_options::none); +} + +inline _LIBCPP_INLINE_VISIBILITY bool +copy_file(const path& __from, const path& __to, error_code& __ec) { + return __copy_file(__from, __to, copy_options::none, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY bool +copy_file(const path& __from, const path& __to, copy_options __opt) { + return __copy_file(__from, __to, __opt); +} + +inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, + const path& __to, + copy_options __opt, + error_code& __ec) { + return __copy_file(__from, __to, __opt, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __existing, + const path& __new) { + __copy_symlink(__existing, __new); +} + +inline _LIBCPP_INLINE_VISIBILITY void +copy_symlink(const path& __ext, const path& __new, error_code& __ec) noexcept { + __copy_symlink(__ext, __new, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) { + return __create_directories(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p, + error_code& __ec) { + return __create_directories(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) { + return __create_directory(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY bool +create_directory(const path& __p, error_code& __ec) noexcept { + return __create_directory(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, + const path& __attrs) { + return __create_directory(__p, __attrs); +} + +inline _LIBCPP_INLINE_VISIBILITY bool +create_directory(const path& __p, const path& __attrs, + error_code& __ec) noexcept { + return __create_directory(__p, __attrs, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void +create_directory_symlink(const path& __to, const path& __new) { + __create_directory_symlink(__to, __new); +} + +inline _LIBCPP_INLINE_VISIBILITY void +create_directory_symlink(const path& __to, const path& __new, + error_code& __ec) noexcept { + __create_directory_symlink(__to, __new, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __to, + const path& __new) { + __create_hard_link(__to, __new); +} + +inline _LIBCPP_INLINE_VISIBILITY void +create_hard_link(const path& __to, const path& __new, + error_code& __ec) noexcept { + __create_hard_link(__to, __new, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __to, + const path& __new) { + __create_symlink(__to, __new); +} + +inline _LIBCPP_INLINE_VISIBILITY void +create_symlink(const path& __to, const path& __new, error_code& __ec) noexcept { + return __create_symlink(__to, __new, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) noexcept { + return __s.type() != file_type::none; +} + +inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) noexcept { + return status_known(__s) && __s.type() != file_type::not_found; +} + +inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) { + return exists(__status(__p)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p, + error_code& __ec) noexcept { + auto __s = __status(__p, &__ec); + if (status_known(__s)) + __ec.clear(); + return exists(__s); +} + +inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1, + const path& __p2) { + return __equivalent(__p1, __p2); +} + +inline _LIBCPP_INLINE_VISIBILITY bool +equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept { + return __equivalent(__p1, __p2, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) { + return __file_size(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY uintmax_t +file_size(const path& __p, error_code& __ec) noexcept { + return __file_size(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) { + return __hard_link_count(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY uintmax_t +hard_link_count(const path& __p, error_code& __ec) noexcept { + return __hard_link_count(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) noexcept { + return __s.type() == file_type::block; +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) { + return is_block_file(__status(__p)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p, + error_code& __ec) noexcept { + return is_block_file(__status(__p, &__ec)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool +is_character_file(file_status __s) noexcept { + return __s.type() == file_type::character; +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) { + return is_character_file(__status(__p)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool +is_character_file(const path& __p, error_code& __ec) noexcept { + return is_character_file(__status(__p, &__ec)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) noexcept { + return __s.type() == file_type::directory; +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) { + return is_directory(__status(__p)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p, + error_code& __ec) noexcept { + return is_directory(__status(__p, &__ec)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) { + return __fs_is_empty(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p, + error_code& __ec) { + return __fs_is_empty(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) noexcept { + return __s.type() == file_type::fifo; +} +inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) { + return is_fifo(__status(__p)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p, + error_code& __ec) noexcept { + return is_fifo(__status(__p, &__ec)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool +is_regular_file(file_status __s) noexcept { + return __s.type() == file_type::regular; +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) { + return is_regular_file(__status(__p)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool +is_regular_file(const path& __p, error_code& __ec) noexcept { + return is_regular_file(__status(__p, &__ec)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) noexcept { + return __s.type() == file_type::socket; +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) { + return is_socket(__status(__p)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p, + error_code& __ec) noexcept { + return is_socket(__status(__p, &__ec)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) noexcept { + return __s.type() == file_type::symlink; +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) { + return is_symlink(__symlink_status(__p)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p, + error_code& __ec) noexcept { + return is_symlink(__symlink_status(__p, &__ec)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) noexcept { + return exists(__s) && !is_regular_file(__s) && !is_directory(__s) && + !is_symlink(__s); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) { + return is_other(__status(__p)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p, + error_code& __ec) noexcept { + return is_other(__status(__p, &__ec)); +} + +inline _LIBCPP_INLINE_VISIBILITY file_time_type +last_write_time(const path& __p) { + return __last_write_time(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY file_time_type +last_write_time(const path& __p, error_code& __ec) noexcept { + return __last_write_time(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p, + file_time_type __t) { + __last_write_time(__p, __t); +} + +inline _LIBCPP_INLINE_VISIBILITY void +last_write_time(const path& __p, file_time_type __t, + error_code& __ec) noexcept { + __last_write_time(__p, __t, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void +permissions(const path& __p, perms __prms, + perm_options __opts = perm_options::replace) { + __permissions(__p, __prms, __opts); +} + +inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms, + error_code& __ec) noexcept { + __permissions(__p, __prms, perm_options::replace, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms, + perm_options __opts, + error_code& __ec) { + __permissions(__p, __prms, __opts, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, + const path& __base, + error_code& __ec) { + path __tmp = __weakly_canonical(__p, &__ec); + if (__ec) + return {}; + path __tmp_base = __weakly_canonical(__base, &__ec); + if (__ec) + return {}; + return __tmp.lexically_proximate(__tmp_base); +} + +inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, + error_code& __ec) { + return proximate(__p, current_path(), __ec); +} + +inline _LIBCPP_INLINE_VISIBILITY path +proximate(const path& __p, const path& __base = current_path()) { + return __weakly_canonical(__p).lexically_proximate( + __weakly_canonical(__base)); +} + +inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) { + return __read_symlink(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p, + error_code& __ec) { + return __read_symlink(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, + const path& __base, + error_code& __ec) { + path __tmp = __weakly_canonical(__p, &__ec); + if (__ec) + return path(); + path __tmpbase = __weakly_canonical(__base, &__ec); + if (__ec) + return path(); + return __tmp.lexically_relative(__tmpbase); +} + +inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, + error_code& __ec) { + return relative(__p, current_path(), __ec); +} + +inline _LIBCPP_INLINE_VISIBILITY path +relative(const path& __p, const path& __base = current_path()) { + return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base)); +} + +inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) { + return __remove(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p, + error_code& __ec) noexcept { + return __remove(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) { + return __remove_all(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p, + error_code& __ec) { + return __remove_all(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from, + const path& __to) { + return __rename(__from, __to); +} + +inline _LIBCPP_INLINE_VISIBILITY void +rename(const path& __from, const path& __to, error_code& __ec) noexcept { + return __rename(__from, __to, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p, + uintmax_t __ns) { + return __resize_file(__p, __ns); +} + +inline _LIBCPP_INLINE_VISIBILITY void +resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept { + return __resize_file(__p, __ns, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) { + return __space(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p, + error_code& __ec) noexcept { + return __space(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) { + return __status(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p, + error_code& __ec) noexcept { + return __status(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) { + return __symlink_status(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY file_status +symlink_status(const path& __p, error_code& __ec) noexcept { + return __symlink_status(__p, &__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() { + return __temp_directory_path(); +} + +inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) { + return __temp_directory_path(&__ec); +} + +inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p) { + return __weakly_canonical(__p); +} + +inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p, + error_code& __ec) { + return __weakly_canonical(__p, &__ec); +} + +class directory_iterator; +class recursive_directory_iterator; +class _LIBCPP_HIDDEN __dir_stream; + +class directory_entry { + typedef _VSTD_FS::path _Path; + +public: + // constructors and destructors + directory_entry() noexcept = default; + directory_entry(directory_entry const&) = default; + directory_entry(directory_entry&&) noexcept = default; + + _LIBCPP_INLINE_VISIBILITY + explicit directory_entry(_Path const& __p) : __p_(__p) { + error_code __ec; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + directory_entry(_Path const& __p, error_code& __ec) : __p_(__p) { + __refresh(&__ec); + } + + ~directory_entry() {} + + directory_entry& operator=(directory_entry const&) = default; + directory_entry& operator=(directory_entry&&) noexcept = default; + + _LIBCPP_INLINE_VISIBILITY + void assign(_Path const& __p) { + __p_ = __p; + error_code __ec; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + void assign(_Path const& __p, error_code& __ec) { + __p_ = __p; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + void replace_filename(_Path const& __p) { + __p_.replace_filename(__p); + error_code __ec; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + void replace_filename(_Path const& __p, error_code& __ec) { + __p_ = __p_.parent_path() / __p; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + void refresh() { __refresh(); } + + _LIBCPP_INLINE_VISIBILITY + void refresh(error_code& __ec) noexcept { __refresh(&__ec); } + + _LIBCPP_INLINE_VISIBILITY + _Path const& path() const noexcept { return __p_; } + + _LIBCPP_INLINE_VISIBILITY + operator const _Path&() const noexcept { return __p_; } + + _LIBCPP_INLINE_VISIBILITY + bool exists() const { return _VSTD_FS::exists(file_status{__get_ft()}); } + + _LIBCPP_INLINE_VISIBILITY + bool exists(error_code& __ec) const noexcept { + return _VSTD_FS::exists(file_status{__get_ft(&__ec)}); + } + + _LIBCPP_INLINE_VISIBILITY + bool is_block_file() const { return __get_ft() == file_type::block; } + + _LIBCPP_INLINE_VISIBILITY + bool is_block_file(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::block; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_character_file() const { return __get_ft() == file_type::character; } + + _LIBCPP_INLINE_VISIBILITY + bool is_character_file(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::character; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_directory() const { return __get_ft() == file_type::directory; } + + _LIBCPP_INLINE_VISIBILITY + bool is_directory(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::directory; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_fifo() const { return __get_ft() == file_type::fifo; } + + _LIBCPP_INLINE_VISIBILITY + bool is_fifo(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::fifo; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_other() const { return _VSTD_FS::is_other(file_status{__get_ft()}); } + + _LIBCPP_INLINE_VISIBILITY + bool is_other(error_code& __ec) const noexcept { + return _VSTD_FS::is_other(file_status{__get_ft(&__ec)}); + } + + _LIBCPP_INLINE_VISIBILITY + bool is_regular_file() const { return __get_ft() == file_type::regular; } + + _LIBCPP_INLINE_VISIBILITY + bool is_regular_file(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::regular; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_socket() const { return __get_ft() == file_type::socket; } + + _LIBCPP_INLINE_VISIBILITY + bool is_socket(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::socket; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_symlink() const { return __get_sym_ft() == file_type::symlink; } + + _LIBCPP_INLINE_VISIBILITY + bool is_symlink(error_code& __ec) const noexcept { + return __get_sym_ft(&__ec) == file_type::symlink; + } + _LIBCPP_INLINE_VISIBILITY + uintmax_t file_size() const { return __get_size(); } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t file_size(error_code& __ec) const noexcept { + return __get_size(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t hard_link_count() const { return __get_nlink(); } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t hard_link_count(error_code& __ec) const noexcept { + return __get_nlink(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + file_time_type last_write_time() const { return __get_write_time(); } + + _LIBCPP_INLINE_VISIBILITY + file_time_type last_write_time(error_code& __ec) const noexcept { + return __get_write_time(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + file_status status() const { return __get_status(); } + + _LIBCPP_INLINE_VISIBILITY + file_status status(error_code& __ec) const noexcept { + return __get_status(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + file_status symlink_status() const { return __get_symlink_status(); } + + _LIBCPP_INLINE_VISIBILITY + file_status symlink_status(error_code& __ec) const noexcept { + return __get_symlink_status(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + bool operator<(directory_entry const& __rhs) const noexcept { + return __p_ < __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator==(directory_entry const& __rhs) const noexcept { + return __p_ == __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator!=(directory_entry const& __rhs) const noexcept { + return __p_ != __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator<=(directory_entry const& __rhs) const noexcept { + return __p_ <= __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator>(directory_entry const& __rhs) const noexcept { + return __p_ > __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator>=(directory_entry const& __rhs) const noexcept { + return __p_ >= __rhs.__p_; + } + +private: + friend class directory_iterator; + friend class recursive_directory_iterator; + friend class __dir_stream; + + enum _CacheType : unsigned char { + _Empty, + _IterSymlink, + _IterNonSymlink, + _RefreshSymlink, + _RefreshSymlinkUnresolved, + _RefreshNonSymlink + }; + + struct __cached_data { + uintmax_t __size_; + uintmax_t __nlink_; + file_time_type __write_time_; + perms __sym_perms_; + perms __non_sym_perms_; + file_type __type_; + _CacheType __cache_type_; + + _LIBCPP_INLINE_VISIBILITY + __cached_data() noexcept { __reset(); } + + _LIBCPP_INLINE_VISIBILITY + void __reset() { + __cache_type_ = _Empty; + __type_ = file_type::none; + __sym_perms_ = __non_sym_perms_ = perms::unknown; + __size_ = __nlink_ = uintmax_t(-1); + __write_time_ = file_time_type::min(); + } + }; + + _LIBCPP_INLINE_VISIBILITY + static __cached_data __create_iter_result(file_type __ft) { + __cached_data __data; + __data.__type_ = __ft; + __data.__cache_type_ = [&]() { + switch (__ft) { + case file_type::none: + return _Empty; + case file_type::symlink: + return _IterSymlink; + default: + return _IterNonSymlink; + } + }(); + return __data; + } + + _LIBCPP_INLINE_VISIBILITY + void __assign_iter_entry(_Path&& __p, __cached_data __dt) { + __p_ = std::move(__p); + __data_ = __dt; + } + + _LIBCPP_FUNC_VIS + error_code __do_refresh() noexcept; + + _LIBCPP_INLINE_VISIBILITY + static bool __is_dne_error(error_code const& __ec) { + if (!__ec) + return true; + switch (static_cast<errc>(__ec.value())) { + case errc::no_such_file_or_directory: + case errc::not_a_directory: + return true; + default: + return false; + } + } + + _LIBCPP_INLINE_VISIBILITY + void __handle_error(const char* __msg, error_code* __dest_ec, + error_code const& __ec, bool __allow_dne = false) const { + if (__dest_ec) { + *__dest_ec = __ec; + return; + } + if (__ec && (!__allow_dne || !__is_dne_error(__ec))) + __throw_filesystem_error(__msg, __p_, __ec); + } + + _LIBCPP_INLINE_VISIBILITY + void __refresh(error_code* __ec = nullptr) { + __handle_error("in directory_entry::refresh", __ec, __do_refresh(), + /*allow_dne*/ true); + } + + _LIBCPP_INLINE_VISIBILITY + file_type __get_sym_ft(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + return __symlink_status(__p_, __ec).type(); + case _IterSymlink: + case _RefreshSymlink: + case _RefreshSymlinkUnresolved: + if (__ec) + __ec->clear(); + return file_type::symlink; + case _IterNonSymlink: + case _RefreshNonSymlink: + file_status __st(__data_.__type_); + if (__ec && !_VSTD_FS::exists(__st)) + *__ec = make_error_code(errc::no_such_file_or_directory); + else if (__ec) + __ec->clear(); + return __data_.__type_; + } + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + file_type __get_ft(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return __status(__p_, __ec).type(); + case _IterNonSymlink: + case _RefreshNonSymlink: + case _RefreshSymlink: { + file_status __st(__data_.__type_); + if (__ec && !_VSTD_FS::exists(__st)) + *__ec = make_error_code(errc::no_such_file_or_directory); + else if (__ec) + __ec->clear(); + return __data_.__type_; + } + } + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + file_status __get_status(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return __status(__p_, __ec); + case _RefreshNonSymlink: + case _RefreshSymlink: + return file_status(__get_ft(__ec), __data_.__non_sym_perms_); + } + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + file_status __get_symlink_status(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + return __symlink_status(__p_, __ec); + case _RefreshNonSymlink: + return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_); + case _RefreshSymlink: + case _RefreshSymlinkUnresolved: + return file_status(__get_sym_ft(__ec), __data_.__sym_perms_); + } + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t __get_size(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return _VSTD_FS::__file_size(__p_, __ec); + case _RefreshSymlink: + case _RefreshNonSymlink: { + error_code __m_ec; + file_status __st(__get_ft(&__m_ec)); + __handle_error("in directory_entry::file_size", __ec, __m_ec); + if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) { + errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory + : errc::not_supported; + __handle_error("in directory_entry::file_size", __ec, + make_error_code(__err_kind)); + } + return __data_.__size_; + } + } + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t __get_nlink(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return _VSTD_FS::__hard_link_count(__p_, __ec); + case _RefreshSymlink: + case _RefreshNonSymlink: { + error_code __m_ec; + (void)__get_ft(&__m_ec); + __handle_error("in directory_entry::hard_link_count", __ec, __m_ec); + return __data_.__nlink_; + } + } + _LIBCPP_UNREACHABLE(); + } + + _LIBCPP_INLINE_VISIBILITY + file_time_type __get_write_time(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return _VSTD_FS::__last_write_time(__p_, __ec); + case _RefreshSymlink: + case _RefreshNonSymlink: { + error_code __m_ec; + file_status __st(__get_ft(&__m_ec)); + __handle_error("in directory_entry::last_write_time", __ec, __m_ec); + if (_VSTD_FS::exists(__st) && + __data_.__write_time_ == file_time_type::min()) + __handle_error("in directory_entry::last_write_time", __ec, + make_error_code(errc::value_too_large)); + return __data_.__write_time_; + } + } + _LIBCPP_UNREACHABLE(); + } + +private: + _Path __p_; + __cached_data __data_; +}; + +class __dir_element_proxy { +public: + inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() { + return _VSTD::move(__elem_); + } + +private: + friend class directory_iterator; + friend class recursive_directory_iterator; + explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {} + __dir_element_proxy(__dir_element_proxy&& __o) + : __elem_(_VSTD::move(__o.__elem_)) {} + directory_entry __elem_; +}; + +class directory_iterator { +public: + typedef directory_entry value_type; + typedef ptrdiff_t difference_type; + typedef value_type const* pointer; + typedef value_type const& reference; + typedef input_iterator_tag iterator_category; + +public: + //ctor & dtor + directory_iterator() noexcept {} + + explicit directory_iterator(const path& __p) + : directory_iterator(__p, nullptr) {} + + directory_iterator(const path& __p, directory_options __opts) + : directory_iterator(__p, nullptr, __opts) {} + + directory_iterator(const path& __p, error_code& __ec) + : directory_iterator(__p, &__ec) {} + + directory_iterator(const path& __p, directory_options __opts, + error_code& __ec) + : directory_iterator(__p, &__ec, __opts) {} + + directory_iterator(const directory_iterator&) = default; + directory_iterator(directory_iterator&&) = default; + directory_iterator& operator=(const directory_iterator&) = default; + + directory_iterator& operator=(directory_iterator&& __o) noexcept { + // non-default implementation provided to support self-move assign. + if (this != &__o) { + __imp_ = _VSTD::move(__o.__imp_); + } + return *this; + } + + ~directory_iterator() = default; + + const directory_entry& operator*() const { + _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced"); + return __dereference(); + } + + const directory_entry* operator->() const { return &**this; } + + directory_iterator& operator++() { return __increment(); } + + __dir_element_proxy operator++(int) { + __dir_element_proxy __p(**this); + __increment(); + return __p; + } + + directory_iterator& increment(error_code& __ec) { return __increment(&__ec); } + +private: + inline _LIBCPP_INLINE_VISIBILITY friend bool + operator==(const directory_iterator& __lhs, + const directory_iterator& __rhs) noexcept; + + // construct the dir_stream + _LIBCPP_FUNC_VIS + directory_iterator(const path&, error_code*, + directory_options = directory_options::none); + + _LIBCPP_FUNC_VIS + directory_iterator& __increment(error_code* __ec = nullptr); + + _LIBCPP_FUNC_VIS + const directory_entry& __dereference() const; + +private: + shared_ptr<__dir_stream> __imp_; +}; + +inline _LIBCPP_INLINE_VISIBILITY bool +operator==(const directory_iterator& __lhs, + const directory_iterator& __rhs) noexcept { + return __lhs.__imp_ == __rhs.__imp_; +} + +inline _LIBCPP_INLINE_VISIBILITY bool +operator!=(const directory_iterator& __lhs, + const directory_iterator& __rhs) noexcept { + return !(__lhs == __rhs); +} + +// enable directory_iterator range-based for statements +inline _LIBCPP_INLINE_VISIBILITY directory_iterator +begin(directory_iterator __iter) noexcept { + return __iter; +} + +inline _LIBCPP_INLINE_VISIBILITY directory_iterator +end(const directory_iterator&) noexcept { + return directory_iterator(); +} + +class recursive_directory_iterator { +public: + using value_type = directory_entry; + using difference_type = std::ptrdiff_t; + using pointer = directory_entry const*; + using reference = directory_entry const&; + using iterator_category = std::input_iterator_tag; + +public: + // constructors and destructor + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator() noexcept : __rec_(false) {} + + _LIBCPP_INLINE_VISIBILITY + explicit recursive_directory_iterator( + const path& __p, directory_options __xoptions = directory_options::none) + : recursive_directory_iterator(__p, __xoptions, nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator(const path& __p, directory_options __xoptions, + error_code& __ec) + : recursive_directory_iterator(__p, __xoptions, &__ec) {} + + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator(const path& __p, error_code& __ec) + : recursive_directory_iterator(__p, directory_options::none, &__ec) {} + + recursive_directory_iterator(const recursive_directory_iterator&) = default; + recursive_directory_iterator(recursive_directory_iterator&&) = default; + + recursive_directory_iterator& + operator=(const recursive_directory_iterator&) = default; + + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator& + operator=(recursive_directory_iterator&& __o) noexcept { + // non-default implementation provided to support self-move assign. + if (this != &__o) { + __imp_ = _VSTD::move(__o.__imp_); + __rec_ = __o.__rec_; + } + return *this; + } + + ~recursive_directory_iterator() = default; + + _LIBCPP_INLINE_VISIBILITY + const directory_entry& operator*() const { return __dereference(); } + + _LIBCPP_INLINE_VISIBILITY + const directory_entry* operator->() const { return &__dereference(); } + + recursive_directory_iterator& operator++() { return __increment(); } + + _LIBCPP_INLINE_VISIBILITY + __dir_element_proxy operator++(int) { + __dir_element_proxy __p(**this); + __increment(); + return __p; + } + + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator& increment(error_code& __ec) { + return __increment(&__ec); + } + + _LIBCPP_FUNC_VIS directory_options options() const; + _LIBCPP_FUNC_VIS int depth() const; + + _LIBCPP_INLINE_VISIBILITY + void pop() { __pop(); } + + _LIBCPP_INLINE_VISIBILITY + void pop(error_code& __ec) { __pop(&__ec); } + + _LIBCPP_INLINE_VISIBILITY + bool recursion_pending() const { return __rec_; } + + _LIBCPP_INLINE_VISIBILITY + void disable_recursion_pending() { __rec_ = false; } + +private: + recursive_directory_iterator(const path& __p, directory_options __opt, + error_code* __ec); + + _LIBCPP_FUNC_VIS + const directory_entry& __dereference() const; + + _LIBCPP_FUNC_VIS + bool __try_recursion(error_code* __ec); + + _LIBCPP_FUNC_VIS + void __advance(error_code* __ec = nullptr); + + _LIBCPP_FUNC_VIS + recursive_directory_iterator& __increment(error_code* __ec = nullptr); + + _LIBCPP_FUNC_VIS + void __pop(error_code* __ec = nullptr); + + inline _LIBCPP_INLINE_VISIBILITY friend bool + operator==(const recursive_directory_iterator&, + const recursive_directory_iterator&) noexcept; + + struct _LIBCPP_HIDDEN __shared_imp; + shared_ptr<__shared_imp> __imp_; + bool __rec_; +}; // class recursive_directory_iterator + +inline _LIBCPP_INLINE_VISIBILITY bool +operator==(const recursive_directory_iterator& __lhs, + const recursive_directory_iterator& __rhs) noexcept { + return __lhs.__imp_ == __rhs.__imp_; +} + +_LIBCPP_INLINE_VISIBILITY +inline bool operator!=(const recursive_directory_iterator& __lhs, + const recursive_directory_iterator& __rhs) noexcept { + return !(__lhs == __rhs); +} +// enable recursive_directory_iterator range-based for statements +inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator +begin(recursive_directory_iterator __iter) noexcept { + return __iter; +} + +inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator +end(const recursive_directory_iterator&) noexcept { + return recursive_directory_iterator(); +} + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // !_LIBCPP_CXX03_LANG + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_FILESYSTEM diff --git a/android/x86/include/v8/libc++/float.h b/android/x86/include/v8/libc++/float.h new file mode 100755 index 00000000..5c1e1db7 --- /dev/null +++ b/android/x86/include/v8/libc++/float.h @@ -0,0 +1,93 @@ +// -*- C++ -*- +//===--------------------------- float.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FLOAT_H +#define _LIBCPP_FLOAT_H + +/* + float.h synopsis + +Macros: + + FLT_ROUNDS + FLT_EVAL_METHOD // C99 + FLT_RADIX + + FLT_MANT_DIG + DBL_MANT_DIG + LDBL_MANT_DIG + + FLT_HAS_SUBNORM // C11 + DBL_HAS_SUBNORM // C11 + LDBL_HAS_SUBNORM // C11 + + DECIMAL_DIG // C99 + FLT_DECIMAL_DIG // C11 + DBL_DECIMAL_DIG // C11 + LDBL_DECIMAL_DIG // C11 + + FLT_DIG + DBL_DIG + LDBL_DIG + + FLT_MIN_EXP + DBL_MIN_EXP + LDBL_MIN_EXP + + FLT_MIN_10_EXP + DBL_MIN_10_EXP + LDBL_MIN_10_EXP + + FLT_MAX_EXP + DBL_MAX_EXP + LDBL_MAX_EXP + + FLT_MAX_10_EXP + DBL_MAX_10_EXP + LDBL_MAX_10_EXP + + FLT_MAX + DBL_MAX + LDBL_MAX + + FLT_EPSILON + DBL_EPSILON + LDBL_EPSILON + + FLT_MIN + DBL_MIN + LDBL_MIN + + FLT_TRUE_MIN // C11 + DBL_TRUE_MIN // C11 + LDBL_TRUE_MIN // C11 + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <float.h> + +#ifdef __cplusplus + +#ifndef FLT_EVAL_METHOD +#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ +#endif + +#ifndef DECIMAL_DIG +#define DECIMAL_DIG __DECIMAL_DIG__ +#endif + +#endif // __cplusplus + +#endif // _LIBCPP_FLOAT_H diff --git a/android/x86/include/v8/libc++/forward_list b/android/x86/include/v8/libc++/forward_list new file mode 100755 index 00000000..bbea71ee --- /dev/null +++ b/android/x86/include/v8/libc++/forward_list @@ -0,0 +1,1767 @@ +// -*- C++ -*- +//===----------------------- forward_list ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FORWARD_LIST +#define _LIBCPP_FORWARD_LIST + +/* + forward_list synopsis + +namespace std +{ + +template <class T, class Allocator = allocator<T>> +class forward_list +{ +public: + typedef T value_type; + typedef Allocator allocator_type; + + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef <details> iterator; + typedef <details> const_iterator; + + forward_list() + noexcept(is_nothrow_default_constructible<allocator_type>::value); + explicit forward_list(const allocator_type& a); + explicit forward_list(size_type n); + explicit forward_list(size_type n, const allocator_type& a); // C++14 + forward_list(size_type n, const value_type& v); + forward_list(size_type n, const value_type& v, const allocator_type& a); + template <class InputIterator> + forward_list(InputIterator first, InputIterator last); + template <class InputIterator> + forward_list(InputIterator first, InputIterator last, const allocator_type& a); + forward_list(const forward_list& x); + forward_list(const forward_list& x, const allocator_type& a); + forward_list(forward_list&& x) + noexcept(is_nothrow_move_constructible<allocator_type>::value); + forward_list(forward_list&& x, const allocator_type& a); + forward_list(initializer_list<value_type> il); + forward_list(initializer_list<value_type> il, const allocator_type& a); + + ~forward_list(); + + forward_list& operator=(const forward_list& x); + forward_list& operator=(forward_list&& x) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value); + forward_list& operator=(initializer_list<value_type> il); + + template <class InputIterator> + void assign(InputIterator first, InputIterator last); + void assign(size_type n, const value_type& v); + void assign(initializer_list<value_type> il); + + allocator_type get_allocator() const noexcept; + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + iterator before_begin() noexcept; + const_iterator before_begin() const noexcept; + const_iterator cbefore_begin() const noexcept; + + bool empty() const noexcept; + size_type max_size() const noexcept; + + reference front(); + const_reference front() const; + + template <class... Args> reference emplace_front(Args&&... args); // reference in C++17 + void push_front(const value_type& v); + void push_front(value_type&& v); + + void pop_front(); + + template <class... Args> + iterator emplace_after(const_iterator p, Args&&... args); + iterator insert_after(const_iterator p, const value_type& v); + iterator insert_after(const_iterator p, value_type&& v); + iterator insert_after(const_iterator p, size_type n, const value_type& v); + template <class InputIterator> + iterator insert_after(const_iterator p, + InputIterator first, InputIterator last); + iterator insert_after(const_iterator p, initializer_list<value_type> il); + + iterator erase_after(const_iterator p); + iterator erase_after(const_iterator first, const_iterator last); + + void swap(forward_list& x) + noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17 + + void resize(size_type n); + void resize(size_type n, const value_type& v); + void clear() noexcept; + + void splice_after(const_iterator p, forward_list& x); + void splice_after(const_iterator p, forward_list&& x); + void splice_after(const_iterator p, forward_list& x, const_iterator i); + void splice_after(const_iterator p, forward_list&& x, const_iterator i); + void splice_after(const_iterator p, forward_list& x, + const_iterator first, const_iterator last); + void splice_after(const_iterator p, forward_list&& x, + const_iterator first, const_iterator last); + void remove(const value_type& v); + template <class Predicate> void remove_if(Predicate pred); + void unique(); + template <class BinaryPredicate> void unique(BinaryPredicate binary_pred); + void merge(forward_list& x); + void merge(forward_list&& x); + template <class Compare> void merge(forward_list& x, Compare comp); + template <class Compare> void merge(forward_list&& x, Compare comp); + void sort(); + template <class Compare> void sort(Compare comp); + void reverse() noexcept; +}; + + +template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> + forward_list(InputIterator, InputIterator, Allocator = Allocator()) + -> forward_list<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 + +template <class T, class Allocator> + bool operator==(const forward_list<T, Allocator>& x, + const forward_list<T, Allocator>& y); + +template <class T, class Allocator> + bool operator< (const forward_list<T, Allocator>& x, + const forward_list<T, Allocator>& y); + +template <class T, class Allocator> + bool operator!=(const forward_list<T, Allocator>& x, + const forward_list<T, Allocator>& y); + +template <class T, class Allocator> + bool operator> (const forward_list<T, Allocator>& x, + const forward_list<T, Allocator>& y); + +template <class T, class Allocator> + bool operator>=(const forward_list<T, Allocator>& x, + const forward_list<T, Allocator>& y); + +template <class T, class Allocator> + bool operator<=(const forward_list<T, Allocator>& x, + const forward_list<T, Allocator>& y); + +template <class T, class Allocator> + void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y) + noexcept(noexcept(x.swap(y))); + +template <class T, class Allocator, class U> + void erase(forward_list<T, Allocator>& c, const U& value); // C++20 +template <class T, class Allocator, class Predicate> + void erase_if(forward_list<T, Allocator>& c, Predicate pred); // C++20 + +} // std + +*/ + +#include <__config> +#include <initializer_list> +#include <memory> +#include <limits> +#include <iterator> +#include <algorithm> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp, class _VoidPtr> struct __forward_list_node; +template <class _NodePtr> struct __forward_begin_node; + + +template <class> +struct __forward_list_node_value_type; + +template <class _Tp, class _VoidPtr> +struct __forward_list_node_value_type<__forward_list_node<_Tp, _VoidPtr> > { + typedef _Tp type; +}; + +template <class _NodePtr> +struct __forward_node_traits { + + typedef typename remove_cv< + typename pointer_traits<_NodePtr>::element_type>::type __node; + typedef typename __forward_list_node_value_type<__node>::type __node_value_type; + typedef _NodePtr __node_pointer; + typedef __forward_begin_node<_NodePtr> __begin_node; + typedef typename __rebind_pointer<_NodePtr, __begin_node>::type + __begin_node_pointer; + typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer; + +#if defined(_LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB) + typedef __begin_node_pointer __iter_node_pointer; +#else + typedef typename conditional< + is_pointer<__void_pointer>::value, + __begin_node_pointer, + __node_pointer + >::type __iter_node_pointer; +#endif + + typedef typename conditional< + is_same<__iter_node_pointer, __node_pointer>::value, + __begin_node_pointer, + __node_pointer + >::type __non_iter_node_pointer; + + _LIBCPP_INLINE_VISIBILITY + static __iter_node_pointer __as_iter_node(__iter_node_pointer __p) { + return __p; + } + _LIBCPP_INLINE_VISIBILITY + static __iter_node_pointer __as_iter_node(__non_iter_node_pointer __p) { + return static_cast<__iter_node_pointer>(static_cast<__void_pointer>(__p)); + } +}; + +template <class _NodePtr> +struct __forward_begin_node +{ + typedef _NodePtr pointer; + typedef typename __rebind_pointer<_NodePtr, __forward_begin_node>::type __begin_node_pointer; + + pointer __next_; + + _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + __begin_node_pointer __next_as_begin() const { + return static_cast<__begin_node_pointer>(__next_); + } +}; + +template <class _Tp, class _VoidPtr> +struct _LIBCPP_HIDDEN __begin_node_of +{ + typedef __forward_begin_node< + typename __rebind_pointer<_VoidPtr, __forward_list_node<_Tp, _VoidPtr> >::type + > type; +}; + +template <class _Tp, class _VoidPtr> +struct __forward_list_node + : public __begin_node_of<_Tp, _VoidPtr>::type +{ + typedef _Tp value_type; + + value_type __value_; +}; + + +template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS forward_list; +template<class _NodeConstPtr> class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator; + +template <class _NodePtr> +class _LIBCPP_TEMPLATE_VIS __forward_list_iterator +{ + typedef __forward_node_traits<_NodePtr> __traits; + typedef typename __traits::__node_pointer __node_pointer; + typedef typename __traits::__begin_node_pointer __begin_node_pointer; + typedef typename __traits::__iter_node_pointer __iter_node_pointer; + typedef typename __traits::__void_pointer __void_pointer; + + __iter_node_pointer __ptr_; + + _LIBCPP_INLINE_VISIBILITY + __begin_node_pointer __get_begin() const { + return static_cast<__begin_node_pointer>( + static_cast<__void_pointer>(__ptr_)); + } + _LIBCPP_INLINE_VISIBILITY + __node_pointer __get_unsafe_node_pointer() const { + return static_cast<__node_pointer>( + static_cast<__void_pointer>(__ptr_)); + } + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT + : __ptr_(__traits::__as_iter_node(__p)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT + : __ptr_(__traits::__as_iter_node(__p)) {} + + template<class, class> friend class _LIBCPP_TEMPLATE_VIS forward_list; + template<class> friend class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename __traits::__node_value_type value_type; + typedef value_type& reference; + typedef typename pointer_traits<__node_pointer>::difference_type + difference_type; + typedef typename __rebind_pointer<__node_pointer, value_type>::type pointer; + + _LIBCPP_INLINE_VISIBILITY + __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __get_unsafe_node_pointer()->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const { + return pointer_traits<pointer>::pointer_to(__get_unsafe_node_pointer()->__value_); + } + + _LIBCPP_INLINE_VISIBILITY + __forward_list_iterator& operator++() + { + __ptr_ = __traits::__as_iter_node(__ptr_->__next_); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __forward_list_iterator operator++(int) + { + __forward_list_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __forward_list_iterator& __x, + const __forward_list_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __forward_list_iterator& __x, + const __forward_list_iterator& __y) + {return !(__x == __y);} +}; + +template <class _NodeConstPtr> +class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator +{ + static_assert((!is_const<typename pointer_traits<_NodeConstPtr>::element_type>::value), ""); + typedef _NodeConstPtr _NodePtr; + + typedef __forward_node_traits<_NodePtr> __traits; + typedef typename __traits::__node __node; + typedef typename __traits::__node_pointer __node_pointer; + typedef typename __traits::__begin_node_pointer __begin_node_pointer; + typedef typename __traits::__iter_node_pointer __iter_node_pointer; + typedef typename __traits::__void_pointer __void_pointer; + + __iter_node_pointer __ptr_; + + __begin_node_pointer __get_begin() const { + return static_cast<__begin_node_pointer>( + static_cast<__void_pointer>(__ptr_)); + } + __node_pointer __get_unsafe_node_pointer() const { + return static_cast<__node_pointer>( + static_cast<__void_pointer>(__ptr_)); + } + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT + : __ptr_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT + : __ptr_(__traits::__as_iter_node(__p)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_const_iterator(__node_pointer __p) _NOEXCEPT + : __ptr_(__traits::__as_iter_node(__p)) {} + + + template<class, class> friend class forward_list; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename __traits::__node_value_type value_type; + typedef const value_type& reference; + typedef typename pointer_traits<__node_pointer>::difference_type + difference_type; + typedef typename __rebind_pointer<__node_pointer, const value_type>::type + pointer; + + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT + : __ptr_(__p.__ptr_) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __get_unsafe_node_pointer()->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return pointer_traits<pointer>::pointer_to( + __get_unsafe_node_pointer()->__value_);} + + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator& operator++() + { + __ptr_ = __traits::__as_iter_node(__ptr_->__next_); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator operator++(int) + { + __forward_list_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __forward_list_const_iterator& __x, + const __forward_list_const_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __forward_list_const_iterator& __x, + const __forward_list_const_iterator& __y) + {return !(__x == __y);} +}; + +template <class _Tp, class _Alloc> +class __forward_list_base +{ +protected: + typedef _Tp value_type; + typedef _Alloc allocator_type; + + typedef typename allocator_traits<allocator_type>::void_pointer void_pointer; + typedef __forward_list_node<value_type, void_pointer> __node; + typedef typename __begin_node_of<value_type, void_pointer>::type __begin_node; + typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __node>::type __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + typedef typename __node_traits::pointer __node_pointer; + + typedef typename __rebind_alloc_helper< + allocator_traits<allocator_type>, __begin_node + >::type __begin_node_allocator; + typedef typename allocator_traits<__begin_node_allocator>::pointer + __begin_node_pointer; + + static_assert((!is_same<allocator_type, __node_allocator>::value), + "internal allocator type must differ from user-specified " + "type; otherwise overload resolution breaks"); + + __compressed_pair<__begin_node, __node_allocator> __before_begin_; + + _LIBCPP_INLINE_VISIBILITY + __begin_node_pointer __before_begin() _NOEXCEPT + {return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_.first());} + _LIBCPP_INLINE_VISIBILITY + __begin_node_pointer __before_begin() const _NOEXCEPT + {return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_.first()));} + + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __alloc() _NOEXCEPT + {return __before_begin_.second();} + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __alloc() const _NOEXCEPT + {return __before_begin_.second();} + + typedef __forward_list_iterator<__node_pointer> iterator; + typedef __forward_list_const_iterator<__node_pointer> const_iterator; + + _LIBCPP_INLINE_VISIBILITY + __forward_list_base() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) + : __before_begin_(__begin_node()) {} + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_base(const allocator_type& __a) + : __before_begin_(__begin_node(), __node_allocator(__a)) {} + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_base(const __node_allocator& __a) + : __before_begin_(__begin_node(), __a) {} +#ifndef _LIBCPP_CXX03_LANG +public: + _LIBCPP_INLINE_VISIBILITY + __forward_list_base(__forward_list_base&& __x) + _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); + _LIBCPP_INLINE_VISIBILITY + __forward_list_base(__forward_list_base&& __x, const allocator_type& __a); +#endif // _LIBCPP_CXX03_LANG + +private: + __forward_list_base(const __forward_list_base&); + __forward_list_base& operator=(const __forward_list_base&); + +public: + ~__forward_list_base(); + +protected: + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __forward_list_base& __x) + {__copy_assign_alloc(__x, integral_constant<bool, + __node_traits::propagate_on_container_copy_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__forward_list_base& __x) + _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<__node_allocator>::value) + {__move_assign_alloc(__x, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>());} + +public: + _LIBCPP_INLINE_VISIBILITY + void swap(__forward_list_base& __x) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT; +#else + _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || + __is_nothrow_swappable<__node_allocator>::value); +#endif +protected: + void clear() _NOEXCEPT; + +private: + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __forward_list_base&, false_type) {} + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __forward_list_base& __x, true_type) + { + if (__alloc() != __x.__alloc()) + clear(); + __alloc() = __x.__alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT + {} + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__forward_list_base& __x, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) + {__alloc() = _VSTD::move(__x.__alloc());} +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +inline +__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x) + _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) + : __before_begin_(_VSTD::move(__x.__before_begin_)) +{ + __x.__before_begin()->__next_ = nullptr; +} + +template <class _Tp, class _Alloc> +inline +__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x, + const allocator_type& __a) + : __before_begin_(__begin_node(), __node_allocator(__a)) +{ + if (__alloc() == __x.__alloc()) + { + __before_begin()->__next_ = __x.__before_begin()->__next_; + __x.__before_begin()->__next_ = nullptr; + } +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +__forward_list_base<_Tp, _Alloc>::~__forward_list_base() +{ + clear(); +} + +template <class _Tp, class _Alloc> +inline +void +__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || + __is_nothrow_swappable<__node_allocator>::value) +#endif +{ + __swap_allocator(__alloc(), __x.__alloc(), + integral_constant<bool, __node_traits::propagate_on_container_swap::value>()); + using _VSTD::swap; + swap(__before_begin()->__next_, __x.__before_begin()->__next_); +} + +template <class _Tp, class _Alloc> +void +__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT +{ + __node_allocator& __a = __alloc(); + for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;) + { + __node_pointer __next = __p->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__p->__value_)); + __node_traits::deallocate(__a, __p, 1); + __p = __next; + } + __before_begin()->__next_ = nullptr; +} + +template <class _Tp, class _Alloc /*= allocator<_Tp>*/> +class _LIBCPP_TEMPLATE_VIS forward_list + : private __forward_list_base<_Tp, _Alloc> +{ + typedef __forward_list_base<_Tp, _Alloc> base; + typedef typename base::__node_allocator __node_allocator; + typedef typename base::__node __node; + typedef typename base::__node_traits __node_traits; + typedef typename base::__node_pointer __node_pointer; + typedef typename base::__begin_node_pointer __begin_node_pointer; + +public: + typedef _Tp value_type; + typedef _Alloc allocator_type; + + static_assert((is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + + _LIBCPP_INLINE_VISIBILITY + forward_list() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) + {} // = default; + _LIBCPP_INLINE_VISIBILITY + explicit forward_list(const allocator_type& __a); + explicit forward_list(size_type __n); +#if _LIBCPP_STD_VER > 11 + explicit forward_list(size_type __n, const allocator_type& __a); +#endif + forward_list(size_type __n, const value_type& __v); + forward_list(size_type __n, const value_type& __v, const allocator_type& __a); + template <class _InputIterator> + forward_list(_InputIterator __f, _InputIterator __l, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type* = nullptr); + template <class _InputIterator> + forward_list(_InputIterator __f, _InputIterator __l, + const allocator_type& __a, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type* = nullptr); + forward_list(const forward_list& __x); + forward_list(const forward_list& __x, const allocator_type& __a); + + forward_list& operator=(const forward_list& __x); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + forward_list(forward_list&& __x) + _NOEXCEPT_(is_nothrow_move_constructible<base>::value) + : base(_VSTD::move(__x)) {} + forward_list(forward_list&& __x, const allocator_type& __a); + + forward_list(initializer_list<value_type> __il); + forward_list(initializer_list<value_type> __il, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + forward_list& operator=(forward_list&& __x) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value); + + _LIBCPP_INLINE_VISIBILITY + forward_list& operator=(initializer_list<value_type> __il); + + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list<value_type> __il); +#endif // _LIBCPP_CXX03_LANG + + // ~forward_list() = default; + + template <class _InputIterator> + typename enable_if + < + __is_input_iterator<_InputIterator>::value, + void + >::type + assign(_InputIterator __f, _InputIterator __l); + void assign(size_type __n, const value_type& __v); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT + {return allocator_type(base::__alloc());} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT + {return iterator(base::__before_begin()->__next_);} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT + {return const_iterator(base::__before_begin()->__next_);} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT + {return iterator(nullptr);} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT + {return const_iterator(nullptr);} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT + {return const_iterator(base::__before_begin()->__next_);} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT + {return const_iterator(nullptr);} + + _LIBCPP_INLINE_VISIBILITY + iterator before_begin() _NOEXCEPT + {return iterator(base::__before_begin());} + _LIBCPP_INLINE_VISIBILITY + const_iterator before_begin() const _NOEXCEPT + {return const_iterator(base::__before_begin());} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbefore_begin() const _NOEXCEPT + {return const_iterator(base::__before_begin());} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT + {return base::__before_begin()->__next_ == nullptr;} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT { + return std::min<size_type>( + __node_traits::max_size(base::__alloc()), + numeric_limits<difference_type>::max()); + } + + _LIBCPP_INLINE_VISIBILITY + reference front() {return base::__before_begin()->__next_->__value_;} + _LIBCPP_INLINE_VISIBILITY + const_reference front() const {return base::__before_begin()->__next_->__value_;} + +#ifndef _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 14 + template <class... _Args> reference emplace_front(_Args&&... __args); +#else + template <class... _Args> void emplace_front(_Args&&... __args); +#endif + void push_front(value_type&& __v); +#endif // _LIBCPP_CXX03_LANG + void push_front(const value_type& __v); + + void pop_front(); + +#ifndef _LIBCPP_CXX03_LANG + template <class... _Args> + iterator emplace_after(const_iterator __p, _Args&&... __args); + + iterator insert_after(const_iterator __p, value_type&& __v); + iterator insert_after(const_iterator __p, initializer_list<value_type> __il) + {return insert_after(__p, __il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + iterator insert_after(const_iterator __p, const value_type& __v); + iterator insert_after(const_iterator __p, size_type __n, const value_type& __v); + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_input_iterator<_InputIterator>::value, + iterator + >::type + insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l); + + iterator erase_after(const_iterator __p); + iterator erase_after(const_iterator __f, const_iterator __l); + + _LIBCPP_INLINE_VISIBILITY + void swap(forward_list& __x) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) +#endif + {base::swap(__x);} + + void resize(size_type __n); + void resize(size_type __n, const value_type& __v); + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {base::clear();} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void splice_after(const_iterator __p, forward_list&& __x); + _LIBCPP_INLINE_VISIBILITY + void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i); + _LIBCPP_INLINE_VISIBILITY + void splice_after(const_iterator __p, forward_list&& __x, + const_iterator __f, const_iterator __l); +#endif // _LIBCPP_CXX03_LANG + void splice_after(const_iterator __p, forward_list& __x); + void splice_after(const_iterator __p, forward_list& __x, const_iterator __i); + void splice_after(const_iterator __p, forward_list& __x, + const_iterator __f, const_iterator __l); + void remove(const value_type& __v); + template <class _Predicate> void remove_if(_Predicate __pred); + _LIBCPP_INLINE_VISIBILITY + void unique() {unique(__equal_to<value_type>());} + template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void merge(forward_list&& __x) {merge(__x, __less<value_type>());} + template <class _Compare> + _LIBCPP_INLINE_VISIBILITY + void merge(forward_list&& __x, _Compare __comp) + {merge(__x, _VSTD::move(__comp));} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void merge(forward_list& __x) {merge(__x, __less<value_type>());} + template <class _Compare> void merge(forward_list& __x, _Compare __comp); + _LIBCPP_INLINE_VISIBILITY + void sort() {sort(__less<value_type>());} + template <class _Compare> _LIBCPP_INLINE_VISIBILITY void sort(_Compare __comp); + void reverse() _NOEXCEPT; + +private: + +#ifndef _LIBCPP_CXX03_LANG + void __move_assign(forward_list& __x, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); + void __move_assign(forward_list& __x, false_type); +#endif // _LIBCPP_CXX03_LANG + + template <class _Compare> + static + __node_pointer + __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp); + + template <class _Compare> + static + __node_pointer + __sort(__node_pointer __f, difference_type __sz, _Compare& __comp); +}; + + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +forward_list(_InputIterator, _InputIterator) + -> forward_list<typename iterator_traits<_InputIterator>::value_type, _Alloc>; + +template<class _InputIterator, + class _Alloc, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +forward_list(_InputIterator, _InputIterator, _Alloc) + -> forward_list<typename iterator_traits<_InputIterator>::value_type, _Alloc>; +#endif + +template <class _Tp, class _Alloc> +inline +forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a) + : base(__a) +{ +} + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(size_type __n) +{ + if (__n > 0) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1)); + for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n, + __p = __p->__next_as_begin()) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); + __h->__next_ = nullptr; + __p->__next_ = __h.release(); + } + } +} + +#if _LIBCPP_STD_VER > 11 +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(size_type __n, + const allocator_type& __base_alloc) + : base ( __base_alloc ) +{ + if (__n > 0) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1)); + for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n, + __p = __p->__next_as_begin()) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); + __h->__next_ = nullptr; + __p->__next_ = __h.release(); + } + } +} +#endif + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v) +{ + insert_after(cbefore_begin(), __n, __v); +} + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v, + const allocator_type& __a) + : base(__a) +{ + insert_after(cbefore_begin(), __n, __v); +} + +template <class _Tp, class _Alloc> +template <class _InputIterator> +forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type*) +{ + insert_after(cbefore_begin(), __f, __l); +} + +template <class _Tp, class _Alloc> +template <class _InputIterator> +forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, + const allocator_type& __a, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type*) + : base(__a) +{ + insert_after(cbefore_begin(), __f, __l); +} + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x) + : base( + __node_traits::select_on_container_copy_construction(__x.__alloc())) { + insert_after(cbefore_begin(), __x.begin(), __x.end()); +} + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x, + const allocator_type& __a) + : base(__a) +{ + insert_after(cbefore_begin(), __x.begin(), __x.end()); +} + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) +{ + if (this != &__x) + { + base::__copy_assign_alloc(__x); + assign(__x.begin(), __x.end()); + } + return *this; +} + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, + const allocator_type& __a) + : base(_VSTD::move(__x), __a) +{ + if (base::__alloc() != __x.__alloc()) + { + typedef move_iterator<iterator> _Ip; + insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end())); + } +} + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il) +{ + insert_after(cbefore_begin(), __il.begin(), __il.end()); +} + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il, + const allocator_type& __a) + : base(__a) +{ + insert_after(cbefore_begin(), __il.begin(), __il.end()); +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) +{ + clear(); + base::__move_assign_alloc(__x); + base::__before_begin()->__next_ = __x.__before_begin()->__next_; + __x.__before_begin()->__next_ = nullptr; +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type) +{ + if (base::__alloc() == __x.__alloc()) + __move_assign(__x, true_type()); + else + { + typedef move_iterator<iterator> _Ip; + assign(_Ip(__x.begin()), _Ip(__x.end())); + } +} + +template <class _Tp, class _Alloc> +inline +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(forward_list&& __x) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value) +{ + __move_assign(__x, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +template <class _Tp, class _Alloc> +inline +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il) +{ + assign(__il.begin(), __il.end()); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +template <class _InputIterator> +typename enable_if +< + __is_input_iterator<_InputIterator>::value, + void +>::type +forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l) +{ + iterator __i = before_begin(); + iterator __j = _VSTD::next(__i); + iterator __e = end(); + for (; __j != __e && __f != __l; ++__i, (void) ++__j, ++__f) + *__j = *__f; + if (__j == __e) + insert_after(__i, __f, __l); + else + erase_after(__i, __e); +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v) +{ + iterator __i = before_begin(); + iterator __j = _VSTD::next(__i); + iterator __e = end(); + for (; __j != __e && __n > 0; --__n, ++__i, ++__j) + *__j = __v; + if (__j == __e) + insert_after(__i, __n, __v); + else + erase_after(__i, __e); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +inline +void +forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il) +{ + assign(__il.begin(), __il.end()); +} + +template <class _Tp, class _Alloc> +template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename forward_list<_Tp, _Alloc>::reference +#else +void +#endif +forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) +{ + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), + _VSTD::forward<_Args>(__args)...); + __h->__next_ = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __h.release(); +#if _LIBCPP_STD_VER > 14 + return base::__before_begin()->__next_->__value_; +#endif +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::push_front(value_type&& __v) +{ + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v)); + __h->__next_ = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __h.release(); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::push_front(const value_type& __v) +{ + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __h->__next_ = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __h.release(); +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::pop_front() +{ + __node_allocator& __a = base::__alloc(); + __node_pointer __p = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __p->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__p->__value_)); + __node_traits::deallocate(__a, __p, 1); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +template <class... _Args> +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args) +{ + __begin_node_pointer const __r = __p.__get_begin(); + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), + _VSTD::forward<_Args>(__args)...); + __h->__next_ = __r->__next_; + __r->__next_ = __h.release(); + return iterator(__r->__next_); +} + +template <class _Tp, class _Alloc> +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) +{ + __begin_node_pointer const __r = __p.__get_begin(); + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v)); + __h->__next_ = __r->__next_; + __r->__next_ = __h.release(); + return iterator(__r->__next_); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v) +{ + __begin_node_pointer const __r = __p.__get_begin(); + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __h->__next_ = __r->__next_; + __r->__next_ = __h.release(); + return iterator(__r->__next_); +} + +template <class _Tp, class _Alloc> +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, + const value_type& __v) +{ + __begin_node_pointer __r = __p.__get_begin(); + if (__n > 0) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __node_pointer __first = __h.release(); + __node_pointer __last = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (--__n; __n != 0; --__n, __last = __last->__next_) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __last->__next_ = __h.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__first != nullptr) + { + __node_pointer __next = __first->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__first->__value_)); + __node_traits::deallocate(__a, __first, 1); + __first = __next; + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __last->__next_ = __r->__next_; + __r->__next_ = __first; + __r = static_cast<__begin_node_pointer>(__last); + } + return iterator(__r); +} + +template <class _Tp, class _Alloc> +template <class _InputIterator> +typename enable_if +< + __is_input_iterator<_InputIterator>::value, + typename forward_list<_Tp, _Alloc>::iterator +>::type +forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, + _InputIterator __f, _InputIterator __l) +{ + __begin_node_pointer __r = __p.__get_begin(); + if (__f != __l) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f); + __node_pointer __first = __h.release(); + __node_pointer __last = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_))) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f); + __last->__next_ = __h.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__first != nullptr) + { + __node_pointer __next = __first->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__first->__value_)); + __node_traits::deallocate(__a, __first, 1); + __first = __next; + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __last->__next_ = __r->__next_; + __r->__next_ = __first; + __r = static_cast<__begin_node_pointer>(__last); + } + return iterator(__r); +} + +template <class _Tp, class _Alloc> +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::erase_after(const_iterator __f) +{ + __begin_node_pointer __p = __f.__get_begin(); + __node_pointer __n = __p->__next_; + __p->__next_ = __n->__next_; + __node_allocator& __a = base::__alloc(); + __node_traits::destroy(__a, _VSTD::addressof(__n->__value_)); + __node_traits::deallocate(__a, __n, 1); + return iterator(__p->__next_); +} + +template <class _Tp, class _Alloc> +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l) +{ + __node_pointer __e = __l.__get_unsafe_node_pointer(); + if (__f != __l) + { + __begin_node_pointer __bp = __f.__get_begin(); + + __node_pointer __n = __bp->__next_; + if (__n != __e) + { + __bp->__next_ = __e; + __node_allocator& __a = base::__alloc(); + do + { + __node_pointer __tmp = __n->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__n->__value_)); + __node_traits::deallocate(__a, __n, 1); + __n = __tmp; + } while (__n != __e); + } + } + return iterator(__e); +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::resize(size_type __n) +{ + size_type __sz = 0; + iterator __p = before_begin(); + iterator __i = begin(); + iterator __e = end(); + for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz) + ; + if (__i != __e) + erase_after(__p, __e); + else + { + __n -= __sz; + if (__n > 0) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1)); + for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n, + __ptr = __ptr->__next_as_begin()) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); + __h->__next_ = nullptr; + __ptr->__next_ = __h.release(); + } + } + } +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v) +{ + size_type __sz = 0; + iterator __p = before_begin(); + iterator __i = begin(); + iterator __e = end(); + for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz) + ; + if (__i != __e) + erase_after(__p, __e); + else + { + __n -= __sz; + if (__n > 0) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _Dp; + unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1)); + for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n, + __ptr = __ptr->__next_as_begin()) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __h->__next_ = nullptr; + __ptr->__next_ = __h.release(); + } + } + } +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list& __x) +{ + if (!__x.empty()) + { + if (__p.__get_begin()->__next_ != nullptr) + { + const_iterator __lm1 = __x.before_begin(); + while (__lm1.__get_begin()->__next_ != nullptr) + ++__lm1; + __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_; + } + __p.__get_begin()->__next_ = __x.__before_begin()->__next_; + __x.__before_begin()->__next_ = nullptr; + } +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list& /*__other*/, + const_iterator __i) +{ + const_iterator __lm1 = _VSTD::next(__i); + if (__p != __i && __p != __lm1) + { + __i.__get_begin()->__next_ = __lm1.__get_begin()->__next_; + __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_; + __p.__get_begin()->__next_ = __lm1.__get_unsafe_node_pointer(); + } +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list& /*__other*/, + const_iterator __f, const_iterator __l) +{ + if (__f != __l && __p != __f) + { + const_iterator __lm1 = __f; + while (__lm1.__get_begin()->__next_ != __l.__get_begin()) + ++__lm1; + if (__f != __lm1) + { + __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_; + __p.__get_begin()->__next_ = __f.__get_begin()->__next_; + __f.__get_begin()->__next_ = __l.__get_unsafe_node_pointer(); + } + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list&& __x) +{ + splice_after(__p, __x); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list&& __x, + const_iterator __i) +{ + splice_after(__p, __x, __i); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list&& __x, + const_iterator __f, const_iterator __l) +{ + splice_after(__p, __x, __f, __l); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::remove(const value_type& __v) +{ + forward_list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing + iterator __e = end(); + for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;) + { + if (__i.__get_begin()->__next_->__value_ == __v) + { + iterator __j = _VSTD::next(__i, 2); + for (; __j != __e && *__j == __v; ++__j) + ; + __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j); + if (__j == __e) + break; + __i = __j; + } + else + ++__i; + } +} + +template <class _Tp, class _Alloc> +template <class _Predicate> +void +forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred) +{ + iterator __e = end(); + for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;) + { + if (__pred(__i.__get_begin()->__next_->__value_)) + { + iterator __j = _VSTD::next(__i, 2); + for (; __j != __e && __pred(*__j); ++__j) + ; + erase_after(__i, __j); + if (__j == __e) + break; + __i = __j; + } + else + ++__i; + } +} + +template <class _Tp, class _Alloc> +template <class _BinaryPredicate> +void +forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred) +{ + for (iterator __i = begin(), __e = end(); __i != __e;) + { + iterator __j = _VSTD::next(__i); + for (; __j != __e && __binary_pred(*__i, *__j); ++__j) + ; + if (__i.__get_begin()->__next_ != __j.__get_unsafe_node_pointer()) + erase_after(__i, __j); + __i = __j; + } +} + +template <class _Tp, class _Alloc> +template <class _Compare> +void +forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp) +{ + if (this != &__x) + { + base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_, + __x.__before_begin()->__next_, + __comp); + __x.__before_begin()->__next_ = nullptr; + } +} + +template <class _Tp, class _Alloc> +template <class _Compare> +typename forward_list<_Tp, _Alloc>::__node_pointer +forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2, + _Compare& __comp) +{ + if (__f1 == nullptr) + return __f2; + if (__f2 == nullptr) + return __f1; + __node_pointer __r; + if (__comp(__f2->__value_, __f1->__value_)) + { + __node_pointer __t = __f2; + while (__t->__next_ != nullptr && + __comp(__t->__next_->__value_, __f1->__value_)) + __t = __t->__next_; + __r = __f2; + __f2 = __t->__next_; + __t->__next_ = __f1; + } + else + __r = __f1; + __node_pointer __p = __f1; + __f1 = __f1->__next_; + while (__f1 != nullptr && __f2 != nullptr) + { + if (__comp(__f2->__value_, __f1->__value_)) + { + __node_pointer __t = __f2; + while (__t->__next_ != nullptr && + __comp(__t->__next_->__value_, __f1->__value_)) + __t = __t->__next_; + __p->__next_ = __f2; + __f2 = __t->__next_; + __t->__next_ = __f1; + } + __p = __f1; + __f1 = __f1->__next_; + } + if (__f2 != nullptr) + __p->__next_ = __f2; + return __r; +} + +template <class _Tp, class _Alloc> +template <class _Compare> +inline +void +forward_list<_Tp, _Alloc>::sort(_Compare __comp) +{ + base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_, + _VSTD::distance(begin(), end()), __comp); +} + +template <class _Tp, class _Alloc> +template <class _Compare> +typename forward_list<_Tp, _Alloc>::__node_pointer +forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz, + _Compare& __comp) +{ + switch (__sz) + { + case 0: + case 1: + return __f1; + case 2: + if (__comp(__f1->__next_->__value_, __f1->__value_)) + { + __node_pointer __t = __f1->__next_; + __t->__next_ = __f1; + __f1->__next_ = nullptr; + __f1 = __t; + } + return __f1; + } + difference_type __sz1 = __sz / 2; + difference_type __sz2 = __sz - __sz1; + __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__get_unsafe_node_pointer(); + __node_pointer __f2 = __t->__next_; + __t->__next_ = nullptr; + return __merge(__sort(__f1, __sz1, __comp), + __sort(__f2, __sz2, __comp), __comp); +} + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT +{ + __node_pointer __p = base::__before_begin()->__next_; + if (__p != nullptr) + { + __node_pointer __f = __p->__next_; + __p->__next_ = nullptr; + while (__f != nullptr) + { + __node_pointer __t = __f->__next_; + __f->__next_ = __p; + __p = __f; + __f = __t; + } + base::__before_begin()->__next_ = __p; + } +} + +template <class _Tp, class _Alloc> +bool operator==(const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + typedef forward_list<_Tp, _Alloc> _Cp; + typedef typename _Cp::const_iterator _Ip; + _Ip __ix = __x.begin(); + _Ip __ex = __x.end(); + _Ip __iy = __y.begin(); + _Ip __ey = __y.end(); + for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy) + if (!(*__ix == *__iy)) + return false; + return (__ix == __ex) == (__iy == __ey); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool operator< (const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), + __y.begin(), __y.end()); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool operator> (const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool operator>=(const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return !(__x < __y); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool operator<=(const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Tp, class _Allocator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred) +{ __c.remove_if(__pred); } + +template <class _Tp, class _Allocator, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +void erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v) +{ _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; }); } +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_FORWARD_LIST diff --git a/android/x86/include/v8/libc++/fstream b/android/x86/include/v8/libc++/fstream new file mode 100755 index 00000000..60a05b0d --- /dev/null +++ b/android/x86/include/v8/libc++/fstream @@ -0,0 +1,1764 @@ +// -*- C++ -*- +//===------------------------- fstream ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FSTREAM +#define _LIBCPP_FSTREAM + +/* + fstream synopsis + +template <class charT, class traits = char_traits<charT> > +class basic_filebuf + : public basic_streambuf<charT, traits> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // 27.9.1.2 Constructors/destructor: + basic_filebuf(); + basic_filebuf(basic_filebuf&& rhs); + virtual ~basic_filebuf(); + + // 27.9.1.3 Assign/swap: + basic_filebuf& operator=(basic_filebuf&& rhs); + void swap(basic_filebuf& rhs); + + // 27.9.1.4 Members: + bool is_open() const; + basic_filebuf* open(const char* s, ios_base::openmode mode); + basic_filebuf* open(const string& s, ios_base::openmode mode); + basic_filebuf* open(const filesystem::path& p, ios_base::openmode mode); // C++17 + basic_filebuf* close(); + +protected: + // 27.9.1.5 Overridden virtual functions: + virtual streamsize showmanyc(); + virtual int_type underflow(); + virtual int_type uflow(); + virtual int_type pbackfail(int_type c = traits_type::eof()); + virtual int_type overflow (int_type c = traits_type::eof()); + virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* s, streamsize n); + virtual pos_type seekoff(off_type off, ios_base::seekdir way, + ios_base::openmode which = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type sp, + ios_base::openmode which = ios_base::in | ios_base::out); + virtual int sync(); + virtual void imbue(const locale& loc); +}; + +template <class charT, class traits> + void + swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y); + +typedef basic_filebuf<char> filebuf; +typedef basic_filebuf<wchar_t> wfilebuf; + +template <class charT, class traits = char_traits<charT> > +class basic_ifstream + : public basic_istream<charT,traits> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + basic_ifstream(); + explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in); + explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in); + explicit basic_ifstream(const filesystem::path& p, + ios_base::openmode mode = ios_base::in); // C++17 + basic_ifstream(basic_ifstream&& rhs); + + basic_ifstream& operator=(basic_ifstream&& rhs); + void swap(basic_ifstream& rhs); + + basic_filebuf<char_type, traits_type>* rdbuf() const; + bool is_open() const; + void open(const char* s, ios_base::openmode mode = ios_base::in); + void open(const string& s, ios_base::openmode mode = ios_base::in); + void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in); // C++17 + + void close(); +}; + +template <class charT, class traits> + void + swap(basic_ifstream<charT, traits>& x, basic_ifstream<charT, traits>& y); + +typedef basic_ifstream<char> ifstream; +typedef basic_ifstream<wchar_t> wifstream; + +template <class charT, class traits = char_traits<charT> > +class basic_ofstream + : public basic_ostream<charT,traits> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + basic_ofstream(); + explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out); + explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out); + explicit basic_ofstream(const filesystem::path& p, + ios_base::openmode mode = ios_base::out); // C++17 + basic_ofstream(basic_ofstream&& rhs); + + basic_ofstream& operator=(basic_ofstream&& rhs); + void swap(basic_ofstream& rhs); + + basic_filebuf<char_type, traits_type>* rdbuf() const; + bool is_open() const; + void open(const char* s, ios_base::openmode mode = ios_base::out); + void open(const string& s, ios_base::openmode mode = ios_base::out); + void open(const filesystem::path& p, + ios_base::openmode mode = ios_base::out); // C++17 + + void close(); +}; + +template <class charT, class traits> + void + swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y); + +typedef basic_ofstream<char> ofstream; +typedef basic_ofstream<wchar_t> wofstream; + +template <class charT, class traits=char_traits<charT> > +class basic_fstream + : public basic_iostream<charT,traits> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + basic_fstream(); + explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); + explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); + explicit basic_fstream(const filesystem::path& p, + ios_base::openmode mode = ios_base::in|ios_base::out); C++17 + basic_fstream(basic_fstream&& rhs); + + basic_fstream& operator=(basic_fstream&& rhs); + void swap(basic_fstream& rhs); + + basic_filebuf<char_type, traits_type>* rdbuf() const; + bool is_open() const; + void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); + void open(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); + void open(const filesystem::path& s, + ios_base::openmode mode = ios_base::in|ios_base::out); // C++17 + + void close(); +}; + +template <class charT, class traits> + void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y); + +typedef basic_fstream<char> fstream; +typedef basic_fstream<wchar_t> wfstream; + +} // std + +*/ + +#include <__config> +#include <ostream> +#include <istream> +#include <__locale> +#include <cstdio> +#include <cstdlib> +#include <filesystem> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_filebuf + : public basic_streambuf<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef typename traits_type::state_type state_type; + + // 27.9.1.2 Constructors/destructor: + basic_filebuf(); +#ifndef _LIBCPP_CXX03_LANG + basic_filebuf(basic_filebuf&& __rhs); +#endif + virtual ~basic_filebuf(); + + // 27.9.1.3 Assign/swap: +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_filebuf& operator=(basic_filebuf&& __rhs); +#endif + void swap(basic_filebuf& __rhs); + + // 27.9.1.4 Members: + _LIBCPP_INLINE_VISIBILITY + bool is_open() const; +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE + basic_filebuf* open(const char* __s, ios_base::openmode __mode); +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR + basic_filebuf* open(const wchar_t* __s, ios_base::openmode __mode); +#endif + _LIBCPP_INLINE_VISIBILITY + basic_filebuf* open(const string& __s, ios_base::openmode __mode); + +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY + basic_filebuf* open(const _VSTD_FS::path& __p, ios_base::openmode __mode) { + return open(__p.c_str(), __mode); + } +#endif + _LIBCPP_INLINE_VISIBILITY + basic_filebuf* __open(int __fd, ios_base::openmode __mode); +#endif + basic_filebuf* close(); + + _LIBCPP_INLINE_VISIBILITY + inline static const char* + __make_mdstring(ios_base::openmode __mode) _NOEXCEPT; + + protected: + // 27.9.1.5 Overridden virtual functions: + virtual int_type underflow(); + virtual int_type pbackfail(int_type __c = traits_type::eof()); + virtual int_type overflow (int_type __c = traits_type::eof()); + virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n); + virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __wch = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type __sp, + ios_base::openmode __wch = ios_base::in | ios_base::out); + virtual int sync(); + virtual void imbue(const locale& __loc); + +private: + char* __extbuf_; + const char* __extbufnext_; + const char* __extbufend_; + char __extbuf_min_[8]; + size_t __ebs_; + char_type* __intbuf_; + size_t __ibs_; + FILE* __file_; + const codecvt<char_type, char, state_type>* __cv_; + state_type __st_; + state_type __st_last_; + ios_base::openmode __om_; + ios_base::openmode __cm_; + bool __owns_eb_; + bool __owns_ib_; + bool __always_noconv_; + + bool __read_mode(); + void __write_mode(); +}; + +template <class _CharT, class _Traits> +basic_filebuf<_CharT, _Traits>::basic_filebuf() + : __extbuf_(0), + __extbufnext_(0), + __extbufend_(0), + __ebs_(0), + __intbuf_(0), + __ibs_(0), + __file_(0), + __cv_(nullptr), + __st_(), + __st_last_(), + __om_(0), + __cm_(0), + __owns_eb_(false), + __owns_ib_(false), + __always_noconv_(false) +{ + if (has_facet<codecvt<char_type, char, state_type> >(this->getloc())) + { + __cv_ = &use_facet<codecvt<char_type, char, state_type> >(this->getloc()); + __always_noconv_ = __cv_->always_noconv(); + } + setbuf(0, 4096); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) + : basic_streambuf<_CharT, _Traits>(__rhs) +{ + if (__rhs.__extbuf_ == __rhs.__extbuf_min_) + { + __extbuf_ = __extbuf_min_; + __extbufnext_ = __extbuf_ + (__rhs.__extbufnext_ - __rhs.__extbuf_); + __extbufend_ = __extbuf_ + (__rhs.__extbufend_ - __rhs.__extbuf_); + } + else + { + __extbuf_ = __rhs.__extbuf_; + __extbufnext_ = __rhs.__extbufnext_; + __extbufend_ = __rhs.__extbufend_; + } + __ebs_ = __rhs.__ebs_; + __intbuf_ = __rhs.__intbuf_; + __ibs_ = __rhs.__ibs_; + __file_ = __rhs.__file_; + __cv_ = __rhs.__cv_; + __st_ = __rhs.__st_; + __st_last_ = __rhs.__st_last_; + __om_ = __rhs.__om_; + __cm_ = __rhs.__cm_; + __owns_eb_ = __rhs.__owns_eb_; + __owns_ib_ = __rhs.__owns_ib_; + __always_noconv_ = __rhs.__always_noconv_; + if (__rhs.pbase()) + { + if (__rhs.pbase() == __rhs.__intbuf_) + this->setp(__intbuf_, __intbuf_ + (__rhs. epptr() - __rhs.pbase())); + else + this->setp((char_type*)__extbuf_, + (char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase())); + this->__pbump(__rhs. pptr() - __rhs.pbase()); + } + else if (__rhs.eback()) + { + if (__rhs.eback() == __rhs.__intbuf_) + this->setg(__intbuf_, __intbuf_ + (__rhs.gptr() - __rhs.eback()), + __intbuf_ + (__rhs.egptr() - __rhs.eback())); + else + this->setg((char_type*)__extbuf_, + (char_type*)__extbuf_ + (__rhs.gptr() - __rhs.eback()), + (char_type*)__extbuf_ + (__rhs.egptr() - __rhs.eback())); + } + __rhs.__extbuf_ = 0; + __rhs.__extbufnext_ = 0; + __rhs.__extbufend_ = 0; + __rhs.__ebs_ = 0; + __rhs.__intbuf_ = 0; + __rhs.__ibs_ = 0; + __rhs.__file_ = 0; + __rhs.__st_ = state_type(); + __rhs.__st_last_ = state_type(); + __rhs.__om_ = 0; + __rhs.__cm_ = 0; + __rhs.__owns_eb_ = false; + __rhs.__owns_ib_ = false; + __rhs.setg(0, 0, 0); + __rhs.setp(0, 0); +} + +template <class _CharT, class _Traits> +inline +basic_filebuf<_CharT, _Traits>& +basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs) +{ + close(); + swap(__rhs); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +basic_filebuf<_CharT, _Traits>::~basic_filebuf() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + close(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__owns_eb_) + delete [] __extbuf_; + if (__owns_ib_) + delete [] __intbuf_; +} + +template <class _CharT, class _Traits> +void +basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) +{ + basic_streambuf<char_type, traits_type>::swap(__rhs); + if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) + { + _VSTD::swap(__extbuf_, __rhs.__extbuf_); + _VSTD::swap(__extbufnext_, __rhs.__extbufnext_); + _VSTD::swap(__extbufend_, __rhs.__extbufend_); + } + else + { + ptrdiff_t __ln = __extbufnext_ - __extbuf_; + ptrdiff_t __le = __extbufend_ - __extbuf_; + ptrdiff_t __rn = __rhs.__extbufnext_ - __rhs.__extbuf_; + ptrdiff_t __re = __rhs.__extbufend_ - __rhs.__extbuf_; + if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) + { + __extbuf_ = __rhs.__extbuf_; + __rhs.__extbuf_ = __rhs.__extbuf_min_; + } + else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_) + { + __rhs.__extbuf_ = __extbuf_; + __extbuf_ = __extbuf_min_; + } + __extbufnext_ = __extbuf_ + __rn; + __extbufend_ = __extbuf_ + __re; + __rhs.__extbufnext_ = __rhs.__extbuf_ + __ln; + __rhs.__extbufend_ = __rhs.__extbuf_ + __le; + } + _VSTD::swap(__ebs_, __rhs.__ebs_); + _VSTD::swap(__intbuf_, __rhs.__intbuf_); + _VSTD::swap(__ibs_, __rhs.__ibs_); + _VSTD::swap(__file_, __rhs.__file_); + _VSTD::swap(__cv_, __rhs.__cv_); + _VSTD::swap(__st_, __rhs.__st_); + _VSTD::swap(__st_last_, __rhs.__st_last_); + _VSTD::swap(__om_, __rhs.__om_); + _VSTD::swap(__cm_, __rhs.__cm_); + _VSTD::swap(__owns_eb_, __rhs.__owns_eb_); + _VSTD::swap(__owns_ib_, __rhs.__owns_ib_); + _VSTD::swap(__always_noconv_, __rhs.__always_noconv_); + if (this->eback() == (char_type*)__rhs.__extbuf_min_) + { + ptrdiff_t __n = this->gptr() - this->eback(); + ptrdiff_t __e = this->egptr() - this->eback(); + this->setg((char_type*)__extbuf_min_, + (char_type*)__extbuf_min_ + __n, + (char_type*)__extbuf_min_ + __e); + } + else if (this->pbase() == (char_type*)__rhs.__extbuf_min_) + { + ptrdiff_t __n = this->pptr() - this->pbase(); + ptrdiff_t __e = this->epptr() - this->pbase(); + this->setp((char_type*)__extbuf_min_, + (char_type*)__extbuf_min_ + __e); + this->__pbump(__n); + } + if (__rhs.eback() == (char_type*)__extbuf_min_) + { + ptrdiff_t __n = __rhs.gptr() - __rhs.eback(); + ptrdiff_t __e = __rhs.egptr() - __rhs.eback(); + __rhs.setg((char_type*)__rhs.__extbuf_min_, + (char_type*)__rhs.__extbuf_min_ + __n, + (char_type*)__rhs.__extbuf_min_ + __e); + } + else if (__rhs.pbase() == (char_type*)__extbuf_min_) + { + ptrdiff_t __n = __rhs.pptr() - __rhs.pbase(); + ptrdiff_t __e = __rhs.epptr() - __rhs.pbase(); + __rhs.setp((char_type*)__rhs.__extbuf_min_, + (char_type*)__rhs.__extbuf_min_ + __e); + __rhs.__pbump(__n); + } +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y) +{ + __x.swap(__y); +} + +template <class _CharT, class _Traits> +inline +bool +basic_filebuf<_CharT, _Traits>::is_open() const +{ + return __file_ != 0; +} + +template <class _CharT, class _Traits> +const char* basic_filebuf<_CharT, _Traits>::__make_mdstring( + ios_base::openmode __mode) _NOEXCEPT { + switch (__mode & ~ios_base::ate) { + case ios_base::out: + case ios_base::out | ios_base::trunc: + return "w"; + case ios_base::out | ios_base::app: + case ios_base::app: + return "a"; + case ios_base::in: + return "r"; + case ios_base::in | ios_base::out: + return "r+"; + case ios_base::in | ios_base::out | ios_base::trunc: + return "w+"; + case ios_base::in | ios_base::out | ios_base::app: + case ios_base::in | ios_base::app: + return "a+"; + case ios_base::out | ios_base::binary: + case ios_base::out | ios_base::trunc | ios_base::binary: + return "wb"; + case ios_base::out | ios_base::app | ios_base::binary: + case ios_base::app | ios_base::binary: + return "ab"; + case ios_base::in | ios_base::binary: + return "rb"; + case ios_base::in | ios_base::out | ios_base::binary: + return "r+b"; + case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary: + return "w+b"; + case ios_base::in | ios_base::out | ios_base::app | ios_base::binary: + case ios_base::in | ios_base::app | ios_base::binary: + return "a+b"; + default: + return nullptr; + } + _LIBCPP_UNREACHABLE(); +} + +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +template <class _CharT, class _Traits> +basic_filebuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) +{ + basic_filebuf<_CharT, _Traits>* __rt = 0; + if (__file_ == 0) + { + if (const char* __mdstr = __make_mdstring(__mode)) { + __rt = this; + __file_ = fopen(__s, __mdstr); + if (__file_) { + __om_ = __mode; + if (__mode & ios_base::ate) { + if (fseek(__file_, 0, SEEK_END)) { + fclose(__file_); + __file_ = 0; + __rt = 0; + } + } + } else + __rt = 0; + } + } + return __rt; +} + +template <class _CharT, class _Traits> +_LIBCPP_INLINE_VISIBILITY basic_filebuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) { + basic_filebuf<_CharT, _Traits>* __rt = 0; + if (__file_ == 0) { + if (const char* __mdstr = __make_mdstring(__mode)) { + __rt = this; + __file_ = fdopen(__fd, __mdstr); + if (__file_) { + __om_ = __mode; + if (__mode & ios_base::ate) { + if (fseek(__file_, 0, SEEK_END)) { + fclose(__file_); + __file_ = 0; + __rt = 0; + } + } + } else + __rt = 0; + } + } + return __rt; +} + +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR +// This is basically the same as the char* overload except that it uses _wfopen +// and long mode strings. +template <class _CharT, class _Traits> +basic_filebuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) +{ + basic_filebuf<_CharT, _Traits>* __rt = 0; + if (__file_ == 0) + { + __rt = this; + const wchar_t* __mdstr; + switch (__mode & ~ios_base::ate) + { + case ios_base::out: + case ios_base::out | ios_base::trunc: + __mdstr = L"w"; + break; + case ios_base::out | ios_base::app: + case ios_base::app: + __mdstr = L"a"; + break; + case ios_base::in: + __mdstr = L"r"; + break; + case ios_base::in | ios_base::out: + __mdstr = L"r+"; + break; + case ios_base::in | ios_base::out | ios_base::trunc: + __mdstr = L"w+"; + break; + case ios_base::in | ios_base::out | ios_base::app: + case ios_base::in | ios_base::app: + __mdstr = L"a+"; + break; + case ios_base::out | ios_base::binary: + case ios_base::out | ios_base::trunc | ios_base::binary: + __mdstr = L"wb"; + break; + case ios_base::out | ios_base::app | ios_base::binary: + case ios_base::app | ios_base::binary: + __mdstr = L"ab"; + break; + case ios_base::in | ios_base::binary: + __mdstr = L"rb"; + break; + case ios_base::in | ios_base::out | ios_base::binary: + __mdstr = L"r+b"; + break; + case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary: + __mdstr = L"w+b"; + break; + case ios_base::in | ios_base::out | ios_base::app | ios_base::binary: + case ios_base::in | ios_base::app | ios_base::binary: + __mdstr = L"a+b"; + break; + default: + __rt = 0; + break; + } + if (__rt) + { + __file_ = _wfopen(__s, __mdstr); + if (__file_) + { + __om_ = __mode; + if (__mode & ios_base::ate) + { + if (fseek(__file_, 0, SEEK_END)) + { + fclose(__file_); + __file_ = 0; + __rt = 0; + } + } + } + else + __rt = 0; + } + } + return __rt; +} +#endif + +template <class _CharT, class _Traits> +inline +basic_filebuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) +{ + return open(__s.c_str(), __mode); +} +#endif + +template <class _CharT, class _Traits> +basic_filebuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::close() +{ + basic_filebuf<_CharT, _Traits>* __rt = 0; + if (__file_) + { + __rt = this; + unique_ptr<FILE, int(*)(FILE*)> __h(__file_, fclose); + if (sync()) + __rt = 0; + if (fclose(__h.release()) == 0) + __file_ = 0; + else + __rt = 0; + setbuf(0, 0); + } + return __rt; +} + +template <class _CharT, class _Traits> +typename basic_filebuf<_CharT, _Traits>::int_type +basic_filebuf<_CharT, _Traits>::underflow() +{ + if (__file_ == 0) + return traits_type::eof(); + bool __initial = __read_mode(); + char_type __1buf; + if (this->gptr() == 0) + this->setg(&__1buf, &__1buf+1, &__1buf+1); + const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4); + int_type __c = traits_type::eof(); + if (this->gptr() == this->egptr()) + { + memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); + if (__always_noconv_) + { + size_t __nmemb = static_cast<size_t>(this->egptr() - this->eback() - __unget_sz); + __nmemb = fread(this->eback() + __unget_sz, 1, __nmemb, __file_); + if (__nmemb != 0) + { + this->setg(this->eback(), + this->eback() + __unget_sz, + this->eback() + __unget_sz + __nmemb); + __c = traits_type::to_int_type(*this->gptr()); + } + } + else + { + _LIBCPP_ASSERT ( !(__extbufnext_ == NULL && (__extbufend_ != __extbufnext_)), "underflow moving from NULL" ); + if (__extbufend_ != __extbufnext_) + memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); + __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); + __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); + size_t __nmemb = _VSTD::min(static_cast<size_t>(__ibs_ - __unget_sz), + static_cast<size_t>(__extbufend_ - __extbufnext_)); + codecvt_base::result __r; + __st_last_ = __st_; + size_t __nr = fread((void*) const_cast<char *>(__extbufnext_), 1, __nmemb, __file_); + if (__nr != 0) + { + if (!__cv_) + __throw_bad_cast(); + + __extbufend_ = __extbufnext_ + __nr; + char_type* __inext; + __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, + this->eback() + __unget_sz, + this->eback() + __ibs_, __inext); + if (__r == codecvt_base::noconv) + { + this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, + (char_type*)const_cast<char *>(__extbufend_)); + __c = traits_type::to_int_type(*this->gptr()); + } + else if (__inext != this->eback() + __unget_sz) + { + this->setg(this->eback(), this->eback() + __unget_sz, __inext); + __c = traits_type::to_int_type(*this->gptr()); + } + } + } + } + else + __c = traits_type::to_int_type(*this->gptr()); + if (this->eback() == &__1buf) + this->setg(0, 0, 0); + return __c; +} + +template <class _CharT, class _Traits> +typename basic_filebuf<_CharT, _Traits>::int_type +basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c) +{ + if (__file_ && this->eback() < this->gptr()) + { + if (traits_type::eq_int_type(__c, traits_type::eof())) + { + this->gbump(-1); + return traits_type::not_eof(__c); + } + if ((__om_ & ios_base::out) || + traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) + { + this->gbump(-1); + *this->gptr() = traits_type::to_char_type(__c); + return __c; + } + } + return traits_type::eof(); +} + +template <class _CharT, class _Traits> +typename basic_filebuf<_CharT, _Traits>::int_type +basic_filebuf<_CharT, _Traits>::overflow(int_type __c) +{ + if (__file_ == 0) + return traits_type::eof(); + __write_mode(); + char_type __1buf; + char_type* __pb_save = this->pbase(); + char_type* __epb_save = this->epptr(); + if (!traits_type::eq_int_type(__c, traits_type::eof())) + { + if (this->pptr() == 0) + this->setp(&__1buf, &__1buf+1); + *this->pptr() = traits_type::to_char_type(__c); + this->pbump(1); + } + if (this->pptr() != this->pbase()) + { + if (__always_noconv_) + { + size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); + if (fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb) + return traits_type::eof(); + } + else + { + char* __extbe = __extbuf_; + codecvt_base::result __r; + do + { + if (!__cv_) + __throw_bad_cast(); + + const char_type* __e; + __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, + __extbuf_, __extbuf_ + __ebs_, __extbe); + if (__e == this->pbase()) + return traits_type::eof(); + if (__r == codecvt_base::noconv) + { + size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); + if (fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb) + return traits_type::eof(); + } + else if (__r == codecvt_base::ok || __r == codecvt_base::partial) + { + size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_); + if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) + return traits_type::eof(); + if (__r == codecvt_base::partial) + { + this->setp(const_cast<char_type*>(__e), this->pptr()); + this->__pbump(this->epptr() - this->pbase()); + } + } + else + return traits_type::eof(); + } while (__r == codecvt_base::partial); + } + this->setp(__pb_save, __epb_save); + } + return traits_type::not_eof(__c); +} + +template <class _CharT, class _Traits> +basic_streambuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n) +{ + this->setg(0, 0, 0); + this->setp(0, 0); + if (__owns_eb_) + delete [] __extbuf_; + if (__owns_ib_) + delete [] __intbuf_; + __ebs_ = __n; + if (__ebs_ > sizeof(__extbuf_min_)) + { + if (__always_noconv_ && __s) + { + __extbuf_ = (char*)__s; + __owns_eb_ = false; + } + else + { + __extbuf_ = new char[__ebs_]; + __owns_eb_ = true; + } + } + else + { + __extbuf_ = __extbuf_min_; + __ebs_ = sizeof(__extbuf_min_); + __owns_eb_ = false; + } + if (!__always_noconv_) + { + __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_)); + if (__s && __ibs_ >= sizeof(__extbuf_min_)) + { + __intbuf_ = __s; + __owns_ib_ = false; + } + else + { + __intbuf_ = new char_type[__ibs_]; + __owns_ib_ = true; + } + } + else + { + __ibs_ = 0; + __intbuf_ = 0; + __owns_ib_ = false; + } + return this; +} + +template <class _CharT, class _Traits> +typename basic_filebuf<_CharT, _Traits>::pos_type +basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode) +{ + if (!__cv_) + __throw_bad_cast(); + + int __width = __cv_->encoding(); + if (__file_ == 0 || (__width <= 0 && __off != 0) || sync()) + return pos_type(off_type(-1)); + // __width > 0 || __off == 0 + int __whence; + switch (__way) + { + case ios_base::beg: + __whence = SEEK_SET; + break; + case ios_base::cur: + __whence = SEEK_CUR; + break; + case ios_base::end: + __whence = SEEK_END; + break; + default: + return pos_type(off_type(-1)); + } +#if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) + if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence)) + return pos_type(off_type(-1)); + pos_type __r = ftell(__file_); +#else + if (fseeko(__file_, __width > 0 ? __width * __off : 0, __whence)) + return pos_type(off_type(-1)); + pos_type __r = ftello(__file_); +#endif + __r.state(__st_); + return __r; +} + +template <class _CharT, class _Traits> +typename basic_filebuf<_CharT, _Traits>::pos_type +basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) +{ + if (__file_ == 0 || sync()) + return pos_type(off_type(-1)); +#if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) + if (fseek(__file_, __sp, SEEK_SET)) + return pos_type(off_type(-1)); +#else + if (fseeko(__file_, __sp, SEEK_SET)) + return pos_type(off_type(-1)); +#endif + __st_ = __sp.state(); + return __sp; +} + +template <class _CharT, class _Traits> +int +basic_filebuf<_CharT, _Traits>::sync() +{ + if (__file_ == 0) + return 0; + if (!__cv_) + __throw_bad_cast(); + + if (__cm_ & ios_base::out) + { + if (this->pptr() != this->pbase()) + if (overflow() == traits_type::eof()) + return -1; + codecvt_base::result __r; + do + { + char* __extbe; + __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); + size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_); + if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) + return -1; + } while (__r == codecvt_base::partial); + if (__r == codecvt_base::error) + return -1; + if (fflush(__file_)) + return -1; + } + else if (__cm_ & ios_base::in) + { + off_type __c; + state_type __state = __st_last_; + bool __update_st = false; + if (__always_noconv_) + __c = this->egptr() - this->gptr(); + else + { + int __width = __cv_->encoding(); + __c = __extbufend_ - __extbufnext_; + if (__width > 0) + __c += __width * (this->egptr() - this->gptr()); + else + { + if (this->gptr() != this->egptr()) + { + const int __off = __cv_->length(__state, __extbuf_, + __extbufnext_, + this->gptr() - this->eback()); + __c += __extbufnext_ - __extbuf_ - __off; + __update_st = true; + } + } + } +#if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) + if (fseek(__file_, -__c, SEEK_CUR)) + return -1; +#else + if (fseeko(__file_, -__c, SEEK_CUR)) + return -1; +#endif + if (__update_st) + __st_ = __state; + __extbufnext_ = __extbufend_ = __extbuf_; + this->setg(0, 0, 0); + __cm_ = 0; + } + return 0; +} + +template <class _CharT, class _Traits> +void +basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc) +{ + sync(); + __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc); + bool __old_anc = __always_noconv_; + __always_noconv_ = __cv_->always_noconv(); + if (__old_anc != __always_noconv_) + { + this->setg(0, 0, 0); + this->setp(0, 0); + // invariant, char_type is char, else we couldn't get here + if (__always_noconv_) // need to dump __intbuf_ + { + if (__owns_eb_) + delete [] __extbuf_; + __owns_eb_ = __owns_ib_; + __ebs_ = __ibs_; + __extbuf_ = (char*)__intbuf_; + __ibs_ = 0; + __intbuf_ = 0; + __owns_ib_ = false; + } + else // need to obtain an __intbuf_. + { // If __extbuf_ is user-supplied, use it, else new __intbuf_ + if (!__owns_eb_ && __extbuf_ != __extbuf_min_) + { + __ibs_ = __ebs_; + __intbuf_ = (char_type*)__extbuf_; + __owns_ib_ = false; + __extbuf_ = new char[__ebs_]; + __owns_eb_ = true; + } + else + { + __ibs_ = __ebs_; + __intbuf_ = new char_type[__ibs_]; + __owns_ib_ = true; + } + } + } +} + +template <class _CharT, class _Traits> +bool +basic_filebuf<_CharT, _Traits>::__read_mode() +{ + if (!(__cm_ & ios_base::in)) + { + this->setp(0, 0); + if (__always_noconv_) + this->setg((char_type*)__extbuf_, + (char_type*)__extbuf_ + __ebs_, + (char_type*)__extbuf_ + __ebs_); + else + this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); + __cm_ = ios_base::in; + return true; + } + return false; +} + +template <class _CharT, class _Traits> +void +basic_filebuf<_CharT, _Traits>::__write_mode() +{ + if (!(__cm_ & ios_base::out)) + { + this->setg(0, 0, 0); + if (__ebs_ > sizeof(__extbuf_min_)) + { + if (__always_noconv_) + this->setp((char_type*)__extbuf_, + (char_type*)__extbuf_ + (__ebs_ - 1)); + else + this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); + } + else + this->setp(0, 0); + __cm_ = ios_base::out; + } +} + +// basic_ifstream + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_ifstream + : public basic_istream<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + _LIBCPP_INLINE_VISIBILITY + basic_ifstream(); +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE + _LIBCPP_INLINE_VISIBILITY + explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in); +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR + _LIBCPP_INLINE_VISIBILITY + explicit basic_ifstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::in); +#endif + _LIBCPP_INLINE_VISIBILITY + explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in); +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY + explicit basic_ifstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in) + : basic_ifstream(__p.c_str(), __mode) {} +#endif // _LIBCPP_STD_VER >= 17 +#endif +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_ifstream(basic_ifstream&& __rhs); + + _LIBCPP_INLINE_VISIBILITY + basic_ifstream& operator=(basic_ifstream&& __rhs); +#endif + _LIBCPP_INLINE_VISIBILITY + void swap(basic_ifstream& __rhs); + + _LIBCPP_INLINE_VISIBILITY + basic_filebuf<char_type, traits_type>* rdbuf() const; + _LIBCPP_INLINE_VISIBILITY + bool is_open() const; +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE + void open(const char* __s, ios_base::openmode __mode = ios_base::in); +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR + void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in); +#endif + void open(const string& __s, ios_base::openmode __mode = ios_base::in); +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY + void open(const filesystem::path& __p, + ios_base::openmode __mode = ios_base::in) { + return open(__p.c_str(), __mode); + } +#endif // _LIBCPP_STD_VER >= 17 + + _LIBCPP_INLINE_VISIBILITY + void __open(int __fd, ios_base::openmode __mode); +#endif + _LIBCPP_INLINE_VISIBILITY + void close(); + +private: + basic_filebuf<char_type, traits_type> __sb_; +}; + +template <class _CharT, class _Traits> +inline +basic_ifstream<_CharT, _Traits>::basic_ifstream() + : basic_istream<char_type, traits_type>(&__sb_) +{ +} + +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +template <class _CharT, class _Traits> +inline +basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode) + : basic_istream<char_type, traits_type>(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::in) == 0) + this->setstate(ios_base::failbit); +} + +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR +template <class _CharT, class _Traits> +inline +basic_ifstream<_CharT, _Traits>::basic_ifstream(const wchar_t* __s, ios_base::openmode __mode) + : basic_istream<char_type, traits_type>(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::in) == 0) + this->setstate(ios_base::failbit); +} +#endif + +template <class _CharT, class _Traits> +inline +basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode) + : basic_istream<char_type, traits_type>(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::in) == 0) + this->setstate(ios_base::failbit); +} +#endif + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +inline +basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs) + : basic_istream<char_type, traits_type>(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) +{ + this->set_rdbuf(&__sb_); +} + +template <class _CharT, class _Traits> +inline +basic_ifstream<_CharT, _Traits>& +basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs) +{ + basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +inline +void +basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs) +{ + basic_istream<char_type, traits_type>::swap(__rhs); + __sb_.swap(__rhs.__sb_); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y) +{ + __x.swap(__y); +} + +template <class _CharT, class _Traits> +inline +basic_filebuf<_CharT, _Traits>* +basic_ifstream<_CharT, _Traits>::rdbuf() const +{ + return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_); +} + +template <class _CharT, class _Traits> +inline +bool +basic_ifstream<_CharT, _Traits>::is_open() const +{ + return __sb_.is_open(); +} + +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +template <class _CharT, class _Traits> +void +basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::in)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR +template <class _CharT, class _Traits> +void +basic_ifstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::in)) + this->clear(); + else + this->setstate(ios_base::failbit); +} +#endif + +template <class _CharT, class _Traits> +void +basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::in)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +template <class _CharT, class _Traits> +void basic_ifstream<_CharT, _Traits>::__open(int __fd, + ios_base::openmode __mode) { + if (__sb_.__open(__fd, __mode | ios_base::in)) + this->clear(); + else + this->setstate(ios_base::failbit); +} +#endif + +template <class _CharT, class _Traits> +inline +void +basic_ifstream<_CharT, _Traits>::close() +{ + if (__sb_.close() == 0) + this->setstate(ios_base::failbit); +} + +// basic_ofstream + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_ofstream + : public basic_ostream<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + _LIBCPP_INLINE_VISIBILITY + basic_ofstream(); + _LIBCPP_INLINE_VISIBILITY + explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out); +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR + _LIBCPP_INLINE_VISIBILITY + explicit basic_ofstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::out); +#endif + _LIBCPP_INLINE_VISIBILITY + explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out); + +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY + explicit basic_ofstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out) + : basic_ofstream(__p.c_str(), __mode) {} +#endif // _LIBCPP_STD_VER >= 17 + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_ofstream(basic_ofstream&& __rhs); + + _LIBCPP_INLINE_VISIBILITY + basic_ofstream& operator=(basic_ofstream&& __rhs); +#endif + _LIBCPP_INLINE_VISIBILITY + void swap(basic_ofstream& __rhs); + + _LIBCPP_INLINE_VISIBILITY + basic_filebuf<char_type, traits_type>* rdbuf() const; + _LIBCPP_INLINE_VISIBILITY + bool is_open() const; +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE + void open(const char* __s, ios_base::openmode __mode = ios_base::out); +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR + void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::out); +#endif + void open(const string& __s, ios_base::openmode __mode = ios_base::out); + +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY + void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out) + { return open(__p.c_str(), __mode); } +#endif // _LIBCPP_STD_VER >= 17 + + _LIBCPP_INLINE_VISIBILITY + void __open(int __fd, ios_base::openmode __mode); +#endif + _LIBCPP_INLINE_VISIBILITY + void close(); + +private: + basic_filebuf<char_type, traits_type> __sb_; +}; + +template <class _CharT, class _Traits> +inline +basic_ofstream<_CharT, _Traits>::basic_ofstream() + : basic_ostream<char_type, traits_type>(&__sb_) +{ +} + +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +template <class _CharT, class _Traits> +inline +basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode) + : basic_ostream<char_type, traits_type>(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::out) == 0) + this->setstate(ios_base::failbit); +} + +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR +template <class _CharT, class _Traits> +inline +basic_ofstream<_CharT, _Traits>::basic_ofstream(const wchar_t* __s, ios_base::openmode __mode) + : basic_ostream<char_type, traits_type>(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::out) == 0) + this->setstate(ios_base::failbit); +} +#endif + +template <class _CharT, class _Traits> +inline +basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode) + : basic_ostream<char_type, traits_type>(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::out) == 0) + this->setstate(ios_base::failbit); +} +#endif + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +inline +basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs) + : basic_ostream<char_type, traits_type>(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) +{ + this->set_rdbuf(&__sb_); +} + +template <class _CharT, class _Traits> +inline +basic_ofstream<_CharT, _Traits>& +basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs) +{ + basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +inline +void +basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs) +{ + basic_ostream<char_type, traits_type>::swap(__rhs); + __sb_.swap(__rhs.__sb_); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y) +{ + __x.swap(__y); +} + +template <class _CharT, class _Traits> +inline +basic_filebuf<_CharT, _Traits>* +basic_ofstream<_CharT, _Traits>::rdbuf() const +{ + return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_); +} + +template <class _CharT, class _Traits> +inline +bool +basic_ofstream<_CharT, _Traits>::is_open() const +{ + return __sb_.is_open(); +} + +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +template <class _CharT, class _Traits> +void +basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::out)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR +template <class _CharT, class _Traits> +void +basic_ofstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::out)) + this->clear(); + else + this->setstate(ios_base::failbit); +} +#endif + +template <class _CharT, class _Traits> +void +basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::out)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +template <class _CharT, class _Traits> +void basic_ofstream<_CharT, _Traits>::__open(int __fd, + ios_base::openmode __mode) { + if (__sb_.__open(__fd, __mode | ios_base::out)) + this->clear(); + else + this->setstate(ios_base::failbit); +} +#endif + +template <class _CharT, class _Traits> +inline +void +basic_ofstream<_CharT, _Traits>::close() +{ + if (__sb_.close() == 0) + this->setstate(ios_base::failbit); +} + +// basic_fstream + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_fstream + : public basic_iostream<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + _LIBCPP_INLINE_VISIBILITY + basic_fstream(); +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE + _LIBCPP_INLINE_VISIBILITY + explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR + _LIBCPP_INLINE_VISIBILITY + explicit basic_fstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); +#endif + _LIBCPP_INLINE_VISIBILITY + explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); + +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY + explicit basic_fstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in | ios_base::out) + : basic_fstream(__p.c_str(), __mode) {} +#endif // _LIBCPP_STD_VER >= 17 + +#endif +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_fstream(basic_fstream&& __rhs); + + _LIBCPP_INLINE_VISIBILITY + basic_fstream& operator=(basic_fstream&& __rhs); +#endif + _LIBCPP_INLINE_VISIBILITY + void swap(basic_fstream& __rhs); + + _LIBCPP_INLINE_VISIBILITY + basic_filebuf<char_type, traits_type>* rdbuf() const; + _LIBCPP_INLINE_VISIBILITY + bool is_open() const; +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE + void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR + void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); +#endif + void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); + +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY + void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in|ios_base::out) + { return open(__p.c_str(), __mode); } +#endif // _LIBCPP_STD_VER >= 17 + +#endif + _LIBCPP_INLINE_VISIBILITY + void close(); + +private: + basic_filebuf<char_type, traits_type> __sb_; +}; + +template <class _CharT, class _Traits> +inline +basic_fstream<_CharT, _Traits>::basic_fstream() + : basic_iostream<char_type, traits_type>(&__sb_) +{ +} + +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +template <class _CharT, class _Traits> +inline +basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode) + : basic_iostream<char_type, traits_type>(&__sb_) +{ + if (__sb_.open(__s, __mode) == 0) + this->setstate(ios_base::failbit); +} + +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR +template <class _CharT, class _Traits> +inline +basic_fstream<_CharT, _Traits>::basic_fstream(const wchar_t* __s, ios_base::openmode __mode) + : basic_iostream<char_type, traits_type>(&__sb_) +{ + if (__sb_.open(__s, __mode) == 0) + this->setstate(ios_base::failbit); +} +#endif + +template <class _CharT, class _Traits> +inline +basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode) + : basic_iostream<char_type, traits_type>(&__sb_) +{ + if (__sb_.open(__s, __mode) == 0) + this->setstate(ios_base::failbit); +} +#endif + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +inline +basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs) + : basic_iostream<char_type, traits_type>(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) +{ + this->set_rdbuf(&__sb_); +} + +template <class _CharT, class _Traits> +inline +basic_fstream<_CharT, _Traits>& +basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs) +{ + basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +inline +void +basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs) +{ + basic_iostream<char_type, traits_type>::swap(__rhs); + __sb_.swap(__rhs.__sb_); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y) +{ + __x.swap(__y); +} + +template <class _CharT, class _Traits> +inline +basic_filebuf<_CharT, _Traits>* +basic_fstream<_CharT, _Traits>::rdbuf() const +{ + return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_); +} + +template <class _CharT, class _Traits> +inline +bool +basic_fstream<_CharT, _Traits>::is_open() const +{ + return __sb_.is_open(); +} + +#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +template <class _CharT, class _Traits> +void +basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR +template <class _CharT, class _Traits> +void +basic_fstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode)) + this->clear(); + else + this->setstate(ios_base::failbit); +} +#endif + +template <class _CharT, class _Traits> +void +basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode)) + this->clear(); + else + this->setstate(ios_base::failbit); +} +#endif + +template <class _CharT, class _Traits> +inline +void +basic_fstream<_CharT, _Traits>::close() +{ + if (__sb_.close() == 0) + this->setstate(ios_base::failbit); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_FSTREAM diff --git a/android/x86/include/v8/libc++/functional b/android/x86/include/v8/libc++/functional new file mode 100755 index 00000000..2cec0ea4 --- /dev/null +++ b/android/x86/include/v8/libc++/functional @@ -0,0 +1,2974 @@ +// -*- C++ -*- +//===------------------------ functional ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUNCTIONAL +#define _LIBCPP_FUNCTIONAL + +/* + functional synopsis + +namespace std +{ + +template <class Arg, class Result> +struct unary_function +{ + typedef Arg argument_type; + typedef Result result_type; +}; + +template <class Arg1, class Arg2, class Result> +struct binary_function +{ + typedef Arg1 first_argument_type; + typedef Arg2 second_argument_type; + typedef Result result_type; +}; + +template <class T> +class reference_wrapper + : public unary_function<T1, R> // if wrapping a unary functor + : public binary_function<T1, T2, R> // if wraping a binary functor +{ +public: + // types + typedef T type; + typedef see below result_type; // Not always defined + + // construct/copy/destroy + reference_wrapper(T&) noexcept; + reference_wrapper(T&&) = delete; // do not bind to temps + reference_wrapper(const reference_wrapper<T>& x) noexcept; + + // assignment + reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; + + // access + operator T& () const noexcept; + T& get() const noexcept; + + // invoke + template <class... ArgTypes> + typename result_of<T&(ArgTypes&&...)>::type + operator() (ArgTypes&&...) const; +}; + +template <class T> reference_wrapper<T> ref(T& t) noexcept; +template <class T> void ref(const T&& t) = delete; +template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; + +template <class T> reference_wrapper<const T> cref(const T& t) noexcept; +template <class T> void cref(const T&& t) = delete; +template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; + +template <class T> struct unwrap_reference; // since C++20 +template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20 +template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20 +template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20 + +template <class T> // <class T=void> in C++14 +struct plus : binary_function<T, T, T> +{ + T operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct minus : binary_function<T, T, T> +{ + T operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct multiplies : binary_function<T, T, T> +{ + T operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct divides : binary_function<T, T, T> +{ + T operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct modulus : binary_function<T, T, T> +{ + T operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct negate : unary_function<T, T> +{ + T operator()(const T& x) const; +}; + +template <class T> // <class T=void> in C++14 +struct equal_to : binary_function<T, T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct not_equal_to : binary_function<T, T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct greater : binary_function<T, T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct less : binary_function<T, T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct greater_equal : binary_function<T, T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct less_equal : binary_function<T, T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct logical_and : binary_function<T, T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct logical_or : binary_function<T, T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct logical_not : unary_function<T, bool> +{ + bool operator()(const T& x) const; +}; + +template <class T> // <class T=void> in C++14 +struct bit_and : unary_function<T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct bit_or : unary_function<T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct bit_xor : unary_function<T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T=void> // C++14 +struct bit_xor : unary_function<T, bool> +{ + bool operator()(const T& x) const; +}; + +template <class Predicate> +class unary_negate // deprecated in C++17 + : public unary_function<typename Predicate::argument_type, bool> +{ +public: + explicit unary_negate(const Predicate& pred); + bool operator()(const typename Predicate::argument_type& x) const; +}; + +template <class Predicate> // deprecated in C++17 +unary_negate<Predicate> not1(const Predicate& pred); + +template <class Predicate> +class binary_negate // deprecated in C++17 + : public binary_function<typename Predicate::first_argument_type, + typename Predicate::second_argument_type, + bool> +{ +public: + explicit binary_negate(const Predicate& pred); + bool operator()(const typename Predicate::first_argument_type& x, + const typename Predicate::second_argument_type& y) const; +}; + +template <class Predicate> // deprecated in C++17 +binary_negate<Predicate> not2(const Predicate& pred); + +template <class F> unspecified not_fn(F&& f); // C++17 + +template<class T> struct is_bind_expression; +template<class T> struct is_placeholder; + + // See C++14 20.9.9, Function object binders +template <class T> inline constexpr bool is_bind_expression_v + = is_bind_expression<T>::value; // C++17 +template <class T> inline constexpr int is_placeholder_v + = is_placeholder<T>::value; // C++17 + + +template<class Fn, class... BoundArgs> + unspecified bind(Fn&&, BoundArgs&&...); +template<class R, class Fn, class... BoundArgs> + unspecified bind(Fn&&, BoundArgs&&...); + +template<class F, class... Args> + invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17 + noexcept(is_nothrow_invocable_v<F, Args...>); + +namespace placeholders { + // M is the implementation-defined number of placeholders + extern unspecified _1; + extern unspecified _2; + . + . + . + extern unspecified _Mp; +} + +template <class Operation> +class binder1st // deprecated in C++11, removed in C++17 + : public unary_function<typename Operation::second_argument_type, + typename Operation::result_type> +{ +protected: + Operation op; + typename Operation::first_argument_type value; +public: + binder1st(const Operation& x, const typename Operation::first_argument_type y); + typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; + typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; +}; + +template <class Operation, class T> +binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 + +template <class Operation> +class binder2nd // deprecated in C++11, removed in C++17 + : public unary_function<typename Operation::first_argument_type, + typename Operation::result_type> +{ +protected: + Operation op; + typename Operation::second_argument_type value; +public: + binder2nd(const Operation& x, const typename Operation::second_argument_type y); + typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; + typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; +}; + +template <class Operation, class T> +binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 + +template <class Arg, class Result> // deprecated in C++11, removed in C++17 +class pointer_to_unary_function : public unary_function<Arg, Result> +{ +public: + explicit pointer_to_unary_function(Result (*f)(Arg)); + Result operator()(Arg x) const; +}; + +template <class Arg, class Result> +pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17 + +template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17 +class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> +{ +public: + explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); + Result operator()(Arg1 x, Arg2 y) const; +}; + +template <class Arg1, class Arg2, class Result> +pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 + +template<class S, class T> // deprecated in C++11, removed in C++17 +class mem_fun_t : public unary_function<T*, S> +{ +public: + explicit mem_fun_t(S (T::*p)()); + S operator()(T* p) const; +}; + +template<class S, class T, class A> +class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17 +{ +public: + explicit mem_fun1_t(S (T::*p)(A)); + S operator()(T* p, A x) const; +}; + +template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 +template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17 + +template<class S, class T> +class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 +{ +public: + explicit mem_fun_ref_t(S (T::*p)()); + S operator()(T& p) const; +}; + +template<class S, class T, class A> +class mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 +{ +public: + explicit mem_fun1_ref_t(S (T::*p)(A)); + S operator()(T& p, A x) const; +}; + +template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 +template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17 + +template <class S, class T> +class const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17 +{ +public: + explicit const_mem_fun_t(S (T::*p)() const); + S operator()(const T* p) const; +}; + +template <class S, class T, class A> +class const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17 +{ +public: + explicit const_mem_fun1_t(S (T::*p)(A) const); + S operator()(const T* p, A x) const; +}; + +template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 +template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 + +template <class S, class T> +class const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 +{ +public: + explicit const_mem_fun_ref_t(S (T::*p)() const); + S operator()(const T& p) const; +}; + +template <class S, class T, class A> +class const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 +{ +public: + explicit const_mem_fun1_ref_t(S (T::*p)(A) const); + S operator()(const T& p, A x) const; +}; + +template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17 +template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 + +template<class R, class T> unspecified mem_fn(R T::*); + +class bad_function_call + : public exception +{ +}; + +template<class> class function; // undefined + +template<class R, class... ArgTypes> +class function<R(ArgTypes...)> + : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and + // ArgTypes contains T1 + : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and + // ArgTypes contains T1 and T2 +{ +public: + typedef R result_type; + + // construct/copy/destroy: + function() noexcept; + function(nullptr_t) noexcept; + function(const function&); + function(function&&) noexcept; + template<class F> + function(F); + template<Allocator Alloc> + function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 + template<Allocator Alloc> + function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 + template<Allocator Alloc> + function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 + template<Allocator Alloc> + function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 + template<class F, Allocator Alloc> + function(allocator_arg_t, const Alloc&, F); // removed in C++17 + + function& operator=(const function&); + function& operator=(function&&) noexcept; + function& operator=(nullptr_t) noexcept; + template<class F> + function& operator=(F&&); + template<class F> + function& operator=(reference_wrapper<F>) noexcept; + + ~function(); + + // function modifiers: + void swap(function&) noexcept; + template<class F, class Alloc> + void assign(F&&, const Alloc&); // Removed in C++17 + + // function capacity: + explicit operator bool() const noexcept; + + // function invocation: + R operator()(ArgTypes...) const; + + // function target access: + const std::type_info& target_type() const noexcept; + template <typename T> T* target() noexcept; + template <typename T> const T* target() const noexcept; +}; + +// Null pointer comparisons: +template <class R, class ... ArgTypes> + bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; + +template <class R, class ... ArgTypes> + bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; + +template <class R, class ... ArgTypes> + bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; + +template <class R, class ... ArgTypes> + bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; + +// specialized algorithms: +template <class R, class ... ArgTypes> + void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; + +template <class T> struct hash; + +template <> struct hash<bool>; +template <> struct hash<char>; +template <> struct hash<signed char>; +template <> struct hash<unsigned char>; +template <> struct hash<char16_t>; +template <> struct hash<char32_t>; +template <> struct hash<wchar_t>; +template <> struct hash<short>; +template <> struct hash<unsigned short>; +template <> struct hash<int>; +template <> struct hash<unsigned int>; +template <> struct hash<long>; +template <> struct hash<long long>; +template <> struct hash<unsigned long>; +template <> struct hash<unsigned long long>; + +template <> struct hash<float>; +template <> struct hash<double>; +template <> struct hash<long double>; + +template<class T> struct hash<T*>; +template <> struct hash<nullptr_t>; // C++17 + +} // std + +POLICY: For non-variadic implementations, the number of arguments is limited + to 3. It is hoped that the need for non-variadic implementations + will be minimal. + +*/ + +#include <__config> +#include <type_traits> +#include <typeinfo> +#include <exception> +#include <memory> +#include <tuple> +#include <utility> +#include <version> + +#include <__functional_base> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x + __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS plus<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x - __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS minus<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x * __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS multiplies<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x / __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS divides<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x % __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS modulus<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return -__x;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS negate<void> +{ + template <class _Tp> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_Tp&& __x) const + _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x))) + -> decltype (- _VSTD::forward<_Tp>(__x)) + { return - _VSTD::forward<_Tp>(__x); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x == __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS equal_to<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x != __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x > __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS greater<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +// less in <__functional_base> + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x >= __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS greater_equal<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x <= __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS less_equal<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x && __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS logical_and<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x || __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS logical_or<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x) const + {return !__x;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS logical_not<void> +{ + template <class _Tp> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_Tp&& __x) const + _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x))) + -> decltype (!_VSTD::forward<_Tp>(__x)) + { return !_VSTD::forward<_Tp>(__x); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x & __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS bit_and<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x | __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS bit_or<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else +template <class _Tp> +#endif +struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x ^ __y;} +}; + +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TEMPLATE_VIS bit_xor<void> +{ + template <class _T1, class _T2> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))) + -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)) + { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp> +{ + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return ~__x;} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS bit_not<void> +{ + template <class _Tp> + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + auto operator()(_Tp&& __x) const + _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x))) + -> decltype (~_VSTD::forward<_Tp>(__x)) + { return ~_VSTD::forward<_Tp>(__x); } + typedef void is_transparent; +}; +#endif + +template <class _Predicate> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate + : public unary_function<typename _Predicate::argument_type, bool> +{ + _Predicate __pred_; +public: + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + explicit unary_negate(const _Predicate& __pred) + : __pred_(__pred) {} + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Predicate::argument_type& __x) const + {return !__pred_(__x);} +}; + +template <class _Predicate> +_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +unary_negate<_Predicate> +not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} + +template <class _Predicate> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate + : public binary_function<typename _Predicate::first_argument_type, + typename _Predicate::second_argument_type, + bool> +{ + _Predicate __pred_; +public: + _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 + binary_negate(const _Predicate& __pred) : __pred_(__pred) {} + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Predicate::first_argument_type& __x, + const typename _Predicate::second_argument_type& __y) const + {return !__pred_(__x, __y);} +}; + +template <class _Predicate> +_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +binary_negate<_Predicate> +not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) +template <class __Operation> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st + : public unary_function<typename __Operation::second_argument_type, + typename __Operation::result_type> +{ +protected: + __Operation op; + typename __Operation::first_argument_type value; +public: + _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, + const typename __Operation::first_argument_type __y) + : op(__x), value(__y) {} + _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() + (typename __Operation::second_argument_type& __x) const + {return op(value, __x);} + _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() + (const typename __Operation::second_argument_type& __x) const + {return op(value, __x);} +}; + +template <class __Operation, class _Tp> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +binder1st<__Operation> +bind1st(const __Operation& __op, const _Tp& __x) + {return binder1st<__Operation>(__op, __x);} + +template <class __Operation> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd + : public unary_function<typename __Operation::first_argument_type, + typename __Operation::result_type> +{ +protected: + __Operation op; + typename __Operation::second_argument_type value; +public: + _LIBCPP_INLINE_VISIBILITY + binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) + : op(__x), value(__y) {} + _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() + ( typename __Operation::first_argument_type& __x) const + {return op(__x, value);} + _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() + (const typename __Operation::first_argument_type& __x) const + {return op(__x, value);} +}; + +template <class __Operation, class _Tp> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +binder2nd<__Operation> +bind2nd(const __Operation& __op, const _Tp& __x) + {return binder2nd<__Operation>(__op, __x);} + +template <class _Arg, class _Result> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function + : public unary_function<_Arg, _Result> +{ + _Result (*__f_)(_Arg); +public: + _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) + : __f_(__f) {} + _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const + {return __f_(__x);} +}; + +template <class _Arg, class _Result> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +pointer_to_unary_function<_Arg,_Result> +ptr_fun(_Result (*__f)(_Arg)) + {return pointer_to_unary_function<_Arg,_Result>(__f);} + +template <class _Arg1, class _Arg2, class _Result> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function + : public binary_function<_Arg1, _Arg2, _Result> +{ + _Result (*__f_)(_Arg1, _Arg2); +public: + _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) + : __f_(__f) {} + _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const + {return __f_(__x, __y);} +}; + +template <class _Arg1, class _Arg2, class _Result> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +pointer_to_binary_function<_Arg1,_Arg2,_Result> +ptr_fun(_Result (*__f)(_Arg1,_Arg2)) + {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} + +template<class _Sp, class _Tp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t + : public unary_function<_Tp*, _Sp> +{ + _Sp (_Tp::*__p_)(); +public: + _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const + {return (__p->*__p_)();} +}; + +template<class _Sp, class _Tp, class _Ap> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t + : public binary_function<_Tp*, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap); +public: + _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const + {return (__p->*__p_)(__x);} +}; + +template<class _Sp, class _Tp> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +mem_fun_t<_Sp,_Tp> +mem_fun(_Sp (_Tp::*__f)()) + {return mem_fun_t<_Sp,_Tp>(__f);} + +template<class _Sp, class _Tp, class _Ap> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +mem_fun1_t<_Sp,_Tp,_Ap> +mem_fun(_Sp (_Tp::*__f)(_Ap)) + {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} + +template<class _Sp, class _Tp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t + : public unary_function<_Tp, _Sp> +{ + _Sp (_Tp::*__p_)(); +public: + _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const + {return (__p.*__p_)();} +}; + +template<class _Sp, class _Tp, class _Ap> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t + : public binary_function<_Tp, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap); +public: + _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const + {return (__p.*__p_)(__x);} +}; + +template<class _Sp, class _Tp> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +mem_fun_ref_t<_Sp,_Tp> +mem_fun_ref(_Sp (_Tp::*__f)()) + {return mem_fun_ref_t<_Sp,_Tp>(__f);} + +template<class _Sp, class _Tp, class _Ap> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +mem_fun1_ref_t<_Sp,_Tp,_Ap> +mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) + {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} + +template <class _Sp, class _Tp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t + : public unary_function<const _Tp*, _Sp> +{ + _Sp (_Tp::*__p_)() const; +public: + _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const + {return (__p->*__p_)();} +}; + +template <class _Sp, class _Tp, class _Ap> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t + : public binary_function<const _Tp*, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap) const; +public: + _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const + {return (__p->*__p_)(__x);} +}; + +template <class _Sp, class _Tp> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +const_mem_fun_t<_Sp,_Tp> +mem_fun(_Sp (_Tp::*__f)() const) + {return const_mem_fun_t<_Sp,_Tp>(__f);} + +template <class _Sp, class _Tp, class _Ap> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +const_mem_fun1_t<_Sp,_Tp,_Ap> +mem_fun(_Sp (_Tp::*__f)(_Ap) const) + {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} + +template <class _Sp, class _Tp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t + : public unary_function<_Tp, _Sp> +{ + _Sp (_Tp::*__p_)() const; +public: + _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const + {return (__p.*__p_)();} +}; + +template <class _Sp, class _Tp, class _Ap> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t + : public binary_function<_Tp, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap) const; +public: + _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const + {return (__p.*__p_)(__x);} +}; + +template <class _Sp, class _Tp> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +const_mem_fun_ref_t<_Sp,_Tp> +mem_fun_ref(_Sp (_Tp::*__f)() const) + {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} + +template <class _Sp, class _Tp, class _Ap> +_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY +const_mem_fun1_ref_t<_Sp,_Tp,_Ap> +mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) + {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} +#endif + +//////////////////////////////////////////////////////////////////////////////// +// MEMFUN +//============================================================================== + +template <class _Tp> +class __mem_fn + : public __weak_result_type<_Tp> +{ +public: + // types + typedef _Tp type; +private: + type __f_; + +public: + _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} + +#ifndef _LIBCPP_CXX03_LANG + // invoke + template <class... _ArgTypes> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return<type, _ArgTypes...>::type + operator() (_ArgTypes&&... __args) const { + return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); + } +#else + + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return0<type, _A0>::type + operator() (_A0& __a0) const { + return __invoke(__f_, __a0); + } + + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return0<type, _A0 const>::type + operator() (_A0 const& __a0) const { + return __invoke(__f_, __a0); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0, _A1>::type + operator() (_A0& __a0, _A1& __a1) const { + return __invoke(__f_, __a0, __a1); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0 const, _A1>::type + operator() (_A0 const& __a0, _A1& __a1) const { + return __invoke(__f_, __a0, __a1); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0, _A1 const>::type + operator() (_A0& __a0, _A1 const& __a1) const { + return __invoke(__f_, __a0, __a1); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0 const, _A1 const>::type + operator() (_A0 const& __a0, _A1 const& __a1) const { + return __invoke(__f_, __a0, __a1); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1, _A2>::type + operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { + return __invoke(__f_, __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1, _A2>::type + operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { + return __invoke(__f_, __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1 const, _A2>::type + operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { + return __invoke(__f_, __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1, _A2 const>::type + operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { + return __invoke(__f_, __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type + operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { + return __invoke(__f_, __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type + operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { + return __invoke(__f_, __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type + operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { + return __invoke(__f_, __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type + operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { + return __invoke(__f_, __a0, __a1, __a2); + } +#endif +}; + +template<class _Rp, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_Rp _Tp::*> +mem_fn(_Rp _Tp::* __pm) _NOEXCEPT +{ + return __mem_fn<_Rp _Tp::*>(__pm); +} + +//////////////////////////////////////////////////////////////////////////////// +// FUNCTION +//============================================================================== + +// bad_function_call + +class _LIBCPP_EXCEPTION_ABI bad_function_call + : public exception +{ +#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +public: + virtual ~bad_function_call() _NOEXCEPT; + + virtual const char* what() const _NOEXCEPT; +#endif +}; + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_bad_function_call() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_function_call(); +#else + _VSTD::abort(); +#endif +} + +template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined + +namespace __function +{ + +template<class _Rp> +struct __maybe_derive_from_unary_function +{ +}; + +template<class _Rp, class _A1> +struct __maybe_derive_from_unary_function<_Rp(_A1)> + : public unary_function<_A1, _Rp> +{ +}; + +template<class _Rp> +struct __maybe_derive_from_binary_function +{ +}; + +template<class _Rp, class _A1, class _A2> +struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> + : public binary_function<_A1, _A2, _Rp> +{ +}; + +template <class _Fp> +_LIBCPP_INLINE_VISIBILITY +bool __not_null(_Fp const&) { return true; } + +template <class _Fp> +_LIBCPP_INLINE_VISIBILITY +bool __not_null(_Fp* __ptr) { return __ptr; } + +template <class _Ret, class _Class> +_LIBCPP_INLINE_VISIBILITY +bool __not_null(_Ret _Class::*__ptr) { return __ptr; } + +template <class _Fp> +_LIBCPP_INLINE_VISIBILITY +bool __not_null(function<_Fp> const& __f) { return !!__f; } + +} // namespace __function + +#ifndef _LIBCPP_CXX03_LANG + +namespace __function { + +// __alloc_func holds a functor and an allocator. + +template <class _Fp, class _Ap, class _FB> class __alloc_func; + +template <class _Fp, class _Ap, class _Rp, class... _ArgTypes> +class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> +{ + __compressed_pair<_Fp, _Ap> __f_; + + public: + typedef _Fp _Target; + typedef _Ap _Alloc; + + _LIBCPP_INLINE_VISIBILITY + const _Target& __target() const { return __f_.first(); } + + // WIN32 APIs may define __allocator, so use __get_allocator instead. + _LIBCPP_INLINE_VISIBILITY + const _Alloc& __get_allocator() const { return __f_.second(); } + + _LIBCPP_INLINE_VISIBILITY + explicit __alloc_func(_Target&& __f) + : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), + _VSTD::forward_as_tuple()) + { + } + + _LIBCPP_INLINE_VISIBILITY + explicit __alloc_func(const _Target& __f, const _Alloc& __a) + : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), + _VSTD::forward_as_tuple(__a)) + { + } + + _LIBCPP_INLINE_VISIBILITY + explicit __alloc_func(const _Target& __f, _Alloc&& __a) + : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), + _VSTD::forward_as_tuple(_VSTD::move(__a))) + { + } + + _LIBCPP_INLINE_VISIBILITY + explicit __alloc_func(_Target&& __f, _Alloc&& __a) + : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), + _VSTD::forward_as_tuple(_VSTD::move(__a))) + { + } + + _LIBCPP_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __arg) + { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first(), + _VSTD::forward<_ArgTypes>(__arg)...); + } + + _LIBCPP_INLINE_VISIBILITY + __alloc_func* __clone() const + { + typedef allocator_traits<_Alloc> __alloc_traits; + typedef + typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type + _AA; + _AA __a(__f_.second()); + typedef __allocator_destructor<_AA> _Dp; + unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a)); + return __hold.release(); + } + + _LIBCPP_INLINE_VISIBILITY + void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } +}; + +// __base provides an abstract interface for copyable functors. + +template<class _Fp> class __base; + +template<class _Rp, class ..._ArgTypes> +class __base<_Rp(_ArgTypes...)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + _LIBCPP_INLINE_VISIBILITY __base() {} + _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() _NOEXCEPT = 0; + virtual void destroy_deallocate() _NOEXCEPT = 0; + virtual _Rp operator()(_ArgTypes&& ...) = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const _NOEXCEPT = 0; + virtual const std::type_info& target_type() const _NOEXCEPT = 0; +#endif // _LIBCPP_NO_RTTI +}; + +// __func implements __base for a given functor type. + +template<class _FD, class _Alloc, class _FB> class __func; + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> + : public __base<_Rp(_ArgTypes...)> +{ + __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __func(_Fp&& __f) + : __f_(_VSTD::move(__f)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit __func(const _Fp& __f, const _Alloc& __a) + : __f_(__f, __a) {} + + _LIBCPP_INLINE_VISIBILITY + explicit __func(const _Fp& __f, _Alloc&& __a) + : __f_(__f, _VSTD::move(__a)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit __func(_Fp&& __f, _Alloc&& __a) + : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + + virtual __base<_Rp(_ArgTypes...)>* __clone() const; + virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; + virtual void destroy() _NOEXCEPT; + virtual void destroy_deallocate() _NOEXCEPT; + virtual _Rp operator()(_ArgTypes&&... __arg); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const _NOEXCEPT; + virtual const std::type_info& target_type() const _NOEXCEPT; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +__base<_Rp(_ArgTypes...)>* +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.__get_allocator()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a)); + return __hold.release(); +} + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +void +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const +{ + ::new (__p) __func(__f_.__target(), __f_.__get_allocator()); +} + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +void +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT +{ + __f_.destroy(); +} + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +void +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.__get_allocator()); + __f_.destroy(); + __a.deallocate(this, 1); +} + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +_Rp +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) +{ + return __f_(_VSTD::forward<_ArgTypes>(__arg)...); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +const void* +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT +{ + if (__ti == typeid(_Fp)) + return &__f_.__target(); + return (const void*)0; +} + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +const std::type_info& +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT +{ + return typeid(_Fp); +} + +#endif // _LIBCPP_NO_RTTI + +// __value_func creates a value-type from a __func. + +template <class _Fp> class __value_func; + +template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)> +{ + typename aligned_storage<3 * sizeof(void*)>::type __buf_; + + typedef __base<_Rp(_ArgTypes...)> __func; + __func* __f_; + + _LIBCPP_NO_CFI static __func* __as_base(void* p) + { + return reinterpret_cast<__func*>(p); + } + + public: + _LIBCPP_INLINE_VISIBILITY + __value_func() _NOEXCEPT : __f_(0) {} + + template <class _Fp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc __a) + : __f_(0) + { + typedef allocator_traits<_Alloc> __alloc_traits; + typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; + typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type + _FunAlloc; + + if (__function::__not_null(__f)) + { + _FunAlloc __af(__a); + if (sizeof(_Fun) <= sizeof(__buf_) && + is_nothrow_copy_constructible<_Fp>::value && + is_nothrow_copy_constructible<_FunAlloc>::value) + { + __f_ = + ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af)); + } + else + { + typedef __allocator_destructor<_FunAlloc> _Dp; + unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); + ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a)); + __f_ = __hold.release(); + } + } + } + + _LIBCPP_INLINE_VISIBILITY + __value_func(const __value_func& __f) + { + if (__f.__f_ == 0) + __f_ = 0; + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f_ = __as_base(&__buf_); + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); + } + + _LIBCPP_INLINE_VISIBILITY + __value_func(__value_func&& __f) _NOEXCEPT + { + if (__f.__f_ == 0) + __f_ = 0; + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f_ = __as_base(&__buf_); + __f.__f_->__clone(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = 0; + } + } + + _LIBCPP_INLINE_VISIBILITY + ~__value_func() + { + if ((void*)__f_ == &__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + } + + _LIBCPP_INLINE_VISIBILITY + __value_func& operator=(__value_func&& __f) + { + *this = nullptr; + if (__f.__f_ == 0) + __f_ = 0; + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f_ = __as_base(&__buf_); + __f.__f_->__clone(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = 0; + } + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __value_func& operator=(nullptr_t) + { + __func* __f = __f_; + __f_ = 0; + if ((void*)__f == &__buf_) + __f->destroy(); + else if (__f) + __f->destroy_deallocate(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __args) const + { + if (__f_ == 0) + __throw_bad_function_call(); + return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(__value_func& __f) _NOEXCEPT + { + if (&__f == this) + return; + if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_) + { + typename aligned_storage<sizeof(__buf_)>::type __tempbuf; + __func* __t = __as_base(&__tempbuf); + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone(__as_base(&__buf_)); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = __as_base(&__buf_); + __t->__clone(__as_base(&__f.__buf_)); + __t->destroy(); + __f.__f_ = __as_base(&__f.__buf_); + } + else if ((void*)__f_ == &__buf_) + { + __f_->__clone(__as_base(&__f.__buf_)); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = __as_base(&__f.__buf_); + } + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f.__f_->__clone(__as_base(&__buf_)); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = __as_base(&__buf_); + } + else + _VSTD::swap(__f_, __f.__f_); + } + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != 0; } + +#ifndef _LIBCPP_NO_RTTI + _LIBCPP_INLINE_VISIBILITY + const std::type_info& target_type() const _NOEXCEPT + { + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); + } + + template <typename _Tp> + _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT + { + if (__f_ == 0) + return 0; + return (const _Tp*)__f_->target(typeid(_Tp)); + } +#endif // _LIBCPP_NO_RTTI +}; + +// Storage for a functor object, to be used with __policy to manage copy and +// destruction. +union __policy_storage +{ + mutable char __small[sizeof(void*) * 2]; + void* __large; +}; + +// True if _Fun can safely be held in __policy_storage.__small. +template <typename _Fun> +struct __use_small_storage + : public _VSTD::integral_constant< + bool, sizeof(_Fun) <= sizeof(__policy_storage) && + _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) && + _VSTD::is_trivially_copy_constructible<_Fun>::value && + _VSTD::is_trivially_destructible<_Fun>::value> {}; + +// Policy contains information about how to copy, destroy, and move the +// underlying functor. You can think of it as a vtable of sorts. +struct __policy +{ + // Used to copy or destroy __large values. null for trivial objects. + void* (*const __clone)(const void*); + void (*const __destroy)(void*); + + // True if this is the null policy (no value). + const bool __is_null; + + // The target type. May be null if RTTI is disabled. + const std::type_info* const __type_info; + + // Returns a pointer to a static policy object suitable for the functor + // type. + template <typename _Fun> + _LIBCPP_INLINE_VISIBILITY static const __policy* __create() + { + return __choose_policy<_Fun>(__use_small_storage<_Fun>()); + } + + _LIBCPP_INLINE_VISIBILITY + static const __policy* __create_empty() + { + static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr, + true, +#ifndef _LIBCPP_NO_RTTI + &typeid(void) +#else + nullptr +#endif + }; + return &__policy_; + } + + private: + template <typename _Fun> static void* __large_clone(const void* __s) + { + const _Fun* __f = static_cast<const _Fun*>(__s); + return __f->__clone(); + } + + template <typename _Fun> static void __large_destroy(void* __s) + { + typedef allocator_traits<typename _Fun::_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type + _FunAlloc; + _Fun* __f = static_cast<_Fun*>(__s); + _FunAlloc __a(__f->__get_allocator()); + __f->destroy(); + __a.deallocate(__f, 1); + } + + template <typename _Fun> + _LIBCPP_INLINE_VISIBILITY static const __policy* + __choose_policy(/* is_small = */ false_type) + { + static const _LIBCPP_CONSTEXPR __policy __policy_ = { + &__large_clone<_Fun>, &__large_destroy<_Fun>, false, +#ifndef _LIBCPP_NO_RTTI + &typeid(typename _Fun::_Target) +#else + nullptr +#endif + }; + return &__policy_; + } + + template <typename _Fun> + _LIBCPP_INLINE_VISIBILITY static const __policy* + __choose_policy(/* is_small = */ true_type) + { + static const _LIBCPP_CONSTEXPR __policy __policy_ = { + nullptr, nullptr, false, +#ifndef _LIBCPP_NO_RTTI + &typeid(typename _Fun::_Target) +#else + nullptr +#endif + }; + return &__policy_; + } +}; + +// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is +// faster for types that can be passed in registers. +template <typename _Tp> +using __fast_forward = + typename _VSTD::conditional<_VSTD::is_scalar<_Tp>::value, _Tp, _Tp&&>::type; + +// __policy_invoker calls an instance of __alloc_func held in __policy_storage. + +template <class _Fp> struct __policy_invoker; + +template <class _Rp, class... _ArgTypes> +struct __policy_invoker<_Rp(_ArgTypes...)> +{ + typedef _Rp (*__Call)(const __policy_storage*, + __fast_forward<_ArgTypes>...); + + __Call __call_; + + // Creates an invoker that throws bad_function_call. + _LIBCPP_INLINE_VISIBILITY + __policy_invoker() : __call_(&__call_empty) {} + + // Creates an invoker that calls the given instance of __func. + template <typename _Fun> + _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create() + { + return __policy_invoker(&__call_impl<_Fun>); + } + + private: + _LIBCPP_INLINE_VISIBILITY + explicit __policy_invoker(__Call __c) : __call_(__c) {} + + static _Rp __call_empty(const __policy_storage*, + __fast_forward<_ArgTypes>...) + { + __throw_bad_function_call(); + } + + template <typename _Fun> + static _Rp __call_impl(const __policy_storage* __buf, + __fast_forward<_ArgTypes>... __args) + { + _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value + ? &__buf->__small + : __buf->__large); + return (*__f)(_VSTD::forward<_ArgTypes>(__args)...); + } +}; + +// __policy_func uses a __policy and __policy_invoker to create a type-erased, +// copyable functor. + +template <class _Fp> class __policy_func; + +template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)> +{ + // Inline storage for small objects. + __policy_storage __buf_; + + // Calls the value stored in __buf_. This could technically be part of + // policy, but storing it here eliminates a level of indirection inside + // operator(). + typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker; + __invoker __invoker_; + + // The policy that describes how to move / copy / destroy __buf_. Never + // null, even if the function is empty. + const __policy* __policy_; + + public: + _LIBCPP_INLINE_VISIBILITY + __policy_func() : __policy_(__policy::__create_empty()) {} + + template <class _Fp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a) + : __policy_(__policy::__create_empty()) + { + typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type + _FunAlloc; + + if (__function::__not_null(__f)) + { + __invoker_ = __invoker::template __create<_Fun>(); + __policy_ = __policy::__create<_Fun>(); + + _FunAlloc __af(__a); + if (__use_small_storage<_Fun>()) + { + ::new ((void*)&__buf_.__small) + _Fun(_VSTD::move(__f), _Alloc(__af)); + } + else + { + typedef __allocator_destructor<_FunAlloc> _Dp; + unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); + ::new ((void*)__hold.get()) + _Fun(_VSTD::move(__f), _Alloc(__af)); + __buf_.__large = __hold.release(); + } + } + } + + _LIBCPP_INLINE_VISIBILITY + __policy_func(const __policy_func& __f) + : __buf_(__f.__buf_), __invoker_(__f.__invoker_), + __policy_(__f.__policy_) + { + if (__policy_->__clone) + __buf_.__large = __policy_->__clone(__f.__buf_.__large); + } + + _LIBCPP_INLINE_VISIBILITY + __policy_func(__policy_func&& __f) + : __buf_(__f.__buf_), __invoker_(__f.__invoker_), + __policy_(__f.__policy_) + { + if (__policy_->__destroy) + { + __f.__policy_ = __policy::__create_empty(); + __f.__invoker_ = __invoker(); + } + } + + _LIBCPP_INLINE_VISIBILITY + ~__policy_func() + { + if (__policy_->__destroy) + __policy_->__destroy(__buf_.__large); + } + + _LIBCPP_INLINE_VISIBILITY + __policy_func& operator=(__policy_func&& __f) + { + *this = nullptr; + __buf_ = __f.__buf_; + __invoker_ = __f.__invoker_; + __policy_ = __f.__policy_; + __f.__policy_ = __policy::__create_empty(); + __f.__invoker_ = __invoker(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __policy_func& operator=(nullptr_t) + { + const __policy* __p = __policy_; + __policy_ = __policy::__create_empty(); + __invoker_ = __invoker(); + if (__p->__destroy) + __p->__destroy(__buf_.__large); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __args) const + { + return __invoker_.__call_(_VSTD::addressof(__buf_), + _VSTD::forward<_ArgTypes>(__args)...); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(__policy_func& __f) + { + _VSTD::swap(__invoker_, __f.__invoker_); + _VSTD::swap(__policy_, __f.__policy_); + _VSTD::swap(__buf_, __f.__buf_); + } + + _LIBCPP_INLINE_VISIBILITY + explicit operator bool() const _NOEXCEPT + { + return !__policy_->__is_null; + } + +#ifndef _LIBCPP_NO_RTTI + _LIBCPP_INLINE_VISIBILITY + const std::type_info& target_type() const _NOEXCEPT + { + return *__policy_->__type_info; + } + + template <typename _Tp> + _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT + { + if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info) + return nullptr; + if (__policy_->__clone) // Out of line storage. + return reinterpret_cast<const _Tp*>(__buf_.__large); + else + return reinterpret_cast<const _Tp*>(&__buf_.__small); + } +#endif // _LIBCPP_NO_RTTI +}; + +} // __function + +template<class _Rp, class ..._ArgTypes> +class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> + : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, + public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> +{ +#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION + typedef __function::__value_func<_Rp(_ArgTypes...)> __func; +#else + typedef __function::__policy_func<_Rp(_ArgTypes...)> __func; +#endif + + __func __f_; + + template <class _Fp, bool = __lazy_and< + integral_constant<bool, !is_same<__uncvref_t<_Fp>, function>::value>, + __invokable<_Fp&, _ArgTypes...> + >::value> + struct __callable; + template <class _Fp> + struct __callable<_Fp, true> + { + static const bool value = is_same<void, _Rp>::value || + is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type, + _Rp>::value; + }; + template <class _Fp> + struct __callable<_Fp, false> + { + static const bool value = false; + }; + + template <class _Fp> + using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type; +public: + typedef _Rp result_type; + + // construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY + function() _NOEXCEPT { } + _LIBCPP_INLINE_VISIBILITY + function(nullptr_t) _NOEXCEPT {} + function(const function&); + function(function&&) _NOEXCEPT; + template<class _Fp, class = _EnableIfCallable<_Fp>> + function(_Fp); + +#if _LIBCPP_STD_VER <= 14 + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) _NOEXCEPT {} + template<class _Alloc> + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {} + template<class _Alloc> + function(allocator_arg_t, const _Alloc&, const function&); + template<class _Alloc> + function(allocator_arg_t, const _Alloc&, function&&); + template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>> + function(allocator_arg_t, const _Alloc& __a, _Fp __f); +#endif + + function& operator=(const function&); + function& operator=(function&&) _NOEXCEPT; + function& operator=(nullptr_t) _NOEXCEPT; + template<class _Fp, class = _EnableIfCallable<_Fp>> + function& operator=(_Fp&&); + + ~function(); + + // function modifiers: + void swap(function&) _NOEXCEPT; + +#if _LIBCPP_STD_VER <= 14 + template<class _Fp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + void assign(_Fp&& __f, const _Alloc& __a) + {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} +#endif + + // function capacity: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { + return static_cast<bool>(__f_); + } + + // deleted overloads close possible hole in the type system + template<class _R2, class... _ArgTypes2> + bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; + template<class _R2, class... _ArgTypes2> + bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; +public: + // function invocation: + _Rp operator()(_ArgTypes...) const; + +#ifndef _LIBCPP_NO_RTTI + // function target access: + const std::type_info& target_type() const _NOEXCEPT; + template <typename _Tp> _Tp* target() _NOEXCEPT; + template <typename _Tp> const _Tp* target() const _NOEXCEPT; +#endif // _LIBCPP_NO_RTTI +}; + +template<class _Rp, class ..._ArgTypes> +function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {} + +#if _LIBCPP_STD_VER <= 14 +template<class _Rp, class ..._ArgTypes> +template <class _Alloc> +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, + const function& __f) : __f_(__f.__f_) {} +#endif + +template <class _Rp, class... _ArgTypes> +function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT + : __f_(_VSTD::move(__f.__f_)) {} + +#if _LIBCPP_STD_VER <= 14 +template<class _Rp, class ..._ArgTypes> +template <class _Alloc> +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, + function&& __f) + : __f_(_VSTD::move(__f.__f_)) {} +#endif + +template <class _Rp, class... _ArgTypes> +template <class _Fp, class> +function<_Rp(_ArgTypes...)>::function(_Fp __f) + : __f_(_VSTD::move(__f), allocator<_Fp>()) {} + +#if _LIBCPP_STD_VER <= 14 +template <class _Rp, class... _ArgTypes> +template <class _Fp, class _Alloc, class> +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a, + _Fp __f) + : __f_(_VSTD::move(__f), __a) {} +#endif + +template<class _Rp, class ..._ArgTypes> +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(const function& __f) +{ + function(__f).swap(*this); + return *this; +} + +template<class _Rp, class ..._ArgTypes> +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT +{ + __f_ = std::move(__f.__f_); + return *this; +} + +template<class _Rp, class ..._ArgTypes> +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT +{ + __f_ = nullptr; + return *this; +} + +template<class _Rp, class ..._ArgTypes> +template <class _Fp, class> +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) +{ + function(_VSTD::forward<_Fp>(__f)).swap(*this); + return *this; +} + +template<class _Rp, class ..._ArgTypes> +function<_Rp(_ArgTypes...)>::~function() {} + +template<class _Rp, class ..._ArgTypes> +void +function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT +{ + __f_.swap(__f.__f_); +} + +template<class _Rp, class ..._ArgTypes> +_Rp +function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const +{ + return __f_(_VSTD::forward<_ArgTypes>(__arg)...); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Rp, class ..._ArgTypes> +const std::type_info& +function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT +{ + return __f_.target_type(); +} + +template<class _Rp, class ..._ArgTypes> +template <typename _Tp> +_Tp* +function<_Rp(_ArgTypes...)>::target() _NOEXCEPT +{ + return (_Tp*)(__f_.template target<_Tp>()); +} + +template<class _Rp, class ..._ArgTypes> +template <typename _Tp> +const _Tp* +function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT +{ + return __f_.template target<_Tp>(); +} + +#endif // _LIBCPP_NO_RTTI + +template <class _Rp, class... _ArgTypes> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} + +template <class _Rp, class... _ArgTypes> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} + +template <class _Rp, class... _ArgTypes> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} + +template <class _Rp, class... _ArgTypes> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} + +template <class _Rp, class... _ArgTypes> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT +{return __x.swap(__y);} + +#else // _LIBCPP_CXX03_LANG + +#include <__functional_03> + +#endif + +//////////////////////////////////////////////////////////////////////////////// +// BIND +//============================================================================== + +template<class _Tp> struct __is_bind_expression : public false_type {}; +template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression + : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; + +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; +#endif + +template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; +template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder + : public __is_placeholder<typename remove_cv<_Tp>::type> {}; + +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; +#endif + +namespace placeholders +{ + +template <int _Np> struct __ph {}; + +#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) +_LIBCPP_FUNC_VIS extern const __ph<1> _1; +_LIBCPP_FUNC_VIS extern const __ph<2> _2; +_LIBCPP_FUNC_VIS extern const __ph<3> _3; +_LIBCPP_FUNC_VIS extern const __ph<4> _4; +_LIBCPP_FUNC_VIS extern const __ph<5> _5; +_LIBCPP_FUNC_VIS extern const __ph<6> _6; +_LIBCPP_FUNC_VIS extern const __ph<7> _7; +_LIBCPP_FUNC_VIS extern const __ph<8> _8; +_LIBCPP_FUNC_VIS extern const __ph<9> _9; +_LIBCPP_FUNC_VIS extern const __ph<10> _10; +#else +/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{}; +#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) + +} // placeholders + +template<int _Np> +struct __is_placeholder<placeholders::__ph<_Np> > + : public integral_constant<int, _Np> {}; + + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Uj> +inline _LIBCPP_INLINE_VISIBILITY +_Tp& +__mu(reference_wrapper<_Tp> __t, _Uj&) +{ + return __t.get(); +} + +template <class _Ti, class ..._Uj, size_t ..._Indx> +inline _LIBCPP_INLINE_VISIBILITY +typename __invoke_of<_Ti&, _Uj...>::type +__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) +{ + return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); +} + +template <class _Ti, class ..._Uj> +inline _LIBCPP_INLINE_VISIBILITY +typename __lazy_enable_if +< + is_bind_expression<_Ti>::value, + __invoke_of<_Ti&, _Uj...> +>::type +__mu(_Ti& __ti, tuple<_Uj...>& __uj) +{ + typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; + return __mu_expand(__ti, __uj, __indices()); +} + +template <bool IsPh, class _Ti, class _Uj> +struct __mu_return2 {}; + +template <class _Ti, class _Uj> +struct __mu_return2<true, _Ti, _Uj> +{ + typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; +}; + +template <class _Ti, class _Uj> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + 0 < is_placeholder<_Ti>::value, + typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type +>::type +__mu(_Ti&, _Uj& __uj) +{ + const size_t _Indx = is_placeholder<_Ti>::value - 1; + return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); +} + +template <class _Ti, class _Uj> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_bind_expression<_Ti>::value && + is_placeholder<_Ti>::value == 0 && + !__is_reference_wrapper<_Ti>::value, + _Ti& +>::type +__mu(_Ti& __ti, _Uj&) +{ + return __ti; +} + +template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, + class _TupleUj> +struct __mu_return_impl; + +template <bool _Invokable, class _Ti, class ..._Uj> +struct __mu_return_invokable // false +{ + typedef __nat type; +}; + +template <class _Ti, class ..._Uj> +struct __mu_return_invokable<true, _Ti, _Uj...> +{ + typedef typename __invoke_of<_Ti&, _Uj...>::type type; +}; + +template <class _Ti, class ..._Uj> +struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > + : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> +{ +}; + +template <class _Ti, class _TupleUj> +struct __mu_return_impl<_Ti, false, false, true, _TupleUj> +{ + typedef typename tuple_element<is_placeholder<_Ti>::value - 1, + _TupleUj>::type&& type; +}; + +template <class _Ti, class _TupleUj> +struct __mu_return_impl<_Ti, true, false, false, _TupleUj> +{ + typedef typename _Ti::type& type; +}; + +template <class _Ti, class _TupleUj> +struct __mu_return_impl<_Ti, false, false, false, _TupleUj> +{ + typedef _Ti& type; +}; + +template <class _Ti, class _TupleUj> +struct __mu_return + : public __mu_return_impl<_Ti, + __is_reference_wrapper<_Ti>::value, + is_bind_expression<_Ti>::value, + 0 < is_placeholder<_Ti>::value && + is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, + _TupleUj> +{ +}; + +template <class _Fp, class _BoundArgs, class _TupleUj> +struct __is_valid_bind_return +{ + static const bool value = false; +}; + +template <class _Fp, class ..._BoundArgs, class _TupleUj> +struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> +{ + static const bool value = __invokable<_Fp, + typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; +}; + +template <class _Fp, class ..._BoundArgs, class _TupleUj> +struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> +{ + static const bool value = __invokable<_Fp, + typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; +}; + +template <class _Fp, class _BoundArgs, class _TupleUj, + bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> +struct __bind_return; + +template <class _Fp, class ..._BoundArgs, class _TupleUj> +struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> +{ + typedef typename __invoke_of + < + _Fp&, + typename __mu_return + < + _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template <class _Fp, class ..._BoundArgs, class _TupleUj> +struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> +{ + typedef typename __invoke_of + < + _Fp&, + typename __mu_return + < + const _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> +inline _LIBCPP_INLINE_VISIBILITY +typename __bind_return<_Fp, _BoundArgs, _Args>::type +__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, + _Args&& __args) +{ + return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...); +} + +template<class _Fp, class ..._BoundArgs> +class __bind + : public __weak_result_type<typename decay<_Fp>::type> +{ +protected: + typedef typename decay<_Fp>::type _Fd; + typedef tuple<typename decay<_BoundArgs>::type...> _Td; +private: + _Fd __f_; + _Td __bound_args_; + + typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; +public: + template <class _Gp, class ..._BA, + class = typename enable_if + < + is_constructible<_Fd, _Gp>::value && + !is_same<typename remove_reference<_Gp>::type, + __bind>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + explicit __bind(_Gp&& __f, _BA&& ...__bound_args) + : __f_(_VSTD::forward<_Gp>(__f)), + __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type + operator()(_Args&& ...__args) + { + return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); + } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type + operator()(_Args&& ...__args) const + { + return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); + } +}; + +template<class _Fp, class ..._BoundArgs> +struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; + +template<class _Rp, class _Fp, class ..._BoundArgs> +class __bind_r + : public __bind<_Fp, _BoundArgs...> +{ + typedef __bind<_Fp, _BoundArgs...> base; + typedef typename base::_Fd _Fd; + typedef typename base::_Td _Td; +public: + typedef _Rp result_type; + + + template <class _Gp, class ..._BA, + class = typename enable_if + < + is_constructible<_Fd, _Gp>::value && + !is_same<typename remove_reference<_Gp>::type, + __bind_r>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) + : base(_VSTD::forward<_Gp>(__f), + _VSTD::forward<_BA>(__bound_args)...) {} + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, + result_type>::value || is_void<_Rp>::value, + result_type + >::type + operator()(_Args&& ...__args) + { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); + } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, + result_type>::value || is_void<_Rp>::value, + result_type + >::type + operator()(_Args&& ...__args) const + { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); + } +}; + +template<class _Rp, class _Fp, class ..._BoundArgs> +struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; + +template<class _Fp, class ..._BoundArgs> +inline _LIBCPP_INLINE_VISIBILITY +__bind<_Fp, _BoundArgs...> +bind(_Fp&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind<_Fp, _BoundArgs...> type; + return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); +} + +template<class _Rp, class _Fp, class ..._BoundArgs> +inline _LIBCPP_INLINE_VISIBILITY +__bind_r<_Rp, _Fp, _BoundArgs...> +bind(_Fp&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; + return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); +} + +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 14 + +template <class _Fn, class ..._Args> +invoke_result_t<_Fn, _Args...> +invoke(_Fn&& __f, _Args&&... __args) + noexcept(is_nothrow_invocable_v<_Fn, _Args...>) +{ + return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); +} + +template <class _DecayFunc> +class _LIBCPP_TEMPLATE_VIS __not_fn_imp { + _DecayFunc __fd; + +public: + __not_fn_imp() = delete; + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + auto operator()(_Args&& ...__args) & + noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) + -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + auto operator()(_Args&& ...__args) && + noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) + -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + auto operator()(_Args&& ...__args) const& + noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) + -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } + + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + auto operator()(_Args&& ...__args) const&& + noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) + -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } + +private: + template <class _RawFunc, + class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>> + _LIBCPP_INLINE_VISIBILITY + explicit __not_fn_imp(_RawFunc&& __rf) + : __fd(_VSTD::forward<_RawFunc>(__rf)) {} + + template <class _RawFunc> + friend inline _LIBCPP_INLINE_VISIBILITY + __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&); +}; + +template <class _RawFunc> +inline _LIBCPP_INLINE_VISIBILITY +__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) { + return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn)); +} + +#endif + +// struct hash<T*> in <memory> + +template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> +pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11 +__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, + forward_iterator_tag, forward_iterator_tag) +{ + if (__first2 == __last2) + return make_pair(__first1, __first1); // Everything matches an empty sequence + while (true) + { + // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks + while (true) + { + if (__first1 == __last1) // return __last1 if no element matches *__first2 + return make_pair(__last1, __last1); + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } + // *__first1 matches *__first2, now match elements after here + _ForwardIterator1 __m1 = __first1; + _ForwardIterator2 __m2 = __first2; + while (true) + { + if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) + return make_pair(__first1, __m1); + if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found + return make_pair(__last1, __last1); + if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 + { + ++__first1; + break; + } // else there is a match, check next elements + } + } +} + +template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> +_LIBCPP_CONSTEXPR_AFTER_CXX11 +pair<_RandomAccessIterator1, _RandomAccessIterator1> +__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, + _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag) +{ + typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; + typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; + // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern + const _D2 __len2 = __last2 - __first2; + if (__len2 == 0) + return make_pair(__first1, __first1); + const _D1 __len1 = __last1 - __first1; + if (__len1 < __len2) + return make_pair(__last1, __last1); + const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here + + while (true) + { + while (true) + { + if (__first1 == __s) + return make_pair(__last1, __last1); + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } + + _RandomAccessIterator1 __m1 = __first1; + _RandomAccessIterator2 __m2 = __first2; + while (true) + { + if (++__m2 == __last2) + return make_pair(__first1, __first1 + __len2); + ++__m1; // no need to check range on __m1 because __s guarantees we have enough source + if (!__pred(*__m1, *__m2)) + { + ++__first1; + break; + } + } + } +} + +#if _LIBCPP_STD_VER > 14 + +// default searcher +template<class _ForwardIterator, class _BinaryPredicate = equal_to<>> +class _LIBCPP_TYPE_VIS default_searcher { +public: + _LIBCPP_INLINE_VISIBILITY + default_searcher(_ForwardIterator __f, _ForwardIterator __l, + _BinaryPredicate __p = _BinaryPredicate()) + : __first_(__f), __last_(__l), __pred_(__p) {} + + template <typename _ForwardIterator2> + _LIBCPP_INLINE_VISIBILITY + pair<_ForwardIterator2, _ForwardIterator2> + operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const + { + return _VSTD::__search(__f, __l, __first_, __last_, __pred_, + typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(), + typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category()); + } + +private: + _ForwardIterator __first_; + _ForwardIterator __last_; + _BinaryPredicate __pred_; + }; + +#endif // _LIBCPP_STD_VER > 14 + +#if _LIBCPP_STD_VER > 17 +template <class _Tp> +using unwrap_reference_t = typename unwrap_reference<_Tp>::type; + +template <class _Tp> +using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type; +#endif // > C++17 + +template <class _Container, class _Predicate> +inline void __libcpp_erase_if_container( _Container& __c, _Predicate __pred) +{ + for (typename _Container::iterator __iter = __c.begin(), __last = __c.end(); __iter != __last;) + { + if (__pred(*__iter)) + __iter = __c.erase(__iter); + else + ++__iter; + } +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_FUNCTIONAL diff --git a/android/x86/include/v8/libc++/future b/android/x86/include/v8/libc++/future new file mode 100755 index 00000000..50bdd2da --- /dev/null +++ b/android/x86/include/v8/libc++/future @@ -0,0 +1,2612 @@ +// -*- C++ -*- +//===--------------------------- future -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUTURE +#define _LIBCPP_FUTURE + +/* + future synopsis + +namespace std +{ + +enum class future_errc +{ + future_already_retrieved = 1, + promise_already_satisfied, + no_state, + broken_promise +}; + +enum class launch +{ + async = 1, + deferred = 2, + any = async | deferred +}; + +enum class future_status +{ + ready, + timeout, + deferred +}; + +template <> struct is_error_code_enum<future_errc> : public true_type { }; +error_code make_error_code(future_errc e) noexcept; +error_condition make_error_condition(future_errc e) noexcept; + +const error_category& future_category() noexcept; + +class future_error + : public logic_error +{ +public: + future_error(error_code ec); // exposition only + explicit future_error(future_errc); // C++17 + const error_code& code() const noexcept; + const char* what() const noexcept; +}; + +template <class R> +class promise +{ +public: + promise(); + template <class Allocator> + promise(allocator_arg_t, const Allocator& a); + promise(promise&& rhs) noexcept; + promise(const promise& rhs) = delete; + ~promise(); + + // assignment + promise& operator=(promise&& rhs) noexcept; + promise& operator=(const promise& rhs) = delete; + void swap(promise& other) noexcept; + + // retrieving the result + future<R> get_future(); + + // setting the result + void set_value(const R& r); + void set_value(R&& r); + void set_exception(exception_ptr p); + + // setting the result with deferred notification + void set_value_at_thread_exit(const R& r); + void set_value_at_thread_exit(R&& r); + void set_exception_at_thread_exit(exception_ptr p); +}; + +template <class R> +class promise<R&> +{ +public: + promise(); + template <class Allocator> + promise(allocator_arg_t, const Allocator& a); + promise(promise&& rhs) noexcept; + promise(const promise& rhs) = delete; + ~promise(); + + // assignment + promise& operator=(promise&& rhs) noexcept; + promise& operator=(const promise& rhs) = delete; + void swap(promise& other) noexcept; + + // retrieving the result + future<R&> get_future(); + + // setting the result + void set_value(R& r); + void set_exception(exception_ptr p); + + // setting the result with deferred notification + void set_value_at_thread_exit(R&); + void set_exception_at_thread_exit(exception_ptr p); +}; + +template <> +class promise<void> +{ +public: + promise(); + template <class Allocator> + promise(allocator_arg_t, const Allocator& a); + promise(promise&& rhs) noexcept; + promise(const promise& rhs) = delete; + ~promise(); + + // assignment + promise& operator=(promise&& rhs) noexcept; + promise& operator=(const promise& rhs) = delete; + void swap(promise& other) noexcept; + + // retrieving the result + future<void> get_future(); + + // setting the result + void set_value(); + void set_exception(exception_ptr p); + + // setting the result with deferred notification + void set_value_at_thread_exit(); + void set_exception_at_thread_exit(exception_ptr p); +}; + +template <class R> void swap(promise<R>& x, promise<R>& y) noexcept; + +template <class R, class Alloc> + struct uses_allocator<promise<R>, Alloc> : public true_type {}; + +template <class R> +class future +{ +public: + future() noexcept; + future(future&&) noexcept; + future(const future& rhs) = delete; + ~future(); + future& operator=(const future& rhs) = delete; + future& operator=(future&&) noexcept; + shared_future<R> share() noexcept; + + // retrieving the value + R get(); + + // functions to check state + bool valid() const noexcept; + + void wait() const; + template <class Rep, class Period> + future_status + wait_for(const chrono::duration<Rep, Period>& rel_time) const; + template <class Clock, class Duration> + future_status + wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; +}; + +template <class R> +class future<R&> +{ +public: + future() noexcept; + future(future&&) noexcept; + future(const future& rhs) = delete; + ~future(); + future& operator=(const future& rhs) = delete; + future& operator=(future&&) noexcept; + shared_future<R&> share() noexcept; + + // retrieving the value + R& get(); + + // functions to check state + bool valid() const noexcept; + + void wait() const; + template <class Rep, class Period> + future_status + wait_for(const chrono::duration<Rep, Period>& rel_time) const; + template <class Clock, class Duration> + future_status + wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; +}; + +template <> +class future<void> +{ +public: + future() noexcept; + future(future&&) noexcept; + future(const future& rhs) = delete; + ~future(); + future& operator=(const future& rhs) = delete; + future& operator=(future&&) noexcept; + shared_future<void> share() noexcept; + + // retrieving the value + void get(); + + // functions to check state + bool valid() const noexcept; + + void wait() const; + template <class Rep, class Period> + future_status + wait_for(const chrono::duration<Rep, Period>& rel_time) const; + template <class Clock, class Duration> + future_status + wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; +}; + +template <class R> +class shared_future +{ +public: + shared_future() noexcept; + shared_future(const shared_future& rhs); + shared_future(future<R>&&) noexcept; + shared_future(shared_future&& rhs) noexcept; + ~shared_future(); + shared_future& operator=(const shared_future& rhs); + shared_future& operator=(shared_future&& rhs) noexcept; + + // retrieving the value + const R& get() const; + + // functions to check state + bool valid() const noexcept; + + void wait() const; + template <class Rep, class Period> + future_status + wait_for(const chrono::duration<Rep, Period>& rel_time) const; + template <class Clock, class Duration> + future_status + wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; +}; + +template <class R> +class shared_future<R&> +{ +public: + shared_future() noexcept; + shared_future(const shared_future& rhs); + shared_future(future<R&>&&) noexcept; + shared_future(shared_future&& rhs) noexcept; + ~shared_future(); + shared_future& operator=(const shared_future& rhs); + shared_future& operator=(shared_future&& rhs) noexcept; + + // retrieving the value + R& get() const; + + // functions to check state + bool valid() const noexcept; + + void wait() const; + template <class Rep, class Period> + future_status + wait_for(const chrono::duration<Rep, Period>& rel_time) const; + template <class Clock, class Duration> + future_status + wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; +}; + +template <> +class shared_future<void> +{ +public: + shared_future() noexcept; + shared_future(const shared_future& rhs); + shared_future(future<void>&&) noexcept; + shared_future(shared_future&& rhs) noexcept; + ~shared_future(); + shared_future& operator=(const shared_future& rhs); + shared_future& operator=(shared_future&& rhs) noexcept; + + // retrieving the value + void get() const; + + // functions to check state + bool valid() const noexcept; + + void wait() const; + template <class Rep, class Period> + future_status + wait_for(const chrono::duration<Rep, Period>& rel_time) const; + template <class Clock, class Duration> + future_status + wait_until(const chrono::time_point<Clock, Duration>& abs_time) const; +}; + +template <class F, class... Args> + future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type> + async(F&& f, Args&&... args); + +template <class F, class... Args> + future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type> + async(launch policy, F&& f, Args&&... args); + +template <class> class packaged_task; // undefined + +template <class R, class... ArgTypes> +class packaged_task<R(ArgTypes...)> +{ +public: + typedef R result_type; // extension + + // construction and destruction + packaged_task() noexcept; + template <class F> + explicit packaged_task(F&& f); + template <class F, class Allocator> + packaged_task(allocator_arg_t, const Allocator& a, F&& f); + ~packaged_task(); + + // no copy + packaged_task(const packaged_task&) = delete; + packaged_task& operator=(const packaged_task&) = delete; + + // move support + packaged_task(packaged_task&& other) noexcept; + packaged_task& operator=(packaged_task&& other) noexcept; + void swap(packaged_task& other) noexcept; + + bool valid() const noexcept; + + // result retrieval + future<R> get_future(); + + // execution + void operator()(ArgTypes... ); + void make_ready_at_thread_exit(ArgTypes...); + + void reset(); +}; + +template <class R> + void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&) noexcept; + +template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>; + +} // std + +*/ + +#include <__config> +#include <system_error> +#include <memory> +#include <chrono> +#include <exception> +#include <mutex> +#include <thread> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_THREADS +#error <future> is not supported on this single threaded system +#else // !_LIBCPP_HAS_NO_THREADS + +_LIBCPP_BEGIN_NAMESPACE_STD + +//enum class future_errc +_LIBCPP_DECLARE_STRONG_ENUM(future_errc) +{ + future_already_retrieved = 1, + promise_already_satisfied, + no_state, + broken_promise +}; +_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc) + +template <> +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc> : public true_type {}; + +#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS +template <> +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc::__lx> : public true_type { }; +#endif + +//enum class launch +_LIBCPP_DECLARE_STRONG_ENUM(launch) +{ + async = 1, + deferred = 2, + any = async | deferred +}; +_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch) + +#ifndef _LIBCPP_HAS_NO_STRONG_ENUMS + +#ifdef _LIBCPP_UNDERLYING_TYPE +typedef underlying_type<launch>::type __launch_underlying_type; +#else +typedef int __launch_underlying_type; +#endif + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator&(launch __x, launch __y) +{ + return static_cast<launch>(static_cast<__launch_underlying_type>(__x) & + static_cast<__launch_underlying_type>(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator|(launch __x, launch __y) +{ + return static_cast<launch>(static_cast<__launch_underlying_type>(__x) | + static_cast<__launch_underlying_type>(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator^(launch __x, launch __y) +{ + return static_cast<launch>(static_cast<__launch_underlying_type>(__x) ^ + static_cast<__launch_underlying_type>(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator~(launch __x) +{ + return static_cast<launch>(~static_cast<__launch_underlying_type>(__x) & 3); +} + +inline _LIBCPP_INLINE_VISIBILITY +launch& +operator&=(launch& __x, launch __y) +{ + __x = __x & __y; return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +launch& +operator|=(launch& __x, launch __y) +{ + __x = __x | __y; return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +launch& +operator^=(launch& __x, launch __y) +{ + __x = __x ^ __y; return __x; +} + +#endif // !_LIBCPP_HAS_NO_STRONG_ENUMS + +//enum class future_status +_LIBCPP_DECLARE_STRONG_ENUM(future_status) +{ + ready, + timeout, + deferred +}; +_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status) + +_LIBCPP_FUNC_VIS +const error_category& future_category() _NOEXCEPT; + +inline _LIBCPP_INLINE_VISIBILITY +error_code +make_error_code(future_errc __e) _NOEXCEPT +{ + return error_code(static_cast<int>(__e), future_category()); +} + +inline _LIBCPP_INLINE_VISIBILITY +error_condition +make_error_condition(future_errc __e) _NOEXCEPT +{ + return error_condition(static_cast<int>(__e), future_category()); +} + +class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_FUTURE_ERROR future_error + : public logic_error +{ + error_code __ec_; +public: + future_error(error_code __ec); +#if _LIBCPP_STD_VERS > 14 + explicit future_error(future_errc _Ev) : logic_error(), __ec_(make_error_code(_Ev)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + const error_code& code() const _NOEXCEPT {return __ec_;} + + virtual ~future_error() _NOEXCEPT; +}; + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_NO_EXCEPTIONS +_LIBCPP_AVAILABILITY_FUTURE_ERROR +#endif +void __throw_future_error(future_errc _Ev) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw future_error(make_error_code(_Ev)); +#else + ((void)_Ev); + _VSTD::abort(); +#endif +} + +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state + : public __shared_count +{ +protected: + exception_ptr __exception_; + mutable mutex __mut_; + mutable condition_variable __cv_; + unsigned __state_; + + virtual void __on_zero_shared() _NOEXCEPT; + void __sub_wait(unique_lock<mutex>& __lk); +public: + enum + { + __constructed = 1, + __future_attached = 2, + ready = 4, + deferred = 8 + }; + + _LIBCPP_INLINE_VISIBILITY + __assoc_sub_state() : __state_(0) {} + + _LIBCPP_INLINE_VISIBILITY + bool __has_value() const + {return (__state_ & __constructed) || (__exception_ != nullptr);} + + _LIBCPP_INLINE_VISIBILITY + void __attach_future() { + lock_guard<mutex> __lk(__mut_); + bool __has_future_attached = (__state_ & __future_attached) != 0; + if (__has_future_attached) + __throw_future_error(future_errc::future_already_retrieved); + this->__add_shared(); + __state_ |= __future_attached; + } + + _LIBCPP_INLINE_VISIBILITY + void __set_deferred() {__state_ |= deferred;} + + void __make_ready(); + _LIBCPP_INLINE_VISIBILITY + bool __is_ready() const {return (__state_ & ready) != 0;} + + void set_value(); + void set_value_at_thread_exit(); + + void set_exception(exception_ptr __p); + void set_exception_at_thread_exit(exception_ptr __p); + + void copy(); + + void wait(); + template <class _Rep, class _Period> + future_status + _LIBCPP_INLINE_VISIBILITY + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const; + template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const; + + virtual void __execute(); +}; + +template <class _Clock, class _Duration> +future_status +__assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const +{ + unique_lock<mutex> __lk(__mut_); + if (__state_ & deferred) + return future_status::deferred; + while (!(__state_ & ready) && _Clock::now() < __abs_time) + __cv_.wait_until(__lk, __abs_time); + if (__state_ & ready) + return future_status::ready; + return future_status::timeout; +} + +template <class _Rep, class _Period> +inline +future_status +__assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const +{ + return wait_until(chrono::steady_clock::now() + __rel_time); +} + +template <class _Rp> +class _LIBCPP_AVAILABILITY_FUTURE __assoc_state + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + typedef typename aligned_storage<sizeof(_Rp), alignment_of<_Rp>::value>::type _Up; +protected: + _Up __value_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + + template <class _Arg> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void set_value(_Arg&& __arg); +#else + void set_value(_Arg& __arg); +#endif + + template <class _Arg> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void set_value_at_thread_exit(_Arg&& __arg); +#else + void set_value_at_thread_exit(_Arg& __arg); +#endif + + _Rp move(); + typename add_lvalue_reference<_Rp>::type copy(); +}; + +template <class _Rp> +void +__assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT +{ + if (this->__state_ & base::__constructed) + reinterpret_cast<_Rp*>(&__value_)->~_Rp(); + delete this; +} + +template <class _Rp> +template <class _Arg> +_LIBCPP_AVAILABILITY_FUTURE +void +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__assoc_state<_Rp>::set_value(_Arg&& __arg) +#else +__assoc_state<_Rp>::set_value(_Arg& __arg) +#endif +{ + unique_lock<mutex> __lk(this->__mut_); + if (this->__has_value()) + __throw_future_error(future_errc::promise_already_satisfied); + ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); + this->__state_ |= base::__constructed | base::ready; + __cv_.notify_all(); +} + +template <class _Rp> +template <class _Arg> +void +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg) +#else +__assoc_state<_Rp>::set_value_at_thread_exit(_Arg& __arg) +#endif +{ + unique_lock<mutex> __lk(this->__mut_); + if (this->__has_value()) + __throw_future_error(future_errc::promise_already_satisfied); + ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); + this->__state_ |= base::__constructed; + __thread_local_data()->__make_ready_at_thread_exit(this); +} + +template <class _Rp> +_Rp +__assoc_state<_Rp>::move() +{ + unique_lock<mutex> __lk(this->__mut_); + this->__sub_wait(__lk); + if (this->__exception_ != nullptr) + rethrow_exception(this->__exception_); + return _VSTD::move(*reinterpret_cast<_Rp*>(&__value_)); +} + +template <class _Rp> +typename add_lvalue_reference<_Rp>::type +__assoc_state<_Rp>::copy() +{ + unique_lock<mutex> __lk(this->__mut_); + this->__sub_wait(__lk); + if (this->__exception_ != nullptr) + rethrow_exception(this->__exception_); + return *reinterpret_cast<_Rp*>(&__value_); +} + +template <class _Rp> +class _LIBCPP_AVAILABILITY_FUTURE __assoc_state<_Rp&> + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + typedef _Rp* _Up; +protected: + _Up __value_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + + void set_value(_Rp& __arg); + void set_value_at_thread_exit(_Rp& __arg); + + _Rp& copy(); +}; + +template <class _Rp> +void +__assoc_state<_Rp&>::__on_zero_shared() _NOEXCEPT +{ + delete this; +} + +template <class _Rp> +void +__assoc_state<_Rp&>::set_value(_Rp& __arg) +{ + unique_lock<mutex> __lk(this->__mut_); + if (this->__has_value()) + __throw_future_error(future_errc::promise_already_satisfied); + __value_ = _VSTD::addressof(__arg); + this->__state_ |= base::__constructed | base::ready; + __cv_.notify_all(); +} + +template <class _Rp> +void +__assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg) +{ + unique_lock<mutex> __lk(this->__mut_); + if (this->__has_value()) + __throw_future_error(future_errc::promise_already_satisfied); + __value_ = _VSTD::addressof(__arg); + this->__state_ |= base::__constructed; + __thread_local_data()->__make_ready_at_thread_exit(this); +} + +template <class _Rp> +_Rp& +__assoc_state<_Rp&>::copy() +{ + unique_lock<mutex> __lk(this->__mut_); + this->__sub_wait(__lk); + if (this->__exception_ != nullptr) + rethrow_exception(this->__exception_); + return *__value_; +} + +template <class _Rp, class _Alloc> +class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc + : public __assoc_state<_Rp> +{ + typedef __assoc_state<_Rp> base; + _Alloc __alloc_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __assoc_state_alloc(const _Alloc& __a) + : __alloc_(__a) {} +}; + +template <class _Rp, class _Alloc> +void +__assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT +{ + if (this->__state_ & base::__constructed) + reinterpret_cast<_Rp*>(_VSTD::addressof(this->__value_))->~_Rp(); + typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al; + typedef allocator_traits<_Al> _ATraits; + typedef pointer_traits<typename _ATraits::pointer> _PTraits; + _Al __a(__alloc_); + this->~__assoc_state_alloc(); + __a.deallocate(_PTraits::pointer_to(*this), 1); +} + +template <class _Rp, class _Alloc> +class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc<_Rp&, _Alloc> + : public __assoc_state<_Rp&> +{ + typedef __assoc_state<_Rp&> base; + _Alloc __alloc_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __assoc_state_alloc(const _Alloc& __a) + : __alloc_(__a) {} +}; + +template <class _Rp, class _Alloc> +void +__assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT +{ + typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al; + typedef allocator_traits<_Al> _ATraits; + typedef pointer_traits<typename _ATraits::pointer> _PTraits; + _Al __a(__alloc_); + this->~__assoc_state_alloc(); + __a.deallocate(_PTraits::pointer_to(*this), 1); +} + +template <class _Alloc> +class _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state_alloc + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + _Alloc __alloc_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __assoc_sub_state_alloc(const _Alloc& __a) + : __alloc_(__a) {} +}; + +template <class _Alloc> +void +__assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT +{ + typedef typename __allocator_traits_rebind<_Alloc, __assoc_sub_state_alloc>::type _Al; + typedef allocator_traits<_Al> _ATraits; + typedef pointer_traits<typename _ATraits::pointer> _PTraits; + _Al __a(__alloc_); + this->~__assoc_sub_state_alloc(); + __a.deallocate(_PTraits::pointer_to(*this), 1); +} + +template <class _Rp, class _Fp> +class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state + : public __assoc_state<_Rp> +{ + typedef __assoc_state<_Rp> base; + + _Fp __func_; + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + explicit __deferred_assoc_state(_Fp&& __f); +#endif + + virtual void __execute(); +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Rp, class _Fp> +inline +__deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f) + : __func_(_VSTD::forward<_Fp>(__f)) +{ + this->__set_deferred(); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Rp, class _Fp> +void +__deferred_assoc_state<_Rp, _Fp>::__execute() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + this->set_value(__func_()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template <class _Fp> +class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state<void, _Fp> + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + + _Fp __func_; + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + explicit __deferred_assoc_state(_Fp&& __f); +#endif + + virtual void __execute(); +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Fp> +inline +__deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f) + : __func_(_VSTD::forward<_Fp>(__f)) +{ + this->__set_deferred(); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Fp> +void +__deferred_assoc_state<void, _Fp>::__execute() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __func_(); + this->set_value(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template <class _Rp, class _Fp> +class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state + : public __assoc_state<_Rp> +{ + typedef __assoc_state<_Rp> base; + + _Fp __func_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + explicit __async_assoc_state(_Fp&& __f); +#endif + + virtual void __execute(); +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Rp, class _Fp> +inline +__async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f) + : __func_(_VSTD::forward<_Fp>(__f)) +{ +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Rp, class _Fp> +void +__async_assoc_state<_Rp, _Fp>::__execute() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + this->set_value(__func_()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template <class _Rp, class _Fp> +void +__async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT +{ + this->wait(); + base::__on_zero_shared(); +} + +template <class _Fp> +class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state<void, _Fp> + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + + _Fp __func_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + explicit __async_assoc_state(_Fp&& __f); +#endif + + virtual void __execute(); +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Fp> +inline +__async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f) + : __func_(_VSTD::forward<_Fp>(__f)) +{ +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Fp> +void +__async_assoc_state<void, _Fp>::__execute() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __func_(); + this->set_value(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template <class _Fp> +void +__async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT +{ + this->wait(); + base::__on_zero_shared(); +} + +template <class _Rp> class _LIBCPP_TEMPLATE_VIS promise; +template <class _Rp> class _LIBCPP_TEMPLATE_VIS shared_future; + +// future + +template <class _Rp> class _LIBCPP_TEMPLATE_VIS future; + +template <class _Rp, class _Fp> +future<_Rp> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__make_deferred_assoc_state(_Fp&& __f); +#else +__make_deferred_assoc_state(_Fp __f); +#endif + +template <class _Rp, class _Fp> +future<_Rp> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__make_async_assoc_state(_Fp&& __f); +#else +__make_async_assoc_state(_Fp __f); +#endif + +template <class _Rp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future +{ + __assoc_state<_Rp>* __state_; + + explicit future(__assoc_state<_Rp>* __state); + + template <class> friend class promise; + template <class> friend class shared_future; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class _R1, class _Fp> + friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); + template <class _R1, class _Fp> + friend future<_R1> __make_async_assoc_state(_Fp&& __f); +#else + template <class _R1, class _Fp> + friend future<_R1> __make_deferred_assoc_state(_Fp __f); + template <class _R1, class _Fp> + friend future<_R1> __make_async_assoc_state(_Fp __f); +#endif + +public: + _LIBCPP_INLINE_VISIBILITY + future() _NOEXCEPT : __state_(nullptr) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + future(future&& __rhs) _NOEXCEPT + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + future(const future&) = delete; + future& operator=(const future&) = delete; + _LIBCPP_INLINE_VISIBILITY + future& operator=(future&& __rhs) _NOEXCEPT + { + future(std::move(__rhs)).swap(*this); + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + future(const future&); + future& operator=(const future&); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~future(); + _LIBCPP_INLINE_VISIBILITY + shared_future<_Rp> share() _NOEXCEPT; + + // retrieving the value + _Rp get(); + + _LIBCPP_INLINE_VISIBILITY + void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const _NOEXCEPT {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template <class _Clock, class _Duration> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template <class _Rp> +future<_Rp>::future(__assoc_state<_Rp>* __state) + : __state_(__state) +{ + __state_->__attach_future(); +} + +struct __release_shared_count +{ + void operator()(__shared_count* p) {p->__release_shared();} +}; + +template <class _Rp> +future<_Rp>::~future() +{ + if (__state_) + __state_->__release_shared(); +} + +template <class _Rp> +_Rp +future<_Rp>::get() +{ + unique_ptr<__shared_count, __release_shared_count> __(__state_); + __assoc_state<_Rp>* __s = __state_; + __state_ = nullptr; + return __s->move(); +} + +template <class _Rp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future<_Rp&> +{ + __assoc_state<_Rp&>* __state_; + + explicit future(__assoc_state<_Rp&>* __state); + + template <class> friend class promise; + template <class> friend class shared_future; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class _R1, class _Fp> + friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); + template <class _R1, class _Fp> + friend future<_R1> __make_async_assoc_state(_Fp&& __f); +#else + template <class _R1, class _Fp> + friend future<_R1> __make_deferred_assoc_state(_Fp __f); + template <class _R1, class _Fp> + friend future<_R1> __make_async_assoc_state(_Fp __f); +#endif + +public: + _LIBCPP_INLINE_VISIBILITY + future() _NOEXCEPT : __state_(nullptr) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + future(future&& __rhs) _NOEXCEPT + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + future(const future&) = delete; + future& operator=(const future&) = delete; + _LIBCPP_INLINE_VISIBILITY + future& operator=(future&& __rhs) _NOEXCEPT + { + future(std::move(__rhs)).swap(*this); + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + future(const future&); + future& operator=(const future&); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~future(); + _LIBCPP_INLINE_VISIBILITY + shared_future<_Rp&> share() _NOEXCEPT; + + // retrieving the value + _Rp& get(); + + _LIBCPP_INLINE_VISIBILITY + void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const _NOEXCEPT {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template <class _Clock, class _Duration> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template <class _Rp> +future<_Rp&>::future(__assoc_state<_Rp&>* __state) + : __state_(__state) +{ + __state_->__attach_future(); +} + +template <class _Rp> +future<_Rp&>::~future() +{ + if (__state_) + __state_->__release_shared(); +} + +template <class _Rp> +_Rp& +future<_Rp&>::get() +{ + unique_ptr<__shared_count, __release_shared_count> __(__state_); + __assoc_state<_Rp&>* __s = __state_; + __state_ = nullptr; + return __s->copy(); +} + +template <> +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE future<void> +{ + __assoc_sub_state* __state_; + + explicit future(__assoc_sub_state* __state); + + template <class> friend class promise; + template <class> friend class shared_future; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class _R1, class _Fp> + friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); + template <class _R1, class _Fp> + friend future<_R1> __make_async_assoc_state(_Fp&& __f); +#else + template <class _R1, class _Fp> + friend future<_R1> __make_deferred_assoc_state(_Fp __f); + template <class _R1, class _Fp> + friend future<_R1> __make_async_assoc_state(_Fp __f); +#endif + +public: + _LIBCPP_INLINE_VISIBILITY + future() _NOEXCEPT : __state_(nullptr) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + future(future&& __rhs) _NOEXCEPT + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + future(const future&) = delete; + future& operator=(const future&) = delete; + _LIBCPP_INLINE_VISIBILITY + future& operator=(future&& __rhs) _NOEXCEPT + { + future(std::move(__rhs)).swap(*this); + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + future(const future&); + future& operator=(const future&); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~future(); + _LIBCPP_INLINE_VISIBILITY + shared_future<void> share() _NOEXCEPT; + + // retrieving the value + void get(); + + _LIBCPP_INLINE_VISIBILITY + void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const _NOEXCEPT {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template <class _Clock, class _Duration> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template <class _Rp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT +{ + __x.swap(__y); +} + +// promise<R> + +template <class _Callable> class packaged_task; + +template <class _Rp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise +{ + __assoc_state<_Rp>* __state_; + + _LIBCPP_INLINE_VISIBILITY + explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} + + template <class> friend class packaged_task; +public: + promise(); + template <class _Alloc> + promise(allocator_arg_t, const _Alloc& __a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise(promise&& __rhs) _NOEXCEPT + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + promise(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~promise(); + + // assignment +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise& operator=(promise&& __rhs) _NOEXCEPT + { + promise(std::move(__rhs)).swap(*this); + return *this; + } + promise& operator=(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise& operator=(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} + + // retrieving the result + future<_Rp> get_future(); + + // setting the result + void set_value(const _Rp& __r); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void set_value(_Rp&& __r); +#endif + void set_exception(exception_ptr __p); + + // setting the result with deferred notification + void set_value_at_thread_exit(const _Rp& __r); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void set_value_at_thread_exit(_Rp&& __r); +#endif + void set_exception_at_thread_exit(exception_ptr __p); +}; + +template <class _Rp> +promise<_Rp>::promise() + : __state_(new __assoc_state<_Rp>) +{ +} + +template <class _Rp> +template <class _Alloc> +promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0) +{ + typedef __assoc_state_alloc<_Rp, _Alloc> _State; + typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a(__a0); + unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0); + __state_ = _VSTD::addressof(*__hold.release()); +} + +template <class _Rp> +promise<_Rp>::~promise() +{ + if (__state_) + { + if (!__state_->__has_value() && __state_->use_count() > 1) + __state_->set_exception(make_exception_ptr( + future_error(make_error_code(future_errc::broken_promise)) + )); + __state_->__release_shared(); + } +} + +template <class _Rp> +future<_Rp> +promise<_Rp>::get_future() +{ + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + return future<_Rp>(__state_); +} + +template <class _Rp> +void +promise<_Rp>::set_value(const _Rp& __r) +{ + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_value(__r); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Rp> +void +promise<_Rp>::set_value(_Rp&& __r) +{ + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_value(_VSTD::move(__r)); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Rp> +void +promise<_Rp>::set_exception(exception_ptr __p) +{ + _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" ); + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_exception(__p); +} + +template <class _Rp> +void +promise<_Rp>::set_value_at_thread_exit(const _Rp& __r) +{ + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_value_at_thread_exit(__r); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Rp> +void +promise<_Rp>::set_value_at_thread_exit(_Rp&& __r) +{ + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_value_at_thread_exit(_VSTD::move(__r)); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Rp> +void +promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p) +{ + _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception_at_thread_exit: received nullptr" ); + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_exception_at_thread_exit(__p); +} + +// promise<R&> + +template <class _Rp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise<_Rp&> +{ + __assoc_state<_Rp&>* __state_; + + _LIBCPP_INLINE_VISIBILITY + explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} + + template <class> friend class packaged_task; + +public: + promise(); + template <class _Allocator> + promise(allocator_arg_t, const _Allocator& __a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise(promise&& __rhs) _NOEXCEPT + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + promise(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~promise(); + + // assignment +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise& operator=(promise&& __rhs) _NOEXCEPT + { + promise(std::move(__rhs)).swap(*this); + return *this; + } + promise& operator=(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise& operator=(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} + + // retrieving the result + future<_Rp&> get_future(); + + // setting the result + void set_value(_Rp& __r); + void set_exception(exception_ptr __p); + + // setting the result with deferred notification + void set_value_at_thread_exit(_Rp&); + void set_exception_at_thread_exit(exception_ptr __p); +}; + +template <class _Rp> +promise<_Rp&>::promise() + : __state_(new __assoc_state<_Rp&>) +{ +} + +template <class _Rp> +template <class _Alloc> +promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0) +{ + typedef __assoc_state_alloc<_Rp&, _Alloc> _State; + typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a(__a0); + unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0); + __state_ = _VSTD::addressof(*__hold.release()); +} + +template <class _Rp> +promise<_Rp&>::~promise() +{ + if (__state_) + { + if (!__state_->__has_value() && __state_->use_count() > 1) + __state_->set_exception(make_exception_ptr( + future_error(make_error_code(future_errc::broken_promise)) + )); + __state_->__release_shared(); + } +} + +template <class _Rp> +future<_Rp&> +promise<_Rp&>::get_future() +{ + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + return future<_Rp&>(__state_); +} + +template <class _Rp> +void +promise<_Rp&>::set_value(_Rp& __r) +{ + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_value(__r); +} + +template <class _Rp> +void +promise<_Rp&>::set_exception(exception_ptr __p) +{ + _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" ); + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_exception(__p); +} + +template <class _Rp> +void +promise<_Rp&>::set_value_at_thread_exit(_Rp& __r) +{ + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_value_at_thread_exit(__r); +} + +template <class _Rp> +void +promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p) +{ + _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception_at_thread_exit: received nullptr" ); + if (__state_ == nullptr) + __throw_future_error(future_errc::no_state); + __state_->set_exception_at_thread_exit(__p); +} + +// promise<void> + +template <> +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE promise<void> +{ + __assoc_sub_state* __state_; + + _LIBCPP_INLINE_VISIBILITY + explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} + + template <class> friend class packaged_task; + +public: + promise(); + template <class _Allocator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + promise(allocator_arg_t, const _Allocator& __a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise(promise&& __rhs) _NOEXCEPT + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + promise(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~promise(); + + // assignment +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise& operator=(promise&& __rhs) _NOEXCEPT + { + promise(std::move(__rhs)).swap(*this); + return *this; + } + promise& operator=(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise& operator=(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} + + // retrieving the result + future<void> get_future(); + + // setting the result + void set_value(); + void set_exception(exception_ptr __p); + + // setting the result with deferred notification + void set_value_at_thread_exit(); + void set_exception_at_thread_exit(exception_ptr __p); +}; + +template <class _Alloc> +promise<void>::promise(allocator_arg_t, const _Alloc& __a0) +{ + typedef __assoc_sub_state_alloc<_Alloc> _State; + typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a(__a0); + unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0); + __state_ = _VSTD::addressof(*__hold.release()); +} + +template <class _Rp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT +{ + __x.swap(__y); +} + +template <class _Rp, class _Alloc> + struct _LIBCPP_TEMPLATE_VIS uses_allocator<promise<_Rp>, _Alloc> + : public true_type {}; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +// packaged_task + +template<class _Fp> class __packaged_task_base; + +template<class _Rp, class ..._ArgTypes> +class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_base<_Rp(_ArgTypes...)> +{ + __packaged_task_base(const __packaged_task_base&); + __packaged_task_base& operator=(const __packaged_task_base&); +public: + _LIBCPP_INLINE_VISIBILITY + __packaged_task_base() {} + _LIBCPP_INLINE_VISIBILITY + virtual ~__packaged_task_base() {} + virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _Rp operator()(_ArgTypes&& ...) = 0; +}; + +template<class _FD, class _Alloc, class _FB> class __packaged_task_func; + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)> + : public __packaged_task_base<_Rp(_ArgTypes...)> +{ + __compressed_pair<_Fp, _Alloc> __f_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __packaged_task_func(const _Fp& __f) : __f_(__f) {} + _LIBCPP_INLINE_VISIBILITY + explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f)) {} + _LIBCPP_INLINE_VISIBILITY + __packaged_task_func(const _Fp& __f, const _Alloc& __a) + : __f_(__f, __a) {} + _LIBCPP_INLINE_VISIBILITY + __packaged_task_func(_Fp&& __f, const _Alloc& __a) + : __f_(_VSTD::move(__f), __a) {} + virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _Rp operator()(_ArgTypes&& ... __args); +}; + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +void +__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to( + __packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT +{ + ::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second())); +} + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +void +__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() +{ + __f_.~__compressed_pair<_Fp, _Alloc>(); +} + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +void +__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() +{ + typedef typename __allocator_traits_rebind<_Alloc, __packaged_task_func>::type _Ap; + typedef allocator_traits<_Ap> _ATraits; + typedef pointer_traits<typename _ATraits::pointer> _PTraits; + _Ap __a(__f_.second()); + __f_.~__compressed_pair<_Fp, _Alloc>(); + __a.deallocate(_PTraits::pointer_to(*this), 1); +} + +template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> +_Rp +__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) +{ + return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); +} + +template <class _Callable> class __packaged_task_function; + +template<class _Rp, class ..._ArgTypes> +class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_function<_Rp(_ArgTypes...)> +{ + typedef __packaged_task_base<_Rp(_ArgTypes...)> __base; + typename aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _Rp result_type; + + // construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY + __packaged_task_function() _NOEXCEPT : __f_(nullptr) {} + template<class _Fp> + __packaged_task_function(_Fp&& __f); + template<class _Fp, class _Alloc> + __packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f); + + __packaged_task_function(__packaged_task_function&&) _NOEXCEPT; + __packaged_task_function& operator=(__packaged_task_function&&) _NOEXCEPT; + + __packaged_task_function(const __packaged_task_function&) = delete; + __packaged_task_function& operator=(const __packaged_task_function&) = delete; + + ~__packaged_task_function(); + + void swap(__packaged_task_function&) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + _Rp operator()(_ArgTypes...) const; +}; + +template<class _Rp, class ..._ArgTypes> +__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) _NOEXCEPT +{ + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__move_to(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = nullptr; + } +} + +template<class _Rp, class ..._ArgTypes> +template <class _Fp> +__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f) + : __f_(nullptr) +{ + typedef typename remove_reference<typename decay<_Fp>::type>::type _FR; + typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(_VSTD::forward<_Fp>(__f)); + } + else + { + typedef allocator<_FF> _Ap; + _Ap __a; + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a)); + __f_ = __hold.release(); + } +} + +template<class _Rp, class ..._ArgTypes> +template <class _Fp, class _Alloc> +__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function( + allocator_arg_t, const _Alloc& __a0, _Fp&& __f) + : __f_(nullptr) +{ + typedef typename remove_reference<typename decay<_Fp>::type>::type _FR; + typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(_VSTD::forward<_Fp>(__f)); + } + else + { + typedef typename __allocator_traits_rebind<_Alloc, _FF>::type _Ap; + _Ap __a(__a0); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new (static_cast<void*>(_VSTD::addressof(*__hold.get()))) + _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a)); + __f_ = _VSTD::addressof(*__hold.release()); + } +} + +template<class _Rp, class ..._ArgTypes> +__packaged_task_function<_Rp(_ArgTypes...)>& +__packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f) _NOEXCEPT +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + __f_ = nullptr; + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__move_to(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = nullptr; + } + return *this; +} + +template<class _Rp, class ..._ArgTypes> +__packaged_task_function<_Rp(_ArgTypes...)>::~__packaged_task_function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template<class _Rp, class ..._ArgTypes> +void +__packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f) _NOEXCEPT +{ + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage<sizeof(__buf_)>::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__move_to(__t); + __f_->destroy(); + __f_ = nullptr; + __f.__f_->__move_to((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = nullptr; + __f_ = (__base*)&__buf_; + __t->__move_to((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__move_to((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__move_to((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template<class _Rp, class ..._ArgTypes> +inline +_Rp +__packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const +{ + return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); +} + +template<class _Rp, class ..._ArgTypes> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task<_Rp(_ArgTypes...)> +{ +public: + typedef _Rp result_type; // extension + +private: + __packaged_task_function<result_type(_ArgTypes...)> __f_; + promise<result_type> __p_; + +public: + // construction and destruction + _LIBCPP_INLINE_VISIBILITY + packaged_task() _NOEXCEPT : __p_(nullptr) {} + template <class _Fp, + class = typename enable_if + < + !is_same< + typename __uncvref<_Fp>::type, + packaged_task + >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} + template <class _Fp, class _Allocator, + class = typename enable_if + < + !is_same< + typename __uncvref<_Fp>::type, + packaged_task + >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) + : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), + __p_(allocator_arg, __a) {} + // ~packaged_task() = default; + + // no copy + packaged_task(const packaged_task&) = delete; + packaged_task& operator=(const packaged_task&) = delete; + + // move support + _LIBCPP_INLINE_VISIBILITY + packaged_task(packaged_task&& __other) _NOEXCEPT + : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} + _LIBCPP_INLINE_VISIBILITY + packaged_task& operator=(packaged_task&& __other) _NOEXCEPT + { + __f_ = _VSTD::move(__other.__f_); + __p_ = _VSTD::move(__other.__p_); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + void swap(packaged_task& __other) _NOEXCEPT + { + __f_.swap(__other.__f_); + __p_.swap(__other.__p_); + } + + _LIBCPP_INLINE_VISIBILITY + bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;} + + // result retrieval + _LIBCPP_INLINE_VISIBILITY + future<result_type> get_future() {return __p_.get_future();} + + // execution + void operator()(_ArgTypes... __args); + void make_ready_at_thread_exit(_ArgTypes... __args); + + void reset(); +}; + +template<class _Rp, class ..._ArgTypes> +void +packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args) +{ + if (__p_.__state_ == nullptr) + __throw_future_error(future_errc::no_state); + if (__p_.__state_->__has_value()) + __throw_future_error(future_errc::promise_already_satisfied); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __p_.set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Rp, class ..._ArgTypes> +void +packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) +{ + if (__p_.__state_ == nullptr) + __throw_future_error(future_errc::no_state); + if (__p_.__state_->__has_value()) + __throw_future_error(future_errc::promise_already_satisfied); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __p_.set_exception_at_thread_exit(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Rp, class ..._ArgTypes> +void +packaged_task<_Rp(_ArgTypes...)>::reset() +{ + if (!valid()) + __throw_future_error(future_errc::no_state); + __p_ = promise<result_type>(); +} + +template<class ..._ArgTypes> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task<void(_ArgTypes...)> +{ +public: + typedef void result_type; // extension + +private: + __packaged_task_function<result_type(_ArgTypes...)> __f_; + promise<result_type> __p_; + +public: + // construction and destruction + _LIBCPP_INLINE_VISIBILITY + packaged_task() _NOEXCEPT : __p_(nullptr) {} + template <class _Fp, + class = typename enable_if + < + !is_same< + typename __uncvref<_Fp>::type, + packaged_task + >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} + template <class _Fp, class _Allocator, + class = typename enable_if + < + !is_same< + typename __uncvref<_Fp>::type, + packaged_task + >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) + : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), + __p_(allocator_arg, __a) {} + // ~packaged_task() = default; + + // no copy + packaged_task(const packaged_task&) = delete; + packaged_task& operator=(const packaged_task&) = delete; + + // move support + _LIBCPP_INLINE_VISIBILITY + packaged_task(packaged_task&& __other) _NOEXCEPT + : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} + _LIBCPP_INLINE_VISIBILITY + packaged_task& operator=(packaged_task&& __other) _NOEXCEPT + { + __f_ = _VSTD::move(__other.__f_); + __p_ = _VSTD::move(__other.__p_); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + void swap(packaged_task& __other) _NOEXCEPT + { + __f_.swap(__other.__f_); + __p_.swap(__other.__p_); + } + + _LIBCPP_INLINE_VISIBILITY + bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;} + + // result retrieval + _LIBCPP_INLINE_VISIBILITY + future<result_type> get_future() {return __p_.get_future();} + + // execution + void operator()(_ArgTypes... __args); + void make_ready_at_thread_exit(_ArgTypes... __args); + + void reset(); +}; + +template<class ..._ArgTypes> +void +packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args) +{ + if (__p_.__state_ == nullptr) + __throw_future_error(future_errc::no_state); + if (__p_.__state_->__has_value()) + __throw_future_error(future_errc::promise_already_satisfied); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __f_(_VSTD::forward<_ArgTypes>(__args)...); + __p_.set_value(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __p_.set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class ..._ArgTypes> +void +packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) +{ + if (__p_.__state_ == nullptr) + __throw_future_error(future_errc::no_state); + if (__p_.__state_->__has_value()) + __throw_future_error(future_errc::promise_already_satisfied); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __f_(_VSTD::forward<_ArgTypes>(__args)...); + __p_.set_value_at_thread_exit(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __p_.set_exception_at_thread_exit(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class ..._ArgTypes> +void +packaged_task<void(_ArgTypes...)>::reset() +{ + if (!valid()) + __throw_future_error(future_errc::no_state); + __p_ = promise<result_type>(); +} + +template <class _Callable> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT +{ + __x.swap(__y); +} + +template <class _Callable, class _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<packaged_task<_Callable>, _Alloc> + : public true_type {}; + +template <class _Rp, class _Fp> +future<_Rp> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__make_deferred_assoc_state(_Fp&& __f) +#else +__make_deferred_assoc_state(_Fp __f) +#endif +{ + unique_ptr<__deferred_assoc_state<_Rp, _Fp>, __release_shared_count> + __h(new __deferred_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f))); + return future<_Rp>(__h.get()); +} + +template <class _Rp, class _Fp> +future<_Rp> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__make_async_assoc_state(_Fp&& __f) +#else +__make_async_assoc_state(_Fp __f) +#endif +{ + unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count> + __h(new __async_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f))); + _VSTD::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach(); + return future<_Rp>(__h.get()); +} + +template <class _Fp, class... _Args> +class __async_func +{ + tuple<_Fp, _Args...> __f_; + +public: + typedef typename __invoke_of<_Fp, _Args...>::type _Rp; + + _LIBCPP_INLINE_VISIBILITY + explicit __async_func(_Fp&& __f, _Args&&... __args) + : __f_(_VSTD::move(__f), _VSTD::move(__args)...) {} + + _LIBCPP_INLINE_VISIBILITY + __async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {} + + _Rp operator()() + { + typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index; + return __execute(_Index()); + } +private: + template <size_t ..._Indices> + _Rp + __execute(__tuple_indices<_Indices...>) + { + return __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...); + } +}; + +inline _LIBCPP_INLINE_VISIBILITY bool __does_policy_contain(launch __policy, launch __value ) +{ return (int(__policy) & int(__value)) != 0; } + +template <class _Fp, class... _Args> +_LIBCPP_NODISCARD_AFTER_CXX17 +future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type> +async(launch __policy, _Fp&& __f, _Args&&... __args) +{ + typedef __async_func<typename decay<_Fp>::type, typename decay<_Args>::type...> _BF; + typedef typename _BF::_Rp _Rp; + +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif + if (__does_policy_contain(__policy, launch::async)) + return _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), + __decay_copy(_VSTD::forward<_Args>(__args))...)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch ( ... ) { if (__policy == launch::async) throw ; } +#endif + + if (__does_policy_contain(__policy, launch::deferred)) + return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), + __decay_copy(_VSTD::forward<_Args>(__args))...)); + return future<_Rp>{}; +} + +template <class _Fp, class... _Args> +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type> +async(_Fp&& __f, _Args&&... __args) +{ + return _VSTD::async(launch::any, _VSTD::forward<_Fp>(__f), + _VSTD::forward<_Args>(__args)...); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +// shared_future + +template <class _Rp> +class _LIBCPP_TEMPLATE_VIS shared_future +{ + __assoc_state<_Rp>* __state_; + +public: + _LIBCPP_INLINE_VISIBILITY + shared_future() _NOEXCEPT : __state_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY + shared_future(const shared_future& __rhs) _NOEXCEPT : __state_(__rhs.__state_) + {if (__state_) __state_->__add_shared();} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future(future<_Rp>&& __f) _NOEXCEPT : __state_(__f.__state_) + {__f.__state_ = nullptr;} + _LIBCPP_INLINE_VISIBILITY + shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) + {__rhs.__state_ = nullptr;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~shared_future(); + shared_future& operator=(const shared_future& __rhs) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future& operator=(shared_future&& __rhs) _NOEXCEPT + { + shared_future(std::move(__rhs)).swap(*this); + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + // retrieving the value + _LIBCPP_INLINE_VISIBILITY + const _Rp& get() const {return __state_->copy();} + + _LIBCPP_INLINE_VISIBILITY + void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const _NOEXCEPT {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template <class _Clock, class _Duration> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template <class _Rp> +shared_future<_Rp>::~shared_future() +{ + if (__state_) + __state_->__release_shared(); +} + +template <class _Rp> +shared_future<_Rp>& +shared_future<_Rp>::operator=(const shared_future& __rhs) _NOEXCEPT +{ + if (__rhs.__state_) + __rhs.__state_->__add_shared(); + if (__state_) + __state_->__release_shared(); + __state_ = __rhs.__state_; + return *this; +} + +template <class _Rp> +class _LIBCPP_TEMPLATE_VIS shared_future<_Rp&> +{ + __assoc_state<_Rp&>* __state_; + +public: + _LIBCPP_INLINE_VISIBILITY + shared_future() _NOEXCEPT : __state_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY + shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) + {if (__state_) __state_->__add_shared();} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future(future<_Rp&>&& __f) _NOEXCEPT : __state_(__f.__state_) + {__f.__state_ = nullptr;} + _LIBCPP_INLINE_VISIBILITY + shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) + {__rhs.__state_ = nullptr;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~shared_future(); + shared_future& operator=(const shared_future& __rhs); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future& operator=(shared_future&& __rhs) _NOEXCEPT + { + shared_future(std::move(__rhs)).swap(*this); + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + // retrieving the value + _LIBCPP_INLINE_VISIBILITY + _Rp& get() const {return __state_->copy();} + + _LIBCPP_INLINE_VISIBILITY + void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const _NOEXCEPT {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template <class _Clock, class _Duration> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template <class _Rp> +shared_future<_Rp&>::~shared_future() +{ + if (__state_) + __state_->__release_shared(); +} + +template <class _Rp> +shared_future<_Rp&>& +shared_future<_Rp&>::operator=(const shared_future& __rhs) +{ + if (__rhs.__state_) + __rhs.__state_->__add_shared(); + if (__state_) + __state_->__release_shared(); + __state_ = __rhs.__state_; + return *this; +} + +template <> +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE shared_future<void> +{ + __assoc_sub_state* __state_; + +public: + _LIBCPP_INLINE_VISIBILITY + shared_future() _NOEXCEPT : __state_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY + shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) + {if (__state_) __state_->__add_shared();} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future(future<void>&& __f) _NOEXCEPT : __state_(__f.__state_) + {__f.__state_ = nullptr;} + _LIBCPP_INLINE_VISIBILITY + shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) + {__rhs.__state_ = nullptr;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~shared_future(); + shared_future& operator=(const shared_future& __rhs); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future& operator=(shared_future&& __rhs) _NOEXCEPT + { + shared_future(std::move(__rhs)).swap(*this); + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + // retrieving the value + _LIBCPP_INLINE_VISIBILITY + void get() const {__state_->copy();} + + _LIBCPP_INLINE_VISIBILITY + void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const _NOEXCEPT {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template <class _Clock, class _Duration> + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template <class _Rp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT +{ + __x.swap(__y); +} + +template <class _Rp> +inline +shared_future<_Rp> +future<_Rp>::share() _NOEXCEPT +{ + return shared_future<_Rp>(_VSTD::move(*this)); +} + +template <class _Rp> +inline +shared_future<_Rp&> +future<_Rp&>::share() _NOEXCEPT +{ + return shared_future<_Rp&>(_VSTD::move(*this)); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +inline +shared_future<void> +future<void>::share() _NOEXCEPT +{ + return shared_future<void>(_VSTD::move(*this)); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +_LIBCPP_END_NAMESPACE_STD + +#endif // !_LIBCPP_HAS_NO_THREADS + +#endif // _LIBCPP_FUTURE diff --git a/android/x86/include/v8/libc++/initializer_list b/android/x86/include/v8/libc++/initializer_list new file mode 100755 index 00000000..6c4493b7 --- /dev/null +++ b/android/x86/include/v8/libc++/initializer_list @@ -0,0 +1,117 @@ +// -*- C++ -*- +//===----------------------- initializer_list -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_INITIALIZER_LIST +#define _LIBCPP_INITIALIZER_LIST + +/* + initializer_list synopsis + +namespace std +{ + +template<class E> +class initializer_list +{ +public: + typedef E value_type; + typedef const E& reference; + typedef const E& const_reference; + typedef size_t size_type; + + typedef const E* iterator; + typedef const E* const_iterator; + + initializer_list() noexcept; // constexpr in C++14 + + size_t size() const noexcept; // constexpr in C++14 + const E* begin() const noexcept; // constexpr in C++14 + const E* end() const noexcept; // constexpr in C++14 +}; + +template<class E> const E* begin(initializer_list<E> il) noexcept; // constexpr in C++14 +template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14 + +} // std + +*/ + +#include <__config> +#include <cstddef> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace std // purposefully not versioned +{ + +#ifndef _LIBCPP_CXX03_LANG + +template<class _Ep> +class _LIBCPP_TEMPLATE_VIS initializer_list +{ + const _Ep* __begin_; + size_t __size_; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 + initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT + : __begin_(__b), + __size_(__s) + {} +public: + typedef _Ep value_type; + typedef const _Ep& reference; + typedef const _Ep& const_reference; + typedef size_t size_type; + + typedef const _Ep* iterator; + typedef const _Ep* const_iterator; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 + initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {} + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 + size_t size() const _NOEXCEPT {return __size_;} + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 + const _Ep* begin() const _NOEXCEPT {return __begin_;} + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 + const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;} +}; + +template<class _Ep> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Ep* +begin(initializer_list<_Ep> __il) _NOEXCEPT +{ + return __il.begin(); +} + +template<class _Ep> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Ep* +end(initializer_list<_Ep> __il) _NOEXCEPT +{ + return __il.end(); +} + +#endif // !defined(_LIBCPP_CXX03_LANG) + +} // std + +#endif // _LIBCPP_INITIALIZER_LIST diff --git a/android/x86/include/v8/libc++/inttypes.h b/android/x86/include/v8/libc++/inttypes.h new file mode 100755 index 00000000..0f1d4f45 --- /dev/null +++ b/android/x86/include/v8/libc++/inttypes.h @@ -0,0 +1,257 @@ +// -*- C++ -*- +//===--------------------------- inttypes.h -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_INTTYPES_H +#define _LIBCPP_INTTYPES_H + +/* + inttypes.h synopsis + +This entire header is C99 / C++0X + +#include <stdint.h> // <cinttypes> includes <cstdint> + +Macros: + + PRId8 + PRId16 + PRId32 + PRId64 + + PRIdLEAST8 + PRIdLEAST16 + PRIdLEAST32 + PRIdLEAST64 + + PRIdFAST8 + PRIdFAST16 + PRIdFAST32 + PRIdFAST64 + + PRIdMAX + PRIdPTR + + PRIi8 + PRIi16 + PRIi32 + PRIi64 + + PRIiLEAST8 + PRIiLEAST16 + PRIiLEAST32 + PRIiLEAST64 + + PRIiFAST8 + PRIiFAST16 + PRIiFAST32 + PRIiFAST64 + + PRIiMAX + PRIiPTR + + PRIo8 + PRIo16 + PRIo32 + PRIo64 + + PRIoLEAST8 + PRIoLEAST16 + PRIoLEAST32 + PRIoLEAST64 + + PRIoFAST8 + PRIoFAST16 + PRIoFAST32 + PRIoFAST64 + + PRIoMAX + PRIoPTR + + PRIu8 + PRIu16 + PRIu32 + PRIu64 + + PRIuLEAST8 + PRIuLEAST16 + PRIuLEAST32 + PRIuLEAST64 + + PRIuFAST8 + PRIuFAST16 + PRIuFAST32 + PRIuFAST64 + + PRIuMAX + PRIuPTR + + PRIx8 + PRIx16 + PRIx32 + PRIx64 + + PRIxLEAST8 + PRIxLEAST16 + PRIxLEAST32 + PRIxLEAST64 + + PRIxFAST8 + PRIxFAST16 + PRIxFAST32 + PRIxFAST64 + + PRIxMAX + PRIxPTR + + PRIX8 + PRIX16 + PRIX32 + PRIX64 + + PRIXLEAST8 + PRIXLEAST16 + PRIXLEAST32 + PRIXLEAST64 + + PRIXFAST8 + PRIXFAST16 + PRIXFAST32 + PRIXFAST64 + + PRIXMAX + PRIXPTR + + SCNd8 + SCNd16 + SCNd32 + SCNd64 + + SCNdLEAST8 + SCNdLEAST16 + SCNdLEAST32 + SCNdLEAST64 + + SCNdFAST8 + SCNdFAST16 + SCNdFAST32 + SCNdFAST64 + + SCNdMAX + SCNdPTR + + SCNi8 + SCNi16 + SCNi32 + SCNi64 + + SCNiLEAST8 + SCNiLEAST16 + SCNiLEAST32 + SCNiLEAST64 + + SCNiFAST8 + SCNiFAST16 + SCNiFAST32 + SCNiFAST64 + + SCNiMAX + SCNiPTR + + SCNo8 + SCNo16 + SCNo32 + SCNo64 + + SCNoLEAST8 + SCNoLEAST16 + SCNoLEAST32 + SCNoLEAST64 + + SCNoFAST8 + SCNoFAST16 + SCNoFAST32 + SCNoFAST64 + + SCNoMAX + SCNoPTR + + SCNu8 + SCNu16 + SCNu32 + SCNu64 + + SCNuLEAST8 + SCNuLEAST16 + SCNuLEAST32 + SCNuLEAST64 + + SCNuFAST8 + SCNuFAST16 + SCNuFAST32 + SCNuFAST64 + + SCNuMAX + SCNuPTR + + SCNx8 + SCNx16 + SCNx32 + SCNx64 + + SCNxLEAST8 + SCNxLEAST16 + SCNxLEAST32 + SCNxLEAST64 + + SCNxFAST8 + SCNxFAST16 + SCNxFAST32 + SCNxFAST64 + + SCNxMAX + SCNxPTR + +Types: + + imaxdiv_t + +intmax_t imaxabs(intmax_t j); +imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom); +intmax_t strtoimax(const char* restrict nptr, char** restrict endptr, int base); +uintmax_t strtoumax(const char* restrict nptr, char** restrict endptr, int base); +intmax_t wcstoimax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); +uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +/* C99 stdlib (e.g. glibc < 2.18) does not provide format macros needed + for C++11 unless __STDC_FORMAT_MACROS is defined +*/ +#if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS) +# define __STDC_FORMAT_MACROS +#endif + +#include_next <inttypes.h> + +#ifdef __cplusplus + +#include <stdint.h> + +#undef imaxabs +#undef imaxdiv + +#endif // __cplusplus + +#endif // _LIBCPP_INTTYPES_H diff --git a/android/x86/include/v8/libc++/iomanip b/android/x86/include/v8/libc++/iomanip new file mode 100755 index 00000000..82b7603a --- /dev/null +++ b/android/x86/include/v8/libc++/iomanip @@ -0,0 +1,670 @@ +// -*- C++ -*- +//===--------------------------- iomanip ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_IOMANIP +#define _LIBCPP_IOMANIP + +/* + iomanip synopsis + +namespace std { + +// types T1, T2, ... are unspecified implementation types +T1 resetiosflags(ios_base::fmtflags mask); +T2 setiosflags (ios_base::fmtflags mask); +T3 setbase(int base); +template<charT> T4 setfill(charT c); +T5 setprecision(int n); +T6 setw(int n); +template <class moneyT> T7 get_money(moneyT& mon, bool intl = false); +template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false); +template <class charT> T9 get_time(struct tm* tmb, const charT* fmt); +template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt); + +template <class charT> + T11 quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\')); // C++14 + +template <class charT, class traits, class Allocator> + T12 quoted(const basic_string<charT, traits, Allocator>& s, + charT delim=charT('"'), charT escape=charT('\\')); // C++14 + +template <class charT, class traits, class Allocator> + T13 quoted(basic_string<charT, traits, Allocator>& s, + charT delim=charT('"'), charT escape=charT('\\')); // C++14 + +} // std + +*/ + +#include <__config> +#include <__string> +#include <istream> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// resetiosflags + +class __iom_t1 +{ + ios_base::fmtflags __mask_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t1(ios_base::fmtflags __m) : __mask_(__m) {} + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t1& __x) + { + __is.unsetf(__x.__mask_); + return __is; + } + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t1& __x) + { + __os.unsetf(__x.__mask_); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t1 +resetiosflags(ios_base::fmtflags __mask) +{ + return __iom_t1(__mask); +} + +// setiosflags + +class __iom_t2 +{ + ios_base::fmtflags __mask_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t2(ios_base::fmtflags __m) : __mask_(__m) {} + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t2& __x) + { + __is.setf(__x.__mask_); + return __is; + } + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t2& __x) + { + __os.setf(__x.__mask_); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t2 +setiosflags(ios_base::fmtflags __mask) +{ + return __iom_t2(__mask); +} + +// setbase + +class __iom_t3 +{ + int __base_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t3(int __b) : __base_(__b) {} + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t3& __x) + { + __is.setf(__x.__base_ == 8 ? ios_base::oct : + __x.__base_ == 10 ? ios_base::dec : + __x.__base_ == 16 ? ios_base::hex : + ios_base::fmtflags(0), ios_base::basefield); + return __is; + } + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t3& __x) + { + __os.setf(__x.__base_ == 8 ? ios_base::oct : + __x.__base_ == 10 ? ios_base::dec : + __x.__base_ == 16 ? ios_base::hex : + ios_base::fmtflags(0), ios_base::basefield); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t3 +setbase(int __base) +{ + return __iom_t3(__base); +} + +// setfill + +template<class _CharT> +class __iom_t4 +{ + _CharT __fill_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t4(_CharT __c) : __fill_(__c) {} + + template <class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t4& __x) + { + __os.fill(__x.__fill_); + return __os; + } +}; + +template<class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +__iom_t4<_CharT> +setfill(_CharT __c) +{ + return __iom_t4<_CharT>(__c); +} + +// setprecision + +class __iom_t5 +{ + int __n_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t5(int __n) : __n_(__n) {} + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t5& __x) + { + __is.precision(__x.__n_); + return __is; + } + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t5& __x) + { + __os.precision(__x.__n_); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t5 +setprecision(int __n) +{ + return __iom_t5(__n); +} + +// setw + +class __iom_t6 +{ + int __n_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t6(int __n) : __n_(__n) {} + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t6& __x) + { + __is.width(__x.__n_); + return __is; + } + + template <class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t6& __x) + { + __os.width(__x.__n_); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t6 +setw(int __n) +{ + return __iom_t6(__n); +} + +// get_money + +template <class _MoneyT> class __iom_t7; + +template <class _CharT, class _Traits, class _MoneyT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x); + +template <class _MoneyT> +class __iom_t7 +{ + _MoneyT& __mon_; + bool __intl_; +public: + _LIBCPP_INLINE_VISIBILITY + __iom_t7(_MoneyT& __mon, bool __intl) + : __mon_(__mon), __intl_(__intl) {} + + template <class _CharT, class _Traits, class _Mp> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_Mp>& __x); +}; + +template <class _CharT, class _Traits, class _MoneyT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __s(__is); + if (__s) + { + typedef istreambuf_iterator<_CharT, _Traits> _Ip; + typedef money_get<_CharT, _Ip> _Fp; + ios_base::iostate __err = ios_base::goodbit; + const _Fp& __mf = use_facet<_Fp>(__is.getloc()); + __mf.get(_Ip(__is), _Ip(), __x.__intl_, __is, __err, __x.__mon_); + __is.setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +template <class _MoneyT> +inline _LIBCPP_INLINE_VISIBILITY +__iom_t7<_MoneyT> +get_money(_MoneyT& __mon, bool __intl = false) +{ + return __iom_t7<_MoneyT>(__mon, __intl); +} + +// put_money + +template <class _MoneyT> class __iom_t8; + +template <class _CharT, class _Traits, class _MoneyT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x); + +template <class _MoneyT> +class __iom_t8 +{ + const _MoneyT& __mon_; + bool __intl_; +public: + _LIBCPP_INLINE_VISIBILITY + __iom_t8(const _MoneyT& __mon, bool __intl) + : __mon_(__mon), __intl_(__intl) {} + + template <class _CharT, class _Traits, class _Mp> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_Mp>& __x); +}; + +template <class _CharT, class _Traits, class _MoneyT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_ostream<_CharT, _Traits>::sentry __s(__os); + if (__s) + { + typedef ostreambuf_iterator<_CharT, _Traits> _Op; + typedef money_put<_CharT, _Op> _Fp; + const _Fp& __mf = use_facet<_Fp>(__os.getloc()); + if (__mf.put(_Op(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed()) + __os.setstate(ios_base::badbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __os.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __os; +} + +template <class _MoneyT> +inline _LIBCPP_INLINE_VISIBILITY +__iom_t8<_MoneyT> +put_money(const _MoneyT& __mon, bool __intl = false) +{ + return __iom_t8<_MoneyT>(__mon, __intl); +} + +// get_time + +template <class _CharT> class __iom_t9; + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x); + +template <class _CharT> +class __iom_t9 +{ + tm* __tm_; + const _CharT* __fmt_; +public: + _LIBCPP_INLINE_VISIBILITY + __iom_t9(tm* __tm, const _CharT* __fmt) + : __tm_(__tm), __fmt_(__fmt) {} + + template <class _Cp, class _Traits> + friend + basic_istream<_Cp, _Traits>& + operator>>(basic_istream<_Cp, _Traits>& __is, const __iom_t9<_Cp>& __x); +}; + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __s(__is); + if (__s) + { + typedef istreambuf_iterator<_CharT, _Traits> _Ip; + typedef time_get<_CharT, _Ip> _Fp; + ios_base::iostate __err = ios_base::goodbit; + const _Fp& __tf = use_facet<_Fp>(__is.getloc()); + __tf.get(_Ip(__is), _Ip(), __is, __err, __x.__tm_, + __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)); + __is.setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +__iom_t9<_CharT> +get_time(tm* __tm, const _CharT* __fmt) +{ + return __iom_t9<_CharT>(__tm, __fmt); +} + +// put_time + +template <class _CharT> class __iom_t10; + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x); + +template <class _CharT> +class __iom_t10 +{ + const tm* __tm_; + const _CharT* __fmt_; +public: + _LIBCPP_INLINE_VISIBILITY + __iom_t10(const tm* __tm, const _CharT* __fmt) + : __tm_(__tm), __fmt_(__fmt) {} + + template <class _Cp, class _Traits> + friend + basic_ostream<_Cp, _Traits>& + operator<<(basic_ostream<_Cp, _Traits>& __os, const __iom_t10<_Cp>& __x); +}; + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_ostream<_CharT, _Traits>::sentry __s(__os); + if (__s) + { + typedef ostreambuf_iterator<_CharT, _Traits> _Op; + typedef time_put<_CharT, _Op> _Fp; + const _Fp& __tf = use_facet<_Fp>(__os.getloc()); + if (__tf.put(_Op(__os), __os, __os.fill(), __x.__tm_, + __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)).failed()) + __os.setstate(ios_base::badbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __os.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __os; +} + +template <class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +__iom_t10<_CharT> +put_time(const tm* __tm, const _CharT* __fmt) +{ + return __iom_t10<_CharT>(__tm, __fmt); +} + +template <class _CharT, class _Traits, class _ForwardIterator> +std::basic_ostream<_CharT, _Traits> & +__quoted_output ( basic_ostream<_CharT, _Traits> &__os, + _ForwardIterator __first, _ForwardIterator __last, _CharT __delim, _CharT __escape ) +{ + _VSTD::basic_string<_CharT, _Traits> __str; + __str.push_back(__delim); + for ( ; __first != __last; ++ __first ) + { + if (_Traits::eq (*__first, __escape) || _Traits::eq (*__first, __delim)) + __str.push_back(__escape); + __str.push_back(*__first); + } + __str.push_back(__delim); + return __put_character_sequence(__os, __str.data(), __str.size()); +} + +template <class _CharT, class _Traits, class _String> +basic_istream<_CharT, _Traits> & +__quoted_input ( basic_istream<_CharT, _Traits> &__is, _String & __string, _CharT __delim, _CharT __escape ) +{ + __string.clear (); + _CharT __c; + __is >> __c; + if ( __is.fail ()) + return __is; + + if (!_Traits::eq (__c, __delim)) // no delimiter, read the whole string + { + __is.unget (); + __is >> __string; + return __is; + } + + __save_flags<_CharT, _Traits> sf(__is); + noskipws (__is); + while (true) + { + __is >> __c; + if ( __is.fail ()) + break; + if (_Traits::eq (__c, __escape)) + { + __is >> __c; + if ( __is.fail ()) + break; + } + else if (_Traits::eq (__c, __delim)) + break; + __string.push_back ( __c ); + } + return __is; +} + + +template <class _CharT, class _Traits, class _Iter> +basic_ostream<_CharT, _Traits>& operator<<( + basic_ostream<_CharT, _Traits>& __os, + const __quoted_output_proxy<_CharT, _Iter, _Traits> & __proxy) +{ + return __quoted_output (__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape); +} + +template <class _CharT, class _Traits, class _Allocator> +struct __quoted_proxy +{ + basic_string<_CharT, _Traits, _Allocator> &__string; + _CharT __delim; + _CharT __escape; + + __quoted_proxy(basic_string<_CharT, _Traits, _Allocator> &__s, _CharT __d, _CharT __e) + : __string(__s), __delim(__d), __escape(__e) {} +}; + +template <class _CharT, class _Traits, class _Allocator> +_LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& operator<<( + basic_ostream<_CharT, _Traits>& __os, + const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy) +{ + return __quoted_output (__os, __proxy.__string.cbegin (), __proxy.__string.cend (), __proxy.__delim, __proxy.__escape); +} + +// extractor for non-const basic_string& proxies +template <class _CharT, class _Traits, class _Allocator> +_LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& operator>>( + basic_istream<_CharT, _Traits>& __is, + const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy) +{ + return __quoted_input ( __is, __proxy.__string, __proxy.__delim, __proxy.__escape ); +} + + +template <class _CharT> +_LIBCPP_INLINE_VISIBILITY +__quoted_output_proxy<_CharT, const _CharT *> +quoted ( const _CharT *__s, _CharT __delim = _CharT('"'), _CharT __escape =_CharT('\\')) +{ + const _CharT *__end = __s; + while ( *__end ) ++__end; + return __quoted_output_proxy<_CharT, const _CharT *> ( __s, __end, __delim, __escape ); +} + + +template <class _CharT, class _Traits, class _Allocator> +_LIBCPP_INLINE_VISIBILITY +__quoted_output_proxy<_CharT, typename basic_string <_CharT, _Traits, _Allocator>::const_iterator> +__quoted ( const basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\')) +{ + return __quoted_output_proxy<_CharT, + typename basic_string <_CharT, _Traits, _Allocator>::const_iterator> + ( __s.cbegin(), __s.cend (), __delim, __escape ); +} + +template <class _CharT, class _Traits, class _Allocator> +_LIBCPP_INLINE_VISIBILITY +__quoted_proxy<_CharT, _Traits, _Allocator> +__quoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\')) +{ + return __quoted_proxy<_CharT, _Traits, _Allocator>( __s, __delim, __escape ); +} + + +#if _LIBCPP_STD_VER > 11 + +template <class _CharT, class _Traits, class _Allocator> +_LIBCPP_INLINE_VISIBILITY +__quoted_output_proxy<_CharT, typename basic_string <_CharT, _Traits, _Allocator>::const_iterator> +quoted ( const basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\')) +{ + return __quoted(__s, __delim, __escape); +} + +template <class _CharT, class _Traits, class _Allocator> +_LIBCPP_INLINE_VISIBILITY +__quoted_proxy<_CharT, _Traits, _Allocator> +quoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\')) +{ + return __quoted(__s, __delim, __escape); +} + +template <class _CharT, class _Traits> +__quoted_output_proxy<_CharT, const _CharT *, _Traits> +quoted (basic_string_view <_CharT, _Traits> __sv, + _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\')) +{ + return __quoted_output_proxy<_CharT, const _CharT *, _Traits> + ( __sv.data(), __sv.data() + __sv.size(), __delim, __escape ); +} +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_IOMANIP diff --git a/android/x86/include/v8/libc++/ios b/android/x86/include/v8/libc++/ios new file mode 100755 index 00000000..ce4e1769 --- /dev/null +++ b/android/x86/include/v8/libc++/ios @@ -0,0 +1,1066 @@ +// -*- C++ -*- +//===---------------------------- ios -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_IOS +#define _LIBCPP_IOS + +/* + ios synopsis + +#include <iosfwd> + +namespace std +{ + +typedef OFF_T streamoff; +typedef SZ_T streamsize; +template <class stateT> class fpos; + +class ios_base +{ +public: + class failure; + + typedef T1 fmtflags; + static constexpr fmtflags boolalpha; + static constexpr fmtflags dec; + static constexpr fmtflags fixed; + static constexpr fmtflags hex; + static constexpr fmtflags internal; + static constexpr fmtflags left; + static constexpr fmtflags oct; + static constexpr fmtflags right; + static constexpr fmtflags scientific; + static constexpr fmtflags showbase; + static constexpr fmtflags showpoint; + static constexpr fmtflags showpos; + static constexpr fmtflags skipws; + static constexpr fmtflags unitbuf; + static constexpr fmtflags uppercase; + static constexpr fmtflags adjustfield; + static constexpr fmtflags basefield; + static constexpr fmtflags floatfield; + + typedef T2 iostate; + static constexpr iostate badbit; + static constexpr iostate eofbit; + static constexpr iostate failbit; + static constexpr iostate goodbit; + + typedef T3 openmode; + static constexpr openmode app; + static constexpr openmode ate; + static constexpr openmode binary; + static constexpr openmode in; + static constexpr openmode out; + static constexpr openmode trunc; + + typedef T4 seekdir; + static constexpr seekdir beg; + static constexpr seekdir cur; + static constexpr seekdir end; + + class Init; + + // 27.5.2.2 fmtflags state: + fmtflags flags() const; + fmtflags flags(fmtflags fmtfl); + fmtflags setf(fmtflags fmtfl); + fmtflags setf(fmtflags fmtfl, fmtflags mask); + void unsetf(fmtflags mask); + + streamsize precision() const; + streamsize precision(streamsize prec); + streamsize width() const; + streamsize width(streamsize wide); + + // 27.5.2.3 locales: + locale imbue(const locale& loc); + locale getloc() const; + + // 27.5.2.5 storage: + static int xalloc(); + long& iword(int index); + void*& pword(int index); + + // destructor + virtual ~ios_base(); + + // 27.5.2.6 callbacks; + enum event { erase_event, imbue_event, copyfmt_event }; + typedef void (*event_callback)(event, ios_base&, int index); + void register_callback(event_callback fn, int index); + + ios_base(const ios_base&) = delete; + ios_base& operator=(const ios_base&) = delete; + + static bool sync_with_stdio(bool sync = true); + +protected: + ios_base(); +}; + +template <class charT, class traits = char_traits<charT> > +class basic_ios + : public ios_base +{ +public: + // types: + typedef charT char_type; + typedef typename traits::int_type int_type; // removed in C++17 + typedef typename traits::pos_type pos_type; // removed in C++17 + typedef typename traits::off_type off_type; // removed in C++17 + typedef traits traits_type; + + operator unspecified-bool-type() const; + bool operator!() const; + iostate rdstate() const; + void clear(iostate state = goodbit); + void setstate(iostate state); + bool good() const; + bool eof() const; + bool fail() const; + bool bad() const; + + iostate exceptions() const; + void exceptions(iostate except); + + // 27.5.4.1 Constructor/destructor: + explicit basic_ios(basic_streambuf<charT,traits>* sb); + virtual ~basic_ios(); + + // 27.5.4.2 Members: + basic_ostream<charT,traits>* tie() const; + basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr); + + basic_streambuf<charT,traits>* rdbuf() const; + basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb); + + basic_ios& copyfmt(const basic_ios& rhs); + + char_type fill() const; + char_type fill(char_type ch); + + locale imbue(const locale& loc); + + char narrow(char_type c, char dfault) const; + char_type widen(char c) const; + + basic_ios(const basic_ios& ) = delete; + basic_ios& operator=(const basic_ios&) = delete; + +protected: + basic_ios(); + void init(basic_streambuf<charT,traits>* sb); + void move(basic_ios& rhs); + void swap(basic_ios& rhs) noexcept; + void set_rdbuf(basic_streambuf<charT, traits>* sb); +}; + +// 27.5.5, manipulators: +ios_base& boolalpha (ios_base& str); +ios_base& noboolalpha(ios_base& str); +ios_base& showbase (ios_base& str); +ios_base& noshowbase (ios_base& str); +ios_base& showpoint (ios_base& str); +ios_base& noshowpoint(ios_base& str); +ios_base& showpos (ios_base& str); +ios_base& noshowpos (ios_base& str); +ios_base& skipws (ios_base& str); +ios_base& noskipws (ios_base& str); +ios_base& uppercase (ios_base& str); +ios_base& nouppercase(ios_base& str); +ios_base& unitbuf (ios_base& str); +ios_base& nounitbuf (ios_base& str); + +// 27.5.5.2 adjustfield: +ios_base& internal (ios_base& str); +ios_base& left (ios_base& str); +ios_base& right (ios_base& str); + +// 27.5.5.3 basefield: +ios_base& dec (ios_base& str); +ios_base& hex (ios_base& str); +ios_base& oct (ios_base& str); + +// 27.5.5.4 floatfield: +ios_base& fixed (ios_base& str); +ios_base& scientific (ios_base& str); +ios_base& hexfloat (ios_base& str); +ios_base& defaultfloat(ios_base& str); + +// 27.5.5.5 error reporting: +enum class io_errc +{ + stream = 1 +}; + +concept_map ErrorCodeEnum<io_errc> { }; +error_code make_error_code(io_errc e) noexcept; +error_condition make_error_condition(io_errc e) noexcept; +storage-class-specifier const error_category& iostream_category() noexcept; + +} // std + +*/ + +#include <__config> +#include <iosfwd> +#include <__locale> +#include <system_error> + +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) +#include <atomic> // for __xindex_ +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +typedef ptrdiff_t streamsize; + +class _LIBCPP_TYPE_VIS ios_base +{ +public: + class _LIBCPP_EXCEPTION_ABI failure; + + typedef unsigned int fmtflags; + static const fmtflags boolalpha = 0x0001; + static const fmtflags dec = 0x0002; + static const fmtflags fixed = 0x0004; + static const fmtflags hex = 0x0008; + static const fmtflags internal = 0x0010; + static const fmtflags left = 0x0020; + static const fmtflags oct = 0x0040; + static const fmtflags right = 0x0080; + static const fmtflags scientific = 0x0100; + static const fmtflags showbase = 0x0200; + static const fmtflags showpoint = 0x0400; + static const fmtflags showpos = 0x0800; + static const fmtflags skipws = 0x1000; + static const fmtflags unitbuf = 0x2000; + static const fmtflags uppercase = 0x4000; + static const fmtflags adjustfield = left | right | internal; + static const fmtflags basefield = dec | oct | hex; + static const fmtflags floatfield = scientific | fixed; + + typedef unsigned int iostate; + static const iostate badbit = 0x1; + static const iostate eofbit = 0x2; + static const iostate failbit = 0x4; + static const iostate goodbit = 0x0; + + typedef unsigned int openmode; + static const openmode app = 0x01; + static const openmode ate = 0x02; + static const openmode binary = 0x04; + static const openmode in = 0x08; + static const openmode out = 0x10; + static const openmode trunc = 0x20; + + enum seekdir {beg, cur, end}; + +#if _LIBCPP_STD_VER <= 14 + typedef iostate io_state; + typedef openmode open_mode; + typedef seekdir seek_dir; + + typedef _VSTD::streamoff streamoff; + typedef _VSTD::streampos streampos; +#endif + + class _LIBCPP_TYPE_VIS Init; + + // 27.5.2.2 fmtflags state: + _LIBCPP_INLINE_VISIBILITY fmtflags flags() const; + _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl); + _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl); + _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask); + _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask); + + _LIBCPP_INLINE_VISIBILITY streamsize precision() const; + _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec); + _LIBCPP_INLINE_VISIBILITY streamsize width() const; + _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide); + + // 27.5.2.3 locales: + locale imbue(const locale& __loc); + locale getloc() const; + + // 27.5.2.5 storage: + static int xalloc(); + long& iword(int __index); + void*& pword(int __index); + + // destructor + virtual ~ios_base(); + + // 27.5.2.6 callbacks; + enum event { erase_event, imbue_event, copyfmt_event }; + typedef void (*event_callback)(event, ios_base&, int __index); + void register_callback(event_callback __fn, int __index); + +private: + ios_base(const ios_base&); // = delete; + ios_base& operator=(const ios_base&); // = delete; + +public: + static bool sync_with_stdio(bool __sync = true); + + _LIBCPP_INLINE_VISIBILITY iostate rdstate() const; + void clear(iostate __state = goodbit); + _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state); + + _LIBCPP_INLINE_VISIBILITY bool good() const; + _LIBCPP_INLINE_VISIBILITY bool eof() const; + _LIBCPP_INLINE_VISIBILITY bool fail() const; + _LIBCPP_INLINE_VISIBILITY bool bad() const; + + _LIBCPP_INLINE_VISIBILITY iostate exceptions() const; + _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate); + + void __set_badbit_and_consider_rethrow(); + void __set_failbit_and_consider_rethrow(); + + _LIBCPP_INLINE_VISIBILITY + void __setstate_nothrow(iostate __state) + { + if (__rdbuf_) + __rdstate_ |= __state; + else + __rdstate_ |= __state | ios_base::badbit; + } + +protected: + _LIBCPP_INLINE_VISIBILITY + ios_base() {// purposefully does no initialization + } + + void init(void* __sb); + _LIBCPP_INLINE_VISIBILITY void* rdbuf() const {return __rdbuf_;} + + _LIBCPP_INLINE_VISIBILITY + void rdbuf(void* __sb) + { + __rdbuf_ = __sb; + clear(); + } + + void __call_callbacks(event); + void copyfmt(const ios_base&); + void move(ios_base&); + void swap(ios_base&) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + void set_rdbuf(void* __sb) + { + __rdbuf_ = __sb; + } + +private: + // All data members must be scalars + fmtflags __fmtflags_; + streamsize __precision_; + streamsize __width_; + iostate __rdstate_; + iostate __exceptions_; + void* __rdbuf_; + void* __loc_; + event_callback* __fn_; + int* __index_; + size_t __event_size_; + size_t __event_cap_; +// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only +// enabled with clang. +#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) + static atomic<int> __xindex_; +#else + static int __xindex_; +#endif + long* __iarray_; + size_t __iarray_size_; + size_t __iarray_cap_; + void** __parray_; + size_t __parray_size_; + size_t __parray_cap_; +}; + +//enum class io_errc +_LIBCPP_DECLARE_STRONG_ENUM(io_errc) +{ + stream = 1 +}; +_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc) + +template <> +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { }; + +#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS +template <> +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { }; +#endif + +_LIBCPP_FUNC_VIS +const error_category& iostream_category() _NOEXCEPT; + +inline _LIBCPP_INLINE_VISIBILITY +error_code +make_error_code(io_errc __e) _NOEXCEPT +{ + return error_code(static_cast<int>(__e), iostream_category()); +} + +inline _LIBCPP_INLINE_VISIBILITY +error_condition +make_error_condition(io_errc __e) _NOEXCEPT +{ + return error_condition(static_cast<int>(__e), iostream_category()); +} + +class _LIBCPP_EXCEPTION_ABI ios_base::failure + : public system_error +{ +public: + explicit failure(const string& __msg, const error_code& __ec = io_errc::stream); + explicit failure(const char* __msg, const error_code& __ec = io_errc::stream); + virtual ~failure() throw(); +}; + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_failure(char const* __msg) { +#ifndef _LIBCPP_NO_EXCEPTIONS + throw ios_base::failure(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +class _LIBCPP_TYPE_VIS ios_base::Init +{ +public: + Init(); + ~Init(); +}; + +// fmtflags + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::fmtflags +ios_base::flags() const +{ + return __fmtflags_; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::fmtflags +ios_base::flags(fmtflags __fmtfl) +{ + fmtflags __r = __fmtflags_; + __fmtflags_ = __fmtfl; + return __r; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::fmtflags +ios_base::setf(fmtflags __fmtfl) +{ + fmtflags __r = __fmtflags_; + __fmtflags_ |= __fmtfl; + return __r; +} + +inline _LIBCPP_INLINE_VISIBILITY +void +ios_base::unsetf(fmtflags __mask) +{ + __fmtflags_ &= ~__mask; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::fmtflags +ios_base::setf(fmtflags __fmtfl, fmtflags __mask) +{ + fmtflags __r = __fmtflags_; + unsetf(__mask); + __fmtflags_ |= __fmtfl & __mask; + return __r; +} + +// precision + +inline _LIBCPP_INLINE_VISIBILITY +streamsize +ios_base::precision() const +{ + return __precision_; +} + +inline _LIBCPP_INLINE_VISIBILITY +streamsize +ios_base::precision(streamsize __prec) +{ + streamsize __r = __precision_; + __precision_ = __prec; + return __r; +} + +// width + +inline _LIBCPP_INLINE_VISIBILITY +streamsize +ios_base::width() const +{ + return __width_; +} + +inline _LIBCPP_INLINE_VISIBILITY +streamsize +ios_base::width(streamsize __wide) +{ + streamsize __r = __width_; + __width_ = __wide; + return __r; +} + +// iostate + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::iostate +ios_base::rdstate() const +{ + return __rdstate_; +} + +inline _LIBCPP_INLINE_VISIBILITY +void +ios_base::setstate(iostate __state) +{ + clear(__rdstate_ | __state); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +ios_base::good() const +{ + return __rdstate_ == 0; +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +ios_base::eof() const +{ + return (__rdstate_ & eofbit) != 0; +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +ios_base::fail() const +{ + return (__rdstate_ & (failbit | badbit)) != 0; +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +ios_base::bad() const +{ + return (__rdstate_ & badbit) != 0; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::iostate +ios_base::exceptions() const +{ + return __exceptions_; +} + +inline _LIBCPP_INLINE_VISIBILITY +void +ios_base::exceptions(iostate __iostate) +{ + __exceptions_ = __iostate; + clear(__rdstate_); +} + +#if defined(_LIBCPP_CXX03_LANG) +struct _LIBCPP_TYPE_VIS __cxx03_bool { + typedef void (__cxx03_bool::*__bool_type)(); + void __true_value() {} +}; +#endif + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_ios + : public ios_base +{ +public: + // types: + typedef _CharT char_type; + typedef _Traits traits_type; + + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + static_assert((is_same<_CharT, typename traits_type::char_type>::value), + "traits_type::char_type must be the same type as CharT"); + + // __true_value will generate undefined references when linking unless + // we give it internal linkage. + +#if defined(_LIBCPP_CXX03_LANG) + _LIBCPP_INLINE_VISIBILITY + operator __cxx03_bool::__bool_type() const { + return !fail() ? &__cxx03_bool::__true_value : nullptr; + } +#else + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT operator bool() const {return !fail();} +#endif + + _LIBCPP_INLINE_VISIBILITY bool operator!() const {return fail();} + _LIBCPP_INLINE_VISIBILITY iostate rdstate() const {return ios_base::rdstate();} + _LIBCPP_INLINE_VISIBILITY void clear(iostate __state = goodbit) {ios_base::clear(__state);} + _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state) {ios_base::setstate(__state);} + _LIBCPP_INLINE_VISIBILITY bool good() const {return ios_base::good();} + _LIBCPP_INLINE_VISIBILITY bool eof() const {return ios_base::eof();} + _LIBCPP_INLINE_VISIBILITY bool fail() const {return ios_base::fail();} + _LIBCPP_INLINE_VISIBILITY bool bad() const {return ios_base::bad();} + + _LIBCPP_INLINE_VISIBILITY iostate exceptions() const {return ios_base::exceptions();} + _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);} + + // 27.5.4.1 Constructor/destructor: + _LIBCPP_INLINE_VISIBILITY + explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb); + virtual ~basic_ios(); + + // 27.5.4.2 Members: + _LIBCPP_INLINE_VISIBILITY + basic_ostream<char_type, traits_type>* tie() const; + _LIBCPP_INLINE_VISIBILITY + basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr); + + _LIBCPP_INLINE_VISIBILITY + basic_streambuf<char_type, traits_type>* rdbuf() const; + _LIBCPP_INLINE_VISIBILITY + basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb); + + basic_ios& copyfmt(const basic_ios& __rhs); + + _LIBCPP_INLINE_VISIBILITY + char_type fill() const; + _LIBCPP_INLINE_VISIBILITY + char_type fill(char_type __ch); + + _LIBCPP_INLINE_VISIBILITY + locale imbue(const locale& __loc); + + _LIBCPP_INLINE_VISIBILITY + char narrow(char_type __c, char __dfault) const; + _LIBCPP_INLINE_VISIBILITY + char_type widen(char __c) const; + +protected: + _LIBCPP_INLINE_VISIBILITY + basic_ios() {// purposefully does no initialization + } + _LIBCPP_INLINE_VISIBILITY + void init(basic_streambuf<char_type, traits_type>* __sb); + + _LIBCPP_INLINE_VISIBILITY + void move(basic_ios& __rhs); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void move(basic_ios&& __rhs) {move(__rhs);} +#endif + _LIBCPP_INLINE_VISIBILITY + void swap(basic_ios& __rhs) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb); +private: + basic_ostream<char_type, traits_type>* __tie_; + mutable int_type __fill_; +}; + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb) +{ + init(__sb); +} + +template <class _CharT, class _Traits> +basic_ios<_CharT, _Traits>::~basic_ios() +{ +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb) +{ + ios_base::init(__sb); + __tie_ = 0; + __fill_ = traits_type::eof(); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>* +basic_ios<_CharT, _Traits>::tie() const +{ + return __tie_; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>* +basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr) +{ + basic_ostream<char_type, traits_type>* __r = __tie_; + __tie_ = __tiestr; + return __r; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_streambuf<_CharT, _Traits>* +basic_ios<_CharT, _Traits>::rdbuf() const +{ + return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf()); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_streambuf<_CharT, _Traits>* +basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb) +{ + basic_streambuf<char_type, traits_type>* __r = rdbuf(); + ios_base::rdbuf(__sb); + return __r; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +locale +basic_ios<_CharT, _Traits>::imbue(const locale& __loc) +{ + locale __r = getloc(); + ios_base::imbue(__loc); + if (rdbuf()) + rdbuf()->pubimbue(__loc); + return __r; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +char +basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const +{ + return use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +_CharT +basic_ios<_CharT, _Traits>::widen(char __c) const +{ + return use_facet<ctype<char_type> >(getloc()).widen(__c); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +_CharT +basic_ios<_CharT, _Traits>::fill() const +{ + if (traits_type::eq_int_type(traits_type::eof(), __fill_)) + __fill_ = widen(' '); + return __fill_; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +_CharT +basic_ios<_CharT, _Traits>::fill(char_type __ch) +{ + char_type __r = __fill_; + __fill_ = __ch; + return __r; +} + +template <class _CharT, class _Traits> +basic_ios<_CharT, _Traits>& +basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) +{ + if (this != &__rhs) + { + __call_callbacks(erase_event); + ios_base::copyfmt(__rhs); + __tie_ = __rhs.__tie_; + __fill_ = __rhs.__fill_; + __call_callbacks(copyfmt_event); + exceptions(__rhs.exceptions()); + } + return *this; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ios<_CharT, _Traits>::move(basic_ios& __rhs) +{ + ios_base::move(__rhs); + __tie_ = __rhs.__tie_; + __rhs.__tie_ = 0; + __fill_ = __rhs.__fill_; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT +{ + ios_base::swap(__rhs); + _VSTD::swap(__tie_, __rhs.__tie_); + _VSTD::swap(__fill_, __rhs.__fill_); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb) +{ + ios_base::set_rdbuf(__sb); +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +boolalpha(ios_base& __str) +{ + __str.setf(ios_base::boolalpha); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noboolalpha(ios_base& __str) +{ + __str.unsetf(ios_base::boolalpha); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +showbase(ios_base& __str) +{ + __str.setf(ios_base::showbase); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noshowbase(ios_base& __str) +{ + __str.unsetf(ios_base::showbase); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +showpoint(ios_base& __str) +{ + __str.setf(ios_base::showpoint); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noshowpoint(ios_base& __str) +{ + __str.unsetf(ios_base::showpoint); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +showpos(ios_base& __str) +{ + __str.setf(ios_base::showpos); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noshowpos(ios_base& __str) +{ + __str.unsetf(ios_base::showpos); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +skipws(ios_base& __str) +{ + __str.setf(ios_base::skipws); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noskipws(ios_base& __str) +{ + __str.unsetf(ios_base::skipws); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +uppercase(ios_base& __str) +{ + __str.setf(ios_base::uppercase); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +nouppercase(ios_base& __str) +{ + __str.unsetf(ios_base::uppercase); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +unitbuf(ios_base& __str) +{ + __str.setf(ios_base::unitbuf); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +nounitbuf(ios_base& __str) +{ + __str.unsetf(ios_base::unitbuf); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +internal(ios_base& __str) +{ + __str.setf(ios_base::internal, ios_base::adjustfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +left(ios_base& __str) +{ + __str.setf(ios_base::left, ios_base::adjustfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +right(ios_base& __str) +{ + __str.setf(ios_base::right, ios_base::adjustfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +dec(ios_base& __str) +{ + __str.setf(ios_base::dec, ios_base::basefield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +hex(ios_base& __str) +{ + __str.setf(ios_base::hex, ios_base::basefield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +oct(ios_base& __str) +{ + __str.setf(ios_base::oct, ios_base::basefield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +fixed(ios_base& __str) +{ + __str.setf(ios_base::fixed, ios_base::floatfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +scientific(ios_base& __str) +{ + __str.setf(ios_base::scientific, ios_base::floatfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +hexfloat(ios_base& __str) +{ + __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +defaultfloat(ios_base& __str) +{ + __str.unsetf(ios_base::floatfield); + return __str; +} + +template <class _CharT, class _Traits> +class __save_flags +{ + typedef basic_ios<_CharT, _Traits> __stream_type; + typedef typename __stream_type::fmtflags fmtflags; + + __stream_type& __stream_; + fmtflags __fmtflags_; + _CharT __fill_; + + __save_flags(const __save_flags&); + __save_flags& operator=(const __save_flags&); +public: + _LIBCPP_INLINE_VISIBILITY + explicit __save_flags(__stream_type& __stream) + : __stream_(__stream), + __fmtflags_(__stream.flags()), + __fill_(__stream.fill()) + {} + _LIBCPP_INLINE_VISIBILITY + ~__save_flags() + { + __stream_.flags(__fmtflags_); + __stream_.fill(__fill_); + } +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_IOS diff --git a/android/x86/include/v8/libc++/iosfwd b/android/x86/include/v8/libc++/iosfwd new file mode 100755 index 00000000..0ffe75f1 --- /dev/null +++ b/android/x86/include/v8/libc++/iosfwd @@ -0,0 +1,220 @@ +// -*- C++ -*- +//===--------------------------- iosfwd -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_IOSFWD +#define _LIBCPP_IOSFWD + +/* + iosfwd synopsis + +namespace std +{ + +template<class charT> struct char_traits; +template<> struct char_traits<char>; +template<> struct char_traits<char8_t>; // C++20 +template<> struct char_traits<char16_t>; +template<> struct char_traits<char32_t>; +template<> struct char_traits<wchar_t>; + +template<class T> class allocator; + +class ios_base; +template <class charT, class traits = char_traits<charT> > class basic_ios; + +template <class charT, class traits = char_traits<charT> > class basic_streambuf; +template <class charT, class traits = char_traits<charT> > class basic_istream; +template <class charT, class traits = char_traits<charT> > class basic_ostream; +template <class charT, class traits = char_traits<charT> > class basic_iostream; + +template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > + class basic_stringbuf; +template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > + class basic_istringstream; +template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > + class basic_ostringstream; +template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > + class basic_stringstream; + +template <class charT, class traits = char_traits<charT> > class basic_filebuf; +template <class charT, class traits = char_traits<charT> > class basic_ifstream; +template <class charT, class traits = char_traits<charT> > class basic_ofstream; +template <class charT, class traits = char_traits<charT> > class basic_fstream; + +template <class charT, class traits = char_traits<charT> > class istreambuf_iterator; +template <class charT, class traits = char_traits<charT> > class ostreambuf_iterator; + +typedef basic_ios<char> ios; +typedef basic_ios<wchar_t> wios; + +typedef basic_streambuf<char> streambuf; +typedef basic_istream<char> istream; +typedef basic_ostream<char> ostream; +typedef basic_iostream<char> iostream; + +typedef basic_stringbuf<char> stringbuf; +typedef basic_istringstream<char> istringstream; +typedef basic_ostringstream<char> ostringstream; +typedef basic_stringstream<char> stringstream; + +typedef basic_filebuf<char> filebuf; +typedef basic_ifstream<char> ifstream; +typedef basic_ofstream<char> ofstream; +typedef basic_fstream<char> fstream; + +typedef basic_streambuf<wchar_t> wstreambuf; +typedef basic_istream<wchar_t> wistream; +typedef basic_ostream<wchar_t> wostream; +typedef basic_iostream<wchar_t> wiostream; + +typedef basic_stringbuf<wchar_t> wstringbuf; +typedef basic_istringstream<wchar_t> wistringstream; +typedef basic_ostringstream<wchar_t> wostringstream; +typedef basic_stringstream<wchar_t> wstringstream; + +typedef basic_filebuf<wchar_t> wfilebuf; +typedef basic_ifstream<wchar_t> wifstream; +typedef basic_ofstream<wchar_t> wofstream; +typedef basic_fstream<wchar_t> wfstream; + +template <class state> class fpos; +typedef fpos<char_traits<char>::state_type> streampos; +typedef fpos<char_traits<wchar_t>::state_type> wstreampos; + +} // std + +*/ + +#include <__config> +#include <wchar.h> // for mbstate_t + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +class _LIBCPP_TYPE_VIS ios_base; + +template<class _CharT> struct _LIBCPP_TEMPLATE_VIS char_traits; +template<> struct char_traits<char>; +#ifndef _LIBCPP_NO_HAS_CHAR8_T +template<> struct char_traits<char8_t>; +#endif +template<> struct char_traits<char16_t>; +template<> struct char_traits<char32_t>; +template<> struct char_traits<wchar_t>; + +template<class _Tp> class _LIBCPP_TEMPLATE_VIS allocator; + +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_ios; + +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_streambuf; +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_istream; +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_ostream; +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_iostream; + +template <class _CharT, class _Traits = char_traits<_CharT>, + class _Allocator = allocator<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_stringbuf; +template <class _CharT, class _Traits = char_traits<_CharT>, + class _Allocator = allocator<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_istringstream; +template <class _CharT, class _Traits = char_traits<_CharT>, + class _Allocator = allocator<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_ostringstream; +template <class _CharT, class _Traits = char_traits<_CharT>, + class _Allocator = allocator<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_stringstream; + +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_filebuf; +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_ifstream; +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_ofstream; +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_fstream; + +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS istreambuf_iterator; +template <class _CharT, class _Traits = char_traits<_CharT> > + class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator; + +typedef basic_ios<char> ios; +typedef basic_ios<wchar_t> wios; + +typedef basic_streambuf<char> streambuf; +typedef basic_istream<char> istream; +typedef basic_ostream<char> ostream; +typedef basic_iostream<char> iostream; + +typedef basic_stringbuf<char> stringbuf; +typedef basic_istringstream<char> istringstream; +typedef basic_ostringstream<char> ostringstream; +typedef basic_stringstream<char> stringstream; + +typedef basic_filebuf<char> filebuf; +typedef basic_ifstream<char> ifstream; +typedef basic_ofstream<char> ofstream; +typedef basic_fstream<char> fstream; + +typedef basic_streambuf<wchar_t> wstreambuf; +typedef basic_istream<wchar_t> wistream; +typedef basic_ostream<wchar_t> wostream; +typedef basic_iostream<wchar_t> wiostream; + +typedef basic_stringbuf<wchar_t> wstringbuf; +typedef basic_istringstream<wchar_t> wistringstream; +typedef basic_ostringstream<wchar_t> wostringstream; +typedef basic_stringstream<wchar_t> wstringstream; + +typedef basic_filebuf<wchar_t> wfilebuf; +typedef basic_ifstream<wchar_t> wifstream; +typedef basic_ofstream<wchar_t> wofstream; +typedef basic_fstream<wchar_t> wfstream; + +template <class _State> class _LIBCPP_TEMPLATE_VIS fpos; +typedef fpos<mbstate_t> streampos; +typedef fpos<mbstate_t> wstreampos; +#ifndef _LIBCPP_NO_HAS_CHAR8_T +typedef fpos<mbstate_t> u8streampos; +#endif +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS +typedef fpos<mbstate_t> u16streampos; +typedef fpos<mbstate_t> u32streampos; +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +#if defined(_NEWLIB_VERSION) +// On newlib, off_t is 'long int' +typedef long int streamoff; // for char_traits in <string> +#else +typedef long long streamoff; // for char_traits in <string> +#endif + +template <class _CharT, // for <stdexcept> + class _Traits = char_traits<_CharT>, + class _Allocator = allocator<_CharT> > + class _LIBCPP_TEMPLATE_VIS basic_string; +typedef basic_string<char, char_traits<char>, allocator<char> > string; +typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring; + + +// Include other forward declarations here +template <class _Tp, class _Alloc = allocator<_Tp> > +class _LIBCPP_TEMPLATE_VIS vector; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_IOSFWD diff --git a/android/x86/include/v8/libc++/iostream b/android/x86/include/v8/libc++/iostream new file mode 100755 index 00000000..595620b8 --- /dev/null +++ b/android/x86/include/v8/libc++/iostream @@ -0,0 +1,63 @@ +// -*- C++ -*- +//===--------------------------- iostream ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_IOSTREAM +#define _LIBCPP_IOSTREAM + +/* + iostream synopsis + +#include <ios> +#include <streambuf> +#include <istream> +#include <ostream> + +namespace std { + +extern istream cin; +extern ostream cout; +extern ostream cerr; +extern ostream clog; +extern wistream wcin; +extern wostream wcout; +extern wostream wcerr; +extern wostream wclog; + +} // std + +*/ + +#include <__config> +#include <ios> +#include <streambuf> +#include <istream> +#include <ostream> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_HAS_NO_STDIN +extern _LIBCPP_FUNC_VIS istream cin; +extern _LIBCPP_FUNC_VIS wistream wcin; +#endif +#ifndef _LIBCPP_HAS_NO_STDOUT +extern _LIBCPP_FUNC_VIS ostream cout; +extern _LIBCPP_FUNC_VIS wostream wcout; +#endif +extern _LIBCPP_FUNC_VIS ostream cerr; +extern _LIBCPP_FUNC_VIS wostream wcerr; +extern _LIBCPP_FUNC_VIS ostream clog; +extern _LIBCPP_FUNC_VIS wostream wclog; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_IOSTREAM diff --git a/android/x86/include/v8/libc++/istream b/android/x86/include/v8/libc++/istream new file mode 100755 index 00000000..d6217bbb --- /dev/null +++ b/android/x86/include/v8/libc++/istream @@ -0,0 +1,1651 @@ +// -*- C++ -*- +//===--------------------------- istream ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ISTREAM +#define _LIBCPP_ISTREAM + +/* + istream synopsis + +template <class charT, class traits = char_traits<charT> > +class basic_istream + : virtual public basic_ios<charT,traits> +{ +public: + // types (inherited from basic_ios (27.5.4)): + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // 27.7.1.1.1 Constructor/destructor: + explicit basic_istream(basic_streambuf<char_type, traits_type>* sb); + basic_istream(basic_istream&& rhs); + virtual ~basic_istream(); + + // 27.7.1.1.2 Assign/swap: + basic_istream& operator=(basic_istream&& rhs); + void swap(basic_istream& rhs); + + // 27.7.1.1.3 Prefix/suffix: + class sentry; + + // 27.7.1.2 Formatted input: + basic_istream& operator>>(basic_istream& (*pf)(basic_istream&)); + basic_istream& operator>>(basic_ios<char_type, traits_type>& + (*pf)(basic_ios<char_type, traits_type>&)); + basic_istream& operator>>(ios_base& (*pf)(ios_base&)); + basic_istream& operator>>(basic_streambuf<char_type, traits_type>* sb); + basic_istream& operator>>(bool& n); + basic_istream& operator>>(short& n); + basic_istream& operator>>(unsigned short& n); + basic_istream& operator>>(int& n); + basic_istream& operator>>(unsigned int& n); + basic_istream& operator>>(long& n); + basic_istream& operator>>(unsigned long& n); + basic_istream& operator>>(long long& n); + basic_istream& operator>>(unsigned long long& n); + basic_istream& operator>>(float& f); + basic_istream& operator>>(double& f); + basic_istream& operator>>(long double& f); + basic_istream& operator>>(void*& p); + + // 27.7.1.3 Unformatted input: + streamsize gcount() const; + int_type get(); + basic_istream& get(char_type& c); + basic_istream& get(char_type* s, streamsize n); + basic_istream& get(char_type* s, streamsize n, char_type delim); + basic_istream& get(basic_streambuf<char_type,traits_type>& sb); + basic_istream& get(basic_streambuf<char_type,traits_type>& sb, char_type delim); + + basic_istream& getline(char_type* s, streamsize n); + basic_istream& getline(char_type* s, streamsize n, char_type delim); + + basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof()); + int_type peek(); + basic_istream& read (char_type* s, streamsize n); + streamsize readsome(char_type* s, streamsize n); + + basic_istream& putback(char_type c); + basic_istream& unget(); + int sync(); + + pos_type tellg(); + basic_istream& seekg(pos_type); + basic_istream& seekg(off_type, ios_base::seekdir); +protected: + basic_istream(const basic_istream& rhs) = delete; + basic_istream(basic_istream&& rhs); + // 27.7.2.1.2 Assign/swap: + basic_istream& operator=(const basic_istream& rhs) = delete; + basic_istream& operator=(basic_istream&& rhs); + void swap(basic_istream& rhs); +}; + +// 27.7.1.2.3 character extraction templates: +template<class charT, class traits> + basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&); + +template<class traits> + basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&); + +template<class traits> + basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&); + +template<class charT, class traits> + basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*); + +template<class traits> + basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*); + +template<class traits> + basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*); + +template <class charT, class traits> + void + swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y); + +typedef basic_istream<char> istream; +typedef basic_istream<wchar_t> wistream; + +template <class charT, class traits = char_traits<charT> > +class basic_iostream : + public basic_istream<charT,traits>, + public basic_ostream<charT,traits> +{ +public: + // types: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // constructor/destructor + explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb); + basic_iostream(basic_iostream&& rhs); + virtual ~basic_iostream(); + + // assign/swap + basic_iostream& operator=(basic_iostream&& rhs); + void swap(basic_iostream& rhs); +}; + +template <class charT, class traits> + void + swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y); + +typedef basic_iostream<char> iostream; +typedef basic_iostream<wchar_t> wiostream; + +template <class charT, class traits> + basic_istream<charT,traits>& + ws(basic_istream<charT,traits>& is); + +template <class charT, class traits, class T> + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>&& is, T& x); + +} // std + +*/ + +#include <__config> +#include <version> +#include <ostream> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_istream + : virtual public basic_ios<_CharT, _Traits> +{ + streamsize __gc_; +public: + // types (inherited from basic_ios (27.5.4)): + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // 27.7.1.1.1 Constructor/destructor: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) : __gc_(0) + { this->init(__sb); } + virtual ~basic_istream(); +protected: +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY + basic_istream(basic_istream&& __rhs); + + // 27.7.1.1.2 Assign/swap: + inline _LIBCPP_INLINE_VISIBILITY + basic_istream& operator=(basic_istream&& __rhs); +#endif + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + void swap(basic_istream& __rhs) { + _VSTD::swap(__gc_, __rhs.__gc_); + basic_ios<char_type, traits_type>::swap(__rhs); + } + +#ifndef _LIBCPP_CXX03_LANG + basic_istream (const basic_istream& __rhs) = delete; + basic_istream& operator=(const basic_istream& __rhs) = delete; +#endif +public: + + // 27.7.1.1.3 Prefix/suffix: + class _LIBCPP_TEMPLATE_VIS sentry; + + // 27.7.1.2 Formatted input: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) + { return __pf(*this); } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_istream& operator>>(basic_ios<char_type, traits_type>& + (*__pf)(basic_ios<char_type, traits_type>&)) + { __pf(*this); return *this; } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_istream& operator>>(ios_base& (*__pf)(ios_base&)) + { __pf(*this); return *this; } + + basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb); + basic_istream& operator>>(bool& __n); + basic_istream& operator>>(short& __n); + basic_istream& operator>>(unsigned short& __n); + basic_istream& operator>>(int& __n); + basic_istream& operator>>(unsigned int& __n); + basic_istream& operator>>(long& __n); + basic_istream& operator>>(unsigned long& __n); + basic_istream& operator>>(long long& __n); + basic_istream& operator>>(unsigned long long& __n); + basic_istream& operator>>(float& __f); + basic_istream& operator>>(double& __f); + basic_istream& operator>>(long double& __f); + basic_istream& operator>>(void*& __p); + + // 27.7.1.3 Unformatted input: + _LIBCPP_INLINE_VISIBILITY + streamsize gcount() const {return __gc_;} + int_type get(); + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_istream& get(char_type& __c) { + int_type __ch = get(); + if (__ch != traits_type::eof()) + __c = traits_type::to_char_type(__ch); + return *this; + } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_istream& get(char_type* __s, streamsize __n) + { return get(__s, __n, this->widen('\n')); } + + basic_istream& get(char_type* __s, streamsize __n, char_type __dlm); + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_istream& get(basic_streambuf<char_type, traits_type>& __sb) + { return get(__sb, this->widen('\n')); } + + basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm); + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_istream& getline(char_type* __s, streamsize __n) + { return getline(__s, __n, this->widen('\n')); } + + basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm); + + basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof()); + int_type peek(); + basic_istream& read (char_type* __s, streamsize __n); + streamsize readsome(char_type* __s, streamsize __n); + + basic_istream& putback(char_type __c); + basic_istream& unget(); + int sync(); + + pos_type tellg(); + basic_istream& seekg(pos_type __pos); + basic_istream& seekg(off_type __off, ios_base::seekdir __dir); +}; + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry +{ + bool __ok_; + + sentry(const sentry&); // = delete; + sentry& operator=(const sentry&); // = delete; + +public: + explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false); +// ~sentry() = default; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT + operator bool() const {return __ok_;} +}; + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is, + bool __noskipws) + : __ok_(false) +{ + if (__is.good()) + { + if (__is.tie()) + __is.tie()->flush(); + if (!__noskipws && (__is.flags() & ios_base::skipws)) + { + typedef istreambuf_iterator<_CharT, _Traits> _Ip; + const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); + _Ip __i(__is); + _Ip __eof; + for (; __i != __eof; ++__i) + if (!__ct.is(__ct.space, *__i)) + break; + if (__i == __eof) + __is.setstate(ios_base::failbit | ios_base::eofbit); + } + __ok_ = __is.good(); + } + else + __is.setstate(ios_base::failbit); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) + : __gc_(__rhs.__gc_) +{ + __rhs.__gc_ = 0; + this->move(__rhs); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) +{ + swap(__rhs); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>::~basic_istream() +{ +} + +template <class _Tp, class _CharT, class _Traits> +_LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +__input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __s(__is); + if (__s) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef istreambuf_iterator<_CharT, _Traits> _Ip; + typedef num_get<_CharT, _Ip> _Fp; + use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __n); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); + } + return __is; +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) +{ + return _VSTD::__input_arithmetic<unsigned short>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n) +{ + return _VSTD::__input_arithmetic<unsigned int>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(long& __n) +{ + return _VSTD::__input_arithmetic<long>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n) +{ + return _VSTD::__input_arithmetic<unsigned long>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(long long& __n) +{ + return _VSTD::__input_arithmetic<long long>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n) +{ + return _VSTD::__input_arithmetic<unsigned long long>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(float& __n) +{ + return _VSTD::__input_arithmetic<float>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(double& __n) +{ + return _VSTD::__input_arithmetic<double>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(long double& __n) +{ + return _VSTD::__input_arithmetic<long double>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(bool& __n) +{ + return _VSTD::__input_arithmetic<bool>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(void*& __n) +{ + return _VSTD::__input_arithmetic<void*>(*this, __n); +} + +template <class _Tp, class _CharT, class _Traits> +_LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +__input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __s(__is); + if (__s) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef istreambuf_iterator<_CharT, _Traits> _Ip; + typedef num_get<_CharT, _Ip> _Fp; + long __temp; + use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __temp); + if (__temp < numeric_limits<_Tp>::min()) + { + __state |= ios_base::failbit; + __n = numeric_limits<_Tp>::min(); + } + else if (__temp > numeric_limits<_Tp>::max()) + { + __state |= ios_base::failbit; + __n = numeric_limits<_Tp>::max(); + } + else + { + __n = static_cast<_Tp>(__temp); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + __is.setstate(__state); + } + return __is; +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(short& __n) +{ + return _VSTD::__input_arithmetic_with_numeric_limits<short>(*this, __n); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(int& __n) +{ + return _VSTD::__input_arithmetic_with_numeric_limits<int>(*this, __n); +} + +template<class _CharT, class _Traits> +_LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +__input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n) +{ + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif + _CharT* __s = __p; + const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); + while (__s != __p + (__n-1)) + { + typename _Traits::int_type __i = __is.rdbuf()->sgetc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __state |= ios_base::eofbit; + break; + } + _CharT __ch = _Traits::to_char_type(__i); + if (__ct.is(__ct.space, __ch)) + break; + *__s++ = __ch; + __is.rdbuf()->sbumpc(); + } + *__s = _CharT(); + __is.width(0); + if (__s == __p) + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); + } + return __is; +} + +#if _LIBCPP_STD_VER > 17 + +template<class _CharT, class _Traits, size_t _Np> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, _CharT (&__buf)[_Np]) +{ + size_t __n = _Np; + if (__is.width() > 0) + __n = _VSTD::min(size_t(__is.width()), _Np); + return _VSTD::__input_c_string(__is, __buf, __n); +} + +template<class _Traits, size_t _Np> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<char, _Traits>& +operator>>(basic_istream<char, _Traits>& __is, unsigned char (&__buf)[_Np]) +{ + return __is >> (char(&)[_Np])__buf; +} + +template<class _Traits, size_t _Np> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<char, _Traits>& +operator>>(basic_istream<char, _Traits>& __is, signed char (&__buf)[_Np]) +{ + return __is >> (char(&)[_Np])__buf; +} + +#else + +template<class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s) +{ + streamsize __n = __is.width(); + if (__n <= 0) + __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1; + return _VSTD::__input_c_string(__is, __s, size_t(__n)); +} + +template<class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<char, _Traits>& +operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s) +{ + return __is >> (char*)__s; +} + +template<class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<char, _Traits>& +operator>>(basic_istream<char, _Traits>& __is, signed char* __s) +{ + return __is >> (char*)__s; +} + +#endif // _LIBCPP_STD_VER > 17 + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) +{ + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif + typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + __state |= ios_base::eofbit | ios_base::failbit; + else + __c = _Traits::to_char_type(__i); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); + } + return __is; +} + +template<class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<char, _Traits>& +operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c) +{ + return __is >> (char&)__c; +} + +template<class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<char, _Traits>& +operator>>(basic_istream<char, _Traits>& __is, signed char& __c) +{ + return __is >> (char&)__c; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb) +{ + ios_base::iostate __state = ios_base::goodbit; + __gc_ = 0; + sentry __s(*this, true); + if (__s) + { + if (__sb) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + while (true) + { + typename traits_type::int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, _Traits::eof())) + { + __state |= ios_base::eofbit; + break; + } + if (traits_type::eq_int_type( + __sb->sputc(traits_type::to_char_type(__i)), + traits_type::eof())) + break; + ++__gc_; + this->rdbuf()->sbumpc(); + } + if (__gc_ == 0) + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + if (__gc_ == 0) + __state |= ios_base::failbit; + + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::failbit || this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + else + { + __state |= ios_base::failbit; + } + this->setstate(__state); + } + return *this; +} + +template<class _CharT, class _Traits> +typename basic_istream<_CharT, _Traits>::int_type +basic_istream<_CharT, _Traits>::get() +{ + ios_base::iostate __state = ios_base::goodbit; + __gc_ = 0; + int_type __r = traits_type::eof(); + sentry __s(*this, true); + if (__s) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif + __r = this->rdbuf()->sbumpc(); + if (traits_type::eq_int_type(__r, traits_type::eof())) + __state |= ios_base::failbit | ios_base::eofbit; + else + __gc_ = 1; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__setstate_nothrow(this->rdstate() | ios_base::badbit); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + this->setstate(__state); + } + return __r; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) +{ + ios_base::iostate __state = ios_base::goodbit; + __gc_ = 0; + sentry __sen(*this, true); + if (__sen) + { + if (__n > 0) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif + while (__gc_ < __n-1) + { + int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __state |= ios_base::eofbit; + break; + } + char_type __ch = traits_type::to_char_type(__i); + if (traits_type::eq(__ch, __dlm)) + break; + *__s++ = __ch; + ++__gc_; + this->rdbuf()->sbumpc(); + } + if (__gc_ == 0) + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + if (__n > 0) + *__s = char_type(); + throw; + } + } +#endif + } + else + { + __state |= ios_base::failbit; + } + + if (__n > 0) + *__s = char_type(); + this->setstate(__state); + } + if (__n > 0) + *__s = char_type(); + return *this; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb, + char_type __dlm) +{ + ios_base::iostate __state = ios_base::goodbit; + __gc_ = 0; + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + while (true) + { + typename traits_type::int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __state |= ios_base::eofbit; + break; + } + char_type __ch = traits_type::to_char_type(__i); + if (traits_type::eq(__ch, __dlm)) + break; + if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof())) + break; + ++__gc_; + this->rdbuf()->sbumpc(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + // according to the spec, exceptions here are caught but not rethrown + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__gc_ == 0) + __state |= ios_base::failbit; + this->setstate(__state); + } + return *this; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) +{ + ios_base::iostate __state = ios_base::goodbit; + __gc_ = 0; + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + while (true) + { + typename traits_type::int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __state |= ios_base::eofbit; + break; + } + char_type __ch = traits_type::to_char_type(__i); + if (traits_type::eq(__ch, __dlm)) + { + this->rdbuf()->sbumpc(); + ++__gc_; + break; + } + if (__gc_ >= __n-1) + { + __state |= ios_base::failbit; + break; + } + *__s++ = __ch; + this->rdbuf()->sbumpc(); + ++__gc_; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + if (__n > 0) + *__s = char_type(); + if (__gc_ == 0) + __state |= ios_base::failbit; + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + if (__n > 0) + *__s = char_type(); + if (__gc_ == 0) + __state |= ios_base::failbit; + this->setstate(__state); + return *this; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) +{ + ios_base::iostate __state = ios_base::goodbit; + __gc_ = 0; + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + if (__n == numeric_limits<streamsize>::max()) + { + while (true) + { + typename traits_type::int_type __i = this->rdbuf()->sbumpc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __state |= ios_base::eofbit; + break; + } + ++__gc_; + if (traits_type::eq_int_type(__i, __dlm)) + break; + } + } + else + { + while (__gc_ < __n) + { + typename traits_type::int_type __i = this->rdbuf()->sbumpc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __state |= ios_base::eofbit; + break; + } + ++__gc_; + if (traits_type::eq_int_type(__i, __dlm)) + break; + } + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } + return *this; +} + +template<class _CharT, class _Traits> +typename basic_istream<_CharT, _Traits>::int_type +basic_istream<_CharT, _Traits>::peek() +{ + ios_base::iostate __state = ios_base::goodbit; + __gc_ = 0; + int_type __r = traits_type::eof(); + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __r = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__r, traits_type::eof())) + __state |= ios_base::eofbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } + return __r; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) +{ + ios_base::iostate __state = ios_base::goodbit; + __gc_ = 0; + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __gc_ = this->rdbuf()->sgetn(__s, __n); + if (__gc_ != __n) + __state |= ios_base::failbit | ios_base::eofbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + else + { + __state |= ios_base::failbit; + } + this->setstate(__state); + return *this; +} + +template<class _CharT, class _Traits> +streamsize +basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) +{ + ios_base::iostate __state = ios_base::goodbit; + __gc_ = 0; + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + streamsize __c = this->rdbuf()->in_avail(); + switch (__c) + { + case -1: + __state |= ios_base::eofbit; + break; + case 0: + break; + default: + __n = _VSTD::min(__c, __n); + __gc_ = this->rdbuf()->sgetn(__s, __n); + if (__gc_ != __n) + __state |= ios_base::failbit | ios_base::eofbit; + break; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + else + { + __state |= ios_base::failbit; + } + this->setstate(__state); + return __gc_; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::putback(char_type __c) +{ + ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; + __gc_ = 0; + this->clear(__state); + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof()) + __state |= ios_base::badbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + else + { + __state |= ios_base::failbit; + } + this->setstate(__state); + return *this; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::unget() +{ + ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; + __gc_ = 0; + this->clear(__state); + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof()) + __state |= ios_base::badbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + else + { + __state |= ios_base::failbit; + } + this->setstate(__state); + return *this; +} + +template<class _CharT, class _Traits> +int +basic_istream<_CharT, _Traits>::sync() +{ + ios_base::iostate __state = ios_base::goodbit; + int __r = 0; + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + if (this->rdbuf() == 0) + return -1; + if (this->rdbuf()->pubsync() == -1) + { + __state |= ios_base::badbit; + return -1; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } + return __r; +} + +template<class _CharT, class _Traits> +typename basic_istream<_CharT, _Traits>::pos_type +basic_istream<_CharT, _Traits>::tellg() +{ + ios_base::iostate __state = ios_base::goodbit; + pos_type __r(-1); + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } + return __r; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::seekg(pos_type __pos) +{ + ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; + this->clear(__state); + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1)) + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } + return *this; +} + +template<class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) +{ + ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; + this->clear(__state); + sentry __sen(*this, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1)) + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } + return *this; +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +ws(basic_istream<_CharT, _Traits>& __is) +{ + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); + while (true) + { + typename _Traits::int_type __i = __is.rdbuf()->sgetc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __state |= ios_base::eofbit; + break; + } + if (!__ct.is(__ct.space, _Traits::to_char_type(__i))) + break; + __is.rdbuf()->sbumpc(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS + __is.setstate(__state); + } + return __is; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x) +{ + __is >> _VSTD::forward<_Tp>(__x); + return __is; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_iostream + : public basic_istream<_CharT, _Traits>, + public basic_ostream<_CharT, _Traits> +{ +public: + // types: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // constructor/destructor + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb) + : basic_istream<_CharT, _Traits>(__sb) + {} + + virtual ~basic_iostream(); +protected: +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY + basic_iostream(basic_iostream&& __rhs); + + // assign/swap + inline _LIBCPP_INLINE_VISIBILITY + basic_iostream& operator=(basic_iostream&& __rhs); +#endif + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + void swap(basic_iostream& __rhs) + { basic_istream<char_type, traits_type>::swap(__rhs); } +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs) + : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) +{ +} + +template <class _CharT, class _Traits> +basic_iostream<_CharT, _Traits>& +basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) +{ + swap(__rhs); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +basic_iostream<_CharT, _Traits>::~basic_iostream() +{ +} + +template<class _CharT, class _Traits, class _Allocator> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + basic_string<_CharT, _Traits, _Allocator>& __str) +{ + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif + __str.clear(); + streamsize __n = __is.width(); + if (__n <= 0) + __n = __str.max_size(); + if (__n <= 0) + __n = numeric_limits<streamsize>::max(); + streamsize __c = 0; + const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); + while (__c < __n) + { + typename _Traits::int_type __i = __is.rdbuf()->sgetc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __state |= ios_base::eofbit; + break; + } + _CharT __ch = _Traits::to_char_type(__i); + if (__ct.is(__ct.space, __ch)) + break; + __str.push_back(__ch); + ++__c; + __is.rdbuf()->sbumpc(); + } + __is.width(0); + if (__c == 0) + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); + } + return __is; +} + +template<class _CharT, class _Traits, class _Allocator> +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>& __is, + basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) +{ + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif + __str.clear(); + streamsize __extr = 0; + while (true) + { + typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __state |= ios_base::eofbit; + break; + } + ++__extr; + _CharT __ch = _Traits::to_char_type(__i); + if (_Traits::eq(__ch, __dlm)) + break; + __str.push_back(__ch); + if (__str.size() == __str.max_size()) + { + __state |= ios_base::failbit; + break; + } + } + if (__extr == 0) + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); + } + return __is; +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>& __is, + basic_string<_CharT, _Traits, _Allocator>& __str) +{ + return getline(__is, __str, __is.widen('\n')); +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>&& __is, + basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) +{ + return getline(__is, __str, __dlm); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>&& __is, + basic_string<_CharT, _Traits, _Allocator>& __str) +{ + return getline(__is, __str, __is.widen('\n')); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, size_t _Size> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) +{ + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif + basic_string<_CharT, _Traits> __str; + const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); + size_t __c = 0; + _CharT __zero = __ct.widen('0'); + _CharT __one = __ct.widen('1'); + while (__c < _Size) + { + typename _Traits::int_type __i = __is.rdbuf()->sgetc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __state |= ios_base::eofbit; + break; + } + _CharT __ch = _Traits::to_char_type(__i); + if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one)) + break; + __str.push_back(__ch); + ++__c; + __is.rdbuf()->sbumpc(); + } + __x = bitset<_Size>(__str); + if (__c == 0) + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); + } + return __is; +} + +#ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>) +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_ISTREAM diff --git a/android/x86/include/v8/libc++/iterator b/android/x86/include/v8/libc++/iterator new file mode 100755 index 00000000..5846c1b4 --- /dev/null +++ b/android/x86/include/v8/libc++/iterator @@ -0,0 +1,1927 @@ +// -*- C++ -*- +//===-------------------------- iterator ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ITERATOR +#define _LIBCPP_ITERATOR + +/* + iterator synopsis + +namespace std +{ + +template<class Iterator> +struct iterator_traits +{ + typedef typename Iterator::difference_type difference_type; + typedef typename Iterator::value_type value_type; + typedef typename Iterator::pointer pointer; + typedef typename Iterator::reference reference; + typedef typename Iterator::iterator_category iterator_category; +}; + +template<class T> +struct iterator_traits<T*> +{ + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef random_access_iterator_tag iterator_category; +}; + +template<class Category, class T, class Distance = ptrdiff_t, + class Pointer = T*, class Reference = T&> +struct iterator +{ + typedef T value_type; + typedef Distance difference_type; + typedef Pointer pointer; + typedef Reference reference; + typedef Category iterator_category; +}; + +struct input_iterator_tag {}; +struct output_iterator_tag {}; +struct forward_iterator_tag : public input_iterator_tag {}; +struct bidirectional_iterator_tag : public forward_iterator_tag {}; +struct random_access_iterator_tag : public bidirectional_iterator_tag {}; + +// 27.4.3, iterator operations +// extension: second argument not conforming to C++03 +template <class InputIterator> // constexpr in C++17 + constexpr void advance(InputIterator& i, + typename iterator_traits<InputIterator>::difference_type n); + +template <class InputIterator> // constexpr in C++17 + constexpr typename iterator_traits<InputIterator>::difference_type + distance(InputIterator first, InputIterator last); + +template <class InputIterator> // constexpr in C++17 + constexpr InputIterator next(InputIterator x, +typename iterator_traits<InputIterator>::difference_type n = 1); + +template <class BidirectionalIterator> // constexpr in C++17 + constexpr BidirectionalIterator prev(BidirectionalIterator x, + typename iterator_traits<BidirectionalIterator>::difference_type n = 1); + +template <class Iterator> +class reverse_iterator + : public iterator<typename iterator_traits<Iterator>::iterator_category, + typename iterator_traits<Iterator>::value_type, + typename iterator_traits<Iterator>::difference_type, + typename iterator_traits<Iterator>::pointer, + typename iterator_traits<Iterator>::reference> +{ +protected: + Iterator current; +public: + typedef Iterator iterator_type; + typedef typename iterator_traits<Iterator>::difference_type difference_type; + typedef typename iterator_traits<Iterator>::reference reference; + typedef typename iterator_traits<Iterator>::pointer pointer; + + constexpr reverse_iterator(); + constexpr explicit reverse_iterator(Iterator x); + template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u); + template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u); + constexpr Iterator base() const; + constexpr reference operator*() const; + constexpr pointer operator->() const; + constexpr reverse_iterator& operator++(); + constexpr reverse_iterator operator++(int); + constexpr reverse_iterator& operator--(); + constexpr reverse_iterator operator--(int); + constexpr reverse_iterator operator+ (difference_type n) const; + constexpr reverse_iterator& operator+=(difference_type n); + constexpr reverse_iterator operator- (difference_type n) const; + constexpr reverse_iterator& operator-=(difference_type n); + constexpr reference operator[](difference_type n) const; +}; + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr auto +operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y) +-> decltype(__y.base() - __x.base()); // constexpr in C++17 + +template <class Iterator> +constexpr reverse_iterator<Iterator> +operator+(typename reverse_iterator<Iterator>::difference_type n, + const reverse_iterator<Iterator>& x); // constexpr in C++17 + +template <class Iterator> +constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17 + +template <class Container> +class back_insert_iterator +{ +protected: + Container* container; +public: + typedef Container container_type; + typedef void value_type; + typedef void difference_type; + typedef void reference; + typedef void pointer; + + explicit back_insert_iterator(Container& x); + back_insert_iterator& operator=(const typename Container::value_type& value); + back_insert_iterator& operator*(); + back_insert_iterator& operator++(); + back_insert_iterator operator++(int); +}; + +template <class Container> back_insert_iterator<Container> back_inserter(Container& x); + +template <class Container> +class front_insert_iterator +{ +protected: + Container* container; +public: + typedef Container container_type; + typedef void value_type; + typedef void difference_type; + typedef void reference; + typedef void pointer; + + explicit front_insert_iterator(Container& x); + front_insert_iterator& operator=(const typename Container::value_type& value); + front_insert_iterator& operator*(); + front_insert_iterator& operator++(); + front_insert_iterator operator++(int); +}; + +template <class Container> front_insert_iterator<Container> front_inserter(Container& x); + +template <class Container> +class insert_iterator +{ +protected: + Container* container; + typename Container::iterator iter; +public: + typedef Container container_type; + typedef void value_type; + typedef void difference_type; + typedef void reference; + typedef void pointer; + + insert_iterator(Container& x, typename Container::iterator i); + insert_iterator& operator=(const typename Container::value_type& value); + insert_iterator& operator*(); + insert_iterator& operator++(); + insert_iterator& operator++(int); +}; + +template <class Container, class Iterator> +insert_iterator<Container> inserter(Container& x, Iterator i); + +template <class Iterator> +class move_iterator { +public: + typedef Iterator iterator_type; + typedef typename iterator_traits<Iterator>::difference_type difference_type; + typedef Iterator pointer; + typedef typename iterator_traits<Iterator>::value_type value_type; + typedef typename iterator_traits<Iterator>::iterator_category iterator_category; + typedef value_type&& reference; + + constexpr move_iterator(); // all the constexprs are in C++17 + constexpr explicit move_iterator(Iterator i); + template <class U> + constexpr move_iterator(const move_iterator<U>& u); + template <class U> + constexpr move_iterator& operator=(const move_iterator<U>& u); + constexpr iterator_type base() const; + constexpr reference operator*() const; + constexpr pointer operator->() const; + constexpr move_iterator& operator++(); + constexpr move_iterator operator++(int); + constexpr move_iterator& operator--(); + constexpr move_iterator operator--(int); + constexpr move_iterator operator+(difference_type n) const; + constexpr move_iterator& operator+=(difference_type n); + constexpr move_iterator operator-(difference_type n) const; + constexpr move_iterator& operator-=(difference_type n); + constexpr unspecified operator[](difference_type n) const; +private: + Iterator current; // exposition only +}; + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr bool // constexpr in C++17 +operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); + +template <class Iterator1, class Iterator2> +constexpr auto // constexpr in C++17 +operator-(const move_iterator<Iterator1>& x, + const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base()); + +template <class Iterator> +constexpr move_iterator<Iterator> operator+( // constexpr in C++17 + typename move_iterator<Iterator>::difference_type n, + const move_iterator<Iterator>& x); + +template <class Iterator> // constexpr in C++17 +constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i); + + +template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> +class istream_iterator + : public iterator<input_iterator_tag, T, Distance, const T*, const T&> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_istream<charT,traits> istream_type; + + constexpr istream_iterator(); + istream_iterator(istream_type& s); + istream_iterator(const istream_iterator& x); + ~istream_iterator(); + + const T& operator*() const; + const T* operator->() const; + istream_iterator& operator++(); + istream_iterator operator++(int); +}; + +template <class T, class charT, class traits, class Distance> +bool operator==(const istream_iterator<T,charT,traits,Distance>& x, + const istream_iterator<T,charT,traits,Distance>& y); +template <class T, class charT, class traits, class Distance> +bool operator!=(const istream_iterator<T,charT,traits,Distance>& x, + const istream_iterator<T,charT,traits,Distance>& y); + +template <class T, class charT = char, class traits = char_traits<charT> > +class ostream_iterator + : public iterator<output_iterator_tag, void, void, void ,void> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_ostream<charT,traits> ostream_type; + + ostream_iterator(ostream_type& s); + ostream_iterator(ostream_type& s, const charT* delimiter); + ostream_iterator(const ostream_iterator& x); + ~ostream_iterator(); + ostream_iterator& operator=(const T& value); + + ostream_iterator& operator*(); + ostream_iterator& operator++(); + ostream_iterator& operator++(int); +}; + +template<class charT, class traits = char_traits<charT> > +class istreambuf_iterator + : public iterator<input_iterator_tag, charT, + typename traits::off_type, unspecified, + charT> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits::int_type int_type; + typedef basic_streambuf<charT,traits> streambuf_type; + typedef basic_istream<charT,traits> istream_type; + + istreambuf_iterator() noexcept; + istreambuf_iterator(istream_type& s) noexcept; + istreambuf_iterator(streambuf_type* s) noexcept; + istreambuf_iterator(a-private-type) noexcept; + + charT operator*() const; + pointer operator->() const; + istreambuf_iterator& operator++(); + a-private-type operator++(int); + + bool equal(const istreambuf_iterator& b) const; +}; + +template <class charT, class traits> +bool operator==(const istreambuf_iterator<charT,traits>& a, + const istreambuf_iterator<charT,traits>& b); +template <class charT, class traits> +bool operator!=(const istreambuf_iterator<charT,traits>& a, + const istreambuf_iterator<charT,traits>& b); + +template <class charT, class traits = char_traits<charT> > +class ostreambuf_iterator + : public iterator<output_iterator_tag, void, void, void, void> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_streambuf<charT,traits> streambuf_type; + typedef basic_ostream<charT,traits> ostream_type; + + ostreambuf_iterator(ostream_type& s) noexcept; + ostreambuf_iterator(streambuf_type* s) noexcept; + ostreambuf_iterator& operator=(charT c); + ostreambuf_iterator& operator*(); + ostreambuf_iterator& operator++(); + ostreambuf_iterator& operator++(int); + bool failed() const noexcept; +}; + +template <class C> constexpr auto begin(C& c) -> decltype(c.begin()); +template <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); +template <class C> constexpr auto end(C& c) -> decltype(c.end()); +template <class C> constexpr auto end(const C& c) -> decltype(c.end()); +template <class T, size_t N> constexpr T* begin(T (&array)[N]); +template <class T, size_t N> constexpr T* end(T (&array)[N]); + +template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 +template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 +template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 +template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 +template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 +template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 +template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14 +template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14 +template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 +template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 +template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 +template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 + +// 24.8, container access: +template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17 +template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17 + +template <class C> constexpr auto ssize(const C& c) + -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20 +template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20 + +template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 +template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17 +template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17 +template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17 +template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17 +template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17 +template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17 + +} // std + +*/ + +#include <__config> +#include <iosfwd> // for forward declarations of vector and string. +#include <__functional_base> +#include <type_traits> +#include <cstddef> +#include <initializer_list> +#include <version> +#ifdef __APPLE__ +#include <Availability.h> +#endif + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {}; +struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {}; +struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {}; +struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {}; +struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {}; + +template <class _Tp> +struct __has_iterator_typedefs +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + template <class _Up> static char __test(typename std::__void_t<typename _Up::iterator_category>::type* = 0, + typename std::__void_t<typename _Up::difference_type>::type* = 0, + typename std::__void_t<typename _Up::value_type>::type* = 0, + typename std::__void_t<typename _Up::reference>::type* = 0, + typename std::__void_t<typename _Up::pointer>::type* = 0 + ); +public: + static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1; +}; + + +template <class _Tp> +struct __has_iterator_category +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + template <class _Up> static char __test(typename _Up::iterator_category* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template <class _Iter, bool> struct __iterator_traits_impl {}; + +template <class _Iter> +struct __iterator_traits_impl<_Iter, true> +{ + typedef typename _Iter::difference_type difference_type; + typedef typename _Iter::value_type value_type; + typedef typename _Iter::pointer pointer; + typedef typename _Iter::reference reference; + typedef typename _Iter::iterator_category iterator_category; +}; + +template <class _Iter, bool> struct __iterator_traits {}; + +template <class _Iter> +struct __iterator_traits<_Iter, true> + : __iterator_traits_impl + < + _Iter, + is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value || + is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value + > +{}; + +// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category +// exists. Else iterator_traits<Iterator> will be an empty class. This is a +// conforming extension which allows some programs to compile and behave as +// the client expects instead of failing at compile time. + +template <class _Iter> +struct _LIBCPP_TEMPLATE_VIS iterator_traits + : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {}; + +template<class _Tp> +struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> +{ + typedef ptrdiff_t difference_type; + typedef typename remove_cv<_Tp>::type value_type; + typedef _Tp* pointer; + typedef _Tp& reference; + typedef random_access_iterator_tag iterator_category; +}; + +template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value> +struct __has_iterator_category_convertible_to + : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value> +{}; + +template <class _Tp, class _Up> +struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {}; + +template <class _Tp> +struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {}; + +template <class _Tp> +struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {}; + +template <class _Tp> +struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {}; + +template <class _Tp> +struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; + +template <class _Tp> +struct __is_exactly_input_iterator + : public integral_constant<bool, + __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && + !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; + +template<class _Category, class _Tp, class _Distance = ptrdiff_t, + class _Pointer = _Tp*, class _Reference = _Tp&> +struct _LIBCPP_TEMPLATE_VIS iterator +{ + typedef _Tp value_type; + typedef _Distance difference_type; + typedef _Pointer pointer; + typedef _Reference reference; + typedef _Category iterator_category; +}; + +template <class _InputIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +void __advance(_InputIter& __i, + typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) +{ + for (; __n > 0; --__n) + ++__i; +} + +template <class _BiDirIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +void __advance(_BiDirIter& __i, + typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) +{ + if (__n >= 0) + for (; __n > 0; --__n) + ++__i; + else + for (; __n < 0; ++__n) + --__i; +} + +template <class _RandIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +void __advance(_RandIter& __i, + typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) +{ + __i += __n; +} + +template <class _InputIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +void advance(_InputIter& __i, + typename iterator_traits<_InputIter>::difference_type __n) +{ + _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value, + "Attempt to advance(it, -n) on a non-bidi iterator"); + __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); +} + +template <class _InputIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename iterator_traits<_InputIter>::difference_type +__distance(_InputIter __first, _InputIter __last, input_iterator_tag) +{ + typename iterator_traits<_InputIter>::difference_type __r(0); + for (; __first != __last; ++__first) + ++__r; + return __r; +} + +template <class _RandIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename iterator_traits<_RandIter>::difference_type +__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) +{ + return __last - __first; +} + +template <class _InputIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename iterator_traits<_InputIter>::difference_type +distance(_InputIter __first, _InputIter __last) +{ + return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); +} + +template <class _InputIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename enable_if +< + __is_input_iterator<_InputIter>::value, + _InputIter +>::type +next(_InputIter __x, + typename iterator_traits<_InputIter>::difference_type __n = 1) +{ + _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value, + "Attempt to next(it, -n) on a non-bidi iterator"); + + _VSTD::advance(__x, __n); + return __x; +} + +template <class _InputIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename enable_if +< + __is_input_iterator<_InputIter>::value, + _InputIter +>::type +prev(_InputIter __x, + typename iterator_traits<_InputIter>::difference_type __n = 1) +{ + _LIBCPP_ASSERT(__n <= 0 || __is_bidirectional_iterator<_InputIter>::value, + "Attempt to prev(it, +n) on a non-bidi iterator"); + _VSTD::advance(__x, -__n); + return __x; +} + + +template <class _Tp, class = void> +struct __is_stashing_iterator : false_type {}; + +template <class _Tp> +struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type> + : true_type {}; + +template <class _Iter> +class _LIBCPP_TEMPLATE_VIS reverse_iterator + : public iterator<typename iterator_traits<_Iter>::iterator_category, + typename iterator_traits<_Iter>::value_type, + typename iterator_traits<_Iter>::difference_type, + typename iterator_traits<_Iter>::pointer, + typename iterator_traits<_Iter>::reference> +{ +private: + /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break + + static_assert(!__is_stashing_iterator<_Iter>::value, + "The specified iterator type cannot be used with reverse_iterator; " + "Using stashing iterators with reverse_iterator causes undefined behavior"); + +protected: + _Iter current; +public: + typedef _Iter iterator_type; + typedef typename iterator_traits<_Iter>::difference_type difference_type; + typedef typename iterator_traits<_Iter>::reference reference; + typedef typename iterator_traits<_Iter>::pointer pointer; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator() : __t(), current() {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator=(const reverse_iterator<_Up>& __u) + { __t = current = __u.base(); return *this; } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _Iter base() const {return current;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator*() const {_Iter __tmp = current; return *--__tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + pointer operator->() const {return _VSTD::addressof(operator*());} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator++() {--current; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator--() {++current; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator[](difference_type __n) const {return *(*this + __n);} +}; + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() == __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() > __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() != __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() < __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() <= __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() >= __y.base(); +} + +#ifndef _LIBCPP_CXX03_LANG +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +-> decltype(__y.base() - __x.base()) +{ + return __y.base() - __x.base(); +} +#else +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY +typename reverse_iterator<_Iter1>::difference_type +operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __y.base() - __x.base(); +} +#endif + +template <class _Iter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Iter> +operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) +{ + return reverse_iterator<_Iter>(__x.base() - __n); +} + +#if _LIBCPP_STD_VER > 11 +template <class _Iter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) +{ + return reverse_iterator<_Iter>(__i); +} +#endif + +template <class _Container> +class _LIBCPP_TEMPLATE_VIS back_insert_iterator + : public iterator<output_iterator_tag, + void, + void, + void, + void> +{ +protected: + _Container* container; +public: + typedef _Container container_type; + + _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} + _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_) + {container->push_back(__value_); return *this;} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) + {container->push_back(_VSTD::move(__value_)); return *this;} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;} +}; + +template <class _Container> +inline _LIBCPP_INLINE_VISIBILITY +back_insert_iterator<_Container> +back_inserter(_Container& __x) +{ + return back_insert_iterator<_Container>(__x); +} + +template <class _Container> +class _LIBCPP_TEMPLATE_VIS front_insert_iterator + : public iterator<output_iterator_tag, + void, + void, + void, + void> +{ +protected: + _Container* container; +public: + typedef _Container container_type; + + _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} + _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_) + {container->push_front(__value_); return *this;} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) + {container->push_front(_VSTD::move(__value_)); return *this;} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;} +}; + +template <class _Container> +inline _LIBCPP_INLINE_VISIBILITY +front_insert_iterator<_Container> +front_inserter(_Container& __x) +{ + return front_insert_iterator<_Container>(__x); +} + +template <class _Container> +class _LIBCPP_TEMPLATE_VIS insert_iterator + : public iterator<output_iterator_tag, + void, + void, + void, + void> +{ +protected: + _Container* container; + typename _Container::iterator iter; +public: + typedef _Container container_type; + + _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i) + : container(_VSTD::addressof(__x)), iter(__i) {} + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_) + {iter = container->insert(iter, __value_); ++iter; return *this;} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) + {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;} +}; + +template <class _Container> +inline _LIBCPP_INLINE_VISIBILITY +insert_iterator<_Container> +inserter(_Container& __x, typename _Container::iterator __i) +{ + return insert_iterator<_Container>(__x, __i); +} + +template <class _Tp, class _CharT = char, + class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t> +class _LIBCPP_TEMPLATE_VIS istream_iterator + : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_istream<_CharT,_Traits> istream_type; +private: + istream_type* __in_stream_; + _Tp __value_; +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {} + _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s)) + { + if (!(*__in_stream_ >> __value_)) + __in_stream_ = 0; + } + + _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} + _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));} + _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() + { + if (!(*__in_stream_ >> __value_)) + __in_stream_ = 0; + return *this; + } + _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) + {istream_iterator __t(*this); ++(*this); return __t;} + + template <class _Up, class _CharU, class _TraitsU, class _DistanceU> + friend _LIBCPP_INLINE_VISIBILITY + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); + + template <class _Up, class _CharU, class _TraitsU, class _DistanceU> + friend _LIBCPP_INLINE_VISIBILITY + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); +}; + +template <class _Tp, class _CharT, class _Traits, class _Distance> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return __x.__in_stream_ == __y.__in_stream_; +} + +template <class _Tp, class _CharT, class _Traits, class _Distance> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > +class _LIBCPP_TEMPLATE_VIS ostream_iterator + : public iterator<output_iterator_tag, void, void, void, void> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_ostream<_CharT,_Traits> ostream_type; +private: + ostream_type* __out_stream_; + const char_type* __delim_; +public: + _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT + : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {} + _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT + : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} + _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) + { + *__out_stream_ << __value_; + if (__delim_) + *__out_stream_ << __delim_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} +}; + +template<class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS istreambuf_iterator + : public iterator<input_iterator_tag, _CharT, + typename _Traits::off_type, _CharT*, + _CharT> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename _Traits::int_type int_type; + typedef basic_streambuf<_CharT,_Traits> streambuf_type; + typedef basic_istream<_CharT,_Traits> istream_type; +private: + mutable streambuf_type* __sbuf_; + + class __proxy + { + char_type __keep_; + streambuf_type* __sbuf_; + _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) + : __keep_(__c), __sbuf_(__s) {} + friend class istreambuf_iterator; + public: + _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} + }; + + _LIBCPP_INLINE_VISIBILITY + bool __test_for_eof() const + { + if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) + __sbuf_ = 0; + return __sbuf_ == 0; + } +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {} + _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT + : __sbuf_(__s.rdbuf()) {} + _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT + : __sbuf_(__s) {} + _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT + : __sbuf_(__p.__sbuf_) {} + + _LIBCPP_INLINE_VISIBILITY char_type operator*() const + {return static_cast<char_type>(__sbuf_->sgetc());} + _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() + { + __sbuf_->sbumpc(); + return *this; + } + _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) + { + return __proxy(__sbuf_->sbumpc(), __sbuf_); + } + + _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const + {return __test_for_eof() == __b.__test_for_eof();} +}; + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, + const istreambuf_iterator<_CharT,_Traits>& __b) + {return __a.equal(__b);} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, + const istreambuf_iterator<_CharT,_Traits>& __b) + {return !__a.equal(__b);} + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator + : public iterator<output_iterator_tag, void, void, void, void> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_streambuf<_CharT,_Traits> streambuf_type; + typedef basic_ostream<_CharT,_Traits> ostream_type; +private: + streambuf_type* __sbuf_; +public: + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT + : __sbuf_(__s.rdbuf()) {} + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT + : __sbuf_(__s) {} + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) + { + if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) + __sbuf_ = 0; + return *this; + } + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} + _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;} + +#if !defined(__APPLE__) || \ + (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ + (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) + + template <class _Ch, class _Tr> + friend + _LIBCPP_HIDDEN + ostreambuf_iterator<_Ch, _Tr> + __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, + const _Ch* __ob, const _Ch* __op, const _Ch* __oe, + ios_base& __iob, _Ch __fl); +#endif +}; + +template <class _Iter> +class _LIBCPP_TEMPLATE_VIS move_iterator +{ +private: + _Iter __i; +public: + typedef _Iter iterator_type; + typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; + typedef typename iterator_traits<iterator_type>::value_type value_type; + typedef typename iterator_traits<iterator_type>::difference_type difference_type; + typedef iterator_type pointer; +#ifndef _LIBCPP_CXX03_LANG + typedef typename iterator_traits<iterator_type>::reference __reference; + typedef typename conditional< + is_reference<__reference>::value, + typename remove_reference<__reference>::type&&, + __reference + >::type reference; +#else + typedef typename iterator_traits<iterator_type>::reference reference; +#endif + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator() : __i() {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + explicit move_iterator(_Iter __x) : __i(__x) {} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator*() const { return static_cast<reference>(*__i); } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + pointer operator->() const { return __i;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator& operator++() {++__i; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator& operator--() {--__i; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator& operator+=(difference_type __n) {__i += __n; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); } +}; + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() == __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() < __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() != __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() > __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() >= __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +bool +operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() <= __y.base(); +} + +#ifndef _LIBCPP_CXX03_LANG +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +-> decltype(__x.base() - __y.base()) +{ + return __x.base() - __y.base(); +} +#else +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY +typename move_iterator<_Iter1>::difference_type +operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() - __y.base(); +} +#endif + +template <class _Iter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +move_iterator<_Iter> +operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) +{ + return move_iterator<_Iter>(__x.base() + __n); +} + +template <class _Iter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +move_iterator<_Iter> +make_move_iterator(_Iter __i) +{ + return move_iterator<_Iter>(__i); +} + +// __wrap_iter + +template <class _Iter> class __wrap_iter; + +template <class _Iter1, class _Iter2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template <class _Iter1, class _Iter2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template <class _Iter1, class _Iter2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template <class _Iter1, class _Iter2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template <class _Iter1, class _Iter2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template <class _Iter1, class _Iter2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +#ifndef _LIBCPP_CXX03_LANG +template <class _Iter1, class _Iter2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +auto +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +-> decltype(__x.base() - __y.base()); +#else +template <class _Iter1, class _Iter2> +_LIBCPP_INLINE_VISIBILITY +typename __wrap_iter<_Iter1>::difference_type +operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +#endif + +template <class _Iter> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +__wrap_iter<_Iter> +operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; + +template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op); +template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2); +template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op); +template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2); + +#if _LIBCPP_DEBUG_LEVEL < 2 + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + _Tp* +>::type +__unwrap_iter(__wrap_iter<_Tp*>); + +#else + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + __wrap_iter<_Tp*> +>::type +__unwrap_iter(__wrap_iter<_Tp*> __i); + +#endif + +template <class _Iter> +class __wrap_iter +{ +public: + typedef _Iter iterator_type; + typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; + typedef typename iterator_traits<iterator_type>::value_type value_type; + typedef typename iterator_traits<iterator_type>::difference_type difference_type; + typedef typename iterator_traits<iterator_type>::pointer pointer; + typedef typename iterator_traits<iterator_type>::reference reference; +private: + iterator_type __i; +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __i{} +#endif + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } + template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG + __wrap_iter(const __wrap_iter<_Up>& __u, + typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT + : __i(__u.base()) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__iterator_copy(this, &__u); +#endif + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG + __wrap_iter(const __wrap_iter& __x) + : __i(__x.base()) + { + __get_db()->__iterator_copy(this, &__x); + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG + __wrap_iter& operator=(const __wrap_iter& __x) + { + if (this != &__x) + { + __get_db()->__iterator_copy(this, &__x); + __i = __x.__i; + } + return *this; + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG + ~__wrap_iter() + { + __get_db()->__erase_i(this); + } +#endif + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable iterator"); +#endif + return *__i; + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable iterator"); +#endif + return (pointer)_VSTD::addressof(*__i); + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable iterator"); +#endif + ++__i; + return *this; + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT + {__wrap_iter __tmp(*this); ++(*this); return __tmp;} + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), + "Attempted to decrement non-decrementable iterator"); +#endif + --__i; + return *this; + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT + {__wrap_iter __tmp(*this); --(*this); return __tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT + {__wrap_iter __w(*this); __w += __n; return __w;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), + "Attempted to add/subtract iterator outside of valid range"); +#endif + __i += __n; + return *this; + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT + {return *this + (-__n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT + {*this += -__n; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), + "Attempted to subscript iterator outside of valid range"); +#endif + return __i[__n]; + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;} + +private: +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x) + { + __get_db()->__insert_ic(this, __p); + } +#else + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} +#endif + + template <class _Up> friend class __wrap_iter; + template <class _CharT, class _Traits, class _Alloc> friend class basic_string; + template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector; + template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span; + + template <class _Iter1, class _Iter2> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + bool + operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template <class _Iter1, class _Iter2> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + bool + operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template <class _Iter1, class _Iter2> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + bool + operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template <class _Iter1, class _Iter2> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + bool + operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template <class _Iter1, class _Iter2> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + bool + operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template <class _Iter1, class _Iter2> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + bool + operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +#ifndef _LIBCPP_CXX03_LANG + template <class _Iter1, class _Iter2> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + auto + operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT + -> decltype(__x.base() - __y.base()); +#else + template <class _Iter1, class _Iter2> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + typename __wrap_iter<_Iter1>::difference_type + operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +#endif + + template <class _Iter1> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + __wrap_iter<_Iter1> + operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; + + template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op); + template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2); + template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op); + template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2); + +#if _LIBCPP_DEBUG_LEVEL < 2 + template <class _Tp> + _LIBCPP_CONSTEXPR_IF_NODEBUG friend + typename enable_if + < + is_trivially_copy_assignable<_Tp>::value, + _Tp* + >::type + __unwrap_iter(__wrap_iter<_Tp*>); +#else + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG + typename enable_if + < + is_trivially_copy_assignable<_Tp>::value, + __wrap_iter<_Tp*> + >::type + __unwrap_iter(__wrap_iter<_Tp*> __i); +#endif +}; + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return __x.base() == __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), + "Attempted to compare incomparable iterators"); +#endif + return __x.base() < __y.base(); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return !(__x == __y); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return __y < __x; +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return !(__x < __y); +} + +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return !(__y < __x); +} + +template <class _Iter1> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +{ + return !(__x == __y); +} + +template <class _Iter1> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +{ + return __y < __x; +} + +template <class _Iter1> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +{ + return !(__x < __y); +} + +template <class _Iter1> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +bool +operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +{ + return !(__y < __x); +} + +#ifndef _LIBCPP_CXX03_LANG +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +auto +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +-> decltype(__x.base() - __y.base()) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), + "Attempted to subtract incompatible iterators"); +#endif + return __x.base() - __y.base(); +} +#else +template <class _Iter1, class _Iter2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +typename __wrap_iter<_Iter1>::difference_type +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), + "Attempted to subtract incompatible iterators"); +#endif + return __x.base() - __y.base(); +} +#endif + +template <class _Iter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +__wrap_iter<_Iter> +operator+(typename __wrap_iter<_Iter>::difference_type __n, + __wrap_iter<_Iter> __x) _NOEXCEPT +{ + __x += __n; + return __x; +} + +template <class _Iter> +struct __libcpp_is_trivial_iterator + : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; + +template <class _Iter> +struct __libcpp_is_trivial_iterator<move_iterator<_Iter> > + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; + +template <class _Iter> +struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> > + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; + +template <class _Iter> +struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; + + +template <class _Tp, size_t _Np> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp* +begin(_Tp (&__array)[_Np]) +{ + return __array; +} + +template <class _Tp, size_t _Np> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp* +end(_Tp (&__array)[_Np]) +{ + return __array + _Np; +} + +#if !defined(_LIBCPP_CXX03_LANG) + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +begin(_Cp& __c) -> decltype(__c.begin()) +{ + return __c.begin(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +begin(const _Cp& __c) -> decltype(__c.begin()) +{ + return __c.begin(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +end(_Cp& __c) -> decltype(__c.end()) +{ + return __c.end(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +end(const _Cp& __c) -> decltype(__c.end()) +{ + return __c.end(); +} + +#if _LIBCPP_STD_VER > 11 + +template <class _Tp, size_t _Np> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) +{ + return reverse_iterator<_Tp*>(__array + _Np); +} + +template <class _Tp, size_t _Np> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) +{ + return reverse_iterator<_Tp*>(__array); +} + +template <class _Ep> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) +{ + return reverse_iterator<const _Ep*>(__il.end()); +} + +template <class _Ep> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) +{ + return reverse_iterator<const _Ep*>(__il.begin()); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) +{ + return _VSTD::begin(__c); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) +{ + return _VSTD::end(__c); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) +{ + return __c.rbegin(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) +{ + return __c.rbegin(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto rend(_Cp& __c) -> decltype(__c.rend()) +{ + return __c.rend(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto rend(const _Cp& __c) -> decltype(__c.rend()) +{ + return __c.rend(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) +{ + return _VSTD::rbegin(__c); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) +{ + return _VSTD::rend(__c); +} + +#endif + + +#else // defined(_LIBCPP_CXX03_LANG) + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY +typename _Cp::iterator +begin(_Cp& __c) +{ + return __c.begin(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY +typename _Cp::const_iterator +begin(const _Cp& __c) +{ + return __c.begin(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY +typename _Cp::iterator +end(_Cp& __c) +{ + return __c.end(); +} + +template <class _Cp> +_LIBCPP_INLINE_VISIBILITY +typename _Cp::const_iterator +end(const _Cp& __c) +{ + return __c.end(); +} + +#endif // !defined(_LIBCPP_CXX03_LANG) + +#if _LIBCPP_STD_VER > 14 + +// #if _LIBCPP_STD_VER > 11 +// template <> +// struct _LIBCPP_TEMPLATE_VIS plus<void> +// { +// template <class _T1, class _T2> +// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +// auto operator()(_T1&& __t, _T2&& __u) const +// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) +// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) +// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } +// typedef void is_transparent; +// }; +// #endif + +template <class _Cont> +_LIBCPP_INLINE_VISIBILITY +constexpr auto size(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.size())) +-> decltype (__c.size()) +{ return __c.size(); } + +template <class _Tp, size_t _Sz> +_LIBCPP_INLINE_VISIBILITY +constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } + +#if _LIBCPP_STD_VER > 17 +template <class _Cont> +_LIBCPP_INLINE_VISIBILITY +constexpr auto ssize(const _Cont& __c) +_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()))) +-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> +{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); } + +template <class _Tp, ptrdiff_t _Sz> +_LIBCPP_INLINE_VISIBILITY +constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } +#endif + +template <class _Cont> +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY +constexpr auto empty(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.empty())) +-> decltype (__c.empty()) +{ return __c.empty(); } + +template <class _Tp, size_t _Sz> +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY +constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } + +template <class _Ep> +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY +constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } + +template <class _Cont> constexpr +_LIBCPP_INLINE_VISIBILITY +auto data(_Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } + +template <class _Cont> constexpr +_LIBCPP_INLINE_VISIBILITY +auto data(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } + +template <class _Tp, size_t _Sz> +_LIBCPP_INLINE_VISIBILITY +constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } + +template <class _Ep> +_LIBCPP_INLINE_VISIBILITY +constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } +#endif + + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ITERATOR diff --git a/android/x86/include/v8/libc++/limits b/android/x86/include/v8/libc++/limits new file mode 100755 index 00000000..82c1ea13 --- /dev/null +++ b/android/x86/include/v8/libc++/limits @@ -0,0 +1,818 @@ +// -*- C++ -*- +//===---------------------------- limits ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LIMITS +#define _LIBCPP_LIMITS + +/* + limits synopsis + +namespace std +{ + +template<class T> +class numeric_limits +{ +public: + static constexpr bool is_specialized = false; + static constexpr T min() noexcept; + static constexpr T max() noexcept; + static constexpr T lowest() noexcept; + + static constexpr int digits = 0; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + static constexpr bool is_signed = false; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = 0; + static constexpr T epsilon() noexcept; + static constexpr T round_error() noexcept; + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr T infinity() noexcept; + static constexpr T quiet_NaN() noexcept; + static constexpr T signaling_NaN() noexcept; + static constexpr T denorm_min() noexcept; + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = false; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; +}; + +enum float_round_style +{ + round_indeterminate = -1, + round_toward_zero = 0, + round_to_nearest = 1, + round_toward_infinity = 2, + round_toward_neg_infinity = 3 +}; + +enum float_denorm_style +{ + denorm_indeterminate = -1, + denorm_absent = 0, + denorm_present = 1 +}; + +template<> class numeric_limits<cv bool>; + +template<> class numeric_limits<cv char>; +template<> class numeric_limits<cv signed char>; +template<> class numeric_limits<cv unsigned char>; +template<> class numeric_limits<cv wchar_t>; +template<> class numeric_limits<cv char8_t>; // C++20 +template<> class numeric_limits<cv char16_t>; +template<> class numeric_limits<cv char32_t>; + +template<> class numeric_limits<cv short>; +template<> class numeric_limits<cv int>; +template<> class numeric_limits<cv long>; +template<> class numeric_limits<cv long long>; +template<> class numeric_limits<cv unsigned short>; +template<> class numeric_limits<cv unsigned int>; +template<> class numeric_limits<cv unsigned long>; +template<> class numeric_limits<cv unsigned long long>; + +template<> class numeric_limits<cv float>; +template<> class numeric_limits<cv double>; +template<> class numeric_limits<cv long double>; + +} // std + +*/ +#include <__config> +#include <type_traits> + +#if defined(_LIBCPP_COMPILER_MSVC) +#include "support/win32/limits_msvc_win32.h" +#endif // _LIBCPP_MSVCRT + +#if defined(__IBMCPP__) +#include "support/ibm/limits.h" +#endif // __IBMCPP__ + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> +#include <version> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +enum float_round_style +{ + round_indeterminate = -1, + round_toward_zero = 0, + round_to_nearest = 1, + round_toward_infinity = 2, + round_toward_neg_infinity = 3 +}; + +enum float_denorm_style +{ + denorm_indeterminate = -1, + denorm_absent = 0, + denorm_present = 1 +}; + +template <class _Tp, bool = is_arithmetic<_Tp>::value> +class __libcpp_numeric_limits +{ +protected: + typedef _Tp type; + + static _LIBCPP_CONSTEXPR const bool is_specialized = false; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return type();} + + static _LIBCPP_CONSTEXPR const int digits = 0; + static _LIBCPP_CONSTEXPR const int digits10 = 0; + static _LIBCPP_CONSTEXPR const int max_digits10 = 0; + static _LIBCPP_CONSTEXPR const bool is_signed = false; + static _LIBCPP_CONSTEXPR const bool is_integer = false; + static _LIBCPP_CONSTEXPR const bool is_exact = false; + static _LIBCPP_CONSTEXPR const int radix = 0; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return type();} + + static _LIBCPP_CONSTEXPR const int min_exponent = 0; + static _LIBCPP_CONSTEXPR const int min_exponent10 = 0; + static _LIBCPP_CONSTEXPR const int max_exponent = 0; + static _LIBCPP_CONSTEXPR const int max_exponent10 = 0; + + static _LIBCPP_CONSTEXPR const bool has_infinity = false; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return type();} + + static _LIBCPP_CONSTEXPR const bool is_iec559 = false; + static _LIBCPP_CONSTEXPR const bool is_bounded = false; + static _LIBCPP_CONSTEXPR const bool is_modulo = false; + + static _LIBCPP_CONSTEXPR const bool traps = false; + static _LIBCPP_CONSTEXPR const bool tinyness_before = false; + static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; +}; + +template <class _Tp, int __digits, bool _IsSigned> +struct __libcpp_compute_min +{ + static _LIBCPP_CONSTEXPR const _Tp value = _Tp(_Tp(1) << __digits); +}; + +template <class _Tp, int __digits> +struct __libcpp_compute_min<_Tp, __digits, false> +{ + static _LIBCPP_CONSTEXPR const _Tp value = _Tp(0); +}; + +template <class _Tp> +class __libcpp_numeric_limits<_Tp, true> +{ +protected: + typedef _Tp type; + + static _LIBCPP_CONSTEXPR const bool is_specialized = true; + + static _LIBCPP_CONSTEXPR const bool is_signed = type(-1) < type(0); + static _LIBCPP_CONSTEXPR const int digits = static_cast<int>(sizeof(type) * __CHAR_BIT__ - is_signed); + static _LIBCPP_CONSTEXPR const int digits10 = digits * 3 / 10; + static _LIBCPP_CONSTEXPR const int max_digits10 = 0; + static _LIBCPP_CONSTEXPR const type __min = __libcpp_compute_min<type, digits, is_signed>::value; + static _LIBCPP_CONSTEXPR const type __max = is_signed ? type(type(~0) ^ __min) : type(~0); + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __min;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __max;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return min();} + + static _LIBCPP_CONSTEXPR const bool is_integer = true; + static _LIBCPP_CONSTEXPR const bool is_exact = true; + static _LIBCPP_CONSTEXPR const int radix = 2; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return type(0);} + + static _LIBCPP_CONSTEXPR const int min_exponent = 0; + static _LIBCPP_CONSTEXPR const int min_exponent10 = 0; + static _LIBCPP_CONSTEXPR const int max_exponent = 0; + static _LIBCPP_CONSTEXPR const int max_exponent10 = 0; + + static _LIBCPP_CONSTEXPR const bool has_infinity = false; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return type(0);} + + static _LIBCPP_CONSTEXPR const bool is_iec559 = false; + static _LIBCPP_CONSTEXPR const bool is_bounded = true; + static _LIBCPP_CONSTEXPR const bool is_modulo = !_VSTD::is_signed<_Tp>::value; + +#if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || \ + defined(__wasm__) + static _LIBCPP_CONSTEXPR const bool traps = true; +#else + static _LIBCPP_CONSTEXPR const bool traps = false; +#endif + static _LIBCPP_CONSTEXPR const bool tinyness_before = false; + static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; +}; + +template <> +class __libcpp_numeric_limits<bool, true> +{ +protected: + typedef bool type; + + static _LIBCPP_CONSTEXPR const bool is_specialized = true; + + static _LIBCPP_CONSTEXPR const bool is_signed = false; + static _LIBCPP_CONSTEXPR const int digits = 1; + static _LIBCPP_CONSTEXPR const int digits10 = 0; + static _LIBCPP_CONSTEXPR const int max_digits10 = 0; + static _LIBCPP_CONSTEXPR const type __min = false; + static _LIBCPP_CONSTEXPR const type __max = true; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __min;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __max;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return min();} + + static _LIBCPP_CONSTEXPR const bool is_integer = true; + static _LIBCPP_CONSTEXPR const bool is_exact = true; + static _LIBCPP_CONSTEXPR const int radix = 2; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return type(0);} + + static _LIBCPP_CONSTEXPR const int min_exponent = 0; + static _LIBCPP_CONSTEXPR const int min_exponent10 = 0; + static _LIBCPP_CONSTEXPR const int max_exponent = 0; + static _LIBCPP_CONSTEXPR const int max_exponent10 = 0; + + static _LIBCPP_CONSTEXPR const bool has_infinity = false; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return type(0);} + + static _LIBCPP_CONSTEXPR const bool is_iec559 = false; + static _LIBCPP_CONSTEXPR const bool is_bounded = true; + static _LIBCPP_CONSTEXPR const bool is_modulo = false; + + static _LIBCPP_CONSTEXPR const bool traps = false; + static _LIBCPP_CONSTEXPR const bool tinyness_before = false; + static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; +}; + +template <> +class __libcpp_numeric_limits<float, true> +{ +protected: + typedef float type; + + static _LIBCPP_CONSTEXPR const bool is_specialized = true; + + static _LIBCPP_CONSTEXPR const bool is_signed = true; + static _LIBCPP_CONSTEXPR const int digits = __FLT_MANT_DIG__; + static _LIBCPP_CONSTEXPR const int digits10 = __FLT_DIG__; + static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103l)/100000l; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __FLT_MIN__;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __FLT_MAX__;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return -max();} + + static _LIBCPP_CONSTEXPR const bool is_integer = false; + static _LIBCPP_CONSTEXPR const bool is_exact = false; + static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __FLT_EPSILON__;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return 0.5F;} + + static _LIBCPP_CONSTEXPR const int min_exponent = __FLT_MIN_EXP__; + static _LIBCPP_CONSTEXPR const int min_exponent10 = __FLT_MIN_10_EXP__; + static _LIBCPP_CONSTEXPR const int max_exponent = __FLT_MAX_EXP__; + static _LIBCPP_CONSTEXPR const int max_exponent10 = __FLT_MAX_10_EXP__; + + static _LIBCPP_CONSTEXPR const bool has_infinity = true; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __builtin_huge_valf();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __builtin_nanf("");} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __builtin_nansf("");} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __FLT_DENORM_MIN__;} + + static _LIBCPP_CONSTEXPR const bool is_iec559 = true; + static _LIBCPP_CONSTEXPR const bool is_bounded = true; + static _LIBCPP_CONSTEXPR const bool is_modulo = false; + + static _LIBCPP_CONSTEXPR const bool traps = false; + static _LIBCPP_CONSTEXPR const bool tinyness_before = false; + static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest; +}; + +template <> +class __libcpp_numeric_limits<double, true> +{ +protected: + typedef double type; + + static _LIBCPP_CONSTEXPR const bool is_specialized = true; + + static _LIBCPP_CONSTEXPR const bool is_signed = true; + static _LIBCPP_CONSTEXPR const int digits = __DBL_MANT_DIG__; + static _LIBCPP_CONSTEXPR const int digits10 = __DBL_DIG__; + static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103l)/100000l; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __DBL_MIN__;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __DBL_MAX__;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return -max();} + + static _LIBCPP_CONSTEXPR const bool is_integer = false; + static _LIBCPP_CONSTEXPR const bool is_exact = false; + static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __DBL_EPSILON__;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return 0.5;} + + static _LIBCPP_CONSTEXPR const int min_exponent = __DBL_MIN_EXP__; + static _LIBCPP_CONSTEXPR const int min_exponent10 = __DBL_MIN_10_EXP__; + static _LIBCPP_CONSTEXPR const int max_exponent = __DBL_MAX_EXP__; + static _LIBCPP_CONSTEXPR const int max_exponent10 = __DBL_MAX_10_EXP__; + + static _LIBCPP_CONSTEXPR const bool has_infinity = true; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __builtin_huge_val();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __builtin_nan("");} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __builtin_nans("");} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __DBL_DENORM_MIN__;} + + static _LIBCPP_CONSTEXPR const bool is_iec559 = true; + static _LIBCPP_CONSTEXPR const bool is_bounded = true; + static _LIBCPP_CONSTEXPR const bool is_modulo = false; + + static _LIBCPP_CONSTEXPR const bool traps = false; + static _LIBCPP_CONSTEXPR const bool tinyness_before = false; + static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest; +}; + +template <> +class __libcpp_numeric_limits<long double, true> +{ +protected: + typedef long double type; + + static _LIBCPP_CONSTEXPR const bool is_specialized = true; + + static _LIBCPP_CONSTEXPR const bool is_signed = true; + static _LIBCPP_CONSTEXPR const int digits = __LDBL_MANT_DIG__; + static _LIBCPP_CONSTEXPR const int digits10 = __LDBL_DIG__; + static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103l)/100000l; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __LDBL_MIN__;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __LDBL_MAX__;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return -max();} + + static _LIBCPP_CONSTEXPR const bool is_integer = false; + static _LIBCPP_CONSTEXPR const bool is_exact = false; + static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __LDBL_EPSILON__;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return 0.5;} + + static _LIBCPP_CONSTEXPR const int min_exponent = __LDBL_MIN_EXP__; + static _LIBCPP_CONSTEXPR const int min_exponent10 = __LDBL_MIN_10_EXP__; + static _LIBCPP_CONSTEXPR const int max_exponent = __LDBL_MAX_EXP__; + static _LIBCPP_CONSTEXPR const int max_exponent10 = __LDBL_MAX_10_EXP__; + + static _LIBCPP_CONSTEXPR const bool has_infinity = true; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __builtin_huge_vall();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __builtin_nanl("");} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __builtin_nansl("");} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __LDBL_DENORM_MIN__;} + +#if (defined(__ppc__) || defined(__ppc64__)) + static _LIBCPP_CONSTEXPR const bool is_iec559 = false; +#else + static _LIBCPP_CONSTEXPR const bool is_iec559 = true; +#endif + static _LIBCPP_CONSTEXPR const bool is_bounded = true; + static _LIBCPP_CONSTEXPR const bool is_modulo = false; + + static _LIBCPP_CONSTEXPR const bool traps = false; + static _LIBCPP_CONSTEXPR const bool tinyness_before = false; + static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest; +}; + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS numeric_limits + : private __libcpp_numeric_limits<typename remove_cv<_Tp>::type> +{ + typedef __libcpp_numeric_limits<typename remove_cv<_Tp>::type> __base; + typedef typename __base::type type; +public: + static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __base::min();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __base::max();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return __base::lowest();} + + static _LIBCPP_CONSTEXPR const int digits = __base::digits; + static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10; + static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10; + static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed; + static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer; + static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact; + static _LIBCPP_CONSTEXPR const int radix = __base::radix; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __base::epsilon();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return __base::round_error();} + + static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent; + static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10; + static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent; + static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10; + + static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __base::infinity();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __base::denorm_min();} + + static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559; + static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded; + static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo; + + static _LIBCPP_CONSTEXPR const bool traps = __base::traps; + static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before; + static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style; +}; + +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_specialized; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits10; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_digits10; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_signed; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_integer; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_exact; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::radix; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent10; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent10; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_infinity; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_quiet_NaN; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_signaling_NaN; +template <class _Tp> + _LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<_Tp>::has_denorm; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_denorm_loss; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_iec559; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_bounded; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_modulo; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::traps; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::tinyness_before; +template <class _Tp> + _LIBCPP_CONSTEXPR const float_round_style numeric_limits<_Tp>::round_style; + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS numeric_limits<const _Tp> + : private numeric_limits<_Tp> +{ + typedef numeric_limits<_Tp> __base; + typedef _Tp type; +public: + static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __base::min();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __base::max();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return __base::lowest();} + + static _LIBCPP_CONSTEXPR const int digits = __base::digits; + static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10; + static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10; + static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed; + static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer; + static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact; + static _LIBCPP_CONSTEXPR const int radix = __base::radix; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __base::epsilon();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return __base::round_error();} + + static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent; + static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10; + static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent; + static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10; + + static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __base::infinity();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __base::denorm_min();} + + static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559; + static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded; + static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo; + + static _LIBCPP_CONSTEXPR const bool traps = __base::traps; + static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before; + static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style; +}; + +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_specialized; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::digits; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::digits10; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::max_digits10; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_signed; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_integer; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_exact; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::radix; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::min_exponent; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::min_exponent10; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::max_exponent; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::max_exponent10; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_infinity; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_quiet_NaN; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_signaling_NaN; +template <class _Tp> + _LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<const _Tp>::has_denorm; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_denorm_loss; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_iec559; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_bounded; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_modulo; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::traps; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::tinyness_before; +template <class _Tp> + _LIBCPP_CONSTEXPR const float_round_style numeric_limits<const _Tp>::round_style; + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS numeric_limits<volatile _Tp> + : private numeric_limits<_Tp> +{ + typedef numeric_limits<_Tp> __base; + typedef _Tp type; +public: + static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __base::min();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __base::max();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return __base::lowest();} + + static _LIBCPP_CONSTEXPR const int digits = __base::digits; + static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10; + static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10; + static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed; + static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer; + static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact; + static _LIBCPP_CONSTEXPR const int radix = __base::radix; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __base::epsilon();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return __base::round_error();} + + static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent; + static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10; + static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent; + static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10; + + static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __base::infinity();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __base::denorm_min();} + + static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559; + static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded; + static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo; + + static _LIBCPP_CONSTEXPR const bool traps = __base::traps; + static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before; + static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style; +}; + +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_specialized; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::digits; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::digits10; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::max_digits10; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_signed; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_integer; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_exact; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::radix; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::min_exponent; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::min_exponent10; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::max_exponent; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::max_exponent10; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_infinity; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_quiet_NaN; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_signaling_NaN; +template <class _Tp> + _LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<volatile _Tp>::has_denorm; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_denorm_loss; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_iec559; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_bounded; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_modulo; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::traps; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::tinyness_before; +template <class _Tp> + _LIBCPP_CONSTEXPR const float_round_style numeric_limits<volatile _Tp>::round_style; + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS numeric_limits<const volatile _Tp> + : private numeric_limits<_Tp> +{ + typedef numeric_limits<_Tp> __base; + typedef _Tp type; +public: + static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __base::min();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __base::max();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return __base::lowest();} + + static _LIBCPP_CONSTEXPR const int digits = __base::digits; + static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10; + static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10; + static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed; + static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer; + static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact; + static _LIBCPP_CONSTEXPR const int radix = __base::radix; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __base::epsilon();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return __base::round_error();} + + static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent; + static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10; + static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent; + static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10; + + static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity; + static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN; + static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN; + static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm; + static _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __base::infinity();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __base::denorm_min();} + + static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559; + static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded; + static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo; + + static _LIBCPP_CONSTEXPR const bool traps = __base::traps; + static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before; + static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style; +}; + +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_specialized; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::digits; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::digits10; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::max_digits10; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_signed; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_integer; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_exact; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::radix; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::min_exponent; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::min_exponent10; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::max_exponent; +template <class _Tp> + _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::max_exponent10; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_infinity; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_quiet_NaN; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_signaling_NaN; +template <class _Tp> + _LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<const volatile _Tp>::has_denorm; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_denorm_loss; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_iec559; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_bounded; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_modulo; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::traps; +template <class _Tp> + _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::tinyness_before; +template <class _Tp> + _LIBCPP_CONSTEXPR const float_round_style numeric_limits<const volatile _Tp>::round_style; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_LIMITS diff --git a/android/x86/include/v8/libc++/limits.h b/android/x86/include/v8/libc++/limits.h new file mode 100755 index 00000000..4a212f8f --- /dev/null +++ b/android/x86/include/v8/libc++/limits.h @@ -0,0 +1,64 @@ +// -*- C++ -*- +//===--------------------------- limits.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LIMITS_H +#define _LIBCPP_LIMITS_H + +/* + limits.h synopsis + +Macros: + + CHAR_BIT + SCHAR_MIN + SCHAR_MAX + UCHAR_MAX + CHAR_MIN + CHAR_MAX + MB_LEN_MAX + SHRT_MIN + SHRT_MAX + USHRT_MAX + INT_MIN + INT_MAX + UINT_MAX + LONG_MIN + LONG_MAX + ULONG_MAX + LLONG_MIN // C99 + LLONG_MAX // C99 + ULLONG_MAX // C99 + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifndef __GNUC__ +#include_next <limits.h> +#else +// GCC header limits.h recursively includes itself through another header called +// syslimits.h for some reason. This setup breaks down if we directly +// #include_next GCC's limits.h (reasons not entirely clear to me). Therefore, +// we manually re-create the necessary include sequence below: + +// Get the system limits.h defines (force recurse into the next level) +#define _GCC_LIMITS_H_ +#define _GCC_NEXT_LIMITS_H +#include_next <limits.h> + +// Get the ISO C defines +#undef _GCC_LIMITS_H_ +#include_next <limits.h> +#endif // __GNUC__ + +#endif // _LIBCPP_LIMITS_H diff --git a/android/x86/include/v8/libc++/list b/android/x86/include/v8/libc++/list new file mode 100755 index 00000000..6e878f44 --- /dev/null +++ b/android/x86/include/v8/libc++/list @@ -0,0 +1,2479 @@ +// -*- C++ -*- +//===---------------------------- list ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LIST +#define _LIBCPP_LIST + +/* + list synopsis + +namespace std +{ + +template <class T, class Alloc = allocator<T> > +class list +{ +public: + + // types: + typedef T value_type; + typedef Alloc allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef implementation-defined size_type; + typedef implementation-defined difference_type; + typedef reverse_iterator<iterator> reverse_iterator; + typedef reverse_iterator<const_iterator> const_reverse_iterator; + + list() + noexcept(is_nothrow_default_constructible<allocator_type>::value); + explicit list(const allocator_type& a); + explicit list(size_type n); + explicit list(size_type n, const allocator_type& a); // C++14 + list(size_type n, const value_type& value); + list(size_type n, const value_type& value, const allocator_type& a); + template <class Iter> + list(Iter first, Iter last); + template <class Iter> + list(Iter first, Iter last, const allocator_type& a); + list(const list& x); + list(const list&, const allocator_type& a); + list(list&& x) + noexcept(is_nothrow_move_constructible<allocator_type>::value); + list(list&&, const allocator_type& a); + list(initializer_list<value_type>); + list(initializer_list<value_type>, const allocator_type& a); + + ~list(); + + list& operator=(const list& x); + list& operator=(list&& x) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value); + list& operator=(initializer_list<value_type>); + template <class Iter> + void assign(Iter first, Iter last); + void assign(size_type n, const value_type& t); + void assign(initializer_list<value_type>); + + allocator_type get_allocator() const noexcept; + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + template <class... Args> + reference emplace_front(Args&&... args); // reference in C++17 + void pop_front(); + template <class... Args> + reference emplace_back(Args&&... args); // reference in C++17 + void pop_back(); + void push_front(const value_type& x); + void push_front(value_type&& x); + void push_back(const value_type& x); + void push_back(value_type&& x); + template <class... Args> + iterator emplace(const_iterator position, Args&&... args); + iterator insert(const_iterator position, const value_type& x); + iterator insert(const_iterator position, value_type&& x); + iterator insert(const_iterator position, size_type n, const value_type& x); + template <class Iter> + iterator insert(const_iterator position, Iter first, Iter last); + iterator insert(const_iterator position, initializer_list<value_type> il); + + iterator erase(const_iterator position); + iterator erase(const_iterator position, const_iterator last); + + void resize(size_type sz); + void resize(size_type sz, const value_type& c); + + void swap(list&) + noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17 + void clear() noexcept; + + void splice(const_iterator position, list& x); + void splice(const_iterator position, list&& x); + void splice(const_iterator position, list& x, const_iterator i); + void splice(const_iterator position, list&& x, const_iterator i); + void splice(const_iterator position, list& x, const_iterator first, + const_iterator last); + void splice(const_iterator position, list&& x, const_iterator first, + const_iterator last); + + void remove(const value_type& value); + template <class Pred> void remove_if(Pred pred); + void unique(); + template <class BinaryPredicate> + void unique(BinaryPredicate binary_pred); + void merge(list& x); + void merge(list&& x); + template <class Compare> + void merge(list& x, Compare comp); + template <class Compare> + void merge(list&& x, Compare comp); + void sort(); + template <class Compare> + void sort(Compare comp); + void reverse() noexcept; +}; + + +template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> + list(InputIterator, InputIterator, Allocator = Allocator()) + -> list<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 + +template <class T, class Alloc> + bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y); +template <class T, class Alloc> + bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y); +template <class T, class Alloc> + bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y); +template <class T, class Alloc> + bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y); +template <class T, class Alloc> + bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y); +template <class T, class Alloc> + bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y); + +template <class T, class Alloc> + void swap(list<T,Alloc>& x, list<T,Alloc>& y) + noexcept(noexcept(x.swap(y))); + +template <class T, class Allocator, class U> + void erase(list<T, Allocator>& c, const U& value); // C++20 +template <class T, class Allocator, class Predicate> + void erase_if(list<T, Allocator>& c, Predicate pred); // C++20 + +} // std + +*/ + +#include <__config> + +#include <memory> +#include <limits> +#include <initializer_list> +#include <iterator> +#include <algorithm> +#include <type_traits> +#include <version> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp, class _VoidPtr> struct __list_node; +template <class _Tp, class _VoidPtr> struct __list_node_base; + +template <class _Tp, class _VoidPtr> +struct __list_node_pointer_traits { + typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type + __node_pointer; + typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type + __base_pointer; + +#if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB) + typedef __base_pointer __link_pointer; +#else + typedef typename conditional< + is_pointer<_VoidPtr>::value, + __base_pointer, + __node_pointer + >::type __link_pointer; +#endif + + typedef typename conditional< + is_same<__link_pointer, __node_pointer>::value, + __base_pointer, + __node_pointer + >::type __non_link_pointer; + + static _LIBCPP_INLINE_VISIBILITY + __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) { + return __p; + } + + static _LIBCPP_INLINE_VISIBILITY + __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) { + return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p)); + } + +}; + +template <class _Tp, class _VoidPtr> +struct __list_node_base +{ + typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; + typedef typename _NodeTraits::__node_pointer __node_pointer; + typedef typename _NodeTraits::__base_pointer __base_pointer; + typedef typename _NodeTraits::__link_pointer __link_pointer; + + __link_pointer __prev_; + __link_pointer __next_; + + _LIBCPP_INLINE_VISIBILITY + __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())), + __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {} + + _LIBCPP_INLINE_VISIBILITY + __base_pointer __self() { + return pointer_traits<__base_pointer>::pointer_to(*this); + } + + _LIBCPP_INLINE_VISIBILITY + __node_pointer __as_node() { + return static_cast<__node_pointer>(__self()); + } +}; + +template <class _Tp, class _VoidPtr> +struct __list_node + : public __list_node_base<_Tp, _VoidPtr> +{ + _Tp __value_; + + typedef __list_node_base<_Tp, _VoidPtr> __base; + typedef typename __base::__link_pointer __link_pointer; + + _LIBCPP_INLINE_VISIBILITY + __link_pointer __as_link() { + return static_cast<__link_pointer>(__base::__self()); + } +}; + +template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list; +template <class _Tp, class _Alloc> class __list_imp; +template <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator; + +template <class _Tp, class _VoidPtr> +class _LIBCPP_TEMPLATE_VIS __list_iterator +{ + typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; + typedef typename _NodeTraits::__link_pointer __link_pointer; + + __link_pointer __ptr_; + +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT + : __ptr_(__p) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCPP_INLINE_VISIBILITY + explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {} +#endif + + + + template<class, class> friend class list; + template<class, class> friend class __list_imp; + template<class, class> friend class __list_const_iterator; +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef value_type& reference; + typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer; + typedef typename pointer_traits<pointer>::difference_type difference_type; + + _LIBCPP_INLINE_VISIBILITY + __list_iterator() _NOEXCEPT : __ptr_(nullptr) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + __list_iterator(const __list_iterator& __p) + : __ptr_(__p.__ptr_) + { + __get_db()->__iterator_copy(this, &__p); + } + + _LIBCPP_INLINE_VISIBILITY + ~__list_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __list_iterator& operator=(const __list_iterator& __p) + { + if (this != &__p) + { + __get_db()->__iterator_copy(this, &__p); + __ptr_ = __p.__ptr_; + } + return *this; + } + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::iterator"); +#endif + return __ptr_->__as_node()->__value_; + } + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_); + } + + _LIBCPP_INLINE_VISIBILITY + __list_iterator& operator++() + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable list::iterator"); +#endif + __ptr_ = __ptr_->__next_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __list_iterator& operator--() + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), + "Attempted to decrement non-decrementable list::iterator"); +#endif + __ptr_ = __ptr_->__prev_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __list_iterator& __x, const __list_iterator& __y) + { + return __x.__ptr_ == __y.__ptr_; + } + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __list_iterator& __x, const __list_iterator& __y) + {return !(__x == __y);} +}; + +template <class _Tp, class _VoidPtr> +class _LIBCPP_TEMPLATE_VIS __list_const_iterator +{ + typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; + typedef typename _NodeTraits::__link_pointer __link_pointer; + + __link_pointer __ptr_; + +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT + : __ptr_(__p) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCPP_INLINE_VISIBILITY + explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {} +#endif + + template<class, class> friend class list; + template<class, class> friend class __list_imp; +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef const value_type& reference; + typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer; + typedef typename pointer_traits<pointer>::difference_type difference_type; + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT + : __ptr_(__p.__ptr_) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__iterator_copy(this, &__p); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator(const __list_const_iterator& __p) + : __ptr_(__p.__ptr_) + { + __get_db()->__iterator_copy(this, &__p); + } + + _LIBCPP_INLINE_VISIBILITY + ~__list_const_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator& operator=(const __list_const_iterator& __p) + { + if (this != &__p) + { + __get_db()->__iterator_copy(this, &__p); + __ptr_ = __p.__ptr_; + } + return *this; + } + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + reference operator*() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::const_iterator"); +#endif + return __ptr_->__as_node()->__value_; + } + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::const_iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_); + } + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator& operator++() + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable list::const_iterator"); +#endif + __ptr_ = __ptr_->__next_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator& operator--() + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), + "Attempted to decrement non-decrementable list::const_iterator"); +#endif + __ptr_ = __ptr_->__prev_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) + { + return __x.__ptr_ == __y.__ptr_; + } + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) + {return !(__x == __y);} +}; + +template <class _Tp, class _Alloc> +class __list_imp +{ + __list_imp(const __list_imp&); + __list_imp& operator=(const __list_imp&); +public: + typedef _Alloc allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __alloc_traits::size_type size_type; +protected: + typedef _Tp value_type; + typedef typename __alloc_traits::void_pointer __void_pointer; + typedef __list_iterator<value_type, __void_pointer> iterator; + typedef __list_const_iterator<value_type, __void_pointer> const_iterator; + typedef __list_node_base<value_type, __void_pointer> __node_base; + typedef __list_node<value_type, __void_pointer> __node; + typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef allocator_traits<__node_allocator> __node_alloc_traits; + typedef typename __node_alloc_traits::pointer __node_pointer; + typedef typename __node_alloc_traits::pointer __node_const_pointer; + typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits; + typedef typename __node_pointer_traits::__link_pointer __link_pointer; + typedef __link_pointer __link_const_pointer; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::difference_type difference_type; + + typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator; + typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer; + static_assert((!is_same<allocator_type, __node_allocator>::value), + "internal allocator type must differ from user-specified " + "type; otherwise overload resolution breaks"); + + __node_base __end_; + __compressed_pair<size_type, __node_allocator> __size_alloc_; + + _LIBCPP_INLINE_VISIBILITY + __link_pointer __end_as_link() const _NOEXCEPT { + return __node_pointer_traits::__unsafe_link_pointer_cast( + const_cast<__node_base&>(__end_).__self()); + } + + _LIBCPP_INLINE_VISIBILITY + size_type& __sz() _NOEXCEPT {return __size_alloc_.first();} + _LIBCPP_INLINE_VISIBILITY + const size_type& __sz() const _NOEXCEPT + {return __size_alloc_.first();} + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __node_alloc() _NOEXCEPT + {return __size_alloc_.second();} + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __node_alloc() const _NOEXCEPT + {return __size_alloc_.second();} + + _LIBCPP_INLINE_VISIBILITY + size_type __node_alloc_max_size() const _NOEXCEPT { + return __node_alloc_traits::max_size(__node_alloc()); + } + _LIBCPP_INLINE_VISIBILITY + static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + __list_imp() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value); + _LIBCPP_INLINE_VISIBILITY + __list_imp(const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + __list_imp(const __node_allocator& __a); +#ifndef _LIBCPP_CXX03_LANG + __list_imp(__node_allocator&& __a) _NOEXCEPT; +#endif + ~__list_imp(); + void clear() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __sz() == 0;} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__end_.__next_, this); +#else + return iterator(__end_.__next_); +#endif + } + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(__end_.__next_, this); +#else + return const_iterator(__end_.__next_); +#endif + } + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__end_as_link(), this); +#else + return iterator(__end_as_link()); +#endif + } + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(__end_as_link(), this); +#else + return const_iterator(__end_as_link()); +#endif + } + + void swap(__list_imp& __c) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT; +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value); +#endif + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __list_imp& __c) + {__copy_assign_alloc(__c, integral_constant<bool, + __node_alloc_traits::propagate_on_container_copy_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__list_imp& __c) + _NOEXCEPT_( + !__node_alloc_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<__node_allocator>::value) + {__move_assign_alloc(__c, integral_constant<bool, + __node_alloc_traits::propagate_on_container_move_assignment::value>());} + +private: + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __list_imp& __c, true_type) + { + if (__node_alloc() != __c.__node_alloc()) + clear(); + __node_alloc() = __c.__node_alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __list_imp&, false_type) + {} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__list_imp& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) + { + __node_alloc() = _VSTD::move(__c.__node_alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__list_imp&, false_type) + _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY + void __invalidate_all_iterators() { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif + } +}; + +// Unlink nodes [__f, __l] +template <class _Tp, class _Alloc> +inline +void +__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l) + _NOEXCEPT +{ + __f->__prev_->__next_ = __l->__next_; + __l->__next_->__prev_ = __f->__prev_; +} + +template <class _Tp, class _Alloc> +inline +__list_imp<_Tp, _Alloc>::__list_imp() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) + : __size_alloc_(0) +{ +} + +template <class _Tp, class _Alloc> +inline +__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) + : __size_alloc_(0, __node_allocator(__a)) +{ +} + +template <class _Tp, class _Alloc> +inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a) + : __size_alloc_(0, __a) {} + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp, class _Alloc> +inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT + : __size_alloc_(0, std::move(__a)) {} +#endif + +template <class _Tp, class _Alloc> +__list_imp<_Tp, _Alloc>::~__list_imp() { + clear(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__erase_c(this); +#endif +} + +template <class _Tp, class _Alloc> +void +__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT +{ + if (!empty()) + { + __node_allocator& __na = __node_alloc(); + __link_pointer __f = __end_.__next_; + __link_pointer __l = __end_as_link(); + __unlink_nodes(__f, __l->__prev_); + __sz() = 0; + while (__f != __l) + { + __node_pointer __np = __f->__as_node(); + __f = __f->__next_; + __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); + __node_alloc_traits::deallocate(__na, __np, 1); + } + __invalidate_all_iterators(); + } +} + +template <class _Tp, class _Alloc> +void +__list_imp<_Tp, _Alloc>::swap(__list_imp& __c) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value) +#endif +{ + _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || + this->__node_alloc() == __c.__node_alloc(), + "list::swap: Either propagate_on_container_swap must be true" + " or the allocators must compare equal"); + using _VSTD::swap; + __swap_allocator(__node_alloc(), __c.__node_alloc()); + swap(__sz(), __c.__sz()); + swap(__end_, __c.__end_); + if (__sz() == 0) + __end_.__next_ = __end_.__prev_ = __end_as_link(); + else + __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link(); + if (__c.__sz() == 0) + __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link(); + else + __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link(); + +#if _LIBCPP_DEBUG_LEVEL >= 2 + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + std::swap(__cn1->beg_, __cn2->beg_); + std::swap(__cn1->end_, __cn2->end_); + std::swap(__cn1->cap_, __cn2->cap_); + for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;) + { + --__p; + const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); + if (__i->__ptr_ == __c.__end_as_link()) + { + __cn2->__add(*__p); + if (--__cn1->end_ != __p) + memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*)); + } + else + (*__p)->__c_ = __cn1; + } + for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + { + --__p; + const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); + if (__i->__ptr_ == __end_as_link()) + { + __cn1->__add(*__p); + if (--__cn2->end_ != __p) + memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + } + else + (*__p)->__c_ = __cn2; + } + __db->unlock(); +#endif +} + +template <class _Tp, class _Alloc /*= allocator<_Tp>*/> +class _LIBCPP_TEMPLATE_VIS list + : private __list_imp<_Tp, _Alloc> +{ + typedef __list_imp<_Tp, _Alloc> base; + typedef typename base::__node __node; + typedef typename base::__node_allocator __node_allocator; + typedef typename base::__node_pointer __node_pointer; + typedef typename base::__node_alloc_traits __node_alloc_traits; + typedef typename base::__node_base __node_base; + typedef typename base::__node_base_pointer __node_base_pointer; + typedef typename base::__link_pointer __link_pointer; + +public: + typedef _Tp value_type; + typedef _Alloc allocator_type; + static_assert((is_same<value_type, typename allocator_type::value_type>::value), + "Invalid allocator::value_type"); + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + + _LIBCPP_INLINE_VISIBILITY + list() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + _LIBCPP_INLINE_VISIBILITY + explicit list(const allocator_type& __a) : base(__a) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + explicit list(size_type __n); +#if _LIBCPP_STD_VER > 11 + explicit list(size_type __n, const allocator_type& __a); +#endif + list(size_type __n, const value_type& __x); + list(size_type __n, const value_type& __x, const allocator_type& __a); + template <class _InpIter> + list(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); + template <class _InpIter> + list(_InpIter __f, _InpIter __l, const allocator_type& __a, + typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); + + list(const list& __c); + list(const list& __c, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + list& operator=(const list& __c); +#ifndef _LIBCPP_CXX03_LANG + list(initializer_list<value_type> __il); + list(initializer_list<value_type> __il, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + list(list&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); + _LIBCPP_INLINE_VISIBILITY + list(list&& __c, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + list& operator=(list&& __c) + _NOEXCEPT_( + __node_alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value); + + _LIBCPP_INLINE_VISIBILITY + list& operator=(initializer_list<value_type> __il) + {assign(__il.begin(), __il.end()); return *this;} + + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list<value_type> __il) + {assign(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + + template <class _InpIter> + void assign(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); + void assign(size_type __n, const value_type& __x); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return base::__sz();} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return base::empty();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + { + return std::min<size_type>( + base::__node_alloc_max_size(), + numeric_limits<difference_type >::max()); + } + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return base::begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return base::begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return base::end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return base::end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return base::begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return base::end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + reference front() + { + _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); + return base::__end_.__next_->__as_node()->__value_; + } + _LIBCPP_INLINE_VISIBILITY + const_reference front() const + { + _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); + return base::__end_.__next_->__as_node()->__value_; + } + _LIBCPP_INLINE_VISIBILITY + reference back() + { + _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); + return base::__end_.__prev_->__as_node()->__value_; + } + _LIBCPP_INLINE_VISIBILITY + const_reference back() const + { + _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); + return base::__end_.__prev_->__as_node()->__value_; + } + +#ifndef _LIBCPP_CXX03_LANG + void push_front(value_type&& __x); + void push_back(value_type&& __x); + + template <class... _Args> +#if _LIBCPP_STD_VER > 14 + reference emplace_front(_Args&&... __args); +#else + void emplace_front(_Args&&... __args); +#endif + template <class... _Args> +#if _LIBCPP_STD_VER > 14 + reference emplace_back(_Args&&... __args); +#else + void emplace_back(_Args&&... __args); +#endif + template <class... _Args> + iterator emplace(const_iterator __p, _Args&&... __args); + + iterator insert(const_iterator __p, value_type&& __x); + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, initializer_list<value_type> __il) + {return insert(__p, __il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + + void push_front(const value_type& __x); + void push_back(const value_type& __x); + +#ifndef _LIBCPP_CXX03_LANG + template <class _Arg> + _LIBCPP_INLINE_VISIBILITY + void __emplace_back(_Arg&& __arg) { emplace_back(_VSTD::forward<_Arg>(__arg)); } +#else + _LIBCPP_INLINE_VISIBILITY + void __emplace_back(value_type const& __arg) { push_back(__arg); } +#endif + + iterator insert(const_iterator __p, const value_type& __x); + iterator insert(const_iterator __p, size_type __n, const value_type& __x); + template <class _InpIter> + iterator insert(const_iterator __p, _InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); + + _LIBCPP_INLINE_VISIBILITY + void swap(list& __c) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) +#endif + {base::swap(__c);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {base::clear();} + + void pop_front(); + void pop_back(); + + iterator erase(const_iterator __p); + iterator erase(const_iterator __f, const_iterator __l); + + void resize(size_type __n); + void resize(size_type __n, const value_type& __x); + + void splice(const_iterator __p, list& __c); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void splice(const_iterator __p, list&& __c) {splice(__p, __c);} + _LIBCPP_INLINE_VISIBILITY + void splice(const_iterator __p, list&& __c, const_iterator __i) + {splice(__p, __c, __i);} + _LIBCPP_INLINE_VISIBILITY + void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) + {splice(__p, __c, __f, __l);} +#endif + void splice(const_iterator __p, list& __c, const_iterator __i); + void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); + + void remove(const value_type& __x); + template <class _Pred> void remove_if(_Pred __pred); + _LIBCPP_INLINE_VISIBILITY + void unique(); + template <class _BinaryPred> + void unique(_BinaryPred __binary_pred); + _LIBCPP_INLINE_VISIBILITY + void merge(list& __c); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void merge(list&& __c) {merge(__c);} + + template <class _Comp> + _LIBCPP_INLINE_VISIBILITY + void merge(list&& __c, _Comp __comp) {merge(__c, __comp);} +#endif + template <class _Comp> + void merge(list& __c, _Comp __comp); + + _LIBCPP_INLINE_VISIBILITY + void sort(); + template <class _Comp> + _LIBCPP_INLINE_VISIBILITY + void sort(_Comp __comp); + + void reverse() _NOEXCEPT; + + bool __invariants() const; + + typedef __allocator_destructor<__node_allocator> __node_destructor; + typedef unique_ptr<__node, __node_destructor> __hold_pointer; + + _LIBCPP_INLINE_VISIBILITY + __hold_pointer __allocate_node(__node_allocator& __na) { + __node_pointer __p = __node_alloc_traits::allocate(__na, 1); + __p->__prev_ = nullptr; + return __hold_pointer(__p, __node_destructor(__na, 1)); + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const; + bool __decrementable(const const_iterator* __i) const; + bool __addable(const const_iterator* __i, ptrdiff_t __n) const; + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +private: + _LIBCPP_INLINE_VISIBILITY + static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l); + _LIBCPP_INLINE_VISIBILITY + void __link_nodes_at_front(__link_pointer __f, __link_pointer __l); + _LIBCPP_INLINE_VISIBILITY + void __link_nodes_at_back (__link_pointer __f, __link_pointer __l); + iterator __iterator(size_type __n); + template <class _Comp> + static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); + + void __move_assign(list& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value); + void __move_assign(list& __c, false_type); +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +list(_InputIterator, _InputIterator) + -> list<typename iterator_traits<_InputIterator>::value_type, _Alloc>; + +template<class _InputIterator, + class _Alloc, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +list(_InputIterator, _InputIterator, _Alloc) + -> list<typename iterator_traits<_InputIterator>::value_type, _Alloc>; +#endif + +// Link in nodes [__f, __l] just prior to __p +template <class _Tp, class _Alloc> +inline +void +list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l) +{ + __p->__prev_->__next_ = __f; + __f->__prev_ = __p->__prev_; + __p->__prev_ = __l; + __l->__next_ = __p; +} + +// Link in nodes [__f, __l] at the front of the list +template <class _Tp, class _Alloc> +inline +void +list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l) +{ + __f->__prev_ = base::__end_as_link(); + __l->__next_ = base::__end_.__next_; + __l->__next_->__prev_ = __l; + base::__end_.__next_ = __f; +} + +// Link in nodes [__f, __l] at the back of the list +template <class _Tp, class _Alloc> +inline +void +list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l) +{ + __l->__next_ = base::__end_as_link(); + __f->__prev_ = base::__end_.__prev_; + __f->__prev_->__next_ = __f; + base::__end_.__prev_ = __l; +} + + +template <class _Tp, class _Alloc> +inline +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::__iterator(size_type __n) +{ + return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n) + : _VSTD::prev(end(), base::__sz() - __n); +} + +template <class _Tp, class _Alloc> +list<_Tp, _Alloc>::list(size_type __n) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __n > 0; --__n) +#ifndef _LIBCPP_CXX03_LANG + emplace_back(); +#else + push_back(value_type()); +#endif +} + +#if _LIBCPP_STD_VER > 11 +template <class _Tp, class _Alloc> +list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __n > 0; --__n) + emplace_back(); +} +#endif + +template <class _Tp, class _Alloc> +list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __n > 0; --__n) + push_back(__x); +} + +template <class _Tp, class _Alloc> +list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __n > 0; --__n) + push_back(__x); +} + +template <class _Tp, class _Alloc> +template <class _InpIter> +list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type*) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __f != __l; ++__f) + __emplace_back(*__f); +} + +template <class _Tp, class _Alloc> +template <class _InpIter> +list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a, + typename enable_if<__is_input_iterator<_InpIter>::value>::type*) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __f != __l; ++__f) + __emplace_back(*__f); +} + +template <class _Tp, class _Alloc> +list<_Tp, _Alloc>::list(const list& __c) + : base(__node_alloc_traits::select_on_container_copy_construction( + __c.__node_alloc())) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) + push_back(*__i); +} + +template <class _Tp, class _Alloc> +list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) + push_back(*__i); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), + __e = __il.end(); __i != __e; ++__i) + push_back(*__i); +} + +template <class _Tp, class _Alloc> +list<_Tp, _Alloc>::list(initializer_list<value_type> __il) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), + __e = __il.end(); __i != __e; ++__i) + push_back(*__i); +} + +template <class _Tp, class _Alloc> +inline list<_Tp, _Alloc>::list(list&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) + : base(_VSTD::move(__c.__node_alloc())) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + splice(end(), __c); +} + +template <class _Tp, class _Alloc> +inline +list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__a == __c.get_allocator()) + splice(end(), __c); + else + { + typedef move_iterator<iterator> _Ip; + assign(_Ip(__c.begin()), _Ip(__c.end())); + } +} + +template <class _Tp, class _Alloc> +inline +list<_Tp, _Alloc>& +list<_Tp, _Alloc>::operator=(list&& __c) + _NOEXCEPT_( + __node_alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value) +{ + __move_assign(__c, integral_constant<bool, + __node_alloc_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::__move_assign(list& __c, false_type) +{ + if (base::__node_alloc() != __c.__node_alloc()) + { + typedef move_iterator<iterator> _Ip; + assign(_Ip(__c.begin()), _Ip(__c.end())); + } + else + __move_assign(__c, true_type()); +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::__move_assign(list& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) +{ + clear(); + base::__move_assign_alloc(__c); + splice(end(), __c); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +inline +list<_Tp, _Alloc>& +list<_Tp, _Alloc>::operator=(const list& __c) +{ + if (this != &__c) + { + base::__copy_assign_alloc(__c); + assign(__c.begin(), __c.end()); + } + return *this; +} + +template <class _Tp, class _Alloc> +template <class _InpIter> +void +list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type*) +{ + iterator __i = begin(); + iterator __e = end(); + for (; __f != __l && __i != __e; ++__f, ++__i) + *__i = *__f; + if (__i == __e) + insert(__e, __f, __l); + else + erase(__i, __e); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) +{ + iterator __i = begin(); + iterator __e = end(); + for (; __n > 0 && __i != __e; --__n, ++__i) + *__i = __x; + if (__i == __e) + insert(__e, __n, __x); + else + erase(__i, __e); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif +} + +template <class _Tp, class _Alloc> +inline +_Alloc +list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT +{ + return allocator_type(base::__node_alloc()); +} + +template <class _Tp, class _Alloc> +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::insert(iterator, x) called with an iterator not" + " referring to this list"); +#endif + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link()); + ++base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__hold.release()->__as_link(), this); +#else + return iterator(__hold.release()->__as_link()); +#endif +} + +template <class _Tp, class _Alloc> +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::insert(iterator, n, x) called with an iterator not" + " referring to this list"); + iterator __r(__p.__ptr_, this); +#else + iterator __r(__p.__ptr_); +#endif + if (__n > 0) + { + size_type __ds = 0; + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + ++__ds; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __r = iterator(__hold->__as_link(), this); +#else + __r = iterator(__hold->__as_link()); +#endif + __hold.release(); + iterator __e = __r; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (--__n; __n != 0; --__n, ++__e, ++__ds) + { + __hold.reset(__node_alloc_traits::allocate(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __e.__ptr_->__next_ = __hold->__as_link(); + __hold->__prev_ = __e.__ptr_; + __hold.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (true) + { + __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); + __link_pointer __prev = __e.__ptr_->__prev_; + __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); + if (__prev == 0) + break; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __e = iterator(__prev, this); +#else + __e = iterator(__prev); +#endif + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); + base::__sz() += __ds; + } + return __r; +} + +template <class _Tp, class _Alloc> +template <class _InpIter> +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type*) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::insert(iterator, range) called with an iterator not" + " referring to this list"); + iterator __r(__p.__ptr_, this); +#else + iterator __r(__p.__ptr_); +#endif + if (__f != __l) + { + size_type __ds = 0; + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); + ++__ds; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __r = iterator(__hold.get()->__as_link(), this); +#else + __r = iterator(__hold.get()->__as_link()); +#endif + __hold.release(); + iterator __e = __r; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds) + { + __hold.reset(__node_alloc_traits::allocate(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); + __e.__ptr_->__next_ = __hold.get()->__as_link(); + __hold->__prev_ = __e.__ptr_; + __hold.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (true) + { + __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); + __link_pointer __prev = __e.__ptr_->__prev_; + __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); + if (__prev == 0) + break; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __e = iterator(__prev, this); +#else + __e = iterator(__prev); +#endif + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); + base::__sz() += __ds; + } + return __r; +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::push_front(const value_type& __x) +{ + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __link_pointer __nl = __hold->__as_link(); + __link_nodes_at_front(__nl, __nl); + ++base::__sz(); + __hold.release(); +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::push_back(const value_type& __x) +{ + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); + ++base::__sz(); + __hold.release(); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::push_front(value_type&& __x) +{ + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); + __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); + ++base::__sz(); + __hold.release(); +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::push_back(value_type&& __x) +{ + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); + __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); + ++base::__sz(); + __hold.release(); +} + +template <class _Tp, class _Alloc> +template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename list<_Tp, _Alloc>::reference +#else +void +#endif +list<_Tp, _Alloc>::emplace_front(_Args&&... __args) +{ + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); + __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); + ++base::__sz(); +#if _LIBCPP_STD_VER > 14 + return __hold.release()->__value_; +#else + __hold.release(); +#endif +} + +template <class _Tp, class _Alloc> +template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename list<_Tp, _Alloc>::reference +#else +void +#endif +list<_Tp, _Alloc>::emplace_back(_Args&&... __args) +{ + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); + __link_pointer __nl = __hold->__as_link(); + __link_nodes_at_back(__nl, __nl); + ++base::__sz(); +#if _LIBCPP_STD_VER > 14 + return __hold.release()->__value_; +#else + __hold.release(); +#endif +} + +template <class _Tp, class _Alloc> +template <class... _Args> +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::emplace(iterator, args...) called with an iterator not" + " referring to this list"); +#endif + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); + __link_pointer __nl = __hold.get()->__as_link(); + __link_nodes(__p.__ptr_, __nl, __nl); + ++base::__sz(); + __hold.release(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__nl, this); +#else + return iterator(__nl); +#endif +} + +template <class _Tp, class _Alloc> +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::insert(iterator, x) called with an iterator not" + " referring to this list"); +#endif + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); + __link_pointer __nl = __hold->__as_link(); + __link_nodes(__p.__ptr_, __nl, __nl); + ++base::__sz(); + __hold.release(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__nl, this); +#else + return iterator(__nl); +#endif +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::pop_front() +{ + _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); + __node_allocator& __na = base::__node_alloc(); + __link_pointer __n = base::__end_.__next_; + base::__unlink_nodes(__n, __n); + --base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast<iterator*>((*__p)->__i_); + if (__i->__ptr_ == __n) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_pointer __np = __n->__as_node(); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); + __node_alloc_traits::deallocate(__na, __np, 1); +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::pop_back() +{ + _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list"); + __node_allocator& __na = base::__node_alloc(); + __link_pointer __n = base::__end_.__prev_; + base::__unlink_nodes(__n, __n); + --base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast<iterator*>((*__p)->__i_); + if (__i->__ptr_ == __n) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_pointer __np = __n->__as_node(); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); + __node_alloc_traits::deallocate(__na, __np, 1); +} + +template <class _Tp, class _Alloc> +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::erase(const_iterator __p) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::erase(iterator) called with an iterator not" + " referring to this list"); +#endif + _LIBCPP_ASSERT(__p != end(), + "list::erase(iterator) called with a non-dereferenceable iterator"); + __node_allocator& __na = base::__node_alloc(); + __link_pointer __n = __p.__ptr_; + __link_pointer __r = __n->__next_; + base::__unlink_nodes(__n, __n); + --base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __ip = __c->end_; __ip != __c->beg_; ) + { + --__ip; + iterator* __i = static_cast<iterator*>((*__ip)->__i_); + if (__i->__ptr_ == __n) + { + (*__ip)->__c_ = nullptr; + if (--__c->end_ != __ip) + memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_pointer __np = __n->__as_node(); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); + __node_alloc_traits::deallocate(__na, __np, 1); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__r, this); +#else + return iterator(__r); +#endif +} + +template <class _Tp, class _Alloc> +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this, + "list::erase(iterator, iterator) called with an iterator not" + " referring to this list"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this, + "list::erase(iterator, iterator) called with an iterator not" + " referring to this list"); +#endif + if (__f != __l) + { + __node_allocator& __na = base::__node_alloc(); + base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_); + while (__f != __l) + { + __link_pointer __n = __f.__ptr_; + ++__f; + --base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast<iterator*>((*__p)->__i_); + if (__i->__ptr_ == __n) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_pointer __np = __n->__as_node(); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); + __node_alloc_traits::deallocate(__na, __np, 1); + } + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__l.__ptr_, this); +#else + return iterator(__l.__ptr_); +#endif +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::resize(size_type __n) +{ + if (__n < base::__sz()) + erase(__iterator(__n), end()); + else if (__n > base::__sz()) + { + __n -= base::__sz(); + size_type __ds = 0; + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); + ++__ds; +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator __r = iterator(__hold.release()->__as_link(), this); +#else + iterator __r = iterator(__hold.release()->__as_link()); +#endif + iterator __e = __r; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (--__n; __n != 0; --__n, ++__e, ++__ds) + { + __hold.reset(__node_alloc_traits::allocate(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); + __e.__ptr_->__next_ = __hold.get()->__as_link(); + __hold->__prev_ = __e.__ptr_; + __hold.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (true) + { + __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); + __link_pointer __prev = __e.__ptr_->__prev_; + __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); + if (__prev == 0) + break; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __e = iterator(__prev, this); +#else + __e = iterator(__prev); +#endif + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __link_nodes_at_back(__r.__ptr_, __e.__ptr_); + base::__sz() += __ds; + } +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) +{ + if (__n < base::__sz()) + erase(__iterator(__n), end()); + else if (__n > base::__sz()) + { + __n -= base::__sz(); + size_type __ds = 0; + __node_allocator& __na = base::__node_alloc(); + __hold_pointer __hold = __allocate_node(__na); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + ++__ds; + __link_pointer __nl = __hold.release()->__as_link(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator __r = iterator(__nl, this); +#else + iterator __r = iterator(__nl); +#endif + iterator __e = __r; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (--__n; __n != 0; --__n, ++__e, ++__ds) + { + __hold.reset(__node_alloc_traits::allocate(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __e.__ptr_->__next_ = __hold.get()->__as_link(); + __hold->__prev_ = __e.__ptr_; + __hold.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (true) + { + __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); + __link_pointer __prev = __e.__ptr_->__prev_; + __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); + if (__prev == 0) + break; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __e = iterator(__prev, this); +#else + __e = iterator(__prev); +#endif + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_); + base::__sz() += __ds; + } +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) +{ + _LIBCPP_ASSERT(this != &__c, + "list::splice(iterator, list) called with this == &list"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::splice(iterator, list) called with an iterator not" + " referring to this list"); +#endif + if (!__c.empty()) + { + __link_pointer __f = __c.__end_.__next_; + __link_pointer __l = __c.__end_.__prev_; + base::__unlink_nodes(__f, __l); + __link_nodes(__p.__ptr_, __f, __l); + base::__sz() += __c.__sz(); + __c.__sz() = 0; +#if _LIBCPP_DEBUG_LEVEL >= 2 + if (&__c != this) { + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) + { + --__ip; + iterator* __i = static_cast<iterator*>((*__ip)->__i_); + if (__i->__ptr_ != __c.__end_as_link()) + { + __cn1->__add(*__ip); + (*__ip)->__c_ = __cn1; + if (--__cn2->end_ != __ip) + memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); + } + } + __db->unlock(); + } +#endif + } +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::splice(iterator, list, iterator) called with first iterator not" + " referring to this list"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c, + "list::splice(iterator, list, iterator) called with second iterator not" + " referring to list argument"); + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i), + "list::splice(iterator, list, iterator) called with second iterator not" + " derefereceable"); +#endif + if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) + { + __link_pointer __f = __i.__ptr_; + base::__unlink_nodes(__f, __f); + __link_nodes(__p.__ptr_, __f, __f); + --__c.__sz(); + ++base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + if (&__c != this) { + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) + { + --__ip; + iterator* __j = static_cast<iterator*>((*__ip)->__i_); + if (__j->__ptr_ == __f) + { + __cn1->__add(*__ip); + (*__ip)->__c_ = __cn1; + if (--__cn2->end_ != __ip) + memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); + } + } + __db->unlock(); + } +#endif + } +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::splice(iterator, list, iterator, iterator) called with first iterator not" + " referring to this list"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c, + "list::splice(iterator, list, iterator, iterator) called with second iterator not" + " referring to list argument"); + if (this == &__c) + { + for (const_iterator __i = __f; __i != __l; ++__i) + _LIBCPP_ASSERT(__i != __p, + "list::splice(iterator, list, iterator, iterator)" + " called with the first iterator within the range" + " of the second and third iterators"); + } +#endif + if (__f != __l) + { + __link_pointer __first = __f.__ptr_; + --__l; + __link_pointer __last = __l.__ptr_; + if (this != &__c) + { + size_type __s = _VSTD::distance(__f, __l) + 1; + __c.__sz() -= __s; + base::__sz() += __s; + } + base::__unlink_nodes(__first, __last); + __link_nodes(__p.__ptr_, __first, __last); +#if _LIBCPP_DEBUG_LEVEL >= 2 + if (&__c != this) { + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) + { + --__ip; + iterator* __j = static_cast<iterator*>((*__ip)->__i_); + for (__link_pointer __k = __f.__ptr_; + __k != __l.__ptr_; __k = __k->__next_) + { + if (__j->__ptr_ == __k) + { + __cn1->__add(*__ip); + (*__ip)->__c_ = __cn1; + if (--__cn2->end_ != __ip) + memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); + } + } + } + __db->unlock(); + } +#endif + } +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::remove(const value_type& __x) +{ + list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing + for (const_iterator __i = begin(), __e = end(); __i != __e;) + { + if (*__i == __x) + { + const_iterator __j = _VSTD::next(__i); + for (; __j != __e && *__j == __x; ++__j) + ; + __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j); + __i = __j; + if (__i != __e) + ++__i; + } + else + ++__i; + } +} + +template <class _Tp, class _Alloc> +template <class _Pred> +void +list<_Tp, _Alloc>::remove_if(_Pred __pred) +{ + for (iterator __i = begin(), __e = end(); __i != __e;) + { + if (__pred(*__i)) + { + iterator __j = _VSTD::next(__i); + for (; __j != __e && __pred(*__j); ++__j) + ; + __i = erase(__i, __j); + if (__i != __e) + ++__i; + } + else + ++__i; + } +} + +template <class _Tp, class _Alloc> +inline +void +list<_Tp, _Alloc>::unique() +{ + unique(__equal_to<value_type>()); +} + +template <class _Tp, class _Alloc> +template <class _BinaryPred> +void +list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) +{ + for (iterator __i = begin(), __e = end(); __i != __e;) + { + iterator __j = _VSTD::next(__i); + for (; __j != __e && __binary_pred(*__i, *__j); ++__j) + ; + if (++__i != __j) + __i = erase(__i, __j); + } +} + +template <class _Tp, class _Alloc> +inline +void +list<_Tp, _Alloc>::merge(list& __c) +{ + merge(__c, __less<value_type>()); +} + +template <class _Tp, class _Alloc> +template <class _Comp> +void +list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) +{ + if (this != _VSTD::addressof(__c)) + { + iterator __f1 = begin(); + iterator __e1 = end(); + iterator __f2 = __c.begin(); + iterator __e2 = __c.end(); + while (__f1 != __e1 && __f2 != __e2) + { + if (__comp(*__f2, *__f1)) + { + size_type __ds = 1; + iterator __m2 = _VSTD::next(__f2); + for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds) + ; + base::__sz() += __ds; + __c.__sz() -= __ds; + __link_pointer __f = __f2.__ptr_; + __link_pointer __l = __m2.__ptr_->__prev_; + __f2 = __m2; + base::__unlink_nodes(__f, __l); + __m2 = _VSTD::next(__f1); + __link_nodes(__f1.__ptr_, __f, __l); + __f1 = __m2; + } + else + ++__f1; + } + splice(__e1, __c); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + { + --__p; + iterator* __i = static_cast<iterator*>((*__p)->__i_); + if (__i->__ptr_ != __c.__end_as_link()) + { + __cn1->__add(*__p); + (*__p)->__c_ = __cn1; + if (--__cn2->end_ != __p) + memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + } + } + __db->unlock(); +#endif + } +} + +template <class _Tp, class _Alloc> +inline +void +list<_Tp, _Alloc>::sort() +{ + sort(__less<value_type>()); +} + +template <class _Tp, class _Alloc> +template <class _Comp> +inline +void +list<_Tp, _Alloc>::sort(_Comp __comp) +{ + __sort(begin(), end(), base::__sz(), __comp); +} + +template <class _Tp, class _Alloc> +template <class _Comp> +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) +{ + switch (__n) + { + case 0: + case 1: + return __f1; + case 2: + if (__comp(*--__e2, *__f1)) + { + __link_pointer __f = __e2.__ptr_; + base::__unlink_nodes(__f, __f); + __link_nodes(__f1.__ptr_, __f, __f); + return __e2; + } + return __f1; + } + size_type __n2 = __n / 2; + iterator __e1 = _VSTD::next(__f1, __n2); + iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp); + iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp); + if (__comp(*__f2, *__f1)) + { + iterator __m2 = _VSTD::next(__f2); + for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) + ; + __link_pointer __f = __f2.__ptr_; + __link_pointer __l = __m2.__ptr_->__prev_; + __r = __f2; + __e1 = __f2 = __m2; + base::__unlink_nodes(__f, __l); + __m2 = _VSTD::next(__f1); + __link_nodes(__f1.__ptr_, __f, __l); + __f1 = __m2; + } + else + ++__f1; + while (__f1 != __e1 && __f2 != __e2) + { + if (__comp(*__f2, *__f1)) + { + iterator __m2 = _VSTD::next(__f2); + for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) + ; + __link_pointer __f = __f2.__ptr_; + __link_pointer __l = __m2.__ptr_->__prev_; + if (__e1 == __f2) + __e1 = __m2; + __f2 = __m2; + base::__unlink_nodes(__f, __l); + __m2 = _VSTD::next(__f1); + __link_nodes(__f1.__ptr_, __f, __l); + __f1 = __m2; + } + else + ++__f1; + } + return __r; +} + +template <class _Tp, class _Alloc> +void +list<_Tp, _Alloc>::reverse() _NOEXCEPT +{ + if (base::__sz() > 1) + { + iterator __e = end(); + for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;) + { + _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_); + __i.__ptr_ = __i.__ptr_->__prev_; + } + _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_); + } +} + +template <class _Tp, class _Alloc> +bool +list<_Tp, _Alloc>::__invariants() const +{ + return size() == _VSTD::distance(begin(), end()); +} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + +template <class _Tp, class _Alloc> +bool +list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const +{ + return __i->__ptr_ != this->__end_as_link(); +} + +template <class _Tp, class _Alloc> +bool +list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const +{ + return !empty() && __i->__ptr_ != base::__end_.__next_; +} + +template <class _Tp, class _Alloc> +bool +list<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +template <class _Tp, class _Alloc> +bool +list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return !(__x < __y); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Tp, class _Allocator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred) +{ __c.remove_if(__pred); } + +template <class _Tp, class _Allocator, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +void erase(list<_Tp, _Allocator>& __c, const _Up& __v) +{ _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; }); } +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_LIST diff --git a/android/x86/include/v8/libc++/locale b/android/x86/include/v8/libc++/locale new file mode 100755 index 00000000..c3c05eb3 --- /dev/null +++ b/android/x86/include/v8/libc++/locale @@ -0,0 +1,4359 @@ +// -*- C++ -*- +//===-------------------------- locale ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LOCALE +#define _LIBCPP_LOCALE + +/* + locale synopsis + +namespace std +{ + +class locale +{ +public: + // types: + class facet; + class id; + + typedef int category; + static const category // values assigned here are for exposition only + none = 0x000, + collate = 0x010, + ctype = 0x020, + monetary = 0x040, + numeric = 0x080, + time = 0x100, + messages = 0x200, + all = collate | ctype | monetary | numeric | time | messages; + + // construct/copy/destroy: + locale() noexcept; + locale(const locale& other) noexcept; + explicit locale(const char* std_name); + explicit locale(const string& std_name); + locale(const locale& other, const char* std_name, category); + locale(const locale& other, const string& std_name, category); + template <class Facet> locale(const locale& other, Facet* f); + locale(const locale& other, const locale& one, category); + + ~locale(); // not virtual + + const locale& operator=(const locale& other) noexcept; + + template <class Facet> locale combine(const locale& other) const; + + // locale operations: + basic_string<char> name() const; + bool operator==(const locale& other) const; + bool operator!=(const locale& other) const; + template <class charT, class Traits, class Allocator> + bool operator()(const basic_string<charT,Traits,Allocator>& s1, + const basic_string<charT,Traits,Allocator>& s2) const; + + // global locale objects: + static locale global(const locale&); + static const locale& classic(); +}; + +template <class Facet> const Facet& use_facet(const locale&); +template <class Facet> bool has_facet(const locale&) noexcept; + +// 22.3.3, convenience interfaces: +template <class charT> bool isspace (charT c, const locale& loc); +template <class charT> bool isprint (charT c, const locale& loc); +template <class charT> bool iscntrl (charT c, const locale& loc); +template <class charT> bool isupper (charT c, const locale& loc); +template <class charT> bool islower (charT c, const locale& loc); +template <class charT> bool isalpha (charT c, const locale& loc); +template <class charT> bool isdigit (charT c, const locale& loc); +template <class charT> bool ispunct (charT c, const locale& loc); +template <class charT> bool isxdigit(charT c, const locale& loc); +template <class charT> bool isalnum (charT c, const locale& loc); +template <class charT> bool isgraph (charT c, const locale& loc); +template <class charT> charT toupper(charT c, const locale& loc); +template <class charT> charT tolower(charT c, const locale& loc); + +template<class Codecvt, class Elem = wchar_t, + class Wide_alloc = allocator<Elem>, + class Byte_alloc = allocator<char>> +class wstring_convert +{ +public: + typedef basic_string<char, char_traits<char>, Byte_alloc> byte_string; + typedef basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string; + typedef typename Codecvt::state_type state_type; + typedef typename wide_string::traits_type::int_type int_type; + + explicit wstring_convert(Codecvt* pcvt = new Codecvt); // explicit in C++14 + wstring_convert(Codecvt* pcvt, state_type state); + explicit wstring_convert(const byte_string& byte_err, // explicit in C++14 + const wide_string& wide_err = wide_string()); + wstring_convert(const wstring_convert&) = delete; // C++14 + wstring_convert & operator=(const wstring_convert &) = delete; // C++14 + ~wstring_convert(); + + wide_string from_bytes(char byte); + wide_string from_bytes(const char* ptr); + wide_string from_bytes(const byte_string& str); + wide_string from_bytes(const char* first, const char* last); + + byte_string to_bytes(Elem wchar); + byte_string to_bytes(const Elem* wptr); + byte_string to_bytes(const wide_string& wstr); + byte_string to_bytes(const Elem* first, const Elem* last); + + size_t converted() const; // noexcept in C++14 + state_type state() const; +}; + +template <class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem>> +class wbuffer_convert + : public basic_streambuf<Elem, Tr> +{ +public: + typedef typename Tr::state_type state_type; + + explicit wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt, + state_type state = state_type()); // explicit in C++14 + wbuffer_convert(const wbuffer_convert&) = delete; // C++14 + wbuffer_convert & operator=(const wbuffer_convert &) = delete; // C++14 + ~wbuffer_convert(); // C++14 + + streambuf* rdbuf() const; + streambuf* rdbuf(streambuf* bytebuf); + + state_type state() const; +}; + +// 22.4.1 and 22.4.1.3, ctype: +class ctype_base; +template <class charT> class ctype; +template <> class ctype<char>; // specialization +template <class charT> class ctype_byname; +template <> class ctype_byname<char>; // specialization + +class codecvt_base; +template <class internT, class externT, class stateT> class codecvt; +template <class internT, class externT, class stateT> class codecvt_byname; + +// 22.4.2 and 22.4.3, numeric: +template <class charT, class InputIterator> class num_get; +template <class charT, class OutputIterator> class num_put; +template <class charT> class numpunct; +template <class charT> class numpunct_byname; + +// 22.4.4, col lation: +template <class charT> class collate; +template <class charT> class collate_byname; + +// 22.4.5, date and time: +class time_base; +template <class charT, class InputIterator> class time_get; +template <class charT, class InputIterator> class time_get_byname; +template <class charT, class OutputIterator> class time_put; +template <class charT, class OutputIterator> class time_put_byname; + +// 22.4.6, money: +class money_base; +template <class charT, class InputIterator> class money_get; +template <class charT, class OutputIterator> class money_put; +template <class charT, bool Intl> class moneypunct; +template <class charT, bool Intl> class moneypunct_byname; + +// 22.4.7, message retrieval: +class messages_base; +template <class charT> class messages; +template <class charT> class messages_byname; + +} // std + +*/ + +#include <__config> +#include <__locale> +#include <__debug> +#include <algorithm> +#include <memory> +#include <ios> +#include <streambuf> +#include <iterator> +#include <limits> +#include <version> +#ifndef __APPLE__ +#include <cstdarg> +#endif +#include <cstdlib> +#include <ctime> +#include <cstdio> +#ifdef _LIBCPP_HAS_CATOPEN +#include <nl_types.h> +#endif + +#ifdef __APPLE__ +#include <Availability.h> +#endif + +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS +#include <__bsd_locale_defaults.h> +#else +#include <__bsd_locale_fallbacks.h> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if defined(__APPLE__) || defined(__FreeBSD__) +# define _LIBCPP_GET_C_LOCALE 0 +#elif defined(__CloudABI__) || defined(__NetBSD__) +# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE +#else +# define _LIBCPP_GET_C_LOCALE __cloc() + // Get the C locale object + _LIBCPP_FUNC_VIS locale_t __cloc(); +#define __cloc_defined +#endif + +// __scan_keyword +// Scans [__b, __e) until a match is found in the basic_strings range +// [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke). +// __b will be incremented (visibly), consuming CharT until a match is found +// or proved to not exist. A keyword may be "", in which will match anything. +// If one keyword is a prefix of another, and the next CharT in the input +// might match another keyword, the algorithm will attempt to find the longest +// matching keyword. If the longer matching keyword ends up not matching, then +// no keyword match is found. If no keyword match is found, __ke is returned +// and failbit is set in __err. +// Else an iterator pointing to the matching keyword is found. If more than +// one keyword matches, an iterator to the first matching keyword is returned. +// If on exit __b == __e, eofbit is set in __err. If __case_sensitive is false, +// __ct is used to force to lower case before comparing characters. +// Examples: +// Keywords: "a", "abb" +// If the input is "a", the first keyword matches and eofbit is set. +// If the input is "abc", no match is found and "ab" are consumed. +template <class _InputIterator, class _ForwardIterator, class _Ctype> +_LIBCPP_HIDDEN +_ForwardIterator +__scan_keyword(_InputIterator& __b, _InputIterator __e, + _ForwardIterator __kb, _ForwardIterator __ke, + const _Ctype& __ct, ios_base::iostate& __err, + bool __case_sensitive = true) +{ + typedef typename iterator_traits<_InputIterator>::value_type _CharT; + size_t __nkw = static_cast<size_t>(_VSTD::distance(__kb, __ke)); + const unsigned char __doesnt_match = '\0'; + const unsigned char __might_match = '\1'; + const unsigned char __does_match = '\2'; + unsigned char __statbuf[100]; + unsigned char* __status = __statbuf; + unique_ptr<unsigned char, void(*)(void*)> __stat_hold(0, free); + if (__nkw > sizeof(__statbuf)) + { + __status = (unsigned char*)malloc(__nkw); + if (__status == 0) + __throw_bad_alloc(); + __stat_hold.reset(__status); + } + size_t __n_might_match = __nkw; // At this point, any keyword might match + size_t __n_does_match = 0; // but none of them definitely do + // Initialize all statuses to __might_match, except for "" keywords are __does_match + unsigned char* __st = __status; + for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st) + { + if (!__ky->empty()) + *__st = __might_match; + else + { + *__st = __does_match; + --__n_might_match; + ++__n_does_match; + } + } + // While there might be a match, test keywords against the next CharT + for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx) + { + // Peek at the next CharT but don't consume it + _CharT __c = *__b; + if (!__case_sensitive) + __c = __ct.toupper(__c); + bool __consume = false; + // For each keyword which might match, see if the __indx character is __c + // If a match if found, consume __c + // If a match is found, and that is the last character in the keyword, + // then that keyword matches. + // If the keyword doesn't match this character, then change the keyword + // to doesn't match + __st = __status; + for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st) + { + if (*__st == __might_match) + { + _CharT __kc = (*__ky)[__indx]; + if (!__case_sensitive) + __kc = __ct.toupper(__kc); + if (__c == __kc) + { + __consume = true; + if (__ky->size() == __indx+1) + { + *__st = __does_match; + --__n_might_match; + ++__n_does_match; + } + } + else + { + *__st = __doesnt_match; + --__n_might_match; + } + } + } + // consume if we matched a character + if (__consume) + { + ++__b; + // If we consumed a character and there might be a matched keyword that + // was marked matched on a previous iteration, then such keywords + // which are now marked as not matching. + if (__n_might_match + __n_does_match > 1) + { + __st = __status; + for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st) + { + if (*__st == __does_match && __ky->size() != __indx+1) + { + *__st = __doesnt_match; + --__n_does_match; + } + } + } + } + } + // We've exited the loop because we hit eof and/or we have no more "might matches". + if (__b == __e) + __err |= ios_base::eofbit; + // Return the first matching result + for (__st = __status; __kb != __ke; ++__kb, (void) ++__st) + if (*__st == __does_match) + break; + if (__kb == __ke) + __err |= ios_base::failbit; + return __kb; +} + +struct _LIBCPP_TYPE_VIS __num_get_base +{ + static const int __num_get_buf_sz = 40; + + static int __get_base(ios_base&); + static const char __src[33]; +}; + +_LIBCPP_FUNC_VIS +void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, + ios_base::iostate& __err); + +template <class _CharT> +struct __num_get + : protected __num_get_base +{ + static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, + _CharT& __thousands_sep); + + static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, + char* __a, char*& __a_end, + _CharT __decimal_point, _CharT __thousands_sep, + const string& __grouping, unsigned* __g, + unsigned*& __g_end, unsigned& __dc, _CharT* __atoms); +#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET + static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep); + static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, + unsigned& __dc, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, _CharT* __atoms); + +#else + static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep) + { + locale __loc = __iob.getloc(); + const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); + __thousands_sep = __np.thousands_sep(); + return __np.grouping(); + } + + const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const + { + return __do_widen_p(__iob, __atoms); + } + + + static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, + unsigned& __dc, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, const _CharT* __atoms); +private: + template<typename T> + const T* __do_widen_p(ios_base& __iob, T* __atoms) const + { + locale __loc = __iob.getloc(); + use_facet<ctype<T> >(__loc).widen(__src, __src + 26, __atoms); + return __atoms; + } + + const char* __do_widen_p(ios_base& __iob, char* __atoms) const + { + (void)__iob; + (void)__atoms; + return __src; + } +#endif +}; + +#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET +template <class _CharT> +string +__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) +{ + locale __loc = __iob.getloc(); + use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 26, __atoms); + const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); + __thousands_sep = __np.thousands_sep(); + return __np.grouping(); +} +#endif + +template <class _CharT> +string +__num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, + _CharT& __thousands_sep) +{ + locale __loc = __iob.getloc(); + use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 32, __atoms); + const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); + __decimal_point = __np.decimal_point(); + __thousands_sep = __np.thousands_sep(); + return __np.grouping(); +} + +template <class _CharT> +int +#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET +__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, + unsigned& __dc, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, _CharT* __atoms) +#else +__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, + unsigned& __dc, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, const _CharT* __atoms) + +#endif +{ + if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) + { + *__a_end++ = __ct == __atoms[24] ? '+' : '-'; + __dc = 0; + return 0; + } + if (__grouping.size() != 0 && __ct == __thousands_sep) + { + if (__g_end-__g < __num_get_buf_sz) + { + *__g_end++ = __dc; + __dc = 0; + } + return 0; + } + ptrdiff_t __f = find(__atoms, __atoms + 26, __ct) - __atoms; + if (__f >= 24) + return -1; + switch (__base) + { + case 8: + case 10: + if (__f >= __base) + return -1; + break; + case 16: + if (__f < 22) + break; + if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0') + { + __dc = 0; + *__a_end++ = __src[__f]; + return 0; + } + return -1; + } + *__a_end++ = __src[__f]; + ++__dc; + return 0; +} + +template <class _CharT> +int +__num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end, + _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms) +{ + if (__ct == __decimal_point) + { + if (!__in_units) + return -1; + __in_units = false; + *__a_end++ = '.'; + if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) + *__g_end++ = __dc; + return 0; + } + if (__ct == __thousands_sep && __grouping.size() != 0) + { + if (!__in_units) + return -1; + if (__g_end-__g < __num_get_buf_sz) + { + *__g_end++ = __dc; + __dc = 0; + } + return 0; + } + ptrdiff_t __f = find(__atoms, __atoms + 32, __ct) - __atoms; + if (__f >= 32) + return -1; + char __x = __src[__f]; + if (__x == '-' || __x == '+') + { + if (__a_end == __a || (__a_end[-1] & 0x5F) == (__exp & 0x7F)) + { + *__a_end++ = __x; + return 0; + } + return -1; + } + if (__x == 'x' || __x == 'X') + __exp = 'P'; + else if ((__x & 0x5F) == __exp) + { + __exp |= (char) 0x80; + if (__in_units) + { + __in_units = false; + if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) + *__g_end++ = __dc; + } + } + *__a_end++ = __x; + if (__f >= 22) + return 0; + ++__dc; + return 0; +} + +_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>) + +template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > +class _LIBCPP_TEMPLATE_VIS num_get + : public locale::facet, + private __num_get<_CharT> +{ +public: + typedef _CharT char_type; + typedef _InputIterator iter_type; + + _LIBCPP_INLINE_VISIBILITY + explicit num_get(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, bool& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long long& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned short& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned int& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned long& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned long long& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, float& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, double& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long double& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, void*& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + static locale::id id; + +protected: + _LIBCPP_INLINE_VISIBILITY + ~num_get() {} + + template <class _Fp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + iter_type __do_get_floating_point + (iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, _Fp& __v) const; + + template <class _Signed> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + iter_type __do_get_signed + (iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, _Signed& __v) const; + + template <class _Unsigned> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + iter_type __do_get_unsigned + (iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, _Unsigned& __v) const; + + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, bool& __v) const; + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long& __v) const + { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); } + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long long& __v) const + { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); } + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned short& __v) const + { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned int& __v) const + { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned long& __v) const + { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned long long& __v) const + { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, float& __v) const + { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); } + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, double& __v) const + { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); } + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long double& __v) const + { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); } + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, void*& __v) const; +}; + +template <class _CharT, class _InputIterator> +locale::id +num_get<_CharT, _InputIterator>::id; + +template <class _Tp> +_LIBCPP_HIDDEN _Tp +__num_get_signed_integral(const char* __a, const char* __a_end, + ios_base::iostate& __err, int __base) +{ + if (__a != __a_end) + { + typename remove_reference<decltype(errno)>::type __save_errno = errno; + errno = 0; + char *__p2; + long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); + typename remove_reference<decltype(errno)>::type __current_errno = errno; + if (__current_errno == 0) + errno = __save_errno; + if (__p2 != __a_end) + { + __err = ios_base::failbit; + return 0; + } + else if (__current_errno == ERANGE || + __ll < numeric_limits<_Tp>::min() || + numeric_limits<_Tp>::max() < __ll) + { + __err = ios_base::failbit; + if (__ll > 0) + return numeric_limits<_Tp>::max(); + else + return numeric_limits<_Tp>::min(); + } + return static_cast<_Tp>(__ll); + } + __err = ios_base::failbit; + return 0; +} + +template <class _Tp> +_LIBCPP_HIDDEN _Tp +__num_get_unsigned_integral(const char* __a, const char* __a_end, + ios_base::iostate& __err, int __base) +{ + if (__a != __a_end) + { + const bool __negate = *__a == '-'; + if (__negate && ++__a == __a_end) { + __err = ios_base::failbit; + return 0; + } + typename remove_reference<decltype(errno)>::type __save_errno = errno; + errno = 0; + char *__p2; + unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); + typename remove_reference<decltype(errno)>::type __current_errno = errno; + if (__current_errno == 0) + errno = __save_errno; + if (__p2 != __a_end) + { + __err = ios_base::failbit; + return 0; + } + else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll) + { + __err = ios_base::failbit; + return numeric_limits<_Tp>::max(); + } + _Tp __res = static_cast<_Tp>(__ll); + if (__negate) __res = -__res; + return __res; + } + __err = ios_base::failbit; + return 0; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __do_strtod(const char* __a, char** __p2); + +template <> +inline _LIBCPP_INLINE_VISIBILITY +float __do_strtod<float>(const char* __a, char** __p2) { + return strtof_l(__a, __p2, _LIBCPP_GET_C_LOCALE); +} + +template <> +inline _LIBCPP_INLINE_VISIBILITY +double __do_strtod<double>(const char* __a, char** __p2) { + return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE); +} + +template <> +inline _LIBCPP_INLINE_VISIBILITY +long double __do_strtod<long double>(const char* __a, char** __p2) { + return strtold_l(__a, __p2, _LIBCPP_GET_C_LOCALE); +} + +template <class _Tp> +_LIBCPP_HIDDEN +_Tp +__num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) +{ + if (__a != __a_end) + { + typename remove_reference<decltype(errno)>::type __save_errno = errno; + errno = 0; + char *__p2; + _Tp __ld = __do_strtod<_Tp>(__a, &__p2); + typename remove_reference<decltype(errno)>::type __current_errno = errno; + if (__current_errno == 0) + errno = __save_errno; + if (__p2 != __a_end) + { + __err = ios_base::failbit; + return 0; + } + else if (__current_errno == ERANGE) + __err = ios_base::failbit; + return __ld; + } + __err = ios_base::failbit; + return 0; +} + +template <class _CharT, class _InputIterator> +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + bool& __v) const +{ + if ((__iob.flags() & ios_base::boolalpha) == 0) + { + long __lv = -1; + __b = do_get(__b, __e, __iob, __err, __lv); + switch (__lv) + { + case 0: + __v = false; + break; + case 1: + __v = true; + break; + default: + __v = true; + __err = ios_base::failbit; + break; + } + return __b; + } + const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__iob.getloc()); + const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__iob.getloc()); + typedef typename numpunct<_CharT>::string_type string_type; + const string_type __names[2] = {__np.truename(), __np.falsename()}; + const string_type* __i = __scan_keyword(__b, __e, __names, __names+2, + __ct, __err); + __v = __i == __names; + return __b; +} + +// signed + +template <class _CharT, class _InputIterator> +template <class _Signed> +_InputIterator +num_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + _Signed& __v) const +{ + // Stage 1 + int __base = this->__get_base(__iob); + // Stage 2 + char_type __thousands_sep; + const int __atoms_size = 26; +#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET + char_type __atoms1[__atoms_size]; + const char_type *__atoms = this->__do_widen(__iob, __atoms1); + string __grouping = this->__stage2_int_prep(__iob, __thousands_sep); +#else + char_type __atoms[__atoms_size]; + string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); +#endif + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + { + if (__a_end == __a + __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, __g, __g_end, + __atoms)) + break; + } + if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_signed_integral<_Signed>(__a, __a_end, __err, __base); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +// unsigned + +template <class _CharT, class _InputIterator> +template <class _Unsigned> +_InputIterator +num_get<_CharT, _InputIterator>::__do_get_unsigned(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + _Unsigned& __v) const +{ + // Stage 1 + int __base = this->__get_base(__iob); + // Stage 2 + char_type __thousands_sep; + const int __atoms_size = 26; +#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET + char_type __atoms1[__atoms_size]; + const char_type *__atoms = this->__do_widen(__iob, __atoms1); + string __grouping = this->__stage2_int_prep(__iob, __thousands_sep); +#else + char_type __atoms[__atoms_size]; + string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); +#endif + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + { + if (__a_end == __a + __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, __g, __g_end, + __atoms)) + break; + } + if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +// floating point + +template <class _CharT, class _InputIterator> +template <class _Fp> +_InputIterator +num_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + _Fp& __v) const +{ + // Stage 1, nothing to do + // Stage 2 + char_type __atoms[32]; + char_type __decimal_point; + char_type __thousands_sep; + string __grouping = this->__stage2_float_prep(__iob, __atoms, + __decimal_point, + __thousands_sep); + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + bool __in_units = true; + char __exp = 'E'; + for (; __b != __e; ++__b) + { + if (__a_end == __a + __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } + if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, + __decimal_point, __thousands_sep, + __grouping, __g, __g_end, + __dc, __atoms)) + break; + } + if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_float<_Fp>(__a, __a_end, __err); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template <class _CharT, class _InputIterator> +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + void*& __v) const +{ + // Stage 1 + int __base = 16; + // Stage 2 + char_type __atoms[26]; + char_type __thousands_sep = 0; + string __grouping; + use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src, + __num_get_base::__src + 26, __atoms); + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + { + if (__a_end == __a + __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, + __g, __g_end, __atoms)) + break; + } + // Stage 3 + __buf.resize(__a_end - __a); + if (__libcpp_sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1) + __err = ios_base::failbit; + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>) + +struct _LIBCPP_TYPE_VIS __num_put_base +{ +protected: + static void __format_int(char* __fmt, const char* __len, bool __signd, + ios_base::fmtflags __flags); + static bool __format_float(char* __fmt, const char* __len, + ios_base::fmtflags __flags); + static char* __identify_padding(char* __nb, char* __ne, + const ios_base& __iob); +}; + +template <class _CharT> +struct __num_put + : protected __num_put_base +{ + static void __widen_and_group_int(char* __nb, char* __np, char* __ne, + _CharT* __ob, _CharT*& __op, _CharT*& __oe, + const locale& __loc); + static void __widen_and_group_float(char* __nb, char* __np, char* __ne, + _CharT* __ob, _CharT*& __op, _CharT*& __oe, + const locale& __loc); +}; + +template <class _CharT> +void +__num_put<_CharT>::__widen_and_group_int(char* __nb, char* __np, char* __ne, + _CharT* __ob, _CharT*& __op, _CharT*& __oe, + const locale& __loc) +{ + const ctype<_CharT>& __ct = use_facet<ctype<_CharT> > (__loc); + const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc); + string __grouping = __npt.grouping(); + if (__grouping.empty()) + { + __ct.widen(__nb, __ne, __ob); + __oe = __ob + (__ne - __nb); + } + else + { + __oe = __ob; + char* __nf = __nb; + if (*__nf == '-' || *__nf == '+') + *__oe++ = __ct.widen(*__nf++); + if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || + __nf[1] == 'X')) + { + *__oe++ = __ct.widen(*__nf++); + *__oe++ = __ct.widen(*__nf++); + } + reverse(__nf, __ne); + _CharT __thousands_sep = __npt.thousands_sep(); + unsigned __dc = 0; + unsigned __dg = 0; + for (char* __p = __nf; __p < __ne; ++__p) + { + if (static_cast<unsigned>(__grouping[__dg]) > 0 && + __dc == static_cast<unsigned>(__grouping[__dg])) + { + *__oe++ = __thousands_sep; + __dc = 0; + if (__dg < __grouping.size()-1) + ++__dg; + } + *__oe++ = __ct.widen(*__p); + ++__dc; + } + reverse(__ob + (__nf - __nb), __oe); + } + if (__np == __ne) + __op = __oe; + else + __op = __ob + (__np - __nb); +} + +template <class _CharT> +void +__num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne, + _CharT* __ob, _CharT*& __op, _CharT*& __oe, + const locale& __loc) +{ + const ctype<_CharT>& __ct = use_facet<ctype<_CharT> > (__loc); + const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc); + string __grouping = __npt.grouping(); + __oe = __ob; + char* __nf = __nb; + if (*__nf == '-' || *__nf == '+') + *__oe++ = __ct.widen(*__nf++); + char* __ns; + if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || + __nf[1] == 'X')) + { + *__oe++ = __ct.widen(*__nf++); + *__oe++ = __ct.widen(*__nf++); + for (__ns = __nf; __ns < __ne; ++__ns) + if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) + break; + } + else + { + for (__ns = __nf; __ns < __ne; ++__ns) + if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) + break; + } + if (__grouping.empty()) + { + __ct.widen(__nf, __ns, __oe); + __oe += __ns - __nf; + } + else + { + reverse(__nf, __ns); + _CharT __thousands_sep = __npt.thousands_sep(); + unsigned __dc = 0; + unsigned __dg = 0; + for (char* __p = __nf; __p < __ns; ++__p) + { + if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) + { + *__oe++ = __thousands_sep; + __dc = 0; + if (__dg < __grouping.size()-1) + ++__dg; + } + *__oe++ = __ct.widen(*__p); + ++__dc; + } + reverse(__ob + (__nf - __nb), __oe); + } + for (__nf = __ns; __nf < __ne; ++__nf) + { + if (*__nf == '.') + { + *__oe++ = __npt.decimal_point(); + ++__nf; + break; + } + else + *__oe++ = __ct.widen(*__nf); + } + __ct.widen(__nf, __ne, __oe); + __oe += __ne - __nf; + if (__np == __ne) + __op = __oe; + else + __op = __ob + (__np - __nb); +} + +_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>) + +template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > +class _LIBCPP_TEMPLATE_VIS num_put + : public locale::facet, + private __num_put<_CharT> +{ +public: + typedef _CharT char_type; + typedef _OutputIterator iter_type; + + _LIBCPP_INLINE_VISIBILITY + explicit num_put(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + bool __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + long __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + long long __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + unsigned long __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + unsigned long long __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + double __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + long double __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + const void* __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + static locale::id id; + +protected: + _LIBCPP_INLINE_VISIBILITY + ~num_put() {} + + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + bool __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + long __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + long long __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + unsigned long) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + unsigned long long) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + double __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + long double __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + const void* __v) const; +}; + +template <class _CharT, class _OutputIterator> +locale::id +num_put<_CharT, _OutputIterator>::id; + +template <class _CharT, class _OutputIterator> +_LIBCPP_HIDDEN +_OutputIterator +__pad_and_output(_OutputIterator __s, + const _CharT* __ob, const _CharT* __op, const _CharT* __oe, + ios_base& __iob, _CharT __fl) +{ + streamsize __sz = __oe - __ob; + streamsize __ns = __iob.width(); + if (__ns > __sz) + __ns -= __sz; + else + __ns = 0; + for (;__ob < __op; ++__ob, ++__s) + *__s = *__ob; + for (; __ns; --__ns, ++__s) + *__s = __fl; + for (; __ob < __oe; ++__ob, ++__s) + *__s = *__ob; + __iob.width(0); + return __s; +} + +#if !defined(__APPLE__) || \ + (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ + (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) + +template <class _CharT, class _Traits> +_LIBCPP_HIDDEN +ostreambuf_iterator<_CharT, _Traits> +__pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s, + const _CharT* __ob, const _CharT* __op, const _CharT* __oe, + ios_base& __iob, _CharT __fl) +{ + if (__s.__sbuf_ == nullptr) + return __s; + streamsize __sz = __oe - __ob; + streamsize __ns = __iob.width(); + if (__ns > __sz) + __ns -= __sz; + else + __ns = 0; + streamsize __np = __op - __ob; + if (__np > 0) + { + if (__s.__sbuf_->sputn(__ob, __np) != __np) + { + __s.__sbuf_ = nullptr; + return __s; + } + } + if (__ns > 0) + { + basic_string<_CharT, _Traits> __sp(__ns, __fl); + if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns) + { + __s.__sbuf_ = nullptr; + return __s; + } + } + __np = __oe - __op; + if (__np > 0) + { + if (__s.__sbuf_->sputn(__op, __np) != __np) + { + __s.__sbuf_ = nullptr; + return __s; + } + } + __iob.width(0); + return __s; +} + +#endif + +template <class _CharT, class _OutputIterator> +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, bool __v) const +{ + if ((__iob.flags() & ios_base::boolalpha) == 0) + return do_put(__s, __iob, __fl, (unsigned long)__v); + const numpunct<char_type>& __np = use_facet<numpunct<char_type> >(__iob.getloc()); + typedef typename numpunct<char_type>::string_type string_type; +#if _LIBCPP_DEBUG_LEVEL >= 2 + string_type __tmp(__v ? __np.truename() : __np.falsename()); + string_type __nm = _VSTD::move(__tmp); +#else + string_type __nm = __v ? __np.truename() : __np.falsename(); +#endif + for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s) + *__s = *__i; + return __s; +} + +template <class _CharT, class _OutputIterator> +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, long __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[6] = {'%', 0}; + const char* __len = "l"; + this->__format_int(__fmt+1, __len, true, __iob.flags()); + const unsigned __nbuf = (numeric_limits<long>::digits / 3) + + ((numeric_limits<long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + + 2; + char __nar[__nbuf]; + int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +template <class _CharT, class _OutputIterator> +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, long long __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[8] = {'%', 0}; + const char* __len = "ll"; + this->__format_int(__fmt+1, __len, true, __iob.flags()); + const unsigned __nbuf = (numeric_limits<long long>::digits / 3) + + ((numeric_limits<long long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + + 2; + char __nar[__nbuf]; + int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +template <class _CharT, class _OutputIterator> +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, unsigned long __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[6] = {'%', 0}; + const char* __len = "l"; + this->__format_int(__fmt+1, __len, false, __iob.flags()); + const unsigned __nbuf = (numeric_limits<unsigned long>::digits / 3) + + ((numeric_limits<unsigned long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + + 1; + char __nar[__nbuf]; + int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +template <class _CharT, class _OutputIterator> +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, unsigned long long __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[8] = {'%', 0}; + const char* __len = "ll"; + this->__format_int(__fmt+1, __len, false, __iob.flags()); + const unsigned __nbuf = (numeric_limits<unsigned long long>::digits / 3) + + ((numeric_limits<unsigned long long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + + 1; + char __nar[__nbuf]; + int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +template <class _CharT, class _OutputIterator> +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, double __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[8] = {'%', 0}; + const char* __len = ""; + bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); + const unsigned __nbuf = 30; + char __nar[__nbuf]; + char* __nb = __nar; + int __nc; + if (__specify_precision) + __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, + (int)__iob.precision(), __v); + else + __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); + unique_ptr<char, void(*)(void*)> __nbh(0, free); + if (__nc > static_cast<int>(__nbuf-1)) + { + if (__specify_precision) + __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); + else + __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); + if (__nb == 0) + __throw_bad_alloc(); + __nbh.reset(__nb); + } + char* __ne = __nb + __nc; + char* __np = this->__identify_padding(__nb, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __ob = __o; + unique_ptr<char_type, void(*)(void*)> __obh(0, free); + if (__nb != __nar) + { + __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type)); + if (__ob == 0) + __throw_bad_alloc(); + __obh.reset(__ob); + } + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); + return __s; +} + +template <class _CharT, class _OutputIterator> +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, long double __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[8] = {'%', 0}; + const char* __len = "L"; + bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); + const unsigned __nbuf = 30; + char __nar[__nbuf]; + char* __nb = __nar; + int __nc; + if (__specify_precision) + __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, + (int)__iob.precision(), __v); + else + __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); + unique_ptr<char, void(*)(void*)> __nbh(0, free); + if (__nc > static_cast<int>(__nbuf-1)) + { + if (__specify_precision) + __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); + else + __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); + if (__nb == 0) + __throw_bad_alloc(); + __nbh.reset(__nb); + } + char* __ne = __nb + __nc; + char* __np = this->__identify_padding(__nb, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __ob = __o; + unique_ptr<char_type, void(*)(void*)> __obh(0, free); + if (__nb != __nar) + { + __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type)); + if (__ob == 0) + __throw_bad_alloc(); + __obh.reset(__ob); + } + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); + return __s; +} + +template <class _CharT, class _OutputIterator> +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, const void* __v) const +{ + // Stage 1 - Get pointer in narrow char + char __fmt[6] = "%p"; + const unsigned __nbuf = 20; + char __nar[__nbuf]; + int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); + __ct.widen(__nar, __ne, __o); + __oe = __o + (__ne - __nar); + if (__np == __ne) + __op = __oe; + else + __op = __o + (__np - __nar); + // [__o, __oe) contains wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>) + +template <class _CharT, class _InputIterator> +_LIBCPP_HIDDEN +int +__get_up_to_n_digits(_InputIterator& __b, _InputIterator __e, + ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) +{ + // Precondition: __n >= 1 + if (__b == __e) + { + __err |= ios_base::eofbit | ios_base::failbit; + return 0; + } + // get first digit + _CharT __c = *__b; + if (!__ct.is(ctype_base::digit, __c)) + { + __err |= ios_base::failbit; + return 0; + } + int __r = __ct.narrow(__c, 0) - '0'; + for (++__b, (void) --__n; __b != __e && __n > 0; ++__b, (void) --__n) + { + // get next digit + __c = *__b; + if (!__ct.is(ctype_base::digit, __c)) + return __r; + __r = __r * 10 + __ct.narrow(__c, 0) - '0'; + } + if (__b == __e) + __err |= ios_base::eofbit; + return __r; +} + +class _LIBCPP_TYPE_VIS time_base +{ +public: + enum dateorder {no_order, dmy, mdy, ymd, ydm}; +}; + +template <class _CharT> +class _LIBCPP_TEMPLATE_VIS __time_get_c_storage +{ +protected: + typedef basic_string<_CharT> string_type; + + virtual const string_type* __weeks() const; + virtual const string_type* __months() const; + virtual const string_type* __am_pm() const; + virtual const string_type& __c() const; + virtual const string_type& __r() const; + virtual const string_type& __x() const; + virtual const string_type& __X() const; + + _LIBCPP_INLINE_VISIBILITY + ~__time_get_c_storage() {} +}; + +template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__weeks() const; +template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__months() const; +template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__am_pm() const; +template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__c() const; +template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__r() const; +template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__x() const; +template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__X() const; + +template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__weeks() const; +template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__months() const; +template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__am_pm() const; +template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__c() const; +template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__r() const; +template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__x() const; +template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__X() const; + +template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > +class _LIBCPP_TEMPLATE_VIS time_get + : public locale::facet, + public time_base, + private __time_get_c_storage<_CharT> +{ +public: + typedef _CharT char_type; + typedef _InputIterator iter_type; + typedef time_base::dateorder dateorder; + typedef basic_string<char_type> string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit time_get(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + dateorder date_order() const + { + return this->do_date_order(); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get_time(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_time(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get_date(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_date(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get_weekday(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_weekday(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get_monthname(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_monthname(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get_year(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_year(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm *__tm, + char __fmt, char __mod = 0) const + { + return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod); + } + + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm, + const char_type* __fmtb, const char_type* __fmte) const; + + static locale::id id; + +protected: + _LIBCPP_INLINE_VISIBILITY + ~time_get() {} + + virtual dateorder do_date_order() const; + virtual iter_type do_get_time(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get_date(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get_year(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm, + char __fmt, char __mod) const; +private: + void __get_white_space(iter_type& __b, iter_type __e, + ios_base::iostate& __err, const ctype<char_type>& __ct) const; + void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + + void __get_weekdayname(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_monthname(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_day(int& __d, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_month(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_year(int& __y, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_year4(int& __y, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_hour(int& __d, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_12_hour(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_am_pm(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_minute(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_second(int& __s, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_weekday(int& __w, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; + void __get_day_year_num(int& __w, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const; +}; + +template <class _CharT, class _InputIterator> +locale::id +time_get<_CharT, _InputIterator>::id; + +// time_get primitives + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_weekdayname(int& __w, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + // Note: ignoring case comes from the POSIX strptime spec + const string_type* __wk = this->__weeks(); + ptrdiff_t __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk; + if (__i < 14) + __w = __i % 7; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_monthname(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + // Note: ignoring case comes from the POSIX strptime spec + const string_type* __month = this->__months(); + ptrdiff_t __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month; + if (__i < 24) + __m = __i % 12; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_day(int& __d, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31) + __d = __t; + else + __err |= ios_base::failbit; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_month(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1; + if (!(__err & ios_base::failbit) && __t <= 11) + __m = __t; + else + __err |= ios_base::failbit; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_year(int& __y, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); + if (!(__err & ios_base::failbit)) + { + if (__t < 69) + __t += 2000; + else if (69 <= __t && __t <= 99) + __t += 1900; + __y = __t - 1900; + } +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_year4(int& __y, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); + if (!(__err & ios_base::failbit)) + __y = __t - 1900; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_hour(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && __t <= 23) + __h = __t; + else + __err |= ios_base::failbit; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_12_hour(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12) + __h = __t; + else + __err |= ios_base::failbit; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_minute(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && __t <= 59) + __m = __t; + else + __err |= ios_base::failbit; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_second(int& __s, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && __t <= 60) + __s = __t; + else + __err |= ios_base::failbit; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_weekday(int& __w, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 1); + if (!(__err & ios_base::failbit) && __t <= 6) + __w = __t; + else + __err |= ios_base::failbit; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_day_year_num(int& __d, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 3); + if (!(__err & ios_base::failbit) && __t <= 365) + __d = __t; + else + __err |= ios_base::failbit; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_white_space(iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) + ; + if (__b == __e) + __err |= ios_base::eofbit; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_am_pm(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + const string_type* __ap = this->__am_pm(); + if (__ap[0].size() + __ap[1].size() == 0) + { + __err |= ios_base::failbit; + return; + } + ptrdiff_t __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap; + if (__i == 0 && __h == 12) + __h = 0; + else if (__i == 1 && __h < 12) + __h += 12; +} + +template <class _CharT, class _InputIterator> +void +time_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype<char_type>& __ct) const +{ + if (__b == __e) + { + __err |= ios_base::eofbit | ios_base::failbit; + return; + } + if (__ct.narrow(*__b, 0) != '%') + __err |= ios_base::failbit; + else if(++__b == __e) + __err |= ios_base::eofbit; +} + +// time_get end primitives + +template <class _CharT, class _InputIterator> +_InputIterator +time_get<_CharT, _InputIterator>::get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, tm* __tm, + const char_type* __fmtb, const char_type* __fmte) const +{ + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); + __err = ios_base::goodbit; + while (__fmtb != __fmte && __err == ios_base::goodbit) + { + if (__b == __e) + { + __err = ios_base::failbit; + break; + } + if (__ct.narrow(*__fmtb, 0) == '%') + { + if (++__fmtb == __fmte) + { + __err = ios_base::failbit; + break; + } + char __cmd = __ct.narrow(*__fmtb, 0); + char __opt = '\0'; + if (__cmd == 'E' || __cmd == '0') + { + if (++__fmtb == __fmte) + { + __err = ios_base::failbit; + break; + } + __opt = __cmd; + __cmd = __ct.narrow(*__fmtb, 0); + } + __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt); + ++__fmtb; + } + else if (__ct.is(ctype_base::space, *__fmtb)) + { + for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb) + ; + for ( ; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) + ; + } + else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) + { + ++__b; + ++__fmtb; + } + else + __err = ios_base::failbit; + } + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template <class _CharT, class _InputIterator> +typename time_get<_CharT, _InputIterator>::dateorder +time_get<_CharT, _InputIterator>::do_date_order() const +{ + return mdy; +} + +template <class _CharT, class _InputIterator> +_InputIterator +time_get<_CharT, _InputIterator>::do_get_time(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; + return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); +} + +template <class _CharT, class _InputIterator> +_InputIterator +time_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const string_type& __fmt = this->__x(); + return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size()); +} + +template <class _CharT, class _InputIterator> +_InputIterator +time_get<_CharT, _InputIterator>::do_get_weekday(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); + __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); + return __b; +} + +template <class _CharT, class _InputIterator> +_InputIterator +time_get<_CharT, _InputIterator>::do_get_monthname(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); + __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); + return __b; +} + +template <class _CharT, class _InputIterator> +_InputIterator +time_get<_CharT, _InputIterator>::do_get_year(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); + __get_year(__tm->tm_year, __b, __e, __err, __ct); + return __b; +} + +template <class _CharT, class _InputIterator> +_InputIterator +time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, tm* __tm, + char __fmt, char) const +{ + __err = ios_base::goodbit; + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); + switch (__fmt) + { + case 'a': + case 'A': + __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); + break; + case 'b': + case 'B': + case 'h': + __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); + break; + case 'c': + { + const string_type& __fm = this->__c(); + __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); + } + break; + case 'd': + case 'e': + __get_day(__tm->tm_mday, __b, __e, __err, __ct); + break; + case 'D': + { + const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'}; + __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); + } + break; + case 'F': + { + const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'}; + __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); + } + break; + case 'H': + __get_hour(__tm->tm_hour, __b, __e, __err, __ct); + break; + case 'I': + __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct); + break; + case 'j': + __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct); + break; + case 'm': + __get_month(__tm->tm_mon, __b, __e, __err, __ct); + break; + case 'M': + __get_minute(__tm->tm_min, __b, __e, __err, __ct); + break; + case 'n': + case 't': + __get_white_space(__b, __e, __err, __ct); + break; + case 'p': + __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct); + break; + case 'r': + { + const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'}; + __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); + } + break; + case 'R': + { + const char_type __fm[] = {'%', 'H', ':', '%', 'M'}; + __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); + } + break; + case 'S': + __get_second(__tm->tm_sec, __b, __e, __err, __ct); + break; + case 'T': + { + const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; + __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); + } + break; + case 'w': + __get_weekday(__tm->tm_wday, __b, __e, __err, __ct); + break; + case 'x': + return do_get_date(__b, __e, __iob, __err, __tm); + case 'X': + { + const string_type& __fm = this->__X(); + __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); + } + break; + case 'y': + __get_year(__tm->tm_year, __b, __e, __err, __ct); + break; + case 'Y': + __get_year4(__tm->tm_year, __b, __e, __err, __ct); + break; + case '%': + __get_percent(__b, __e, __err, __ct); + break; + default: + __err |= ios_base::failbit; + } + return __b; +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>) + +class _LIBCPP_TYPE_VIS __time_get +{ +protected: + locale_t __loc_; + + __time_get(const char* __nm); + __time_get(const string& __nm); + ~__time_get(); +}; + +template <class _CharT> +class _LIBCPP_TEMPLATE_VIS __time_get_storage + : public __time_get +{ +protected: + typedef basic_string<_CharT> string_type; + + string_type __weeks_[14]; + string_type __months_[24]; + string_type __am_pm_[2]; + string_type __c_; + string_type __r_; + string_type __x_; + string_type __X_; + + explicit __time_get_storage(const char* __nm); + explicit __time_get_storage(const string& __nm); + + _LIBCPP_INLINE_VISIBILITY ~__time_get_storage() {} + + time_base::dateorder __do_date_order() const; + +private: + void init(const ctype<_CharT>&); + string_type __analyze(char __fmt, const ctype<_CharT>&); +}; + +#define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \ +template <> _LIBCPP_FUNC_VIS time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \ +template <> _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const char*); \ +template <> _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const string&); \ +template <> _LIBCPP_FUNC_VIS void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \ +template <> _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \ +extern template _LIBCPP_FUNC_VIS time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \ +extern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const char*); \ +extern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const string&); \ +extern template _LIBCPP_FUNC_VIS void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \ +extern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \ +/**/ + +_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char) +_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t) +#undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION + +template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > +class _LIBCPP_TEMPLATE_VIS time_get_byname + : public time_get<_CharT, _InputIterator>, + private __time_get_storage<_CharT> +{ +public: + typedef time_base::dateorder dateorder; + typedef _InputIterator iter_type; + typedef _CharT char_type; + typedef basic_string<char_type> string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit time_get_byname(const char* __nm, size_t __refs = 0) + : time_get<_CharT, _InputIterator>(__refs), + __time_get_storage<_CharT>(__nm) {} + _LIBCPP_INLINE_VISIBILITY + explicit time_get_byname(const string& __nm, size_t __refs = 0) + : time_get<_CharT, _InputIterator>(__refs), + __time_get_storage<_CharT>(__nm) {} + +protected: + _LIBCPP_INLINE_VISIBILITY + ~time_get_byname() {} + + _LIBCPP_INLINE_VISIBILITY + virtual dateorder do_date_order() const {return this->__do_date_order();} +private: + _LIBCPP_INLINE_VISIBILITY + virtual const string_type* __weeks() const {return this->__weeks_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type* __months() const {return this->__months_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type* __am_pm() const {return this->__am_pm_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type& __c() const {return this->__c_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type& __r() const {return this->__r_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type& __x() const {return this->__x_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type& __X() const {return this->__X_;} +}; + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>) + +class _LIBCPP_TYPE_VIS __time_put +{ + locale_t __loc_; +protected: + _LIBCPP_INLINE_VISIBILITY __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {} + __time_put(const char* __nm); + __time_put(const string& __nm); + ~__time_put(); + void __do_put(char* __nb, char*& __ne, const tm* __tm, + char __fmt, char __mod) const; + void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, + char __fmt, char __mod) const; +}; + +template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > +class _LIBCPP_TEMPLATE_VIS time_put + : public locale::facet, + private __time_put +{ +public: + typedef _CharT char_type; + typedef _OutputIterator iter_type; + + _LIBCPP_INLINE_VISIBILITY + explicit time_put(size_t __refs = 0) + : locale::facet(__refs) {} + + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, + const char_type* __pb, const char_type* __pe) const; + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + const tm* __tm, char __fmt, char __mod = 0) const + { + return do_put(__s, __iob, __fl, __tm, __fmt, __mod); + } + + static locale::id id; + +protected: + _LIBCPP_INLINE_VISIBILITY + ~time_put() {} + virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, + char __fmt, char __mod) const; + + _LIBCPP_INLINE_VISIBILITY + explicit time_put(const char* __nm, size_t __refs) + : locale::facet(__refs), + __time_put(__nm) {} + _LIBCPP_INLINE_VISIBILITY + explicit time_put(const string& __nm, size_t __refs) + : locale::facet(__refs), + __time_put(__nm) {} +}; + +template <class _CharT, class _OutputIterator> +locale::id +time_put<_CharT, _OutputIterator>::id; + +template <class _CharT, class _OutputIterator> +_OutputIterator +time_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob, + char_type __fl, const tm* __tm, + const char_type* __pb, + const char_type* __pe) const +{ + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); + for (; __pb != __pe; ++__pb) + { + if (__ct.narrow(*__pb, 0) == '%') + { + if (++__pb == __pe) + { + *__s++ = __pb[-1]; + break; + } + char __mod = 0; + char __fmt = __ct.narrow(*__pb, 0); + if (__fmt == 'E' || __fmt == 'O') + { + if (++__pb == __pe) + { + *__s++ = __pb[-2]; + *__s++ = __pb[-1]; + break; + } + __mod = __fmt; + __fmt = __ct.narrow(*__pb, 0); + } + __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod); + } + else + *__s++ = *__pb; + } + return __s; +} + +template <class _CharT, class _OutputIterator> +_OutputIterator +time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&, + char_type, const tm* __tm, + char __fmt, char __mod) const +{ + char_type __nar[100]; + char_type* __nb = __nar; + char_type* __ne = __nb + 100; + __do_put(__nb, __ne, __tm, __fmt, __mod); + return _VSTD::copy(__nb, __ne, __s); +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>) + +template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > +class _LIBCPP_TEMPLATE_VIS time_put_byname + : public time_put<_CharT, _OutputIterator> +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit time_put_byname(const char* __nm, size_t __refs = 0) + : time_put<_CharT, _OutputIterator>(__nm, __refs) {} + + _LIBCPP_INLINE_VISIBILITY + explicit time_put_byname(const string& __nm, size_t __refs = 0) + : time_put<_CharT, _OutputIterator>(__nm, __refs) {} + +protected: + _LIBCPP_INLINE_VISIBILITY + ~time_put_byname() {} +}; + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>) + +// money_base + +class _LIBCPP_TYPE_VIS money_base +{ +public: + enum part {none, space, symbol, sign, value}; + struct pattern {char field[4];}; + + _LIBCPP_INLINE_VISIBILITY money_base() {} +}; + +// moneypunct + +template <class _CharT, bool _International = false> +class _LIBCPP_TEMPLATE_VIS moneypunct + : public locale::facet, + public money_base +{ +public: + typedef _CharT char_type; + typedef basic_string<char_type> string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit moneypunct(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();} + _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();} + _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();} + _LIBCPP_INLINE_VISIBILITY string_type curr_symbol() const {return do_curr_symbol();} + _LIBCPP_INLINE_VISIBILITY string_type positive_sign() const {return do_positive_sign();} + _LIBCPP_INLINE_VISIBILITY string_type negative_sign() const {return do_negative_sign();} + _LIBCPP_INLINE_VISIBILITY int frac_digits() const {return do_frac_digits();} + _LIBCPP_INLINE_VISIBILITY pattern pos_format() const {return do_pos_format();} + _LIBCPP_INLINE_VISIBILITY pattern neg_format() const {return do_neg_format();} + + static locale::id id; + static const bool intl = _International; + +protected: + _LIBCPP_INLINE_VISIBILITY + ~moneypunct() {} + + virtual char_type do_decimal_point() const {return numeric_limits<char_type>::max();} + virtual char_type do_thousands_sep() const {return numeric_limits<char_type>::max();} + virtual string do_grouping() const {return string();} + virtual string_type do_curr_symbol() const {return string_type();} + virtual string_type do_positive_sign() const {return string_type();} + virtual string_type do_negative_sign() const {return string_type(1, '-');} + virtual int do_frac_digits() const {return 0;} + virtual pattern do_pos_format() const + {pattern __p = {{symbol, sign, none, value}}; return __p;} + virtual pattern do_neg_format() const + {pattern __p = {{symbol, sign, none, value}}; return __p;} +}; + +template <class _CharT, bool _International> +locale::id +moneypunct<_CharT, _International>::id; + +template <class _CharT, bool _International> +const bool +moneypunct<_CharT, _International>::intl; + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>) + +// moneypunct_byname + +template <class _CharT, bool _International = false> +class _LIBCPP_TEMPLATE_VIS moneypunct_byname + : public moneypunct<_CharT, _International> +{ +public: + typedef money_base::pattern pattern; + typedef _CharT char_type; + typedef basic_string<char_type> string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit moneypunct_byname(const char* __nm, size_t __refs = 0) + : moneypunct<_CharT, _International>(__refs) {init(__nm);} + + _LIBCPP_INLINE_VISIBILITY + explicit moneypunct_byname(const string& __nm, size_t __refs = 0) + : moneypunct<_CharT, _International>(__refs) {init(__nm.c_str());} + +protected: + _LIBCPP_INLINE_VISIBILITY + ~moneypunct_byname() {} + + virtual char_type do_decimal_point() const {return __decimal_point_;} + virtual char_type do_thousands_sep() const {return __thousands_sep_;} + virtual string do_grouping() const {return __grouping_;} + virtual string_type do_curr_symbol() const {return __curr_symbol_;} + virtual string_type do_positive_sign() const {return __positive_sign_;} + virtual string_type do_negative_sign() const {return __negative_sign_;} + virtual int do_frac_digits() const {return __frac_digits_;} + virtual pattern do_pos_format() const {return __pos_format_;} + virtual pattern do_neg_format() const {return __neg_format_;} + +private: + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; + string_type __curr_symbol_; + string_type __positive_sign_; + string_type __negative_sign_; + int __frac_digits_; + pattern __pos_format_; + pattern __neg_format_; + + void init(const char*); +}; + +template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, false>::init(const char*); +template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, true>::init(const char*); +template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, false>::init(const char*); +template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, true>::init(const char*); + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>) + +// money_get + +template <class _CharT> +class __money_get +{ +protected: + typedef _CharT char_type; + typedef basic_string<char_type> string_type; + + _LIBCPP_INLINE_VISIBILITY __money_get() {} + + static void __gather_info(bool __intl, const locale& __loc, + money_base::pattern& __pat, char_type& __dp, + char_type& __ts, string& __grp, + string_type& __sym, string_type& __psn, + string_type& __nsn, int& __fd); +}; + +template <class _CharT> +void +__money_get<_CharT>::__gather_info(bool __intl, const locale& __loc, + money_base::pattern& __pat, char_type& __dp, + char_type& __ts, string& __grp, + string_type& __sym, string_type& __psn, + string_type& __nsn, int& __fd) +{ + if (__intl) + { + const moneypunct<char_type, true>& __mp = + use_facet<moneypunct<char_type, true> >(__loc); + __pat = __mp.neg_format(); + __nsn = __mp.negative_sign(); + __psn = __mp.positive_sign(); + __dp = __mp.decimal_point(); + __ts = __mp.thousands_sep(); + __grp = __mp.grouping(); + __sym = __mp.curr_symbol(); + __fd = __mp.frac_digits(); + } + else + { + const moneypunct<char_type, false>& __mp = + use_facet<moneypunct<char_type, false> >(__loc); + __pat = __mp.neg_format(); + __nsn = __mp.negative_sign(); + __psn = __mp.positive_sign(); + __dp = __mp.decimal_point(); + __ts = __mp.thousands_sep(); + __grp = __mp.grouping(); + __sym = __mp.curr_symbol(); + __fd = __mp.frac_digits(); + } +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>) + +template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > +class _LIBCPP_TEMPLATE_VIS money_get + : public locale::facet, + private __money_get<_CharT> +{ +public: + typedef _CharT char_type; + typedef _InputIterator iter_type; + typedef basic_string<char_type> string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit money_get(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, + ios_base::iostate& __err, long double& __v) const + { + return do_get(__b, __e, __intl, __iob, __err, __v); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, + ios_base::iostate& __err, string_type& __v) const + { + return do_get(__b, __e, __intl, __iob, __err, __v); + } + + static locale::id id; + +protected: + + _LIBCPP_INLINE_VISIBILITY + ~money_get() {} + + virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, + ios_base& __iob, ios_base::iostate& __err, + long double& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, + ios_base& __iob, ios_base::iostate& __err, + string_type& __v) const; + +private: + static bool __do_get(iter_type& __b, iter_type __e, + bool __intl, const locale& __loc, + ios_base::fmtflags __flags, ios_base::iostate& __err, + bool& __neg, const ctype<char_type>& __ct, + unique_ptr<char_type, void(*)(void*)>& __wb, + char_type*& __wn, char_type* __we); +}; + +template <class _CharT, class _InputIterator> +locale::id +money_get<_CharT, _InputIterator>::id; + +_LIBCPP_FUNC_VIS void __do_nothing(void*); + +template <class _Tp> +_LIBCPP_HIDDEN +void +__double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e) +{ + bool __owns = __b.get_deleter() != __do_nothing; + size_t __cur_cap = static_cast<size_t>(__e-__b.get()) * sizeof(_Tp); + size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ? + 2 * __cur_cap : numeric_limits<size_t>::max(); + if (__new_cap == 0) + __new_cap = sizeof(_Tp); + size_t __n_off = static_cast<size_t>(__n - __b.get()); + _Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap); + if (__t == 0) + __throw_bad_alloc(); + if (__owns) + __b.release(); + __b = unique_ptr<_Tp, void(*)(void*)>(__t, free); + __new_cap /= sizeof(_Tp); + __n = __b.get() + __n_off; + __e = __b.get() + __new_cap; +} + +// true == success +template <class _CharT, class _InputIterator> +bool +money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e, + bool __intl, const locale& __loc, + ios_base::fmtflags __flags, + ios_base::iostate& __err, + bool& __neg, + const ctype<char_type>& __ct, + unique_ptr<char_type, void(*)(void*)>& __wb, + char_type*& __wn, char_type* __we) +{ + const unsigned __bz = 100; + unsigned __gbuf[__bz]; + unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing); + unsigned* __gn = __gb.get(); + unsigned* __ge = __gn + __bz; + money_base::pattern __pat; + char_type __dp; + char_type __ts; + string __grp; + string_type __sym; + string_type __psn; + string_type __nsn; + // Capture the spaces read into money_base::{space,none} so they + // can be compared to initial spaces in __sym. + string_type __spaces; + int __fd; + __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp, + __sym, __psn, __nsn, __fd); + const string_type* __trailing_sign = 0; + __wn = __wb.get(); + for (unsigned __p = 0; __p < 4 && __b != __e; ++__p) + { + switch (__pat.field[__p]) + { + case money_base::space: + if (__p != 3) + { + if (__ct.is(ctype_base::space, *__b)) + __spaces.push_back(*__b++); + else + { + __err |= ios_base::failbit; + return false; + } + } + _LIBCPP_FALLTHROUGH(); + case money_base::none: + if (__p != 3) + { + while (__b != __e && __ct.is(ctype_base::space, *__b)) + __spaces.push_back(*__b++); + } + break; + case money_base::sign: + if (__psn.size() + __nsn.size() > 0) + { + if (__psn.size() == 0 || __nsn.size() == 0) + { // sign is optional + if (__psn.size() > 0) + { // __nsn.size() == 0 + if (*__b == __psn[0]) + { + ++__b; + if (__psn.size() > 1) + __trailing_sign = &__psn; + } + else + __neg = true; + } + else if (*__b == __nsn[0]) // __nsn.size() > 0 && __psn.size() == 0 + { + ++__b; + __neg = true; + if (__nsn.size() > 1) + __trailing_sign = &__nsn; + } + } + else // sign is required + { + if (*__b == __psn[0]) + { + ++__b; + if (__psn.size() > 1) + __trailing_sign = &__psn; + } + else if (*__b == __nsn[0]) + { + ++__b; + __neg = true; + if (__nsn.size() > 1) + __trailing_sign = &__nsn; + } + else + { + __err |= ios_base::failbit; + return false; + } + } + } + break; + case money_base::symbol: + { + bool __more_needed = __trailing_sign || + (__p < 2) || + (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none)); + bool __sb = (__flags & ios_base::showbase) != 0; + if (__sb || __more_needed) + { + typename string_type::const_iterator __sym_space_end = __sym.begin(); + if (__p > 0 && (__pat.field[__p - 1] == money_base::none || + __pat.field[__p - 1] == money_base::space)) { + // Match spaces we've already read against spaces at + // the beginning of __sym. + while (__sym_space_end != __sym.end() && + __ct.is(ctype_base::space, *__sym_space_end)) + ++__sym_space_end; + const size_t __num_spaces = __sym_space_end - __sym.begin(); + if (__num_spaces > __spaces.size() || + !equal(__spaces.end() - __num_spaces, __spaces.end(), + __sym.begin())) { + // No match. Put __sym_space_end back at the + // beginning of __sym, which will prevent a + // match in the next loop. + __sym_space_end = __sym.begin(); + } + } + typename string_type::const_iterator __sym_curr_char = __sym_space_end; + while (__sym_curr_char != __sym.end() && __b != __e && + *__b == *__sym_curr_char) { + ++__b; + ++__sym_curr_char; + } + if (__sb && __sym_curr_char != __sym.end()) + { + __err |= ios_base::failbit; + return false; + } + } + } + break; + case money_base::value: + { + unsigned __ng = 0; + for (; __b != __e; ++__b) + { + char_type __c = *__b; + if (__ct.is(ctype_base::digit, __c)) + { + if (__wn == __we) + __double_or_nothing(__wb, __wn, __we); + *__wn++ = __c; + ++__ng; + } + else if (__grp.size() > 0 && __ng > 0 && __c == __ts) + { + if (__gn == __ge) + __double_or_nothing(__gb, __gn, __ge); + *__gn++ = __ng; + __ng = 0; + } + else + break; + } + if (__gb.get() != __gn && __ng > 0) + { + if (__gn == __ge) + __double_or_nothing(__gb, __gn, __ge); + *__gn++ = __ng; + } + if (__fd > 0) + { + if (__b == __e || *__b != __dp) + { + __err |= ios_base::failbit; + return false; + } + for (++__b; __fd > 0; --__fd, ++__b) + { + if (__b == __e || !__ct.is(ctype_base::digit, *__b)) + { + __err |= ios_base::failbit; + return false; + } + if (__wn == __we) + __double_or_nothing(__wb, __wn, __we); + *__wn++ = *__b; + } + } + if (__wn == __wb.get()) + { + __err |= ios_base::failbit; + return false; + } + } + break; + } + } + if (__trailing_sign) + { + for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) + { + if (__b == __e || *__b != (*__trailing_sign)[__i]) + { + __err |= ios_base::failbit; + return false; + } + } + } + if (__gb.get() != __gn) + { + ios_base::iostate __et = ios_base::goodbit; + __check_grouping(__grp, __gb.get(), __gn, __et); + if (__et) + { + __err |= ios_base::failbit; + return false; + } + } + return true; +} + +template <class _CharT, class _InputIterator> +_InputIterator +money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + bool __intl, ios_base& __iob, + ios_base::iostate& __err, + long double& __v) const +{ + const int __bz = 100; + char_type __wbuf[__bz]; + unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing); + char_type* __wn; + char_type* __we = __wbuf + __bz; + locale __loc = __iob.getloc(); + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); + bool __neg = false; + if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, + __wb, __wn, __we)) + { + const char __src[] = "0123456789"; + char_type __atoms[sizeof(__src)-1]; + __ct.widen(__src, __src + (sizeof(__src)-1), __atoms); + char __nbuf[__bz]; + char* __nc = __nbuf; + unique_ptr<char, void(*)(void*)> __h(0, free); + if (__wn - __wb.get() > __bz-2) + { + __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2))); + if (__h.get() == 0) + __throw_bad_alloc(); + __nc = __h.get(); + } + if (__neg) + *__nc++ = '-'; + for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc) + *__nc = __src[find(__atoms, _VSTD::end(__atoms), *__w) - __atoms]; + *__nc = char(); + if (sscanf(__nbuf, "%Lf", &__v) != 1) + __throw_runtime_error("money_get error"); + } + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template <class _CharT, class _InputIterator> +_InputIterator +money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + bool __intl, ios_base& __iob, + ios_base::iostate& __err, + string_type& __v) const +{ + const int __bz = 100; + char_type __wbuf[__bz]; + unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing); + char_type* __wn; + char_type* __we = __wbuf + __bz; + locale __loc = __iob.getloc(); + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); + bool __neg = false; + if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, + __wb, __wn, __we)) + { + __v.clear(); + if (__neg) + __v.push_back(__ct.widen('-')); + char_type __z = __ct.widen('0'); + char_type* __w; + for (__w = __wb.get(); __w < __wn-1; ++__w) + if (*__w != __z) + break; + __v.append(__w, __wn); + } + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>) + +// money_put + +template <class _CharT> +class __money_put +{ +protected: + typedef _CharT char_type; + typedef basic_string<char_type> string_type; + + _LIBCPP_INLINE_VISIBILITY __money_put() {} + + static void __gather_info(bool __intl, bool __neg, const locale& __loc, + money_base::pattern& __pat, char_type& __dp, + char_type& __ts, string& __grp, + string_type& __sym, string_type& __sn, + int& __fd); + static void __format(char_type* __mb, char_type*& __mi, char_type*& __me, + ios_base::fmtflags __flags, + const char_type* __db, const char_type* __de, + const ctype<char_type>& __ct, bool __neg, + const money_base::pattern& __pat, char_type __dp, + char_type __ts, const string& __grp, + const string_type& __sym, const string_type& __sn, + int __fd); +}; + +template <class _CharT> +void +__money_put<_CharT>::__gather_info(bool __intl, bool __neg, const locale& __loc, + money_base::pattern& __pat, char_type& __dp, + char_type& __ts, string& __grp, + string_type& __sym, string_type& __sn, + int& __fd) +{ + if (__intl) + { + const moneypunct<char_type, true>& __mp = + use_facet<moneypunct<char_type, true> >(__loc); + if (__neg) + { + __pat = __mp.neg_format(); + __sn = __mp.negative_sign(); + } + else + { + __pat = __mp.pos_format(); + __sn = __mp.positive_sign(); + } + __dp = __mp.decimal_point(); + __ts = __mp.thousands_sep(); + __grp = __mp.grouping(); + __sym = __mp.curr_symbol(); + __fd = __mp.frac_digits(); + } + else + { + const moneypunct<char_type, false>& __mp = + use_facet<moneypunct<char_type, false> >(__loc); + if (__neg) + { + __pat = __mp.neg_format(); + __sn = __mp.negative_sign(); + } + else + { + __pat = __mp.pos_format(); + __sn = __mp.positive_sign(); + } + __dp = __mp.decimal_point(); + __ts = __mp.thousands_sep(); + __grp = __mp.grouping(); + __sym = __mp.curr_symbol(); + __fd = __mp.frac_digits(); + } +} + +template <class _CharT> +void +__money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __me, + ios_base::fmtflags __flags, + const char_type* __db, const char_type* __de, + const ctype<char_type>& __ct, bool __neg, + const money_base::pattern& __pat, char_type __dp, + char_type __ts, const string& __grp, + const string_type& __sym, const string_type& __sn, + int __fd) +{ + __me = __mb; + for (unsigned __p = 0; __p < 4; ++__p) + { + switch (__pat.field[__p]) + { + case money_base::none: + __mi = __me; + break; + case money_base::space: + __mi = __me; + *__me++ = __ct.widen(' '); + break; + case money_base::sign: + if (!__sn.empty()) + *__me++ = __sn[0]; + break; + case money_base::symbol: + if (!__sym.empty() && (__flags & ios_base::showbase)) + __me = _VSTD::copy(__sym.begin(), __sym.end(), __me); + break; + case money_base::value: + { + // remember start of value so we can reverse it + char_type* __t = __me; + // find beginning of digits + if (__neg) + ++__db; + // find end of digits + const char_type* __d; + for (__d = __db; __d < __de; ++__d) + if (!__ct.is(ctype_base::digit, *__d)) + break; + // print fractional part + if (__fd > 0) + { + int __f; + for (__f = __fd; __d > __db && __f > 0; --__f) + *__me++ = *--__d; + char_type __z = __f > 0 ? __ct.widen('0') : char_type(); + for (; __f > 0; --__f) + *__me++ = __z; + *__me++ = __dp; + } + // print units part + if (__d == __db) + { + *__me++ = __ct.widen('0'); + } + else + { + unsigned __ng = 0; + unsigned __ig = 0; + unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max() + : static_cast<unsigned>(__grp[__ig]); + while (__d != __db) + { + if (__ng == __gl) + { + *__me++ = __ts; + __ng = 0; + if (++__ig < __grp.size()) + __gl = __grp[__ig] == numeric_limits<char>::max() ? + numeric_limits<unsigned>::max() : + static_cast<unsigned>(__grp[__ig]); + } + *__me++ = *--__d; + ++__ng; + } + } + // reverse it + reverse(__t, __me); + } + break; + } + } + // print rest of sign, if any + if (__sn.size() > 1) + __me = _VSTD::copy(__sn.begin()+1, __sn.end(), __me); + // set alignment + if ((__flags & ios_base::adjustfield) == ios_base::left) + __mi = __me; + else if ((__flags & ios_base::adjustfield) != ios_base::internal) + __mi = __mb; +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>) + +template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > +class _LIBCPP_TEMPLATE_VIS money_put + : public locale::facet, + private __money_put<_CharT> +{ +public: + typedef _CharT char_type; + typedef _OutputIterator iter_type; + typedef basic_string<char_type> string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit money_put(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, + long double __units) const + { + return do_put(__s, __intl, __iob, __fl, __units); + } + + _LIBCPP_INLINE_VISIBILITY + iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, + const string_type& __digits) const + { + return do_put(__s, __intl, __iob, __fl, __digits); + } + + static locale::id id; + +protected: + _LIBCPP_INLINE_VISIBILITY + ~money_put() {} + + virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, + char_type __fl, long double __units) const; + virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, + char_type __fl, const string_type& __digits) const; +}; + +template <class _CharT, class _OutputIterator> +locale::id +money_put<_CharT, _OutputIterator>::id; + +template <class _CharT, class _OutputIterator> +_OutputIterator +money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, + ios_base& __iob, char_type __fl, + long double __units) const +{ + // convert to char + const size_t __bs = 100; + char __buf[__bs]; + char* __bb = __buf; + char_type __digits[__bs]; + char_type* __db = __digits; + size_t __n = static_cast<size_t>(snprintf(__bb, __bs, "%.0Lf", __units)); + unique_ptr<char, void(*)(void*)> __hn(0, free); + unique_ptr<char_type, void(*)(void*)> __hd(0, free); + // secure memory for digit storage + if (__n > __bs-1) + { + __n = static_cast<size_t>(__libcpp_asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units)); + if (__bb == 0) + __throw_bad_alloc(); + __hn.reset(__bb); + __hd.reset((char_type*)malloc(__n * sizeof(char_type))); + if (__hd == nullptr) + __throw_bad_alloc(); + __db = __hd.get(); + } + // gather info + locale __loc = __iob.getloc(); + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); + __ct.widen(__bb, __bb + __n, __db); + bool __neg = __n > 0 && __bb[0] == '-'; + money_base::pattern __pat; + char_type __dp; + char_type __ts; + string __grp; + string_type __sym; + string_type __sn; + int __fd; + this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); + // secure memory for formatting + char_type __mbuf[__bs]; + char_type* __mb = __mbuf; + unique_ptr<char_type, void(*)(void*)> __hw(0, free); + size_t __exn = static_cast<int>(__n) > __fd ? + (__n - static_cast<size_t>(__fd)) * 2 + __sn.size() + + __sym.size() + static_cast<size_t>(__fd) + 1 + : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2; + if (__exn > __bs) + { + __hw.reset((char_type*)malloc(__exn * sizeof(char_type))); + __mb = __hw.get(); + if (__mb == 0) + __throw_bad_alloc(); + } + // format + char_type* __mi; + char_type* __me; + this->__format(__mb, __mi, __me, __iob.flags(), + __db, __db + __n, __ct, + __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); + return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); +} + +template <class _CharT, class _OutputIterator> +_OutputIterator +money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, + ios_base& __iob, char_type __fl, + const string_type& __digits) const +{ + // gather info + locale __loc = __iob.getloc(); + const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); + bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-'); + money_base::pattern __pat; + char_type __dp; + char_type __ts; + string __grp; + string_type __sym; + string_type __sn; + int __fd; + this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); + // secure memory for formatting + char_type __mbuf[100]; + char_type* __mb = __mbuf; + unique_ptr<char_type, void(*)(void*)> __h(0, free); + size_t __exn = static_cast<int>(__digits.size()) > __fd ? + (__digits.size() - static_cast<size_t>(__fd)) * 2 + + __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 1 + : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2; + if (__exn > 100) + { + __h.reset((char_type*)malloc(__exn * sizeof(char_type))); + __mb = __h.get(); + if (__mb == 0) + __throw_bad_alloc(); + } + // format + char_type* __mi; + char_type* __me; + this->__format(__mb, __mi, __me, __iob.flags(), + __digits.data(), __digits.data() + __digits.size(), __ct, + __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); + return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>) + +// messages + +class _LIBCPP_TYPE_VIS messages_base +{ +public: + typedef ptrdiff_t catalog; + + _LIBCPP_INLINE_VISIBILITY messages_base() {} +}; + +template <class _CharT> +class _LIBCPP_TEMPLATE_VIS messages + : public locale::facet, + public messages_base +{ +public: + typedef _CharT char_type; + typedef basic_string<_CharT> string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit messages(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + catalog open(const basic_string<char>& __nm, const locale& __loc) const + { + return do_open(__nm, __loc); + } + + _LIBCPP_INLINE_VISIBILITY + string_type get(catalog __c, int __set, int __msgid, + const string_type& __dflt) const + { + return do_get(__c, __set, __msgid, __dflt); + } + + _LIBCPP_INLINE_VISIBILITY + void close(catalog __c) const + { + do_close(__c); + } + + static locale::id id; + +protected: + _LIBCPP_INLINE_VISIBILITY + ~messages() {} + + virtual catalog do_open(const basic_string<char>&, const locale&) const; + virtual string_type do_get(catalog, int __set, int __msgid, + const string_type& __dflt) const; + virtual void do_close(catalog) const; +}; + +template <class _CharT> +locale::id +messages<_CharT>::id; + +template <class _CharT> +typename messages<_CharT>::catalog +messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const +{ +#ifdef _LIBCPP_HAS_CATOPEN + catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE); + if (__cat != -1) + __cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1)); + return __cat; +#else // !_LIBCPP_HAS_CATOPEN + _LIBCPP_UNUSED_VAR(__nm); + return -1; +#endif // _LIBCPP_HAS_CATOPEN +} + +template <class _CharT> +typename messages<_CharT>::string_type +messages<_CharT>::do_get(catalog __c, int __set, int __msgid, + const string_type& __dflt) const +{ +#ifdef _LIBCPP_HAS_CATOPEN + string __ndflt; + __narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt), + __dflt.c_str(), + __dflt.c_str() + __dflt.size()); + if (__c != -1) + __c <<= 1; + nl_catd __cat = (nl_catd)__c; + char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str()); + string_type __w; + __widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w), + __n, __n + strlen(__n)); + return __w; +#else // !_LIBCPP_HAS_CATOPEN + _LIBCPP_UNUSED_VAR(__c); + _LIBCPP_UNUSED_VAR(__set); + _LIBCPP_UNUSED_VAR(__msgid); + return __dflt; +#endif // _LIBCPP_HAS_CATOPEN +} + +template <class _CharT> +void +messages<_CharT>::do_close(catalog __c) const +{ +#ifdef _LIBCPP_HAS_CATOPEN + if (__c != -1) + __c <<= 1; + nl_catd __cat = (nl_catd)__c; + catclose(__cat); +#else // !_LIBCPP_HAS_CATOPEN + _LIBCPP_UNUSED_VAR(__c); +#endif // _LIBCPP_HAS_CATOPEN +} + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>) + +template <class _CharT> +class _LIBCPP_TEMPLATE_VIS messages_byname + : public messages<_CharT> +{ +public: + typedef messages_base::catalog catalog; + typedef basic_string<_CharT> string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit messages_byname(const char*, size_t __refs = 0) + : messages<_CharT>(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + explicit messages_byname(const string&, size_t __refs = 0) + : messages<_CharT>(__refs) {} + +protected: + _LIBCPP_INLINE_VISIBILITY + ~messages_byname() {} +}; + +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>) + +template<class _Codecvt, class _Elem = wchar_t, + class _Wide_alloc = allocator<_Elem>, + class _Byte_alloc = allocator<char> > +class _LIBCPP_TEMPLATE_VIS wstring_convert +{ +public: + typedef basic_string<char, char_traits<char>, _Byte_alloc> byte_string; + typedef basic_string<_Elem, char_traits<_Elem>, _Wide_alloc> wide_string; + typedef typename _Codecvt::state_type state_type; + typedef typename wide_string::traits_type::int_type int_type; + +private: + byte_string __byte_err_string_; + wide_string __wide_err_string_; + _Codecvt* __cvtptr_; + state_type __cvtstate_; + size_t __cvtcount_; + + wstring_convert(const wstring_convert& __wc); + wstring_convert& operator=(const wstring_convert& __wc); +public: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(_Codecvt* __pcvt = new _Codecvt); + _LIBCPP_INLINE_VISIBILITY + wstring_convert(_Codecvt* __pcvt, state_type __state); + _LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(const byte_string& __byte_err, + const wide_string& __wide_err = wide_string()); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + wstring_convert(wstring_convert&& __wc); +#endif + ~wstring_convert(); + + _LIBCPP_INLINE_VISIBILITY + wide_string from_bytes(char __byte) + {return from_bytes(&__byte, &__byte+1);} + _LIBCPP_INLINE_VISIBILITY + wide_string from_bytes(const char* __ptr) + {return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));} + _LIBCPP_INLINE_VISIBILITY + wide_string from_bytes(const byte_string& __str) + {return from_bytes(__str.data(), __str.data() + __str.size());} + wide_string from_bytes(const char* __first, const char* __last); + + _LIBCPP_INLINE_VISIBILITY + byte_string to_bytes(_Elem __wchar) + {return to_bytes(&__wchar, &__wchar+1);} + _LIBCPP_INLINE_VISIBILITY + byte_string to_bytes(const _Elem* __wptr) + {return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));} + _LIBCPP_INLINE_VISIBILITY + byte_string to_bytes(const wide_string& __wstr) + {return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());} + byte_string to_bytes(const _Elem* __first, const _Elem* __last); + + _LIBCPP_INLINE_VISIBILITY + size_t converted() const _NOEXCEPT {return __cvtcount_;} + _LIBCPP_INLINE_VISIBILITY + state_type state() const {return __cvtstate_;} +}; + +template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> +inline +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + wstring_convert(_Codecvt* __pcvt) + : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) +{ +} + +template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> +inline +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + wstring_convert(_Codecvt* __pcvt, state_type __state) + : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) +{ +} + +template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err) + : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), + __cvtstate_(), __cvtcount_(0) +{ + __cvtptr_ = new _Codecvt; +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> +inline +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + wstring_convert(wstring_convert&& __wc) + : __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)), + __wide_err_string_(_VSTD::move(__wc.__wide_err_string_)), + __cvtptr_(__wc.__cvtptr_), + __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtcount_) +{ + __wc.__cvtptr_ = nullptr; +} + +#endif // _LIBCPP_CXX03_LANG + +template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::~wstring_convert() +{ + delete __cvtptr_; +} + +template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> +typename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::wide_string +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + from_bytes(const char* __frm, const char* __frm_end) +{ + __cvtcount_ = 0; + if (__cvtptr_ != nullptr) + { + wide_string __ws(2*(__frm_end - __frm), _Elem()); + if (__frm != __frm_end) + __ws.resize(__ws.capacity()); + codecvt_base::result __r = codecvt_base::ok; + state_type __st = __cvtstate_; + if (__frm != __frm_end) + { + _Elem* __to = &__ws[0]; + _Elem* __to_end = __to + __ws.size(); + const char* __frm_nxt; + do + { + _Elem* __to_nxt; + __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, + __to, __to_end, __to_nxt); + __cvtcount_ += __frm_nxt - __frm; + if (__frm_nxt == __frm) + { + __r = codecvt_base::error; + } + else if (__r == codecvt_base::noconv) + { + __ws.resize(__to - &__ws[0]); + // This only gets executed if _Elem is char + __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end); + __frm = __frm_nxt; + __r = codecvt_base::ok; + } + else if (__r == codecvt_base::ok) + { + __ws.resize(__to_nxt - &__ws[0]); + __frm = __frm_nxt; + } + else if (__r == codecvt_base::partial) + { + ptrdiff_t __s = __to_nxt - &__ws[0]; + __ws.resize(2 * __s); + __to = &__ws[0] + __s; + __to_end = &__ws[0] + __ws.size(); + __frm = __frm_nxt; + } + } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); + } + if (__r == codecvt_base::ok) + return __ws; + } + + if (__wide_err_string_.empty()) + __throw_range_error("wstring_convert: from_bytes error"); + + return __wide_err_string_; +} + +template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> +typename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::byte_string +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + to_bytes(const _Elem* __frm, const _Elem* __frm_end) +{ + __cvtcount_ = 0; + if (__cvtptr_ != nullptr) + { + byte_string __bs(2*(__frm_end - __frm), char()); + if (__frm != __frm_end) + __bs.resize(__bs.capacity()); + codecvt_base::result __r = codecvt_base::ok; + state_type __st = __cvtstate_; + if (__frm != __frm_end) + { + char* __to = &__bs[0]; + char* __to_end = __to + __bs.size(); + const _Elem* __frm_nxt; + do + { + char* __to_nxt; + __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, + __to, __to_end, __to_nxt); + __cvtcount_ += __frm_nxt - __frm; + if (__frm_nxt == __frm) + { + __r = codecvt_base::error; + } + else if (__r == codecvt_base::noconv) + { + __bs.resize(__to - &__bs[0]); + // This only gets executed if _Elem is char + __bs.append((const char*)__frm, (const char*)__frm_end); + __frm = __frm_nxt; + __r = codecvt_base::ok; + } + else if (__r == codecvt_base::ok) + { + __bs.resize(__to_nxt - &__bs[0]); + __frm = __frm_nxt; + } + else if (__r == codecvt_base::partial) + { + ptrdiff_t __s = __to_nxt - &__bs[0]; + __bs.resize(2 * __s); + __to = &__bs[0] + __s; + __to_end = &__bs[0] + __bs.size(); + __frm = __frm_nxt; + } + } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); + } + if (__r == codecvt_base::ok) + { + size_t __s = __bs.size(); + __bs.resize(__bs.capacity()); + char* __to = &__bs[0] + __s; + char* __to_end = __to + __bs.size(); + do + { + char* __to_nxt; + __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt); + if (__r == codecvt_base::noconv) + { + __bs.resize(__to - &__bs[0]); + __r = codecvt_base::ok; + } + else if (__r == codecvt_base::ok) + { + __bs.resize(__to_nxt - &__bs[0]); + } + else if (__r == codecvt_base::partial) + { + ptrdiff_t __sp = __to_nxt - &__bs[0]; + __bs.resize(2 * __sp); + __to = &__bs[0] + __sp; + __to_end = &__bs[0] + __bs.size(); + } + } while (__r == codecvt_base::partial); + if (__r == codecvt_base::ok) + return __bs; + } + } + + if (__byte_err_string_.empty()) + __throw_range_error("wstring_convert: to_bytes error"); + + return __byte_err_string_; +} + +template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> > +class _LIBCPP_TEMPLATE_VIS wbuffer_convert + : public basic_streambuf<_Elem, _Tr> +{ +public: + // types: + typedef _Elem char_type; + typedef _Tr traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef typename _Codecvt::state_type state_type; + +private: + char* __extbuf_; + const char* __extbufnext_; + const char* __extbufend_; + char __extbuf_min_[8]; + size_t __ebs_; + char_type* __intbuf_; + size_t __ibs_; + streambuf* __bufptr_; + _Codecvt* __cv_; + state_type __st_; + ios_base::openmode __cm_; + bool __owns_eb_; + bool __owns_ib_; + bool __always_noconv_; + + wbuffer_convert(const wbuffer_convert&); + wbuffer_convert& operator=(const wbuffer_convert&); +public: + _LIBCPP_EXPLICIT_AFTER_CXX11 wbuffer_convert(streambuf* __bytebuf = 0, + _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type()); + ~wbuffer_convert(); + + _LIBCPP_INLINE_VISIBILITY + streambuf* rdbuf() const {return __bufptr_;} + _LIBCPP_INLINE_VISIBILITY + streambuf* rdbuf(streambuf* __bytebuf) + { + streambuf* __r = __bufptr_; + __bufptr_ = __bytebuf; + return __r; + } + + _LIBCPP_INLINE_VISIBILITY + state_type state() const {return __st_;} + +protected: + virtual int_type underflow(); + virtual int_type pbackfail(int_type __c = traits_type::eof()); + virtual int_type overflow (int_type __c = traits_type::eof()); + virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, + streamsize __n); + virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __wch = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type __sp, + ios_base::openmode __wch = ios_base::in | ios_base::out); + virtual int sync(); + +private: + bool __read_mode(); + void __write_mode(); + wbuffer_convert* __close(); +}; + +template <class _Codecvt, class _Elem, class _Tr> +wbuffer_convert<_Codecvt, _Elem, _Tr>:: + wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state) + : __extbuf_(0), + __extbufnext_(0), + __extbufend_(0), + __ebs_(0), + __intbuf_(0), + __ibs_(0), + __bufptr_(__bytebuf), + __cv_(__pcvt), + __st_(__state), + __cm_(0), + __owns_eb_(false), + __owns_ib_(false), + __always_noconv_(__cv_ ? __cv_->always_noconv() : false) +{ + setbuf(0, 4096); +} + +template <class _Codecvt, class _Elem, class _Tr> +wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() +{ + __close(); + delete __cv_; + if (__owns_eb_) + delete [] __extbuf_; + if (__owns_ib_) + delete [] __intbuf_; +} + +template <class _Codecvt, class _Elem, class _Tr> +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() +{ + if (__cv_ == 0 || __bufptr_ == 0) + return traits_type::eof(); + bool __initial = __read_mode(); + char_type __1buf; + if (this->gptr() == 0) + this->setg(&__1buf, &__1buf+1, &__1buf+1); + const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4); + int_type __c = traits_type::eof(); + if (this->gptr() == this->egptr()) + { + memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); + if (__always_noconv_) + { + streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz); + __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb); + if (__nmemb != 0) + { + this->setg(this->eback(), + this->eback() + __unget_sz, + this->eback() + __unget_sz + __nmemb); + __c = *this->gptr(); + } + } + else + { + _LIBCPP_ASSERT(!(__extbufnext_ == NULL && (__extbufend_ != __extbufnext_)), "underflow moving from NULL" ); + if (__extbufend_ != __extbufnext_) + memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); + __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); + __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); + streamsize __nmemb = _VSTD::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz), + static_cast<streamsize>(__extbufend_ - __extbufnext_)); + codecvt_base::result __r; + // FIXME: Do we ever need to restore the state here? + //state_type __svs = __st_; + streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb); + if (__nr != 0) + { + __extbufend_ = __extbufnext_ + __nr; + char_type* __inext; + __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, + this->eback() + __unget_sz, + this->egptr(), __inext); + if (__r == codecvt_base::noconv) + { + this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, + (char_type*) const_cast<char *>(__extbufend_)); + __c = *this->gptr(); + } + else if (__inext != this->eback() + __unget_sz) + { + this->setg(this->eback(), this->eback() + __unget_sz, __inext); + __c = *this->gptr(); + } + } + } + } + else + __c = *this->gptr(); + if (this->eback() == &__1buf) + this->setg(0, 0, 0); + return __c; +} + +template <class _Codecvt, class _Elem, class _Tr> +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) +{ + if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr()) + { + if (traits_type::eq_int_type(__c, traits_type::eof())) + { + this->gbump(-1); + return traits_type::not_eof(__c); + } + if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) + { + this->gbump(-1); + *this->gptr() = traits_type::to_char_type(__c); + return __c; + } + } + return traits_type::eof(); +} + +template <class _Codecvt, class _Elem, class _Tr> +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) +{ + if (__cv_ == 0 || __bufptr_ == 0) + return traits_type::eof(); + __write_mode(); + char_type __1buf; + char_type* __pb_save = this->pbase(); + char_type* __epb_save = this->epptr(); + if (!traits_type::eq_int_type(__c, traits_type::eof())) + { + if (this->pptr() == 0) + this->setp(&__1buf, &__1buf+1); + *this->pptr() = traits_type::to_char_type(__c); + this->pbump(1); + } + if (this->pptr() != this->pbase()) + { + if (__always_noconv_) + { + streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase()); + if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) + return traits_type::eof(); + } + else + { + char* __extbe = __extbuf_; + codecvt_base::result __r; + do + { + const char_type* __e; + __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, + __extbuf_, __extbuf_ + __ebs_, __extbe); + if (__e == this->pbase()) + return traits_type::eof(); + if (__r == codecvt_base::noconv) + { + streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); + if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) + return traits_type::eof(); + } + else if (__r == codecvt_base::ok || __r == codecvt_base::partial) + { + streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_); + if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) + return traits_type::eof(); + if (__r == codecvt_base::partial) + { + this->setp(const_cast<char_type *>(__e), this->pptr()); + this->__pbump(this->epptr() - this->pbase()); + } + } + else + return traits_type::eof(); + } while (__r == codecvt_base::partial); + } + this->setp(__pb_save, __epb_save); + } + return traits_type::not_eof(__c); +} + +template <class _Codecvt, class _Elem, class _Tr> +basic_streambuf<_Elem, _Tr>* +wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n) +{ + this->setg(0, 0, 0); + this->setp(0, 0); + if (__owns_eb_) + delete [] __extbuf_; + if (__owns_ib_) + delete [] __intbuf_; + __ebs_ = __n; + if (__ebs_ > sizeof(__extbuf_min_)) + { + if (__always_noconv_ && __s) + { + __extbuf_ = (char*)__s; + __owns_eb_ = false; + } + else + { + __extbuf_ = new char[__ebs_]; + __owns_eb_ = true; + } + } + else + { + __extbuf_ = __extbuf_min_; + __ebs_ = sizeof(__extbuf_min_); + __owns_eb_ = false; + } + if (!__always_noconv_) + { + __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_)); + if (__s && __ibs_ >= sizeof(__extbuf_min_)) + { + __intbuf_ = __s; + __owns_ib_ = false; + } + else + { + __intbuf_ = new char_type[__ibs_]; + __owns_ib_ = true; + } + } + else + { + __ibs_ = 0; + __intbuf_ = 0; + __owns_ib_ = false; + } + return this; +} + +template <class _Codecvt, class _Elem, class _Tr> +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __om) +{ + int __width = __cv_->encoding(); + if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync()) + return pos_type(off_type(-1)); + // __width > 0 || __off == 0, now check __way + if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end) + return pos_type(off_type(-1)); + pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om); + __r.state(__st_); + return __r; +} + +template <class _Codecvt, class _Elem, class _Tr> +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) +{ + if (__cv_ == 0 || __bufptr_ == 0 || sync()) + return pos_type(off_type(-1)); + if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1))) + return pos_type(off_type(-1)); + return __sp; +} + +template <class _Codecvt, class _Elem, class _Tr> +int +wbuffer_convert<_Codecvt, _Elem, _Tr>::sync() +{ + if (__cv_ == 0 || __bufptr_ == 0) + return 0; + if (__cm_ & ios_base::out) + { + if (this->pptr() != this->pbase()) + if (overflow() == traits_type::eof()) + return -1; + codecvt_base::result __r; + do + { + char* __extbe; + __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); + streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_); + if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) + return -1; + } while (__r == codecvt_base::partial); + if (__r == codecvt_base::error) + return -1; + if (__bufptr_->pubsync()) + return -1; + } + else if (__cm_ & ios_base::in) + { + off_type __c; + if (__always_noconv_) + __c = this->egptr() - this->gptr(); + else + { + int __width = __cv_->encoding(); + __c = __extbufend_ - __extbufnext_; + if (__width > 0) + __c += __width * (this->egptr() - this->gptr()); + else + { + if (this->gptr() != this->egptr()) + { + reverse(this->gptr(), this->egptr()); + codecvt_base::result __r; + const char_type* __e = this->gptr(); + char* __extbe; + do + { + __r = __cv_->out(__st_, __e, this->egptr(), __e, + __extbuf_, __extbuf_ + __ebs_, __extbe); + switch (__r) + { + case codecvt_base::noconv: + __c += this->egptr() - this->gptr(); + break; + case codecvt_base::ok: + case codecvt_base::partial: + __c += __extbe - __extbuf_; + break; + default: + return -1; + } + } while (__r == codecvt_base::partial); + } + } + } + if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1))) + return -1; + this->setg(0, 0, 0); + __cm_ = 0; + } + return 0; +} + +template <class _Codecvt, class _Elem, class _Tr> +bool +wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode() +{ + if (!(__cm_ & ios_base::in)) + { + this->setp(0, 0); + if (__always_noconv_) + this->setg((char_type*)__extbuf_, + (char_type*)__extbuf_ + __ebs_, + (char_type*)__extbuf_ + __ebs_); + else + this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); + __cm_ = ios_base::in; + return true; + } + return false; +} + +template <class _Codecvt, class _Elem, class _Tr> +void +wbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode() +{ + if (!(__cm_ & ios_base::out)) + { + this->setg(0, 0, 0); + if (__ebs_ > sizeof(__extbuf_min_)) + { + if (__always_noconv_) + this->setp((char_type*)__extbuf_, + (char_type*)__extbuf_ + (__ebs_ - 1)); + else + this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); + } + else + this->setp(0, 0); + __cm_ = ios_base::out; + } +} + +template <class _Codecvt, class _Elem, class _Tr> +wbuffer_convert<_Codecvt, _Elem, _Tr>* +wbuffer_convert<_Codecvt, _Elem, _Tr>::__close() +{ + wbuffer_convert* __rt = 0; + if (__cv_ != 0 && __bufptr_ != 0) + { + __rt = this; + if ((__cm_ & ios_base::out) && sync()) + __rt = 0; + } + return __rt; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_LOCALE diff --git a/android/x86/include/v8/libc++/locale.h b/android/x86/include/v8/libc++/locale.h new file mode 100755 index 00000000..a21ee385 --- /dev/null +++ b/android/x86/include/v8/libc++/locale.h @@ -0,0 +1,44 @@ +// -*- C++ -*- +//===---------------------------- locale.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LOCALE_H +#define _LIBCPP_LOCALE_H + +/* + locale.h synopsis + +Macros: + + LC_ALL + LC_COLLATE + LC_CTYPE + LC_MONETARY + LC_NUMERIC + LC_TIME + +Types: + + lconv + +Functions: + + setlocale + localeconv + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <locale.h> + +#endif // _LIBCPP_LOCALE_H diff --git a/android/x86/include/v8/libc++/map b/android/x86/include/v8/libc++/map new file mode 100755 index 00000000..a8bf448d --- /dev/null +++ b/android/x86/include/v8/libc++/map @@ -0,0 +1,2181 @@ +// -*- C++ -*- +//===----------------------------- map ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_MAP +#define _LIBCPP_MAP + +/* + + map synopsis + +namespace std +{ + +template <class Key, class T, class Compare = less<Key>, + class Allocator = allocator<pair<const Key, T>>> +class map +{ +public: + // types: + typedef Key key_type; + typedef T mapped_type; + typedef pair<const key_type, mapped_type> value_type; + typedef Compare key_compare; + typedef Allocator allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + typedef unspecified node_type; // C++17 + typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17 + + class value_compare + : public binary_function<value_type, value_type, bool> + { + friend class map; + protected: + key_compare comp; + + value_compare(key_compare c); + public: + bool operator()(const value_type& x, const value_type& y) const; + }; + + // construct/copy/destroy: + map() + noexcept( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_default_constructible<key_compare>::value && + is_nothrow_copy_constructible<key_compare>::value); + explicit map(const key_compare& comp); + map(const key_compare& comp, const allocator_type& a); + template <class InputIterator> + map(InputIterator first, InputIterator last, + const key_compare& comp = key_compare()); + template <class InputIterator> + map(InputIterator first, InputIterator last, + const key_compare& comp, const allocator_type& a); + map(const map& m); + map(map&& m) + noexcept( + is_nothrow_move_constructible<allocator_type>::value && + is_nothrow_move_constructible<key_compare>::value); + explicit map(const allocator_type& a); + map(const map& m, const allocator_type& a); + map(map&& m, const allocator_type& a); + map(initializer_list<value_type> il, const key_compare& comp = key_compare()); + map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); + template <class InputIterator> + map(InputIterator first, InputIterator last, const allocator_type& a) + : map(first, last, Compare(), a) {} // C++14 + map(initializer_list<value_type> il, const allocator_type& a) + : map(il, Compare(), a) {} // C++14 + ~map(); + + map& operator=(const map& m); + map& operator=(map&& m) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value && + is_nothrow_move_assignable<key_compare>::value); + map& operator=(initializer_list<value_type> il); + + // iterators: + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + // element access: + mapped_type& operator[](const key_type& k); + mapped_type& operator[](key_type&& k); + + mapped_type& at(const key_type& k); + const mapped_type& at(const key_type& k) const; + + // modifiers: + template <class... Args> + pair<iterator, bool> emplace(Args&&... args); + template <class... Args> + iterator emplace_hint(const_iterator position, Args&&... args); + pair<iterator, bool> insert(const value_type& v); + pair<iterator, bool> insert( value_type&& v); // C++17 + template <class P> + pair<iterator, bool> insert(P&& p); + iterator insert(const_iterator position, const value_type& v); + iterator insert(const_iterator position, value_type&& v); // C++17 + template <class P> + iterator insert(const_iterator position, P&& p); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + void insert(initializer_list<value_type> il); + + node_type extract(const_iterator position); // C++17 + node_type extract(const key_type& x); // C++17 + insert_return_type insert(node_type&& nh); // C++17 + iterator insert(const_iterator hint, node_type&& nh); // C++17 + + template <class... Args> + pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17 + template <class... Args> + pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17 + template <class... Args> + iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17 + template <class... Args> + iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17 + template <class M> + pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17 + template <class M> + pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17 + template <class M> + iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17 + template <class M> + iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17 + + iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + template<class C2> + void merge(map<Key, T, C2, Allocator>& source); // C++17 + template<class C2> + void merge(map<Key, T, C2, Allocator>&& source); // C++17 + template<class C2> + void merge(multimap<Key, T, C2, Allocator>& source); // C++17 + template<class C2> + void merge(multimap<Key, T, C2, Allocator>&& source); // C++17 + + void swap(map& m) + noexcept(allocator_traits<allocator_type>::is_always_equal::value && + is_nothrow_swappable<key_compare>::value); // C++17 + + // observers: + allocator_type get_allocator() const noexcept; + key_compare key_comp() const; + value_compare value_comp() const; + + // map operations: + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + template<typename K> + iterator find(const K& x); // C++14 + template<typename K> + const_iterator find(const K& x) const; // C++14 + template<typename K> + size_type count(const K& x) const; // C++14 + + size_type count(const key_type& k) const; + iterator lower_bound(const key_type& k); + const_iterator lower_bound(const key_type& k) const; + template<typename K> + iterator lower_bound(const K& x); // C++14 + template<typename K> + const_iterator lower_bound(const K& x) const; // C++14 + + iterator upper_bound(const key_type& k); + const_iterator upper_bound(const key_type& k) const; + template<typename K> + iterator upper_bound(const K& x); // C++14 + template<typename K> + const_iterator upper_bound(const K& x) const; // C++14 + + pair<iterator,iterator> equal_range(const key_type& k); + pair<const_iterator,const_iterator> equal_range(const key_type& k) const; + template<typename K> + pair<iterator,iterator> equal_range(const K& x); // C++14 + template<typename K> + pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14 +}; + +template <class Key, class T, class Compare, class Allocator> +bool +operator==(const map<Key, T, Compare, Allocator>& x, + const map<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator< (const map<Key, T, Compare, Allocator>& x, + const map<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator!=(const map<Key, T, Compare, Allocator>& x, + const map<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator> (const map<Key, T, Compare, Allocator>& x, + const map<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator>=(const map<Key, T, Compare, Allocator>& x, + const map<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator<=(const map<Key, T, Compare, Allocator>& x, + const map<Key, T, Compare, Allocator>& y); + +// specialized algorithms: +template <class Key, class T, class Compare, class Allocator> +void +swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y) + noexcept(noexcept(x.swap(y))); + +template <class Key, class T, class Compare, class Allocator, class Predicate> + void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20 + + +template <class Key, class T, class Compare = less<Key>, + class Allocator = allocator<pair<const Key, T>>> +class multimap +{ +public: + // types: + typedef Key key_type; + typedef T mapped_type; + typedef pair<const key_type,mapped_type> value_type; + typedef Compare key_compare; + typedef Allocator allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + typedef unspecified node_type; // C++17 + + class value_compare + : public binary_function<value_type,value_type,bool> + { + friend class multimap; + protected: + key_compare comp; + value_compare(key_compare c); + public: + bool operator()(const value_type& x, const value_type& y) const; + }; + + // construct/copy/destroy: + multimap() + noexcept( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_default_constructible<key_compare>::value && + is_nothrow_copy_constructible<key_compare>::value); + explicit multimap(const key_compare& comp); + multimap(const key_compare& comp, const allocator_type& a); + template <class InputIterator> + multimap(InputIterator first, InputIterator last, const key_compare& comp); + template <class InputIterator> + multimap(InputIterator first, InputIterator last, const key_compare& comp, + const allocator_type& a); + multimap(const multimap& m); + multimap(multimap&& m) + noexcept( + is_nothrow_move_constructible<allocator_type>::value && + is_nothrow_move_constructible<key_compare>::value); + explicit multimap(const allocator_type& a); + multimap(const multimap& m, const allocator_type& a); + multimap(multimap&& m, const allocator_type& a); + multimap(initializer_list<value_type> il, const key_compare& comp = key_compare()); + multimap(initializer_list<value_type> il, const key_compare& comp, + const allocator_type& a); + template <class InputIterator> + multimap(InputIterator first, InputIterator last, const allocator_type& a) + : multimap(first, last, Compare(), a) {} // C++14 + multimap(initializer_list<value_type> il, const allocator_type& a) + : multimap(il, Compare(), a) {} // C++14 + ~multimap(); + + multimap& operator=(const multimap& m); + multimap& operator=(multimap&& m) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value && + is_nothrow_move_assignable<key_compare>::value); + multimap& operator=(initializer_list<value_type> il); + + // iterators: + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + // modifiers: + template <class... Args> + iterator emplace(Args&&... args); + template <class... Args> + iterator emplace_hint(const_iterator position, Args&&... args); + iterator insert(const value_type& v); + iterator insert( value_type&& v); // C++17 + template <class P> + iterator insert(P&& p); + iterator insert(const_iterator position, const value_type& v); + iterator insert(const_iterator position, value_type&& v); // C++17 + template <class P> + iterator insert(const_iterator position, P&& p); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + void insert(initializer_list<value_type> il); + + node_type extract(const_iterator position); // C++17 + node_type extract(const key_type& x); // C++17 + iterator insert(node_type&& nh); // C++17 + iterator insert(const_iterator hint, node_type&& nh); // C++17 + + iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + template<class C2> + void merge(multimap<Key, T, C2, Allocator>& source); // C++17 + template<class C2> + void merge(multimap<Key, T, C2, Allocator>&& source); // C++17 + template<class C2> + void merge(map<Key, T, C2, Allocator>& source); // C++17 + template<class C2> + void merge(map<Key, T, C2, Allocator>&& source); // C++17 + + void swap(multimap& m) + noexcept(allocator_traits<allocator_type>::is_always_equal::value && + is_nothrow_swappable<key_compare>::value); // C++17 + + // observers: + allocator_type get_allocator() const noexcept; + key_compare key_comp() const; + value_compare value_comp() const; + + // map operations: + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + template<typename K> + iterator find(const K& x); // C++14 + template<typename K> + const_iterator find(const K& x) const; // C++14 + template<typename K> + size_type count(const K& x) const; // C++14 + + size_type count(const key_type& k) const; + iterator lower_bound(const key_type& k); + const_iterator lower_bound(const key_type& k) const; + template<typename K> + iterator lower_bound(const K& x); // C++14 + template<typename K> + const_iterator lower_bound(const K& x) const; // C++14 + + iterator upper_bound(const key_type& k); + const_iterator upper_bound(const key_type& k) const; + template<typename K> + iterator upper_bound(const K& x); // C++14 + template<typename K> + const_iterator upper_bound(const K& x) const; // C++14 + + pair<iterator,iterator> equal_range(const key_type& k); + pair<const_iterator,const_iterator> equal_range(const key_type& k) const; + template<typename K> + pair<iterator,iterator> equal_range(const K& x); // C++14 + template<typename K> + pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14 +}; + +template <class Key, class T, class Compare, class Allocator> +bool +operator==(const multimap<Key, T, Compare, Allocator>& x, + const multimap<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator< (const multimap<Key, T, Compare, Allocator>& x, + const multimap<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator!=(const multimap<Key, T, Compare, Allocator>& x, + const multimap<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator> (const multimap<Key, T, Compare, Allocator>& x, + const multimap<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator>=(const multimap<Key, T, Compare, Allocator>& x, + const multimap<Key, T, Compare, Allocator>& y); + +template <class Key, class T, class Compare, class Allocator> +bool +operator<=(const multimap<Key, T, Compare, Allocator>& x, + const multimap<Key, T, Compare, Allocator>& y); + +// specialized algorithms: +template <class Key, class T, class Compare, class Allocator> +void +swap(multimap<Key, T, Compare, Allocator>& x, + multimap<Key, T, Compare, Allocator>& y) + noexcept(noexcept(x.swap(y))); + +template <class Key, class T, class Compare, class Allocator, class Predicate> + void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20 + +} // std + +*/ + +#include <__config> +#include <__tree> +#include <__node_handle> +#include <iterator> +#include <memory> +#include <utility> +#include <functional> +#include <initializer_list> +#include <type_traits> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Key, class _CP, class _Compare, + bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value> +class __map_value_compare + : private _Compare +{ +public: + _LIBCPP_INLINE_VISIBILITY + __map_value_compare() + _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) + : _Compare() {} + _LIBCPP_INLINE_VISIBILITY + __map_value_compare(_Compare c) + _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) + : _Compare(c) {} + _LIBCPP_INLINE_VISIBILITY + const _Compare& key_comp() const _NOEXCEPT {return *this;} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _CP& __y) const + {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _Key& __y) const + {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _CP& __y) const + {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);} + void swap(__map_value_compare&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) + { + using _VSTD::swap; + swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y)); + } + +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type + operator () ( const _K2& __x, const _CP& __y ) const + {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);} + + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type + operator () (const _CP& __x, const _K2& __y) const + {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);} +#endif +}; + +template <class _Key, class _CP, class _Compare> +class __map_value_compare<_Key, _CP, _Compare, false> +{ + _Compare comp; + +public: + _LIBCPP_INLINE_VISIBILITY + __map_value_compare() + _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) + : comp() {} + _LIBCPP_INLINE_VISIBILITY + __map_value_compare(_Compare c) + _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) + : comp(c) {} + _LIBCPP_INLINE_VISIBILITY + const _Compare& key_comp() const _NOEXCEPT {return comp;} + + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _CP& __y) const + {return comp(__x.__get_value().first, __y.__get_value().first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _Key& __y) const + {return comp(__x.__get_value().first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _CP& __y) const + {return comp(__x, __y.__get_value().first);} + void swap(__map_value_compare&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) + { + using _VSTD::swap; + swap(comp, __y.comp); + } + +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type + operator () ( const _K2& __x, const _CP& __y ) const + {return comp (__x, __y.__get_value().first);} + + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type + operator () (const _CP& __x, const _K2& __y) const + {return comp (__x.__get_value().first, __y);} +#endif +}; + +template <class _Key, class _CP, class _Compare, bool __b> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x, + __map_value_compare<_Key, _CP, _Compare, __b>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Allocator> +class __map_node_destructor +{ + typedef _Allocator allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + +public: + typedef typename __alloc_traits::pointer pointer; + +private: + allocator_type& __na_; + + __map_node_destructor& operator=(const __map_node_destructor&); + +public: + bool __first_constructed; + bool __second_constructed; + + _LIBCPP_INLINE_VISIBILITY + explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT + : __na_(__na), + __first_constructed(false), + __second_constructed(false) + {} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT + : __na_(__x.__na_), + __first_constructed(__x.__value_constructed), + __second_constructed(__x.__value_constructed) + { + __x.__value_constructed = false; + } +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + if (__second_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second)); + if (__first_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } +}; + +template <class _Key, class _Tp, class _Compare, class _Allocator> + class map; +template <class _Key, class _Tp, class _Compare, class _Allocator> + class multimap; +template <class _TreeIterator> class __map_const_iterator; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Key, class _Tp> +struct __value_type +{ + typedef _Key key_type; + typedef _Tp mapped_type; + typedef pair<const key_type, mapped_type> value_type; + typedef pair<key_type&, mapped_type&> __nc_ref_pair_type; + typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type; + +private: + value_type __cc; + +public: + _LIBCPP_INLINE_VISIBILITY + value_type& __get_value() + { +#if _LIBCPP_STD_VER > 14 + return *_VSTD::launder(_VSTD::addressof(__cc)); +#else + return __cc; +#endif + } + + _LIBCPP_INLINE_VISIBILITY + const value_type& __get_value() const + { +#if _LIBCPP_STD_VER > 14 + return *_VSTD::launder(_VSTD::addressof(__cc)); +#else + return __cc; +#endif + } + + _LIBCPP_INLINE_VISIBILITY + __nc_ref_pair_type __ref() + { + value_type& __v = __get_value(); + return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second); + } + + _LIBCPP_INLINE_VISIBILITY + __nc_rref_pair_type __move() + { + value_type& __v = __get_value(); + return __nc_rref_pair_type( + _VSTD::move(const_cast<key_type&>(__v.first)), + _VSTD::move(__v.second)); + } + + _LIBCPP_INLINE_VISIBILITY + __value_type& operator=(const __value_type& __v) + { + __ref() = __v.__get_value(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __value_type& operator=(__value_type&& __v) + { + __ref() = __v.__move(); + return *this; + } + + template <class _ValueTp, + class = typename enable_if< + __is_same_uncvref<_ValueTp, value_type>::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + __value_type& operator=(_ValueTp&& __v) + { + __ref() = _VSTD::forward<_ValueTp>(__v); + return *this; + } + +private: + __value_type() _LIBCPP_EQUAL_DELETE; + ~__value_type() _LIBCPP_EQUAL_DELETE; + __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE; + __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE; +}; + +#else + +template <class _Key, class _Tp> +struct __value_type +{ + typedef _Key key_type; + typedef _Tp mapped_type; + typedef pair<const key_type, mapped_type> value_type; + +private: + value_type __cc; + +public: + _LIBCPP_INLINE_VISIBILITY + value_type& __get_value() { return __cc; } + _LIBCPP_INLINE_VISIBILITY + const value_type& __get_value() const { return __cc; } + +private: + __value_type(); + __value_type(__value_type const&); + __value_type& operator=(__value_type const&); + ~__value_type(); +}; + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp> +struct __extract_key_value_types; + +template <class _Key, class _Tp> +struct __extract_key_value_types<__value_type<_Key, _Tp> > +{ + typedef _Key const __key_type; + typedef _Tp __mapped_type; +}; + +template <class _TreeIterator> +class _LIBCPP_TEMPLATE_VIS __map_iterator +{ + typedef typename _TreeIterator::_NodeTypes _NodeTypes; + typedef typename _TreeIterator::__pointer_traits __pointer_traits; + + _TreeIterator __i_; + +public: + typedef bidirectional_iterator_tag iterator_category; + typedef typename _NodeTypes::__map_value_type value_type; + typedef typename _TreeIterator::difference_type difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__map_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY + __map_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __i_->__get_value();} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} + + _LIBCPP_INLINE_VISIBILITY + __map_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __map_iterator operator++(int) + { + __map_iterator __t(*this); + ++(*this); + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + __map_iterator& operator--() {--__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __map_iterator operator--(int) + { + __map_iterator __t(*this); + --(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __map_iterator& __x, const __map_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __map_iterator& __x, const __map_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; +}; + +template <class _TreeIterator> +class _LIBCPP_TEMPLATE_VIS __map_const_iterator +{ + typedef typename _TreeIterator::_NodeTypes _NodeTypes; + typedef typename _TreeIterator::__pointer_traits __pointer_traits; + + _TreeIterator __i_; + +public: + typedef bidirectional_iterator_tag iterator_category; + typedef typename _NodeTypes::__map_value_type value_type; + typedef typename _TreeIterator::difference_type difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_map_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator(__map_iterator< + typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT + : __i_(__i.__i_) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __i_->__get_value();} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} + + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator operator++(int) + { + __map_const_iterator __t(*this); + ++(*this); + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator& operator--() {--__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator operator--(int) + { + __map_const_iterator __t(*this); + --(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; +}; + +template <class _Key, class _Tp, class _Compare = less<_Key>, + class _Allocator = allocator<pair<const _Key, _Tp> > > +class _LIBCPP_TEMPLATE_VIS map +{ +public: + // types: + typedef _Key key_type; + typedef _Tp mapped_type; + typedef pair<const key_type, mapped_type> value_type; + typedef _Compare key_compare; + typedef _Allocator allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + + static_assert((is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + + class _LIBCPP_TEMPLATE_VIS value_compare + : public binary_function<value_type, value_type, bool> + { + friend class map; + protected: + key_compare comp; + + _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {} + public: + _LIBCPP_INLINE_VISIBILITY + bool operator()(const value_type& __x, const value_type& __y) const + {return comp(__x.first, __y.first);} + }; + +private: + + typedef _VSTD::__value_type<key_type, mapped_type> __value_type; + typedef __map_value_compare<key_type, __value_type, key_compare> __vc; + typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, + __value_type>::type __allocator_type; + typedef __tree<__value_type, __vc, __allocator_type> __base; + typedef typename __base::__node_traits __node_traits; + typedef allocator_traits<allocator_type> __alloc_traits; + + __base __tree_; + +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef __map_iterator<typename __base::iterator> iterator; + typedef __map_const_iterator<typename __base::const_iterator> const_iterator; + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + +#if _LIBCPP_STD_VER > 14 + typedef __map_node_handle<typename __base::__node, allocator_type> node_type; + typedef __insert_return_type<iterator, node_type> insert_return_type; +#endif + + template <class _Key2, class _Value2, class _Comp2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS map; + template <class _Key2, class _Value2, class _Comp2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS multimap; + + _LIBCPP_INLINE_VISIBILITY + map() + _NOEXCEPT_( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_default_constructible<key_compare>::value && + is_nothrow_copy_constructible<key_compare>::value) + : __tree_(__vc(key_compare())) {} + + _LIBCPP_INLINE_VISIBILITY + explicit map(const key_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_copy_constructible<key_compare>::value) + : __tree_(__vc(__comp)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit map(const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + map(_InputIterator __f, _InputIterator __l, + const key_compare& __comp = key_compare()) + : __tree_(__vc(__comp)) + { + insert(__f, __l); + } + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + map(_InputIterator __f, _InputIterator __l, + const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), typename __base::allocator_type(__a)) + { + insert(__f, __l); + } + +#if _LIBCPP_STD_VER > 11 + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + map(_InputIterator __f, _InputIterator __l, const allocator_type& __a) + : map(__f, __l, key_compare(), __a) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + map(const map& __m) + : __tree_(__m.__tree_) + { + insert(__m.begin(), __m.end()); + } + + _LIBCPP_INLINE_VISIBILITY + map& operator=(const map& __m) + { +#ifndef _LIBCPP_CXX03_LANG + __tree_ = __m.__tree_; +#else + if (this != &__m) { + __tree_.clear(); + __tree_.value_comp() = __m.__tree_.value_comp(); + __tree_.__copy_assign_alloc(__m.__tree_); + insert(__m.begin(), __m.end()); + } +#endif + return *this; + } + +#ifndef _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + map(map&& __m) + _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) + : __tree_(_VSTD::move(__m.__tree_)) + { + } + + map(map&& __m, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + map& operator=(map&& __m) + _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) + { + __tree_ = _VSTD::move(__m.__tree_); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + map(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) + : __tree_(__vc(__comp)) + { + insert(__il.begin(), __il.end()); + } + + _LIBCPP_INLINE_VISIBILITY + map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), typename __base::allocator_type(__a)) + { + insert(__il.begin(), __il.end()); + } + +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + map(initializer_list<value_type> __il, const allocator_type& __a) + : map(__il, key_compare(), __a) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + map& operator=(initializer_list<value_type> __il) + { + __tree_.__assign_unique(__il.begin(), __il.end()); + return *this; + } + +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + explicit map(const allocator_type& __a) + : __tree_(typename __base::allocator_type(__a)) + { + } + + _LIBCPP_INLINE_VISIBILITY + map(const map& __m, const allocator_type& __a) + : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) + { + insert(__m.begin(), __m.end()); + } + + _LIBCPP_INLINE_VISIBILITY + ~map() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __tree_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __tree_.end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT {return rend();} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __tree_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __tree_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __tree_.max_size();} + + mapped_type& operator[](const key_type& __k); +#ifndef _LIBCPP_CXX03_LANG + mapped_type& operator[](key_type&& __k); +#endif + + mapped_type& at(const key_type& __k); + const mapped_type& at(const key_type& __k) const; + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} + _LIBCPP_INLINE_VISIBILITY + key_compare key_comp() const {return __tree_.value_comp().key_comp();} + _LIBCPP_INLINE_VISIBILITY + value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());} + +#ifndef _LIBCPP_CXX03_LANG + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> emplace(_Args&& ...__args) { + return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...); + } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + iterator emplace_hint(const_iterator __p, _Args&& ...__args) { + return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...); + } + + template <class _Pp, + class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert(_Pp&& __p) + {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));} + + template <class _Pp, + class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __pos, _Pp&& __p) + {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));} + +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + insert(const value_type& __v) {return __tree_.__insert_unique(__v);} + + _LIBCPP_INLINE_VISIBILITY + iterator + insert(const_iterator __p, const value_type& __v) + {return __tree_.__insert_unique(__p.__i_, __v);} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, value_type&& __v) + {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} +#endif + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __f, _InputIterator __l) + { + for (const_iterator __e = cend(); __f != __l; ++__f) + insert(__e.__i_, *__f); + } + +#if _LIBCPP_STD_VER > 14 + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) + { + return __tree_.__emplace_unique_key_args(__k, + _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(__k), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) + { + return __tree_.__emplace_unique_key_args(__k, + _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::move(__k)), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) + { + return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, + _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(__k), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) + { + return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, + _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::move(__k)), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) + { + iterator __p = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + { + __p->second = _VSTD::forward<_Vp>(__v); + return _VSTD::make_pair(__p, false); + } + return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) + { + iterator __p = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + { + __p->second = _VSTD::forward<_Vp>(__v); + return _VSTD::make_pair(__p, false); + } + return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v) + { + iterator __p = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + { + __p->second = _VSTD::forward<_Vp>(__v); + return __p; + } + return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v)); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v) + { + iterator __p = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + { + __p->second = _VSTD::forward<_Vp>(__v); + return __p; + } + return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)); + } + +#endif // _LIBCPP_STD_VER > 14 + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) + {return __tree_.__erase_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __f, const_iterator __l) + {return __tree_.erase(__f.__i_, __l.__i_);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__tree_.clear();} + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + insert_return_type insert(node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to map::insert()"); + return __tree_.template __node_handle_insert_unique< + node_type, insert_return_type>(_VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __hint, node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to map::insert()"); + return __tree_.template __node_handle_insert_unique<node_type>( + __hint.__i_, _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(key_type const& __key) + { + return __tree_.template __node_handle_extract<node_type>(__key); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(const_iterator __it) + { + return __tree_.template __node_handle_extract<node_type>(__it.__i_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_unique(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_unique(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_unique(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_unique(__source.__tree_); + } +#endif + + _LIBCPP_INLINE_VISIBILITY + void swap(map& __m) + _NOEXCEPT_(__is_nothrow_swappable<__base>::value) + {__tree_.swap(__m.__tree_);} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __tree_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __tree_.find(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type + find(const _K2& __k) {return __tree_.find(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type + find(const _K2& __k) const {return __tree_.find(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const + {return __tree_.__count_unique(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type + count(const _K2& __k) const {return __tree_.__count_multi(__k);} +#endif + _LIBCPP_INLINE_VISIBILITY + iterator lower_bound(const key_type& __k) + {return __tree_.lower_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator lower_bound(const key_type& __k) const + {return __tree_.lower_bound(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type + lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} + + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type + lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + iterator upper_bound(const key_type& __k) + {return __tree_.upper_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator upper_bound(const key_type& __k) const + {return __tree_.upper_bound(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type + upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type + upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + pair<iterator,iterator> equal_range(const key_type& __k) + {return __tree_.__equal_range_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator,const_iterator> equal_range(const key_type& __k) const + {return __tree_.__equal_range_unique(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type + equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type + equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} +#endif + +private: + typedef typename __base::__node __node; + typedef typename __base::__node_allocator __node_allocator; + typedef typename __base::__node_pointer __node_pointer; + typedef typename __base::__node_base_pointer __node_base_pointer; + typedef typename __base::__parent_pointer __parent_pointer; + + typedef __map_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + +#ifdef _LIBCPP_CXX03_LANG + __node_holder __construct_node_with_key(const key_type& __k); +#endif +}; + + +#ifndef _LIBCPP_CXX03_LANG +template <class _Key, class _Tp, class _Compare, class _Allocator> +map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a) + : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) +{ + if (__a != __m.get_allocator()) + { + const_iterator __e = cend(); + while (!__m.empty()) + __tree_.__insert_unique(__e.__i_, + __m.__tree_.remove(__m.begin().__i_)->__value_.__move()); + } +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +_Tp& +map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) +{ + return __tree_.__emplace_unique_key_args(__k, + _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(__k), + _VSTD::forward_as_tuple()).first->__get_value().second; +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +_Tp& +map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) +{ + return __tree_.__emplace_unique_key_args(__k, + _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::move(__k)), + _VSTD::forward_as_tuple()).first->__get_value().second; +} + +#else // _LIBCPP_CXX03_LANG + +template <class _Key, class _Tp, class _Compare, class _Allocator> +typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder +map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k) +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second)); + __h.get_deleter().__second_constructed = true; + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +_Tp& +map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __node_holder __h = __construct_node_with_key(__k); + __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __r = __h.release(); + } + return __r->__value_.__get_value().second; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Key, class _Tp, class _Compare, class _Allocator> +_Tp& +map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); + if (__child == nullptr) + __throw_out_of_range("map::at: key not found"); + return static_cast<__node_pointer>(__child)->__value_.__get_value().second; +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +const _Tp& +map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const +{ + __parent_pointer __parent; + __node_base_pointer __child = __tree_.__find_equal(__parent, __k); + if (__child == nullptr) + __throw_out_of_range("map::at: key not found"); + return static_cast<__node_pointer>(__child)->__value_.__get_value().second; +} + + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__x == __y); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return __y < __x; +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__x < __y); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__y < __x); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(map<_Key, _Tp, _Compare, _Allocator>& __x, + map<_Key, _Tp, _Compare, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) +{ __libcpp_erase_if_container(__c, __pred); } +#endif + + +template <class _Key, class _Tp, class _Compare = less<_Key>, + class _Allocator = allocator<pair<const _Key, _Tp> > > +class _LIBCPP_TEMPLATE_VIS multimap +{ +public: + // types: + typedef _Key key_type; + typedef _Tp mapped_type; + typedef pair<const key_type, mapped_type> value_type; + typedef _Compare key_compare; + typedef _Allocator allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + + static_assert((is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + + class _LIBCPP_TEMPLATE_VIS value_compare + : public binary_function<value_type, value_type, bool> + { + friend class multimap; + protected: + key_compare comp; + + _LIBCPP_INLINE_VISIBILITY + value_compare(key_compare c) : comp(c) {} + public: + _LIBCPP_INLINE_VISIBILITY + bool operator()(const value_type& __x, const value_type& __y) const + {return comp(__x.first, __y.first);} + }; + +private: + + typedef _VSTD::__value_type<key_type, mapped_type> __value_type; + typedef __map_value_compare<key_type, __value_type, key_compare> __vc; + typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, + __value_type>::type __allocator_type; + typedef __tree<__value_type, __vc, __allocator_type> __base; + typedef typename __base::__node_traits __node_traits; + typedef allocator_traits<allocator_type> __alloc_traits; + + __base __tree_; + +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef __map_iterator<typename __base::iterator> iterator; + typedef __map_const_iterator<typename __base::const_iterator> const_iterator; + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + +#if _LIBCPP_STD_VER > 14 + typedef __map_node_handle<typename __base::__node, allocator_type> node_type; +#endif + + template <class _Key2, class _Value2, class _Comp2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS map; + template <class _Key2, class _Value2, class _Comp2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS multimap; + + _LIBCPP_INLINE_VISIBILITY + multimap() + _NOEXCEPT_( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_default_constructible<key_compare>::value && + is_nothrow_copy_constructible<key_compare>::value) + : __tree_(__vc(key_compare())) {} + + _LIBCPP_INLINE_VISIBILITY + explicit multimap(const key_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_copy_constructible<key_compare>::value) + : __tree_(__vc(__comp)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit multimap(const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + multimap(_InputIterator __f, _InputIterator __l, + const key_compare& __comp = key_compare()) + : __tree_(__vc(__comp)) + { + insert(__f, __l); + } + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + multimap(_InputIterator __f, _InputIterator __l, + const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), typename __base::allocator_type(__a)) + { + insert(__f, __l); + } + +#if _LIBCPP_STD_VER > 11 + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a) + : multimap(__f, __l, key_compare(), __a) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + multimap(const multimap& __m) + : __tree_(__m.__tree_.value_comp(), + __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) + { + insert(__m.begin(), __m.end()); + } + + _LIBCPP_INLINE_VISIBILITY + multimap& operator=(const multimap& __m) + { +#ifndef _LIBCPP_CXX03_LANG + __tree_ = __m.__tree_; +#else + if (this != &__m) { + __tree_.clear(); + __tree_.value_comp() = __m.__tree_.value_comp(); + __tree_.__copy_assign_alloc(__m.__tree_); + insert(__m.begin(), __m.end()); + } +#endif + return *this; + } + +#ifndef _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + multimap(multimap&& __m) + _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) + : __tree_(_VSTD::move(__m.__tree_)) + { + } + + multimap(multimap&& __m, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + multimap& operator=(multimap&& __m) + _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) + { + __tree_ = _VSTD::move(__m.__tree_); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) + : __tree_(__vc(__comp)) + { + insert(__il.begin(), __il.end()); + } + + _LIBCPP_INLINE_VISIBILITY + multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), typename __base::allocator_type(__a)) + { + insert(__il.begin(), __il.end()); + } + +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + multimap(initializer_list<value_type> __il, const allocator_type& __a) + : multimap(__il, key_compare(), __a) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + multimap& operator=(initializer_list<value_type> __il) + { + __tree_.__assign_multi(__il.begin(), __il.end()); + return *this; + } + +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + explicit multimap(const allocator_type& __a) + : __tree_(typename __base::allocator_type(__a)) + { + } + + _LIBCPP_INLINE_VISIBILITY + multimap(const multimap& __m, const allocator_type& __a) + : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) + { + insert(__m.begin(), __m.end()); + } + + _LIBCPP_INLINE_VISIBILITY + ~multimap() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __tree_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __tree_.end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT {return rend();} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __tree_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __tree_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __tree_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} + _LIBCPP_INLINE_VISIBILITY + key_compare key_comp() const {return __tree_.value_comp().key_comp();} + _LIBCPP_INLINE_VISIBILITY + value_compare value_comp() const + {return value_compare(__tree_.value_comp().key_comp());} + +#ifndef _LIBCPP_CXX03_LANG + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + iterator emplace(_Args&& ...__args) { + return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...); + } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + iterator emplace_hint(const_iterator __p, _Args&& ...__args) { + return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...); + } + + template <class _Pp, + class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator insert(_Pp&& __p) + {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));} + + template <class _Pp, + class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __pos, _Pp&& __p) + {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(value_type&& __v) + {return __tree_.__insert_multi(_VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, value_type&& __v) + {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));} + + + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} + +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, const value_type& __v) + {return __tree_.__insert_multi(__p.__i_, __v);} + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __f, _InputIterator __l) + { + for (const_iterator __e = cend(); __f != __l; ++__f) + __tree_.__insert_multi(__e.__i_, *__f); + } + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __f, const_iterator __l) + {return __tree_.erase(__f.__i_, __l.__i_);} + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + iterator insert(node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to multimap::insert()"); + return __tree_.template __node_handle_insert_multi<node_type>( + _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __hint, node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to multimap::insert()"); + return __tree_.template __node_handle_insert_multi<node_type>( + __hint.__i_, _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(key_type const& __key) + { + return __tree_.template __node_handle_extract<node_type>(__key); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(const_iterator __it) + { + return __tree_.template __node_handle_extract<node_type>( + __it.__i_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __tree_.__node_handle_merge_multi(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __tree_.__node_handle_merge_multi(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __tree_.__node_handle_merge_multi(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __tree_.__node_handle_merge_multi(__source.__tree_); + } +#endif + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__tree_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(multimap& __m) + _NOEXCEPT_(__is_nothrow_swappable<__base>::value) + {__tree_.swap(__m.__tree_);} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __tree_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __tree_.find(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type + find(const _K2& __k) {return __tree_.find(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type + find(const _K2& __k) const {return __tree_.find(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const + {return __tree_.__count_multi(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type + count(const _K2& __k) const {return __tree_.__count_multi(__k);} +#endif + _LIBCPP_INLINE_VISIBILITY + iterator lower_bound(const key_type& __k) + {return __tree_.lower_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator lower_bound(const key_type& __k) const + {return __tree_.lower_bound(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type + lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} + + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type + lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + iterator upper_bound(const key_type& __k) + {return __tree_.upper_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator upper_bound(const key_type& __k) const + {return __tree_.upper_bound(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type + upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type + upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + pair<iterator,iterator> equal_range(const key_type& __k) + {return __tree_.__equal_range_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator,const_iterator> equal_range(const key_type& __k) const + {return __tree_.__equal_range_multi(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type + equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type + equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} +#endif + +private: + typedef typename __base::__node __node; + typedef typename __base::__node_allocator __node_allocator; + typedef typename __base::__node_pointer __node_pointer; + + typedef __map_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; +}; + +#ifndef _LIBCPP_CXX03_LANG +template <class _Key, class _Tp, class _Compare, class _Allocator> +multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a) + : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) +{ + if (__a != __m.get_allocator()) + { + const_iterator __e = cend(); + while (!__m.empty()) + __tree_.__insert_multi(__e.__i_, + _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move())); + } +} +#endif + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__x == __y); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return __y < __x; +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__x < __y); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__y < __x); +} + +template <class _Key, class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, + multimap<_Key, _Tp, _Compare, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) +{ __libcpp_erase_if_container(__c, __pred); } +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_MAP diff --git a/android/x86/include/v8/libc++/math.h b/android/x86/include/v8/libc++/math.h new file mode 100755 index 00000000..6f9a76ba --- /dev/null +++ b/android/x86/include/v8/libc++/math.h @@ -0,0 +1,1530 @@ +// -*- C++ -*- +//===---------------------------- math.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_MATH_H +#define _LIBCPP_MATH_H + +/* + math.h synopsis + +Macros: + + HUGE_VAL + HUGE_VALF // C99 + HUGE_VALL // C99 + INFINITY // C99 + NAN // C99 + FP_INFINITE // C99 + FP_NAN // C99 + FP_NORMAL // C99 + FP_SUBNORMAL // C99 + FP_ZERO // C99 + FP_FAST_FMA // C99 + FP_FAST_FMAF // C99 + FP_FAST_FMAL // C99 + FP_ILOGB0 // C99 + FP_ILOGBNAN // C99 + MATH_ERRNO // C99 + MATH_ERREXCEPT // C99 + math_errhandling // C99 + +Types: + + float_t // C99 + double_t // C99 + +// C90 + +floating_point abs(floating_point x); + +floating_point acos (arithmetic x); +float acosf(float x); +long double acosl(long double x); + +floating_point asin (arithmetic x); +float asinf(float x); +long double asinl(long double x); + +floating_point atan (arithmetic x); +float atanf(float x); +long double atanl(long double x); + +floating_point atan2 (arithmetic y, arithmetic x); +float atan2f(float y, float x); +long double atan2l(long double y, long double x); + +floating_point ceil (arithmetic x); +float ceilf(float x); +long double ceill(long double x); + +floating_point cos (arithmetic x); +float cosf(float x); +long double cosl(long double x); + +floating_point cosh (arithmetic x); +float coshf(float x); +long double coshl(long double x); + +floating_point exp (arithmetic x); +float expf(float x); +long double expl(long double x); + +floating_point fabs (arithmetic x); +float fabsf(float x); +long double fabsl(long double x); + +floating_point floor (arithmetic x); +float floorf(float x); +long double floorl(long double x); + +floating_point fmod (arithmetic x, arithmetic y); +float fmodf(float x, float y); +long double fmodl(long double x, long double y); + +floating_point frexp (arithmetic value, int* exp); +float frexpf(float value, int* exp); +long double frexpl(long double value, int* exp); + +floating_point ldexp (arithmetic value, int exp); +float ldexpf(float value, int exp); +long double ldexpl(long double value, int exp); + +floating_point log (arithmetic x); +float logf(float x); +long double logl(long double x); + +floating_point log10 (arithmetic x); +float log10f(float x); +long double log10l(long double x); + +floating_point modf (floating_point value, floating_point* iptr); +float modff(float value, float* iptr); +long double modfl(long double value, long double* iptr); + +floating_point pow (arithmetic x, arithmetic y); +float powf(float x, float y); +long double powl(long double x, long double y); + +floating_point sin (arithmetic x); +float sinf(float x); +long double sinl(long double x); + +floating_point sinh (arithmetic x); +float sinhf(float x); +long double sinhl(long double x); + +floating_point sqrt (arithmetic x); +float sqrtf(float x); +long double sqrtl(long double x); + +floating_point tan (arithmetic x); +float tanf(float x); +long double tanl(long double x); + +floating_point tanh (arithmetic x); +float tanhf(float x); +long double tanhl(long double x); + +// C99 + +bool signbit(arithmetic x); + +int fpclassify(arithmetic x); + +bool isfinite(arithmetic x); +bool isinf(arithmetic x); +bool isnan(arithmetic x); +bool isnormal(arithmetic x); + +bool isgreater(arithmetic x, arithmetic y); +bool isgreaterequal(arithmetic x, arithmetic y); +bool isless(arithmetic x, arithmetic y); +bool islessequal(arithmetic x, arithmetic y); +bool islessgreater(arithmetic x, arithmetic y); +bool isunordered(arithmetic x, arithmetic y); + +floating_point acosh (arithmetic x); +float acoshf(float x); +long double acoshl(long double x); + +floating_point asinh (arithmetic x); +float asinhf(float x); +long double asinhl(long double x); + +floating_point atanh (arithmetic x); +float atanhf(float x); +long double atanhl(long double x); + +floating_point cbrt (arithmetic x); +float cbrtf(float x); +long double cbrtl(long double x); + +floating_point copysign (arithmetic x, arithmetic y); +float copysignf(float x, float y); +long double copysignl(long double x, long double y); + +floating_point erf (arithmetic x); +float erff(float x); +long double erfl(long double x); + +floating_point erfc (arithmetic x); +float erfcf(float x); +long double erfcl(long double x); + +floating_point exp2 (arithmetic x); +float exp2f(float x); +long double exp2l(long double x); + +floating_point expm1 (arithmetic x); +float expm1f(float x); +long double expm1l(long double x); + +floating_point fdim (arithmetic x, arithmetic y); +float fdimf(float x, float y); +long double fdiml(long double x, long double y); + +floating_point fma (arithmetic x, arithmetic y, arithmetic z); +float fmaf(float x, float y, float z); +long double fmal(long double x, long double y, long double z); + +floating_point fmax (arithmetic x, arithmetic y); +float fmaxf(float x, float y); +long double fmaxl(long double x, long double y); + +floating_point fmin (arithmetic x, arithmetic y); +float fminf(float x, float y); +long double fminl(long double x, long double y); + +floating_point hypot (arithmetic x, arithmetic y); +float hypotf(float x, float y); +long double hypotl(long double x, long double y); + +int ilogb (arithmetic x); +int ilogbf(float x); +int ilogbl(long double x); + +floating_point lgamma (arithmetic x); +float lgammaf(float x); +long double lgammal(long double x); + +long long llrint (arithmetic x); +long long llrintf(float x); +long long llrintl(long double x); + +long long llround (arithmetic x); +long long llroundf(float x); +long long llroundl(long double x); + +floating_point log1p (arithmetic x); +float log1pf(float x); +long double log1pl(long double x); + +floating_point log2 (arithmetic x); +float log2f(float x); +long double log2l(long double x); + +floating_point logb (arithmetic x); +float logbf(float x); +long double logbl(long double x); + +long lrint (arithmetic x); +long lrintf(float x); +long lrintl(long double x); + +long lround (arithmetic x); +long lroundf(float x); +long lroundl(long double x); + +double nan (const char* str); +float nanf(const char* str); +long double nanl(const char* str); + +floating_point nearbyint (arithmetic x); +float nearbyintf(float x); +long double nearbyintl(long double x); + +floating_point nextafter (arithmetic x, arithmetic y); +float nextafterf(float x, float y); +long double nextafterl(long double x, long double y); + +floating_point nexttoward (arithmetic x, long double y); +float nexttowardf(float x, long double y); +long double nexttowardl(long double x, long double y); + +floating_point remainder (arithmetic x, arithmetic y); +float remainderf(float x, float y); +long double remainderl(long double x, long double y); + +floating_point remquo (arithmetic x, arithmetic y, int* pquo); +float remquof(float x, float y, int* pquo); +long double remquol(long double x, long double y, int* pquo); + +floating_point rint (arithmetic x); +float rintf(float x); +long double rintl(long double x); + +floating_point round (arithmetic x); +float roundf(float x); +long double roundl(long double x); + +floating_point scalbln (arithmetic x, long ex); +float scalblnf(float x, long ex); +long double scalblnl(long double x, long ex); + +floating_point scalbn (arithmetic x, int ex); +float scalbnf(float x, int ex); +long double scalbnl(long double x, int ex); + +floating_point tgamma (arithmetic x); +float tgammaf(float x); +long double tgammal(long double x); + +floating_point trunc (arithmetic x); +float truncf(float x); +long double truncl(long double x); + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <math.h> + +#ifdef __cplusplus + +// We support including .h headers inside 'extern "C"' contexts, so switch +// back to C++ linkage before including these C++ headers. +extern "C++" { + +#include <type_traits> +#include <limits> + +// signbit + +#ifdef signbit + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT +{ + return signbit(__lcpp_x); +} + +#undef signbit + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type +signbit(_A1 __lcpp_x) _NOEXCEPT +{ + return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type +signbit(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x < 0; } + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type +signbit(_A1) _NOEXCEPT +{ return false; } + +#elif defined(_LIBCPP_MSVCRT) + +template <typename _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type +signbit(_A1 __lcpp_x) _NOEXCEPT +{ + return ::signbit(static_cast<typename std::__promote<_A1>::type>(__lcpp_x)); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type +signbit(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x < 0; } + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type +signbit(_A1) _NOEXCEPT +{ return false; } + +#endif // signbit + +// fpclassify + +#ifdef fpclassify + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +int +__libcpp_fpclassify(_A1 __lcpp_x) _NOEXCEPT +{ + return fpclassify(__lcpp_x); +} + +#undef fpclassify + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_floating_point<_A1>::value, int>::type +fpclassify(_A1 __lcpp_x) _NOEXCEPT +{ + return __libcpp_fpclassify((typename std::__promote<_A1>::type)__lcpp_x); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, int>::type +fpclassify(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL; } + +#elif defined(_LIBCPP_MSVCRT) + +template <typename _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type +fpclassify(_A1 __lcpp_x) _NOEXCEPT +{ + return ::fpclassify(static_cast<typename std::__promote<_A1>::type>(__lcpp_x)); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, int>::type +fpclassify(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL; } + +#endif // fpclassify + +// isfinite + +#ifdef isfinite + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT +{ + return isfinite(__lcpp_x); +} + +#undef isfinite + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, + bool>::type +isfinite(_A1 __lcpp_x) _NOEXCEPT +{ + return __libcpp_isfinite((typename std::__promote<_A1>::type)__lcpp_x); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, + bool>::type +isfinite(_A1) _NOEXCEPT +{ return true; } + +#endif // isfinite + +// isinf + +#ifdef isinf + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT +{ + return isinf(__lcpp_x); +} + +#undef isinf + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, + bool>::type +isinf(_A1 __lcpp_x) _NOEXCEPT +{ + return __libcpp_isinf((typename std::__promote<_A1>::type)__lcpp_x); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, + bool>::type +isinf(_A1) _NOEXCEPT +{ return false; } + +#ifdef _LIBCPP_PREFERRED_OVERLOAD +inline _LIBCPP_INLINE_VISIBILITY +bool +isinf(float __lcpp_x) _NOEXCEPT { return __libcpp_isinf(__lcpp_x); } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +bool +isinf(double __lcpp_x) _NOEXCEPT { return __libcpp_isinf(__lcpp_x); } + +inline _LIBCPP_INLINE_VISIBILITY +bool +isinf(long double __lcpp_x) _NOEXCEPT { return __libcpp_isinf(__lcpp_x); } +#endif + +#endif // isinf + +// isnan + +#ifdef isnan + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT +{ + return isnan(__lcpp_x); +} + +#undef isnan + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type +isnan(_A1 __lcpp_x) _NOEXCEPT +{ + return __libcpp_isnan((typename std::__promote<_A1>::type)__lcpp_x); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, bool>::type +isnan(_A1) _NOEXCEPT +{ return false; } + +#ifdef _LIBCPP_PREFERRED_OVERLOAD +inline _LIBCPP_INLINE_VISIBILITY +bool +isnan(float __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +bool +isnan(double __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); } + +inline _LIBCPP_INLINE_VISIBILITY +bool +isnan(long double __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); } +#endif + +#endif // isnan + +// isnormal + +#ifdef isnormal + +template <class _A1> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_isnormal(_A1 __lcpp_x) _NOEXCEPT +{ + return isnormal(__lcpp_x); +} + +#undef isnormal + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type +isnormal(_A1 __lcpp_x) _NOEXCEPT +{ + return __libcpp_isnormal((typename std::__promote<_A1>::type)__lcpp_x); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, bool>::type +isnormal(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x != 0; } + +#endif // isnormal + +// isgreater + +#ifdef isgreater + +template <class _A1, class _A2> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + return isgreater(__lcpp_x, __lcpp_y); +} + +#undef isgreater + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + bool +>::type +isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type type; + return __libcpp_isgreater((type)__lcpp_x, (type)__lcpp_y); +} + +#endif // isgreater + +// isgreaterequal + +#ifdef isgreaterequal + +template <class _A1, class _A2> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + return isgreaterequal(__lcpp_x, __lcpp_y); +} + +#undef isgreaterequal + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + bool +>::type +isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type type; + return __libcpp_isgreaterequal((type)__lcpp_x, (type)__lcpp_y); +} + +#endif // isgreaterequal + +// isless + +#ifdef isless + +template <class _A1, class _A2> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + return isless(__lcpp_x, __lcpp_y); +} + +#undef isless + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + bool +>::type +isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type type; + return __libcpp_isless((type)__lcpp_x, (type)__lcpp_y); +} + +#endif // isless + +// islessequal + +#ifdef islessequal + +template <class _A1, class _A2> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + return islessequal(__lcpp_x, __lcpp_y); +} + +#undef islessequal + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + bool +>::type +islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type type; + return __libcpp_islessequal((type)__lcpp_x, (type)__lcpp_y); +} + +#endif // islessequal + +// islessgreater + +#ifdef islessgreater + +template <class _A1, class _A2> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + return islessgreater(__lcpp_x, __lcpp_y); +} + +#undef islessgreater + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + bool +>::type +islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type type; + return __libcpp_islessgreater((type)__lcpp_x, (type)__lcpp_y); +} + +#endif // islessgreater + +// isunordered + +#ifdef isunordered + +template <class _A1, class _A2> +_LIBCPP_INLINE_VISIBILITY +bool +__libcpp_isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + return isunordered(__lcpp_x, __lcpp_y); +} + +#undef isunordered + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + bool +>::type +isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type type; + return __libcpp_isunordered((type)__lcpp_x, (type)__lcpp_y); +} + +#endif // isunordered + +// abs + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY +float +abs(float __lcpp_x) _NOEXCEPT {return ::fabsf(__lcpp_x);} + +inline _LIBCPP_INLINE_VISIBILITY +double +abs(double __lcpp_x) _NOEXCEPT {return ::fabs(__lcpp_x);} + +inline _LIBCPP_INLINE_VISIBILITY +long double +abs(long double __lcpp_x) _NOEXCEPT {return ::fabsl(__lcpp_x);} +#endif // !(defined(_AIX) || defined(__sun__)) + +// acos + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float acos(float __lcpp_x) _NOEXCEPT {return ::acosf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return ::acosl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +acos(_A1 __lcpp_x) _NOEXCEPT {return ::acos((double)__lcpp_x);} + +// asin + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float asin(float __lcpp_x) _NOEXCEPT {return ::asinf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return ::asinl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +asin(_A1 __lcpp_x) _NOEXCEPT {return ::asin((double)__lcpp_x);} + +// atan + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float atan(float __lcpp_x) _NOEXCEPT {return ::atanf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return ::atanl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +atan(_A1 __lcpp_x) _NOEXCEPT {return ::atan((double)__lcpp_x);} + +// atan2 + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT {return ::atan2f(__lcpp_y, __lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return ::atan2l(__lcpp_y, __lcpp_x);} +#endif + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::atan2((__result_type)__lcpp_y, (__result_type)__lcpp_x); +} + +// ceil + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float ceil(float __lcpp_x) _NOEXCEPT {return ::ceilf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ::ceill(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +ceil(_A1 __lcpp_x) _NOEXCEPT {return ::ceil((double)__lcpp_x);} + +// cos + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float cos(float __lcpp_x) _NOEXCEPT {return ::cosf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __lcpp_x) _NOEXCEPT {return ::cosl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +cos(_A1 __lcpp_x) _NOEXCEPT {return ::cos((double)__lcpp_x);} + +// cosh + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float cosh(float __lcpp_x) _NOEXCEPT {return ::coshf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __lcpp_x) _NOEXCEPT {return ::coshl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +cosh(_A1 __lcpp_x) _NOEXCEPT {return ::cosh((double)__lcpp_x);} + +// exp + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float exp(float __lcpp_x) _NOEXCEPT {return ::expf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __lcpp_x) _NOEXCEPT {return ::expl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +exp(_A1 __lcpp_x) _NOEXCEPT {return ::exp((double)__lcpp_x);} + +// fabs + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float fabs(float __lcpp_x) _NOEXCEPT {return ::fabsf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __lcpp_x) _NOEXCEPT {return ::fabsl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +fabs(_A1 __lcpp_x) _NOEXCEPT {return ::fabs((double)__lcpp_x);} + +// floor + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float floor(float __lcpp_x) _NOEXCEPT {return ::floorf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __lcpp_x) _NOEXCEPT {return ::floorl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +floor(_A1 __lcpp_x) _NOEXCEPT {return ::floor((double)__lcpp_x);} + +// fmod + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float fmod(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::fmodf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::fmodl(__lcpp_x, __lcpp_y);} +#endif + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +fmod(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::fmod((__result_type)__lcpp_x, (__result_type)__lcpp_y); +} + +// frexp + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float frexp(float __lcpp_x, int* __lcpp_e) _NOEXCEPT {return ::frexpf(__lcpp_x, __lcpp_e);} +inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __lcpp_x, int* __lcpp_e) _NOEXCEPT {return ::frexpl(__lcpp_x, __lcpp_e);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +frexp(_A1 __lcpp_x, int* __lcpp_e) _NOEXCEPT {return ::frexp((double)__lcpp_x, __lcpp_e);} + +// ldexp + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __lcpp_x, int __lcpp_e) _NOEXCEPT {return ::ldexpf(__lcpp_x, __lcpp_e);} +inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __lcpp_x, int __lcpp_e) _NOEXCEPT {return ::ldexpl(__lcpp_x, __lcpp_e);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +ldexp(_A1 __lcpp_x, int __lcpp_e) _NOEXCEPT {return ::ldexp((double)__lcpp_x, __lcpp_e);} + +// log + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float log(float __lcpp_x) _NOEXCEPT {return ::logf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double log(long double __lcpp_x) _NOEXCEPT {return ::logl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +log(_A1 __lcpp_x) _NOEXCEPT {return ::log((double)__lcpp_x);} + +// log10 + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float log10(float __lcpp_x) _NOEXCEPT {return ::log10f(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __lcpp_x) _NOEXCEPT {return ::log10l(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +log10(_A1 __lcpp_x) _NOEXCEPT {return ::log10((double)__lcpp_x);} + +// modf + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float modf(float __lcpp_x, float* __lcpp_y) _NOEXCEPT {return ::modff(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __lcpp_x, long double* __lcpp_y) _NOEXCEPT {return ::modfl(__lcpp_x, __lcpp_y);} +#endif + +// pow + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float pow(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::powf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::powl(__lcpp_x, __lcpp_y);} +#endif + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::pow((__result_type)__lcpp_x, (__result_type)__lcpp_y); +} + +// sin + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float sin(float __lcpp_x) _NOEXCEPT {return ::sinf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __lcpp_x) _NOEXCEPT {return ::sinl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +sin(_A1 __lcpp_x) _NOEXCEPT {return ::sin((double)__lcpp_x);} + +// sinh + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float sinh(float __lcpp_x) _NOEXCEPT {return ::sinhf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __lcpp_x) _NOEXCEPT {return ::sinhl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +sinh(_A1 __lcpp_x) _NOEXCEPT {return ::sinh((double)__lcpp_x);} + +// sqrt + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __lcpp_x) _NOEXCEPT {return ::sqrtf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __lcpp_x) _NOEXCEPT {return ::sqrtl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +sqrt(_A1 __lcpp_x) _NOEXCEPT {return ::sqrt((double)__lcpp_x);} + +// tan + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float tan(float __lcpp_x) _NOEXCEPT {return ::tanf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __lcpp_x) _NOEXCEPT {return ::tanl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +tan(_A1 __lcpp_x) _NOEXCEPT {return ::tan((double)__lcpp_x);} + +// tanh + +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float tanh(float __lcpp_x) _NOEXCEPT {return ::tanhf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __lcpp_x) _NOEXCEPT {return ::tanhl(__lcpp_x);} +#endif + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +tanh(_A1 __lcpp_x) _NOEXCEPT {return ::tanh((double)__lcpp_x);} + +// acosh + +inline _LIBCPP_INLINE_VISIBILITY float acosh(float __lcpp_x) _NOEXCEPT {return ::acoshf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return ::acoshl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +acosh(_A1 __lcpp_x) _NOEXCEPT {return ::acosh((double)__lcpp_x);} + +// asinh + +inline _LIBCPP_INLINE_VISIBILITY float asinh(float __lcpp_x) _NOEXCEPT {return ::asinhf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return ::asinhl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +asinh(_A1 __lcpp_x) _NOEXCEPT {return ::asinh((double)__lcpp_x);} + +// atanh + +inline _LIBCPP_INLINE_VISIBILITY float atanh(float __lcpp_x) _NOEXCEPT {return ::atanhf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return ::atanhl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +atanh(_A1 __lcpp_x) _NOEXCEPT {return ::atanh((double)__lcpp_x);} + +// cbrt + +inline _LIBCPP_INLINE_VISIBILITY float cbrt(float __lcpp_x) _NOEXCEPT {return ::cbrtf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return ::cbrtl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +cbrt(_A1 __lcpp_x) _NOEXCEPT {return ::cbrt((double)__lcpp_x);} + +// copysign + +inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x, + float __lcpp_y) _NOEXCEPT { + return ::copysignf(__lcpp_x, __lcpp_y); +} +inline _LIBCPP_INLINE_VISIBILITY long double +copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT { + return ::copysignl(__lcpp_x, __lcpp_y); +} + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y); +} + +// erf + +inline _LIBCPP_INLINE_VISIBILITY float erf(float __lcpp_x) _NOEXCEPT {return ::erff(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __lcpp_x) _NOEXCEPT {return ::erfl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +erf(_A1 __lcpp_x) _NOEXCEPT {return ::erf((double)__lcpp_x);} + +// erfc + +inline _LIBCPP_INLINE_VISIBILITY float erfc(float __lcpp_x) _NOEXCEPT {return ::erfcf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __lcpp_x) _NOEXCEPT {return ::erfcl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +erfc(_A1 __lcpp_x) _NOEXCEPT {return ::erfc((double)__lcpp_x);} + +// exp2 + +inline _LIBCPP_INLINE_VISIBILITY float exp2(float __lcpp_x) _NOEXCEPT {return ::exp2f(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __lcpp_x) _NOEXCEPT {return ::exp2l(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +exp2(_A1 __lcpp_x) _NOEXCEPT {return ::exp2((double)__lcpp_x);} + +// expm1 + +inline _LIBCPP_INLINE_VISIBILITY float expm1(float __lcpp_x) _NOEXCEPT {return ::expm1f(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __lcpp_x) _NOEXCEPT {return ::expm1l(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +expm1(_A1 __lcpp_x) _NOEXCEPT {return ::expm1((double)__lcpp_x);} + +// fdim + +inline _LIBCPP_INLINE_VISIBILITY float fdim(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::fdimf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::fdiml(__lcpp_x, __lcpp_y);} + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +fdim(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::fdim((__result_type)__lcpp_x, (__result_type)__lcpp_y); +} + +// fma + +inline _LIBCPP_INLINE_VISIBILITY float fma(float __lcpp_x, float __lcpp_y, float __lcpp_z) _NOEXCEPT {return ::fmaf(__lcpp_x, __lcpp_y, __lcpp_z);} +inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long double __lcpp_y, long double __lcpp_z) _NOEXCEPT {return ::fmal(__lcpp_x, __lcpp_y, __lcpp_z);} + +template <class _A1, class _A2, class _A3> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value && + std::is_arithmetic<_A3>::value, + std::__promote<_A1, _A2, _A3> +>::type +fma(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2, _A3>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value && + std::is_same<_A3, __result_type>::value)), ""); + return ::fma((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); +} + +// fmax + +inline _LIBCPP_INLINE_VISIBILITY float fmax(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::fmaxf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::fmaxl(__lcpp_x, __lcpp_y);} + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +fmax(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::fmax((__result_type)__lcpp_x, (__result_type)__lcpp_y); +} + +// fmin + +inline _LIBCPP_INLINE_VISIBILITY float fmin(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::fminf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::fminl(__lcpp_x, __lcpp_y);} + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +fmin(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::fmin((__result_type)__lcpp_x, (__result_type)__lcpp_y); +} + +// hypot + +inline _LIBCPP_INLINE_VISIBILITY float hypot(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::hypotf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::hypotl(__lcpp_x, __lcpp_y);} + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +hypot(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y); +} + +// ilogb + +inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __lcpp_x) _NOEXCEPT {return ::ilogbf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __lcpp_x) _NOEXCEPT {return ::ilogbl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, int>::type +ilogb(_A1 __lcpp_x) _NOEXCEPT {return ::ilogb((double)__lcpp_x);} + +// lgamma + +inline _LIBCPP_INLINE_VISIBILITY float lgamma(float __lcpp_x) _NOEXCEPT {return ::lgammaf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __lcpp_x) _NOEXCEPT {return ::lgammal(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +lgamma(_A1 __lcpp_x) _NOEXCEPT {return ::lgamma((double)__lcpp_x);} + +// llrint + +inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __lcpp_x) _NOEXCEPT {return ::llrintf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __lcpp_x) _NOEXCEPT {return ::llrintl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, long long>::type +llrint(_A1 __lcpp_x) _NOEXCEPT {return ::llrint((double)__lcpp_x);} + +// llround + +inline _LIBCPP_INLINE_VISIBILITY long long llround(float __lcpp_x) _NOEXCEPT {return ::llroundf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __lcpp_x) _NOEXCEPT {return ::llroundl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, long long>::type +llround(_A1 __lcpp_x) _NOEXCEPT {return ::llround((double)__lcpp_x);} + +// log1p + +inline _LIBCPP_INLINE_VISIBILITY float log1p(float __lcpp_x) _NOEXCEPT {return ::log1pf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __lcpp_x) _NOEXCEPT {return ::log1pl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +log1p(_A1 __lcpp_x) _NOEXCEPT {return ::log1p((double)__lcpp_x);} + +// log2 + +inline _LIBCPP_INLINE_VISIBILITY float log2(float __lcpp_x) _NOEXCEPT {return ::log2f(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __lcpp_x) _NOEXCEPT {return ::log2l(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +log2(_A1 __lcpp_x) _NOEXCEPT {return ::log2((double)__lcpp_x);} + +// logb + +inline _LIBCPP_INLINE_VISIBILITY float logb(float __lcpp_x) _NOEXCEPT {return ::logbf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __lcpp_x) _NOEXCEPT {return ::logbl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +logb(_A1 __lcpp_x) _NOEXCEPT {return ::logb((double)__lcpp_x);} + +// lrint + +inline _LIBCPP_INLINE_VISIBILITY long lrint(float __lcpp_x) _NOEXCEPT {return ::lrintf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __lcpp_x) _NOEXCEPT {return ::lrintl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, long>::type +lrint(_A1 __lcpp_x) _NOEXCEPT {return ::lrint((double)__lcpp_x);} + +// lround + +inline _LIBCPP_INLINE_VISIBILITY long lround(float __lcpp_x) _NOEXCEPT {return ::lroundf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long lround(long double __lcpp_x) _NOEXCEPT {return ::lroundl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, long>::type +lround(_A1 __lcpp_x) _NOEXCEPT {return ::lround((double)__lcpp_x);} + +// nan + +// nearbyint + +inline _LIBCPP_INLINE_VISIBILITY float nearbyint(float __lcpp_x) _NOEXCEPT {return ::nearbyintf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __lcpp_x) _NOEXCEPT {return ::nearbyintl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +nearbyint(_A1 __lcpp_x) _NOEXCEPT {return ::nearbyint((double)__lcpp_x);} + +// nextafter + +inline _LIBCPP_INLINE_VISIBILITY float nextafter(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::nextafterf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::nextafterl(__lcpp_x, __lcpp_y);} + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +nextafter(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::nextafter((__result_type)__lcpp_x, (__result_type)__lcpp_y); +} + +// nexttoward + +inline _LIBCPP_INLINE_VISIBILITY float nexttoward(float __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::nexttowardf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::nexttowardl(__lcpp_x, __lcpp_y);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +nexttoward(_A1 __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::nexttoward((double)__lcpp_x, __lcpp_y);} + +// remainder + +inline _LIBCPP_INLINE_VISIBILITY float remainder(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::remainderf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::remainderl(__lcpp_x, __lcpp_y);} + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +remainder(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::remainder((__result_type)__lcpp_x, (__result_type)__lcpp_y); +} + +// remquo + +inline _LIBCPP_INLINE_VISIBILITY float remquo(float __lcpp_x, float __lcpp_y, int* __lcpp_z) _NOEXCEPT {return ::remquof(__lcpp_x, __lcpp_y, __lcpp_z);} +inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long double __lcpp_y, int* __lcpp_z) _NOEXCEPT {return ::remquol(__lcpp_x, __lcpp_y, __lcpp_z);} + +template <class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value, + std::__promote<_A1, _A2> +>::type +remquo(_A1 __lcpp_x, _A2 __lcpp_y, int* __lcpp_z) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value)), ""); + return ::remquo((__result_type)__lcpp_x, (__result_type)__lcpp_y, __lcpp_z); +} + +// rint + +inline _LIBCPP_INLINE_VISIBILITY float rint(float __lcpp_x) _NOEXCEPT {return ::rintf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __lcpp_x) _NOEXCEPT {return ::rintl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +rint(_A1 __lcpp_x) _NOEXCEPT {return ::rint((double)__lcpp_x);} + +// round + +inline _LIBCPP_INLINE_VISIBILITY float round(float __lcpp_x) _NOEXCEPT {return ::roundf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double round(long double __lcpp_x) _NOEXCEPT {return ::roundl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +round(_A1 __lcpp_x) _NOEXCEPT {return ::round((double)__lcpp_x);} + +// scalbln + +inline _LIBCPP_INLINE_VISIBILITY float scalbln(float __lcpp_x, long __lcpp_y) _NOEXCEPT {return ::scalblnf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __lcpp_x, long __lcpp_y) _NOEXCEPT {return ::scalblnl(__lcpp_x, __lcpp_y);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +scalbln(_A1 __lcpp_x, long __lcpp_y) _NOEXCEPT {return ::scalbln((double)__lcpp_x, __lcpp_y);} + +// scalbn + +inline _LIBCPP_INLINE_VISIBILITY float scalbn(float __lcpp_x, int __lcpp_y) _NOEXCEPT {return ::scalbnf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __lcpp_x, int __lcpp_y) _NOEXCEPT {return ::scalbnl(__lcpp_x, __lcpp_y);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +scalbn(_A1 __lcpp_x, int __lcpp_y) _NOEXCEPT {return ::scalbn((double)__lcpp_x, __lcpp_y);} + +// tgamma + +inline _LIBCPP_INLINE_VISIBILITY float tgamma(float __lcpp_x) _NOEXCEPT {return ::tgammaf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __lcpp_x) _NOEXCEPT {return ::tgammal(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +tgamma(_A1 __lcpp_x) _NOEXCEPT {return ::tgamma((double)__lcpp_x);} + +// trunc + +inline _LIBCPP_INLINE_VISIBILITY float trunc(float __lcpp_x) _NOEXCEPT {return ::truncf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __lcpp_x) _NOEXCEPT {return ::truncl(__lcpp_x);} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, double>::type +trunc(_A1 __lcpp_x) _NOEXCEPT {return ::trunc((double)__lcpp_x);} + +} // extern "C++" + +#endif // __cplusplus + +#else // _LIBCPP_MATH_H + +// This include lives outside the header guard in order to support an MSVC +// extension which allows users to do: +// +// #define _USE_MATH_DEFINES +// #include <math.h> +// +// and receive the definitions of mathematical constants, even if <math.h> +// has previously been included. +#if defined(_LIBCPP_MSVCRT) && defined(_USE_MATH_DEFINES) +#include_next <math.h> +#endif + +#endif // _LIBCPP_MATH_H diff --git a/android/x86/include/v8/libc++/memory b/android/x86/include/v8/libc++/memory new file mode 100755 index 00000000..3398629c --- /dev/null +++ b/android/x86/include/v8/libc++/memory @@ -0,0 +1,5675 @@ +// -*- C++ -*- +//===-------------------------- memory ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_MEMORY +#define _LIBCPP_MEMORY + +/* + memory synopsis + +namespace std +{ + +struct allocator_arg_t { }; +inline constexpr allocator_arg_t allocator_arg = allocator_arg_t(); + +template <class T, class Alloc> struct uses_allocator; + +template <class Ptr> +struct pointer_traits +{ + typedef Ptr pointer; + typedef <details> element_type; + typedef <details> difference_type; + + template <class U> using rebind = <details>; + + static pointer pointer_to(<details>); +}; + +template <class T> +struct pointer_traits<T*> +{ + typedef T* pointer; + typedef T element_type; + typedef ptrdiff_t difference_type; + + template <class U> using rebind = U*; + + static pointer pointer_to(<details>) noexcept; // constexpr in C++20 +}; + +template <class T> constexpr T* to_address(T* p) noexcept; // C++20 +template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20 + +template <class Alloc> +struct allocator_traits +{ + typedef Alloc allocator_type; + typedef typename allocator_type::value_type + value_type; + + typedef Alloc::pointer | value_type* pointer; + typedef Alloc::const_pointer + | pointer_traits<pointer>::rebind<const value_type> + const_pointer; + typedef Alloc::void_pointer + | pointer_traits<pointer>::rebind<void> + void_pointer; + typedef Alloc::const_void_pointer + | pointer_traits<pointer>::rebind<const void> + const_void_pointer; + typedef Alloc::difference_type + | pointer_traits<pointer>::difference_type + difference_type; + typedef Alloc::size_type + | make_unsigned<difference_type>::type + size_type; + typedef Alloc::propagate_on_container_copy_assignment + | false_type propagate_on_container_copy_assignment; + typedef Alloc::propagate_on_container_move_assignment + | false_type propagate_on_container_move_assignment; + typedef Alloc::propagate_on_container_swap + | false_type propagate_on_container_swap; + typedef Alloc::is_always_equal + | is_empty is_always_equal; + + template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>; + template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; + + static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20 + static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20 + + static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; + + template <class T, class... Args> + static void construct(allocator_type& a, T* p, Args&&... args); + + template <class T> + static void destroy(allocator_type& a, T* p); + + static size_type max_size(const allocator_type& a); // noexcept in C++14 + + static allocator_type + select_on_container_copy_construction(const allocator_type& a); +}; + +template <> +class allocator<void> +{ +public: + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template <class _Up> struct rebind {typedef allocator<_Up> other;}; +}; + +template <class T> +class allocator +{ +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef typename add_lvalue_reference<T>::type reference; + typedef typename add_lvalue_reference<const T>::type const_reference; + typedef T value_type; + + template <class U> struct rebind {typedef allocator<U> other;}; + + constexpr allocator() noexcept; // constexpr in C++20 + constexpr allocator(const allocator&) noexcept; // constexpr in C++20 + template <class U> + constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20 + ~allocator(); + pointer address(reference x) const noexcept; + const_pointer address(const_reference x) const noexcept; + pointer allocate(size_type, allocator<void>::const_pointer hint = 0); + void deallocate(pointer p, size_type n) noexcept; + size_type max_size() const noexcept; + template<class U, class... Args> + void construct(U* p, Args&&... args); + template <class U> + void destroy(U* p); +}; + +template <class T, class U> +bool operator==(const allocator<T>&, const allocator<U>&) noexcept; + +template <class T, class U> +bool operator!=(const allocator<T>&, const allocator<U>&) noexcept; + +template <class OutputIterator, class T> +class raw_storage_iterator + : public iterator<output_iterator_tag, + T, // purposefully not C++03 + ptrdiff_t, // purposefully not C++03 + T*, // purposefully not C++03 + raw_storage_iterator&> // purposefully not C++03 +{ +public: + explicit raw_storage_iterator(OutputIterator x); + raw_storage_iterator& operator*(); + raw_storage_iterator& operator=(const T& element); + raw_storage_iterator& operator++(); + raw_storage_iterator operator++(int); +}; + +template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; +template <class T> void return_temporary_buffer(T* p) noexcept; + +template <class T> T* addressof(T& r) noexcept; +template <class T> T* addressof(const T&& r) noexcept = delete; + +template <class InputIterator, class ForwardIterator> +ForwardIterator +uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); + +template <class InputIterator, class Size, class ForwardIterator> +ForwardIterator +uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); + +template <class ForwardIterator, class T> +void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); + +template <class ForwardIterator, class Size, class T> +ForwardIterator +uninitialized_fill_n(ForwardIterator first, Size n, const T& x); + +template <class T> +void destroy_at(T* location); + +template <class ForwardIterator> + void destroy(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class Size> + ForwardIterator destroy_n(ForwardIterator first, Size n); + +template <class InputIterator, class ForwardIterator> + ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result); + +template <class InputIterator, class Size, class ForwardIterator> + pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result); + +template <class ForwardIterator> + void uninitialized_value_construct(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class Size> + ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n); + +template <class ForwardIterator> + void uninitialized_default_construct(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class Size> + ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n); + +template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17 + +template<class X> +class auto_ptr // deprecated in C++11, removed in C++17 +{ +public: + typedef X element_type; + + explicit auto_ptr(X* p =0) throw(); + auto_ptr(auto_ptr&) throw(); + template<class Y> auto_ptr(auto_ptr<Y>&) throw(); + auto_ptr& operator=(auto_ptr&) throw(); + template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw(); + auto_ptr& operator=(auto_ptr_ref<X> r) throw(); + ~auto_ptr() throw(); + + typename add_lvalue_reference<X>::type operator*() const throw(); + X* operator->() const throw(); + X* get() const throw(); + X* release() throw(); + void reset(X* p =0) throw(); + + auto_ptr(auto_ptr_ref<X>) throw(); + template<class Y> operator auto_ptr_ref<Y>() throw(); + template<class Y> operator auto_ptr<Y>() throw(); +}; + +template <class T> +struct default_delete +{ + constexpr default_delete() noexcept = default; + template <class U> default_delete(const default_delete<U>&) noexcept; + + void operator()(T*) const noexcept; +}; + +template <class T> +struct default_delete<T[]> +{ + constexpr default_delete() noexcept = default; + void operator()(T*) const noexcept; + template <class U> void operator()(U*) const = delete; +}; + +template <class T, class D = default_delete<T>> +class unique_ptr +{ +public: + typedef see below pointer; + typedef T element_type; + typedef D deleter_type; + + // constructors + constexpr unique_ptr() noexcept; + explicit unique_ptr(pointer p) noexcept; + unique_ptr(pointer p, see below d1) noexcept; + unique_ptr(pointer p, see below d2) noexcept; + unique_ptr(unique_ptr&& u) noexcept; + unique_ptr(nullptr_t) noexcept : unique_ptr() { } + template <class U, class E> + unique_ptr(unique_ptr<U, E>&& u) noexcept; + template <class U> + unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17 + + // destructor + ~unique_ptr(); + + // assignment + unique_ptr& operator=(unique_ptr&& u) noexcept; + template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; + unique_ptr& operator=(nullptr_t) noexcept; + + // observers + typename add_lvalue_reference<T>::type operator*() const; + pointer operator->() const noexcept; + pointer get() const noexcept; + deleter_type& get_deleter() noexcept; + const deleter_type& get_deleter() const noexcept; + explicit operator bool() const noexcept; + + // modifiers + pointer release() noexcept; + void reset(pointer p = pointer()) noexcept; + void swap(unique_ptr& u) noexcept; +}; + +template <class T, class D> +class unique_ptr<T[], D> +{ +public: + typedef implementation-defined pointer; + typedef T element_type; + typedef D deleter_type; + + // constructors + constexpr unique_ptr() noexcept; + explicit unique_ptr(pointer p) noexcept; + unique_ptr(pointer p, see below d) noexcept; + unique_ptr(pointer p, see below d) noexcept; + unique_ptr(unique_ptr&& u) noexcept; + unique_ptr(nullptr_t) noexcept : unique_ptr() { } + + // destructor + ~unique_ptr(); + + // assignment + unique_ptr& operator=(unique_ptr&& u) noexcept; + unique_ptr& operator=(nullptr_t) noexcept; + + // observers + T& operator[](size_t i) const; + pointer get() const noexcept; + deleter_type& get_deleter() noexcept; + const deleter_type& get_deleter() const noexcept; + explicit operator bool() const noexcept; + + // modifiers + pointer release() noexcept; + void reset(pointer p = pointer()) noexcept; + void reset(nullptr_t) noexcept; + template <class U> void reset(U) = delete; + void swap(unique_ptr& u) noexcept; +}; + +template <class T, class D> + void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept; + +template <class T1, class D1, class T2, class D2> + bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); +template <class T1, class D1, class T2, class D2> + bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); +template <class T1, class D1, class T2, class D2> + bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); +template <class T1, class D1, class T2, class D2> + bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); +template <class T1, class D1, class T2, class D2> + bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); +template <class T1, class D1, class T2, class D2> + bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +template <class T, class D> + bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; +template <class T, class D> + bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; +template <class T, class D> + bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; +template <class T, class D> + bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; + +template <class T, class D> + bool operator<(const unique_ptr<T, D>& x, nullptr_t); +template <class T, class D> + bool operator<(nullptr_t, const unique_ptr<T, D>& y); +template <class T, class D> + bool operator<=(const unique_ptr<T, D>& x, nullptr_t); +template <class T, class D> + bool operator<=(nullptr_t, const unique_ptr<T, D>& y); +template <class T, class D> + bool operator>(const unique_ptr<T, D>& x, nullptr_t); +template <class T, class D> + bool operator>(nullptr_t, const unique_ptr<T, D>& y); +template <class T, class D> + bool operator>=(const unique_ptr<T, D>& x, nullptr_t); +template <class T, class D> + bool operator>=(nullptr_t, const unique_ptr<T, D>& y); + +class bad_weak_ptr + : public std::exception +{ + bad_weak_ptr() noexcept; +}; + +template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14 +template<class T> unique_ptr<T> make_unique(size_t n); // C++14 +template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] + +template<class E, class T, class Y, class D> + basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p); + +template<class T> +class shared_ptr +{ +public: + typedef T element_type; + typedef weak_ptr<T> weak_type; // C++17 + + // constructors: + constexpr shared_ptr() noexcept; + template<class Y> explicit shared_ptr(Y* p); + template<class Y, class D> shared_ptr(Y* p, D d); + template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); + template <class D> shared_ptr(nullptr_t p, D d); + template <class D, class A> shared_ptr(nullptr_t p, D d, A a); + template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept; + shared_ptr(const shared_ptr& r) noexcept; + template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept; + shared_ptr(shared_ptr&& r) noexcept; + template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept; + template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); + template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17 + template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r); + shared_ptr(nullptr_t) : shared_ptr() { } + + // destructor: + ~shared_ptr(); + + // assignment: + shared_ptr& operator=(const shared_ptr& r) noexcept; + template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept; + shared_ptr& operator=(shared_ptr&& r) noexcept; + template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); + template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17 + template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); + + // modifiers: + void swap(shared_ptr& r) noexcept; + void reset() noexcept; + template<class Y> void reset(Y* p); + template<class Y, class D> void reset(Y* p, D d); + template<class Y, class D, class A> void reset(Y* p, D d, A a); + + // observers: + T* get() const noexcept; + T& operator*() const noexcept; + T* operator->() const noexcept; + long use_count() const noexcept; + bool unique() const noexcept; + explicit operator bool() const noexcept; + template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; + template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; +}; + +// shared_ptr comparisons: +template<class T, class U> + bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; +template<class T, class U> + bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; +template<class T, class U> + bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; +template<class T, class U> + bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; +template<class T, class U> + bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; +template<class T, class U> + bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; + +template <class T> + bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; +template <class T> + bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; +template <class T> + bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; +template <class T> + bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; +template <class T> + bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; +template <class T> +bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; +template <class T> + bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; +template <class T> + bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; +template <class T> + bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; +template <class T> + bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; +template <class T> + bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; +template <class T> + bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; + +// shared_ptr specialized algorithms: +template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept; + +// shared_ptr casts: +template<class T, class U> + shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept; +template<class T, class U> + shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept; +template<class T, class U> + shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept; + +// shared_ptr I/O: +template<class E, class T, class Y> + basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p); + +// shared_ptr get_deleter: +template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept; + +template<class T, class... Args> + shared_ptr<T> make_shared(Args&&... args); +template<class T, class A, class... Args> + shared_ptr<T> allocate_shared(const A& a, Args&&... args); + +template<class T> +class weak_ptr +{ +public: + typedef T element_type; + + // constructors + constexpr weak_ptr() noexcept; + template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept; + weak_ptr(weak_ptr const& r) noexcept; + template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept; + weak_ptr(weak_ptr&& r) noexcept; // C++14 + template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14 + + // destructor + ~weak_ptr(); + + // assignment + weak_ptr& operator=(weak_ptr const& r) noexcept; + template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept; + template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept; + weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14 + template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14 + + // modifiers + void swap(weak_ptr& r) noexcept; + void reset() noexcept; + + // observers + long use_count() const noexcept; + bool expired() const noexcept; + shared_ptr<T> lock() const noexcept; + template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; + template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; +}; + +// weak_ptr specialized algorithms: +template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept; + +// class owner_less: +template<class T> struct owner_less; + +template<class T> +struct owner_less<shared_ptr<T>> + : binary_function<shared_ptr<T>, shared_ptr<T>, bool> +{ + typedef bool result_type; + bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept; + bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; + bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; +}; + +template<class T> +struct owner_less<weak_ptr<T>> + : binary_function<weak_ptr<T>, weak_ptr<T>, bool> +{ + typedef bool result_type; + bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept; + bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; + bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; +}; + +template <> // Added in C++14 +struct owner_less<void> +{ + template <class _Tp, class _Up> + bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; + template <class _Tp, class _Up> + bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; + template <class _Tp, class _Up> + bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; + template <class _Tp, class _Up> + bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; + + typedef void is_transparent; +}; + +template<class T> +class enable_shared_from_this +{ +protected: + constexpr enable_shared_from_this() noexcept; + enable_shared_from_this(enable_shared_from_this const&) noexcept; + enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; + ~enable_shared_from_this(); +public: + shared_ptr<T> shared_from_this(); + shared_ptr<T const> shared_from_this() const; +}; + +template<class T> + bool atomic_is_lock_free(const shared_ptr<T>* p); +template<class T> + shared_ptr<T> atomic_load(const shared_ptr<T>* p); +template<class T> + shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo); +template<class T> + void atomic_store(shared_ptr<T>* p, shared_ptr<T> r); +template<class T> + void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); +template<class T> + shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r); +template<class T> + shared_ptr<T> + atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); +template<class T> + bool + atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); +template<class T> + bool + atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); +template<class T> + bool + atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, + shared_ptr<T> w, memory_order success, + memory_order failure); +template<class T> + bool + atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, + shared_ptr<T> w, memory_order success, + memory_order failure); +// Hash support +template <class T> struct hash; +template <class T, class D> struct hash<unique_ptr<T, D> >; +template <class T> struct hash<shared_ptr<T> >; + +template <class T, class Alloc> + inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; + +// Pointer safety +enum class pointer_safety { relaxed, preferred, strict }; +void declare_reachable(void *p); +template <class T> T *undeclare_reachable(T *p); +void declare_no_pointers(char *p, size_t n); +void undeclare_no_pointers(char *p, size_t n); +pointer_safety get_pointer_safety() noexcept; + +void* align(size_t alignment, size_t size, void*& ptr, size_t& space); + +} // std + +*/ + +#include <__config> +#include <type_traits> +#include <typeinfo> +#include <cstddef> +#include <cstdint> +#include <new> +#include <utility> +#include <limits> +#include <iterator> +#include <__functional_base> +#include <iosfwd> +#include <tuple> +#include <stdexcept> +#include <cstring> +#include <cassert> +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) +# include <atomic> +#endif +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +_ValueType __libcpp_relaxed_load(_ValueType const* __value) { +#if !defined(_LIBCPP_HAS_NO_THREADS) && \ + defined(__ATOMIC_RELAXED) && \ + (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) + return __atomic_load_n(__value, __ATOMIC_RELAXED); +#else + return *__value; +#endif +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +_ValueType __libcpp_acquire_load(_ValueType const* __value) { +#if !defined(_LIBCPP_HAS_NO_THREADS) && \ + defined(__ATOMIC_ACQUIRE) && \ + (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) + return __atomic_load_n(__value, __ATOMIC_ACQUIRE); +#else + return *__value; +#endif +} + +// addressof moved to <type_traits> + +template <class _Tp> class allocator; + +template <> +class _LIBCPP_TEMPLATE_VIS allocator<void> +{ +public: + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template <class _Up> struct rebind {typedef allocator<_Up> other;}; +}; + +template <> +class _LIBCPP_TEMPLATE_VIS allocator<const void> +{ +public: + typedef const void* pointer; + typedef const void* const_pointer; + typedef const void value_type; + + template <class _Up> struct rebind {typedef allocator<_Up> other;}; +}; + +// pointer_traits + +template <class _Tp, class = void> +struct __has_element_type : false_type {}; + +template <class _Tp> +struct __has_element_type<_Tp, + typename __void_t<typename _Tp::element_type>::type> : true_type {}; + +template <class _Ptr, bool = __has_element_type<_Ptr>::value> +struct __pointer_traits_element_type; + +template <class _Ptr> +struct __pointer_traits_element_type<_Ptr, true> +{ + typedef typename _Ptr::element_type type; +}; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template <template <class, class...> class _Sp, class _Tp, class ..._Args> +struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> +{ + typedef typename _Sp<_Tp, _Args...>::element_type type; +}; + +template <template <class, class...> class _Sp, class _Tp, class ..._Args> +struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> +{ + typedef _Tp type; +}; + +#else // _LIBCPP_HAS_NO_VARIADICS + +template <template <class> class _Sp, class _Tp> +struct __pointer_traits_element_type<_Sp<_Tp>, true> +{ + typedef typename _Sp<_Tp>::element_type type; +}; + +template <template <class> class _Sp, class _Tp> +struct __pointer_traits_element_type<_Sp<_Tp>, false> +{ + typedef _Tp type; +}; + +template <template <class, class> class _Sp, class _Tp, class _A0> +struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true> +{ + typedef typename _Sp<_Tp, _A0>::element_type type; +}; + +template <template <class, class> class _Sp, class _Tp, class _A0> +struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false> +{ + typedef _Tp type; +}; + +template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> +struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true> +{ + typedef typename _Sp<_Tp, _A0, _A1>::element_type type; +}; + +template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> +struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false> +{ + typedef _Tp type; +}; + +template <template <class, class, class, class> class _Sp, class _Tp, class _A0, + class _A1, class _A2> +struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true> +{ + typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type; +}; + +template <template <class, class, class, class> class _Sp, class _Tp, class _A0, + class _A1, class _A2> +struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false> +{ + typedef _Tp type; +}; + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template <class _Tp, class = void> +struct __has_difference_type : false_type {}; + +template <class _Tp> +struct __has_difference_type<_Tp, + typename __void_t<typename _Tp::difference_type>::type> : true_type {}; + +template <class _Ptr, bool = __has_difference_type<_Ptr>::value> +struct __pointer_traits_difference_type +{ + typedef ptrdiff_t type; +}; + +template <class _Ptr> +struct __pointer_traits_difference_type<_Ptr, true> +{ + typedef typename _Ptr::difference_type type; +}; + +template <class _Tp, class _Up> +struct __has_rebind +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Xp> static __two __test(...); + template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> +struct __pointer_traits_rebind +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename _Tp::template rebind<_Up> type; +#else + typedef typename _Tp::template rebind<_Up>::other type; +#endif +}; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type; +#else + typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; +#endif +}; + +template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> +{ + typedef _Sp<_Up, _Args...> type; +}; + +#else // _LIBCPP_HAS_NO_VARIADICS + +template <template <class> class _Sp, class _Tp, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true> +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename _Sp<_Tp>::template rebind<_Up> type; +#else + typedef typename _Sp<_Tp>::template rebind<_Up>::other type; +#endif +}; + +template <template <class> class _Sp, class _Tp, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false> +{ + typedef _Sp<_Up> type; +}; + +template <template <class, class> class _Sp, class _Tp, class _A0, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true> +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type; +#else + typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type; +#endif +}; + +template <template <class, class> class _Sp, class _Tp, class _A0, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false> +{ + typedef _Sp<_Up, _A0> type; +}; + +template <template <class, class, class> class _Sp, class _Tp, class _A0, + class _A1, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true> +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type; +#else + typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type; +#endif +}; + +template <template <class, class, class> class _Sp, class _Tp, class _A0, + class _A1, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false> +{ + typedef _Sp<_Up, _A0, _A1> type; +}; + +template <template <class, class, class, class> class _Sp, class _Tp, class _A0, + class _A1, class _A2, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true> +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type; +#else + typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; +#endif +}; + +template <template <class, class, class, class> class _Sp, class _Tp, class _A0, + class _A1, class _A2, class _Up> +struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false> +{ + typedef _Sp<_Up, _A0, _A1, _A2> type; +}; + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template <class _Ptr> +struct _LIBCPP_TEMPLATE_VIS pointer_traits +{ + typedef _Ptr pointer; + typedef typename __pointer_traits_element_type<pointer>::type element_type; + typedef typename __pointer_traits_difference_type<pointer>::type difference_type; + +#ifndef _LIBCPP_CXX03_LANG + template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type; +#else + template <class _Up> struct rebind + {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;}; +#endif // _LIBCPP_CXX03_LANG + +private: + struct __nat {}; +public: + _LIBCPP_INLINE_VISIBILITY + static pointer pointer_to(typename conditional<is_void<element_type>::value, + __nat, element_type>::type& __r) + {return pointer::pointer_to(__r);} +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> +{ + typedef _Tp* pointer; + typedef _Tp element_type; + typedef ptrdiff_t difference_type; + +#ifndef _LIBCPP_CXX03_LANG + template <class _Up> using rebind = _Up*; +#else + template <class _Up> struct rebind {typedef _Up* other;}; +#endif + +private: + struct __nat {}; +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + static pointer pointer_to(typename conditional<is_void<element_type>::value, + __nat, element_type>::type& __r) _NOEXCEPT + {return _VSTD::addressof(__r);} +}; + +template <class _From, class _To> +struct __rebind_pointer { +#ifndef _LIBCPP_CXX03_LANG + typedef typename pointer_traits<_From>::template rebind<_To> type; +#else + typedef typename pointer_traits<_From>::template rebind<_To>::other type; +#endif +}; + +// allocator_traits + +template <class _Tp, class = void> +struct __has_pointer_type : false_type {}; + +template <class _Tp> +struct __has_pointer_type<_Tp, + typename __void_t<typename _Tp::pointer>::type> : true_type {}; + +namespace __pointer_type_imp +{ + +template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value> +struct __pointer_type +{ + typedef typename _Dp::pointer type; +}; + +template <class _Tp, class _Dp> +struct __pointer_type<_Tp, _Dp, false> +{ + typedef _Tp* type; +}; + +} // __pointer_type_imp + +template <class _Tp, class _Dp> +struct __pointer_type +{ + typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type; +}; + +template <class _Tp, class = void> +struct __has_const_pointer : false_type {}; + +template <class _Tp> +struct __has_const_pointer<_Tp, + typename __void_t<typename _Tp::const_pointer>::type> : true_type {}; + +template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value> +struct __const_pointer +{ + typedef typename _Alloc::const_pointer type; +}; + +template <class _Tp, class _Ptr, class _Alloc> +struct __const_pointer<_Tp, _Ptr, _Alloc, false> +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type; +#else + typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type; +#endif +}; + +template <class _Tp, class = void> +struct __has_void_pointer : false_type {}; + +template <class _Tp> +struct __has_void_pointer<_Tp, + typename __void_t<typename _Tp::void_pointer>::type> : true_type {}; + +template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value> +struct __void_pointer +{ + typedef typename _Alloc::void_pointer type; +}; + +template <class _Ptr, class _Alloc> +struct __void_pointer<_Ptr, _Alloc, false> +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename pointer_traits<_Ptr>::template rebind<void> type; +#else + typedef typename pointer_traits<_Ptr>::template rebind<void>::other type; +#endif +}; + +template <class _Tp, class = void> +struct __has_const_void_pointer : false_type {}; + +template <class _Tp> +struct __has_const_void_pointer<_Tp, + typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {}; + +template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value> +struct __const_void_pointer +{ + typedef typename _Alloc::const_void_pointer type; +}; + +template <class _Ptr, class _Alloc> +struct __const_void_pointer<_Ptr, _Alloc, false> +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename pointer_traits<_Ptr>::template rebind<const void> type; +#else + typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type; +#endif +}; + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +_Tp* +__to_raw_pointer(_Tp* __p) _NOEXCEPT +{ + return __p; +} + +#if _LIBCPP_STD_VER <= 17 +template <class _Pointer> +inline _LIBCPP_INLINE_VISIBILITY +typename pointer_traits<_Pointer>::element_type* +__to_raw_pointer(_Pointer __p) _NOEXCEPT +{ + return _VSTD::__to_raw_pointer(__p.operator->()); +} +#else +template <class _Pointer> +inline _LIBCPP_INLINE_VISIBILITY +auto +__to_raw_pointer(const _Pointer& __p) _NOEXCEPT +-> decltype(pointer_traits<_Pointer>::to_address(__p)) +{ + return pointer_traits<_Pointer>::to_address(__p); +} + +template <class _Pointer, class... _None> +inline _LIBCPP_INLINE_VISIBILITY +auto +__to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT +{ + return _VSTD::__to_raw_pointer(__p.operator->()); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY constexpr +_Tp* +to_address(_Tp* __p) _NOEXCEPT +{ + static_assert(!is_function_v<_Tp>, "_Tp is a function type"); + return __p; +} + +template <class _Pointer> +inline _LIBCPP_INLINE_VISIBILITY +auto +to_address(const _Pointer& __p) _NOEXCEPT +{ + return _VSTD::__to_raw_pointer(__p); +} +#endif + +template <class _Tp, class = void> +struct __has_size_type : false_type {}; + +template <class _Tp> +struct __has_size_type<_Tp, + typename __void_t<typename _Tp::size_type>::type> : true_type {}; + +template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> +struct __size_type +{ + typedef typename make_unsigned<_DiffType>::type type; +}; + +template <class _Alloc, class _DiffType> +struct __size_type<_Alloc, _DiffType, true> +{ + typedef typename _Alloc::size_type type; +}; + +template <class _Tp, class = void> +struct __has_propagate_on_container_copy_assignment : false_type {}; + +template <class _Tp> +struct __has_propagate_on_container_copy_assignment<_Tp, + typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type> + : true_type {}; + +template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value> +struct __propagate_on_container_copy_assignment +{ + typedef false_type type; +}; + +template <class _Alloc> +struct __propagate_on_container_copy_assignment<_Alloc, true> +{ + typedef typename _Alloc::propagate_on_container_copy_assignment type; +}; + +template <class _Tp, class = void> +struct __has_propagate_on_container_move_assignment : false_type {}; + +template <class _Tp> +struct __has_propagate_on_container_move_assignment<_Tp, + typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type> + : true_type {}; + +template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value> +struct __propagate_on_container_move_assignment +{ + typedef false_type type; +}; + +template <class _Alloc> +struct __propagate_on_container_move_assignment<_Alloc, true> +{ + typedef typename _Alloc::propagate_on_container_move_assignment type; +}; + +template <class _Tp, class = void> +struct __has_propagate_on_container_swap : false_type {}; + +template <class _Tp> +struct __has_propagate_on_container_swap<_Tp, + typename __void_t<typename _Tp::propagate_on_container_swap>::type> + : true_type {}; + +template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value> +struct __propagate_on_container_swap +{ + typedef false_type type; +}; + +template <class _Alloc> +struct __propagate_on_container_swap<_Alloc, true> +{ + typedef typename _Alloc::propagate_on_container_swap type; +}; + +template <class _Tp, class = void> +struct __has_is_always_equal : false_type {}; + +template <class _Tp> +struct __has_is_always_equal<_Tp, + typename __void_t<typename _Tp::is_always_equal>::type> + : true_type {}; + +template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value> +struct __is_always_equal +{ + typedef typename _VSTD::is_empty<_Alloc>::type type; +}; + +template <class _Alloc> +struct __is_always_equal<_Alloc, true> +{ + typedef typename _Alloc::is_always_equal type; +}; + +template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> +struct __has_rebind_other +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Xp> static __two __test(...); + template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template <class _Tp, class _Up> +struct __has_rebind_other<_Tp, _Up, false> +{ + static const bool value = false; +}; + +template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> +struct __allocator_traits_rebind +{ + typedef typename _Tp::template rebind<_Up>::other type; +}; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> +{ + typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type; +}; + +template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> +{ + typedef _Alloc<_Up, _Args...> type; +}; + +#else // _LIBCPP_HAS_NO_VARIADICS + +template <template <class> class _Alloc, class _Tp, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true> +{ + typedef typename _Alloc<_Tp>::template rebind<_Up>::other type; +}; + +template <template <class> class _Alloc, class _Tp, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false> +{ + typedef _Alloc<_Up> type; +}; + +template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true> +{ + typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type; +}; + +template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false> +{ + typedef _Alloc<_Up, _A0> type; +}; + +template <template <class, class, class> class _Alloc, class _Tp, class _A0, + class _A1, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true> +{ + typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type; +}; + +template <template <class, class, class> class _Alloc, class _Tp, class _A0, + class _A1, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false> +{ + typedef _Alloc<_Up, _A0, _A1> type; +}; + +template <template <class, class, class, class> class _Alloc, class _Tp, class _A0, + class _A1, class _A2, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true> +{ + typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; +}; + +template <template <class, class, class, class> class _Alloc, class _Tp, class _A0, + class _A1, class _A2, class _Up> +struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false> +{ + typedef _Alloc<_Up, _A0, _A1, _A2> type; +}; + +#endif // _LIBCPP_HAS_NO_VARIADICS + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Alloc, class _SizeType, class _ConstVoidPtr> +auto +__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) + -> decltype((void)__a.allocate(__sz, __p), true_type()); + +template <class _Alloc, class _SizeType, class _ConstVoidPtr> +auto +__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) + -> false_type; + +template <class _Alloc, class _SizeType, class _ConstVoidPtr> +struct __has_allocate_hint + : integral_constant<bool, + is_same< + decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(), + declval<_SizeType>(), + declval<_ConstVoidPtr>())), + true_type>::value> +{ +}; + +#else // _LIBCPP_CXX03_LANG + +template <class _Alloc, class _SizeType, class _ConstVoidPtr> +struct __has_allocate_hint + : true_type +{ +}; + +#endif // _LIBCPP_CXX03_LANG + +#if !defined(_LIBCPP_CXX03_LANG) + +template <class _Alloc, class _Tp, class ..._Args> +decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(), + _VSTD::declval<_Args>()...), + true_type()) +__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args); + +template <class _Alloc, class _Pointer, class ..._Args> +false_type +__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args); + +template <class _Alloc, class _Pointer, class ..._Args> +struct __has_construct + : integral_constant<bool, + is_same< + decltype(_VSTD::__has_construct_test(declval<_Alloc>(), + declval<_Pointer>(), + declval<_Args>()...)), + true_type>::value> +{ +}; + +template <class _Alloc, class _Pointer> +auto +__has_destroy_test(_Alloc&& __a, _Pointer&& __p) + -> decltype(__a.destroy(__p), true_type()); + +template <class _Alloc, class _Pointer> +auto +__has_destroy_test(const _Alloc& __a, _Pointer&& __p) + -> false_type; + +template <class _Alloc, class _Pointer> +struct __has_destroy + : integral_constant<bool, + is_same< + decltype(_VSTD::__has_destroy_test(declval<_Alloc>(), + declval<_Pointer>())), + true_type>::value> +{ +}; + +template <class _Alloc> +auto +__has_max_size_test(_Alloc&& __a) + -> decltype(__a.max_size(), true_type()); + +template <class _Alloc> +auto +__has_max_size_test(const volatile _Alloc& __a) + -> false_type; + +template <class _Alloc> +struct __has_max_size + : integral_constant<bool, + is_same< + decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())), + true_type>::value> +{ +}; + +template <class _Alloc> +auto +__has_select_on_container_copy_construction_test(_Alloc&& __a) + -> decltype(__a.select_on_container_copy_construction(), true_type()); + +template <class _Alloc> +auto +__has_select_on_container_copy_construction_test(const volatile _Alloc& __a) + -> false_type; + +template <class _Alloc> +struct __has_select_on_container_copy_construction + : integral_constant<bool, + is_same< + decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())), + true_type>::value> +{ +}; + +#else // _LIBCPP_CXX03_LANG + +template <class _Alloc, class _Pointer, class _Tp, class = void> +struct __has_construct : std::false_type {}; + +template <class _Alloc, class _Pointer, class _Tp> +struct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t< + decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>())) +>::type> : std::true_type {}; + +template <class _Alloc, class _Pointer, class = void> +struct __has_destroy : false_type {}; + +template <class _Alloc, class _Pointer> +struct __has_destroy<_Alloc, _Pointer, typename __void_t< + decltype(_VSTD::declval<_Alloc>().destroy(_VSTD::declval<_Pointer>())) +>::type> : std::true_type {}; + +template <class _Alloc> +struct __has_max_size + : true_type +{ +}; + +template <class _Alloc> +struct __has_select_on_container_copy_construction + : false_type +{ +}; + +#endif // _LIBCPP_CXX03_LANG + +template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value> +struct __alloc_traits_difference_type +{ + typedef typename pointer_traits<_Ptr>::difference_type type; +}; + +template <class _Alloc, class _Ptr> +struct __alloc_traits_difference_type<_Alloc, _Ptr, true> +{ + typedef typename _Alloc::difference_type type; +}; + +template <class _Tp> +struct __is_default_allocator : false_type {}; + +template <class _Tp> +struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type {}; + +template <class _Alloc> +struct _LIBCPP_TEMPLATE_VIS allocator_traits +{ + typedef _Alloc allocator_type; + typedef typename allocator_type::value_type value_type; + + typedef typename __pointer_type<value_type, allocator_type>::type pointer; + typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer; + typedef typename __void_pointer<pointer, allocator_type>::type void_pointer; + typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer; + + typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type; + typedef typename __size_type<allocator_type, difference_type>::type size_type; + + typedef typename __propagate_on_container_copy_assignment<allocator_type>::type + propagate_on_container_copy_assignment; + typedef typename __propagate_on_container_move_assignment<allocator_type>::type + propagate_on_container_move_assignment; + typedef typename __propagate_on_container_swap<allocator_type>::type + propagate_on_container_swap; + typedef typename __is_always_equal<allocator_type>::type + is_always_equal; + +#ifndef _LIBCPP_CXX03_LANG + template <class _Tp> using rebind_alloc = + typename __allocator_traits_rebind<allocator_type, _Tp>::type; + template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; +#else // _LIBCPP_CXX03_LANG + template <class _Tp> struct rebind_alloc + {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;}; + template <class _Tp> struct rebind_traits + {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;}; +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + static pointer allocate(allocator_type& __a, size_type __n) + {return __a.allocate(__n);} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) + {return __allocate(__a, __n, __hint, + __has_allocate_hint<allocator_type, size_type, const_void_pointer>());} + + _LIBCPP_INLINE_VISIBILITY + static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT + {__a.deallocate(__p, __n);} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class _Tp, class... _Args> + _LIBCPP_INLINE_VISIBILITY + static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) + {__construct(__has_construct<allocator_type, _Tp*, _Args...>(), + __a, __p, _VSTD::forward<_Args>(__args)...);} +#else // _LIBCPP_HAS_NO_VARIADICS + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + static void construct(allocator_type&, _Tp* __p) + { + ::new ((void*)__p) _Tp(); + } + template <class _Tp, class _A0> + _LIBCPP_INLINE_VISIBILITY + static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0) + { + __construct(__has_construct<allocator_type, _Tp*, const _A0&>(), + __a, __p, __a0); + } + template <class _Tp, class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + static void construct(allocator_type&, _Tp* __p, const _A0& __a0, + const _A1& __a1) + { + ::new ((void*)__p) _Tp(__a0, __a1); + } + template <class _Tp, class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + static void construct(allocator_type&, _Tp* __p, const _A0& __a0, + const _A1& __a1, const _A2& __a2) + { + ::new ((void*)__p) _Tp(__a0, __a1, __a2); + } +#endif // _LIBCPP_HAS_NO_VARIADICS + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + static void destroy(allocator_type& __a, _Tp* __p) + {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);} + + _LIBCPP_INLINE_VISIBILITY + static size_type max_size(const allocator_type& __a) _NOEXCEPT + {return __max_size(__has_max_size<const allocator_type>(), __a);} + + _LIBCPP_INLINE_VISIBILITY + static allocator_type + select_on_container_copy_construction(const allocator_type& __a) + {return __select_on_container_copy_construction( + __has_select_on_container_copy_construction<const allocator_type>(), + __a);} + + template <class _Ptr> + _LIBCPP_INLINE_VISIBILITY + static + void + __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) + { + for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) + construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1)); + } + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + (__is_default_allocator<allocator_type>::value + || !__has_construct<allocator_type, _Tp*, _Tp>::value) && + is_trivially_move_constructible<_Tp>::value, + void + >::type + __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) + { + ptrdiff_t _Np = __end1 - __begin1; + if (_Np > 0) + { + _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); + __begin2 += _Np; + } + } + + template <class _Iter, class _Ptr> + _LIBCPP_INLINE_VISIBILITY + static + void + __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) + { + for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) + construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1); + } + + template <class _SourceTp, class _DestTp, + class _RawSourceTp = typename remove_const<_SourceTp>::type, + class _RawDestTp = typename remove_const<_DestTp>::type> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + is_trivially_move_constructible<_DestTp>::value && + is_same<_RawSourceTp, _RawDestTp>::value && + (__is_default_allocator<allocator_type>::value || + !__has_construct<allocator_type, _DestTp*, _SourceTp&>::value), + void + >::type + __construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2) + { + ptrdiff_t _Np = __end1 - __begin1; + if (_Np > 0) + { + _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp)); + __begin2 += _Np; + } + } + + template <class _Ptr> + _LIBCPP_INLINE_VISIBILITY + static + void + __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2) + { + while (__end1 != __begin1) + { + construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1)); + --__end2; + } + } + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + (__is_default_allocator<allocator_type>::value + || !__has_construct<allocator_type, _Tp*, _Tp>::value) && + is_trivially_move_constructible<_Tp>::value, + void + >::type + __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) + { + ptrdiff_t _Np = __end1 - __begin1; + __end2 -= _Np; + if (_Np > 0) + _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); + } + +private: + + _LIBCPP_INLINE_VISIBILITY + static pointer __allocate(allocator_type& __a, size_type __n, + const_void_pointer __hint, true_type) + {return __a.allocate(__n, __hint);} + _LIBCPP_INLINE_VISIBILITY + static pointer __allocate(allocator_type& __a, size_type __n, + const_void_pointer, false_type) + {return __a.allocate(__n);} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class _Tp, class... _Args> + _LIBCPP_INLINE_VISIBILITY + static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args) + {__a.construct(__p, _VSTD::forward<_Args>(__args)...);} + template <class _Tp, class... _Args> + _LIBCPP_INLINE_VISIBILITY + static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args) + { + ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...); + } +#else // _LIBCPP_HAS_NO_VARIADICS + template <class _Tp, class _A0> + _LIBCPP_INLINE_VISIBILITY + static void __construct(true_type, allocator_type& __a, _Tp* __p, + const _A0& __a0) + {__a.construct(__p, __a0);} + template <class _Tp, class _A0> + _LIBCPP_INLINE_VISIBILITY + static void __construct(false_type, allocator_type&, _Tp* __p, + const _A0& __a0) + { + ::new ((void*)__p) _Tp(__a0); + } +#endif // _LIBCPP_HAS_NO_VARIADICS + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + static void __destroy(true_type, allocator_type& __a, _Tp* __p) + {__a.destroy(__p);} + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + static void __destroy(false_type, allocator_type&, _Tp* __p) + { + __p->~_Tp(); + } + + _LIBCPP_INLINE_VISIBILITY + static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT + {return __a.max_size();} + _LIBCPP_INLINE_VISIBILITY + static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT + {return numeric_limits<size_type>::max() / sizeof(value_type);} + + _LIBCPP_INLINE_VISIBILITY + static allocator_type + __select_on_container_copy_construction(true_type, const allocator_type& __a) + {return __a.select_on_container_copy_construction();} + _LIBCPP_INLINE_VISIBILITY + static allocator_type + __select_on_container_copy_construction(false_type, const allocator_type& __a) + {return __a;} +}; + +template <class _Traits, class _Tp> +struct __rebind_alloc_helper +{ +#ifndef _LIBCPP_CXX03_LANG + typedef typename _Traits::template rebind_alloc<_Tp> type; +#else + typedef typename _Traits::template rebind_alloc<_Tp>::other type; +#endif +}; + +// allocator + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS allocator +{ +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + + typedef true_type propagate_on_container_move_assignment; + typedef true_type is_always_equal; + + template <class _Up> struct rebind {typedef allocator<_Up> other;}; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator() _NOEXCEPT {} + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator(const allocator<_Up>&) _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT + {return _VSTD::addressof(__x);} + _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT + {return _VSTD::addressof(__x);} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + pointer allocate(size_type __n, allocator<void>::const_pointer = 0) + { + if (__n > max_size()) + __throw_length_error("allocator<T>::allocate(size_t n)" + " 'n' exceeds maximum supported size"); + return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); + } + _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT + {_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));} + _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT + {return size_type(~0) / sizeof(_Tp);} +#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + template <class _Up, class... _Args> + _LIBCPP_INLINE_VISIBILITY + void + construct(_Up* __p, _Args&&... __args) + { + ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); + } +#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p) + { + ::new((void*)__p) _Tp(); + } +# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, _A0& __a0) + { + ::new((void*)__p) _Tp(__a0); + } + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, const _A0& __a0) + { + ::new((void*)__p) _Tp(__a0); + } +# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, _A0& __a0, _A1& __a1) + { + ::new((void*)__p) _Tp(__a0, __a1); + } + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, const _A0& __a0, _A1& __a1) + { + ::new((void*)__p) _Tp(__a0, __a1); + } + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, _A0& __a0, const _A1& __a1) + { + ::new((void*)__p) _Tp(__a0, __a1); + } + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, const _A0& __a0, const _A1& __a1) + { + ::new((void*)__p) _Tp(__a0, __a1); + } +#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} +}; + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS allocator<const _Tp> +{ +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef const _Tp* pointer; + typedef const _Tp* const_pointer; + typedef const _Tp& reference; + typedef const _Tp& const_reference; + typedef const _Tp value_type; + + typedef true_type propagate_on_container_move_assignment; + typedef true_type is_always_equal; + + template <class _Up> struct rebind {typedef allocator<_Up> other;}; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator() _NOEXCEPT {} + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator(const allocator<_Up>&) _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT + {return _VSTD::addressof(__x);} + _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) + { + if (__n > max_size()) + __throw_length_error("allocator<const T>::allocate(size_t n)" + " 'n' exceeds maximum supported size"); + return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); + } + _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT + {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));} + _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT + {return size_type(~0) / sizeof(_Tp);} +#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + template <class _Up, class... _Args> + _LIBCPP_INLINE_VISIBILITY + void + construct(_Up* __p, _Args&&... __args) + { + ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); + } +#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p) + { + ::new((void*) const_cast<_Tp *>(__p)) _Tp(); + } +# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, _A0& __a0) + { + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0); + } + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, const _A0& __a0) + { + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0); + } +# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, _A0& __a0, _A1& __a1) + { + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); + } + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, const _A0& __a0, _A1& __a1) + { + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); + } + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, _A0& __a0, const _A1& __a1) + { + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); + } + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + void + construct(pointer __p, const _A0& __a0, const _A1& __a1) + { + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); + } +#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} +}; + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} + +template <class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} + +template <class _OutputIterator, class _Tp> +class _LIBCPP_TEMPLATE_VIS raw_storage_iterator + : public iterator<output_iterator_tag, + _Tp, // purposefully not C++03 + ptrdiff_t, // purposefully not C++03 + _Tp*, // purposefully not C++03 + raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03 +{ +private: + _OutputIterator __x_; +public: + _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} + _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) + {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;} +#if _LIBCPP_STD_VER >= 14 + _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) + {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;} +#endif + _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} + _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) + {raw_storage_iterator __t(*this); ++__x_; return __t;} +#if _LIBCPP_STD_VER >= 14 + _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } +#endif +}; + +template <class _Tp> +_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI +pair<_Tp*, ptrdiff_t> +get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT +{ + pair<_Tp*, ptrdiff_t> __r(0, 0); + const ptrdiff_t __m = (~ptrdiff_t(0) ^ + ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) + / sizeof(_Tp); + if (__n > __m) + __n = __m; + while (__n > 0) + { +#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) + if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) + { + std::align_val_t __al = + std::align_val_t(std::alignment_of<_Tp>::value); + __r.first = static_cast<_Tp*>(::operator new( + __n * sizeof(_Tp), __al, nothrow)); + } else { + __r.first = static_cast<_Tp*>(::operator new( + __n * sizeof(_Tp), nothrow)); + } +#else + if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) + { + // Since aligned operator new is unavailable, return an empty + // buffer rather than one with invalid alignment. + return __r; + } + + __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); +#endif + + if (__r.first) + { + __r.second = __n; + break; + } + __n /= 2; + } + return __r; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void return_temporary_buffer(_Tp* __p) _NOEXCEPT +{ + _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); +} + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +template <class _Tp> +struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref +{ + _Tp* __ptr_; +}; + +template<class _Tp> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr +{ +private: + _Tp* __ptr_; +public: + typedef _Tp element_type; + + _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {} + _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {} + template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw() + : __ptr_(__p.release()) {} + _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw() + {reset(__p.release()); return *this;} + template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw() + {reset(__p.release()); return *this;} + _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw() + {reset(__p.__ptr_); return *this;} + _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;} + + _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw() + {return *__ptr_;} + _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;} + _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;} + _LIBCPP_INLINE_VISIBILITY _Tp* release() throw() + { + _Tp* __t = __ptr_; + __ptr_ = 0; + return __t; + } + _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw() + { + if (__ptr_ != __p) + delete __ptr_; + __ptr_ = __p; + } + + _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {} + template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw() + {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} + template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw() + {return auto_ptr<_Up>(release());} +}; + +template <> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> +{ +public: + typedef void element_type; +}; +#endif + +template <class _Tp, int _Idx, + bool _CanBeEmptyBase = + is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value> +struct __compressed_pair_elem { + typedef _Tp _ParamT; + typedef _Tp& reference; + typedef const _Tp& const_reference; + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {} + + template <class _Up, class = typename enable_if< + !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit + __compressed_pair_elem(_Up&& __u) + : __value_(_VSTD::forward<_Up>(__u)) + { + } + + template <class... _Args, size_t... _Indexes> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, + __tuple_indices<_Indexes...>) + : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} +#else + _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {} + _LIBCPP_INLINE_VISIBILITY + __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {} +#endif + + _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } + _LIBCPP_INLINE_VISIBILITY + const_reference __get() const _NOEXCEPT { return __value_; } + +private: + _Tp __value_; +}; + +template <class _Tp, int _Idx> +struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { + typedef _Tp _ParamT; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp __value_type; + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default; + + template <class _Up, class = typename enable_if< + !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit + __compressed_pair_elem(_Up&& __u) + : __value_type(_VSTD::forward<_Up>(__u)) + {} + + template <class... _Args, size_t... _Indexes> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, + __tuple_indices<_Indexes...>) + : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} +#else + _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {} + _LIBCPP_INLINE_VISIBILITY + __compressed_pair_elem(_ParamT __p) + : __value_type(std::forward<_ParamT>(__p)) {} +#endif + + _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } + _LIBCPP_INLINE_VISIBILITY + const_reference __get() const _NOEXCEPT { return *this; } +}; + +// Tag used to construct the second element of the compressed pair. +struct __second_tag {}; + +template <class _T1, class _T2> +class __compressed_pair : private __compressed_pair_elem<_T1, 0>, + private __compressed_pair_elem<_T2, 1> { + typedef __compressed_pair_elem<_T1, 0> _Base1; + typedef __compressed_pair_elem<_T2, 1> _Base2; + + // NOTE: This static assert should never fire because __compressed_pair + // is *almost never* used in a scenario where it's possible for T1 == T2. + // (The exception is std::function where it is possible that the function + // object and the allocator have the same type). + static_assert((!is_same<_T1, _T2>::value), + "__compressed_pair cannot be instantated when T1 and T2 are the same type; " + "The current implementation is NOT ABI-compatible with the previous " + "implementation for this configuration"); + +public: +#ifndef _LIBCPP_CXX03_LANG + template <bool _Dummy = true, + class = typename enable_if< + __dependent_type<is_default_constructible<_T1>, _Dummy>::value && + __dependent_type<is_default_constructible<_T2>, _Dummy>::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + constexpr __compressed_pair() {} + + template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type, + __compressed_pair>::value, + bool>::type = true> + _LIBCPP_INLINE_VISIBILITY constexpr explicit + __compressed_pair(_Tp&& __t) + : _Base1(std::forward<_Tp>(__t)), _Base2() {} + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY constexpr + __compressed_pair(__second_tag, _Tp&& __t) + : _Base1(), _Base2(std::forward<_Tp>(__t)) {} + + template <class _U1, class _U2> + _LIBCPP_INLINE_VISIBILITY constexpr + __compressed_pair(_U1&& __t1, _U2&& __t2) + : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} + + template <class... _Args1, class... _Args2> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, + tuple<_Args2...> __second_args) + : _Base1(__pc, _VSTD::move(__first_args), + typename __make_tuple_indices<sizeof...(_Args1)>::type()), + _Base2(__pc, _VSTD::move(__second_args), + typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} + +#else + _LIBCPP_INLINE_VISIBILITY + __compressed_pair() {} + + _LIBCPP_INLINE_VISIBILITY explicit + __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {} + + _LIBCPP_INLINE_VISIBILITY + __compressed_pair(__second_tag, _T2 __t2) + : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {} + + _LIBCPP_INLINE_VISIBILITY + __compressed_pair(_T1 __t1, _T2 __t2) + : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + typename _Base1::reference first() _NOEXCEPT { + return static_cast<_Base1&>(*this).__get(); + } + + _LIBCPP_INLINE_VISIBILITY + typename _Base1::const_reference first() const _NOEXCEPT { + return static_cast<_Base1 const&>(*this).__get(); + } + + _LIBCPP_INLINE_VISIBILITY + typename _Base2::reference second() _NOEXCEPT { + return static_cast<_Base2&>(*this).__get(); + } + + _LIBCPP_INLINE_VISIBILITY + typename _Base2::const_reference second() const _NOEXCEPT { + return static_cast<_Base2 const&>(*this).__get(); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(__compressed_pair& __x) + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && + __is_nothrow_swappable<_T2>::value) + { + using std::swap; + swap(first(), __x.first()); + swap(second(), __x.second()); + } +}; + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && + __is_nothrow_swappable<_T2>::value) { + __x.swap(__y); +} + +// default_delete + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS default_delete { + static_assert(!is_function<_Tp>::value, + "default_delete cannot be instantiated for function types"); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; +#else + _LIBCPP_INLINE_VISIBILITY default_delete() {} +#endif + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + default_delete(const default_delete<_Up>&, + typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = + 0) _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT { + static_assert(sizeof(_Tp) > 0, + "default_delete can not delete incomplete type"); + static_assert(!is_void<_Tp>::value, + "default_delete can not delete incomplete type"); + delete __ptr; + } +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> { +private: + template <class _Up> + struct _EnableIfConvertible + : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; + +public: +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; +#else + _LIBCPP_INLINE_VISIBILITY default_delete() {} +#endif + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + default_delete(const default_delete<_Up[]>&, + typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {} + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + typename _EnableIfConvertible<_Up>::type + operator()(_Up* __ptr) const _NOEXCEPT { + static_assert(sizeof(_Tp) > 0, + "default_delete can not delete incomplete type"); + static_assert(!is_void<_Tp>::value, + "default_delete can not delete void type"); + delete[] __ptr; + } +}; + + + +#ifndef _LIBCPP_CXX03_LANG +template <class _Deleter> +struct __unique_ptr_deleter_sfinae { + static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); + typedef const _Deleter& __lval_ref_type; + typedef _Deleter&& __good_rval_ref_type; + typedef true_type __enable_rval_overload; +}; + +template <class _Deleter> +struct __unique_ptr_deleter_sfinae<_Deleter const&> { + typedef const _Deleter& __lval_ref_type; + typedef const _Deleter&& __bad_rval_ref_type; + typedef false_type __enable_rval_overload; +}; + +template <class _Deleter> +struct __unique_ptr_deleter_sfinae<_Deleter&> { + typedef _Deleter& __lval_ref_type; + typedef _Deleter&& __bad_rval_ref_type; + typedef false_type __enable_rval_overload; +}; +#endif // !defined(_LIBCPP_CXX03_LANG) + +template <class _Tp, class _Dp = default_delete<_Tp> > +class _LIBCPP_TEMPLATE_VIS unique_ptr { +public: + typedef _Tp element_type; + typedef _Dp deleter_type; + typedef typename __pointer_type<_Tp, deleter_type>::type pointer; + + static_assert(!is_rvalue_reference<deleter_type>::value, + "the specified deleter type cannot be an rvalue reference"); + +private: + __compressed_pair<pointer, deleter_type> __ptr_; + + struct __nat { int __for_bool_; }; + +#ifndef _LIBCPP_CXX03_LANG + typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; + + template <bool _Dummy> + using _LValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; + + template <bool _Dummy> + using _GoodRValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; + + template <bool _Dummy> + using _BadRValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; + + template <bool _Dummy, class _Deleter = typename __dependent_type< + __identity<deleter_type>, _Dummy>::type> + using _EnableIfDeleterDefaultConstructible = + typename enable_if<is_default_constructible<_Deleter>::value && + !is_pointer<_Deleter>::value>::type; + + template <class _ArgType> + using _EnableIfDeleterConstructible = + typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; + + template <class _UPtr, class _Up> + using _EnableIfMoveConvertible = typename enable_if< + is_convertible<typename _UPtr::pointer, pointer>::value && + !is_array<_Up>::value + >::type; + + template <class _UDel> + using _EnableIfDeleterConvertible = typename enable_if< + (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || + (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) + >::type; + + template <class _UDel> + using _EnableIfDeleterAssignable = typename enable_if< + is_assignable<_Dp&, _UDel&&>::value + >::type; + +public: + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + constexpr unique_ptr() noexcept : __ptr_(pointer()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept + : __ptr_(__p, __d) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept + : __ptr_(__p, _VSTD::move(__d)) { + static_assert(!is_reference<deleter_type>::value, + "rvalue deleter bound to reference"); + } + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; + + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr&& __u) noexcept + : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { + } + + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterConvertible<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT + : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(auto_ptr<_Up>&& __p, + typename enable_if<is_convertible<_Up*, _Tp*>::value && + is_same<_Dp, default_delete<_Tp>>::value, + __nat>::type = __nat()) _NOEXCEPT + : __ptr_(__p.release()) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); + return *this; + } + + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterAssignable<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); + return *this; + } + +#else // _LIBCPP_CXX03_LANG +private: + unique_ptr(unique_ptr&); + template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&); + + unique_ptr& operator=(unique_ptr&); + template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&); + +public: + _LIBCPP_INLINE_VISIBILITY + unique_ptr() : __ptr_(pointer()) + { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + static_assert(is_default_constructible<deleter_type>::value, + "unique_ptr::deleter_type is not default constructible"); + } + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t) : __ptr_(pointer()) + { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(pointer __p) + : __ptr_(_VSTD::move(__p)) { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } + + _LIBCPP_INLINE_VISIBILITY + operator __rv<unique_ptr>() { + return __rv<unique_ptr>(*this); + } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr(__rv<unique_ptr> __u) + : __ptr_(__u->release(), + _VSTD::forward<deleter_type>(__u->get_deleter())) {} + + template <class _Up, class _Ep> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + !is_array<_Up>::value && + is_convertible<typename unique_ptr<_Up, _Ep>::pointer, + pointer>::value && + is_assignable<deleter_type&, _Ep&>::value, + unique_ptr&>::type + operator=(unique_ptr<_Up, _Ep> __u) { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, deleter_type __d) + : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {} +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<is_convertible<_Up*, _Tp*>::value && + is_same<_Dp, default_delete<_Tp> >::value, + unique_ptr&>::type + operator=(auto_ptr<_Up> __p) { + reset(__p.release()); + return *this; + } +#endif + + _LIBCPP_INLINE_VISIBILITY + ~unique_ptr() { reset(); } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(nullptr_t) _NOEXCEPT { + reset(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + typename add_lvalue_reference<_Tp>::type + operator*() const { + return *__ptr_.first(); + } + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const _NOEXCEPT { + return __ptr_.first(); + } + _LIBCPP_INLINE_VISIBILITY + pointer get() const _NOEXCEPT { + return __ptr_.first(); + } + _LIBCPP_INLINE_VISIBILITY + deleter_type& get_deleter() _NOEXCEPT { + return __ptr_.second(); + } + _LIBCPP_INLINE_VISIBILITY + const deleter_type& get_deleter() const _NOEXCEPT { + return __ptr_.second(); + } + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { + return __ptr_.first() != nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + pointer release() _NOEXCEPT { + pointer __t = __ptr_.first(); + __ptr_.first() = pointer(); + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + void reset(pointer __p = pointer()) _NOEXCEPT { + pointer __tmp = __ptr_.first(); + __ptr_.first() = __p; + if (__tmp) + __ptr_.second()(__tmp); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(unique_ptr& __u) _NOEXCEPT { + __ptr_.swap(__u.__ptr_); + } +}; + + +template <class _Tp, class _Dp> +class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> { +public: + typedef _Tp element_type; + typedef _Dp deleter_type; + typedef typename __pointer_type<_Tp, deleter_type>::type pointer; + +private: + __compressed_pair<pointer, deleter_type> __ptr_; + + template <class _From> + struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; + + template <class _FromElem> + struct _CheckArrayPointerConversion<_FromElem*> + : integral_constant<bool, + is_same<_FromElem*, pointer>::value || + (is_same<pointer, element_type*>::value && + is_convertible<_FromElem(*)[], element_type(*)[]>::value) + > + {}; + +#ifndef _LIBCPP_CXX03_LANG + typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; + + template <bool _Dummy> + using _LValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; + + template <bool _Dummy> + using _GoodRValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; + + template <bool _Dummy> + using _BadRValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; + + template <bool _Dummy, class _Deleter = typename __dependent_type< + __identity<deleter_type>, _Dummy>::type> + using _EnableIfDeleterDefaultConstructible = + typename enable_if<is_default_constructible<_Deleter>::value && + !is_pointer<_Deleter>::value>::type; + + template <class _ArgType> + using _EnableIfDeleterConstructible = + typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; + + template <class _Pp> + using _EnableIfPointerConvertible = typename enable_if< + _CheckArrayPointerConversion<_Pp>::value + >::type; + + template <class _UPtr, class _Up, + class _ElemT = typename _UPtr::element_type> + using _EnableIfMoveConvertible = typename enable_if< + is_array<_Up>::value && + is_same<pointer, element_type*>::value && + is_same<typename _UPtr::pointer, _ElemT*>::value && + is_convertible<_ElemT(*)[], element_type(*)[]>::value + >::type; + + template <class _UDel> + using _EnableIfDeleterConvertible = typename enable_if< + (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || + (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) + >::type; + + template <class _UDel> + using _EnableIfDeleterAssignable = typename enable_if< + is_assignable<_Dp&, _UDel&&>::value + >::type; + +public: + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + constexpr unique_ptr() noexcept : __ptr_(pointer()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>, + class = _EnableIfPointerConvertible<_Pp>> + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(_Pp __p) noexcept + : __ptr_(__p) {} + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>, + class = _EnableIfPointerConvertible<_Pp>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept + : __ptr_(__p, __d) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept + : __ptr_(nullptr, __d) {} + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>, + class = _EnableIfPointerConvertible<_Pp>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept + : __ptr_(__p, _VSTD::move(__d)) { + static_assert(!is_reference<deleter_type>::value, + "rvalue deleter bound to reference"); + } + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept + : __ptr_(nullptr, _VSTD::move(__d)) { + static_assert(!is_reference<deleter_type>::value, + "rvalue deleter bound to reference"); + } + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>, + class = _EnableIfPointerConvertible<_Pp>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; + + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr&& __u) noexcept + : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { + } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(unique_ptr&& __u) noexcept { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); + return *this; + } + + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterConvertible<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept + : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) { + } + + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterAssignable<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr& + operator=(unique_ptr<_Up, _Ep>&& __u) noexcept { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); + return *this; + } + +#else // _LIBCPP_CXX03_LANG +private: + template <class _Up> explicit unique_ptr(_Up); + + unique_ptr(unique_ptr&); + template <class _Up> unique_ptr(unique_ptr<_Up>&); + + unique_ptr& operator=(unique_ptr&); + template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&); + + template <class _Up> + unique_ptr(_Up __u, + typename conditional< + is_reference<deleter_type>::value, deleter_type, + typename add_lvalue_reference<const deleter_type>::type>::type, + typename enable_if<is_convertible<_Up, pointer>::value, + __nat>::type = __nat()); +public: + _LIBCPP_INLINE_VISIBILITY + unique_ptr() : __ptr_(pointer()) { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t) : __ptr_(pointer()) { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } + + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(pointer __p) : __ptr_(__p) { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, deleter_type __d) + : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {} + + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t, deleter_type __d) + : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {} + + _LIBCPP_INLINE_VISIBILITY + operator __rv<unique_ptr>() { + return __rv<unique_ptr>(*this); + } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr(__rv<unique_ptr> __u) + : __ptr_(__u->release(), + _VSTD::forward<deleter_type>(__u->get_deleter())) {} + + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(__rv<unique_ptr> __u) { + reset(__u->release()); + __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter()); + return *this; + } + +#endif // _LIBCPP_CXX03_LANG + +public: + _LIBCPP_INLINE_VISIBILITY + ~unique_ptr() { reset(); } + + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(nullptr_t) _NOEXCEPT { + reset(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + typename add_lvalue_reference<_Tp>::type + operator[](size_t __i) const { + return __ptr_.first()[__i]; + } + _LIBCPP_INLINE_VISIBILITY + pointer get() const _NOEXCEPT { + return __ptr_.first(); + } + + _LIBCPP_INLINE_VISIBILITY + deleter_type& get_deleter() _NOEXCEPT { + return __ptr_.second(); + } + + _LIBCPP_INLINE_VISIBILITY + const deleter_type& get_deleter() const _NOEXCEPT { + return __ptr_.second(); + } + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { + return __ptr_.first() != nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + pointer release() _NOEXCEPT { + pointer __t = __ptr_.first(); + __ptr_.first() = pointer(); + return __t; + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + _CheckArrayPointerConversion<_Pp>::value + >::type + reset(_Pp __p) _NOEXCEPT { + pointer __tmp = __ptr_.first(); + __ptr_.first() = __p; + if (__tmp) + __ptr_.second()(__tmp); + } + + _LIBCPP_INLINE_VISIBILITY + void reset(nullptr_t = nullptr) _NOEXCEPT { + pointer __tmp = __ptr_.first(); + __ptr_.first() = nullptr; + if (__tmp) + __ptr_.second()(__tmp); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(unique_ptr& __u) _NOEXCEPT { + __ptr_.swap(__u.__ptr_); + } + +}; + +template <class _Tp, class _Dp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + __is_swappable<_Dp>::value, + void +>::type +swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);} + +template <class _T1, class _D1, class _T2, class _D2> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} + +template <class _T1, class _D1, class _T2, class _D2> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} + +template <class _T1, class _D1, class _T2, class _D2> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) +{ + typedef typename unique_ptr<_T1, _D1>::pointer _P1; + typedef typename unique_ptr<_T2, _D2>::pointer _P2; + typedef typename common_type<_P1, _P2>::type _Vp; + return less<_Vp>()(__x.get(), __y.get()); +} + +template <class _T1, class _D1, class _T2, class _D2> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} + +template <class _T1, class _D1, class _T2, class _D2> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} + +template <class _T1, class _D1, class _T2, class _D2> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT +{ + return !__x; +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT +{ + return !__x; +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT +{ + return static_cast<bool>(__x); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT +{ + return static_cast<bool>(__x); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) +{ + typedef typename unique_ptr<_T1, _D1>::pointer _P1; + return less<_P1>()(__x.get(), nullptr); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) +{ + typedef typename unique_ptr<_T1, _D1>::pointer _P1; + return less<_P1>()(nullptr, __x.get()); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) +{ + return nullptr < __x; +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) +{ + return __x < nullptr; +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) +{ + return !(nullptr < __x); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) +{ + return !(__x < nullptr); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) +{ + return !(__x < nullptr); +} + +template <class _T1, class _D1> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) +{ + return !(nullptr < __x); +} + +#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp, class _Dp> +inline _LIBCPP_INLINE_VISIBILITY +unique_ptr<_Tp, _Dp> +move(unique_ptr<_Tp, _Dp>& __t) +{ + return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t)); +} + +#endif + +#if _LIBCPP_STD_VER > 11 + +template<class _Tp> +struct __unique_if +{ + typedef unique_ptr<_Tp> __unique_single; +}; + +template<class _Tp> +struct __unique_if<_Tp[]> +{ + typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; +}; + +template<class _Tp, size_t _Np> +struct __unique_if<_Tp[_Np]> +{ + typedef void __unique_array_known_bound; +}; + +template<class _Tp, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +typename __unique_if<_Tp>::__unique_single +make_unique(_Args&&... __args) +{ + return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename __unique_if<_Tp>::__unique_array_unknown_bound +make_unique(size_t __n) +{ + typedef typename remove_extent<_Tp>::type _Up; + return unique_ptr<_Tp>(new _Up[__n]()); +} + +template<class _Tp, class... _Args> + typename __unique_if<_Tp>::__unique_array_known_bound + make_unique(_Args&&...) = delete; + +#endif // _LIBCPP_STD_VER > 11 + +template <class _Tp, class _Dp> +#ifdef _LIBCPP_CXX03_LANG +struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> > +#else +struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< + unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>> +#endif +{ + typedef unique_ptr<_Tp, _Dp> argument_type; + typedef size_t result_type; + _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type& __ptr) const + { + typedef typename argument_type::pointer pointer; + return hash<pointer>()(__ptr.get()); + } +}; + +struct __destruct_n +{ +private: + size_t __size_; + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT + {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT + {++__size_;} + _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT + {__size_ = __s;} + _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT + {} +public: + _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT + : __size_(__s) {} + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT + {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT + {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT + {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} +}; + +template <class _Alloc> +class __allocator_destructor +{ + typedef allocator_traits<_Alloc> __alloc_traits; +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::size_type size_type; +private: + _Alloc& __alloc_; + size_type __s_; +public: + _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) + _NOEXCEPT + : __alloc_(__a), __s_(__s) {} + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + {__alloc_traits::deallocate(__alloc_, __p, __s_);} +}; + +template <class _InputIterator, class _ForwardIterator> +_ForwardIterator +uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; +#ifndef _LIBCPP_NO_EXCEPTIONS + _ForwardIterator __s = __r; + try + { +#endif + for (; __f != __l; ++__f, (void) ++__r) + ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (; __s != __r; ++__s) + __s->~value_type(); + throw; + } +#endif + return __r; +} + +template <class _InputIterator, class _Size, class _ForwardIterator> +_ForwardIterator +uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; +#ifndef _LIBCPP_NO_EXCEPTIONS + _ForwardIterator __s = __r; + try + { +#endif + for (; __n > 0; ++__f, (void) ++__r, (void) --__n) + ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (; __s != __r; ++__s) + __s->~value_type(); + throw; + } +#endif + return __r; +} + +template <class _ForwardIterator, class _Tp> +void +uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; +#ifndef _LIBCPP_NO_EXCEPTIONS + _ForwardIterator __s = __f; + try + { +#endif + for (; __f != __l; ++__f) + ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (; __s != __f; ++__s) + __s->~value_type(); + throw; + } +#endif +} + +template <class _ForwardIterator, class _Size, class _Tp> +_ForwardIterator +uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; +#ifndef _LIBCPP_NO_EXCEPTIONS + _ForwardIterator __s = __f; + try + { +#endif + for (; __n > 0; ++__f, (void) --__n) + ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (; __s != __f; ++__s) + __s->~value_type(); + throw; + } +#endif + return __f; +} + +#if _LIBCPP_STD_VER > 14 + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void destroy_at(_Tp* __loc) { + _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); + __loc->~_Tp(); +} + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +void destroy(_ForwardIterator __first, _ForwardIterator __last) { + for (; __first != __last; ++__first) + _VSTD::destroy_at(_VSTD::addressof(*__first)); +} + +template <class _ForwardIterator, class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { + for (; __n > 0; (void)++__first, --__n) + _VSTD::destroy_at(_VSTD::addressof(*__first)); + return __first; +} + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __idx != __last; ++__idx) + ::new((void*)_VSTD::addressof(*__idx)) _Vt; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + +template <class _ForwardIterator, class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __n > 0; (void)++__idx, --__n) + ::new((void*)_VSTD::addressof(*__idx)) _Vt; + return __idx; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __idx != __last; ++__idx) + ::new((void*)_VSTD::addressof(*__idx)) _Vt(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + +template <class _ForwardIterator, class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __n > 0; (void)++__idx, --__n) + ::new((void*)_VSTD::addressof(*__idx)) _Vt(); + return __idx; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + + +template <class _InputIt, class _ForwardIt> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) { + using _Vt = typename iterator_traits<_ForwardIt>::value_type; + auto __idx = __first_res; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __first != __last; (void)++__idx, ++__first) + ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); + return __idx; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first_res, __idx); + throw; + } +#endif +} + +template <class _InputIt, class _Size, class _ForwardIt> +inline _LIBCPP_INLINE_VISIBILITY +pair<_InputIt, _ForwardIt> +uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { + using _Vt = typename iterator_traits<_ForwardIt>::value_type; + auto __idx = __first_res; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __n > 0; ++__idx, (void)++__first, --__n) + ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); + return {__first, __idx}; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first_res, __idx); + throw; + } +#endif +} + + +#endif // _LIBCPP_STD_VER > 14 + +// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively) +// should be sufficient for thread safety. +// See https://bugs.llvm.org/show_bug.cgi?id=22803 +#if defined(__clang__) && __has_builtin(__atomic_add_fetch) \ + && defined(__ATOMIC_RELAXED) \ + && defined(__ATOMIC_ACQ_REL) +# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT +#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407 +# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT +#endif + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _Tp +__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT +{ +#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) + return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED); +#else + return __t += 1; +#endif +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _Tp +__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT +{ +#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) + return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL); +#else + return __t -= 1; +#endif +} + +class _LIBCPP_EXCEPTION_ABI bad_weak_ptr + : public std::exception +{ +public: + virtual ~bad_weak_ptr() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_bad_weak_ptr() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_weak_ptr(); +#else + _VSTD::abort(); +#endif +} + +template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr; + +class _LIBCPP_TYPE_VIS __shared_count +{ + __shared_count(const __shared_count&); + __shared_count& operator=(const __shared_count&); + +protected: + long __shared_owners_; + virtual ~__shared_count(); +private: + virtual void __on_zero_shared() _NOEXCEPT = 0; + +public: + _LIBCPP_INLINE_VISIBILITY + explicit __shared_count(long __refs = 0) _NOEXCEPT + : __shared_owners_(__refs) {} + +#if defined(_LIBCPP_BUILDING_LIBRARY) && \ + defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) + void __add_shared() _NOEXCEPT; + bool __release_shared() _NOEXCEPT; +#else + _LIBCPP_INLINE_VISIBILITY + void __add_shared() _NOEXCEPT { + __libcpp_atomic_refcount_increment(__shared_owners_); + } + _LIBCPP_INLINE_VISIBILITY + bool __release_shared() _NOEXCEPT { + if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { + __on_zero_shared(); + return true; + } + return false; + } +#endif + _LIBCPP_INLINE_VISIBILITY + long use_count() const _NOEXCEPT { + return __libcpp_relaxed_load(&__shared_owners_) + 1; + } +}; + +class _LIBCPP_TYPE_VIS __shared_weak_count + : private __shared_count +{ + long __shared_weak_owners_; + +public: + _LIBCPP_INLINE_VISIBILITY + explicit __shared_weak_count(long __refs = 0) _NOEXCEPT + : __shared_count(__refs), + __shared_weak_owners_(__refs) {} +protected: + virtual ~__shared_weak_count(); + +public: +#if defined(_LIBCPP_BUILDING_LIBRARY) && \ + defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) + void __add_shared() _NOEXCEPT; + void __add_weak() _NOEXCEPT; + void __release_shared() _NOEXCEPT; +#else + _LIBCPP_INLINE_VISIBILITY + void __add_shared() _NOEXCEPT { + __shared_count::__add_shared(); + } + _LIBCPP_INLINE_VISIBILITY + void __add_weak() _NOEXCEPT { + __libcpp_atomic_refcount_increment(__shared_weak_owners_); + } + _LIBCPP_INLINE_VISIBILITY + void __release_shared() _NOEXCEPT { + if (__shared_count::__release_shared()) + __release_weak(); + } +#endif + void __release_weak() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + long use_count() const _NOEXCEPT {return __shared_count::use_count();} + __shared_weak_count* lock() _NOEXCEPT; + + // Define the function out only if we build static libc++ without RTTI. + // Otherwise we may break clients who need to compile their projects with + // -fno-rtti and yet link against a libc++.dylib compiled + // without -fno-rtti. +#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC) + virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; +#endif +private: + virtual void __on_zero_shared_weak() _NOEXCEPT = 0; +}; + +template <class _Tp, class _Dp, class _Alloc> +class __shared_ptr_pointer + : public __shared_weak_count +{ + __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; +public: + _LIBCPP_INLINE_VISIBILITY + __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) + : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {} + +#ifndef _LIBCPP_NO_RTTI + virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; +#endif + +private: + virtual void __on_zero_shared() _NOEXCEPT; + virtual void __on_zero_shared_weak() _NOEXCEPT; +}; + +#ifndef _LIBCPP_NO_RTTI + +template <class _Tp, class _Dp, class _Alloc> +const void* +__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT +{ + return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr; +} + +#endif // _LIBCPP_NO_RTTI + +template <class _Tp, class _Dp, class _Alloc> +void +__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT +{ + __data_.first().second()(__data_.first().first()); + __data_.first().second().~_Dp(); +} + +template <class _Tp, class _Dp, class _Alloc> +void +__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT +{ + typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; + typedef allocator_traits<_Al> _ATraits; + typedef pointer_traits<typename _ATraits::pointer> _PTraits; + + _Al __a(__data_.second()); + __data_.second().~_Alloc(); + __a.deallocate(_PTraits::pointer_to(*this), 1); +} + +template <class _Tp, class _Alloc> +class __shared_ptr_emplace + : public __shared_weak_count +{ + __compressed_pair<_Alloc, _Tp> __data_; +public: +#ifndef _LIBCPP_HAS_NO_VARIADICS + + _LIBCPP_INLINE_VISIBILITY + __shared_ptr_emplace(_Alloc __a) + : __data_(_VSTD::move(__a)) {} + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) + : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {} + +#else // _LIBCPP_HAS_NO_VARIADICS + + _LIBCPP_INLINE_VISIBILITY + __shared_ptr_emplace(_Alloc __a) + : __data_(__a) {} + + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + __shared_ptr_emplace(_Alloc __a, _A0& __a0) + : __data_(__a, _Tp(__a0)) {} + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) + : __data_(__a, _Tp(__a0, __a1)) {} + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) + : __data_(__a, _Tp(__a0, __a1, __a2)) {} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +private: + virtual void __on_zero_shared() _NOEXCEPT; + virtual void __on_zero_shared_weak() _NOEXCEPT; +public: + _LIBCPP_INLINE_VISIBILITY + _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());} +}; + +template <class _Tp, class _Alloc> +void +__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT +{ + __data_.second().~_Tp(); +} + +template <class _Tp, class _Alloc> +void +__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT +{ + typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; + typedef allocator_traits<_Al> _ATraits; + typedef pointer_traits<typename _ATraits::pointer> _PTraits; + _Al __a(__data_.first()); + __data_.first().~_Alloc(); + __a.deallocate(_PTraits::pointer_to(*this), 1); +} + +struct __shared_ptr_dummy_rebind_allocator_type; +template <> +class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> +{ +public: + template <class _Other> + struct rebind + { + typedef allocator<_Other> other; + }; +}; + +template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; + +template<class _Tp> +class _LIBCPP_TEMPLATE_VIS shared_ptr +{ +public: + typedef _Tp element_type; + +#if _LIBCPP_STD_VER > 14 + typedef weak_ptr<_Tp> weak_type; +#endif +private: + element_type* __ptr_; + __shared_weak_count* __cntrl_; + + struct __nat {int __for_bool_;}; +public: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; + template<class _Yp> + explicit shared_ptr(_Yp* __p, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); + template<class _Yp, class _Dp> + shared_ptr(_Yp* __p, _Dp __d, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); + template<class _Yp, class _Dp, class _Alloc> + shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); + template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); + template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); + template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + shared_ptr(const shared_ptr& __r) _NOEXCEPT; + template<class _Yp> + _LIBCPP_INLINE_VISIBILITY + shared_ptr(const shared_ptr<_Yp>& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) + _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_ptr(shared_ptr&& __r) _NOEXCEPT; + template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) + _NOEXCEPT; +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat()); +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template<class _Yp> + shared_ptr(auto_ptr<_Yp>&& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); +#else + template<class _Yp> + shared_ptr(auto_ptr<_Yp> __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); +#endif +#endif +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>&&, + typename enable_if + < + !is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>&&, + typename enable_if + < + is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>, + typename enable_if + < + !is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>, + typename enable_if + < + is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + ~shared_ptr(); + + _LIBCPP_INLINE_VISIBILITY + shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; + template<class _Yp> + typename enable_if + < + is_convertible<_Yp*, element_type*>::value, + shared_ptr& + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; + template<class _Yp> + typename enable_if + < + is_convertible<_Yp*, element_type*>::value, + shared_ptr<_Tp>& + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(shared_ptr<_Yp>&& __r); +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) + template<class _Yp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + !is_array<_Yp>::value && + is_convertible<_Yp*, element_type*>::value, + shared_ptr + >::type& + operator=(auto_ptr<_Yp>&& __r); +#endif +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) + template<class _Yp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + !is_array<_Yp>::value && + is_convertible<_Yp*, element_type*>::value, + shared_ptr& + >::type + operator=(auto_ptr<_Yp> __r); +#endif +#endif + template <class _Yp, class _Dp> + typename enable_if + < + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + shared_ptr& + >::type +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + operator=(unique_ptr<_Yp, _Dp>&& __r); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + operator=(unique_ptr<_Yp, _Dp> __r); +#endif + + _LIBCPP_INLINE_VISIBILITY + void swap(shared_ptr& __r) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void reset() _NOEXCEPT; + template<class _Yp> + typename enable_if + < + is_convertible<_Yp*, element_type*>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + reset(_Yp* __p); + template<class _Yp, class _Dp> + typename enable_if + < + is_convertible<_Yp*, element_type*>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + reset(_Yp* __p, _Dp __d); + template<class _Yp, class _Dp, class _Alloc> + typename enable_if + < + is_convertible<_Yp*, element_type*>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + reset(_Yp* __p, _Dp __d, _Alloc __a); + + _LIBCPP_INLINE_VISIBILITY + element_type* get() const _NOEXCEPT {return __ptr_;} + _LIBCPP_INLINE_VISIBILITY + typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT + {return *__ptr_;} + _LIBCPP_INLINE_VISIBILITY + element_type* operator->() const _NOEXCEPT {return __ptr_;} + _LIBCPP_INLINE_VISIBILITY + long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} + _LIBCPP_INLINE_VISIBILITY + bool unique() const _NOEXCEPT {return use_count() == 1;} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT + {return __cntrl_ < __p.__cntrl_;} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT + {return __cntrl_ < __p.__cntrl_;} + _LIBCPP_INLINE_VISIBILITY + bool + __owner_equivalent(const shared_ptr& __p) const + {return __cntrl_ == __p.__cntrl_;} + +#ifndef _LIBCPP_NO_RTTI + template <class _Dp> + _LIBCPP_INLINE_VISIBILITY + _Dp* __get_deleter() const _NOEXCEPT + {return static_cast<_Dp*>(__cntrl_ + ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) + : nullptr);} +#endif // _LIBCPP_NO_RTTI + +#ifndef _LIBCPP_HAS_NO_VARIADICS + + template<class ..._Args> + static + shared_ptr<_Tp> + make_shared(_Args&& ...__args); + + template<class _Alloc, class ..._Args> + static + shared_ptr<_Tp> + allocate_shared(const _Alloc& __a, _Args&& ...__args); + +#else // _LIBCPP_HAS_NO_VARIADICS + + static shared_ptr<_Tp> make_shared(); + + template<class _A0> + static shared_ptr<_Tp> make_shared(_A0&); + + template<class _A0, class _A1> + static shared_ptr<_Tp> make_shared(_A0&, _A1&); + + template<class _A0, class _A1, class _A2> + static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); + + template<class _Alloc> + static shared_ptr<_Tp> + allocate_shared(const _Alloc& __a); + + template<class _Alloc, class _A0> + static shared_ptr<_Tp> + allocate_shared(const _Alloc& __a, _A0& __a0); + + template<class _Alloc, class _A0, class _A1> + static shared_ptr<_Tp> + allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); + + template<class _Alloc, class _A0, class _A1, class _A2> + static shared_ptr<_Tp> + allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); + +#endif // _LIBCPP_HAS_NO_VARIADICS + +private: + template <class _Yp, bool = is_function<_Yp>::value> + struct __shared_ptr_default_allocator + { + typedef allocator<_Yp> type; + }; + + template <class _Yp> + struct __shared_ptr_default_allocator<_Yp, true> + { + typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type; + }; + + template <class _Yp, class _OrigPtr> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<is_convertible<_OrigPtr*, + const enable_shared_from_this<_Yp>* + >::value, + void>::type + __enable_weak_this(const enable_shared_from_this<_Yp>* __e, + _OrigPtr* __ptr) _NOEXCEPT + { + typedef typename remove_cv<_Yp>::type _RawYp; + if (__e && __e->__weak_this_.expired()) + { + __e->__weak_this_ = shared_ptr<_RawYp>(*this, + const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); + } + } + + _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {} + + template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; + template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; +}; + + +template<class _Tp> +inline +_LIBCPP_CONSTEXPR +shared_ptr<_Tp>::shared_ptr() _NOEXCEPT + : __ptr_(0), + __cntrl_(0) +{ +} + +template<class _Tp> +inline +_LIBCPP_CONSTEXPR +shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT + : __ptr_(0), + __cntrl_(0) +{ +} + +template<class _Tp> +template<class _Yp> +shared_ptr<_Tp>::shared_ptr(_Yp* __p, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) + : __ptr_(__p) +{ + unique_ptr<_Yp> __hold(__p); + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT()); + __hold.release(); + __enable_weak_this(__p, __p); +} + +template<class _Tp> +template<class _Yp, class _Dp> +shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) + : __ptr_(__p) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); + __enable_weak_this(__p, __p); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __d(__p); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Tp> +template<class _Dp> +shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) + : __ptr_(0) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; + typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __d(__p); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Tp> +template<class _Yp, class _Dp, class _Alloc> +shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) + : __ptr_(__p) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__p, __d, __a); + __cntrl_ = _VSTD::addressof(*__hold2.release()); + __enable_weak_this(__p, __p); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __d(__p); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Tp> +template<class _Dp, class _Alloc> +shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) + : __ptr_(0) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__p, __d, __a); + __cntrl_ = _VSTD::addressof(*__hold2.release()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __d(__p); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template<class _Tp> +template<class _Yp> +inline +shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT + : __ptr_(__p), + __cntrl_(__r.__cntrl_) +{ + if (__cntrl_) + __cntrl_->__add_shared(); +} + +template<class _Tp> +inline +shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + if (__cntrl_) + __cntrl_->__add_shared(); +} + +template<class _Tp> +template<class _Yp> +inline +shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) + _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + if (__cntrl_) + __cntrl_->__add_shared(); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template<class _Tp> +inline +shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + __r.__ptr_ = 0; + __r.__cntrl_ = 0; +} + +template<class _Tp> +template<class _Yp> +inline +shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) + _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + __r.__ptr_ = 0; + __r.__cntrl_ = 0; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +template<class _Tp> +template<class _Yp> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, +#else +shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r, +#endif + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) + : __ptr_(__r.get()) +{ + typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); + __enable_weak_this(__r.get(), __r.get()); + __r.release(); +} +#endif + +template<class _Tp> +template <class _Yp, class _Dp> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, +#else +shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, +#endif + typename enable_if + < + !is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type) + : __ptr_(__r.get()) +{ +#if _LIBCPP_STD_VER > 11 + if (__ptr_ == nullptr) + __cntrl_ = nullptr; + else +#endif + { + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); + __enable_weak_this(__r.get(), __r.get()); + } + __r.release(); +} + +template<class _Tp> +template <class _Yp, class _Dp> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, +#else +shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, +#endif + typename enable_if + < + is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type) + : __ptr_(__r.get()) +{ +#if _LIBCPP_STD_VER > 11 + if (__ptr_ == nullptr) + __cntrl_ = nullptr; + else +#endif + { + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, + reference_wrapper<typename remove_reference<_Dp>::type>, + _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT()); + __enable_weak_this(__r.get(), __r.get()); + } + __r.release(); +} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template<class _Tp> +template<class ..._Args> +shared_ptr<_Tp> +shared_ptr<_Tp>::make_shared(_Args&& ...__args) +{ + static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" ); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a2; + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = __hold2.release(); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +template<class _Tp> +template<class _Alloc, class ..._Args> +shared_ptr<_Tp> +shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) +{ + static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" ); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +#else // _LIBCPP_HAS_NO_VARIADICS + +template<class _Tp> +shared_ptr<_Tp> +shared_ptr<_Tp>::make_shared() +{ + static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" ); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2; + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(__hold2.get()) _CntrlBlk(__alloc2); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = __hold2.release(); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +template<class _Tp> +template<class _A0> +shared_ptr<_Tp> +shared_ptr<_Tp>::make_shared(_A0& __a0) +{ + static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" ); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2; + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = __hold2.release(); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +template<class _Tp> +template<class _A0, class _A1> +shared_ptr<_Tp> +shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) +{ + static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" ); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2; + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = __hold2.release(); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +template<class _Tp> +template<class _A0, class _A1, class _A2> +shared_ptr<_Tp> +shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) +{ + static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" ); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2; + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = __hold2.release(); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +template<class _Tp> +template<class _Alloc> +shared_ptr<_Tp> +shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) +{ + static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" ); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +template<class _Tp> +template<class _Alloc, class _A0> +shared_ptr<_Tp> +shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) +{ + static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" ); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, __a0); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +template<class _Tp> +template<class _Alloc, class _A0, class _A1> +shared_ptr<_Tp> +shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) +{ + static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" ); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, __a0, __a1); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +template<class _Tp> +template<class _Alloc, class _A0, class _A1, class _A2> +shared_ptr<_Tp> +shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) +{ + static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" ); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, __a0, __a1, __a2); + shared_ptr<_Tp> __r; + __r.__ptr_ = __hold2.get()->get(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template<class _Tp> +shared_ptr<_Tp>::~shared_ptr() +{ + if (__cntrl_) + __cntrl_->__release_shared(); +} + +template<class _Tp> +inline +shared_ptr<_Tp>& +shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT +{ + shared_ptr(__r).swap(*this); + return *this; +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + shared_ptr<_Tp>& +>::type +shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT +{ + shared_ptr(__r).swap(*this); + return *this; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template<class _Tp> +inline +shared_ptr<_Tp>& +shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT +{ + shared_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + shared_ptr<_Tp>& +>::type +shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) +{ + shared_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + !is_array<_Yp>::value && + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + shared_ptr<_Tp> +>::type& +shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) +{ + shared_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} +#endif + +template<class _Tp> +template <class _Yp, class _Dp> +inline +typename enable_if +< + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, + typename shared_ptr<_Tp>::element_type*>::value, + shared_ptr<_Tp>& +>::type +shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) +{ + shared_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) +template<class _Tp> +template<class _Yp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_array<_Yp>::value && + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + shared_ptr<_Tp>& +>::type +shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) +{ + shared_ptr(__r).swap(*this); + return *this; +} +#endif + +template<class _Tp> +template <class _Yp, class _Dp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, + typename shared_ptr<_Tp>::element_type*>::value, + shared_ptr<_Tp>& +>::type +shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) +{ + shared_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template<class _Tp> +inline +void +shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT +{ + _VSTD::swap(__ptr_, __r.__ptr_); + _VSTD::swap(__cntrl_, __r.__cntrl_); +} + +template<class _Tp> +inline +void +shared_ptr<_Tp>::reset() _NOEXCEPT +{ + shared_ptr().swap(*this); +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + void +>::type +shared_ptr<_Tp>::reset(_Yp* __p) +{ + shared_ptr(__p).swap(*this); +} + +template<class _Tp> +template<class _Yp, class _Dp> +inline +typename enable_if +< + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + void +>::type +shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) +{ + shared_ptr(__p, __d).swap(*this); +} + +template<class _Tp> +template<class _Yp, class _Dp, class _Alloc> +inline +typename enable_if +< + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + void +>::type +shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) +{ + shared_ptr(__p, __d, __a).swap(*this); +} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template<class _Tp, class ..._Args> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_array<_Tp>::value, + shared_ptr<_Tp> +>::type +make_shared(_Args&& ...__args) +{ + return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...); +} + +template<class _Tp, class _Alloc, class ..._Args> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_array<_Tp>::value, + shared_ptr<_Tp> +>::type +allocate_shared(const _Alloc& __a, _Args&& ...__args) +{ + return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...); +} + +#else // _LIBCPP_HAS_NO_VARIADICS + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +shared_ptr<_Tp> +make_shared() +{ + return shared_ptr<_Tp>::make_shared(); +} + +template<class _Tp, class _A0> +inline _LIBCPP_INLINE_VISIBILITY +shared_ptr<_Tp> +make_shared(_A0& __a0) +{ + return shared_ptr<_Tp>::make_shared(__a0); +} + +template<class _Tp, class _A0, class _A1> +inline _LIBCPP_INLINE_VISIBILITY +shared_ptr<_Tp> +make_shared(_A0& __a0, _A1& __a1) +{ + return shared_ptr<_Tp>::make_shared(__a0, __a1); +} + +template<class _Tp, class _A0, class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +shared_ptr<_Tp> +make_shared(_A0& __a0, _A1& __a1, _A2& __a2) +{ + return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2); +} + +template<class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +shared_ptr<_Tp> +allocate_shared(const _Alloc& __a) +{ + return shared_ptr<_Tp>::allocate_shared(__a); +} + +template<class _Tp, class _Alloc, class _A0> +inline _LIBCPP_INLINE_VISIBILITY +shared_ptr<_Tp> +allocate_shared(const _Alloc& __a, _A0& __a0) +{ + return shared_ptr<_Tp>::allocate_shared(__a, __a0); +} + +template<class _Tp, class _Alloc, class _A0, class _A1> +inline _LIBCPP_INLINE_VISIBILITY +shared_ptr<_Tp> +allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) +{ + return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1); +} + +template<class _Tp, class _Alloc, class _A0, class _A1, class _A2> +inline _LIBCPP_INLINE_VISIBILITY +shared_ptr<_Tp> +allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT +{ + return __x.get() == __y.get(); +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT +{ + return !(__x == __y); +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT +{ +#if _LIBCPP_STD_VER <= 11 + typedef typename common_type<_Tp*, _Up*>::type _Vp; + return less<_Vp>()(__x.get(), __y.get()); +#else + return less<>()(__x.get(), __y.get()); +#endif + +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT +{ + return __y < __x; +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT +{ + return !(__y < __x); +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT +{ + return !(__x < __y); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT +{ + return !__x; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT +{ + return !__x; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT +{ + return static_cast<bool>(__x); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT +{ + return static_cast<bool>(__x); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT +{ + return less<_Tp*>()(__x.get(), nullptr); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT +{ + return less<_Tp*>()(nullptr, __x.get()); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT +{ + return nullptr < __x; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT +{ + return __x < nullptr; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT +{ + return !(nullptr < __x); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT +{ + return !(__x < nullptr); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT +{ + return !(__x < nullptr); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT +{ + return !(nullptr < __x); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT +{ + __x.swap(__y); +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_array<_Tp>::value && !is_array<_Up>::value, + shared_ptr<_Tp> +>::type +static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT +{ + return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); +} + +template<class _Tp, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_array<_Tp>::value && !is_array<_Up>::value, + shared_ptr<_Tp> +>::type +dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT +{ + _Tp* __p = dynamic_cast<_Tp*>(__r.get()); + return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); +} + +template<class _Tp, class _Up> +typename enable_if +< + is_array<_Tp>::value == is_array<_Up>::value, + shared_ptr<_Tp> +>::type +const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT +{ + typedef typename remove_extent<_Tp>::type _RTp; + return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); +} + +#ifndef _LIBCPP_NO_RTTI + +template<class _Dp, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Dp* +get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT +{ + return __p.template __get_deleter<_Dp>(); +} + +#endif // _LIBCPP_NO_RTTI + +template<class _Tp> +class _LIBCPP_TEMPLATE_VIS weak_ptr +{ +public: + typedef _Tp element_type; +private: + element_type* __ptr_; + __shared_weak_count* __cntrl_; + +public: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; + template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r, + typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) + _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + weak_ptr(weak_ptr const& __r) _NOEXCEPT; + template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r, + typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) + _NOEXCEPT; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + weak_ptr(weak_ptr&& __r) _NOEXCEPT; + template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r, + typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) + _NOEXCEPT; +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~weak_ptr(); + + _LIBCPP_INLINE_VISIBILITY + weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; + template<class _Yp> + typename enable_if + < + is_convertible<_Yp*, element_type*>::value, + weak_ptr& + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; + template<class _Yp> + typename enable_if + < + is_convertible<_Yp*, element_type*>::value, + weak_ptr& + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + template<class _Yp> + typename enable_if + < + is_convertible<_Yp*, element_type*>::value, + weak_ptr& + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + void swap(weak_ptr& __r) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void reset() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + long use_count() const _NOEXCEPT + {return __cntrl_ ? __cntrl_->use_count() : 0;} + _LIBCPP_INLINE_VISIBILITY + bool expired() const _NOEXCEPT + {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} + shared_ptr<_Tp> lock() const _NOEXCEPT; + template<class _Up> + _LIBCPP_INLINE_VISIBILITY + bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT + {return __cntrl_ < __r.__cntrl_;} + template<class _Up> + _LIBCPP_INLINE_VISIBILITY + bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT + {return __cntrl_ < __r.__cntrl_;} + + template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; + template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; +}; + +template<class _Tp> +inline +_LIBCPP_CONSTEXPR +weak_ptr<_Tp>::weak_ptr() _NOEXCEPT + : __ptr_(0), + __cntrl_(0) +{ +} + +template<class _Tp> +inline +weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + if (__cntrl_) + __cntrl_->__add_weak(); +} + +template<class _Tp> +template<class _Yp> +inline +weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, + typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) + _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + if (__cntrl_) + __cntrl_->__add_weak(); +} + +template<class _Tp> +template<class _Yp> +inline +weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, + typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) + _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + if (__cntrl_) + __cntrl_->__add_weak(); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template<class _Tp> +inline +weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + __r.__ptr_ = 0; + __r.__cntrl_ = 0; +} + +template<class _Tp> +template<class _Yp> +inline +weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, + typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) + _NOEXCEPT + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_) +{ + __r.__ptr_ = 0; + __r.__cntrl_ = 0; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template<class _Tp> +weak_ptr<_Tp>::~weak_ptr() +{ + if (__cntrl_) + __cntrl_->__release_weak(); +} + +template<class _Tp> +inline +weak_ptr<_Tp>& +weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT +{ + weak_ptr(__r).swap(*this); + return *this; +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + is_convertible<_Yp*, _Tp*>::value, + weak_ptr<_Tp>& +>::type +weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT +{ + weak_ptr(__r).swap(*this); + return *this; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template<class _Tp> +inline +weak_ptr<_Tp>& +weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT +{ + weak_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + is_convertible<_Yp*, _Tp*>::value, + weak_ptr<_Tp>& +>::type +weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT +{ + weak_ptr(_VSTD::move(__r)).swap(*this); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template<class _Tp> +template<class _Yp> +inline +typename enable_if +< + is_convertible<_Yp*, _Tp*>::value, + weak_ptr<_Tp>& +>::type +weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT +{ + weak_ptr(__r).swap(*this); + return *this; +} + +template<class _Tp> +inline +void +weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT +{ + _VSTD::swap(__ptr_, __r.__ptr_); + _VSTD::swap(__cntrl_, __r.__cntrl_); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT +{ + __x.swap(__y); +} + +template<class _Tp> +inline +void +weak_ptr<_Tp>::reset() _NOEXCEPT +{ + weak_ptr().swap(*this); +} + +template<class _Tp> +template<class _Yp> +shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) + : __ptr_(__r.__ptr_), + __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) +{ + if (__cntrl_ == 0) + __throw_bad_weak_ptr(); +} + +template<class _Tp> +shared_ptr<_Tp> +weak_ptr<_Tp>::lock() const _NOEXCEPT +{ + shared_ptr<_Tp> __r; + __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; + if (__r.__cntrl_) + __r.__ptr_ = __ptr_; + return __r; +} + +#if _LIBCPP_STD_VER > 14 +template <class _Tp = void> struct owner_less; +#else +template <class _Tp> struct owner_less; +#endif + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > + : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> +{ + typedef bool result_type; + _LIBCPP_INLINE_VISIBILITY + bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > + : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> +{ + typedef bool result_type; + _LIBCPP_INLINE_VISIBILITY + bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} +}; + +#if _LIBCPP_STD_VER > 14 +template <> +struct _LIBCPP_TEMPLATE_VIS owner_less<void> +{ + template <class _Tp, class _Up> + _LIBCPP_INLINE_VISIBILITY + bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} + template <class _Tp, class _Up> + _LIBCPP_INLINE_VISIBILITY + bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} + template <class _Tp, class _Up> + _LIBCPP_INLINE_VISIBILITY + bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} + template <class _Tp, class _Up> + _LIBCPP_INLINE_VISIBILITY + bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT + {return __x.owner_before(__y);} + typedef void is_transparent; +}; +#endif + +template<class _Tp> +class _LIBCPP_TEMPLATE_VIS enable_shared_from_this +{ + mutable weak_ptr<_Tp> __weak_this_; +protected: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + enable_shared_from_this() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT + {return *this;} + _LIBCPP_INLINE_VISIBILITY + ~enable_shared_from_this() {} +public: + _LIBCPP_INLINE_VISIBILITY + shared_ptr<_Tp> shared_from_this() + {return shared_ptr<_Tp>(__weak_this_);} + _LIBCPP_INLINE_VISIBILITY + shared_ptr<_Tp const> shared_from_this() const + {return shared_ptr<const _Tp>(__weak_this_);} + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + weak_ptr<_Tp> weak_from_this() _NOEXCEPT + { return __weak_this_; } + + _LIBCPP_INLINE_VISIBILITY + weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT + { return __weak_this_; } +#endif // _LIBCPP_STD_VER > 14 + + template <class _Up> friend class shared_ptr; +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > +{ + typedef shared_ptr<_Tp> argument_type; + typedef size_t result_type; + + _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type& __ptr) const _NOEXCEPT + { + return hash<_Tp*>()(__ptr.get()); + } +}; + +template<class _CharT, class _Traits, class _Yp> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); + + +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) + +class _LIBCPP_TYPE_VIS __sp_mut +{ + void* __lx; +public: + void lock() _NOEXCEPT; + void unlock() _NOEXCEPT; + +private: + _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; + __sp_mut(const __sp_mut&); + __sp_mut& operator=(const __sp_mut&); + + friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); +}; + +_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +__sp_mut& __get_sp_mut(const void*); + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_is_lock_free(const shared_ptr<_Tp>*) +{ + return false; +} + +template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +shared_ptr<_Tp> +atomic_load(const shared_ptr<_Tp>* __p) +{ + __sp_mut& __m = __get_sp_mut(__p); + __m.lock(); + shared_ptr<_Tp> __q = *__p; + __m.unlock(); + return __q; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +shared_ptr<_Tp> +atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) +{ + return atomic_load(__p); +} + +template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +void +atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) +{ + __sp_mut& __m = __get_sp_mut(__p); + __m.lock(); + __p->swap(__r); + __m.unlock(); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +void +atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) +{ + atomic_store(__p, __r); +} + +template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +shared_ptr<_Tp> +atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) +{ + __sp_mut& __m = __get_sp_mut(__p); + __m.lock(); + __p->swap(__r); + __m.unlock(); + return __r; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +shared_ptr<_Tp> +atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) +{ + return atomic_exchange(__p, __r); +} + +template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +bool +atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) +{ + shared_ptr<_Tp> __temp; + __sp_mut& __m = __get_sp_mut(__p); + __m.lock(); + if (__p->__owner_equivalent(*__v)) + { + _VSTD::swap(__temp, *__p); + *__p = __w; + __m.unlock(); + return true; + } + _VSTD::swap(__temp, *__v); + *__v = *__p; + __m.unlock(); + return false; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +bool +atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) +{ + return atomic_compare_exchange_strong(__p, __v, __w); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +bool +atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, + shared_ptr<_Tp> __w, memory_order, memory_order) +{ + return atomic_compare_exchange_strong(__p, __v, __w); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +bool +atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, + shared_ptr<_Tp> __w, memory_order, memory_order) +{ + return atomic_compare_exchange_weak(__p, __v, __w); +} + +#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) + +//enum class +#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) +# ifndef _LIBCPP_CXX03_LANG +enum class pointer_safety : unsigned char { + relaxed, + preferred, + strict +}; +# endif +#else +struct _LIBCPP_TYPE_VIS pointer_safety +{ + enum __lx + { + relaxed, + preferred, + strict + }; + + __lx __v_; + + _LIBCPP_INLINE_VISIBILITY + pointer_safety() : __v_() {} + + _LIBCPP_INLINE_VISIBILITY + pointer_safety(__lx __v) : __v_(__v) {} + _LIBCPP_INLINE_VISIBILITY + operator int() const {return __v_;} +}; +#endif + +#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \ + defined(_LIBCPP_BUILDING_LIBRARY) +_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; +#else +// This function is only offered in C++03 under ABI v1. +# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG) +inline _LIBCPP_INLINE_VISIBILITY +pointer_safety get_pointer_safety() _NOEXCEPT { + return pointer_safety::relaxed; +} +# endif +#endif + + +_LIBCPP_FUNC_VIS void declare_reachable(void* __p); +_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); +_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); +_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +undeclare_reachable(_Tp* __p) +{ + return static_cast<_Tp*>(__undeclare_reachable(__p)); +} + +_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); + +// --- Helper for container swap -- +template <typename _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void __swap_allocator(_Alloc & __a1, _Alloc & __a2) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) +#endif +{ + __swap_allocator(__a1, __a2, + integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); +} + +template <typename _Alloc> +_LIBCPP_INLINE_VISIBILITY +void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) +#endif +{ + using _VSTD::swap; + swap(__a1, __a2); +} + +template <typename _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} + +template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > +struct __noexcept_move_assign_container : public integral_constant<bool, + _Traits::propagate_on_container_move_assignment::value +#if _LIBCPP_STD_VER > 14 + || _Traits::is_always_equal::value +#else + && is_nothrow_move_assignable<_Alloc>::value +#endif + > {}; + + +#ifndef _LIBCPP_HAS_NO_VARIADICS +template <class _Tp, class _Alloc> +struct __temp_value { + typedef allocator_traits<_Alloc> _Traits; + + typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v; + _Alloc &__a; + + _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } + _Tp & get() { return *__addr(); } + + template<class... _Args> + _LIBCPP_NO_CFI + __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { + _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)), + _VSTD::forward<_Args>(__args)...); + } + + ~__temp_value() { _Traits::destroy(__a, __addr()); } + }; +#endif + +template<typename _Alloc, typename = void, typename = void> +struct __is_allocator : false_type {}; + +template<typename _Alloc> +struct __is_allocator<_Alloc, + typename __void_t<typename _Alloc::value_type>::type, + typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type + > + : true_type {}; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_MEMORY diff --git a/android/x86/include/v8/libc++/module.modulemap b/android/x86/include/v8/libc++/module.modulemap new file mode 100755 index 00000000..bbfe90ed --- /dev/null +++ b/android/x86/include/v8/libc++/module.modulemap @@ -0,0 +1,608 @@ +// define the module for __config outside of the top level 'std' module +// since __config may be included from C headers which may create an +// include cycle. +module std_config [system] [extern_c] { + header "__config" +} + +module std [system] { + export std_config + // FIXME: The standard does not require that each of these submodules + // re-exports its imported modules. We should provide an alternative form of + // export that issues a warning if a name from the submodule is used, and + // use that to provide a 'strict mode' for libc++. + + // Deprecated C-compatibility headers. These can all be included from within + // an 'extern "C"' context. + module depr [extern_c] { + // <assert.h> provided by C library. + module ctype_h { + header "ctype.h" + export * + } + module errno_h { + header "errno.h" + export * + } + module fenv_h { + header "fenv.h" + export * + } + // <float.h> provided by compiler or C library. + module inttypes_h { + header "inttypes.h" + export stdint_h + export * + } + // <iso646.h> provided by compiler. + // <limits.h> provided by compiler or C library. + module locale_h { + header "locale.h" + export * + } + module math_h { + header "math.h" + export * + } + module setjmp_h { + header "setjmp.h" + export * + } + // FIXME: <stdalign.h> is missing. + // <signal.h> provided by C library. + // <stdarg.h> provided by compiler. + // <stdbool.h> provided by compiler. + module stddef_h { + // <stddef.h>'s __need_* macros require textual inclusion. + textual header "stddef.h" + } + module stdint_h { + header "stdint.h" + export * + // FIXME: This module only exists on OS X and for some reason the + // wildcard above doesn't export it. + export Darwin.C.stdint + } + module stdio_h { + // <stdio.h>'s __need_* macros require textual inclusion. + textual header "stdio.h" + export * + export Darwin.C.stdio + } + module stdlib_h { + // <stdlib.h>'s __need_* macros require textual inclusion. + textual header "stdlib.h" + export * + } + module string_h { + header "string.h" + export * + } + // FIXME: <uchar.h> is missing. + // <time.h> provided by C library. + module wchar_h { + // <wchar.h>'s __need_* macros require textual inclusion. + textual header "wchar.h" + export * + } + module wctype_h { + header "wctype.h" + export * + } + } + + // <complex.h> and <tgmath.h> are not C headers in any real sense, do not + // allow their use in extern "C" contexts. + module complex_h { + header "complex.h" + export ccomplex + export * + } + module tgmath_h { + header "tgmath.h" + export ccomplex + export cmath + export * + } + + // C compatibility headers. + module compat { + module cassert { + // <cassert>'s use of NDEBUG requires textual inclusion. + textual header "cassert" + } + module ccomplex { + header "ccomplex" + export complex + export * + } + module cctype { + header "cctype" + export * + } + module cerrno { + header "cerrno" + export * + } + module cfenv { + header "cfenv" + export * + } + module cfloat { + header "cfloat" + export * + } + module cinttypes { + header "cinttypes" + export cstdint + export * + } + module ciso646 { + header "ciso646" + export * + } + module climits { + header "climits" + export * + } + module clocale { + header "clocale" + export * + } + module cmath { + header "cmath" + export * + } + module csetjmp { + header "csetjmp" + export * + } + module csignal { + header "csignal" + export * + } + // FIXME: <cstdalign> is missing. + module cstdarg { + header "cstdarg" + export * + } + module cstdbool { + header "cstdbool" + export * + } + module cstddef { + header "cstddef" + export * + } + module cstdint { + header "cstdint" + export depr.stdint_h + export * + } + module cstdio { + header "cstdio" + export * + } + module cstdlib { + header "cstdlib" + export * + } + module cstring { + header "cstring" + export * + } + module ctgmath { + header "ctgmath" + export ccomplex + export cmath + export * + } + module ctime { + header "ctime" + export * + } + // FIXME: <cuchar> is missing. + module cwchar { + header "cwchar" + export depr.stdio_h + export * + } + module cwctype { + header "cwctype" + export * + } + } + + module algorithm { + header "algorithm" + export initializer_list + export * + } + module any { + header "any" + export * + } + module array { + header "array" + export initializer_list + export * + } + module atomic { + header "atomic" + export * + } + module bit { + header "bit" + export * + } + module bitset { + header "bitset" + export string + export iosfwd + export * + } + // No submodule for cassert. It fundamentally needs repeated, textual inclusion. + module charconv { + header "charconv" + export * + } + module chrono { + header "chrono" + export * + } + module codecvt { + header "codecvt" + export * + } + module compare { + header "compare" + export * + } + module complex { + header "complex" + export * + } + module condition_variable { + header "condition_variable" + export * + } + module deque { + header "deque" + export initializer_list + export * + } + module exception { + header "exception" + export * + } + module filesystem { + header "filesystem" + export * + } + module forward_list { + header "forward_list" + export initializer_list + export * + } + module fstream { + header "fstream" + export * + } + module functional { + header "functional" + export * + } + module future { + header "future" + export * + } + module initializer_list { + header "initializer_list" + export * + } + module iomanip { + header "iomanip" + export * + } + module ios { + header "ios" + export iosfwd + export * + } + module iosfwd { + header "iosfwd" + export * + } + module iostream { + header "iostream" + export ios + export streambuf + export istream + export ostream + export * + } + module istream { + header "istream" + // FIXME: should re-export ios, streambuf? + export * + } + module iterator { + header "iterator" + export * + } + module limits { + header "limits" + export * + } + module list { + header "list" + export initializer_list + export * + } + module locale { + header "locale" + export * + } + module map { + header "map" + export initializer_list + export * + } + module memory { + header "memory" + export * + } + module mutex { + header "mutex" + export * + } + module new { + header "new" + export * + } + module numeric { + header "numeric" + export * + } + module optional { + header "optional" + export * + } + module ostream { + header "ostream" + // FIXME: should re-export ios, streambuf? + export * + } + module queue { + header "queue" + export initializer_list + export * + } + module random { + header "random" + export initializer_list + export * + } + module ratio { + header "ratio" + export * + } + module regex { + header "regex" + export initializer_list + export * + } + module scoped_allocator { + header "scoped_allocator" + export * + } + module set { + header "set" + export initializer_list + export * + } + module sstream { + header "sstream" + // FIXME: should re-export istream, ostream, ios, streambuf, string? + export * + } + module stack { + header "stack" + export initializer_list + export * + } + module stdexcept { + header "stdexcept" + export * + } + module streambuf { + header "streambuf" + export * + } + module string { + header "string" + export initializer_list + export string_view + export __string + export * + } + module string_view { + header "string_view" + export initializer_list + export __string + export * + } + module strstream { + header "strstream" + export * + } + module system_error { + header "system_error" + export * + } + module thread { + header "thread" + export * + } + module tuple { + header "tuple" + export * + } + module type_traits { + header "type_traits" + export * + } + module typeindex { + header "typeindex" + export * + } + module typeinfo { + header "typeinfo" + export * + } + module unordered_map { + header "unordered_map" + export initializer_list + export * + } + module unordered_set { + header "unordered_set" + export initializer_list + export * + } + module utility { + header "utility" + export initializer_list + export * + } + module valarray { + header "valarray" + export initializer_list + export * + } + module variant { + header "variant" + export * + } + module vector { + header "vector" + export initializer_list + export * + } + module version { + header "version" + export * + } + + // FIXME: These should be private. + module __bit_reference { header "__bit_reference" export * } + module __debug { header "__debug" export * } + module __errc { header "__errc" export * } + module __functional_base { header "__functional_base" export * } + module __hash_table { header "__hash_table" export * } + module __locale { header "__locale" export * } + module __mutex_base { header "__mutex_base" export * } + module __split_buffer { header "__split_buffer" export * } + module __sso_allocator { header "__sso_allocator" export * } + module __std_stream { header "__std_stream" export * } + module __string { header "__string" export * } + module __tree { header "__tree" export * } + module __tuple { header "__tuple" export * } + module __undef_macros { header "__undef_macros" export * } + module __node_handle { header "__node_handle" export * } + + module experimental { + requires cplusplus11 + + module algorithm { + header "experimental/algorithm" + export * + } + module coroutine { + requires coroutines + header "experimental/coroutine" + export * + } + module deque { + header "experimental/deque" + export * + } + module filesystem { + header "experimental/filesystem" + export * + } + module forward_list { + header "experimental/forward_list" + export * + } + module functional { + header "experimental/functional" + export * + } + module iterator { + header "experimental/iterator" + export * + } + module list { + header "experimental/list" + export * + } + module map { + header "experimental/map" + export * + } + module memory_resource { + header "experimental/memory_resource" + export * + } + module propagate_const { + header "experimental/propagate_const" + export * + } + module regex { + header "experimental/regex" + export * + } + module simd { + header "experimental/simd" + export * + } + module set { + header "experimental/set" + export * + } + module span { + header "span" + export * + } + module string { + header "experimental/string" + export * + } + module type_traits { + header "experimental/type_traits" + export * + } + module unordered_map { + header "experimental/unordered_map" + export * + } + module unordered_set { + header "experimental/unordered_set" + export * + } + module utility { + header "experimental/utility" + export * + } + module vector { + header "experimental/vector" + export * + } + // FIXME these should be private + module __memory { + header "experimental/__memory" + export * + } + } // end experimental +} diff --git a/android/x86/include/v8/libc++/mutex b/android/x86/include/v8/libc++/mutex new file mode 100755 index 00000000..20c3ffc3 --- /dev/null +++ b/android/x86/include/v8/libc++/mutex @@ -0,0 +1,711 @@ +// -*- C++ -*- +//===--------------------------- mutex ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_MUTEX +#define _LIBCPP_MUTEX + +/* + mutex synopsis + +namespace std +{ + +class mutex +{ +public: + constexpr mutex() noexcept; + ~mutex(); + + mutex(const mutex&) = delete; + mutex& operator=(const mutex&) = delete; + + void lock(); + bool try_lock(); + void unlock(); + + typedef pthread_mutex_t* native_handle_type; + native_handle_type native_handle(); +}; + +class recursive_mutex +{ +public: + recursive_mutex(); + ~recursive_mutex(); + + recursive_mutex(const recursive_mutex&) = delete; + recursive_mutex& operator=(const recursive_mutex&) = delete; + + void lock(); + bool try_lock() noexcept; + void unlock(); + + typedef pthread_mutex_t* native_handle_type; + native_handle_type native_handle(); +}; + +class timed_mutex +{ +public: + timed_mutex(); + ~timed_mutex(); + + timed_mutex(const timed_mutex&) = delete; + timed_mutex& operator=(const timed_mutex&) = delete; + + void lock(); + bool try_lock(); + template <class Rep, class Period> + bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + template <class Clock, class Duration> + bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + void unlock(); +}; + +class recursive_timed_mutex +{ +public: + recursive_timed_mutex(); + ~recursive_timed_mutex(); + + recursive_timed_mutex(const recursive_timed_mutex&) = delete; + recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete; + + void lock(); + bool try_lock() noexcept; + template <class Rep, class Period> + bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + template <class Clock, class Duration> + bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + void unlock(); +}; + +struct defer_lock_t {}; +struct try_to_lock_t {}; +struct adopt_lock_t {}; + +inline constexpr defer_lock_t defer_lock{}; +inline constexpr try_to_lock_t try_to_lock{}; +inline constexpr adopt_lock_t adopt_lock{}; + +template <class Mutex> +class lock_guard +{ +public: + typedef Mutex mutex_type; + + explicit lock_guard(mutex_type& m); + lock_guard(mutex_type& m, adopt_lock_t); + ~lock_guard(); + + lock_guard(lock_guard const&) = delete; + lock_guard& operator=(lock_guard const&) = delete; +}; + +template <class... MutexTypes> +class scoped_lock // C++17 +{ +public: + using mutex_type = Mutex; // If MutexTypes... consists of the single type Mutex + + explicit scoped_lock(MutexTypes&... m); + scoped_lock(adopt_lock_t, MutexTypes&... m); + ~scoped_lock(); + scoped_lock(scoped_lock const&) = delete; + scoped_lock& operator=(scoped_lock const&) = delete; +private: + tuple<MutexTypes&...> pm; // exposition only +}; + +template <class Mutex> +class unique_lock +{ +public: + typedef Mutex mutex_type; + unique_lock() noexcept; + explicit unique_lock(mutex_type& m); + unique_lock(mutex_type& m, defer_lock_t) noexcept; + unique_lock(mutex_type& m, try_to_lock_t); + unique_lock(mutex_type& m, adopt_lock_t); + template <class Clock, class Duration> + unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time); + template <class Rep, class Period> + unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time); + ~unique_lock(); + + unique_lock(unique_lock const&) = delete; + unique_lock& operator=(unique_lock const&) = delete; + + unique_lock(unique_lock&& u) noexcept; + unique_lock& operator=(unique_lock&& u) noexcept; + + void lock(); + bool try_lock(); + + template <class Rep, class Period> + bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + template <class Clock, class Duration> + bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + + void unlock(); + + void swap(unique_lock& u) noexcept; + mutex_type* release() noexcept; + + bool owns_lock() const noexcept; + explicit operator bool () const noexcept; + mutex_type* mutex() const noexcept; +}; + +template <class Mutex> + void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept; + +template <class L1, class L2, class... L3> + int try_lock(L1&, L2&, L3&...); +template <class L1, class L2, class... L3> + void lock(L1&, L2&, L3&...); + +struct once_flag +{ + constexpr once_flag() noexcept; + + once_flag(const once_flag&) = delete; + once_flag& operator=(const once_flag&) = delete; +}; + +template<class Callable, class ...Args> + void call_once(once_flag& flag, Callable&& func, Args&&... args); + +} // std + +*/ + +#include <__config> +#include <__mutex_base> +#include <cstdint> +#include <functional> +#include <memory> +#ifndef _LIBCPP_CXX03_LANG +#include <tuple> +#endif +#include <version> +#include <__threading_support> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_HAS_NO_THREADS + +class _LIBCPP_TYPE_VIS recursive_mutex +{ + __libcpp_recursive_mutex_t __m_; + +public: + recursive_mutex(); + ~recursive_mutex(); + +private: + recursive_mutex(const recursive_mutex&); // = delete; + recursive_mutex& operator=(const recursive_mutex&); // = delete; + +public: + void lock(); + bool try_lock() _NOEXCEPT; + void unlock() _NOEXCEPT; + + typedef __libcpp_recursive_mutex_t* native_handle_type; + + _LIBCPP_INLINE_VISIBILITY + native_handle_type native_handle() {return &__m_;} +}; + +class _LIBCPP_TYPE_VIS timed_mutex +{ + mutex __m_; + condition_variable __cv_; + bool __locked_; +public: + timed_mutex(); + ~timed_mutex(); + +private: + timed_mutex(const timed_mutex&); // = delete; + timed_mutex& operator=(const timed_mutex&); // = delete; + +public: + void lock(); + bool try_lock() _NOEXCEPT; + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + bool try_lock_for(const chrono::duration<_Rep, _Period>& __d) + {return try_lock_until(chrono::steady_clock::now() + __d);} + template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t); + void unlock() _NOEXCEPT; +}; + +template <class _Clock, class _Duration> +bool +timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) +{ + using namespace chrono; + unique_lock<mutex> __lk(__m_); + bool no_timeout = _Clock::now() < __t; + while (no_timeout && __locked_) + no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout; + if (!__locked_) + { + __locked_ = true; + return true; + } + return false; +} + +class _LIBCPP_TYPE_VIS recursive_timed_mutex +{ + mutex __m_; + condition_variable __cv_; + size_t __count_; + __libcpp_thread_id __id_; +public: + recursive_timed_mutex(); + ~recursive_timed_mutex(); + +private: + recursive_timed_mutex(const recursive_timed_mutex&); // = delete; + recursive_timed_mutex& operator=(const recursive_timed_mutex&); // = delete; + +public: + void lock(); + bool try_lock() _NOEXCEPT; + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + bool try_lock_for(const chrono::duration<_Rep, _Period>& __d) + {return try_lock_until(chrono::steady_clock::now() + __d);} + template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t); + void unlock() _NOEXCEPT; +}; + +template <class _Clock, class _Duration> +bool +recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) +{ + using namespace chrono; + __libcpp_thread_id __id = __libcpp_thread_get_current_id(); + unique_lock<mutex> lk(__m_); + if (__libcpp_thread_id_equal(__id, __id_)) + { + if (__count_ == numeric_limits<size_t>::max()) + return false; + ++__count_; + return true; + } + bool no_timeout = _Clock::now() < __t; + while (no_timeout && __count_ != 0) + no_timeout = __cv_.wait_until(lk, __t) == cv_status::no_timeout; + if (__count_ == 0) + { + __count_ = 1; + __id_ = __id; + return true; + } + return false; +} + +template <class _L0, class _L1> +int +try_lock(_L0& __l0, _L1& __l1) +{ + unique_lock<_L0> __u0(__l0, try_to_lock); + if (__u0.owns_lock()) + { + if (__l1.try_lock()) + { + __u0.release(); + return -1; + } + else + return 1; + } + return 0; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _L0, class _L1, class _L2, class... _L3> +int +try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) +{ + int __r = 0; + unique_lock<_L0> __u0(__l0, try_to_lock); + if (__u0.owns_lock()) + { + __r = try_lock(__l1, __l2, __l3...); + if (__r == -1) + __u0.release(); + else + ++__r; + } + return __r; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _L0, class _L1> +void +lock(_L0& __l0, _L1& __l1) +{ + while (true) + { + { + unique_lock<_L0> __u0(__l0); + if (__l1.try_lock()) + { + __u0.release(); + break; + } + } + __libcpp_thread_yield(); + { + unique_lock<_L1> __u1(__l1); + if (__l0.try_lock()) + { + __u1.release(); + break; + } + } + __libcpp_thread_yield(); + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _L0, class _L1, class _L2, class ..._L3> +void +__lock_first(int __i, _L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3) +{ + while (true) + { + switch (__i) + { + case 0: + { + unique_lock<_L0> __u0(__l0); + __i = try_lock(__l1, __l2, __l3...); + if (__i == -1) + { + __u0.release(); + return; + } + } + ++__i; + __libcpp_thread_yield(); + break; + case 1: + { + unique_lock<_L1> __u1(__l1); + __i = try_lock(__l2, __l3..., __l0); + if (__i == -1) + { + __u1.release(); + return; + } + } + if (__i == sizeof...(_L3) + 1) + __i = 0; + else + __i += 2; + __libcpp_thread_yield(); + break; + default: + __lock_first(__i - 2, __l2, __l3..., __l0, __l1); + return; + } + } +} + +template <class _L0, class _L1, class _L2, class ..._L3> +inline _LIBCPP_INLINE_VISIBILITY +void +lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3) +{ + __lock_first(0, __l0, __l1, __l2, __l3...); +} + +template <class _L0> +inline _LIBCPP_INLINE_VISIBILITY +void __unlock(_L0& __l0) { + __l0.unlock(); +} + +template <class _L0, class _L1> +inline _LIBCPP_INLINE_VISIBILITY +void __unlock(_L0& __l0, _L1& __l1) { + __l0.unlock(); + __l1.unlock(); +} + +template <class _L0, class _L1, class _L2, class ..._L3> +inline _LIBCPP_INLINE_VISIBILITY +void __unlock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) { + __l0.unlock(); + __l1.unlock(); + _VSTD::__unlock(__l2, __l3...); +} + +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 14 +template <class ..._Mutexes> +class _LIBCPP_TEMPLATE_VIS scoped_lock; + +template <> +class _LIBCPP_TEMPLATE_VIS scoped_lock<> { +public: + explicit scoped_lock() {} + ~scoped_lock() = default; + + _LIBCPP_INLINE_VISIBILITY + explicit scoped_lock(adopt_lock_t) {} + + scoped_lock(scoped_lock const&) = delete; + scoped_lock& operator=(scoped_lock const&) = delete; +}; + +template <class _Mutex> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) scoped_lock<_Mutex> { +public: + typedef _Mutex mutex_type; +private: + mutex_type& __m_; +public: + explicit scoped_lock(mutex_type & __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m)) + : __m_(__m) {__m_.lock();} + + ~scoped_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) {__m_.unlock();} + + _LIBCPP_INLINE_VISIBILITY + explicit scoped_lock(adopt_lock_t, mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m)) + : __m_(__m) {} + + scoped_lock(scoped_lock const&) = delete; + scoped_lock& operator=(scoped_lock const&) = delete; +}; + +template <class ..._MArgs> +class _LIBCPP_TEMPLATE_VIS scoped_lock +{ + static_assert(sizeof...(_MArgs) > 1, "At least 2 lock types required"); + typedef tuple<_MArgs&...> _MutexTuple; + +public: + _LIBCPP_INLINE_VISIBILITY + explicit scoped_lock(_MArgs&... __margs) + : __t_(__margs...) + { + _VSTD::lock(__margs...); + } + + _LIBCPP_INLINE_VISIBILITY + scoped_lock(adopt_lock_t, _MArgs&... __margs) + : __t_(__margs...) + { + } + + _LIBCPP_INLINE_VISIBILITY + ~scoped_lock() { + typedef typename __make_tuple_indices<sizeof...(_MArgs)>::type _Indices; + __unlock_unpack(_Indices{}, __t_); + } + + scoped_lock(scoped_lock const&) = delete; + scoped_lock& operator=(scoped_lock const&) = delete; + +private: + template <size_t ..._Indx> + _LIBCPP_INLINE_VISIBILITY + static void __unlock_unpack(__tuple_indices<_Indx...>, _MutexTuple& __mt) { + _VSTD::__unlock(_VSTD::get<_Indx>(__mt)...); + } + + _MutexTuple __t_; +}; + +#endif // _LIBCPP_STD_VER > 14 +#endif // !_LIBCPP_HAS_NO_THREADS + +struct _LIBCPP_TEMPLATE_VIS once_flag; + +#ifndef _LIBCPP_CXX03_LANG + +template<class _Callable, class... _Args> +_LIBCPP_INLINE_VISIBILITY +void call_once(once_flag&, _Callable&&, _Args&&...); + +#else // _LIBCPP_CXX03_LANG + +template<class _Callable> +_LIBCPP_INLINE_VISIBILITY +void call_once(once_flag&, _Callable&); + +template<class _Callable> +_LIBCPP_INLINE_VISIBILITY +void call_once(once_flag&, const _Callable&); + +#endif // _LIBCPP_CXX03_LANG + +struct _LIBCPP_TEMPLATE_VIS once_flag +{ + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR + once_flag() _NOEXCEPT : __state_(0) {} + +#if defined(_LIBCPP_ABI_MICROSOFT) + typedef uintptr_t _State_type; +#else + typedef unsigned long _State_type; +#endif + + +private: + once_flag(const once_flag&); // = delete; + once_flag& operator=(const once_flag&); // = delete; + + _State_type __state_; + +#ifndef _LIBCPP_CXX03_LANG + template<class _Callable, class... _Args> + friend + void call_once(once_flag&, _Callable&&, _Args&&...); +#else // _LIBCPP_CXX03_LANG + template<class _Callable> + friend + void call_once(once_flag&, _Callable&); + + template<class _Callable> + friend + void call_once(once_flag&, const _Callable&); +#endif // _LIBCPP_CXX03_LANG +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Fp> +class __call_once_param +{ + _Fp& __f_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __call_once_param(_Fp& __f) : __f_(__f) {} + + _LIBCPP_INLINE_VISIBILITY + void operator()() + { + typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 1>::type _Index; + __execute(_Index()); + } + +private: + template <size_t ..._Indices> + _LIBCPP_INLINE_VISIBILITY + void __execute(__tuple_indices<_Indices...>) + { + __invoke(_VSTD::get<0>(_VSTD::move(__f_)), _VSTD::get<_Indices>(_VSTD::move(__f_))...); + } +}; + +#else + +template <class _Fp> +class __call_once_param +{ + _Fp& __f_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __call_once_param(_Fp& __f) : __f_(__f) {} + + _LIBCPP_INLINE_VISIBILITY + void operator()() + { + __f_(); + } +}; + +#endif + +template <class _Fp> +void +__call_once_proxy(void* __vp) +{ + __call_once_param<_Fp>* __p = static_cast<__call_once_param<_Fp>*>(__vp); + (*__p)(); +} + +_LIBCPP_FUNC_VIS void __call_once(volatile once_flag::_State_type&, void*, + void (*)(void*)); + +#ifndef _LIBCPP_CXX03_LANG + +template<class _Callable, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +void +call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args) +{ + if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) + { + typedef tuple<_Callable&&, _Args&&...> _Gp; + _Gp __f(_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...); + __call_once_param<_Gp> __p(__f); + __call_once(__flag.__state_, &__p, &__call_once_proxy<_Gp>); + } +} + +#else // _LIBCPP_CXX03_LANG + +template<class _Callable> +inline _LIBCPP_INLINE_VISIBILITY +void +call_once(once_flag& __flag, _Callable& __func) +{ + if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) + { + __call_once_param<_Callable> __p(__func); + __call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>); + } +} + +template<class _Callable> +inline _LIBCPP_INLINE_VISIBILITY +void +call_once(once_flag& __flag, const _Callable& __func) +{ + if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) + { + __call_once_param<const _Callable> __p(__func); + __call_once(__flag.__state_, &__p, &__call_once_proxy<const _Callable>); + } +} + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_MUTEX diff --git a/android/x86/include/v8/libc++/new b/android/x86/include/v8/libc++/new new file mode 100755 index 00000000..4cf4c4c1 --- /dev/null +++ b/android/x86/include/v8/libc++/new @@ -0,0 +1,357 @@ +// -*- C++ -*- +//===----------------------------- new ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_NEW +#define _LIBCPP_NEW + +/* + new synopsis + +namespace std +{ + +class bad_alloc + : public exception +{ +public: + bad_alloc() noexcept; + bad_alloc(const bad_alloc&) noexcept; + bad_alloc& operator=(const bad_alloc&) noexcept; + virtual const char* what() const noexcept; +}; + +class bad_array_new_length : public bad_alloc // C++14 +{ +public: + bad_array_new_length() noexcept; +}; + +enum class align_val_t : size_t {}; // C++17 +struct nothrow_t {}; +extern const nothrow_t nothrow; +typedef void (*new_handler)(); +new_handler set_new_handler(new_handler new_p) noexcept; +new_handler get_new_handler() noexcept; + +// 21.6.4, pointer optimization barrier +template <class T> constexpr T* launder(T* p) noexcept; // C++17 +} // std + +void* operator new(std::size_t size); // replaceable, nodiscard in C++2a +void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17, nodiscard in C++2a +void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a +void* operator new(std::size_t size, std::align_val_t alignment, + const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a +void operator delete(void* ptr) noexcept; // replaceable +void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14 +void operator delete(void* ptr, std::align_val_t alignment) noexcept; // replaceable, C++17 +void operator delete(void* ptr, std::size_t size, + std::align_val_t alignment) noexcept; // replaceable, C++17 +void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable +void operator delete(void* ptr, std:align_val_t alignment, + const std::nothrow_t&) noexcept; // replaceable, C++17 + +void* operator new[](std::size_t size); // replaceable, nodiscard in C++2a +void* operator new[](std::size_t size, + std::align_val_t alignment) noexcept; // replaceable, C++17, nodiscard in C++2a +void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a +void* operator new[](std::size_t size, std::align_val_t alignment, + const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a +void operator delete[](void* ptr) noexcept; // replaceable +void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14 +void operator delete[](void* ptr, + std::align_val_t alignment) noexcept; // replaceable, C++17 +void operator delete[](void* ptr, std::size_t size, + std::align_val_t alignment) noexcept; // replaceable, C++17 +void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable +void operator delete[](void* ptr, std::align_val_t alignment, + const std::nothrow_t&) noexcept; // replaceable, C++17 + +void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++2a +void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++2a +void operator delete (void* ptr, void*) noexcept; +void operator delete[](void* ptr, void*) noexcept; + +*/ + +#include <__config> +#include <exception> +#include <type_traits> +#include <cstddef> +#include <version> +#ifdef _LIBCPP_NO_EXCEPTIONS +#include <cstdlib> +#endif + +#if defined(_LIBCPP_ABI_VCRUNTIME) +#include <new.h> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if !defined(__cpp_sized_deallocation) || __cpp_sized_deallocation < 201309L +#define _LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION +#endif + +#if !defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_STD_VER < 14 && \ + defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION) +# define _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION +#endif + +#if defined(_LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION) || \ + defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION) +# define _LIBCPP_HAS_NO_SIZED_DEALLOCATION +#endif + +#if !__has_builtin(__builtin_operator_new) || \ + __has_builtin(__builtin_operator_new) < 201802L +#define _LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE +#endif + +namespace std // purposefully not using versioning namespace +{ + +#if !defined(_LIBCPP_ABI_VCRUNTIME) +struct _LIBCPP_TYPE_VIS nothrow_t {}; +extern _LIBCPP_FUNC_VIS const nothrow_t nothrow; + +class _LIBCPP_EXCEPTION_ABI bad_alloc + : public exception +{ +public: + bad_alloc() _NOEXCEPT; + virtual ~bad_alloc() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +class _LIBCPP_EXCEPTION_ABI bad_array_new_length + : public bad_alloc +{ +public: + bad_array_new_length() _NOEXCEPT; + virtual ~bad_array_new_length() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +typedef void (*new_handler)(); +_LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; +_LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; + +#endif // !_LIBCPP_ABI_VCRUNTIME + +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec + +#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) && \ + !defined(_LIBCPP_ABI_VCRUNTIME) +#ifndef _LIBCPP_CXX03_LANG +enum class _LIBCPP_ENUM_VIS align_val_t : size_t { }; +#else +enum align_val_t { __zero = 0, __max = (size_t)-1 }; +#endif +#endif + +} // std + +#if defined(_LIBCPP_CXX03_LANG) +#define _THROW_BAD_ALLOC throw(std::bad_alloc) +#else +#define _THROW_BAD_ALLOC +#endif + +#if !defined(_LIBCPP_ABI_VCRUNTIME) + +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION +_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT; +#endif + +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION +_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT; +#endif + +#ifndef _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION +_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT; +#endif + +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION +_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT; +#endif +#endif + +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} +inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} +inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} + +#endif // !_LIBCPP_ABI_VCRUNTIME + +_LIBCPP_BEGIN_NAMESPACE_STD + +_LIBCPP_CONSTEXPR inline _LIBCPP_INLINE_VISIBILITY bool __is_overaligned_for_new(size_t __align) _NOEXCEPT { +#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__ + return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__; +#else + return __align > alignment_of<max_align_t>::value; +#endif +} + +inline _LIBCPP_INLINE_VISIBILITY void *__libcpp_allocate(size_t __size, size_t __align) { +#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION + if (__is_overaligned_for_new(__align)) { + const align_val_t __align_val = static_cast<align_val_t>(__align); +# ifdef _LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE + return ::operator new(__size, __align_val); +# else + return __builtin_operator_new(__size, __align_val); +# endif + } +#else + ((void)__align); +#endif +#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE + return ::operator new(__size); +#else + return __builtin_operator_new(__size); +#endif +} + +struct _DeallocateCaller { + static inline _LIBCPP_INLINE_VISIBILITY + void __do_deallocate_handle_size_align(void *__ptr, size_t __size, size_t __align) { +#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) + ((void)__align); + return __do_deallocate_handle_size(__ptr, __size); +#else + if (__is_overaligned_for_new(__align)) { + const align_val_t __align_val = static_cast<align_val_t>(__align); + return __do_deallocate_handle_size(__ptr, __size, __align_val); + } else { + return __do_deallocate_handle_size(__ptr, __size); + } +#endif + } + + static inline _LIBCPP_INLINE_VISIBILITY + void __do_deallocate_handle_align(void *__ptr, size_t __align) { +#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) + ((void)__align); + return __do_call(__ptr); +#else + if (__is_overaligned_for_new(__align)) { + const align_val_t __align_val = static_cast<align_val_t>(__align); + return __do_call(__ptr, __align_val); + } else { + return __do_call(__ptr); + } +#endif + } + + private: + static inline void __do_deallocate_handle_size(void *__ptr, size_t __size) { +#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION + ((void)__size); + return __do_call(__ptr); +#else + return __do_call(__ptr, __size); +#endif + } + +#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION + static inline void __do_deallocate_handle_size(void *__ptr, size_t __size, align_val_t __align) { +#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION + ((void)__size); + return __do_call(__ptr, __align); +#else + return __do_call(__ptr, __size, __align); +#endif + } +#endif + +private: + template <class _A1, class _A2> + static inline void __do_call(void *__ptr, _A1 __a1, _A2 __a2) { +#if defined(_LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE) || \ + defined(_LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE) + return ::operator delete(__ptr, __a1, __a2); +#else + return __builtin_operator_delete(__ptr, __a1, __a2); +#endif + } + + template <class _A1> + static inline void __do_call(void *__ptr, _A1 __a1) { +#if defined(_LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE) || \ + defined(_LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE) + return ::operator delete(__ptr, __a1); +#else + return __builtin_operator_delete(__ptr, __a1); +#endif + } + + static inline void __do_call(void *__ptr) { +#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE + return ::operator delete(__ptr); +#else + return __builtin_operator_delete(__ptr); +#endif + } +}; + +inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) { + _DeallocateCaller::__do_deallocate_handle_size_align(__ptr, __size, __align); +} + +inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate_unsized(void* __ptr, size_t __align) { + _DeallocateCaller::__do_deallocate_handle_align(__ptr, __align); +} + +template <class _Tp> +_LIBCPP_NODISCARD_AFTER_CXX17 inline +_LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT +{ + static_assert (!(is_function<_Tp>::value), "can't launder functions" ); + static_assert (!(is_same<void, typename remove_cv<_Tp>::type>::value), "can't launder cv-void" ); +#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER + return __builtin_launder(__p); +#else + return __p; +#endif +} + + +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp* launder(_Tp* __p) noexcept +{ + return _VSTD::__launder(__p); +} +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_NEW diff --git a/android/x86/include/v8/libc++/numeric b/android/x86/include/v8/libc++/numeric new file mode 100755 index 00000000..8d159afa --- /dev/null +++ b/android/x86/include/v8/libc++/numeric @@ -0,0 +1,561 @@ +// -*- C++ -*- +//===---------------------------- numeric ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_NUMERIC +#define _LIBCPP_NUMERIC + +/* + numeric synopsis + +namespace std +{ + +template <class InputIterator, class T> + T + accumulate(InputIterator first, InputIterator last, T init); + +template <class InputIterator, class T, class BinaryOperation> + T + accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); + +template<class InputIterator> + typename iterator_traits<InputIterator>::value_type + reduce(InputIterator first, InputIterator last); // C++17 + +template<class InputIterator, class T> + T + reduce(InputIterator first, InputIterator last, T init); // C++17 + +template<class InputIterator, class T, class BinaryOperation> + T + reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17 + +template <class InputIterator1, class InputIterator2, class T> + T + inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); + +template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> + T + inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, + T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); + + +template<class InputIterator1, class InputIterator2, class T> + T + transform_reduce(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, T init); // C++17 + +template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> + T + transform_reduce(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, T init, + BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17 + +template<class InputIterator, class T, class BinaryOperation, class UnaryOperation> + T + transform_reduce(InputIterator first, InputIterator last, T init, + BinaryOperation binary_op, UnaryOperation unary_op); // C++17 + +template <class InputIterator, class OutputIterator> + OutputIterator + partial_sum(InputIterator first, InputIterator last, OutputIterator result); + +template <class InputIterator, class OutputIterator, class BinaryOperation> + OutputIterator + partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); + +template<class InputIterator, class OutputIterator, class T> + OutputIterator + exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init); // C++17 + +template<class InputIterator, class OutputIterator, class T, class BinaryOperation> + OutputIterator + exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init, BinaryOperation binary_op); // C++17 + +template<class InputIterator, class OutputIterator> + OutputIterator + inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17 + +template<class InputIterator, class OutputIterator, class BinaryOperation> + OutputIterator + inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, BinaryOperation binary_op); // C++17 + +template<class InputIterator, class OutputIterator, class BinaryOperation, class T> + OutputIterator + inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, BinaryOperation binary_op, T init); // C++17 + +template<class InputIterator, class OutputIterator, class T, + class BinaryOperation, class UnaryOperation> + OutputIterator + transform_exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init, + BinaryOperation binary_op, UnaryOperation unary_op); // C++17 + +template<class InputIterator, class OutputIterator, + class BinaryOperation, class UnaryOperation> + OutputIterator + transform_inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, + BinaryOperation binary_op, UnaryOperation unary_op); // C++17 + +template<class InputIterator, class OutputIterator, + class BinaryOperation, class UnaryOperation, class T> + OutputIterator + transform_inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, + BinaryOperation binary_op, UnaryOperation unary_op, + T init); // C++17 + +template <class InputIterator, class OutputIterator> + OutputIterator + adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); + +template <class InputIterator, class OutputIterator, class BinaryOperation> + OutputIterator + adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); + +template <class ForwardIterator, class T> + void iota(ForwardIterator first, ForwardIterator last, T value); + +template <class M, class N> + constexpr common_type_t<M,N> gcd(M m, N n); // C++17 + +template <class M, class N> + constexpr common_type_t<M,N> lcm(M m, N n); // C++17 + +integer midpoint(integer a, integer b); // C++20 +pointer midpoint(pointer a, pointer b); // C++20 +floating_point midpoint(floating_point a, floating_point b); // C++20 + +} // std + +*/ + +#include <__config> +#include <iterator> +#include <limits> // for numeric_limits +#include <functional> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _InputIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) +{ + for (; __first != __last; ++__first) + __init = __init + *__first; + return __init; +} + +template <class _InputIterator, class _Tp, class _BinaryOperation> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op) +{ + for (; __first != __last; ++__first) + __init = __binary_op(__init, *__first); + return __init; +} + +#if _LIBCPP_STD_VER > 14 +template <class _InputIterator, class _Tp, class _BinaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b) +{ + for (; __first != __last; ++__first) + __init = __b(__init, *__first); + return __init; +} + +template <class _InputIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +reduce(_InputIterator __first, _InputIterator __last, _Tp __init) +{ + return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>()); +} + +template <class _InputIterator> +inline _LIBCPP_INLINE_VISIBILITY +typename iterator_traits<_InputIterator>::value_type +reduce(_InputIterator __first, _InputIterator __last) +{ + return _VSTD::reduce(__first, __last, + typename iterator_traits<_InputIterator>::value_type{}); +} +#endif + +template <class _InputIterator1, class _InputIterator2, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) + __init = __init + *__first1 * *__first2; + return __init; +} + +template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, + _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) + __init = __binary_op1(__init, __binary_op2(*__first1, *__first2)); + return __init; +} + +#if _LIBCPP_STD_VER > 14 +template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +transform_reduce(_InputIterator __first, _InputIterator __last, + _Tp __init, _BinaryOp __b, _UnaryOp __u) +{ + for (; __first != __last; ++__first) + __init = __b(__init, __u(*__first)); + return __init; +} + +template <class _InputIterator1, class _InputIterator2, + class _Tp, class _BinaryOp1, class _BinaryOp2> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _Tp __init, _BinaryOp1 __b1, _BinaryOp2 __b2) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) + __init = __b1(__init, __b2(*__first1, *__first2)); + return __init; +} + +template <class _InputIterator1, class _InputIterator2, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _Tp __init) +{ + return _VSTD::transform_reduce(__first1, __last1, __first2, _VSTD::move(__init), + _VSTD::plus<>(), _VSTD::multiplies<>()); +} +#endif + +template <class _InputIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t(*__first); + *__result = __t; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + __t = __t + *__first; + *__result = __t; + } + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOperation> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + _BinaryOperation __binary_op) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t(*__first); + *__result = __t; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + __t = __binary_op(__t, *__first); + *__result = __t; + } + } + return __result; +} + +#if _LIBCPP_STD_VER > 14 +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init, _BinaryOp __b) +{ + if (__first != __last) + { + _Tp __saved = __init; + do + { + __init = __b(__init, *__first); + *__result = __saved; + __saved = __init; + ++__result; + } while (++__first != __last); + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init) +{ + return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>()); +} + +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp> +_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b, _Tp __init) +{ + for (; __first != __last; ++__first, (void) ++__result) { + __init = __b(__init, *__first); + *__result = __init; + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOp> +_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b) +{ + if (__first != __last) { + typename std::iterator_traits<_InputIterator>::value_type __init = *__first; + *__result++ = __init; + if (++__first != __last) + return _VSTD::inclusive_scan(__first, __last, __result, __b, __init); + } + + return __result; +} + +template <class _InputIterator, class _OutputIterator> +_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result) +{ + return _VSTD::inclusive_scan(__first, __last, __result, std::plus<>()); +} + +template <class _InputIterator, class _OutputIterator, class _Tp, + class _BinaryOp, class _UnaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +transform_exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init, + _BinaryOp __b, _UnaryOp __u) +{ + if (__first != __last) + { + _Tp __saved = __init; + do + { + __init = __b(__init, __u(*__first)); + *__result = __saved; + __saved = __init; + ++__result; + } while (++__first != __last); + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp> +_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init) +{ + for (; __first != __last; ++__first, (void) ++__result) { + __init = __b(__init, __u(*__first)); + *__result = __init; + } + + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp> +_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b, _UnaryOp __u) +{ + if (__first != __last) { + typename std::iterator_traits<_InputIterator>::value_type __init = __u(*__first); + *__result++ = __init; + if (++__first != __last) + return _VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init); + } + + return __result; +} +#endif + +template <class _InputIterator, class _OutputIterator> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t1(*__first); + *__result = __t1; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + typename iterator_traits<_InputIterator>::value_type __t2(*__first); + *__result = __t2 - __t1; + __t1 = _VSTD::move(__t2); + } + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOperation> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + _BinaryOperation __binary_op) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t1(*__first); + *__result = __t1; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + typename iterator_traits<_InputIterator>::value_type __t2(*__first); + *__result = __binary_op(__t2, __t1); + __t1 = _VSTD::move(__t2); + } + } + return __result; +} + +template <class _ForwardIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void +iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_) +{ + for (; __first != __last; ++__first, (void) ++__value_) + *__first = __value_; +} + + +#if _LIBCPP_STD_VER > 14 +template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __abs; + +template <typename _Result, typename _Source> +struct __abs<_Result, _Source, true> { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + _Result operator()(_Source __t) const noexcept + { + if (__t >= 0) return __t; + if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t); + return -__t; + } +}; + +template <typename _Result, typename _Source> +struct __abs<_Result, _Source, false> { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + _Result operator()(_Source __t) const noexcept { return __t; } +}; + + +template<class _Tp> +_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN +_Tp __gcd(_Tp __m, _Tp __n) +{ + static_assert((!is_signed<_Tp>::value), ""); + return __n == 0 ? __m : _VSTD::__gcd<_Tp>(__n, __m % __n); +} + + +template<class _Tp, class _Up> +_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY +common_type_t<_Tp,_Up> +gcd(_Tp __m, _Up __n) +{ + static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types"); + static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" ); + static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" ); + using _Rp = common_type_t<_Tp,_Up>; + using _Wp = make_unsigned_t<_Rp>; + return static_cast<_Rp>(_VSTD::__gcd( + static_cast<_Wp>(__abs<_Rp, _Tp>()(__m)), + static_cast<_Wp>(__abs<_Rp, _Up>()(__n)))); +} + +template<class _Tp, class _Up> +_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY +common_type_t<_Tp,_Up> +lcm(_Tp __m, _Up __n) +{ + static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types"); + static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" ); + static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" ); + if (__m == 0 || __n == 0) + return 0; + + using _Rp = common_type_t<_Tp,_Up>; + _Rp __val1 = __abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n); + _Rp __val2 = __abs<_Rp, _Up>()(__n); + _LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm"); + return __val1 * __val2; +} + +#endif /* _LIBCPP_STD_VER > 14 */ + +#if _LIBCPP_STD_VER > 17 +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp>, _Tp> +midpoint(_Tp __a, _Tp __b) noexcept +_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ + using _Up = std::make_unsigned_t<_Tp>; + + int __sign = 1; + _Up __m = __a; + _Up __M = __b; + if (__a > __b) + { + __sign = -1; + __m = __b; + __M = __a; + } + return __a + __sign * _Tp(_Up(__M-__m) >> 1); +} + + +template <class _TPtr> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<is_pointer_v<_TPtr>, _TPtr> +midpoint(_TPtr __a, _TPtr __b) noexcept +{ + return __a + _VSTD::midpoint(ptrdiff_t(0), __b - __a); +} +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_NUMERIC diff --git a/android/x86/include/v8/libc++/optional b/android/x86/include/v8/libc++/optional new file mode 100755 index 00000000..1fc752e6 --- /dev/null +++ b/android/x86/include/v8/libc++/optional @@ -0,0 +1,1419 @@ +// -*- C++ -*- +//===-------------------------- optional ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_OPTIONAL +#define _LIBCPP_OPTIONAL + +/* + optional synopsis + +// C++1z + +namespace std { + // 23.6.3, optional for object types + template <class T> class optional; + + // 23.6.4, no-value state indicator + struct nullopt_t{see below }; + inline constexpr nullopt_t nullopt(unspecified ); + + // 23.6.5, class bad_optional_access + class bad_optional_access; + + // 23.6.6, relational operators + template <class T, class U> + constexpr bool operator==(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator!=(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator<(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator>(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator<=(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator>=(const optional<T>&, const optional<U>&); + + // 23.6.7 comparison with nullopt + template <class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept; + + // 23.6.8, comparison with T + template <class T, class U> constexpr bool operator==(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator==(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator!=(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator!=(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator<(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator<(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator<=(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator<=(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator>(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator>(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator>=(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator>=(const T&, const optional<U>&); + + // 23.6.9, specialized algorithms + template <class T> void swap(optional<T>&, optional<T>&) noexcept(see below ); + template <class T> constexpr optional<see below > make_optional(T&&); + template <class T, class... Args> + constexpr optional<T> make_optional(Args&&... args); + template <class T, class U, class... Args> + constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args); + + // 23.6.10, hash support + template <class T> struct hash; + template <class T> struct hash<optional<T>>; + + template <class T> class optional { + public: + using value_type = T; + + // 23.6.3.1, constructors + constexpr optional() noexcept; + constexpr optional(nullopt_t) noexcept; + optional(const optional &); + optional(optional &&) noexcept(see below); + template <class... Args> constexpr explicit optional(in_place_t, Args &&...); + template <class U, class... Args> + constexpr explicit optional(in_place_t, initializer_list<U>, Args &&...); + template <class U = T> + constexpr EXPLICIT optional(U &&); + template <class U> + constexpr EXPLICIT optional(const optional<U> &); + template <class U> + constexpr EXPLICIT optional(optional<U> &&); + + // 23.6.3.2, destructor + ~optional(); + + // 23.6.3.3, assignment + optional &operator=(nullopt_t) noexcept; + optional &operator=(const optional &); // constexpr in C++20 + optional &operator=(optional &&) noexcept(see below); // constexpr in C++20 + template <class U = T> optional &operator=(U &&); + template <class U> optional &operator=(const optional<U> &); + template <class U> optional &operator=(optional<U> &&); + template <class... Args> T& emplace(Args &&...); + template <class U, class... Args> + T& emplace(initializer_list<U>, Args &&...); + + // 23.6.3.4, swap + void swap(optional &) noexcept(see below ); + + // 23.6.3.5, observers + constexpr T const *operator->() const; + constexpr T *operator->(); + constexpr T const &operator*() const &; + constexpr T &operator*() &; + constexpr T &&operator*() &&; + constexpr const T &&operator*() const &&; + constexpr explicit operator bool() const noexcept; + constexpr bool has_value() const noexcept; + constexpr T const &value() const &; + constexpr T &value() &; + constexpr T &&value() &&; + constexpr const T &&value() const &&; + template <class U> constexpr T value_or(U &&) const &; + template <class U> constexpr T value_or(U &&) &&; + + // 23.6.3.6, modifiers + void reset() noexcept; + + private: + T *val; // exposition only + }; + +template<class T> + optional(T) -> optional<T>; + +} // namespace std + +*/ + +#include <__config> +#include <__debug> +#include <__functional_base> +#include <functional> +#include <initializer_list> +#include <new> +#include <stdexcept> +#include <type_traits> +#include <utility> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +namespace std // purposefully not using versioning namespace +{ + +class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access + : public exception +{ +public: + // Get the key function ~bad_optional_access() into the dylib + virtual ~bad_optional_access() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +} // std + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_BEGIN_NAMESPACE_STD + +_LIBCPP_NORETURN +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS +void __throw_bad_optional_access() { +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_optional_access(); +#else + _VSTD::abort(); +#endif +} + +struct nullopt_t +{ + struct __secret_tag { _LIBCPP_INLINE_VISIBILITY explicit __secret_tag() = default; }; + _LIBCPP_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {} +}; + +_LIBCPP_INLINE_VAR constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}}; + +template <class _Tp, bool = is_trivially_destructible<_Tp>::value> +struct __optional_destruct_base; + +template <class _Tp> +struct __optional_destruct_base<_Tp, false> +{ + typedef _Tp value_type; + static_assert(is_object_v<value_type>, + "instantiation of optional with a non-object type is undefined behavior"); + union + { + char __null_state_; + value_type __val_; + }; + bool __engaged_; + + _LIBCPP_INLINE_VISIBILITY + ~__optional_destruct_base() + { + if (__engaged_) + __val_.~value_type(); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr __optional_destruct_base() noexcept + : __null_state_(), + __engaged_(false) {} + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(_VSTD::forward<_Args>(__args)...), + __engaged_(true) {} + + _LIBCPP_INLINE_VISIBILITY + void reset() noexcept + { + if (__engaged_) + { + __val_.~value_type(); + __engaged_ = false; + } + } +}; + +template <class _Tp> +struct __optional_destruct_base<_Tp, true> +{ + typedef _Tp value_type; + static_assert(is_object_v<value_type>, + "instantiation of optional with a non-object type is undefined behavior"); + union + { + char __null_state_; + value_type __val_; + }; + bool __engaged_; + + _LIBCPP_INLINE_VISIBILITY + constexpr __optional_destruct_base() noexcept + : __null_state_(), + __engaged_(false) {} + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(_VSTD::forward<_Args>(__args)...), + __engaged_(true) {} + + _LIBCPP_INLINE_VISIBILITY + void reset() noexcept + { + if (__engaged_) + { + __engaged_ = false; + } + } +}; + +template <class _Tp, bool = is_reference<_Tp>::value> +struct __optional_storage_base : __optional_destruct_base<_Tp> +{ + using __base = __optional_destruct_base<_Tp>; + using value_type = _Tp; + using __base::__base; + + _LIBCPP_INLINE_VISIBILITY + constexpr bool has_value() const noexcept + { + return this->__engaged_; + } + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type& __get() & noexcept + { + return this->__val_; + } + _LIBCPP_INLINE_VISIBILITY + constexpr const value_type& __get() const& noexcept + { + return this->__val_; + } + _LIBCPP_INLINE_VISIBILITY + constexpr value_type&& __get() && noexcept + { + return _VSTD::move(this->__val_); + } + _LIBCPP_INLINE_VISIBILITY + constexpr const value_type&& __get() const&& noexcept + { + return _VSTD::move(this->__val_); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + void __construct(_Args&&... __args) + { + _LIBCPP_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); + ::new((void*)_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Args>(__args)...); + this->__engaged_ = true; + } + + template <class _That> + _LIBCPP_INLINE_VISIBILITY + void __construct_from(_That&& __opt) + { + if (__opt.has_value()) + __construct(_VSTD::forward<_That>(__opt).__get()); + } + + template <class _That> + _LIBCPP_INLINE_VISIBILITY + void __assign_from(_That&& __opt) + { + if (this->__engaged_ == __opt.has_value()) + { + if (this->__engaged_) + this->__val_ = _VSTD::forward<_That>(__opt).__get(); + } + else + { + if (this->__engaged_) + this->reset(); + else + __construct(_VSTD::forward<_That>(__opt).__get()); + } + } +}; + +// optional<T&> is currently required ill-formed, however it may to be in the +// future. For this reason it has already been implemented to ensure we can +// make the change in an ABI compatible manner. +template <class _Tp> +struct __optional_storage_base<_Tp, true> +{ + using value_type = _Tp; + using __raw_type = remove_reference_t<_Tp>; + __raw_type* __value_; + + template <class _Up> + static constexpr bool __can_bind_reference() { + using _RawUp = typename remove_reference<_Up>::type; + using _UpPtr = _RawUp*; + using _RawTp = typename remove_reference<_Tp>::type; + using _TpPtr = _RawTp*; + using _CheckLValueArg = integral_constant<bool, + (is_lvalue_reference<_Up>::value && is_convertible<_UpPtr, _TpPtr>::value) + || is_same<_RawUp, reference_wrapper<_RawTp>>::value + || is_same<_RawUp, reference_wrapper<typename remove_const<_RawTp>::type>>::value + >; + return (is_lvalue_reference<_Tp>::value && _CheckLValueArg::value) + || (is_rvalue_reference<_Tp>::value && !is_lvalue_reference<_Up>::value && + is_convertible<_UpPtr, _TpPtr>::value); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr __optional_storage_base() noexcept + : __value_(nullptr) {} + + template <class _UArg> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit __optional_storage_base(in_place_t, _UArg&& __uarg) + : __value_(_VSTD::addressof(__uarg)) + { + static_assert(__can_bind_reference<_UArg>(), + "Attempted to construct a reference element in tuple from a " + "possible temporary"); + } + + _LIBCPP_INLINE_VISIBILITY + void reset() noexcept { __value_ = nullptr; } + + _LIBCPP_INLINE_VISIBILITY + constexpr bool has_value() const noexcept + { return __value_ != nullptr; } + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type& __get() const& noexcept + { return *__value_; } + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type&& __get() const&& noexcept + { return _VSTD::forward<value_type>(*__value_); } + + template <class _UArg> + _LIBCPP_INLINE_VISIBILITY + void __construct(_UArg&& __val) + { + _LIBCPP_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); + static_assert(__can_bind_reference<_UArg>(), + "Attempted to construct a reference element in tuple from a " + "possible temporary"); + __value_ = _VSTD::addressof(__val); + } + + template <class _That> + _LIBCPP_INLINE_VISIBILITY + void __construct_from(_That&& __opt) + { + if (__opt.has_value()) + __construct(_VSTD::forward<_That>(__opt).__get()); + } + + template <class _That> + _LIBCPP_INLINE_VISIBILITY + void __assign_from(_That&& __opt) + { + if (has_value() == __opt.has_value()) + { + if (has_value()) + *__value_ = _VSTD::forward<_That>(__opt).__get(); + } + else + { + if (has_value()) + reset(); + else + __construct(_VSTD::forward<_That>(__opt).__get()); + } + } +}; + +template <class _Tp, bool = is_trivially_copy_constructible<_Tp>::value> +struct __optional_copy_base : __optional_storage_base<_Tp> +{ + using __optional_storage_base<_Tp>::__optional_storage_base; +}; + +template <class _Tp> +struct __optional_copy_base<_Tp, false> : __optional_storage_base<_Tp> +{ + using __optional_storage_base<_Tp>::__optional_storage_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base() = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base(const __optional_copy_base& __opt) + { + this->__construct_from(__opt); + } + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base(__optional_copy_base&&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base& operator=(const __optional_copy_base&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base& operator=(__optional_copy_base&&) = default; +}; + +template <class _Tp, bool = is_trivially_move_constructible<_Tp>::value> +struct __optional_move_base : __optional_copy_base<_Tp> +{ + using __optional_copy_base<_Tp>::__optional_copy_base; +}; + +template <class _Tp> +struct __optional_move_base<_Tp, false> : __optional_copy_base<_Tp> +{ + using value_type = _Tp; + using __optional_copy_base<_Tp>::__optional_copy_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_base() = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_base(const __optional_move_base&) = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_base(__optional_move_base&& __opt) + noexcept(is_nothrow_move_constructible_v<value_type>) + { + this->__construct_from(_VSTD::move(__opt)); + } + + _LIBCPP_INLINE_VISIBILITY + __optional_move_base& operator=(const __optional_move_base&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_base& operator=(__optional_move_base&&) = default; +}; + +template <class _Tp, bool = + is_trivially_destructible<_Tp>::value && + is_trivially_copy_constructible<_Tp>::value && + is_trivially_copy_assignable<_Tp>::value> +struct __optional_copy_assign_base : __optional_move_base<_Tp> +{ + using __optional_move_base<_Tp>::__optional_move_base; +}; + +template <class _Tp> +struct __optional_copy_assign_base<_Tp, false> : __optional_move_base<_Tp> +{ + using __optional_move_base<_Tp>::__optional_move_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base() = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base(const __optional_copy_assign_base&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base(__optional_copy_assign_base&&) = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base& operator=(const __optional_copy_assign_base& __opt) + { + this->__assign_from(__opt); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = default; +}; + +template <class _Tp, bool = + is_trivially_destructible<_Tp>::value && + is_trivially_move_constructible<_Tp>::value && + is_trivially_move_assignable<_Tp>::value> +struct __optional_move_assign_base : __optional_copy_assign_base<_Tp> +{ + using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base; +}; + +template <class _Tp> +struct __optional_move_assign_base<_Tp, false> : __optional_copy_assign_base<_Tp> +{ + using value_type = _Tp; + using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base() = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base(const __optional_move_assign_base& __opt) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base(__optional_move_assign_base&&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base& operator=(const __optional_move_assign_base&) = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base& operator=(__optional_move_assign_base&& __opt) + noexcept(is_nothrow_move_assignable_v<value_type> && + is_nothrow_move_constructible_v<value_type>) + { + this->__assign_from(_VSTD::move(__opt)); + return *this; + } +}; + +template <class _Tp> +using __optional_sfinae_ctor_base_t = __sfinae_ctor_base< + is_copy_constructible<_Tp>::value, + is_move_constructible<_Tp>::value +>; + +template <class _Tp> +using __optional_sfinae_assign_base_t = __sfinae_assign_base< + (is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value), + (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value) +>; + +template <class _Tp> +class optional + : private __optional_move_assign_base<_Tp> + , private __optional_sfinae_ctor_base_t<_Tp> + , private __optional_sfinae_assign_base_t<_Tp> +{ + using __base = __optional_move_assign_base<_Tp>; +public: + using value_type = _Tp; + +private: + // Disable the reference extension using this static assert. + static_assert(!is_same_v<__uncvref_t<value_type>, in_place_t>, + "instantiation of optional with in_place_t is ill-formed"); + static_assert(!is_same_v<__uncvref_t<value_type>, nullopt_t>, + "instantiation of optional with nullopt_t is ill-formed"); + static_assert(!is_reference_v<value_type>, + "instantiation of optional with a reference type is ill-formed"); + static_assert(is_destructible_v<value_type>, + "instantiation of optional with a non-destructible type is ill-formed"); + static_assert(!is_array_v<value_type>, + "instantiation of optional with an array type is ill-formed"); + + // LWG2756: conditionally explicit conversion from _Up + struct _CheckOptionalArgsConstructor { + template <class _Up> + static constexpr bool __enable_implicit() { + return is_constructible_v<_Tp, _Up&&> && + is_convertible_v<_Up&&, _Tp>; + } + + template <class _Up> + static constexpr bool __enable_explicit() { + return is_constructible_v<_Tp, _Up&&> && + !is_convertible_v<_Up&&, _Tp>; + } + }; + template <class _Up> + using _CheckOptionalArgsCtor = conditional_t< + !is_same_v<__uncvref_t<_Up>, in_place_t> && + !is_same_v<__uncvref_t<_Up>, optional>, + _CheckOptionalArgsConstructor, + __check_tuple_constructor_fail + >; + template <class _QualUp> + struct _CheckOptionalLikeConstructor { + template <class _Up, class _Opt = optional<_Up>> + using __check_constructible_from_opt = __lazy_or< + is_constructible<_Tp, _Opt&>, + is_constructible<_Tp, _Opt const&>, + is_constructible<_Tp, _Opt&&>, + is_constructible<_Tp, _Opt const&&>, + is_convertible<_Opt&, _Tp>, + is_convertible<_Opt const&, _Tp>, + is_convertible<_Opt&&, _Tp>, + is_convertible<_Opt const&&, _Tp> + >; + template <class _Up, class _Opt = optional<_Up>> + using __check_assignable_from_opt = __lazy_or< + is_assignable<_Tp&, _Opt&>, + is_assignable<_Tp&, _Opt const&>, + is_assignable<_Tp&, _Opt&&>, + is_assignable<_Tp&, _Opt const&&> + >; + template <class _Up, class _QUp = _QualUp> + static constexpr bool __enable_implicit() { + return is_convertible<_QUp, _Tp>::value && + !__check_constructible_from_opt<_Up>::value; + } + template <class _Up, class _QUp = _QualUp> + static constexpr bool __enable_explicit() { + return !is_convertible<_QUp, _Tp>::value && + !__check_constructible_from_opt<_Up>::value; + } + template <class _Up, class _QUp = _QualUp> + static constexpr bool __enable_assign() { + // Construction and assignability of _Qup to _Tp has already been + // checked. + return !__check_constructible_from_opt<_Up>::value && + !__check_assignable_from_opt<_Up>::value; + } + }; + + template <class _Up, class _QualUp> + using _CheckOptionalLikeCtor = conditional_t< + __lazy_and< + __lazy_not<is_same<_Up, _Tp>>, + is_constructible<_Tp, _QualUp> + >::value, + _CheckOptionalLikeConstructor<_QualUp>, + __check_tuple_constructor_fail + >; + template <class _Up, class _QualUp> + using _CheckOptionalLikeAssign = conditional_t< + __lazy_and< + __lazy_not<is_same<_Up, _Tp>>, + is_constructible<_Tp, _QualUp>, + is_assignable<_Tp&, _QualUp> + >::value, + _CheckOptionalLikeConstructor<_QualUp>, + __check_tuple_constructor_fail + >; +public: + + _LIBCPP_INLINE_VISIBILITY constexpr optional() noexcept {} + _LIBCPP_INLINE_VISIBILITY constexpr optional(const optional&) = default; + _LIBCPP_INLINE_VISIBILITY constexpr optional(optional&&) = default; + _LIBCPP_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {} + + template <class _InPlaceT, class... _Args, class = enable_if_t< + __lazy_and< + is_same<_InPlaceT, in_place_t>, + is_constructible<value_type, _Args...> + >::value + > + > + _LIBCPP_INLINE_VISIBILITY + constexpr explicit optional(_InPlaceT, _Args&&... __args) + : __base(in_place, _VSTD::forward<_Args>(__args)...) {} + + template <class _Up, class... _Args, class = enable_if_t< + is_constructible_v<value_type, initializer_list<_Up>&, _Args...>> + > + _LIBCPP_INLINE_VISIBILITY + constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) + : __base(in_place, __il, _VSTD::forward<_Args>(__args)...) {} + + template <class _Up = value_type, enable_if_t< + _CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + constexpr optional(_Up&& __v) + : __base(in_place, _VSTD::forward<_Up>(__v)) {} + + template <class _Up, enable_if_t< + _CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit optional(_Up&& __v) + : __base(in_place, _VSTD::forward<_Up>(__v)) {} + + // LWG2756: conditionally explicit conversion from const optional<_Up>& + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_implicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + optional(const optional<_Up>& __v) + { + this->__construct_from(__v); + } + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_explicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + explicit optional(const optional<_Up>& __v) + { + this->__construct_from(__v); + } + + // LWG2756: conditionally explicit conversion from optional<_Up>&& + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_implicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + optional(optional<_Up>&& __v) + { + this->__construct_from(_VSTD::move(__v)); + } + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_explicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + explicit optional(optional<_Up>&& __v) + { + this->__construct_from(_VSTD::move(__v)); + } + + _LIBCPP_INLINE_VISIBILITY + optional& operator=(nullopt_t) noexcept + { + reset(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY optional& operator=(const optional&) = default; + _LIBCPP_INLINE_VISIBILITY optional& operator=(optional&&) = default; + + // LWG2756 + template <class _Up = value_type, + class = enable_if_t + <__lazy_and< + integral_constant<bool, + !is_same_v<__uncvref_t<_Up>, optional> && + !(is_same_v<_Up, value_type> && is_scalar_v<value_type>) + >, + is_constructible<value_type, _Up>, + is_assignable<value_type&, _Up> + >::value> + > + _LIBCPP_INLINE_VISIBILITY + optional& + operator=(_Up&& __v) + { + if (this->has_value()) + this->__get() = _VSTD::forward<_Up>(__v); + else + this->__construct(_VSTD::forward<_Up>(__v)); + return *this; + } + + // LWG2756 + template <class _Up, enable_if_t< + _CheckOptionalLikeAssign<_Up, _Up const&>::template __enable_assign<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + optional& + operator=(const optional<_Up>& __v) + { + this->__assign_from(__v); + return *this; + } + + // LWG2756 + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_assign<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + optional& + operator=(optional<_Up>&& __v) + { + this->__assign_from(_VSTD::move(__v)); + return *this; + } + + template <class... _Args, + class = enable_if_t + < + is_constructible_v<value_type, _Args...> + > + > + _LIBCPP_INLINE_VISIBILITY + _Tp & + emplace(_Args&&... __args) + { + reset(); + this->__construct(_VSTD::forward<_Args>(__args)...); + return this->__get(); + } + + template <class _Up, class... _Args, + class = enable_if_t + < + is_constructible_v<value_type, initializer_list<_Up>&, _Args...> + > + > + _LIBCPP_INLINE_VISIBILITY + _Tp & + emplace(initializer_list<_Up> __il, _Args&&... __args) + { + reset(); + this->__construct(__il, _VSTD::forward<_Args>(__args)...); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(optional& __opt) + noexcept(is_nothrow_move_constructible_v<value_type> && + is_nothrow_swappable_v<value_type>) + { + if (this->has_value() == __opt.has_value()) + { + using _VSTD::swap; + if (this->has_value()) + swap(this->__get(), __opt.__get()); + } + else + { + if (this->has_value()) + { + __opt.__construct(_VSTD::move(this->__get())); + reset(); + } + else + { + this->__construct(_VSTD::move(__opt.__get())); + __opt.reset(); + } + } + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + add_pointer_t<value_type const> + operator->() const + { + _LIBCPP_ASSERT(this->has_value(), "optional operator-> called for disengaged value"); +#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF + return _VSTD::addressof(this->__get()); +#else + return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + add_pointer_t<value_type> + operator->() + { + _LIBCPP_ASSERT(this->has_value(), "optional operator-> called for disengaged value"); +#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF + return _VSTD::addressof(this->__get()); +#else + return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + const value_type& + operator*() const& + { + _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + value_type& + operator*() & + { + _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + value_type&& + operator*() && + { + _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); + return _VSTD::move(this->__get()); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + const value_type&& + operator*() const&& + { + _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); + return _VSTD::move(this->__get()); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr explicit operator bool() const noexcept { return has_value(); } + + using __base::has_value; + using __base::__get; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS + constexpr value_type const& value() const& + { + if (!this->has_value()) + __throw_bad_optional_access(); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS + constexpr value_type& value() & + { + if (!this->has_value()) + __throw_bad_optional_access(); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS + constexpr value_type&& value() && + { + if (!this->has_value()) + __throw_bad_optional_access(); + return _VSTD::move(this->__get()); + } + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS + constexpr value_type const&& value() const&& + { + if (!this->has_value()) + __throw_bad_optional_access(); + return _VSTD::move(this->__get()); + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + constexpr value_type value_or(_Up&& __v) const& + { + static_assert(is_copy_constructible_v<value_type>, + "optional<T>::value_or: T must be copy constructible"); + static_assert(is_convertible_v<_Up, value_type>, + "optional<T>::value_or: U must be convertible to T"); + return this->has_value() ? this->__get() : + static_cast<value_type>(_VSTD::forward<_Up>(__v)); + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + constexpr value_type value_or(_Up&& __v) && + { + static_assert(is_move_constructible_v<value_type>, + "optional<T>::value_or: T must be move constructible"); + static_assert(is_convertible_v<_Up, value_type>, + "optional<T>::value_or: U must be convertible to T"); + return this->has_value() ? _VSTD::move(this->__get()) : + static_cast<value_type>(_VSTD::forward<_Up>(__v)); + } + + using __base::reset; + +private: + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static _Up* + __operator_arrow(true_type, _Up& __x) + { + return _VSTD::addressof(__x); + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static constexpr _Up* + __operator_arrow(false_type, _Up& __x) + { + return &__x; + } +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class T> + optional(T) -> optional<T>; +#endif + +// Comparisons between optionals +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() == + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator==(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (static_cast<bool>(__x) != static_cast<bool>(__y)) + return false; + if (!static_cast<bool>(__x)) + return true; + return *__x == *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() != + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (static_cast<bool>(__x) != static_cast<bool>(__y)) + return true; + if (!static_cast<bool>(__x)) + return false; + return *__x != *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() < + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (!static_cast<bool>(__y)) + return false; + if (!static_cast<bool>(__x)) + return true; + return *__x < *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() > + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (!static_cast<bool>(__x)) + return false; + if (!static_cast<bool>(__y)) + return true; + return *__x > *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (!static_cast<bool>(__x)) + return true; + if (!static_cast<bool>(__y)) + return false; + return *__x <= *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (!static_cast<bool>(__y)) + return true; + if (!static_cast<bool>(__x)) + return false; + return *__x >= *__y; +} + +// Comparisons with nullopt +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator==(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return !static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator==(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return !static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator!=(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator!=(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator<(const optional<_Tp>&, nullopt_t) noexcept +{ + return false; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator<(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator<=(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return !static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator<=(nullopt_t, const optional<_Tp>&) noexcept +{ + return true; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator>(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator>(nullopt_t, const optional<_Tp>&) noexcept +{ + return false; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator>=(const optional<_Tp>&, nullopt_t) noexcept +{ + return true; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator>=(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return !static_cast<bool>(__x); +} + +// Comparisons with T +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() == + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator==(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x == __v : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() == + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator==(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v == *__x : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() != + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator!=(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x != __v : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() != + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator!=(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v != *__x : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() < + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x < __v : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() < + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v < *__x : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<=(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x <= __v : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<=(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v <= *__x : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() > + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x > __v : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() > + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v > *__x : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>=(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x >= __v : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>=(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v >= *__x : true; +} + + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +enable_if_t< + is_move_constructible_v<_Tp> && is_swappable_v<_Tp>, + void +> +swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +optional<decay_t<_Tp>> make_optional(_Tp&& __v) +{ + return optional<decay_t<_Tp>>(_VSTD::forward<_Tp>(__v)); +} + +template <class _Tp, class... _Args> +_LIBCPP_INLINE_VISIBILITY constexpr +optional<_Tp> make_optional(_Args&&... __args) +{ + return optional<_Tp>(in_place, _VSTD::forward<_Args>(__args)...); +} + +template <class _Tp, class _Up, class... _Args> +_LIBCPP_INLINE_VISIBILITY constexpr +optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... __args) +{ + return optional<_Tp>(in_place, __il, _VSTD::forward<_Args>(__args)...); +} + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS hash< + __enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>> +> +{ + typedef optional<_Tp> argument_type; + typedef size_t result_type; + + _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type& __opt) const + { + return static_cast<bool>(__opt) ? hash<remove_const_t<_Tp>>()(*__opt) : 0; + } +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_OPTIONAL diff --git a/android/x86/include/v8/libc++/ostream b/android/x86/include/v8/libc++/ostream new file mode 100755 index 00000000..b20ac34a --- /dev/null +++ b/android/x86/include/v8/libc++/ostream @@ -0,0 +1,1102 @@ +// -*- C++ -*- +//===-------------------------- ostream -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_OSTREAM +#define _LIBCPP_OSTREAM + +/* + ostream synopsis + +template <class charT, class traits = char_traits<charT> > +class basic_ostream + : virtual public basic_ios<charT,traits> +{ +public: + // types (inherited from basic_ios (27.5.4)): + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // 27.7.2.2 Constructor/destructor: + explicit basic_ostream(basic_streambuf<char_type,traits>* sb); + basic_ostream(basic_ostream&& rhs); + virtual ~basic_ostream(); + + // 27.7.2.3 Assign/swap + basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14 + basic_ostream& operator=(basic_ostream&& rhs); + void swap(basic_ostream& rhs); + + // 27.7.2.4 Prefix/suffix: + class sentry; + + // 27.7.2.6 Formatted output: + basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&)); + basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&)); + basic_ostream& operator<<(ios_base& (*pf)(ios_base&)); + basic_ostream& operator<<(bool n); + basic_ostream& operator<<(short n); + basic_ostream& operator<<(unsigned short n); + basic_ostream& operator<<(int n); + basic_ostream& operator<<(unsigned int n); + basic_ostream& operator<<(long n); + basic_ostream& operator<<(unsigned long n); + basic_ostream& operator<<(long long n); + basic_ostream& operator<<(unsigned long long n); + basic_ostream& operator<<(float f); + basic_ostream& operator<<(double f); + basic_ostream& operator<<(long double f); + basic_ostream& operator<<(const void* p); + basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb); + + // 27.7.2.7 Unformatted output: + basic_ostream& put(char_type c); + basic_ostream& write(const char_type* s, streamsize n); + basic_ostream& flush(); + + // 27.7.2.5 seeks: + pos_type tellp(); + basic_ostream& seekp(pos_type); + basic_ostream& seekp(off_type, ios_base::seekdir); +protected: + basic_ostream(const basic_ostream& rhs) = delete; + basic_ostream(basic_ostream&& rhs); + // 27.7.3.3 Assign/swap + basic_ostream& operator=(basic_ostream& rhs) = delete; + basic_ostream& operator=(const basic_ostream&& rhs); + void swap(basic_ostream& rhs); +}; + +// 27.7.2.6.4 character inserters + +template<class charT, class traits> + basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT); + +template<class charT, class traits> + basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char); + +template<class traits> + basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char); + +// signed and unsigned + +template<class traits> + basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char); + +template<class traits> + basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char); + +// NTBS +template<class charT, class traits> + basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*); + +template<class charT, class traits> + basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*); + +template<class traits> + basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*); + +// signed and unsigned +template<class traits> +basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*); + +template<class traits> + basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*); + +// swap: +template <class charT, class traits> + void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y); + +template <class charT, class traits> + basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os); + +template <class charT, class traits> + basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os); + +template <class charT, class traits> + basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os); + +// rvalue stream insertion +template <class charT, class traits, class T> + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>&& os, const T& x); + +} // std + +*/ + +#include <__config> +#include <ios> +#include <streambuf> +#include <locale> +#include <iterator> +#include <bitset> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_ostream + : virtual public basic_ios<_CharT, _Traits> +{ +public: + // types (inherited from basic_ios (27.5.4)): + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // 27.7.2.2 Constructor/destructor: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb) + { this->init(__sb); } + virtual ~basic_ostream(); +protected: +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY + basic_ostream(basic_ostream&& __rhs); + + // 27.7.2.3 Assign/swap + inline _LIBCPP_INLINE_VISIBILITY + basic_ostream& operator=(basic_ostream&& __rhs); +#endif + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + void swap(basic_ostream& __rhs) + { basic_ios<char_type, traits_type>::swap(__rhs); } + +#ifndef _LIBCPP_CXX03_LANG + basic_ostream (const basic_ostream& __rhs) = delete; + basic_ostream& operator=(const basic_ostream& __rhs) = delete; +#else + basic_ostream (const basic_ostream& __rhs); // not defined + basic_ostream& operator=(const basic_ostream& __rhs); // not defined +#endif +public: + + // 27.7.2.4 Prefix/suffix: + class _LIBCPP_TEMPLATE_VIS sentry; + + // 27.7.2.6 Formatted output: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)) + { return __pf(*this); } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_ostream& operator<<(basic_ios<char_type, traits_type>& + (*__pf)(basic_ios<char_type,traits_type>&)) + { __pf(*this); return *this; } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)) + { __pf(*this); return *this; } + + basic_ostream& operator<<(bool __n); + basic_ostream& operator<<(short __n); + basic_ostream& operator<<(unsigned short __n); + basic_ostream& operator<<(int __n); + basic_ostream& operator<<(unsigned int __n); + basic_ostream& operator<<(long __n); + basic_ostream& operator<<(unsigned long __n); + basic_ostream& operator<<(long long __n); + basic_ostream& operator<<(unsigned long long __n); + basic_ostream& operator<<(float __f); + basic_ostream& operator<<(double __f); + basic_ostream& operator<<(long double __f); + basic_ostream& operator<<(const void* __p); + basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb); + + // 27.7.2.7 Unformatted output: + basic_ostream& put(char_type __c); + basic_ostream& write(const char_type* __s, streamsize __n); + basic_ostream& flush(); + + // 27.7.2.5 seeks: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + pos_type tellp(); + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_ostream& seekp(pos_type __pos); + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_ostream& seekp(off_type __off, ios_base::seekdir __dir); + +protected: + _LIBCPP_INLINE_VISIBILITY + basic_ostream() {} // extension, intentially does not initialize +}; + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry +{ + bool __ok_; + basic_ostream<_CharT, _Traits>& __os_; + + sentry(const sentry&); // = delete; + sentry& operator=(const sentry&); // = delete; + +public: + explicit sentry(basic_ostream<_CharT, _Traits>& __os); + ~sentry(); + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT + operator bool() const {return __ok_;} +}; + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os) + : __ok_(false), + __os_(__os) +{ + if (__os.good()) + { + if (__os.tie()) + __os.tie()->flush(); + __ok_ = true; + } +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>::sentry::~sentry() +{ + if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) + && !uncaught_exception()) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + if (__os_.rdbuf()->pubsync() == -1) + __os_.setstate(ios_base::badbit); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) +{ + this->move(__rhs); +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) +{ + swap(__rhs); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>::~basic_ostream() +{ +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + if (__sb) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef istreambuf_iterator<_CharT, _Traits> _Ip; + typedef ostreambuf_iterator<_CharT, _Traits> _Op; + _Ip __i(__sb); + _Ip __eof; + _Op __o(*this); + size_t __c = 0; + for (; __i != __eof; ++__i, ++__o, ++__c) + { + *__o = *__i; + if (__o.failed()) + break; + } + if (__c == 0) + this->setstate(ios_base::failbit); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_failbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + else + this->setstate(ios_base::badbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(bool __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), __n).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(short __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield; + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), + __flags == ios_base::oct || __flags == ios_base::hex ? + static_cast<long>(static_cast<unsigned short>(__n)) : + static_cast<long>(__n)).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(int __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield; + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), + __flags == ios_base::oct || __flags == ios_base::hex ? + static_cast<long>(static_cast<unsigned int>(__n)) : + static_cast<long>(__n)).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(long __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), __n).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), __n).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(long long __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), __n).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), __n).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(float __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(double __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), __n).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(long double __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), __n).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(const void* __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; + const _Fp& __f = use_facet<_Fp>(this->getloc()); + if (__f.put(*this, *this, this->fill(), __n).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template<class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +__put_character_sequence(basic_ostream<_CharT, _Traits>& __os, + const _CharT* __str, size_t __len) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_ostream<_CharT, _Traits>::sentry __s(__os); + if (__s) + { + typedef ostreambuf_iterator<_CharT, _Traits> _Ip; + if (__pad_and_output(_Ip(__os), + __str, + (__os.flags() & ios_base::adjustfield) == ios_base::left ? + __str + __len : + __str, + __str + __len, + __os, + __os.fill()).failed()) + __os.setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __os.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __os; +} + + +template<class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) +{ + return _VSTD::__put_character_sequence(__os, &__c, 1); +} + +template<class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_ostream<_CharT, _Traits>::sentry __s(__os); + if (__s) + { + _CharT __c = __os.widen(__cn); + typedef ostreambuf_iterator<_CharT, _Traits> _Ip; + if (__pad_and_output(_Ip(__os), + &__c, + (__os.flags() & ios_base::adjustfield) == ios_base::left ? + &__c + 1 : + &__c, + &__c + 1, + __os, + __os.fill()).failed()) + __os.setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __os.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __os; +} + +template<class _Traits> +basic_ostream<char, _Traits>& +operator<<(basic_ostream<char, _Traits>& __os, char __c) +{ + return _VSTD::__put_character_sequence(__os, &__c, 1); +} + +template<class _Traits> +basic_ostream<char, _Traits>& +operator<<(basic_ostream<char, _Traits>& __os, signed char __c) +{ + return _VSTD::__put_character_sequence(__os, (char *) &__c, 1); +} + +template<class _Traits> +basic_ostream<char, _Traits>& +operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) +{ + return _VSTD::__put_character_sequence(__os, (char *) &__c, 1); +} + +template<class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) +{ + return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str)); +} + +template<class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_ostream<_CharT, _Traits>::sentry __s(__os); + if (__s) + { + typedef ostreambuf_iterator<_CharT, _Traits> _Ip; + size_t __len = char_traits<char>::length(__strn); + const int __bs = 100; + _CharT __wbb[__bs]; + _CharT* __wb = __wbb; + unique_ptr<_CharT, void(*)(void*)> __h(0, free); + if (__len > __bs) + { + __wb = (_CharT*)malloc(__len*sizeof(_CharT)); + if (__wb == 0) + __throw_bad_alloc(); + __h.reset(__wb); + } + for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p) + *__p = __os.widen(*__strn); + if (__pad_and_output(_Ip(__os), + __wb, + (__os.flags() & ios_base::adjustfield) == ios_base::left ? + __wb + __len : + __wb, + __wb + __len, + __os, + __os.fill()).failed()) + __os.setstate(ios_base::badbit | ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __os.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __os; +} + +template<class _Traits> +basic_ostream<char, _Traits>& +operator<<(basic_ostream<char, _Traits>& __os, const char* __str) +{ + return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str)); +} + +template<class _Traits> +basic_ostream<char, _Traits>& +operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str) +{ + const char *__s = (const char *) __str; + return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s)); +} + +template<class _Traits> +basic_ostream<char, _Traits>& +operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str) +{ + const char *__s = (const char *) __str; + return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s)); +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::put(char_type __c) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef ostreambuf_iterator<_CharT, _Traits> _Op; + _Op __o(*this); + *__o = __c; + if (__o.failed()) + this->setstate(ios_base::badbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this); + if (__sen && __n) + { + if (this->rdbuf()->sputn(__s, __n) != __n) + this->setstate(ios_base::badbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::flush() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + if (this->rdbuf()) + { + sentry __s(*this); + if (__s) + { + if (this->rdbuf()->pubsync() == -1) + this->setstate(ios_base::badbit); + } + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template <class _CharT, class _Traits> +typename basic_ostream<_CharT, _Traits>::pos_type +basic_ostream<_CharT, _Traits>::tellp() +{ + if (this->fail()) + return pos_type(-1); + return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) +{ + sentry __s(*this); + if (!this->fail()) + { + if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1)) + this->setstate(ios_base::failbit); + } + return *this; +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) +{ + sentry __s(*this); + if (!this->fail()) + { + if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1)) + this->setstate(ios_base::failbit); + } + return *this; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +endl(basic_ostream<_CharT, _Traits>& __os) +{ + __os.put(__os.widen('\n')); + __os.flush(); + return __os; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +ends(basic_ostream<_CharT, _Traits>& __os) +{ + __os.put(_CharT()); + return __os; +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +flush(basic_ostream<_CharT, _Traits>& __os) +{ + __os.flush(); + return __os; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Stream, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_lvalue_reference<_Stream>::value && + is_base_of<ios_base, _Stream>::value, + _Stream&& +>::type +operator<<(_Stream&& __os, const _Tp& __x) +{ + __os << __x; + return _VSTD::move(__os); +} + +#endif // _LIBCPP_CXX03_LANG + +template<class _CharT, class _Traits, class _Allocator> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const basic_string<_CharT, _Traits, _Allocator>& __str) +{ + return _VSTD::__put_character_sequence(__os, __str.data(), __str.size()); +} + +template<class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const basic_string_view<_CharT, _Traits> __sv) +{ + return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size()); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) +{ + return __os << __ec.category().name() << ':' << __ec.value(); +} + +template<class _CharT, class _Traits, class _Yp> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) +{ + return __os << __p.get(); +} + +template<class _CharT, class _Traits, class _Yp, class _Dp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same<void, typename __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))>::type>::value, + basic_ostream<_CharT, _Traits>& +>::type +operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) +{ + return __os << __p.get(); +} + +template <class _CharT, class _Traits, size_t _Size> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) +{ + return __os << __x.template to_string<_CharT, _Traits> + (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'), + use_facet<ctype<_CharT> >(__os.getloc()).widen('1')); +} + +#ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>) +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_OSTREAM diff --git a/android/x86/include/v8/libc++/queue b/android/x86/include/v8/libc++/queue new file mode 100755 index 00000000..55be8001 --- /dev/null +++ b/android/x86/include/v8/libc++/queue @@ -0,0 +1,803 @@ +// -*- C++ -*- +//===--------------------------- queue ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_QUEUE +#define _LIBCPP_QUEUE + +/* + queue synopsis + +namespace std +{ + +template <class T, class Container = deque<T>> +class queue +{ +public: + typedef Container container_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::size_type size_type; + +protected: + container_type c; + +public: + queue() = default; + ~queue() = default; + + queue(const queue& q) = default; + queue(queue&& q) = default; + + queue& operator=(const queue& q) = default; + queue& operator=(queue&& q) = default; + + explicit queue(const container_type& c); + explicit queue(container_type&& c) + template <class Alloc> + explicit queue(const Alloc& a); + template <class Alloc> + queue(const container_type& c, const Alloc& a); + template <class Alloc> + queue(container_type&& c, const Alloc& a); + template <class Alloc> + queue(const queue& q, const Alloc& a); + template <class Alloc> + queue(queue&& q, const Alloc& a); + + bool empty() const; + size_type size() const; + + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + void push(const value_type& v); + void push(value_type&& v); + template <class... Args> reference emplace(Args&&... args); // reference in C++17 + void pop(); + + void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>) +}; + +template<class Container> + queue(Container) -> queue<typename Container::value_type, Container>; // C++17 + +template<class Container, class Allocator> + queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17 + +template <class T, class Container> + bool operator==(const queue<T, Container>& x,const queue<T, Container>& y); + +template <class T, class Container> + bool operator< (const queue<T, Container>& x,const queue<T, Container>& y); + +template <class T, class Container> + bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y); + +template <class T, class Container> + bool operator> (const queue<T, Container>& x,const queue<T, Container>& y); + +template <class T, class Container> + bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y); + +template <class T, class Container> + bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y); + +template <class T, class Container> + void swap(queue<T, Container>& x, queue<T, Container>& y) + noexcept(noexcept(x.swap(y))); + +template <class T, class Container = vector<T>, + class Compare = less<typename Container::value_type>> +class priority_queue +{ +public: + typedef Container container_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::size_type size_type; + +protected: + container_type c; + Compare comp; + +public: + priority_queue() = default; + ~priority_queue() = default; + + priority_queue(const priority_queue& q) = default; + priority_queue(priority_queue&& q) = default; + + priority_queue& operator=(const priority_queue& q) = default; + priority_queue& operator=(priority_queue&& q) = default; + + explicit priority_queue(const Compare& comp); + priority_queue(const Compare& comp, const container_type& c); + explicit priority_queue(const Compare& comp, container_type&& c); + template <class InputIterator> + priority_queue(InputIterator first, InputIterator last, + const Compare& comp = Compare()); + template <class InputIterator> + priority_queue(InputIterator first, InputIterator last, + const Compare& comp, const container_type& c); + template <class InputIterator> + priority_queue(InputIterator first, InputIterator last, + const Compare& comp, container_type&& c); + template <class Alloc> + explicit priority_queue(const Alloc& a); + template <class Alloc> + priority_queue(const Compare& comp, const Alloc& a); + template <class Alloc> + priority_queue(const Compare& comp, const container_type& c, + const Alloc& a); + template <class Alloc> + priority_queue(const Compare& comp, container_type&& c, + const Alloc& a); + template <class Alloc> + priority_queue(const priority_queue& q, const Alloc& a); + template <class Alloc> + priority_queue(priority_queue&& q, const Alloc& a); + + bool empty() const; + size_type size() const; + const_reference top() const; + + void push(const value_type& v); + void push(value_type&& v); + template <class... Args> void emplace(Args&&... args); + void pop(); + + void swap(priority_queue& q) + noexcept(is_nothrow_swappable_v<Container> && + is_nothrow_swappable_v<Comp>) +}; + +template <class Compare, class Container> +priority_queue(Compare, Container) + -> priority_queue<typename Container::value_type, Container, Compare>; // C++17 + +template<class InputIterator, + class Compare = less<typename iterator_traits<InputIterator>::value_type>, + class Container = vector<typename iterator_traits<InputIterator>::value_type>> +priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container()) + -> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>; // C++17 + +template<class Compare, class Container, class Allocator> +priority_queue(Compare, Container, Allocator) + -> priority_queue<typename Container::value_type, Container, Compare>; // C++17 + +template <class T, class Container, class Compare> + void swap(priority_queue<T, Container, Compare>& x, + priority_queue<T, Container, Compare>& y) + noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#include <__config> +#include <deque> +#include <vector> +#include <functional> +#include <algorithm> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue; + +template <class _Tp, class _Container> +_LIBCPP_INLINE_VISIBILITY +bool +operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y); + +template <class _Tp, class _Container> +_LIBCPP_INLINE_VISIBILITY +bool +operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y); + +template <class _Tp, class _Container /*= deque<_Tp>*/> +class _LIBCPP_TEMPLATE_VIS queue +{ +public: + typedef _Container container_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::size_type size_type; + static_assert((is_same<_Tp, value_type>::value), "" ); + +protected: + container_type c; + +public: + _LIBCPP_INLINE_VISIBILITY + queue() + _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) + : c() {} + + _LIBCPP_INLINE_VISIBILITY + queue(const queue& __q) : c(__q.c) {} + + _LIBCPP_INLINE_VISIBILITY + queue& operator=(const queue& __q) {c = __q.c; return *this;} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + queue(queue&& __q) + _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value) + : c(_VSTD::move(__q.c)) {} + + _LIBCPP_INLINE_VISIBILITY + queue& operator=(queue&& __q) + _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) + {c = _VSTD::move(__q.c); return *this;} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + explicit queue(const container_type& __c) : c(__c) {} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {} +#endif // _LIBCPP_CXX03_LANG + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + explicit queue(const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(__a) {} + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + queue(const queue& __q, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(__q.c, __a) {} + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + queue(const container_type& __c, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(__c, __a) {} +#ifndef _LIBCPP_CXX03_LANG + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + queue(container_type&& __c, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(_VSTD::move(__c), __a) {} + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + queue(queue&& __q, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(_VSTD::move(__q.c), __a) {} + +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const {return c.empty();} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return c.size();} + + _LIBCPP_INLINE_VISIBILITY + reference front() {return c.front();} + _LIBCPP_INLINE_VISIBILITY + const_reference front() const {return c.front();} + _LIBCPP_INLINE_VISIBILITY + reference back() {return c.back();} + _LIBCPP_INLINE_VISIBILITY + const_reference back() const {return c.back();} + + _LIBCPP_INLINE_VISIBILITY + void push(const value_type& __v) {c.push_back(__v);} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void push(value_type&& __v) {c.push_back(_VSTD::move(__v));} + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_STD_VER > 14 + decltype(auto) emplace(_Args&&... __args) + { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} +#else + void emplace(_Args&&... __args) + { c.emplace_back(_VSTD::forward<_Args>(__args)...);} +#endif +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void pop() {c.pop_front();} + + _LIBCPP_INLINE_VISIBILITY + void swap(queue& __q) + _NOEXCEPT_(__is_nothrow_swappable<container_type>::value) + { + using _VSTD::swap; + swap(c, __q.c); + } + + template <class _T1, class _C1> + friend + _LIBCPP_INLINE_VISIBILITY + bool + operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y); + + template <class _T1, class _C1> + friend + _LIBCPP_INLINE_VISIBILITY + bool + operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y); +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _Container, + class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type +> +queue(_Container) + -> queue<typename _Container::value_type, _Container>; + +template<class _Container, + class _Alloc, + class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type, + class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type +> +queue(_Container, _Alloc) + -> queue<typename _Container::value_type, _Container>; +#endif + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) +{ + return __x.c == __y.c; +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) +{ + return __x.c < __y.c; +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) +{ + return !(__x < __y); +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + __is_swappable<_Container>::value, + void +>::type +swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Tp, class _Container, class _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc> + : public uses_allocator<_Container, _Alloc> +{ +}; + +template <class _Tp, class _Container = vector<_Tp>, + class _Compare = less<typename _Container::value_type> > +class _LIBCPP_TEMPLATE_VIS priority_queue +{ +public: + typedef _Container container_type; + typedef _Compare value_compare; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::size_type size_type; + static_assert((is_same<_Tp, value_type>::value), "" ); + +protected: + container_type c; + value_compare comp; + +public: + _LIBCPP_INLINE_VISIBILITY + priority_queue() + _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value && + is_nothrow_default_constructible<value_compare>::value) + : c(), comp() {} + + _LIBCPP_INLINE_VISIBILITY + priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {} + + _LIBCPP_INLINE_VISIBILITY + priority_queue& operator=(const priority_queue& __q) + {c = __q.c; comp = __q.comp; return *this;} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + priority_queue(priority_queue&& __q) + _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value && + is_nothrow_move_constructible<value_compare>::value) + : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {} + + _LIBCPP_INLINE_VISIBILITY + priority_queue& operator=(priority_queue&& __q) + _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value && + is_nothrow_move_assignable<value_compare>::value) + {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + explicit priority_queue(const value_compare& __comp) + : c(), comp(__comp) {} + _LIBCPP_INLINE_VISIBILITY + priority_queue(const value_compare& __comp, const container_type& __c); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit priority_queue(const value_compare& __comp, container_type&& __c); +#endif + template <class _InputIter> + _LIBCPP_INLINE_VISIBILITY + priority_queue(_InputIter __f, _InputIter __l, + const value_compare& __comp = value_compare()); + template <class _InputIter> + _LIBCPP_INLINE_VISIBILITY + priority_queue(_InputIter __f, _InputIter __l, + const value_compare& __comp, const container_type& __c); +#ifndef _LIBCPP_CXX03_LANG + template <class _InputIter> + _LIBCPP_INLINE_VISIBILITY + priority_queue(_InputIter __f, _InputIter __l, + const value_compare& __comp, container_type&& __c); +#endif // _LIBCPP_CXX03_LANG + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + explicit priority_queue(const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0); + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + priority_queue(const value_compare& __comp, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0); + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + priority_queue(const value_compare& __comp, const container_type& __c, + const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0); + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + priority_queue(const priority_queue& __q, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0); +#ifndef _LIBCPP_CXX03_LANG + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + priority_queue(const value_compare& __comp, container_type&& __c, + const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0); + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + priority_queue(priority_queue&& __q, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0); +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const {return c.empty();} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return c.size();} + _LIBCPP_INLINE_VISIBILITY + const_reference top() const {return c.front();} + + _LIBCPP_INLINE_VISIBILITY + void push(const value_type& __v); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void push(value_type&& __v); + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + void emplace(_Args&&... __args); +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void pop(); + + _LIBCPP_INLINE_VISIBILITY + void swap(priority_queue& __q) + _NOEXCEPT_(__is_nothrow_swappable<container_type>::value && + __is_nothrow_swappable<value_compare>::value); +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template <class _Compare, + class _Container, + class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type, + class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type +> +priority_queue(_Compare, _Container) + -> priority_queue<typename _Container::value_type, _Container, _Compare>; + +template<class _InputIterator, + class _Compare = less<typename iterator_traits<_InputIterator>::value_type>, + class _Container = vector<typename iterator_traits<_InputIterator>::value_type>, + class = typename enable_if< __is_input_iterator<_InputIterator>::value, nullptr_t>::type, + class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type, + class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type +> +priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container()) + -> priority_queue<typename iterator_traits<_InputIterator>::value_type, _Container, _Compare>; + +template<class _Compare, + class _Container, + class _Alloc, + class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type, + class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type, + class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type +> +priority_queue(_Compare, _Container, _Alloc) + -> priority_queue<typename _Container::value_type, _Container, _Compare>; +#endif + +template <class _Tp, class _Container, class _Compare> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp, + const container_type& __c) + : c(__c), + comp(__comp) +{ + _VSTD::make_heap(c.begin(), c.end(), comp); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Container, class _Compare> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, + container_type&& __c) + : c(_VSTD::move(__c)), + comp(__comp) +{ + _VSTD::make_heap(c.begin(), c.end(), comp); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Container, class _Compare> +template <class _InputIter> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, + const value_compare& __comp) + : c(__f, __l), + comp(__comp) +{ + _VSTD::make_heap(c.begin(), c.end(), comp); +} + +template <class _Tp, class _Container, class _Compare> +template <class _InputIter> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, + const value_compare& __comp, + const container_type& __c) + : c(__c), + comp(__comp) +{ + c.insert(c.end(), __f, __l); + _VSTD::make_heap(c.begin(), c.end(), comp); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Container, class _Compare> +template <class _InputIter> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, + const value_compare& __comp, + container_type&& __c) + : c(_VSTD::move(__c)), + comp(__comp) +{ + c.insert(c.end(), __f, __l); + _VSTD::make_heap(c.begin(), c.end(), comp); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Container, class _Compare> +template <class _Alloc> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type*) + : c(__a) +{ +} + +template <class _Tp, class _Container, class _Compare> +template <class _Alloc> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, + const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type*) + : c(__a), + comp(__comp) +{ +} + +template <class _Tp, class _Container, class _Compare> +template <class _Alloc> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, + const container_type& __c, + const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type*) + : c(__c, __a), + comp(__comp) +{ + _VSTD::make_heap(c.begin(), c.end(), comp); +} + +template <class _Tp, class _Container, class _Compare> +template <class _Alloc> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q, + const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type*) + : c(__q.c, __a), + comp(__q.comp) +{ + _VSTD::make_heap(c.begin(), c.end(), comp); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Container, class _Compare> +template <class _Alloc> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, + container_type&& __c, + const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type*) + : c(_VSTD::move(__c), __a), + comp(__comp) +{ + _VSTD::make_heap(c.begin(), c.end(), comp); +} + +template <class _Tp, class _Container, class _Compare> +template <class _Alloc> +inline +priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q, + const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type*) + : c(_VSTD::move(__q.c), __a), + comp(_VSTD::move(__q.comp)) +{ + _VSTD::make_heap(c.begin(), c.end(), comp); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Container, class _Compare> +inline +void +priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) +{ + c.push_back(__v); + _VSTD::push_heap(c.begin(), c.end(), comp); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Container, class _Compare> +inline +void +priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) +{ + c.push_back(_VSTD::move(__v)); + _VSTD::push_heap(c.begin(), c.end(), comp); +} + +template <class _Tp, class _Container, class _Compare> +template <class... _Args> +inline +void +priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args) +{ + c.emplace_back(_VSTD::forward<_Args>(__args)...); + _VSTD::push_heap(c.begin(), c.end(), comp); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Container, class _Compare> +inline +void +priority_queue<_Tp, _Container, _Compare>::pop() +{ + _VSTD::pop_heap(c.begin(), c.end(), comp); + c.pop_back(); +} + +template <class _Tp, class _Container, class _Compare> +inline +void +priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q) + _NOEXCEPT_(__is_nothrow_swappable<container_type>::value && + __is_nothrow_swappable<value_compare>::value) +{ + using _VSTD::swap; + swap(c, __q.c); + swap(comp, __q.comp); +} + +template <class _Tp, class _Container, class _Compare> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + __is_swappable<_Container>::value + && __is_swappable<_Compare>::value, + void +>::type +swap(priority_queue<_Tp, _Container, _Compare>& __x, + priority_queue<_Tp, _Container, _Compare>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Tp, class _Container, class _Compare, class _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc> + : public uses_allocator<_Container, _Alloc> +{ +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_QUEUE diff --git a/android/x86/include/v8/libc++/random b/android/x86/include/v8/libc++/random new file mode 100755 index 00000000..a7323951 --- /dev/null +++ b/android/x86/include/v8/libc++/random @@ -0,0 +1,6743 @@ +// -*- C++ -*- +//===--------------------------- random -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_RANDOM +#define _LIBCPP_RANDOM + +/* + random synopsis + +#include <initializer_list> + +namespace std +{ + +// Engines + +template <class UIntType, UIntType a, UIntType c, UIntType m> +class linear_congruential_engine +{ +public: + // types + typedef UIntType result_type; + + // engine characteristics + static constexpr result_type multiplier = a; + static constexpr result_type increment = c; + static constexpr result_type modulus = m; + static constexpr result_type min() { return c == 0u ? 1u: 0u;} + static constexpr result_type max() { return m - 1u;} + static constexpr result_type default_seed = 1u; + + // constructors and seeding functions + explicit linear_congruential_engine(result_type s = default_seed); + template<class Sseq> explicit linear_congruential_engine(Sseq& q); + void seed(result_type s = default_seed); + template<class Sseq> void seed(Sseq& q); + + // generating functions + result_type operator()(); + void discard(unsigned long long z); +}; + +template <class UIntType, UIntType a, UIntType c, UIntType m> +bool +operator==(const linear_congruential_engine<UIntType, a, c, m>& x, + const linear_congruential_engine<UIntType, a, c, m>& y); + +template <class UIntType, UIntType a, UIntType c, UIntType m> +bool +operator!=(const linear_congruential_engine<UIntType, a, c, m>& x, + const linear_congruential_engine<UIntType, a, c, m>& y); + +template <class charT, class traits, + class UIntType, UIntType a, UIntType c, UIntType m> +basic_ostream<charT, traits>& +operator<<(basic_ostream<charT, traits>& os, + const linear_congruential_engine<UIntType, a, c, m>& x); + +template <class charT, class traits, + class UIntType, UIntType a, UIntType c, UIntType m> +basic_istream<charT, traits>& +operator>>(basic_istream<charT, traits>& is, + linear_congruential_engine<UIntType, a, c, m>& x); + +template <class UIntType, size_t w, size_t n, size_t m, size_t r, + UIntType a, size_t u, UIntType d, size_t s, + UIntType b, size_t t, UIntType c, size_t l, UIntType f> +class mersenne_twister_engine +{ +public: + // types + typedef UIntType result_type; + + // engine characteristics + static constexpr size_t word_size = w; + static constexpr size_t state_size = n; + static constexpr size_t shift_size = m; + static constexpr size_t mask_bits = r; + static constexpr result_type xor_mask = a; + static constexpr size_t tempering_u = u; + static constexpr result_type tempering_d = d; + static constexpr size_t tempering_s = s; + static constexpr result_type tempering_b = b; + static constexpr size_t tempering_t = t; + static constexpr result_type tempering_c = c; + static constexpr size_t tempering_l = l; + static constexpr result_type initialization_multiplier = f; + static constexpr result_type min () { return 0; } + static constexpr result_type max() { return 2^w - 1; } + static constexpr result_type default_seed = 5489u; + + // constructors and seeding functions + explicit mersenne_twister_engine(result_type value = default_seed); + template<class Sseq> explicit mersenne_twister_engine(Sseq& q); + void seed(result_type value = default_seed); + template<class Sseq> void seed(Sseq& q); + + // generating functions + result_type operator()(); + void discard(unsigned long long z); +}; + +template <class UIntType, size_t w, size_t n, size_t m, size_t r, + UIntType a, size_t u, UIntType d, size_t s, + UIntType b, size_t t, UIntType c, size_t l, UIntType f> +bool +operator==( + const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, + const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); + +template <class UIntType, size_t w, size_t n, size_t m, size_t r, + UIntType a, size_t u, UIntType d, size_t s, + UIntType b, size_t t, UIntType c, size_t l, UIntType f> +bool +operator!=( + const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, + const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); + +template <class charT, class traits, + class UIntType, size_t w, size_t n, size_t m, size_t r, + UIntType a, size_t u, UIntType d, size_t s, + UIntType b, size_t t, UIntType c, size_t l, UIntType f> +basic_ostream<charT, traits>& +operator<<(basic_ostream<charT, traits>& os, + const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); + +template <class charT, class traits, + class UIntType, size_t w, size_t n, size_t m, size_t r, + UIntType a, size_t u, UIntType d, size_t s, + UIntType b, size_t t, UIntType c, size_t l, UIntType f> +basic_istream<charT, traits>& +operator>>(basic_istream<charT, traits>& is, + mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); + +template<class UIntType, size_t w, size_t s, size_t r> +class subtract_with_carry_engine +{ +public: + // types + typedef UIntType result_type; + + // engine characteristics + static constexpr size_t word_size = w; + static constexpr size_t short_lag = s; + static constexpr size_t long_lag = r; + static constexpr result_type min() { return 0; } + static constexpr result_type max() { return m-1; } + static constexpr result_type default_seed = 19780503u; + + // constructors and seeding functions + explicit subtract_with_carry_engine(result_type value = default_seed); + template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); + void seed(result_type value = default_seed); + template<class Sseq> void seed(Sseq& q); + + // generating functions + result_type operator()(); + void discard(unsigned long long z); +}; + +template<class UIntType, size_t w, size_t s, size_t r> +bool +operator==( + const subtract_with_carry_engine<UIntType, w, s, r>& x, + const subtract_with_carry_engine<UIntType, w, s, r>& y); + +template<class UIntType, size_t w, size_t s, size_t r> +bool +operator!=( + const subtract_with_carry_engine<UIntType, w, s, r>& x, + const subtract_with_carry_engine<UIntType, w, s, r>& y); + +template <class charT, class traits, + class UIntType, size_t w, size_t s, size_t r> +basic_ostream<charT, traits>& +operator<<(basic_ostream<charT, traits>& os, + const subtract_with_carry_engine<UIntType, w, s, r>& x); + +template <class charT, class traits, + class UIntType, size_t w, size_t s, size_t r> +basic_istream<charT, traits>& +operator>>(basic_istream<charT, traits>& is, + subtract_with_carry_engine<UIntType, w, s, r>& x); + +template<class Engine, size_t p, size_t r> +class discard_block_engine +{ +public: + // types + typedef typename Engine::result_type result_type; + + // engine characteristics + static constexpr size_t block_size = p; + static constexpr size_t used_block = r; + static constexpr result_type min() { return Engine::min(); } + static constexpr result_type max() { return Engine::max(); } + + // constructors and seeding functions + discard_block_engine(); + explicit discard_block_engine(const Engine& e); + explicit discard_block_engine(Engine&& e); + explicit discard_block_engine(result_type s); + template<class Sseq> explicit discard_block_engine(Sseq& q); + void seed(); + void seed(result_type s); + template<class Sseq> void seed(Sseq& q); + + // generating functions + result_type operator()(); + void discard(unsigned long long z); + + // property functions + const Engine& base() const noexcept; +}; + +template<class Engine, size_t p, size_t r> +bool +operator==( + const discard_block_engine<Engine, p, r>& x, + const discard_block_engine<Engine, p, r>& y); + +template<class Engine, size_t p, size_t r> +bool +operator!=( + const discard_block_engine<Engine, p, r>& x, + const discard_block_engine<Engine, p, r>& y); + +template <class charT, class traits, + class Engine, size_t p, size_t r> +basic_ostream<charT, traits>& +operator<<(basic_ostream<charT, traits>& os, + const discard_block_engine<Engine, p, r>& x); + +template <class charT, class traits, + class Engine, size_t p, size_t r> +basic_istream<charT, traits>& +operator>>(basic_istream<charT, traits>& is, + discard_block_engine<Engine, p, r>& x); + +template<class Engine, size_t w, class UIntType> +class independent_bits_engine +{ +public: + // types + typedef UIntType result_type; + + // engine characteristics + static constexpr result_type min() { return 0; } + static constexpr result_type max() { return 2^w - 1; } + + // constructors and seeding functions + independent_bits_engine(); + explicit independent_bits_engine(const Engine& e); + explicit independent_bits_engine(Engine&& e); + explicit independent_bits_engine(result_type s); + template<class Sseq> explicit independent_bits_engine(Sseq& q); + void seed(); + void seed(result_type s); + template<class Sseq> void seed(Sseq& q); + + // generating functions + result_type operator()(); void discard(unsigned long long z); + + // property functions + const Engine& base() const noexcept; +}; + +template<class Engine, size_t w, class UIntType> +bool +operator==( + const independent_bits_engine<Engine, w, UIntType>& x, + const independent_bits_engine<Engine, w, UIntType>& y); + +template<class Engine, size_t w, class UIntType> +bool +operator!=( + const independent_bits_engine<Engine, w, UIntType>& x, + const independent_bits_engine<Engine, w, UIntType>& y); + +template <class charT, class traits, + class Engine, size_t w, class UIntType> +basic_ostream<charT, traits>& +operator<<(basic_ostream<charT, traits>& os, + const independent_bits_engine<Engine, w, UIntType>& x); + +template <class charT, class traits, + class Engine, size_t w, class UIntType> +basic_istream<charT, traits>& +operator>>(basic_istream<charT, traits>& is, + independent_bits_engine<Engine, w, UIntType>& x); + +template<class Engine, size_t k> +class shuffle_order_engine +{ +public: + // types + typedef typename Engine::result_type result_type; + + // engine characteristics + static constexpr size_t table_size = k; + static constexpr result_type min() { return Engine::min; } + static constexpr result_type max() { return Engine::max; } + + // constructors and seeding functions + shuffle_order_engine(); + explicit shuffle_order_engine(const Engine& e); + explicit shuffle_order_engine(Engine&& e); + explicit shuffle_order_engine(result_type s); + template<class Sseq> explicit shuffle_order_engine(Sseq& q); + void seed(); + void seed(result_type s); + template<class Sseq> void seed(Sseq& q); + + // generating functions + result_type operator()(); + void discard(unsigned long long z); + + // property functions + const Engine& base() const noexcept; +}; + +template<class Engine, size_t k> +bool +operator==( + const shuffle_order_engine<Engine, k>& x, + const shuffle_order_engine<Engine, k>& y); + +template<class Engine, size_t k> +bool +operator!=( + const shuffle_order_engine<Engine, k>& x, + const shuffle_order_engine<Engine, k>& y); + +template <class charT, class traits, + class Engine, size_t k> +basic_ostream<charT, traits>& +operator<<(basic_ostream<charT, traits>& os, + const shuffle_order_engine<Engine, k>& x); + +template <class charT, class traits, + class Engine, size_t k> +basic_istream<charT, traits>& +operator>>(basic_istream<charT, traits>& is, + shuffle_order_engine<Engine, k>& x); + +typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> + minstd_rand0; +typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> + minstd_rand; +typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, + 0x9908b0df, + 11, 0xffffffff, + 7, 0x9d2c5680, + 15, 0xefc60000, + 18, 1812433253> mt19937; +typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, + 0xb5026f5aa96619e9, + 29, 0x5555555555555555, + 17, 0x71d67fffeda60000, + 37, 0xfff7eee000000000, + 43, 6364136223846793005> mt19937_64; +typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; +typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; +typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; +typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; +typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; +typedef minstd_rand default_random_engine; + +// Generators + +class random_device +{ +public: + // types + typedef unsigned int result_type; + + // generator characteristics + static constexpr result_type min() { return numeric_limits<result_type>::min(); } + static constexpr result_type max() { return numeric_limits<result_type>::max(); } + + // constructors + explicit random_device(const string& token = "/dev/urandom"); + + // generating functions + result_type operator()(); + + // property functions + double entropy() const noexcept; + + // no copy functions + random_device(const random_device& ) = delete; + void operator=(const random_device& ) = delete; +}; + +// Utilities + +class seed_seq +{ +public: + // types + typedef uint_least32_t result_type; + + // constructors + seed_seq(); + template<class T> + seed_seq(initializer_list<T> il); + template<class InputIterator> + seed_seq(InputIterator begin, InputIterator end); + + // generating functions + template<class RandomAccessIterator> + void generate(RandomAccessIterator begin, RandomAccessIterator end); + + // property functions + size_t size() const; + template<class OutputIterator> + void param(OutputIterator dest) const; + + // no copy functions + seed_seq(const seed_seq&) = delete; + void operator=(const seed_seq& ) = delete; +}; + +template<class RealType, size_t bits, class URNG> + RealType generate_canonical(URNG& g); + +// Distributions + +template<class IntType = int> +class uniform_int_distribution +{ +public: + // types + typedef IntType result_type; + + class param_type + { + public: + typedef uniform_int_distribution distribution_type; + + explicit param_type(IntType a = 0, + IntType b = numeric_limits<IntType>::max()); + + result_type a() const; + result_type b() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit uniform_int_distribution(IntType a = 0, + IntType b = numeric_limits<IntType>::max()); + explicit uniform_int_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type a() const; + result_type b() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const uniform_int_distribution& x, + const uniform_int_distribution& y); + friend bool operator!=(const uniform_int_distribution& x, + const uniform_int_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const uniform_int_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + uniform_int_distribution& x); +}; + +template<class RealType = double> +class uniform_real_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef uniform_real_distribution distribution_type; + + explicit param_type(RealType a = 0, + RealType b = 1); + + result_type a() const; + result_type b() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); + explicit uniform_real_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type a() const; + result_type b() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const uniform_real_distribution& x, + const uniform_real_distribution& y); + friend bool operator!=(const uniform_real_distribution& x, + const uniform_real_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const uniform_real_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + uniform_real_distribution& x); +}; + +class bernoulli_distribution +{ +public: + // types + typedef bool result_type; + + class param_type + { + public: + typedef bernoulli_distribution distribution_type; + + explicit param_type(double p = 0.5); + + double p() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit bernoulli_distribution(double p = 0.5); + explicit bernoulli_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + double p() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const bernoulli_distribution& x, + const bernoulli_distribution& y); + friend bool operator!=(const bernoulli_distribution& x, + const bernoulli_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const bernoulli_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + bernoulli_distribution& x); +}; + +template<class IntType = int> +class binomial_distribution +{ +public: + // types + typedef IntType result_type; + + class param_type + { + public: + typedef binomial_distribution distribution_type; + + explicit param_type(IntType t = 1, double p = 0.5); + + IntType t() const; + double p() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit binomial_distribution(IntType t = 1, double p = 0.5); + explicit binomial_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + IntType t() const; + double p() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const binomial_distribution& x, + const binomial_distribution& y); + friend bool operator!=(const binomial_distribution& x, + const binomial_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const binomial_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + binomial_distribution& x); +}; + +template<class IntType = int> +class geometric_distribution +{ +public: + // types + typedef IntType result_type; + + class param_type + { + public: + typedef geometric_distribution distribution_type; + + explicit param_type(double p = 0.5); + + double p() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit geometric_distribution(double p = 0.5); + explicit geometric_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + double p() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const geometric_distribution& x, + const geometric_distribution& y); + friend bool operator!=(const geometric_distribution& x, + const geometric_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const geometric_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + geometric_distribution& x); +}; + +template<class IntType = int> +class negative_binomial_distribution +{ +public: + // types + typedef IntType result_type; + + class param_type + { + public: + typedef negative_binomial_distribution distribution_type; + + explicit param_type(result_type k = 1, double p = 0.5); + + result_type k() const; + double p() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + explicit negative_binomial_distribution(result_type k = 1, double p = 0.5); + explicit negative_binomial_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type k() const; + double p() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const negative_binomial_distribution& x, + const negative_binomial_distribution& y); + friend bool operator!=(const negative_binomial_distribution& x, + const negative_binomial_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const negative_binomial_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + negative_binomial_distribution& x); +}; + +template<class IntType = int> +class poisson_distribution +{ +public: + // types + typedef IntType result_type; + + class param_type + { + public: + typedef poisson_distribution distribution_type; + + explicit param_type(double mean = 1.0); + + double mean() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit poisson_distribution(double mean = 1.0); + explicit poisson_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + double mean() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const poisson_distribution& x, + const poisson_distribution& y); + friend bool operator!=(const poisson_distribution& x, + const poisson_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const poisson_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + poisson_distribution& x); +}; + +template<class RealType = double> +class exponential_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef exponential_distribution distribution_type; + + explicit param_type(result_type lambda = 1.0); + + result_type lambda() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit exponential_distribution(result_type lambda = 1.0); + explicit exponential_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type lambda() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const exponential_distribution& x, + const exponential_distribution& y); + friend bool operator!=(const exponential_distribution& x, + const exponential_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const exponential_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + exponential_distribution& x); +}; + +template<class RealType = double> +class gamma_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef gamma_distribution distribution_type; + + explicit param_type(result_type alpha = 1, result_type beta = 1); + + result_type alpha() const; + result_type beta() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit gamma_distribution(result_type alpha = 1, result_type beta = 1); + explicit gamma_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type alpha() const; + result_type beta() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const gamma_distribution& x, + const gamma_distribution& y); + friend bool operator!=(const gamma_distribution& x, + const gamma_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const gamma_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + gamma_distribution& x); +}; + +template<class RealType = double> +class weibull_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef weibull_distribution distribution_type; + + explicit param_type(result_type alpha = 1, result_type beta = 1); + + result_type a() const; + result_type b() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + explicit weibull_distribution(result_type a = 1, result_type b = 1); + explicit weibull_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type a() const; + result_type b() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const weibull_distribution& x, + const weibull_distribution& y); + friend bool operator!=(const weibull_distribution& x, + const weibull_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const weibull_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + weibull_distribution& x); +}; + +template<class RealType = double> +class extreme_value_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef extreme_value_distribution distribution_type; + + explicit param_type(result_type a = 0, result_type b = 1); + + result_type a() const; + result_type b() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + explicit extreme_value_distribution(result_type a = 0, result_type b = 1); + explicit extreme_value_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type a() const; + result_type b() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const extreme_value_distribution& x, + const extreme_value_distribution& y); + friend bool operator!=(const extreme_value_distribution& x, + const extreme_value_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const extreme_value_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + extreme_value_distribution& x); +}; + +template<class RealType = double> +class normal_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef normal_distribution distribution_type; + + explicit param_type(result_type mean = 0, result_type stddev = 1); + + result_type mean() const; + result_type stddev() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit normal_distribution(result_type mean = 0, result_type stddev = 1); + explicit normal_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type mean() const; + result_type stddev() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const normal_distribution& x, + const normal_distribution& y); + friend bool operator!=(const normal_distribution& x, + const normal_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const normal_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + normal_distribution& x); +}; + +template<class RealType = double> +class lognormal_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef lognormal_distribution distribution_type; + + explicit param_type(result_type m = 0, result_type s = 1); + + result_type m() const; + result_type s() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + explicit lognormal_distribution(result_type m = 0, result_type s = 1); + explicit lognormal_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type m() const; + result_type s() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const lognormal_distribution& x, + const lognormal_distribution& y); + friend bool operator!=(const lognormal_distribution& x, + const lognormal_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const lognormal_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + lognormal_distribution& x); +}; + +template<class RealType = double> +class chi_squared_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef chi_squared_distribution distribution_type; + + explicit param_type(result_type n = 1); + + result_type n() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + explicit chi_squared_distribution(result_type n = 1); + explicit chi_squared_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type n() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const chi_squared_distribution& x, + const chi_squared_distribution& y); + friend bool operator!=(const chi_squared_distribution& x, + const chi_squared_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const chi_squared_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + chi_squared_distribution& x); +}; + +template<class RealType = double> +class cauchy_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef cauchy_distribution distribution_type; + + explicit param_type(result_type a = 0, result_type b = 1); + + result_type a() const; + result_type b() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + explicit cauchy_distribution(result_type a = 0, result_type b = 1); + explicit cauchy_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type a() const; + result_type b() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const cauchy_distribution& x, + const cauchy_distribution& y); + friend bool operator!=(const cauchy_distribution& x, + const cauchy_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const cauchy_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + cauchy_distribution& x); +}; + +template<class RealType = double> +class fisher_f_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef fisher_f_distribution distribution_type; + + explicit param_type(result_type m = 1, result_type n = 1); + + result_type m() const; + result_type n() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + explicit fisher_f_distribution(result_type m = 1, result_type n = 1); + explicit fisher_f_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type m() const; + result_type n() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const fisher_f_distribution& x, + const fisher_f_distribution& y); + friend bool operator!=(const fisher_f_distribution& x, + const fisher_f_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const fisher_f_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + fisher_f_distribution& x); +}; + +template<class RealType = double> +class student_t_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef student_t_distribution distribution_type; + + explicit param_type(result_type n = 1); + + result_type n() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + explicit student_t_distribution(result_type n = 1); + explicit student_t_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type n() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const student_t_distribution& x, + const student_t_distribution& y); + friend bool operator!=(const student_t_distribution& x, + const student_t_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const student_t_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + student_t_distribution& x); +}; + +template<class IntType = int> +class discrete_distribution +{ +public: + // types + typedef IntType result_type; + + class param_type + { + public: + typedef discrete_distribution distribution_type; + + param_type(); + template<class InputIterator> + param_type(InputIterator firstW, InputIterator lastW); + param_type(initializer_list<double> wl); + template<class UnaryOperation> + param_type(size_t nw, double xmin, double xmax, UnaryOperation fw); + + vector<double> probabilities() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + discrete_distribution(); + template<class InputIterator> + discrete_distribution(InputIterator firstW, InputIterator lastW); + discrete_distribution(initializer_list<double> wl); + template<class UnaryOperation> + discrete_distribution(size_t nw, double xmin, double xmax, + UnaryOperation fw); + explicit discrete_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + vector<double> probabilities() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const discrete_distribution& x, + const discrete_distribution& y); + friend bool operator!=(const discrete_distribution& x, + const discrete_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const discrete_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + discrete_distribution& x); +}; + +template<class RealType = double> +class piecewise_constant_distribution +{ + // types + typedef RealType result_type; + + class param_type + { + public: + typedef piecewise_constant_distribution distribution_type; + + param_type(); + template<class InputIteratorB, class InputIteratorW> + param_type(InputIteratorB firstB, InputIteratorB lastB, + InputIteratorW firstW); + template<class UnaryOperation> + param_type(initializer_list<result_type> bl, UnaryOperation fw); + template<class UnaryOperation> + param_type(size_t nw, result_type xmin, result_type xmax, + UnaryOperation fw); + + vector<result_type> intervals() const; + vector<result_type> densities() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + piecewise_constant_distribution(); + template<class InputIteratorB, class InputIteratorW> + piecewise_constant_distribution(InputIteratorB firstB, + InputIteratorB lastB, + InputIteratorW firstW); + template<class UnaryOperation> + piecewise_constant_distribution(initializer_list<result_type> bl, + UnaryOperation fw); + template<class UnaryOperation> + piecewise_constant_distribution(size_t nw, result_type xmin, + result_type xmax, UnaryOperation fw); + explicit piecewise_constant_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + vector<result_type> intervals() const; + vector<result_type> densities() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const piecewise_constant_distribution& x, + const piecewise_constant_distribution& y); + friend bool operator!=(const piecewise_constant_distribution& x, + const piecewise_constant_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const piecewise_constant_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + piecewise_constant_distribution& x); +}; + +template<class RealType = double> +class piecewise_linear_distribution +{ + // types + typedef RealType result_type; + + class param_type + { + public: + typedef piecewise_linear_distribution distribution_type; + + param_type(); + template<class InputIteratorB, class InputIteratorW> + param_type(InputIteratorB firstB, InputIteratorB lastB, + InputIteratorW firstW); + template<class UnaryOperation> + param_type(initializer_list<result_type> bl, UnaryOperation fw); + template<class UnaryOperation> + param_type(size_t nw, result_type xmin, result_type xmax, + UnaryOperation fw); + + vector<result_type> intervals() const; + vector<result_type> densities() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructor and reset functions + piecewise_linear_distribution(); + template<class InputIteratorB, class InputIteratorW> + piecewise_linear_distribution(InputIteratorB firstB, + InputIteratorB lastB, + InputIteratorW firstW); + + template<class UnaryOperation> + piecewise_linear_distribution(initializer_list<result_type> bl, + UnaryOperation fw); + + template<class UnaryOperation> + piecewise_linear_distribution(size_t nw, result_type xmin, + result_type xmax, UnaryOperation fw); + + explicit piecewise_linear_distribution(const param_type& parm); + void reset(); + + // generating functions + template<class URNG> result_type operator()(URNG& g); + template<class URNG> result_type operator()(URNG& g, const param_type& parm); + + // property functions + vector<result_type> intervals() const; + vector<result_type> densities() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const piecewise_linear_distribution& x, + const piecewise_linear_distribution& y); + friend bool operator!=(const piecewise_linear_distribution& x, + const piecewise_linear_distribution& y); + + template <class charT, class traits> + friend + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + const piecewise_linear_distribution& x); + + template <class charT, class traits> + friend + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, + piecewise_linear_distribution& x); +}; + +} // std +*/ + +#include <__config> +#include <cstddef> +#include <cstdint> +#include <cmath> +#include <type_traits> +#include <initializer_list> +#include <limits> +#include <algorithm> +#include <numeric> +#include <vector> +#include <string> +#include <istream> +#include <ostream> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +// __is_seed_sequence + +template <class _Sseq, class _Engine> +struct __is_seed_sequence +{ + static _LIBCPP_CONSTEXPR const bool value = + !is_convertible<_Sseq, typename _Engine::result_type>::value && + !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; +}; + +// linear_congruential_engine + +template <unsigned long long __a, unsigned long long __c, + unsigned long long __m, unsigned long long _Mp, + bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a)> +struct __lce_ta; + +// 64 + +template <unsigned long long __a, unsigned long long __c, unsigned long long __m> +struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> +{ + typedef unsigned long long result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + // Schrage's algorithm + const result_type __q = __m / __a; + const result_type __r = __m % __a; + const result_type __t0 = __a * (__x % __q); + const result_type __t1 = __r * (__x / __q); + __x = __t0 + (__t0 < __t1) * __m - __t1; + __x += __c - (__x >= __m - __c) * __m; + return __x; + } +}; + +template <unsigned long long __a, unsigned long long __m> +struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> +{ + typedef unsigned long long result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + // Schrage's algorithm + const result_type __q = __m / __a; + const result_type __r = __m % __a; + const result_type __t0 = __a * (__x % __q); + const result_type __t1 = __r * (__x / __q); + __x = __t0 + (__t0 < __t1) * __m - __t1; + return __x; + } +}; + +template <unsigned long long __a, unsigned long long __c, unsigned long long __m> +struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> +{ + typedef unsigned long long result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + return (__a * __x + __c) % __m; + } +}; + +template <unsigned long long __a, unsigned long long __c> +struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> +{ + typedef unsigned long long result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + return __a * __x + __c; + } +}; + +// 32 + +template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> +struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> +{ + typedef unsigned result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + const result_type __a = static_cast<result_type>(_Ap); + const result_type __c = static_cast<result_type>(_Cp); + const result_type __m = static_cast<result_type>(_Mp); + // Schrage's algorithm + const result_type __q = __m / __a; + const result_type __r = __m % __a; + const result_type __t0 = __a * (__x % __q); + const result_type __t1 = __r * (__x / __q); + __x = __t0 + (__t0 < __t1) * __m - __t1; + __x += __c - (__x >= __m - __c) * __m; + return __x; + } +}; + +template <unsigned long long _Ap, unsigned long long _Mp> +struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> +{ + typedef unsigned result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + const result_type __a = static_cast<result_type>(_Ap); + const result_type __m = static_cast<result_type>(_Mp); + // Schrage's algorithm + const result_type __q = __m / __a; + const result_type __r = __m % __a; + const result_type __t0 = __a * (__x % __q); + const result_type __t1 = __r * (__x / __q); + __x = __t0 + (__t0 < __t1) * __m - __t1; + return __x; + } +}; + +template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> +struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> +{ + typedef unsigned result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + const result_type __a = static_cast<result_type>(_Ap); + const result_type __c = static_cast<result_type>(_Cp); + const result_type __m = static_cast<result_type>(_Mp); + return (__a * __x + __c) % __m; + } +}; + +template <unsigned long long _Ap, unsigned long long _Cp> +struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> +{ + typedef unsigned result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + const result_type __a = static_cast<result_type>(_Ap); + const result_type __c = static_cast<result_type>(_Cp); + return __a * __x + __c; + } +}; + +// 16 + +template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> +struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> +{ + typedef unsigned short result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); + } +}; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +class _LIBCPP_TEMPLATE_VIS linear_congruential_engine; + +template <class _CharT, class _Traits, + class _Up, _Up _Ap, _Up _Cp, _Up _Np> +_LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); + +template <class _CharT, class _Traits, + class _Up, _Up _Ap, _Up _Cp, _Up _Np> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +class _LIBCPP_TEMPLATE_VIS linear_congruential_engine +{ +public: + // types + typedef _UIntType result_type; + +private: + result_type __x_; + + static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); + + static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); + static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); +public: + static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; + static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; + static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); + + // engine characteristics + static _LIBCPP_CONSTEXPR const result_type multiplier = __a; + static _LIBCPP_CONSTEXPR const result_type increment = __c; + static _LIBCPP_CONSTEXPR const result_type modulus = __m; + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() {return _Min;} + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() {return _Max;} + static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; + + // constructors and seeding functions + _LIBCPP_INLINE_VISIBILITY + explicit linear_congruential_engine(result_type __s = default_seed) + {seed(__s);} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit linear_congruential_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) + {seed(__q);} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __s = default_seed) + {seed(integral_constant<bool, __m == 0>(), + integral_constant<bool, __c == 0>(), __s);} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, linear_congruential_engine>::value, + void + >::type + seed(_Sseq& __q) + {__seed(__q, integral_constant<unsigned, + 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 + : (__m > 0x100000000ull))>());} + + // generating functions + _LIBCPP_INLINE_VISIBILITY + result_type operator()() + {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));} + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const linear_congruential_engine& __x, + const linear_congruential_engine& __y) + {return __x.__x_ == __y.__x_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const linear_congruential_engine& __x, + const linear_congruential_engine& __y) + {return !(__x == __y);} + +private: + + _LIBCPP_INLINE_VISIBILITY + void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} + _LIBCPP_INLINE_VISIBILITY + void seed(true_type, false_type, result_type __s) {__x_ = __s;} + _LIBCPP_INLINE_VISIBILITY + void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? + 1 : __s % __m;} + _LIBCPP_INLINE_VISIBILITY + void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} + + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 1>); + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 2>); + + template <class _CharT, class _Traits, + class _Up, _Up _Ap, _Up _Cp, _Up _Np> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); + + template <class _CharT, class _Traits, + class _Up, _Up _Ap, _Up _Cp, _Up _Np> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); +}; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type + linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type + linear_congruential_engine<_UIntType, __a, __c, __m>::increment; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type + linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type + linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +template<class _Sseq> +void +linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, + integral_constant<unsigned, 1>) +{ + const unsigned __k = 1; + uint32_t __ar[__k+3]; + __q.generate(__ar, __ar + __k + 3); + result_type __s = static_cast<result_type>(__ar[3] % __m); + __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; +} + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +template<class _Sseq> +void +linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, + integral_constant<unsigned, 2>) +{ + const unsigned __k = 2; + uint32_t __ar[__k+3]; + __q.generate(__ar, __ar + __k + 3); + result_type __s = static_cast<result_type>((__ar[3] + + ((uint64_t)__ar[4] << 32)) % __m); + __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; +} + +template <class _CharT, class _Traits, + class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left); + __os.fill(__os.widen(' ')); + return __os << __x.__x_; +} + +template <class _CharT, class _Traits, + class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + linear_congruential_engine<_UIntType, __a, __c, __m>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + _UIntType __t; + __is >> __t; + if (!__is.fail()) + __x.__x_ = __t; + return __is; +} + +typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> + minstd_rand0; +typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> + minstd_rand; +typedef minstd_rand default_random_engine; +// mersenne_twister_engine + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; + +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +bool +operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y); + +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +_LIBCPP_INLINE_VISIBILITY +bool +operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y); + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x); + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x); + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine +{ +public: + // types + typedef _UIntType result_type; + +private: + result_type __x_[__n]; + size_t __i_; + + static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); + static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); + static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; + static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); + static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); +public: + static _LIBCPP_CONSTEXPR const result_type _Min = 0; + static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : + (result_type(1) << __w) - result_type(1); + static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); + + // engine characteristics + static _LIBCPP_CONSTEXPR const size_t word_size = __w; + static _LIBCPP_CONSTEXPR const size_t state_size = __n; + static _LIBCPP_CONSTEXPR const size_t shift_size = __m; + static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; + static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; + static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; + static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; + static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; + static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; + static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; + static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; + static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; + static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; + + // constructors and seeding functions + _LIBCPP_INLINE_VISIBILITY + explicit mersenne_twister_engine(result_type __sd = default_seed) + {seed(__sd);} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit mersenne_twister_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) + {seed(__q);} + void seed(result_type __sd = default_seed); + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, + void + >::type + seed(_Sseq& __q) + {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} + + // generating functions + result_type operator()(); + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> + friend + bool + operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y); + + template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> + friend + bool + operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y); + + template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x); + + template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x); +private: + + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 1>); + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 2>); + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + __count < __w, + result_type + >::type + __lshift(result_type __x) {return (__x << __count) & _Max;} + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + (__count >= __w), + result_type + >::type + __lshift(result_type) {return result_type(0);} + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + __count < _Dt, + result_type + >::type + __rshift(result_type __x) {return __x >> __count;} + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + (__count >= _Dt), + result_type + >::type + __rshift(result_type) {return result_type(0);} +}; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +void +mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, + __t, __c, __l, __f>::seed(result_type __sd) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ // __w >= 2 + __x_[0] = __sd & _Max; + for (size_t __i = 1; __i < __n; ++__i) + __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; + __i_ = 0; +} + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +template<class _Sseq> +void +mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, + __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) +{ + const unsigned __k = 1; + uint32_t __ar[__n * __k]; + __q.generate(__ar, __ar + __n * __k); + for (size_t __i = 0; __i < __n; ++__i) + __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); + const result_type __mask = __r == _Dt ? result_type(~0) : + (result_type(1) << __r) - result_type(1); + __i_ = 0; + if ((__x_[0] & ~__mask) == 0) + { + for (size_t __i = 1; __i < __n; ++__i) + if (__x_[__i] != 0) + return; + __x_[0] = result_type(1) << (__w - 1); + } +} + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +template<class _Sseq> +void +mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, + __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) +{ + const unsigned __k = 2; + uint32_t __ar[__n * __k]; + __q.generate(__ar, __ar + __n * __k); + for (size_t __i = 0; __i < __n; ++__i) + __x_[__i] = static_cast<result_type>( + (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); + const result_type __mask = __r == _Dt ? result_type(~0) : + (result_type(1) << __r) - result_type(1); + __i_ = 0; + if ((__x_[0] & ~__mask) == 0) + { + for (size_t __i = 1; __i < __n; ++__i) + if (__x_[__i] != 0) + return; + __x_[0] = result_type(1) << (__w - 1); + } +} + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +_UIntType +mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, + __t, __c, __l, __f>::operator()() +{ + const size_t __j = (__i_ + 1) % __n; + const result_type __mask = __r == _Dt ? result_type(~0) : + (result_type(1) << __r) - result_type(1); + const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); + const size_t __k = (__i_ + __m) % __n; + __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); + result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); + __i_ = __j; + __z ^= __lshift<__s>(__z) & __b; + __z ^= __lshift<__t>(__z) & __c; + return __z ^ __rshift<__l>(__z); +} + +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +bool +operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y) +{ + if (__x.__i_ == __y.__i_) + return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); + if (__x.__i_ == 0 || __y.__i_ == 0) + { + size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); + if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, + __y.__x_ + __y.__i_)) + return false; + if (__x.__i_ == 0) + return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); + return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); + } + if (__x.__i_ < __y.__i_) + { + size_t __j = _Np - __y.__i_; + if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), + __y.__x_ + __y.__i_)) + return false; + if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, + __y.__x_)) + return false; + return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, + __y.__x_ + (_Np - (__x.__i_ + __j))); + } + size_t __j = _Np - __x.__i_; + if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), + __x.__x_ + __x.__i_)) + return false; + if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, + __x.__x_)) + return false; + return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, + __x.__x_ + (_Np - (__y.__i_ + __j))); +} + +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.__x_[__x.__i_]; + for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) + __os << __sp << __x.__x_[__j]; + for (size_t __j = 0; __j < __x.__i_; ++__j) + __os << __sp << __x.__x_[__j]; + return __os; +} + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + _UInt __t[_Np]; + for (size_t __i = 0; __i < _Np; ++__i) + __is >> __t[__i]; + if (!__is.fail()) + { + for (size_t __i = 0; __i < _Np; ++__i) + __x.__x_[__i] = __t[__i]; + __x.__i_ = 0; + } + return __is; +} + +typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, + 0x9908b0df, 11, 0xffffffff, + 7, 0x9d2c5680, + 15, 0xefc60000, + 18, 1812433253> mt19937; +typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, + 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, + 17, 0x71d67fffeda60000ULL, + 37, 0xfff7eee000000000ULL, + 43, 6364136223846793005ULL> mt19937_64; + +// subtract_with_carry_engine + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; + +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +bool +operator==( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); + +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +_LIBCPP_INLINE_VISIBILITY +bool +operator!=( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine +{ +public: + // types + typedef _UIntType result_type; + +private: + result_type __x_[__r]; + result_type __c_; + size_t __i_; + + static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; + static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); + static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); + static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); + static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); +public: + static _LIBCPP_CONSTEXPR const result_type _Min = 0; + static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : + (result_type(1) << __w) - result_type(1); + static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); + + // engine characteristics + static _LIBCPP_CONSTEXPR const size_t word_size = __w; + static _LIBCPP_CONSTEXPR const size_t short_lag = __s; + static _LIBCPP_CONSTEXPR const size_t long_lag = __r; + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; + + // constructors and seeding functions + _LIBCPP_INLINE_VISIBILITY + explicit subtract_with_carry_engine(result_type __sd = default_seed) + {seed(__sd);} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit subtract_with_carry_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) + {seed(__q);} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __sd = default_seed) + {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, + void + >::type + seed(_Sseq& __q) + {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} + + // generating functions + result_type operator()(); + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> + friend + bool + operator==( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); + + template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> + friend + bool + operator!=( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); + + template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); + + template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); + +private: + + void seed(result_type __sd, integral_constant<unsigned, 1>); + void seed(result_type __sd, integral_constant<unsigned, 2>); + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 1>); + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 2>); +}; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> + _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> + _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> + _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> + _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type + subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +void +subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, + integral_constant<unsigned, 1>) +{ + linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> + __e(__sd == 0u ? default_seed : __sd); + for (size_t __i = 0; __i < __r; ++__i) + __x_[__i] = static_cast<result_type>(__e() & _Max); + __c_ = __x_[__r-1] == 0; + __i_ = 0; +} + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +void +subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, + integral_constant<unsigned, 2>) +{ + linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> + __e(__sd == 0u ? default_seed : __sd); + for (size_t __i = 0; __i < __r; ++__i) + { + result_type __e0 = __e(); + __x_[__i] = static_cast<result_type>( + (__e0 + ((uint64_t)__e() << 32)) & _Max); + } + __c_ = __x_[__r-1] == 0; + __i_ = 0; +} + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +template<class _Sseq> +void +subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, + integral_constant<unsigned, 1>) +{ + const unsigned __k = 1; + uint32_t __ar[__r * __k]; + __q.generate(__ar, __ar + __r * __k); + for (size_t __i = 0; __i < __r; ++__i) + __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); + __c_ = __x_[__r-1] == 0; + __i_ = 0; +} + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +template<class _Sseq> +void +subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, + integral_constant<unsigned, 2>) +{ + const unsigned __k = 2; + uint32_t __ar[__r * __k]; + __q.generate(__ar, __ar + __r * __k); + for (size_t __i = 0; __i < __r; ++__i) + __x_[__i] = static_cast<result_type>( + (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); + __c_ = __x_[__r-1] == 0; + __i_ = 0; +} + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +_UIntType +subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() +{ + const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; + result_type& __xr = __x_[__i_]; + result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; + __xr = (__xs - __xr - __c_) & _Max; + __c_ = __new_c; + __i_ = (__i_ + 1) % __r; + return __xr; +} + +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +bool +operator==( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) +{ + if (__x.__c_ != __y.__c_) + return false; + if (__x.__i_ == __y.__i_) + return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); + if (__x.__i_ == 0 || __y.__i_ == 0) + { + size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); + if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, + __y.__x_ + __y.__i_)) + return false; + if (__x.__i_ == 0) + return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); + return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); + } + if (__x.__i_ < __y.__i_) + { + size_t __j = _Rp - __y.__i_; + if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), + __y.__x_ + __y.__i_)) + return false; + if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, + __y.__x_)) + return false; + return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, + __y.__x_ + (_Rp - (__x.__i_ + __j))); + } + size_t __j = _Rp - __x.__i_; + if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), + __x.__x_ + __x.__i_)) + return false; + if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, + __x.__x_)) + return false; + return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, + __x.__x_ + (_Rp - (__y.__i_ + __j))); +} + +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.__x_[__x.__i_]; + for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) + __os << __sp << __x.__x_[__j]; + for (size_t __j = 0; __j < __x.__i_; ++__j) + __os << __sp << __x.__x_[__j]; + __os << __sp << __x.__c_; + return __os; +} + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + _UInt __t[_Rp+1]; + for (size_t __i = 0; __i < _Rp+1; ++__i) + __is >> __t[__i]; + if (!__is.fail()) + { + for (size_t __i = 0; __i < _Rp; ++__i) + __x.__x_[__i] = __t[__i]; + __x.__c_ = __t[_Rp]; + __x.__i_ = 0; + } + return __is; +} + +typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; +typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; + +// discard_block_engine + +template<class _Engine, size_t __p, size_t __r> +class _LIBCPP_TEMPLATE_VIS discard_block_engine +{ + _Engine __e_; + int __n_; + + static_assert( 0 < __r, "discard_block_engine invalid parameters"); + static_assert(__r <= __p, "discard_block_engine invalid parameters"); + static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); +public: + // types + typedef typename _Engine::result_type result_type; + + // engine characteristics + static _LIBCPP_CONSTEXPR const size_t block_size = __p; + static _LIBCPP_CONSTEXPR const size_t used_block = __r; + +#ifdef _LIBCPP_CXX03_LANG + static const result_type _Min = _Engine::_Min; + static const result_type _Max = _Engine::_Max; +#else + static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); + static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); +#endif + + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } + + // constructors and seeding functions + _LIBCPP_INLINE_VISIBILITY + discard_block_engine() : __n_(0) {} + _LIBCPP_INLINE_VISIBILITY + explicit discard_block_engine(const _Engine& __e) + : __e_(__e), __n_(0) {} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit discard_block_engine(_Engine&& __e) + : __e_(_VSTD::move(__e)), __n_(0) {} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit discard_block_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && + !is_convertible<_Sseq, _Engine>::value>::type* = 0) + : __e_(__q), __n_(0) {} + _LIBCPP_INLINE_VISIBILITY + void seed() {__e_.seed(); __n_ = 0;} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, discard_block_engine>::value, + void + >::type + seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} + + // generating functions + result_type operator()(); + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + // property functions + _LIBCPP_INLINE_VISIBILITY + const _Engine& base() const _NOEXCEPT {return __e_;} + + template<class _Eng, size_t _Pp, size_t _Rp> + friend + bool + operator==( + const discard_block_engine<_Eng, _Pp, _Rp>& __x, + const discard_block_engine<_Eng, _Pp, _Rp>& __y); + + template<class _Eng, size_t _Pp, size_t _Rp> + friend + bool + operator!=( + const discard_block_engine<_Eng, _Pp, _Rp>& __x, + const discard_block_engine<_Eng, _Pp, _Rp>& __y); + + template <class _CharT, class _Traits, + class _Eng, size_t _Pp, size_t _Rp> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const discard_block_engine<_Eng, _Pp, _Rp>& __x); + + template <class _CharT, class _Traits, + class _Eng, size_t _Pp, size_t _Rp> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + discard_block_engine<_Eng, _Pp, _Rp>& __x); +}; + +template<class _Engine, size_t __p, size_t __r> + _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; + +template<class _Engine, size_t __p, size_t __r> + _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; + +template<class _Engine, size_t __p, size_t __r> +typename discard_block_engine<_Engine, __p, __r>::result_type +discard_block_engine<_Engine, __p, __r>::operator()() +{ + if (__n_ >= static_cast<int>(__r)) + { + __e_.discard(__p - __r); + __n_ = 0; + } + ++__n_; + return __e_(); +} + +template<class _Eng, size_t _Pp, size_t _Rp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, + const discard_block_engine<_Eng, _Pp, _Rp>& __y) +{ + return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; +} + +template<class _Eng, size_t _Pp, size_t _Rp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, + const discard_block_engine<_Eng, _Pp, _Rp>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Pp, size_t _Rp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const discard_block_engine<_Eng, _Pp, _Rp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.__e_ << __sp << __x.__n_; +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Pp, size_t _Rp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + discard_block_engine<_Eng, _Pp, _Rp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + _Eng __e; + int __n; + __is >> __e >> __n; + if (!__is.fail()) + { + __x.__e_ = __e; + __x.__n_ = __n; + } + return __is; +} + +typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; +typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; + +// independent_bits_engine + +template<class _Engine, size_t __w, class _UIntType> +class _LIBCPP_TEMPLATE_VIS independent_bits_engine +{ + template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp> + class __get_n + { + static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; + static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); + static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; + static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; + public: + static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np; + }; +public: + // types + typedef _UIntType result_type; + +private: + _Engine __e_; + + static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; + static_assert( 0 < __w, "independent_bits_engine invalid parameters"); + static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); + + typedef typename _Engine::result_type _Engine_result_type; + typedef typename conditional + < + sizeof(_Engine_result_type) <= sizeof(result_type), + result_type, + _Engine_result_type + >::type _Working_result_type; +#ifdef _LIBCPP_CXX03_LANG + static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min + + _Working_result_type(1); +#else + static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() + + _Working_result_type(1); +#endif + static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; + static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; + static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; + static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; + static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; + static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; + static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : + (_Rp >> __w0) << __w0; + static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : + (_Rp >> (__w0+1)) << (__w0+1); + static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? + _Engine_result_type(~0) >> (_EDt - __w0) : + _Engine_result_type(0); + static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? + _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : + _Engine_result_type(~0); +public: + static _LIBCPP_CONSTEXPR const result_type _Min = 0; + static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : + (result_type(1) << __w) - result_type(1); + static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); + + // engine characteristics + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + + // constructors and seeding functions + _LIBCPP_INLINE_VISIBILITY + independent_bits_engine() {} + _LIBCPP_INLINE_VISIBILITY + explicit independent_bits_engine(const _Engine& __e) + : __e_(__e) {} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit independent_bits_engine(_Engine&& __e) + : __e_(_VSTD::move(__e)) {} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit independent_bits_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && + !is_convertible<_Sseq, _Engine>::value>::type* = 0) + : __e_(__q) {} + _LIBCPP_INLINE_VISIBILITY + void seed() {__e_.seed();} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __sd) {__e_.seed(__sd);} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, independent_bits_engine>::value, + void + >::type + seed(_Sseq& __q) {__e_.seed(__q);} + + // generating functions + _LIBCPP_INLINE_VISIBILITY + result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + // property functions + _LIBCPP_INLINE_VISIBILITY + const _Engine& base() const _NOEXCEPT {return __e_;} + + template<class _Eng, size_t _Wp, class _UInt> + friend + bool + operator==( + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y); + + template<class _Eng, size_t _Wp, class _UInt> + friend + bool + operator!=( + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y); + + template <class _CharT, class _Traits, + class _Eng, size_t _Wp, class _UInt> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const independent_bits_engine<_Eng, _Wp, _UInt>& __x); + + template <class _CharT, class _Traits, + class _Eng, size_t _Wp, class _UInt> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + independent_bits_engine<_Eng, _Wp, _UInt>& __x); + +private: + _LIBCPP_INLINE_VISIBILITY + result_type __eval(false_type); + result_type __eval(true_type); + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + __count < _Dt, + result_type + >::type + __lshift(result_type __x) {return __x << __count;} + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + (__count >= _Dt), + result_type + >::type + __lshift(result_type) {return result_type(0);} +}; + +template<class _Engine, size_t __w, class _UIntType> +inline +_UIntType +independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) +{ + return static_cast<result_type>(__e_() & __mask0); +} + +template<class _Engine, size_t __w, class _UIntType> +_UIntType +independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) +{ + result_type _Sp = 0; + for (size_t __k = 0; __k < __n0; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y0); + _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0)); + } + for (size_t __k = __n0; __k < __n; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y1); + _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1)); + } + return _Sp; +} + +template<class _Eng, size_t _Wp, class _UInt> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==( + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y) +{ + return __x.base() == __y.base(); +} + +template<class _Eng, size_t _Wp, class _UInt> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=( + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Wp, class _UInt> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const independent_bits_engine<_Eng, _Wp, _UInt>& __x) +{ + return __os << __x.base(); +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Wp, class _UInt> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + independent_bits_engine<_Eng, _Wp, _UInt>& __x) +{ + _Eng __e; + __is >> __e; + if (!__is.fail()) + __x.__e_ = __e; + return __is; +} + +// shuffle_order_engine + +template <uint64_t _Xp, uint64_t _Yp> +struct __ugcd +{ + static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; +}; + +template <uint64_t _Xp> +struct __ugcd<_Xp, 0> +{ + static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; +}; + +template <uint64_t _Np, uint64_t _Dp> +class __uratio +{ + static_assert(_Dp != 0, "__uratio divide by 0"); + static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; +public: + static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; + static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; + + typedef __uratio<num, den> type; +}; + +template<class _Engine, size_t __k> +class _LIBCPP_TEMPLATE_VIS shuffle_order_engine +{ + static_assert(0 < __k, "shuffle_order_engine invalid parameters"); +public: + // types + typedef typename _Engine::result_type result_type; + +private: + _Engine __e_; + result_type _V_[__k]; + result_type _Y_; + +public: + // engine characteristics + static _LIBCPP_CONSTEXPR const size_t table_size = __k; + +#ifdef _LIBCPP_CXX03_LANG + static const result_type _Min = _Engine::_Min; + static const result_type _Max = _Engine::_Max; +#else + static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); + static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); +#endif + static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + + static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; + + // constructors and seeding functions + _LIBCPP_INLINE_VISIBILITY + shuffle_order_engine() {__init();} + _LIBCPP_INLINE_VISIBILITY + explicit shuffle_order_engine(const _Engine& __e) + : __e_(__e) {__init();} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit shuffle_order_engine(_Engine&& __e) + : __e_(_VSTD::move(__e)) {__init();} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit shuffle_order_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && + !is_convertible<_Sseq, _Engine>::value>::type* = 0) + : __e_(__q) {__init();} + _LIBCPP_INLINE_VISIBILITY + void seed() {__e_.seed(); __init();} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __sd) {__e_.seed(__sd); __init();} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, shuffle_order_engine>::value, + void + >::type + seed(_Sseq& __q) {__e_.seed(__q); __init();} + + // generating functions + _LIBCPP_INLINE_VISIBILITY + result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + // property functions + _LIBCPP_INLINE_VISIBILITY + const _Engine& base() const _NOEXCEPT {return __e_;} + +private: + template<class _Eng, size_t _Kp> + friend + bool + operator==( + const shuffle_order_engine<_Eng, _Kp>& __x, + const shuffle_order_engine<_Eng, _Kp>& __y); + + template<class _Eng, size_t _Kp> + friend + bool + operator!=( + const shuffle_order_engine<_Eng, _Kp>& __x, + const shuffle_order_engine<_Eng, _Kp>& __y); + + template <class _CharT, class _Traits, + class _Eng, size_t _Kp> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const shuffle_order_engine<_Eng, _Kp>& __x); + + template <class _CharT, class _Traits, + class _Eng, size_t _Kp> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + shuffle_order_engine<_Eng, _Kp>& __x); + + _LIBCPP_INLINE_VISIBILITY + void __init() + { + for (size_t __i = 0; __i < __k; ++__i) + _V_[__i] = __e_(); + _Y_ = __e_(); + } + + _LIBCPP_INLINE_VISIBILITY + result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} + _LIBCPP_INLINE_VISIBILITY + result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} + + _LIBCPP_INLINE_VISIBILITY + result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} + _LIBCPP_INLINE_VISIBILITY + result_type __eval2(true_type) {return __evalf<__k, 0>();} + + template <uint64_t _Np, uint64_t _Dp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), + result_type + >::type + __eval(__uratio<_Np, _Dp>) + {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} + + template <uint64_t _Np, uint64_t _Dp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), + result_type + >::type + __eval(__uratio<_Np, _Dp>) + { + const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min) + / __uratio<_Np, _Dp>::den); + _Y_ = _V_[__j]; + _V_[__j] = __e_(); + return _Y_; + } + + template <uint64_t __n, uint64_t __d> + _LIBCPP_INLINE_VISIBILITY + result_type __evalf() + { + const double _Fp = __d == 0 ? + __n / (2. * 0x8000000000000000ull) : + __n / (double)__d; + const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min)); + _Y_ = _V_[__j]; + _V_[__j] = __e_(); + return _Y_; + } +}; + +template<class _Engine, size_t __k> + _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; + +template<class _Eng, size_t _Kp> +bool +operator==( + const shuffle_order_engine<_Eng, _Kp>& __x, + const shuffle_order_engine<_Eng, _Kp>& __y) +{ + return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) && + __x.__e_ == __y.__e_; +} + +template<class _Eng, size_t _Kp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=( + const shuffle_order_engine<_Eng, _Kp>& __x, + const shuffle_order_engine<_Eng, _Kp>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Kp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const shuffle_order_engine<_Eng, _Kp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.__e_ << __sp << __x._V_[0]; + for (size_t __i = 1; __i < _Kp; ++__i) + __os << __sp << __x._V_[__i]; + return __os << __sp << __x._Y_; +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Kp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + shuffle_order_engine<_Eng, _Kp>& __x) +{ + typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + _Eng __e; + result_type _Vp[_Kp+1]; + __is >> __e; + for (size_t __i = 0; __i < _Kp+1; ++__i) + __is >> _Vp[__i]; + if (!__is.fail()) + { + __x.__e_ = __e; + for (size_t __i = 0; __i < _Kp; ++__i) + __x._V_[__i] = _Vp[__i]; + __x._Y_ = _Vp[_Kp]; + } + return __is; +} + +typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; + +// random_device + +class _LIBCPP_TYPE_VIS random_device +{ +#ifdef _LIBCPP_USING_DEV_RANDOM + int __f_; +#endif // defined(_LIBCPP_USING_DEV_RANDOM) +public: + // types + typedef unsigned result_type; + + // generator characteristics + static _LIBCPP_CONSTEXPR const result_type _Min = 0; + static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; + + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min;} + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max;} + + // constructors + explicit random_device(const string& __token = "/dev/urandom"); + ~random_device(); + + // generating functions + result_type operator()(); + + // property functions + double entropy() const _NOEXCEPT; + +private: + // no copy functions + random_device(const random_device&); // = delete; + random_device& operator=(const random_device&); // = delete; +}; + +// seed_seq + +class _LIBCPP_TEMPLATE_VIS seed_seq +{ +public: + // types + typedef uint32_t result_type; + +private: + vector<result_type> __v_; + + template<class _InputIterator> + void init(_InputIterator __first, _InputIterator __last); +public: + // constructors + _LIBCPP_INLINE_VISIBILITY + seed_seq() _NOEXCEPT {} +#ifndef _LIBCPP_CXX03_LANG + template<class _Tp> + _LIBCPP_INLINE_VISIBILITY + seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + + template<class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + seed_seq(_InputIterator __first, _InputIterator __last) + {init(__first, __last);} + + // generating functions + template<class _RandomAccessIterator> + void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); + + // property functions + _LIBCPP_INLINE_VISIBILITY + size_t size() const _NOEXCEPT {return __v_.size();} + template<class _OutputIterator> + _LIBCPP_INLINE_VISIBILITY + void param(_OutputIterator __dest) const + {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} + +private: + // no copy functions + seed_seq(const seed_seq&); // = delete; + void operator=(const seed_seq&); // = delete; + + _LIBCPP_INLINE_VISIBILITY + static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} +}; + +template<class _InputIterator> +void +seed_seq::init(_InputIterator __first, _InputIterator __last) +{ + for (_InputIterator __s = __first; __s != __last; ++__s) + __v_.push_back(*__s & 0xFFFFFFFF); +} + +template<class _RandomAccessIterator> +void +seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + if (__first != __last) + { + _VSTD::fill(__first, __last, 0x8b8b8b8b); + const size_t __n = static_cast<size_t>(__last - __first); + const size_t __s = __v_.size(); + const size_t __t = (__n >= 623) ? 11 + : (__n >= 68) ? 7 + : (__n >= 39) ? 5 + : (__n >= 7) ? 3 + : (__n - 1) / 2; + const size_t __p = (__n - __t) / 2; + const size_t __q = __p + __t; + const size_t __m = _VSTD::max(__s + 1, __n); + // __k = 0; + { + result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] + ^ __first[__n - 1]); + __first[__p] += __r; + __r += __s; + __first[__q] += __r; + __first[0] = __r; + } + for (size_t __k = 1; __k <= __s; ++__k) + { + const size_t __kmodn = __k % __n; + const size_t __kpmodn = (__k + __p) % __n; + result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] + ^ __first[(__k - 1) % __n]); + __first[__kpmodn] += __r; + __r += __kmodn + __v_[__k-1]; + __first[(__k + __q) % __n] += __r; + __first[__kmodn] = __r; + } + for (size_t __k = __s + 1; __k < __m; ++__k) + { + const size_t __kmodn = __k % __n; + const size_t __kpmodn = (__k + __p) % __n; + result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] + ^ __first[(__k - 1) % __n]); + __first[__kpmodn] += __r; + __r += __kmodn; + __first[(__k + __q) % __n] += __r; + __first[__kmodn] = __r; + } + for (size_t __k = __m; __k < __m + __n; ++__k) + { + const size_t __kmodn = __k % __n; + const size_t __kpmodn = (__k + __p) % __n; + result_type __r = 1566083941 * _Tp(__first[__kmodn] + + __first[__kpmodn] + + __first[(__k - 1) % __n]); + __first[__kpmodn] ^= __r; + __r -= __kmodn; + __first[(__k + __q) % __n] ^= __r; + __first[__kmodn] = __r; + } + } +} + +// generate_canonical + +template<class _RealType, size_t __bits, class _URNG> +_RealType +generate_canonical(_URNG& __g) +{ + const size_t _Dt = numeric_limits<_RealType>::digits; + const size_t __b = _Dt < __bits ? _Dt : __bits; +#ifdef _LIBCPP_CXX03_LANG + const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; +#else + const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; +#endif + const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); + const _RealType _Rp = _URNG::max() - _URNG::min() + _RealType(1); + _RealType __base = _Rp; + _RealType _Sp = __g() - _URNG::min(); + for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) + _Sp += (__g() - _URNG::min()) * __base; + return _Sp / __base; +} + +// uniform_int_distribution + +// in <algorithm> + +template <class _CharT, class _Traits, class _IT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const uniform_int_distribution<_IT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.a() << __sp << __x.b(); +} + +template <class _CharT, class _Traits, class _IT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + uniform_int_distribution<_IT>& __x) +{ + typedef uniform_int_distribution<_IT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __a; + result_type __b; + __is >> __a >> __b; + if (!__is.fail()) + __x.param(param_type(__a, __b)); + return __is; +} + +// uniform_real_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS uniform_real_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __a_; + result_type __b_; + public: + typedef uniform_real_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __a = 0, + result_type __b = 1) + : __a_(__a), __b_(__b) {} + + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __a_;} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __b_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) + : __p_(param_type(__a, __b)) {} + _LIBCPP_INLINE_VISIBILITY + explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __p_.a();} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __p_.b();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return a();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return b();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const uniform_real_distribution& __x, + const uniform_real_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const uniform_real_distribution& __x, + const uniform_real_distribution& __y) + {return !(__x == __y);} +}; + +template<class _RealType> +template<class _URNG> +inline +typename uniform_real_distribution<_RealType>::result_type +uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + return (__p.b() - __p.a()) + * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) + + __p.a(); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const uniform_real_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.a() << __sp << __x.b(); +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + uniform_real_distribution<_RT>& __x) +{ + typedef uniform_real_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __a; + result_type __b; + __is >> __a >> __b; + if (!__is.fail()) + __x.param(param_type(__a, __b)); + return __is; +} + +// bernoulli_distribution + +class _LIBCPP_TEMPLATE_VIS bernoulli_distribution +{ +public: + // types + typedef bool result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + double __p_; + public: + typedef bernoulli_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(double __p = 0.5) : __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit bernoulli_distribution(double __p = 0.5) + : __p_(param_type(__p)) {} + _LIBCPP_INLINE_VISIBILITY + explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_.p();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return false;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return true;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const bernoulli_distribution& __x, + const bernoulli_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const bernoulli_distribution& __x, + const bernoulli_distribution& __y) + {return !(__x == __y);} +}; + +template<class _URNG> +inline +bernoulli_distribution::result_type +bernoulli_distribution::operator()(_URNG& __g, const param_type& __p) +{ + uniform_real_distribution<double> __gen; + return __gen(__g) < __p.p(); +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.p(); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) +{ + typedef bernoulli_distribution _Eng; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + double __p; + __is >> __p; + if (!__is.fail()) + __x.param(param_type(__p)); + return __is; +} + +// binomial_distribution + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS binomial_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __t_; + double __p_; + double __pr_; + double __odds_ratio_; + result_type __r0_; + public: + typedef binomial_distribution distribution_type; + + explicit param_type(result_type __t = 1, double __p = 0.5); + + _LIBCPP_INLINE_VISIBILITY + result_type t() const {return __t_;} + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + friend class binomial_distribution; + }; + +private: + param_type __p_; + +public: + // constructors and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit binomial_distribution(result_type __t = 1, double __p = 0.5) + : __p_(param_type(__t, __p)) {} + _LIBCPP_INLINE_VISIBILITY + explicit binomial_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type t() const {return __p_.t();} + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_.p();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return t();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const binomial_distribution& __x, + const binomial_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const binomial_distribution& __x, + const binomial_distribution& __y) + {return !(__x == __y);} +}; + +#ifndef _LIBCPP_MSVCRT +extern "C" double lgamma_r(double, int *); +#endif + +inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { +#if defined(_LIBCPP_MSVCRT) + return lgamma(__d); +#else + int __sign; + return lgamma_r(__d, &__sign); +#endif +} + +template<class _IntType> +binomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p) + : __t_(__t), __p_(__p) +{ + if (0 < __p_ && __p_ < 1) + { + __r0_ = static_cast<result_type>((__t_ + 1) * __p_); + __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - + __libcpp_lgamma(__r0_ + 1.) - + __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + + (__t_ - __r0_) * _VSTD::log(1 - __p_)); + __odds_ratio_ = __p_ / (1 - __p_); + } +} + +// Reference: Kemp, C.D. (1986). `A modal method for generating binomial +// variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. +template<class _IntType> +template<class _URNG> +_IntType +binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) +{ + if (__pr.__t_ == 0 || __pr.__p_ == 0) + return 0; + if (__pr.__p_ == 1) + return __pr.__t_; + uniform_real_distribution<double> __gen; + double __u = __gen(__g) - __pr.__pr_; + if (__u < 0) + return __pr.__r0_; + double __pu = __pr.__pr_; + double __pd = __pu; + result_type __ru = __pr.__r0_; + result_type __rd = __ru; + while (true) + { + if (__rd >= 1) + { + __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); + __u -= __pd; + if (__u < 0) + return __rd - 1; + } + if ( __rd != 0 ) + --__rd; + ++__ru; + if (__ru <= __pr.__t_) + { + __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; + __u -= __pu; + if (__u < 0) + return __ru; + } + } +} + +template <class _CharT, class _Traits, class _IntType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const binomial_distribution<_IntType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.t() << __sp << __x.p(); +} + +template <class _CharT, class _Traits, class _IntType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + binomial_distribution<_IntType>& __x) +{ + typedef binomial_distribution<_IntType> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __t; + double __p; + __is >> __t >> __p; + if (!__is.fail()) + __x.param(param_type(__t, __p)); + return __is; +} + +// exponential_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS exponential_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __lambda_; + public: + typedef exponential_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} + + _LIBCPP_INLINE_VISIBILITY + result_type lambda() const {return __lambda_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__lambda_ == __y.__lambda_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit exponential_distribution(result_type __lambda = 1) + : __p_(param_type(__lambda)) {} + _LIBCPP_INLINE_VISIBILITY + explicit exponential_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type lambda() const {return __p_.lambda();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const exponential_distribution& __x, + const exponential_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const exponential_distribution& __x, + const exponential_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +_RealType +exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + return -_VSTD::log + ( + result_type(1) - + _VSTD::generate_canonical<result_type, + numeric_limits<result_type>::digits>(__g) + ) + / __p.lambda(); +} + +template <class _CharT, class _Traits, class _RealType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + return __os << __x.lambda(); +} + +template <class _CharT, class _Traits, class _RealType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + exponential_distribution<_RealType>& __x) +{ + typedef exponential_distribution<_RealType> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __lambda; + __is >> __lambda; + if (!__is.fail()) + __x.param(param_type(__lambda)); + return __is; +} + +// normal_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS normal_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __mean_; + result_type __stddev_; + public: + typedef normal_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __mean = 0, result_type __stddev = 1) + : __mean_(__mean), __stddev_(__stddev) {} + + _LIBCPP_INLINE_VISIBILITY + result_type mean() const {return __mean_;} + _LIBCPP_INLINE_VISIBILITY + result_type stddev() const {return __stddev_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + result_type _V_; + bool _V_hot_; + +public: + // constructors and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) + : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} + _LIBCPP_INLINE_VISIBILITY + explicit normal_distribution(const param_type& __p) + : __p_(__p), _V_hot_(false) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {_V_hot_ = false;} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type mean() const {return __p_.mean();} + _LIBCPP_INLINE_VISIBILITY + result_type stddev() const {return __p_.stddev();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return -numeric_limits<result_type>::infinity();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const normal_distribution& __x, + const normal_distribution& __y) + {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && + (!__x._V_hot_ || __x._V_ == __y._V_);} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const normal_distribution& __x, + const normal_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RT>& __x); +}; + +template <class _RealType> +template<class _URNG> +_RealType +normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + result_type _Up; + if (_V_hot_) + { + _V_hot_ = false; + _Up = _V_; + } + else + { + uniform_real_distribution<result_type> _Uni(-1, 1); + result_type __u; + result_type __v; + result_type __s; + do + { + __u = _Uni(__g); + __v = _Uni(__g); + __s = __u * __u + __v * __v; + } while (__s > 1 || __s == 0); + result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); + _V_ = __v * _Fp; + _V_hot_ = true; + _Up = __u * _Fp; + } + return _Up * __p.stddev() + __p.mean(); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; + if (__x._V_hot_) + __os << __sp << __x._V_; + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RT>& __x) +{ + typedef normal_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __mean; + result_type __stddev; + result_type _Vp = 0; + bool _V_hot = false; + __is >> __mean >> __stddev >> _V_hot; + if (_V_hot) + __is >> _Vp; + if (!__is.fail()) + { + __x.param(param_type(__mean, __stddev)); + __x._V_hot_ = _V_hot; + __x._V_ = _Vp; + } + return __is; +} + +// lognormal_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS lognormal_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + normal_distribution<result_type> __nd_; + public: + typedef lognormal_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __m = 0, result_type __s = 1) + : __nd_(__m, __s) {} + + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __nd_.mean();} + _LIBCPP_INLINE_VISIBILITY + result_type s() const {return __nd_.stddev();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__nd_ == __y.__nd_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + friend class lognormal_distribution; + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + lognormal_distribution<_RT>& __x); + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) + : __p_(param_type(__m, __s)) {} + _LIBCPP_INLINE_VISIBILITY + explicit lognormal_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {__p_.__nd_.reset();} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g, const param_type& __p) + {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __p_.m();} + _LIBCPP_INLINE_VISIBILITY + result_type s() const {return __p_.s();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const lognormal_distribution& __x, + const lognormal_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const lognormal_distribution& __x, + const lognormal_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + lognormal_distribution<_RT>& __x); +}; + +template <class _CharT, class _Traits, class _RT> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RT>& __x) +{ + return __os << __x.__p_.__nd_; +} + +template <class _CharT, class _Traits, class _RT> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + lognormal_distribution<_RT>& __x) +{ + return __is >> __x.__p_.__nd_; +} + +// poisson_distribution + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS poisson_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + double __mean_; + double __s_; + double __d_; + double __l_; + double __omega_; + double __c0_; + double __c1_; + double __c2_; + double __c3_; + double __c_; + + public: + typedef poisson_distribution distribution_type; + + explicit param_type(double __mean = 1.0); + + _LIBCPP_INLINE_VISIBILITY + double mean() const {return __mean_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__mean_ == __y.__mean_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + friend class poisson_distribution; + }; + +private: + param_type __p_; + +public: + // constructors and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} + _LIBCPP_INLINE_VISIBILITY + explicit poisson_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + double mean() const {return __p_.mean();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::max();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const poisson_distribution& __x, + const poisson_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const poisson_distribution& __x, + const poisson_distribution& __y) + {return !(__x == __y);} +}; + +template<class _IntType> +poisson_distribution<_IntType>::param_type::param_type(double __mean) + : __mean_(__mean) +{ + if (__mean_ < 10) + { + __s_ = 0; + __d_ = 0; + __l_ = _VSTD::exp(-__mean_); + __omega_ = 0; + __c3_ = 0; + __c2_ = 0; + __c1_ = 0; + __c0_ = 0; + __c_ = 0; + } + else + { + __s_ = _VSTD::sqrt(__mean_); + __d_ = 6 * __mean_ * __mean_; + __l_ = static_cast<result_type>(__mean_ - 1.1484); + __omega_ = .3989423 / __s_; + double __b1_ = .4166667E-1 / __mean_; + double __b2_ = .3 * __b1_ * __b1_; + __c3_ = .1428571 * __b1_ * __b2_; + __c2_ = __b2_ - 15. * __c3_; + __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; + __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; + __c_ = .1069 / __mean_; + } +} + +template <class _IntType> +template<class _URNG> +_IntType +poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) +{ + result_type __x; + uniform_real_distribution<double> __urd; + if (__pr.__mean_ < 10) + { + __x = 0; + for (double __p = __urd(__urng); __p > __pr.__l_; ++__x) + __p *= __urd(__urng); + } + else + { + double __difmuk; + double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); + double __u; + if (__g > 0) + { + __x = static_cast<result_type>(__g); + if (__x >= __pr.__l_) + return __x; + __difmuk = __pr.__mean_ - __x; + __u = __urd(__urng); + if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) + return __x; + } + exponential_distribution<double> __edist; + for (bool __using_exp_dist = false; true; __using_exp_dist = true) + { + double __e; + if (__using_exp_dist || __g < 0) + { + double __t; + do + { + __e = __edist(__urng); + __u = __urd(__urng); + __u += __u - 1; + __t = 1.8 + (__u < 0 ? -__e : __e); + } while (__t <= -.6744); + __x = __pr.__mean_ + __pr.__s_ * __t; + __difmuk = __pr.__mean_ - __x; + __using_exp_dist = true; + } + double __px; + double __py; + if (__x < 10) + { + const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, + 40320, 362880}; + __px = -__pr.__mean_; + __py = _VSTD::pow(__pr.__mean_, (double)__x) / __fac[__x]; + } + else + { + double __del = .8333333E-1 / __x; + __del -= 4.8 * __del * __del * __del; + double __v = __difmuk / __x; + if (_VSTD::abs(__v) > 0.25) + __px = __x * _VSTD::log(1 + __v) - __difmuk - __del; + else + __px = __x * __v * __v * (((((((.1250060 * __v + -.1384794) * + __v + .1421878) * __v + -.1661269) * __v + .2000118) * + __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; + __py = .3989423 / _VSTD::sqrt(__x); + } + double __r = (0.5 - __difmuk) / __pr.__s_; + double __r2 = __r * __r; + double __fx = -0.5 * __r2; + double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * + __r2 + __pr.__c1_) * __r2 + __pr.__c0_); + if (__using_exp_dist) + { + if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - + __fy * _VSTD::exp(__fx + __e)) + break; + } + else + { + if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) + break; + } + } + } + return __x; +} + +template <class _CharT, class _Traits, class _IntType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const poisson_distribution<_IntType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + return __os << __x.mean(); +} + +template <class _CharT, class _Traits, class _IntType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + poisson_distribution<_IntType>& __x) +{ + typedef poisson_distribution<_IntType> _Eng; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + double __mean; + __is >> __mean; + if (!__is.fail()) + __x.param(param_type(__mean)); + return __is; +} + +// weibull_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS weibull_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __a_; + result_type __b_; + public: + typedef weibull_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __a = 1, result_type __b = 1) + : __a_(__a), __b_(__b) {} + + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __a_;} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __b_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit weibull_distribution(result_type __a = 1, result_type __b = 1) + : __p_(param_type(__a, __b)) {} + _LIBCPP_INLINE_VISIBILITY + explicit weibull_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g, const param_type& __p) + {return __p.b() * + _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __p_.a();} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __p_.b();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const weibull_distribution& __x, + const weibull_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const weibull_distribution& __x, + const weibull_distribution& __y) + {return !(__x == __y);} +}; + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const weibull_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.a() << __sp << __x.b(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + weibull_distribution<_RT>& __x) +{ + typedef weibull_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __a; + result_type __b; + __is >> __a >> __b; + if (!__is.fail()) + __x.param(param_type(__a, __b)); + return __is; +} + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS extreme_value_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __a_; + result_type __b_; + public: + typedef extreme_value_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __a = 0, result_type __b = 1) + : __a_(__a), __b_(__b) {} + + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __a_;} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __b_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) + : __p_(param_type(__a, __b)) {} + _LIBCPP_INLINE_VISIBILITY + explicit extreme_value_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __p_.a();} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __p_.b();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return -numeric_limits<result_type>::infinity();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const extreme_value_distribution& __x, + const extreme_value_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const extreme_value_distribution& __x, + const extreme_value_distribution& __y) + {return !(__x == __y);} +}; + +template<class _RealType> +template<class _URNG> +_RealType +extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + return __p.a() - __p.b() * + _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const extreme_value_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.a() << __sp << __x.b(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + extreme_value_distribution<_RT>& __x) +{ + typedef extreme_value_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __a; + result_type __b; + __is >> __a >> __b; + if (!__is.fail()) + __x.param(param_type(__a, __b)); + return __is; +} + +// gamma_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS gamma_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __alpha_; + result_type __beta_; + public: + typedef gamma_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __alpha = 1, result_type __beta = 1) + : __alpha_(__alpha), __beta_(__beta) {} + + _LIBCPP_INLINE_VISIBILITY + result_type alpha() const {return __alpha_;} + _LIBCPP_INLINE_VISIBILITY + result_type beta() const {return __beta_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) + : __p_(param_type(__alpha, __beta)) {} + _LIBCPP_INLINE_VISIBILITY + explicit gamma_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type alpha() const {return __p_.alpha();} + _LIBCPP_INLINE_VISIBILITY + result_type beta() const {return __p_.beta();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const gamma_distribution& __x, + const gamma_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const gamma_distribution& __x, + const gamma_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +_RealType +gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + result_type __a = __p.alpha(); + uniform_real_distribution<result_type> __gen(0, 1); + exponential_distribution<result_type> __egen; + result_type __x; + if (__a == 1) + __x = __egen(__g); + else if (__a > 1) + { + const result_type __b = __a - 1; + const result_type __c = 3 * __a - result_type(0.75); + while (true) + { + const result_type __u = __gen(__g); + const result_type __v = __gen(__g); + const result_type __w = __u * (1 - __u); + if (__w != 0) + { + const result_type __y = _VSTD::sqrt(__c / __w) * + (__u - result_type(0.5)); + __x = __b + __y; + if (__x >= 0) + { + const result_type __z = 64 * __w * __w * __w * __v * __v; + if (__z <= 1 - 2 * __y * __y / __x) + break; + if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) + break; + } + } + } + } + else // __a < 1 + { + while (true) + { + const result_type __u = __gen(__g); + const result_type __es = __egen(__g); + if (__u <= 1 - __a) + { + __x = _VSTD::pow(__u, 1 / __a); + if (__x <= __es) + break; + } + else + { + const result_type __e = -_VSTD::log((1-__u)/__a); + __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); + if (__x <= __e + __es) + break; + } + } + } + return __x * __p.beta(); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const gamma_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.alpha() << __sp << __x.beta(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + gamma_distribution<_RT>& __x) +{ + typedef gamma_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __alpha; + result_type __beta; + __is >> __alpha >> __beta; + if (!__is.fail()) + __x.param(param_type(__alpha, __beta)); + return __is; +} + +// negative_binomial_distribution + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __k_; + double __p_; + public: + typedef negative_binomial_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __k = 1, double __p = 0.5) + : __k_(__k), __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + result_type k() const {return __k_;} + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) + : __p_(__k, __p) {} + _LIBCPP_INLINE_VISIBILITY + explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type k() const {return __p_.k();} + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_.p();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::max();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const negative_binomial_distribution& __x, + const negative_binomial_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const negative_binomial_distribution& __x, + const negative_binomial_distribution& __y) + {return !(__x == __y);} +}; + +template <class _IntType> +template<class _URNG> +_IntType +negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) +{ + result_type __k = __pr.k(); + double __p = __pr.p(); + if (__k <= 21 * __p) + { + bernoulli_distribution __gen(__p); + result_type __f = 0; + result_type __s = 0; + while (__s < __k) + { + if (__gen(__urng)) + ++__s; + else + ++__f; + } + return __f; + } + return poisson_distribution<result_type>(gamma_distribution<double> + (__k, (1-__p)/__p)(__urng))(__urng); +} + +template <class _CharT, class _Traits, class _IntType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const negative_binomial_distribution<_IntType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.k() << __sp << __x.p(); +} + +template <class _CharT, class _Traits, class _IntType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + negative_binomial_distribution<_IntType>& __x) +{ + typedef negative_binomial_distribution<_IntType> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __k; + double __p; + __is >> __k >> __p; + if (!__is.fail()) + __x.param(param_type(__k, __p)); + return __is; +} + +// geometric_distribution + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS geometric_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + double __p_; + public: + typedef geometric_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(double __p = 0.5) : __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + explicit geometric_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g, const param_type& __p) + {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} + + // property functions + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_.p();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::max();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const geometric_distribution& __x, + const geometric_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const geometric_distribution& __x, + const geometric_distribution& __y) + {return !(__x == __y);} +}; + +template <class _CharT, class _Traits, class _IntType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + return __os << __x.p(); +} + +template <class _CharT, class _Traits, class _IntType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + geometric_distribution<_IntType>& __x) +{ + typedef geometric_distribution<_IntType> _Eng; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + double __p; + __is >> __p; + if (!__is.fail()) + __x.param(param_type(__p)); + return __is; +} + +// chi_squared_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS chi_squared_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __n_; + public: + typedef chi_squared_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __n = 1) : __n_(__n) {} + + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __n_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__n_ == __y.__n_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit chi_squared_distribution(result_type __n = 1) + : __p_(param_type(__n)) {} + _LIBCPP_INLINE_VISIBILITY + explicit chi_squared_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g, const param_type& __p) + {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __p_.n();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const chi_squared_distribution& __x, + const chi_squared_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const chi_squared_distribution& __x, + const chi_squared_distribution& __y) + {return !(__x == __y);} +}; + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const chi_squared_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + __os << __x.n(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + chi_squared_distribution<_RT>& __x) +{ + typedef chi_squared_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __n; + __is >> __n; + if (!__is.fail()) + __x.param(param_type(__n)); + return __is; +} + +// cauchy_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS cauchy_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __a_; + result_type __b_; + public: + typedef cauchy_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __a = 0, result_type __b = 1) + : __a_(__a), __b_(__b) {} + + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __a_;} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __b_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) + : __p_(param_type(__a, __b)) {} + _LIBCPP_INLINE_VISIBILITY + explicit cauchy_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __p_.a();} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __p_.b();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return -numeric_limits<result_type>::infinity();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const cauchy_distribution& __x, + const cauchy_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const cauchy_distribution& __x, + const cauchy_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +inline +_RealType +cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + uniform_real_distribution<result_type> __gen; + // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite + return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const cauchy_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.a() << __sp << __x.b(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + cauchy_distribution<_RT>& __x) +{ + typedef cauchy_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __a; + result_type __b; + __is >> __a >> __b; + if (!__is.fail()) + __x.param(param_type(__a, __b)); + return __is; +} + +// fisher_f_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS fisher_f_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __m_; + result_type __n_; + public: + typedef fisher_f_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __m = 1, result_type __n = 1) + : __m_(__m), __n_(__n) {} + + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __m_;} + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __n_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) + : __p_(param_type(__m, __n)) {} + _LIBCPP_INLINE_VISIBILITY + explicit fisher_f_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __p_.m();} + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __p_.n();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const fisher_f_distribution& __x, + const fisher_f_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const fisher_f_distribution& __x, + const fisher_f_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +_RealType +fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); + gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); + return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const fisher_f_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.m() << __sp << __x.n(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + fisher_f_distribution<_RT>& __x) +{ + typedef fisher_f_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __m; + result_type __n; + __is >> __m >> __n; + if (!__is.fail()) + __x.param(param_type(__m, __n)); + return __is; +} + +// student_t_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS student_t_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __n_; + public: + typedef student_t_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __n = 1) : __n_(__n) {} + + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __n_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__n_ == __y.__n_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + normal_distribution<result_type> __nd_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + explicit student_t_distribution(result_type __n = 1) + : __p_(param_type(__n)) {} + _LIBCPP_INLINE_VISIBILITY + explicit student_t_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {__nd_.reset();} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __p_.n();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return -numeric_limits<result_type>::infinity();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const student_t_distribution& __x, + const student_t_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const student_t_distribution& __x, + const student_t_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +_RealType +student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + gamma_distribution<result_type> __gd(__p.n() * .5, 2); + return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const student_t_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + __os << __x.n(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + student_t_distribution<_RT>& __x) +{ + typedef student_t_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + result_type __n; + __is >> __n; + if (!__is.fail()) + __x.param(param_type(__n)); + return __is; +} + +// discrete_distribution + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS discrete_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + vector<double> __p_; + public: + typedef discrete_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + param_type() {} + template<class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + param_type(_InputIterator __f, _InputIterator __l) + : __p_(__f, __l) {__init();} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + param_type(initializer_list<double> __wl) + : __p_(__wl.begin(), __wl.end()) {__init();} +#endif // _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(size_t __nw, double __xmin, double __xmax, + _UnaryOperation __fw); + + vector<double> probabilities() const; + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + private: + void __init(); + + friend class discrete_distribution; + + template <class _CharT, class _Traits, class _IT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const discrete_distribution<_IT>& __x); + + template <class _CharT, class _Traits, class _IT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + discrete_distribution<_IT>& __x); + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + discrete_distribution() {} + template<class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + discrete_distribution(_InputIterator __f, _InputIterator __l) + : __p_(__f, __l) {} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + discrete_distribution(initializer_list<double> __wl) + : __p_(__wl) {} +#endif // _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + discrete_distribution(size_t __nw, double __xmin, double __xmax, + _UnaryOperation __fw) + : __p_(__nw, __xmin, __xmax, __fw) {} + _LIBCPP_INLINE_VISIBILITY + explicit discrete_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + vector<double> probabilities() const {return __p_.probabilities();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return __p_.__p_.size();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const discrete_distribution& __x, + const discrete_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const discrete_distribution& __x, + const discrete_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _IT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const discrete_distribution<_IT>& __x); + + template <class _CharT, class _Traits, class _IT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + discrete_distribution<_IT>& __x); +}; + +template<class _IntType> +template<class _UnaryOperation> +discrete_distribution<_IntType>::param_type::param_type(size_t __nw, + double __xmin, + double __xmax, + _UnaryOperation __fw) +{ + if (__nw > 1) + { + __p_.reserve(__nw - 1); + double __d = (__xmax - __xmin) / __nw; + double __d2 = __d / 2; + for (size_t __k = 0; __k < __nw; ++__k) + __p_.push_back(__fw(__xmin + __k * __d + __d2)); + __init(); + } +} + +template<class _IntType> +void +discrete_distribution<_IntType>::param_type::__init() +{ + if (!__p_.empty()) + { + if (__p_.size() > 1) + { + double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); + for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); + __i < __e; ++__i) + *__i /= __s; + vector<double> __t(__p_.size() - 1); + _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); + swap(__p_, __t); + } + else + { + __p_.clear(); + __p_.shrink_to_fit(); + } + } +} + +template<class _IntType> +vector<double> +discrete_distribution<_IntType>::param_type::probabilities() const +{ + size_t __n = __p_.size(); + _VSTD::vector<double> __p(__n+1); + _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); + if (__n > 0) + __p[__n] = 1 - __p_[__n-1]; + else + __p[0] = 1; + return __p; +} + +template<class _IntType> +template<class _URNG> +_IntType +discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) +{ + uniform_real_distribution<double> __gen; + return static_cast<_IntType>( + _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - + __p.__p_.begin()); +} + +template <class _CharT, class _Traits, class _IT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const discrete_distribution<_IT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + size_t __n = __x.__p_.__p_.size(); + __os << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__p_[__i]; + return __os; +} + +template <class _CharT, class _Traits, class _IT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + discrete_distribution<_IT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + size_t __n; + __is >> __n; + vector<double> __p(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __p[__i]; + if (!__is.fail()) + swap(__x.__p_.__p_, __p); + return __is; +} + +// piecewise_constant_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + vector<result_type> __b_; + vector<result_type> __densities_; + vector<result_type> __areas_; + public: + typedef piecewise_constant_distribution distribution_type; + + param_type(); + template<class _InputIteratorB, class _InputIteratorW> + param_type(_InputIteratorB __fB, _InputIteratorB __lB, + _InputIteratorW __fW); +#ifndef _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); +#endif // _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(size_t __nw, result_type __xmin, result_type __xmax, + _UnaryOperation __fw); + param_type & operator=(const param_type& __rhs); + + _LIBCPP_INLINE_VISIBILITY + vector<result_type> intervals() const {return __b_;} + _LIBCPP_INLINE_VISIBILITY + vector<result_type> densities() const {return __densities_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + private: + void __init(); + + friend class piecewise_constant_distribution; + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_constant_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_constant_distribution<_RT>& __x); + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + piecewise_constant_distribution() {} + template<class _InputIteratorB, class _InputIteratorW> + _LIBCPP_INLINE_VISIBILITY + piecewise_constant_distribution(_InputIteratorB __fB, + _InputIteratorB __lB, + _InputIteratorW __fW) + : __p_(__fB, __lB, __fW) {} + +#ifndef _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + piecewise_constant_distribution(initializer_list<result_type> __bl, + _UnaryOperation __fw) + : __p_(__bl, __fw) {} +#endif // _LIBCPP_CXX03_LANG + + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + piecewise_constant_distribution(size_t __nw, result_type __xmin, + result_type __xmax, _UnaryOperation __fw) + : __p_(__nw, __xmin, __xmax, __fw) {} + + _LIBCPP_INLINE_VISIBILITY + explicit piecewise_constant_distribution(const param_type& __p) + : __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + vector<result_type> intervals() const {return __p_.intervals();} + _LIBCPP_INLINE_VISIBILITY + vector<result_type> densities() const {return __p_.densities();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return __p_.__b_.front();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return __p_.__b_.back();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const piecewise_constant_distribution& __x, + const piecewise_constant_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const piecewise_constant_distribution& __x, + const piecewise_constant_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_constant_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_constant_distribution<_RT>& __x); +}; + +template<class _RealType> +typename piecewise_constant_distribution<_RealType>::param_type & +piecewise_constant_distribution<_RealType>::param_type::operator= + (const param_type& __rhs) +{ +// These can throw + __b_.reserve (__rhs.__b_.size ()); + __densities_.reserve(__rhs.__densities_.size()); + __areas_.reserve (__rhs.__areas_.size()); + +// These can not throw + __b_ = __rhs.__b_; + __densities_ = __rhs.__densities_; + __areas_ = __rhs.__areas_; + return *this; +} + +template<class _RealType> +void +piecewise_constant_distribution<_RealType>::param_type::__init() +{ + // __densities_ contains non-normalized areas + result_type __total_area = _VSTD::accumulate(__densities_.begin(), + __densities_.end(), + result_type()); + for (size_t __i = 0; __i < __densities_.size(); ++__i) + __densities_[__i] /= __total_area; + // __densities_ contains normalized areas + __areas_.assign(__densities_.size(), result_type()); + _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, + __areas_.begin() + 1); + // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] + __densities_.back() = 1 - __areas_.back(); // correct round off error + for (size_t __i = 0; __i < __densities_.size(); ++__i) + __densities_[__i] /= (__b_[__i+1] - __b_[__i]); + // __densities_ now contains __densities_ +} + +template<class _RealType> +piecewise_constant_distribution<_RealType>::param_type::param_type() + : __b_(2), + __densities_(1, 1.0), + __areas_(1, 0.0) +{ + __b_[1] = 1; +} + +template<class _RealType> +template<class _InputIteratorB, class _InputIteratorW> +piecewise_constant_distribution<_RealType>::param_type::param_type( + _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) + : __b_(__fB, __lB) +{ + if (__b_.size() < 2) + { + __b_.resize(2); + __b_[0] = 0; + __b_[1] = 1; + __densities_.assign(1, 1.0); + __areas_.assign(1, 0.0); + } + else + { + __densities_.reserve(__b_.size() - 1); + for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) + __densities_.push_back(*__fW); + __init(); + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _RealType> +template<class _UnaryOperation> +piecewise_constant_distribution<_RealType>::param_type::param_type( + initializer_list<result_type> __bl, _UnaryOperation __fw) + : __b_(__bl.begin(), __bl.end()) +{ + if (__b_.size() < 2) + { + __b_.resize(2); + __b_[0] = 0; + __b_[1] = 1; + __densities_.assign(1, 1.0); + __areas_.assign(1, 0.0); + } + else + { + __densities_.reserve(__b_.size() - 1); + for (size_t __i = 0; __i < __b_.size() - 1; ++__i) + __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); + __init(); + } +} + +#endif // _LIBCPP_CXX03_LANG + +template<class _RealType> +template<class _UnaryOperation> +piecewise_constant_distribution<_RealType>::param_type::param_type( + size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) + : __b_(__nw == 0 ? 2 : __nw + 1) +{ + size_t __n = __b_.size() - 1; + result_type __d = (__xmax - __xmin) / __n; + __densities_.reserve(__n); + for (size_t __i = 0; __i < __n; ++__i) + { + __b_[__i] = __xmin + __i * __d; + __densities_.push_back(__fw(__b_[__i] + __d*.5)); + } + __b_[__n] = __xmax; + __init(); +} + +template<class _RealType> +template<class _URNG> +_RealType +piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + typedef uniform_real_distribution<result_type> _Gen; + result_type __u = _Gen()(__g); + ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), + __u) - __p.__areas_.begin() - 1; + return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_constant_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + size_t __n = __x.__p_.__b_.size(); + __os << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__b_[__i]; + __n = __x.__p_.__densities_.size(); + __os << __sp << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__densities_[__i]; + __n = __x.__p_.__areas_.size(); + __os << __sp << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__areas_[__i]; + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_constant_distribution<_RT>& __x) +{ + typedef piecewise_constant_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + size_t __n; + __is >> __n; + vector<result_type> __b(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __b[__i]; + __is >> __n; + vector<result_type> __densities(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __densities[__i]; + __is >> __n; + vector<result_type> __areas(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __areas[__i]; + if (!__is.fail()) + { + swap(__x.__p_.__b_, __b); + swap(__x.__p_.__densities_, __densities); + swap(__x.__p_.__areas_, __areas); + } + return __is; +} + +// piecewise_linear_distribution + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + vector<result_type> __b_; + vector<result_type> __densities_; + vector<result_type> __areas_; + public: + typedef piecewise_linear_distribution distribution_type; + + param_type(); + template<class _InputIteratorB, class _InputIteratorW> + param_type(_InputIteratorB __fB, _InputIteratorB __lB, + _InputIteratorW __fW); +#ifndef _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); +#endif // _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(size_t __nw, result_type __xmin, result_type __xmax, + _UnaryOperation __fw); + param_type & operator=(const param_type& __rhs); + + _LIBCPP_INLINE_VISIBILITY + vector<result_type> intervals() const {return __b_;} + _LIBCPP_INLINE_VISIBILITY + vector<result_type> densities() const {return __densities_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + private: + void __init(); + + friend class piecewise_linear_distribution; + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_linear_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_linear_distribution<_RT>& __x); + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + piecewise_linear_distribution() {} + template<class _InputIteratorB, class _InputIteratorW> + _LIBCPP_INLINE_VISIBILITY + piecewise_linear_distribution(_InputIteratorB __fB, + _InputIteratorB __lB, + _InputIteratorW __fW) + : __p_(__fB, __lB, __fW) {} + +#ifndef _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + piecewise_linear_distribution(initializer_list<result_type> __bl, + _UnaryOperation __fw) + : __p_(__bl, __fw) {} +#endif // _LIBCPP_CXX03_LANG + + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + piecewise_linear_distribution(size_t __nw, result_type __xmin, + result_type __xmax, _UnaryOperation __fw) + : __p_(__nw, __xmin, __xmax, __fw) {} + + _LIBCPP_INLINE_VISIBILITY + explicit piecewise_linear_distribution(const param_type& __p) + : __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + vector<result_type> intervals() const {return __p_.intervals();} + _LIBCPP_INLINE_VISIBILITY + vector<result_type> densities() const {return __p_.densities();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return __p_.__b_.front();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return __p_.__b_.back();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const piecewise_linear_distribution& __x, + const piecewise_linear_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const piecewise_linear_distribution& __x, + const piecewise_linear_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_linear_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_linear_distribution<_RT>& __x); +}; + +template<class _RealType> +typename piecewise_linear_distribution<_RealType>::param_type & +piecewise_linear_distribution<_RealType>::param_type::operator= + (const param_type& __rhs) +{ +// These can throw + __b_.reserve (__rhs.__b_.size ()); + __densities_.reserve(__rhs.__densities_.size()); + __areas_.reserve (__rhs.__areas_.size()); + +// These can not throw + __b_ = __rhs.__b_; + __densities_ = __rhs.__densities_; + __areas_ = __rhs.__areas_; + return *this; +} + + +template<class _RealType> +void +piecewise_linear_distribution<_RealType>::param_type::__init() +{ + __areas_.assign(__densities_.size() - 1, result_type()); + result_type _Sp = 0; + for (size_t __i = 0; __i < __areas_.size(); ++__i) + { + __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * + (__b_[__i+1] - __b_[__i]) * .5; + _Sp += __areas_[__i]; + } + for (size_t __i = __areas_.size(); __i > 1;) + { + --__i; + __areas_[__i] = __areas_[__i-1] / _Sp; + } + __areas_[0] = 0; + for (size_t __i = 1; __i < __areas_.size(); ++__i) + __areas_[__i] += __areas_[__i-1]; + for (size_t __i = 0; __i < __densities_.size(); ++__i) + __densities_[__i] /= _Sp; +} + +template<class _RealType> +piecewise_linear_distribution<_RealType>::param_type::param_type() + : __b_(2), + __densities_(2, 1.0), + __areas_(1, 0.0) +{ + __b_[1] = 1; +} + +template<class _RealType> +template<class _InputIteratorB, class _InputIteratorW> +piecewise_linear_distribution<_RealType>::param_type::param_type( + _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) + : __b_(__fB, __lB) +{ + if (__b_.size() < 2) + { + __b_.resize(2); + __b_[0] = 0; + __b_[1] = 1; + __densities_.assign(2, 1.0); + __areas_.assign(1, 0.0); + } + else + { + __densities_.reserve(__b_.size()); + for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) + __densities_.push_back(*__fW); + __init(); + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _RealType> +template<class _UnaryOperation> +piecewise_linear_distribution<_RealType>::param_type::param_type( + initializer_list<result_type> __bl, _UnaryOperation __fw) + : __b_(__bl.begin(), __bl.end()) +{ + if (__b_.size() < 2) + { + __b_.resize(2); + __b_[0] = 0; + __b_[1] = 1; + __densities_.assign(2, 1.0); + __areas_.assign(1, 0.0); + } + else + { + __densities_.reserve(__b_.size()); + for (size_t __i = 0; __i < __b_.size(); ++__i) + __densities_.push_back(__fw(__b_[__i])); + __init(); + } +} + +#endif // _LIBCPP_CXX03_LANG + +template<class _RealType> +template<class _UnaryOperation> +piecewise_linear_distribution<_RealType>::param_type::param_type( + size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) + : __b_(__nw == 0 ? 2 : __nw + 1) +{ + size_t __n = __b_.size() - 1; + result_type __d = (__xmax - __xmin) / __n; + __densities_.reserve(__b_.size()); + for (size_t __i = 0; __i < __n; ++__i) + { + __b_[__i] = __xmin + __i * __d; + __densities_.push_back(__fw(__b_[__i])); + } + __b_[__n] = __xmax; + __densities_.push_back(__fw(__b_[__n])); + __init(); +} + +template<class _RealType> +template<class _URNG> +_RealType +piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + typedef uniform_real_distribution<result_type> _Gen; + result_type __u = _Gen()(__g); + ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), + __u) - __p.__areas_.begin() - 1; + __u -= __p.__areas_[__k]; + const result_type __dk = __p.__densities_[__k]; + const result_type __dk1 = __p.__densities_[__k+1]; + const result_type __deltad = __dk1 - __dk; + const result_type __bk = __p.__b_[__k]; + if (__deltad == 0) + return __u / __dk + __bk; + const result_type __bk1 = __p.__b_[__k+1]; + const result_type __deltab = __bk1 - __bk; + return (__bk * __dk1 - __bk1 * __dk + + _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / + __deltad; +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_linear_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | + ios_base::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + size_t __n = __x.__p_.__b_.size(); + __os << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__b_[__i]; + __n = __x.__p_.__densities_.size(); + __os << __sp << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__densities_[__i]; + __n = __x.__p_.__areas_.size(); + __os << __sp << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__areas_[__i]; + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_linear_distribution<_RT>& __x) +{ + typedef piecewise_linear_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + __save_flags<_CharT, _Traits> __lx(__is); + __is.flags(ios_base::dec | ios_base::skipws); + size_t __n; + __is >> __n; + vector<result_type> __b(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __b[__i]; + __is >> __n; + vector<result_type> __densities(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __densities[__i]; + __is >> __n; + vector<result_type> __areas(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __areas[__i]; + if (!__is.fail()) + { + swap(__x.__p_.__b_, __b); + swap(__x.__p_.__densities_, __densities); + swap(__x.__p_.__areas_, __areas); + } + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_RANDOM diff --git a/android/x86/include/v8/libc++/ratio b/android/x86/include/v8/libc++/ratio new file mode 100755 index 00000000..fa7a4bbb --- /dev/null +++ b/android/x86/include/v8/libc++/ratio @@ -0,0 +1,532 @@ +// -*- C++ -*- +//===---------------------------- ratio -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_RATIO +#define _LIBCPP_RATIO + +/* + ratio synopsis + +namespace std +{ + +template <intmax_t N, intmax_t D = 1> +class ratio +{ +public: + static constexpr intmax_t num; + static constexpr intmax_t den; + typedef ratio<num, den> type; +}; + +// ratio arithmetic +template <class R1, class R2> using ratio_add = ...; +template <class R1, class R2> using ratio_subtract = ...; +template <class R1, class R2> using ratio_multiply = ...; +template <class R1, class R2> using ratio_divide = ...; + +// ratio comparison +template <class R1, class R2> struct ratio_equal; +template <class R1, class R2> struct ratio_not_equal; +template <class R1, class R2> struct ratio_less; +template <class R1, class R2> struct ratio_less_equal; +template <class R1, class R2> struct ratio_greater; +template <class R1, class R2> struct ratio_greater_equal; + +// convenience SI typedefs +typedef ratio<1, 1000000000000000000000000> yocto; // not supported +typedef ratio<1, 1000000000000000000000> zepto; // not supported +typedef ratio<1, 1000000000000000000> atto; +typedef ratio<1, 1000000000000000> femto; +typedef ratio<1, 1000000000000> pico; +typedef ratio<1, 1000000000> nano; +typedef ratio<1, 1000000> micro; +typedef ratio<1, 1000> milli; +typedef ratio<1, 100> centi; +typedef ratio<1, 10> deci; +typedef ratio< 10, 1> deca; +typedef ratio< 100, 1> hecto; +typedef ratio< 1000, 1> kilo; +typedef ratio< 1000000, 1> mega; +typedef ratio< 1000000000, 1> giga; +typedef ratio< 1000000000000, 1> tera; +typedef ratio< 1000000000000000, 1> peta; +typedef ratio< 1000000000000000000, 1> exa; +typedef ratio< 1000000000000000000000, 1> zetta; // not supported +typedef ratio<1000000000000000000000000, 1> yotta; // not supported + + // 20.11.5, ratio comparison + template <class R1, class R2> inline constexpr bool ratio_equal_v + = ratio_equal<R1, R2>::value; // C++17 + template <class R1, class R2> inline constexpr bool ratio_not_equal_v + = ratio_not_equal<R1, R2>::value; // C++17 + template <class R1, class R2> inline constexpr bool ratio_less_v + = ratio_less<R1, R2>::value; // C++17 + template <class R1, class R2> inline constexpr bool ratio_less_equal_v + = ratio_less_equal<R1, R2>::value; // C++17 + template <class R1, class R2> inline constexpr bool ratio_greater_v + = ratio_greater<R1, R2>::value; // C++17 + template <class R1, class R2> inline constexpr bool ratio_greater_equal_v + = ratio_greater_equal<R1, R2>::value; // C++17 +} +*/ + +#include <__config> +#include <cstdint> +#include <climits> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +// __static_gcd + +template <intmax_t _Xp, intmax_t _Yp> +struct __static_gcd +{ + static const intmax_t value = __static_gcd<_Yp, _Xp % _Yp>::value; +}; + +template <intmax_t _Xp> +struct __static_gcd<_Xp, 0> +{ + static const intmax_t value = _Xp; +}; + +template <> +struct __static_gcd<0, 0> +{ + static const intmax_t value = 1; +}; + +// __static_lcm + +template <intmax_t _Xp, intmax_t _Yp> +struct __static_lcm +{ + static const intmax_t value = _Xp / __static_gcd<_Xp, _Yp>::value * _Yp; +}; + +template <intmax_t _Xp> +struct __static_abs +{ + static const intmax_t value = _Xp < 0 ? -_Xp : _Xp; +}; + +template <intmax_t _Xp> +struct __static_sign +{ + static const intmax_t value = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1); +}; + +template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value> +class __ll_add; + +template <intmax_t _Xp, intmax_t _Yp> +class __ll_add<_Xp, _Yp, 1> +{ + static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; + static const intmax_t max = -min; + + static_assert(_Xp <= max - _Yp, "overflow in __ll_add"); +public: + static const intmax_t value = _Xp + _Yp; +}; + +template <intmax_t _Xp, intmax_t _Yp> +class __ll_add<_Xp, _Yp, 0> +{ +public: + static const intmax_t value = _Xp; +}; + +template <intmax_t _Xp, intmax_t _Yp> +class __ll_add<_Xp, _Yp, -1> +{ + static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; + static const intmax_t max = -min; + + static_assert(min - _Yp <= _Xp, "overflow in __ll_add"); +public: + static const intmax_t value = _Xp + _Yp; +}; + +template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value> +class __ll_sub; + +template <intmax_t _Xp, intmax_t _Yp> +class __ll_sub<_Xp, _Yp, 1> +{ + static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; + static const intmax_t max = -min; + + static_assert(min + _Yp <= _Xp, "overflow in __ll_sub"); +public: + static const intmax_t value = _Xp - _Yp; +}; + +template <intmax_t _Xp, intmax_t _Yp> +class __ll_sub<_Xp, _Yp, 0> +{ +public: + static const intmax_t value = _Xp; +}; + +template <intmax_t _Xp, intmax_t _Yp> +class __ll_sub<_Xp, _Yp, -1> +{ + static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; + static const intmax_t max = -min; + + static_assert(_Xp <= max + _Yp, "overflow in __ll_sub"); +public: + static const intmax_t value = _Xp - _Yp; +}; + +template <intmax_t _Xp, intmax_t _Yp> +class __ll_mul +{ + static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)); + static const intmax_t min = nan + 1; + static const intmax_t max = -min; + static const intmax_t __a_x = __static_abs<_Xp>::value; + static const intmax_t __a_y = __static_abs<_Yp>::value; + + static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul"); +public: + static const intmax_t value = _Xp * _Yp; +}; + +template <intmax_t _Yp> +class __ll_mul<0, _Yp> +{ +public: + static const intmax_t value = 0; +}; + +template <intmax_t _Xp> +class __ll_mul<_Xp, 0> +{ +public: + static const intmax_t value = 0; +}; + +template <> +class __ll_mul<0, 0> +{ +public: + static const intmax_t value = 0; +}; + +// Not actually used but left here in case needed in future maintenance +template <intmax_t _Xp, intmax_t _Yp> +class __ll_div +{ + static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)); + static const intmax_t min = nan + 1; + static const intmax_t max = -min; + + static_assert(_Xp != nan && _Yp != nan && _Yp != 0, "overflow in __ll_div"); +public: + static const intmax_t value = _Xp / _Yp; +}; + +template <intmax_t _Num, intmax_t _Den = 1> +class _LIBCPP_TEMPLATE_VIS ratio +{ + static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range"); + static_assert(_Den != 0, "ratio divide by 0"); + static_assert(__static_abs<_Den>::value > 0, "ratio denominator is out of range"); + static _LIBCPP_CONSTEXPR const intmax_t __na = __static_abs<_Num>::value; + static _LIBCPP_CONSTEXPR const intmax_t __da = __static_abs<_Den>::value; + static _LIBCPP_CONSTEXPR const intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value; + static _LIBCPP_CONSTEXPR const intmax_t __gcd = __static_gcd<__na, __da>::value; +public: + static _LIBCPP_CONSTEXPR const intmax_t num = __s * __na / __gcd; + static _LIBCPP_CONSTEXPR const intmax_t den = __da / __gcd; + + typedef ratio<num, den> type; +}; + +template <intmax_t _Num, intmax_t _Den> +_LIBCPP_CONSTEXPR const intmax_t ratio<_Num, _Den>::num; + +template <intmax_t _Num, intmax_t _Den> +_LIBCPP_CONSTEXPR const intmax_t ratio<_Num, _Den>::den; + +template <class _Tp> struct __is_ratio : false_type {}; +template <intmax_t _Num, intmax_t _Den> struct __is_ratio<ratio<_Num, _Den> > : true_type {}; + +typedef ratio<1LL, 1000000000000000000LL> atto; +typedef ratio<1LL, 1000000000000000LL> femto; +typedef ratio<1LL, 1000000000000LL> pico; +typedef ratio<1LL, 1000000000LL> nano; +typedef ratio<1LL, 1000000LL> micro; +typedef ratio<1LL, 1000LL> milli; +typedef ratio<1LL, 100LL> centi; +typedef ratio<1LL, 10LL> deci; +typedef ratio< 10LL, 1LL> deca; +typedef ratio< 100LL, 1LL> hecto; +typedef ratio< 1000LL, 1LL> kilo; +typedef ratio< 1000000LL, 1LL> mega; +typedef ratio< 1000000000LL, 1LL> giga; +typedef ratio< 1000000000000LL, 1LL> tera; +typedef ratio< 1000000000000000LL, 1LL> peta; +typedef ratio<1000000000000000000LL, 1LL> exa; + +template <class _R1, class _R2> +struct __ratio_multiply +{ +private: + static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>::value; + static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>::value; +public: + typedef typename ratio + < + __ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value, + __ll_mul<_R2::den / __gcd_n1_d2, _R1::den / __gcd_d1_n2>::value + >::type type; +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> using ratio_multiply + = typename __ratio_multiply<_R1, _R2>::type; + +#else // _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_multiply + : public __ratio_multiply<_R1, _R2>::type {}; + +#endif // _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> +struct __ratio_divide +{ +private: + static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; + static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; +public: + typedef typename ratio + < + __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, + __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value + >::type type; +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> using ratio_divide + = typename __ratio_divide<_R1, _R2>::type; + +#else // _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_divide + : public __ratio_divide<_R1, _R2>::type {}; + +#endif // _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> +struct __ratio_add +{ +private: + static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; + static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; +public: + typedef typename ratio_multiply + < + ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>, + ratio + < + __ll_add + < + __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, + __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value + >::value, + _R2::den + > + >::type type; +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> using ratio_add + = typename __ratio_add<_R1, _R2>::type; + +#else // _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_add + : public __ratio_add<_R1, _R2>::type {}; + +#endif // _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> +struct __ratio_subtract +{ +private: + static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; + static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; +public: + typedef typename ratio_multiply + < + ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>, + ratio + < + __ll_sub + < + __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, + __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value + >::value, + _R2::den + > + >::type type; +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> using ratio_subtract + = typename __ratio_subtract<_R1, _R2>::type; + +#else // _LIBCPP_CXX03_LANG + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_subtract + : public __ratio_subtract<_R1, _R2>::type {}; + +#endif // _LIBCPP_CXX03_LANG + +// ratio_equal + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_equal + : public _LIBCPP_BOOL_CONSTANT((_R1::num == _R2::num && _R1::den == _R2::den)) {}; + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_not_equal + : public _LIBCPP_BOOL_CONSTANT((!ratio_equal<_R1, _R2>::value)) {}; + +// ratio_less + +template <class _R1, class _R2, bool _Odd = false, + intmax_t _Q1 = _R1::num / _R1::den, intmax_t _M1 = _R1::num % _R1::den, + intmax_t _Q2 = _R2::num / _R2::den, intmax_t _M2 = _R2::num % _R2::den> +struct __ratio_less1 +{ + static const bool value = _Odd ? _Q2 < _Q1 : _Q1 < _Q2; +}; + +template <class _R1, class _R2, bool _Odd, intmax_t _Qp> +struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, 0> +{ + static const bool value = false; +}; + +template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M2> +struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, _M2> +{ + static const bool value = !_Odd; +}; + +template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1> +struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, 0> +{ + static const bool value = _Odd; +}; + +template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1, + intmax_t _M2> +struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, _M2> +{ + static const bool value = __ratio_less1<ratio<_R1::den, _M1>, + ratio<_R2::den, _M2>, !_Odd>::value; +}; + +template <class _R1, class _R2, intmax_t _S1 = __static_sign<_R1::num>::value, + intmax_t _S2 = __static_sign<_R2::num>::value> +struct __ratio_less +{ + static const bool value = _S1 < _S2; +}; + +template <class _R1, class _R2> +struct __ratio_less<_R1, _R2, 1LL, 1LL> +{ + static const bool value = __ratio_less1<_R1, _R2>::value; +}; + +template <class _R1, class _R2> +struct __ratio_less<_R1, _R2, -1LL, -1LL> +{ + static const bool value = __ratio_less1<ratio<-_R2::num, _R2::den>, ratio<-_R1::num, _R1::den> >::value; +}; + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_less + : public _LIBCPP_BOOL_CONSTANT((__ratio_less<_R1, _R2>::value)) {}; + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_less_equal + : public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R2, _R1>::value)) {}; + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_greater + : public _LIBCPP_BOOL_CONSTANT((ratio_less<_R2, _R1>::value)) {}; + +template <class _R1, class _R2> +struct _LIBCPP_TEMPLATE_VIS ratio_greater_equal + : public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R1, _R2>::value)) {}; + +template <class _R1, class _R2> +struct __ratio_gcd +{ + typedef ratio<__static_gcd<_R1::num, _R2::num>::value, + __static_lcm<_R1::den, _R2::den>::value> type; +}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_equal_v + = ratio_equal<_R1, _R2>::value; + +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_not_equal_v + = ratio_not_equal<_R1, _R2>::value; + +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_v + = ratio_less<_R1, _R2>::value; + +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_equal_v + = ratio_less_equal<_R1, _R2>::value; + +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_v + = ratio_greater<_R1, _R2>::value; + +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_equal_v + = ratio_greater_equal<_R1, _R2>::value; +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_RATIO diff --git a/android/x86/include/v8/libc++/regex b/android/x86/include/v8/libc++/regex new file mode 100755 index 00000000..b9aa9d63 --- /dev/null +++ b/android/x86/include/v8/libc++/regex @@ -0,0 +1,6650 @@ +// -*- C++ -*- +//===--------------------------- regex ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_REGEX +#define _LIBCPP_REGEX + +/* + regex synopsis + +#include <initializer_list> + +namespace std +{ + +namespace regex_constants +{ + +emum syntax_option_type +{ + icase = unspecified, + nosubs = unspecified, + optimize = unspecified, + collate = unspecified, + ECMAScript = unspecified, + basic = unspecified, + extended = unspecified, + awk = unspecified, + grep = unspecified, + egrep = unspecified +}; + +constexpr syntax_option_type operator~(syntax_option_type f); +constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs); +constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs); + +enum match_flag_type +{ + match_default = 0, + match_not_bol = unspecified, + match_not_eol = unspecified, + match_not_bow = unspecified, + match_not_eow = unspecified, + match_any = unspecified, + match_not_null = unspecified, + match_continuous = unspecified, + match_prev_avail = unspecified, + format_default = 0, + format_sed = unspecified, + format_no_copy = unspecified, + format_first_only = unspecified +}; + +constexpr match_flag_type operator~(match_flag_type f); +constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs); +constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs); + +enum error_type +{ + error_collate = unspecified, + error_ctype = unspecified, + error_escape = unspecified, + error_backref = unspecified, + error_brack = unspecified, + error_paren = unspecified, + error_brace = unspecified, + error_badbrace = unspecified, + error_range = unspecified, + error_space = unspecified, + error_badrepeat = unspecified, + error_complexity = unspecified, + error_stack = unspecified +}; + +} // regex_constants + +class regex_error + : public runtime_error +{ +public: + explicit regex_error(regex_constants::error_type ecode); + regex_constants::error_type code() const; +}; + +template <class charT> +struct regex_traits +{ +public: + typedef charT char_type; + typedef basic_string<char_type> string_type; + typedef locale locale_type; + typedef /bitmask_type/ char_class_type; + + regex_traits(); + + static size_t length(const char_type* p); + charT translate(charT c) const; + charT translate_nocase(charT c) const; + template <class ForwardIterator> + string_type + transform(ForwardIterator first, ForwardIterator last) const; + template <class ForwardIterator> + string_type + transform_primary( ForwardIterator first, ForwardIterator last) const; + template <class ForwardIterator> + string_type + lookup_collatename(ForwardIterator first, ForwardIterator last) const; + template <class ForwardIterator> + char_class_type + lookup_classname(ForwardIterator first, ForwardIterator last, + bool icase = false) const; + bool isctype(charT c, char_class_type f) const; + int value(charT ch, int radix) const; + locale_type imbue(locale_type l); + locale_type getloc()const; +}; + +template <class charT, class traits = regex_traits<charT>> +class basic_regex +{ +public: + // types: + typedef charT value_type; + typedef traits traits_type; + typedef typename traits::string_type string_type; + typedef regex_constants::syntax_option_type flag_type; + typedef typename traits::locale_type locale_type; + + // constants: + static constexpr regex_constants::syntax_option_type icase = regex_constants::icase; + static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs; + static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize; + static constexpr regex_constants::syntax_option_type collate = regex_constants::collate; + static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; + static constexpr regex_constants::syntax_option_type basic = regex_constants::basic; + static constexpr regex_constants::syntax_option_type extended = regex_constants::extended; + static constexpr regex_constants::syntax_option_type awk = regex_constants::awk; + static constexpr regex_constants::syntax_option_type grep = regex_constants::grep; + static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep; + + // construct/copy/destroy: + basic_regex(); + explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript); + basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript); + basic_regex(const basic_regex&); + basic_regex(basic_regex&&) noexcept; + template <class ST, class SA> + explicit basic_regex(const basic_string<charT, ST, SA>& p, + flag_type f = regex_constants::ECMAScript); + template <class ForwardIterator> + basic_regex(ForwardIterator first, ForwardIterator last, + flag_type f = regex_constants::ECMAScript); + basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript); + + ~basic_regex(); + + basic_regex& operator=(const basic_regex&); + basic_regex& operator=(basic_regex&&) noexcept; + basic_regex& operator=(const charT* ptr); + basic_regex& operator=(initializer_list<charT> il); + template <class ST, class SA> + basic_regex& operator=(const basic_string<charT, ST, SA>& p); + + // assign: + basic_regex& assign(const basic_regex& that); + basic_regex& assign(basic_regex&& that) noexcept; + basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript); + basic_regex& assign(const charT* p, size_t len, flag_type f); + template <class string_traits, class A> + basic_regex& assign(const basic_string<charT, string_traits, A>& s, + flag_type f = regex_constants::ECMAScript); + template <class InputIterator> + basic_regex& assign(InputIterator first, InputIterator last, + flag_type f = regex_constants::ECMAScript); + basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript); + + // const operations: + unsigned mark_count() const; + flag_type flags() const; + + // locale: + locale_type imbue(locale_type loc); + locale_type getloc() const; + + // swap: + void swap(basic_regex&); +}; + +template<class ForwardIterator> +basic_regex(ForwardIterator, ForwardIterator, + regex_constants::syntax_option_type = regex_constants::ECMAScript) + -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17 + +typedef basic_regex<char> regex; +typedef basic_regex<wchar_t> wregex; + +template <class charT, class traits> + void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2); + +template <class BidirectionalIterator> +class sub_match + : public pair<BidirectionalIterator, BidirectionalIterator> +{ +public: + typedef typename iterator_traits<BidirectionalIterator>::value_type value_type; + typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; + typedef BidirectionalIterator iterator; + typedef basic_string<value_type> string_type; + + bool matched; + + constexpr sub_match(); + + difference_type length() const; + operator string_type() const; + string_type str() const; + + int compare(const sub_match& s) const; + int compare(const string_type& s) const; + int compare(const value_type* s) const; +}; + +typedef sub_match<const char*> csub_match; +typedef sub_match<const wchar_t*> wcsub_match; +typedef sub_match<string::const_iterator> ssub_match; +typedef sub_match<wstring::const_iterator> wssub_match; + +template <class BiIter> + bool + operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter, class ST, class SA> + bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator==(const sub_match<BiIter>& lhs, + const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator!=(const sub_match<BiIter>& lhs, + const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator<(const sub_match<BiIter>& lhs, + const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); + +template <class BiIter, class ST, class SA> + bool operator>(const sub_match<BiIter>& lhs, + const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator>=(const sub_match<BiIter>& lhs, + const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); + +template <class BiIter, class ST, class SA> + bool + operator<=(const sub_match<BiIter>& lhs, + const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); + +template <class BiIter> + bool + operator==(typename iterator_traits<BiIter>::value_type const* lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator!=(typename iterator_traits<BiIter>::value_type const* lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator<(typename iterator_traits<BiIter>::value_type const* lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator>(typename iterator_traits<BiIter>::value_type const* lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator>=(typename iterator_traits<BiIter>::value_type const* lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator<=(typename iterator_traits<BiIter>::value_type const* lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator==(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const* rhs); + +template <class BiIter> + bool + operator!=(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const* rhs); + +template <class BiIter> + bool + operator<(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const* rhs); + +template <class BiIter> + bool + operator>(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const* rhs); + +template <class BiIter> + bool + operator>=(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const* rhs); + +template <class BiIter> + bool + operator<=(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const* rhs); + +template <class BiIter> + bool + operator==(typename iterator_traits<BiIter>::value_type const& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator!=(typename iterator_traits<BiIter>::value_type const& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator<(typename iterator_traits<BiIter>::value_type const& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator>(typename iterator_traits<BiIter>::value_type const& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator>=(typename iterator_traits<BiIter>::value_type const& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator<=(typename iterator_traits<BiIter>::value_type const& lhs, + const sub_match<BiIter>& rhs); + +template <class BiIter> + bool + operator==(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const& rhs); + +template <class BiIter> + bool + operator!=(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const& rhs); + +template <class BiIter> + bool + operator<(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const& rhs); + +template <class BiIter> + bool + operator>(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const& rhs); + +template <class BiIter> + bool + operator>=(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const& rhs); + +template <class BiIter> + bool + operator<=(const sub_match<BiIter>& lhs, + typename iterator_traits<BiIter>::value_type const& rhs); + +template <class charT, class ST, class BiIter> + basic_ostream<charT, ST>& + operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m); + +template <class BidirectionalIterator, + class Allocator = allocator<sub_match<BidirectionalIterator>>> +class match_results +{ +public: + typedef sub_match<BidirectionalIterator> value_type; + typedef const value_type& const_reference; + typedef value_type& reference; + typedef /implementation-defined/ const_iterator; + typedef const_iterator iterator; + typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; + typedef typename allocator_traits<Allocator>::size_type size_type; + typedef Allocator allocator_type; + typedef typename iterator_traits<BidirectionalIterator>::value_type char_type; + typedef basic_string<char_type> string_type; + + // construct/copy/destroy: + explicit match_results(const Allocator& a = Allocator()); + match_results(const match_results& m); + match_results(match_results&& m) noexcept; + match_results& operator=(const match_results& m); + match_results& operator=(match_results&& m); + ~match_results(); + + bool ready() const; + + // size: + size_type size() const; + size_type max_size() const; + bool empty() const; + + // element access: + difference_type length(size_type sub = 0) const; + difference_type position(size_type sub = 0) const; + string_type str(size_type sub = 0) const; + const_reference operator[](size_type n) const; + + const_reference prefix() const; + const_reference suffix() const; + + const_iterator begin() const; + const_iterator end() const; + const_iterator cbegin() const; + const_iterator cend() const; + + // format: + template <class OutputIter> + OutputIter + format(OutputIter out, const char_type* fmt_first, + const char_type* fmt_last, + regex_constants::match_flag_type flags = regex_constants::format_default) const; + template <class OutputIter, class ST, class SA> + OutputIter + format(OutputIter out, const basic_string<char_type, ST, SA>& fmt, + regex_constants::match_flag_type flags = regex_constants::format_default) const; + template <class ST, class SA> + basic_string<char_type, ST, SA> + format(const basic_string<char_type, ST, SA>& fmt, + regex_constants::match_flag_type flags = regex_constants::format_default) const; + string_type + format(const char_type* fmt, + regex_constants::match_flag_type flags = regex_constants::format_default) const; + + // allocator: + allocator_type get_allocator() const; + + // swap: + void swap(match_results& that); +}; + +typedef match_results<const char*> cmatch; +typedef match_results<const wchar_t*> wcmatch; +typedef match_results<string::const_iterator> smatch; +typedef match_results<wstring::const_iterator> wsmatch; + +template <class BidirectionalIterator, class Allocator> + bool + operator==(const match_results<BidirectionalIterator, Allocator>& m1, + const match_results<BidirectionalIterator, Allocator>& m2); + +template <class BidirectionalIterator, class Allocator> + bool + operator!=(const match_results<BidirectionalIterator, Allocator>& m1, + const match_results<BidirectionalIterator, Allocator>& m2); + +template <class BidirectionalIterator, class Allocator> + void + swap(match_results<BidirectionalIterator, Allocator>& m1, + match_results<BidirectionalIterator, Allocator>& m2); + +template <class BidirectionalIterator, class Allocator, class charT, class traits> + bool + regex_match(BidirectionalIterator first, BidirectionalIterator last, + match_results<BidirectionalIterator, Allocator>& m, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class BidirectionalIterator, class charT, class traits> + bool + regex_match(BidirectionalIterator first, BidirectionalIterator last, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class charT, class Allocator, class traits> + bool + regex_match(const charT* str, match_results<const charT*, Allocator>& m, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class ST, class SA, class Allocator, class charT, class traits> + bool + regex_match(const basic_string<charT, ST, SA>& s, + match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class ST, class SA, class Allocator, class charT, class traits> + bool + regex_match(const basic_string<charT, ST, SA>&& s, + match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 + +template <class charT, class traits> + bool + regex_match(const charT* str, const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class ST, class SA, class charT, class traits> + bool + regex_match(const basic_string<charT, ST, SA>& s, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class BidirectionalIterator, class Allocator, class charT, class traits> + bool + regex_search(BidirectionalIterator first, BidirectionalIterator last, + match_results<BidirectionalIterator, Allocator>& m, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class BidirectionalIterator, class charT, class traits> + bool + regex_search(BidirectionalIterator first, BidirectionalIterator last, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class charT, class Allocator, class traits> + bool + regex_search(const charT* str, match_results<const charT*, Allocator>& m, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class charT, class traits> + bool + regex_search(const charT* str, const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class ST, class SA, class charT, class traits> + bool + regex_search(const basic_string<charT, ST, SA>& s, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class ST, class SA, class Allocator, class charT, class traits> + bool + regex_search(const basic_string<charT, ST, SA>& s, + match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class ST, class SA, class Allocator, class charT, class traits> + bool + regex_search(const basic_string<charT, ST, SA>&& s, + match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, + const basic_regex<charT, traits>& e, + regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 + +template <class OutputIterator, class BidirectionalIterator, + class traits, class charT, class ST, class SA> + OutputIterator + regex_replace(OutputIterator out, + BidirectionalIterator first, BidirectionalIterator last, + const basic_regex<charT, traits>& e, + const basic_string<charT, ST, SA>& fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class OutputIterator, class BidirectionalIterator, + class traits, class charT> + OutputIterator + regex_replace(OutputIterator out, + BidirectionalIterator first, BidirectionalIterator last, + const basic_regex<charT, traits>& e, const charT* fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class traits, class charT, class ST, class SA, class FST, class FSA>> + basic_string<charT, ST, SA> + regex_replace(const basic_string<charT, ST, SA>& s, + const basic_regex<charT, traits>& e, + const basic_string<charT, FST, FSA>& fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class traits, class charT, class ST, class SA> + basic_string<charT, ST, SA> + regex_replace(const basic_string<charT, ST, SA>& s, + const basic_regex<charT, traits>& e, const charT* fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class traits, class charT, class ST, class SA> + basic_string<charT> + regex_replace(const charT* s, + const basic_regex<charT, traits>& e, + const basic_string<charT, ST, SA>& fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class traits, class charT> + basic_string<charT> + regex_replace(const charT* s, + const basic_regex<charT, traits>& e, + const charT* fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template <class BidirectionalIterator, + class charT = typename iterator_traits< BidirectionalIterator>::value_type, + class traits = regex_traits<charT>> +class regex_iterator +{ +public: + typedef basic_regex<charT, traits> regex_type; + typedef match_results<BidirectionalIterator> value_type; + typedef ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; + typedef forward_iterator_tag iterator_category; + + regex_iterator(); + regex_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, + regex_constants::match_flag_type m = regex_constants::match_default); + regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type&& __re, + regex_constants::match_flag_type __m + = regex_constants::match_default) = delete; // C++14 + regex_iterator(const regex_iterator&); + regex_iterator& operator=(const regex_iterator&); + + bool operator==(const regex_iterator&) const; + bool operator!=(const regex_iterator&) const; + + const value_type& operator*() const; + const value_type* operator->() const; + + regex_iterator& operator++(); + regex_iterator operator++(int); +}; + +typedef regex_iterator<const char*> cregex_iterator; +typedef regex_iterator<const wchar_t*> wcregex_iterator; +typedef regex_iterator<string::const_iterator> sregex_iterator; +typedef regex_iterator<wstring::const_iterator> wsregex_iterator; + +template <class BidirectionalIterator, + class charT = typename iterator_traits< BidirectionalIterator>::value_type, + class traits = regex_traits<charT>> +class regex_token_iterator +{ +public: + typedef basic_regex<charT, traits> regex_type; + typedef sub_match<BidirectionalIterator> value_type; + typedef ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; + typedef forward_iterator_tag iterator_category; + + regex_token_iterator(); + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, int submatch = 0, + regex_constants::match_flag_type m = regex_constants::match_default); + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type&& re, int submatch = 0, + regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, const vector<int>& submatches, + regex_constants::match_flag_type m = regex_constants::match_default); + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type&& re, const vector<int>& submatches, + regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, initializer_list<int> submatches, + regex_constants::match_flag_type m = regex_constants::match_default); + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type&& re, initializer_list<int> submatches, + regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 + template <size_t N> + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, const int (&submatches)[N], + regex_constants::match_flag_type m = regex_constants::match_default); + template <size_t N> + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, const int (&submatches)[N], + regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14; + regex_token_iterator(const regex_token_iterator&); + regex_token_iterator& operator=(const regex_token_iterator&); + + bool operator==(const regex_token_iterator&) const; + bool operator!=(const regex_token_iterator&) const; + + const value_type& operator*() const; + const value_type* operator->() const; + + regex_token_iterator& operator++(); + regex_token_iterator operator++(int); +}; + +typedef regex_token_iterator<const char*> cregex_token_iterator; +typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; +typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; +typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; + +} // std +*/ + +#include <__config> +#include <stdexcept> +#include <__locale> +#include <initializer_list> +#include <utility> +#include <iterator> +#include <string> +#include <memory> +#include <vector> +#include <deque> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +#define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace regex_constants +{ + +// syntax_option_type + +enum syntax_option_type +{ + icase = 1 << 0, + nosubs = 1 << 1, + optimize = 1 << 2, + collate = 1 << 3, +#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO + ECMAScript = 1 << 9, +#else + ECMAScript = 0, +#endif + basic = 1 << 4, + extended = 1 << 5, + awk = 1 << 6, + grep = 1 << 7, + egrep = 1 << 8 +}; + +inline _LIBCPP_CONSTEXPR +syntax_option_type __get_grammar(syntax_option_type __g) +{ +#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO + return static_cast<syntax_option_type>(__g & 0x3F0); +#else + return static_cast<syntax_option_type>(__g & 0x1F0); +#endif +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +syntax_option_type +operator~(syntax_option_type __x) +{ + return syntax_option_type(~int(__x) & 0x1FF); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +syntax_option_type +operator&(syntax_option_type __x, syntax_option_type __y) +{ + return syntax_option_type(int(__x) & int(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +syntax_option_type +operator|(syntax_option_type __x, syntax_option_type __y) +{ + return syntax_option_type(int(__x) | int(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +syntax_option_type +operator^(syntax_option_type __x, syntax_option_type __y) +{ + return syntax_option_type(int(__x) ^ int(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +syntax_option_type& +operator&=(syntax_option_type& __x, syntax_option_type __y) +{ + __x = __x & __y; + return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +syntax_option_type& +operator|=(syntax_option_type& __x, syntax_option_type __y) +{ + __x = __x | __y; + return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +syntax_option_type& +operator^=(syntax_option_type& __x, syntax_option_type __y) +{ + __x = __x ^ __y; + return __x; +} + +// match_flag_type + +enum match_flag_type +{ + match_default = 0, + match_not_bol = 1 << 0, + match_not_eol = 1 << 1, + match_not_bow = 1 << 2, + match_not_eow = 1 << 3, + match_any = 1 << 4, + match_not_null = 1 << 5, + match_continuous = 1 << 6, + match_prev_avail = 1 << 7, + format_default = 0, + format_sed = 1 << 8, + format_no_copy = 1 << 9, + format_first_only = 1 << 10, + __no_update_pos = 1 << 11, + __full_match = 1 << 12 +}; + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +match_flag_type +operator~(match_flag_type __x) +{ + return match_flag_type(~int(__x) & 0x0FFF); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +match_flag_type +operator&(match_flag_type __x, match_flag_type __y) +{ + return match_flag_type(int(__x) & int(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +match_flag_type +operator|(match_flag_type __x, match_flag_type __y) +{ + return match_flag_type(int(__x) | int(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +match_flag_type +operator^(match_flag_type __x, match_flag_type __y) +{ + return match_flag_type(int(__x) ^ int(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +match_flag_type& +operator&=(match_flag_type& __x, match_flag_type __y) +{ + __x = __x & __y; + return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +match_flag_type& +operator|=(match_flag_type& __x, match_flag_type __y) +{ + __x = __x | __y; + return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +match_flag_type& +operator^=(match_flag_type& __x, match_flag_type __y) +{ + __x = __x ^ __y; + return __x; +} + +enum error_type +{ + error_collate = 1, + error_ctype, + error_escape, + error_backref, + error_brack, + error_paren, + error_brace, + error_badbrace, + error_range, + error_space, + error_badrepeat, + error_complexity, + error_stack, + __re_err_grammar, + __re_err_empty, + __re_err_unknown +}; + +} // regex_constants + +class _LIBCPP_EXCEPTION_ABI regex_error + : public runtime_error +{ + regex_constants::error_type __code_; +public: + explicit regex_error(regex_constants::error_type __ecode); + virtual ~regex_error() throw(); + _LIBCPP_INLINE_VISIBILITY + regex_constants::error_type code() const {return __code_;} +}; + +template <regex_constants::error_type _Ev> +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_regex_error() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw regex_error(_Ev); +#else + _VSTD::abort(); +#endif +} + +template <class _CharT> +struct _LIBCPP_TEMPLATE_VIS regex_traits +{ +public: + typedef _CharT char_type; + typedef basic_string<char_type> string_type; + typedef locale locale_type; + typedef ctype_base::mask char_class_type; + +#if defined(__mips__) && defined(__GLIBC__) + static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15)); +#elif defined(__NetBSD__) + // NetBSD defines classes up to 0x2000 + // see sys/ctype_bits.h, _CTYPE_Q + static const char_class_type __regex_word = 0x8000; +#else + static const char_class_type __regex_word = 0x80; +#endif + +private: + locale __loc_; + const ctype<char_type>* __ct_; + const collate<char_type>* __col_; + +public: + regex_traits(); + + _LIBCPP_INLINE_VISIBILITY + static size_t length(const char_type* __p) + {return char_traits<char_type>::length(__p);} + _LIBCPP_INLINE_VISIBILITY + char_type translate(char_type __c) const {return __c;} + char_type translate_nocase(char_type __c) const; + template <class _ForwardIterator> + string_type + transform(_ForwardIterator __f, _ForwardIterator __l) const; + template <class _ForwardIterator> + _LIBCPP_INLINE_VISIBILITY + string_type + transform_primary( _ForwardIterator __f, _ForwardIterator __l) const + {return __transform_primary(__f, __l, char_type());} + template <class _ForwardIterator> + _LIBCPP_INLINE_VISIBILITY + string_type + lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const + {return __lookup_collatename(__f, __l, char_type());} + template <class _ForwardIterator> + _LIBCPP_INLINE_VISIBILITY + char_class_type + lookup_classname(_ForwardIterator __f, _ForwardIterator __l, + bool __icase = false) const + {return __lookup_classname(__f, __l, __icase, char_type());} + bool isctype(char_type __c, char_class_type __m) const; + _LIBCPP_INLINE_VISIBILITY + int value(char_type __ch, int __radix) const + {return __regex_traits_value(__ch, __radix);} + locale_type imbue(locale_type __l); + _LIBCPP_INLINE_VISIBILITY + locale_type getloc()const {return __loc_;} + +private: + void __init(); + + template <class _ForwardIterator> + string_type + __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; + template <class _ForwardIterator> + string_type + __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; + + template <class _ForwardIterator> + string_type + __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; + template <class _ForwardIterator> + string_type + __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; + + template <class _ForwardIterator> + char_class_type + __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, + bool __icase, char) const; + template <class _ForwardIterator> + char_class_type + __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, + bool __icase, wchar_t) const; + + static int __regex_traits_value(unsigned char __ch, int __radix); + _LIBCPP_INLINE_VISIBILITY + int __regex_traits_value(char __ch, int __radix) const + {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);} + _LIBCPP_INLINE_VISIBILITY + int __regex_traits_value(wchar_t __ch, int __radix) const; +}; + +template <class _CharT> +const typename regex_traits<_CharT>::char_class_type +regex_traits<_CharT>::__regex_word; + +template <class _CharT> +regex_traits<_CharT>::regex_traits() +{ + __init(); +} + +template <class _CharT> +typename regex_traits<_CharT>::char_type +regex_traits<_CharT>::translate_nocase(char_type __c) const +{ + return __ct_->tolower(__c); +} + +template <class _CharT> +template <class _ForwardIterator> +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const +{ + string_type __s(__f, __l); + return __col_->transform(__s.data(), __s.data() + __s.size()); +} + +template <class _CharT> +void +regex_traits<_CharT>::__init() +{ + __ct_ = &use_facet<ctype<char_type> >(__loc_); + __col_ = &use_facet<collate<char_type> >(__loc_); +} + +template <class _CharT> +typename regex_traits<_CharT>::locale_type +regex_traits<_CharT>::imbue(locale_type __l) +{ + locale __r = __loc_; + __loc_ = __l; + __init(); + return __r; +} + +// transform_primary is very FreeBSD-specific + +template <class _CharT> +template <class _ForwardIterator> +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, + _ForwardIterator __l, char) const +{ + const string_type __s(__f, __l); + string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); + switch (__d.size()) + { + case 1: + break; + case 12: + __d[11] = __d[3]; + break; + default: + __d.clear(); + break; + } + return __d; +} + +template <class _CharT> +template <class _ForwardIterator> +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, + _ForwardIterator __l, wchar_t) const +{ + const string_type __s(__f, __l); + string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); + switch (__d.size()) + { + case 1: + break; + case 3: + __d[2] = __d[0]; + break; + default: + __d.clear(); + break; + } + return __d; +} + +// lookup_collatename is very FreeBSD-specific + +_LIBCPP_FUNC_VIS string __get_collation_name(const char* __s); + +template <class _CharT> +template <class _ForwardIterator> +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, + _ForwardIterator __l, char) const +{ + string_type __s(__f, __l); + string_type __r; + if (!__s.empty()) + { + __r = __get_collation_name(__s.c_str()); + if (__r.empty() && __s.size() <= 2) + { + __r = __col_->transform(__s.data(), __s.data() + __s.size()); + if (__r.size() == 1 || __r.size() == 12) + __r = __s; + else + __r.clear(); + } + } + return __r; +} + +template <class _CharT> +template <class _ForwardIterator> +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, + _ForwardIterator __l, wchar_t) const +{ + string_type __s(__f, __l); + string __n; + __n.reserve(__s.size()); + for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); + __i != __e; ++__i) + { + if (static_cast<unsigned>(*__i) >= 127) + return string_type(); + __n.push_back(char(*__i)); + } + string_type __r; + if (!__s.empty()) + { + __n = __get_collation_name(__n.c_str()); + if (!__n.empty()) + __r.assign(__n.begin(), __n.end()); + else if (__s.size() <= 2) + { + __r = __col_->transform(__s.data(), __s.data() + __s.size()); + if (__r.size() == 1 || __r.size() == 3) + __r = __s; + else + __r.clear(); + } + } + return __r; +} + +// lookup_classname + +regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS +__get_classname(const char* __s, bool __icase); + +template <class _CharT> +template <class _ForwardIterator> +typename regex_traits<_CharT>::char_class_type +regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, + _ForwardIterator __l, + bool __icase, char) const +{ + string_type __s(__f, __l); + __ct_->tolower(&__s[0], &__s[0] + __s.size()); + return __get_classname(__s.c_str(), __icase); +} + +template <class _CharT> +template <class _ForwardIterator> +typename regex_traits<_CharT>::char_class_type +regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, + _ForwardIterator __l, + bool __icase, wchar_t) const +{ + string_type __s(__f, __l); + __ct_->tolower(&__s[0], &__s[0] + __s.size()); + string __n; + __n.reserve(__s.size()); + for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); + __i != __e; ++__i) + { + if (static_cast<unsigned>(*__i) >= 127) + return char_class_type(); + __n.push_back(char(*__i)); + } + return __get_classname(__n.c_str(), __icase); +} + +template <class _CharT> +bool +regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const +{ + if (__ct_->is(__m, __c)) + return true; + return (__c == '_' && (__m & __regex_word)); +} + +template <class _CharT> +int +regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) +{ + if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' + return __ch - '0'; + if (__radix != 8) + { + if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' + return __ch - '0'; + if (__radix == 16) + { + __ch |= 0x20; // tolower + if ('a' <= __ch && __ch <= 'f') + return __ch - ('a' - 10); + } + } + return -1; +} + +template <class _CharT> +inline +int +regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const +{ + return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); +} + +template <class _CharT> class __node; + +template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match; + +template <class _BidirectionalIterator, + class _Allocator = allocator<sub_match<_BidirectionalIterator> > > +class _LIBCPP_TEMPLATE_VIS match_results; + +template <class _CharT> +struct __state +{ + enum + { + __end_state = -1000, + __consume_input, // -999 + __begin_marked_expr, // -998 + __end_marked_expr, // -997 + __pop_state, // -996 + __accept_and_consume, // -995 + __accept_but_not_consume, // -994 + __reject, // -993 + __split, + __repeat + }; + + int __do_; + const _CharT* __first_; + const _CharT* __current_; + const _CharT* __last_; + vector<sub_match<const _CharT*> > __sub_matches_; + vector<pair<size_t, const _CharT*> > __loop_data_; + const __node<_CharT>* __node_; + regex_constants::match_flag_type __flags_; + bool __at_first_; + + _LIBCPP_INLINE_VISIBILITY + __state() + : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), + __node_(nullptr), __flags_() {} +}; + +// __node + +template <class _CharT> +class __node +{ + __node(const __node&); + __node& operator=(const __node&); +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __node() {} + _LIBCPP_INLINE_VISIBILITY + virtual ~__node() {} + + _LIBCPP_INLINE_VISIBILITY + virtual void __exec(__state&) const {} + _LIBCPP_INLINE_VISIBILITY + virtual void __exec_split(bool, __state&) const {} +}; + +// __end_state + +template <class _CharT> +class __end_state + : public __node<_CharT> +{ +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __end_state() {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__end_state<_CharT>::__exec(__state& __s) const +{ + __s.__do_ = __state::__end_state; +} + +// __has_one_state + +template <class _CharT> +class __has_one_state + : public __node<_CharT> +{ + __node<_CharT>* __first_; + +public: + _LIBCPP_INLINE_VISIBILITY + explicit __has_one_state(__node<_CharT>* __s) + : __first_(__s) {} + + _LIBCPP_INLINE_VISIBILITY + __node<_CharT>* first() const {return __first_;} + _LIBCPP_INLINE_VISIBILITY + __node<_CharT>*& first() {return __first_;} +}; + +// __owns_one_state + +template <class _CharT> +class __owns_one_state + : public __has_one_state<_CharT> +{ + typedef __has_one_state<_CharT> base; + +public: + _LIBCPP_INLINE_VISIBILITY + explicit __owns_one_state(__node<_CharT>* __s) + : base(__s) {} + + virtual ~__owns_one_state(); +}; + +template <class _CharT> +__owns_one_state<_CharT>::~__owns_one_state() +{ + delete this->first(); +} + +// __empty_state + +template <class _CharT> +class __empty_state + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __empty_state(__node<_CharT>* __s) + : base(__s) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__empty_state<_CharT>::__exec(__state& __s) const +{ + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->first(); +} + +// __empty_non_own_state + +template <class _CharT> +class __empty_non_own_state + : public __has_one_state<_CharT> +{ + typedef __has_one_state<_CharT> base; + +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __empty_non_own_state(__node<_CharT>* __s) + : base(__s) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__empty_non_own_state<_CharT>::__exec(__state& __s) const +{ + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->first(); +} + +// __repeat_one_loop + +template <class _CharT> +class __repeat_one_loop + : public __has_one_state<_CharT> +{ + typedef __has_one_state<_CharT> base; + +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __repeat_one_loop(__node<_CharT>* __s) + : base(__s) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__repeat_one_loop<_CharT>::__exec(__state& __s) const +{ + __s.__do_ = __state::__repeat; + __s.__node_ = this->first(); +} + +// __owns_two_states + +template <class _CharT> +class __owns_two_states + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + base* __second_; + +public: + _LIBCPP_INLINE_VISIBILITY + explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) + : base(__s1), __second_(__s2) {} + + virtual ~__owns_two_states(); + + _LIBCPP_INLINE_VISIBILITY + base* second() const {return __second_;} + _LIBCPP_INLINE_VISIBILITY + base*& second() {return __second_;} +}; + +template <class _CharT> +__owns_two_states<_CharT>::~__owns_two_states() +{ + delete __second_; +} + +// __loop + +template <class _CharT> +class __loop + : public __owns_two_states<_CharT> +{ + typedef __owns_two_states<_CharT> base; + + size_t __min_; + size_t __max_; + unsigned __loop_id_; + unsigned __mexp_begin_; + unsigned __mexp_end_; + bool __greedy_; + +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __loop(unsigned __loop_id, + __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, + unsigned __mexp_begin, unsigned __mexp_end, + bool __greedy = true, + size_t __min = 0, + size_t __max = numeric_limits<size_t>::max()) + : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), + __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), + __greedy_(__greedy) {} + + virtual void __exec(__state& __s) const; + virtual void __exec_split(bool __second, __state& __s) const; + +private: + _LIBCPP_INLINE_VISIBILITY + void __init_repeat(__state& __s) const + { + __s.__loop_data_[__loop_id_].second = __s.__current_; + for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) + { + __s.__sub_matches_[__i].first = __s.__last_; + __s.__sub_matches_[__i].second = __s.__last_; + __s.__sub_matches_[__i].matched = false; + } + } +}; + +template <class _CharT> +void +__loop<_CharT>::__exec(__state& __s) const +{ + if (__s.__do_ == __state::__repeat) + { + bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; + bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; + if (__do_repeat && __do_alt && + __s.__loop_data_[__loop_id_].second == __s.__current_) + __do_repeat = false; + if (__do_repeat && __do_alt) + __s.__do_ = __state::__split; + else if (__do_repeat) + { + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->first(); + __init_repeat(__s); + } + else + { + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->second(); + } + } + else + { + __s.__loop_data_[__loop_id_].first = 0; + bool __do_repeat = 0 < __max_; + bool __do_alt = 0 >= __min_; + if (__do_repeat && __do_alt) + __s.__do_ = __state::__split; + else if (__do_repeat) + { + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->first(); + __init_repeat(__s); + } + else + { + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->second(); + } + } +} + +template <class _CharT> +void +__loop<_CharT>::__exec_split(bool __second, __state& __s) const +{ + __s.__do_ = __state::__accept_but_not_consume; + if (__greedy_ != __second) + { + __s.__node_ = this->first(); + __init_repeat(__s); + } + else + __s.__node_ = this->second(); +} + +// __alternate + +template <class _CharT> +class __alternate + : public __owns_two_states<_CharT> +{ + typedef __owns_two_states<_CharT> base; + +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __alternate(__owns_one_state<_CharT>* __s1, + __owns_one_state<_CharT>* __s2) + : base(__s1, __s2) {} + + virtual void __exec(__state& __s) const; + virtual void __exec_split(bool __second, __state& __s) const; +}; + +template <class _CharT> +void +__alternate<_CharT>::__exec(__state& __s) const +{ + __s.__do_ = __state::__split; +} + +template <class _CharT> +void +__alternate<_CharT>::__exec_split(bool __second, __state& __s) const +{ + __s.__do_ = __state::__accept_but_not_consume; + if (__second) + __s.__node_ = this->second(); + else + __s.__node_ = this->first(); +} + +// __begin_marked_subexpression + +template <class _CharT> +class __begin_marked_subexpression + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + unsigned __mexp_; +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) + : base(__s), __mexp_(__mexp) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__begin_marked_subexpression<_CharT>::__exec(__state& __s) const +{ + __s.__do_ = __state::__accept_but_not_consume; + __s.__sub_matches_[__mexp_-1].first = __s.__current_; + __s.__node_ = this->first(); +} + +// __end_marked_subexpression + +template <class _CharT> +class __end_marked_subexpression + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + unsigned __mexp_; +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) + : base(__s), __mexp_(__mexp) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__end_marked_subexpression<_CharT>::__exec(__state& __s) const +{ + __s.__do_ = __state::__accept_but_not_consume; + __s.__sub_matches_[__mexp_-1].second = __s.__current_; + __s.__sub_matches_[__mexp_-1].matched = true; + __s.__node_ = this->first(); +} + +// __back_ref + +template <class _CharT> +class __back_ref + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + unsigned __mexp_; +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) + : base(__s), __mexp_(__mexp) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__back_ref<_CharT>::__exec(__state& __s) const +{ + if (__mexp_ > __s.__sub_matches_.size()) + __throw_regex_error<regex_constants::error_backref>(); + sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; + if (__sm.matched) + { + ptrdiff_t __len = __sm.second - __sm.first; + if (__s.__last_ - __s.__current_ >= __len && + _VSTD::equal(__sm.first, __sm.second, __s.__current_)) + { + __s.__do_ = __state::__accept_but_not_consume; + __s.__current_ += __len; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __back_ref_icase + +template <class _CharT, class _Traits> +class __back_ref_icase + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + _Traits __traits_; + unsigned __mexp_; +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, + __node<_CharT>* __s) + : base(__s), __traits_(__traits), __mexp_(__mexp) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT, class _Traits> +void +__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const +{ + sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; + if (__sm.matched) + { + ptrdiff_t __len = __sm.second - __sm.first; + if (__s.__last_ - __s.__current_ >= __len) + { + for (ptrdiff_t __i = 0; __i < __len; ++__i) + { + if (__traits_.translate_nocase(__sm.first[__i]) != + __traits_.translate_nocase(__s.__current_[__i])) + goto __not_equal; + } + __s.__do_ = __state::__accept_but_not_consume; + __s.__current_ += __len; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } + } + else + { +__not_equal: + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __back_ref_collate + +template <class _CharT, class _Traits> +class __back_ref_collate + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + _Traits __traits_; + unsigned __mexp_; +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, + __node<_CharT>* __s) + : base(__s), __traits_(__traits), __mexp_(__mexp) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT, class _Traits> +void +__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const +{ + sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; + if (__sm.matched) + { + ptrdiff_t __len = __sm.second - __sm.first; + if (__s.__last_ - __s.__current_ >= __len) + { + for (ptrdiff_t __i = 0; __i < __len; ++__i) + { + if (__traits_.translate(__sm.first[__i]) != + __traits_.translate(__s.__current_[__i])) + goto __not_equal; + } + __s.__do_ = __state::__accept_but_not_consume; + __s.__current_ += __len; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } + } + else + { +__not_equal: + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __word_boundary + +template <class _CharT, class _Traits> +class __word_boundary + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + _Traits __traits_; + bool __invert_; +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + explicit __word_boundary(const _Traits& __traits, bool __invert, + __node<_CharT>* __s) + : base(__s), __traits_(__traits), __invert_(__invert) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT, class _Traits> +void +__word_boundary<_CharT, _Traits>::__exec(__state& __s) const +{ + bool __is_word_b = false; + if (__s.__first_ != __s.__last_) + { + if (__s.__current_ == __s.__last_) + { + if (!(__s.__flags_ & regex_constants::match_not_eow)) + { + _CharT __c = __s.__current_[-1]; + __is_word_b = __c == '_' || + __traits_.isctype(__c, ctype_base::alnum); + } + } + else if (__s.__current_ == __s.__first_ && + !(__s.__flags_ & regex_constants::match_prev_avail)) + { + if (!(__s.__flags_ & regex_constants::match_not_bow)) + { + _CharT __c = *__s.__current_; + __is_word_b = __c == '_' || + __traits_.isctype(__c, ctype_base::alnum); + } + } + else + { + _CharT __c1 = __s.__current_[-1]; + _CharT __c2 = *__s.__current_; + bool __is_c1_b = __c1 == '_' || + __traits_.isctype(__c1, ctype_base::alnum); + bool __is_c2_b = __c2 == '_' || + __traits_.isctype(__c2, ctype_base::alnum); + __is_word_b = __is_c1_b != __is_c2_b; + } + } + if (__is_word_b != __invert_) + { + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __l_anchor + +template <class _CharT> +class __l_anchor + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __l_anchor(__node<_CharT>* __s) + : base(__s) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__l_anchor<_CharT>::__exec(__state& __s) const +{ + if (__s.__at_first_ && __s.__current_ == __s.__first_ && + !(__s.__flags_ & regex_constants::match_not_bol)) + { + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __r_anchor + +template <class _CharT> +class __r_anchor + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __r_anchor(__node<_CharT>* __s) + : base(__s) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__r_anchor<_CharT>::__exec(__state& __s) const +{ + if (__s.__current_ == __s.__last_ && + !(__s.__flags_ & regex_constants::match_not_eol)) + { + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __match_any + +template <class _CharT> +class __match_any + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __match_any(__node<_CharT>* __s) + : base(__s) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__match_any<_CharT>::__exec(__state& __s) const +{ + if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) + { + __s.__do_ = __state::__accept_and_consume; + ++__s.__current_; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __match_any_but_newline + +template <class _CharT> +class __match_any_but_newline + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __match_any_but_newline(__node<_CharT>* __s) + : base(__s) {} + + virtual void __exec(__state&) const; +}; + +template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const; +template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const; + +// __match_char + +template <class _CharT> +class __match_char + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + _CharT __c_; + + __match_char(const __match_char&); + __match_char& operator=(const __match_char&); +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __match_char(_CharT __c, __node<_CharT>* __s) + : base(__s), __c_(__c) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT> +void +__match_char<_CharT>::__exec(__state& __s) const +{ + if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) + { + __s.__do_ = __state::__accept_and_consume; + ++__s.__current_; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __match_char_icase + +template <class _CharT, class _Traits> +class __match_char_icase + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + _Traits __traits_; + _CharT __c_; + + __match_char_icase(const __match_char_icase&); + __match_char_icase& operator=(const __match_char_icase&); +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) + : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT, class _Traits> +void +__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const +{ + if (__s.__current_ != __s.__last_ && + __traits_.translate_nocase(*__s.__current_) == __c_) + { + __s.__do_ = __state::__accept_and_consume; + ++__s.__current_; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __match_char_collate + +template <class _CharT, class _Traits> +class __match_char_collate + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + _Traits __traits_; + _CharT __c_; + + __match_char_collate(const __match_char_collate&); + __match_char_collate& operator=(const __match_char_collate&); +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) + : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT, class _Traits> +void +__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const +{ + if (__s.__current_ != __s.__last_ && + __traits_.translate(*__s.__current_) == __c_) + { + __s.__do_ = __state::__accept_and_consume; + ++__s.__current_; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +// __bracket_expression + +template <class _CharT, class _Traits> +class __bracket_expression + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + typedef typename _Traits::string_type string_type; + + _Traits __traits_; + vector<_CharT> __chars_; + vector<_CharT> __neg_chars_; + vector<pair<string_type, string_type> > __ranges_; + vector<pair<_CharT, _CharT> > __digraphs_; + vector<string_type> __equivalences_; + typename regex_traits<_CharT>::char_class_type __mask_; + typename regex_traits<_CharT>::char_class_type __neg_mask_; + bool __negate_; + bool __icase_; + bool __collate_; + bool __might_have_digraph_; + + __bracket_expression(const __bracket_expression&); + __bracket_expression& operator=(const __bracket_expression&); +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, + bool __negate, bool __icase, bool __collate) + : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), + __negate_(__negate), __icase_(__icase), __collate_(__collate), + __might_have_digraph_(__traits_.getloc().name() != "C") {} + + virtual void __exec(__state&) const; + + _LIBCPP_INLINE_VISIBILITY + bool __negated() const {return __negate_;} + + _LIBCPP_INLINE_VISIBILITY + void __add_char(_CharT __c) + { + if (__icase_) + __chars_.push_back(__traits_.translate_nocase(__c)); + else if (__collate_) + __chars_.push_back(__traits_.translate(__c)); + else + __chars_.push_back(__c); + } + _LIBCPP_INLINE_VISIBILITY + void __add_neg_char(_CharT __c) + { + if (__icase_) + __neg_chars_.push_back(__traits_.translate_nocase(__c)); + else if (__collate_) + __neg_chars_.push_back(__traits_.translate(__c)); + else + __neg_chars_.push_back(__c); + } + _LIBCPP_INLINE_VISIBILITY + void __add_range(string_type __b, string_type __e) + { + if (__collate_) + { + if (__icase_) + { + for (size_t __i = 0; __i < __b.size(); ++__i) + __b[__i] = __traits_.translate_nocase(__b[__i]); + for (size_t __i = 0; __i < __e.size(); ++__i) + __e[__i] = __traits_.translate_nocase(__e[__i]); + } + else + { + for (size_t __i = 0; __i < __b.size(); ++__i) + __b[__i] = __traits_.translate(__b[__i]); + for (size_t __i = 0; __i < __e.size(); ++__i) + __e[__i] = __traits_.translate(__e[__i]); + } + __ranges_.push_back(make_pair( + __traits_.transform(__b.begin(), __b.end()), + __traits_.transform(__e.begin(), __e.end()))); + } + else + { + if (__b.size() != 1 || __e.size() != 1) + __throw_regex_error<regex_constants::error_collate>(); + if (__icase_) + { + __b[0] = __traits_.translate_nocase(__b[0]); + __e[0] = __traits_.translate_nocase(__e[0]); + } + __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); + } + } + _LIBCPP_INLINE_VISIBILITY + void __add_digraph(_CharT __c1, _CharT __c2) + { + if (__icase_) + __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), + __traits_.translate_nocase(__c2))); + else if (__collate_) + __digraphs_.push_back(make_pair(__traits_.translate(__c1), + __traits_.translate(__c2))); + else + __digraphs_.push_back(make_pair(__c1, __c2)); + } + _LIBCPP_INLINE_VISIBILITY + void __add_equivalence(const string_type& __s) + {__equivalences_.push_back(__s);} + _LIBCPP_INLINE_VISIBILITY + void __add_class(typename regex_traits<_CharT>::char_class_type __mask) + {__mask_ |= __mask;} + _LIBCPP_INLINE_VISIBILITY + void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) + {__neg_mask_ |= __mask;} +}; + +template <class _CharT, class _Traits> +void +__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const +{ + bool __found = false; + unsigned __consumed = 0; + if (__s.__current_ != __s.__last_) + { + ++__consumed; + if (__might_have_digraph_) + { + const _CharT* __next = _VSTD::next(__s.__current_); + if (__next != __s.__last_) + { + pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); + if (__icase_) + { + __ch2.first = __traits_.translate_nocase(__ch2.first); + __ch2.second = __traits_.translate_nocase(__ch2.second); + } + else if (__collate_) + { + __ch2.first = __traits_.translate(__ch2.first); + __ch2.second = __traits_.translate(__ch2.second); + } + if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) + { + // __ch2 is a digraph in this locale + ++__consumed; + for (size_t __i = 0; __i < __digraphs_.size(); ++__i) + { + if (__ch2 == __digraphs_[__i]) + { + __found = true; + goto __exit; + } + } + if (__collate_ && !__ranges_.empty()) + { + string_type __s2 = __traits_.transform(&__ch2.first, + &__ch2.first + 2); + for (size_t __i = 0; __i < __ranges_.size(); ++__i) + { + if (__ranges_[__i].first <= __s2 && + __s2 <= __ranges_[__i].second) + { + __found = true; + goto __exit; + } + } + } + if (!__equivalences_.empty()) + { + string_type __s2 = __traits_.transform_primary(&__ch2.first, + &__ch2.first + 2); + for (size_t __i = 0; __i < __equivalences_.size(); ++__i) + { + if (__s2 == __equivalences_[__i]) + { + __found = true; + goto __exit; + } + } + } + if (__traits_.isctype(__ch2.first, __mask_) && + __traits_.isctype(__ch2.second, __mask_)) + { + __found = true; + goto __exit; + } + if (!__traits_.isctype(__ch2.first, __neg_mask_) && + !__traits_.isctype(__ch2.second, __neg_mask_)) + { + __found = true; + goto __exit; + } + goto __exit; + } + } + } + // test *__s.__current_ as not a digraph + _CharT __ch = *__s.__current_; + if (__icase_) + __ch = __traits_.translate_nocase(__ch); + else if (__collate_) + __ch = __traits_.translate(__ch); + for (size_t __i = 0; __i < __chars_.size(); ++__i) + { + if (__ch == __chars_[__i]) + { + __found = true; + goto __exit; + } + } + // When there's at least one of __neg_chars_ and __neg_mask_, the set + // of "__found" chars is + // union(complement(union(__neg_chars_, __neg_mask_)), + // other cases...) + // + // It doesn't make sense to check this when there are no __neg_chars_ + // and no __neg_mask_. + if (!(__neg_mask_ == 0 && __neg_chars_.empty())) + { + const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_); + const bool __in_neg_chars = + std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != + __neg_chars_.end(); + if (!(__in_neg_mask || __in_neg_chars)) + { + __found = true; + goto __exit; + } + } + if (!__ranges_.empty()) + { + string_type __s2 = __collate_ ? + __traits_.transform(&__ch, &__ch + 1) : + string_type(1, __ch); + for (size_t __i = 0; __i < __ranges_.size(); ++__i) + { + if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) + { + __found = true; + goto __exit; + } + } + } + if (!__equivalences_.empty()) + { + string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); + for (size_t __i = 0; __i < __equivalences_.size(); ++__i) + { + if (__s2 == __equivalences_[__i]) + { + __found = true; + goto __exit; + } + } + } + if (__traits_.isctype(__ch, __mask_)) + { + __found = true; + goto __exit; + } + } + else + __found = __negate_; // force reject +__exit: + if (__found != __negate_) + { + __s.__do_ = __state::__accept_and_consume; + __s.__current_ += __consumed; + __s.__node_ = this->first(); + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +template <class _CharT, class _Traits> class __lookahead; + +template <class _CharT, class _Traits = regex_traits<_CharT> > +class _LIBCPP_TEMPLATE_VIS basic_regex +{ +public: + // types: + typedef _CharT value_type; + typedef _Traits traits_type; + typedef typename _Traits::string_type string_type; + typedef regex_constants::syntax_option_type flag_type; + typedef typename _Traits::locale_type locale_type; + +private: + _Traits __traits_; + flag_type __flags_; + unsigned __marked_count_; + unsigned __loop_count_; + int __open_count_; + shared_ptr<__empty_state<_CharT> > __start_; + __owns_one_state<_CharT>* __end_; + + typedef _VSTD::__state<_CharT> __state; + typedef _VSTD::__node<_CharT> __node; + +public: + // constants: + static const regex_constants::syntax_option_type icase = regex_constants::icase; + static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; + static const regex_constants::syntax_option_type optimize = regex_constants::optimize; + static const regex_constants::syntax_option_type collate = regex_constants::collate; + static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; + static const regex_constants::syntax_option_type basic = regex_constants::basic; + static const regex_constants::syntax_option_type extended = regex_constants::extended; + static const regex_constants::syntax_option_type awk = regex_constants::awk; + static const regex_constants::syntax_option_type grep = regex_constants::grep; + static const regex_constants::syntax_option_type egrep = regex_constants::egrep; + + // construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY + basic_regex() + : __flags_(regex_constants::ECMAScript), __marked_count_(0), __loop_count_(0), __open_count_(0), + __end_(0) + {} + _LIBCPP_INLINE_VISIBILITY + explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript) + : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), + __end_(0) + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__p, __p + __traits_.length(__p)); + } + + _LIBCPP_INLINE_VISIBILITY + basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) + : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), + __end_(0) + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__p, __p + __len); + } + +// basic_regex(const basic_regex&) = default; +// basic_regex(basic_regex&&) = default; + template <class _ST, class _SA> + _LIBCPP_INLINE_VISIBILITY + explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, + flag_type __f = regex_constants::ECMAScript) + : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), + __end_(0) + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__p.begin(), __p.end()); + } + + template <class _ForwardIterator> + _LIBCPP_INLINE_VISIBILITY + basic_regex(_ForwardIterator __first, _ForwardIterator __last, + flag_type __f = regex_constants::ECMAScript) + : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), + __end_(0) + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__first, __last); + } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_regex(initializer_list<value_type> __il, + flag_type __f = regex_constants::ECMAScript) + : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), + __end_(0) + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__il.begin(), __il.end()); + } +#endif // _LIBCPP_CXX03_LANG + +// ~basic_regex() = default; + +// basic_regex& operator=(const basic_regex&) = default; +// basic_regex& operator=(basic_regex&&) = default; + _LIBCPP_INLINE_VISIBILITY + basic_regex& operator=(const value_type* __p) + {return assign(__p);} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_regex& operator=(initializer_list<value_type> __il) + {return assign(__il);} +#endif // _LIBCPP_CXX03_LANG + template <class _ST, class _SA> + _LIBCPP_INLINE_VISIBILITY + basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) + {return assign(__p);} + + // assign: + _LIBCPP_INLINE_VISIBILITY + basic_regex& assign(const basic_regex& __that) + {return *this = __that;} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_regex& assign(basic_regex&& __that) _NOEXCEPT + {return *this = _VSTD::move(__that);} +#endif + _LIBCPP_INLINE_VISIBILITY + basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) + {return assign(__p, __p + __traits_.length(__p), __f);} + _LIBCPP_INLINE_VISIBILITY + basic_regex& assign(const value_type* __p, size_t __len, flag_type __f) + {return assign(__p, __p + __len, __f);} + template <class _ST, class _SA> + _LIBCPP_INLINE_VISIBILITY + basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, + flag_type __f = regex_constants::ECMAScript) + {return assign(__s.begin(), __s.end(), __f);} + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value, + basic_regex& + >::type + assign(_InputIterator __first, _InputIterator __last, + flag_type __f = regex_constants::ECMAScript) + { + basic_string<_CharT> __t(__first, __last); + return assign(__t.begin(), __t.end(), __f); + } + +private: + _LIBCPP_INLINE_VISIBILITY + void __member_init(flag_type __f) + { + __flags_ = __f; + __marked_count_ = 0; + __loop_count_ = 0; + __open_count_ = 0; + __end_ = nullptr; + } +public: + + template <class _ForwardIterator> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + basic_regex& + >::type + assign(_ForwardIterator __first, _ForwardIterator __last, + flag_type __f = regex_constants::ECMAScript) + { + return assign(basic_regex(__first, __last, __f)); + } + +#ifndef _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + basic_regex& assign(initializer_list<value_type> __il, + flag_type __f = regex_constants::ECMAScript) + {return assign(__il.begin(), __il.end(), __f);} + +#endif // _LIBCPP_CXX03_LANG + + // const operations: + _LIBCPP_INLINE_VISIBILITY + unsigned mark_count() const {return __marked_count_;} + _LIBCPP_INLINE_VISIBILITY + flag_type flags() const {return __flags_;} + + // locale: + _LIBCPP_INLINE_VISIBILITY + locale_type imbue(locale_type __loc) + { + __member_init(ECMAScript); + __start_.reset(); + return __traits_.imbue(__loc); + } + _LIBCPP_INLINE_VISIBILITY + locale_type getloc() const {return __traits_.getloc();} + + // swap: + void swap(basic_regex& __r); + +private: + _LIBCPP_INLINE_VISIBILITY + unsigned __loop_count() const {return __loop_count_;} + + template <class _ForwardIterator> + _ForwardIterator + __parse(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, + __owns_one_state<_CharT>* __s, + unsigned __mexp_begin, unsigned __mexp_end); + template <class _ForwardIterator> + _ForwardIterator + __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, + __owns_one_state<_CharT>* __s, + unsigned __mexp_begin, unsigned __mexp_end); + template <class _ForwardIterator> + _ForwardIterator + __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, + __bracket_expression<_CharT, _Traits>* __ml); + template <class _ForwardIterator> + _ForwardIterator + __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, + __bracket_expression<_CharT, _Traits>* __ml); + template <class _ForwardIterator> + _ForwardIterator + __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, + __bracket_expression<_CharT, _Traits>* __ml); + template <class _ForwardIterator> + _ForwardIterator + __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, + __bracket_expression<_CharT, _Traits>* __ml); + template <class _ForwardIterator> + _ForwardIterator + __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, + basic_string<_CharT>& __col_sym); + template <class _ForwardIterator> + _ForwardIterator + __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); + template <class _ForwardIterator> + _ForwardIterator + __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_term(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_atom(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, + basic_string<_CharT>* __str = nullptr); + template <class _ForwardIterator> + _ForwardIterator + __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_grep(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); + template <class _ForwardIterator> + _ForwardIterator + __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, + basic_string<_CharT>& __str, + __bracket_expression<_CharT, _Traits>* __ml); + template <class _ForwardIterator> + _ForwardIterator + __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, + basic_string<_CharT>* __str = nullptr); + + _LIBCPP_INLINE_VISIBILITY + void __push_l_anchor(); + void __push_r_anchor(); + void __push_match_any(); + void __push_match_any_but_newline(); + _LIBCPP_INLINE_VISIBILITY + void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, + unsigned __mexp_begin = 0, unsigned __mexp_end = 0) + {__push_loop(__min, numeric_limits<size_t>::max(), __s, + __mexp_begin, __mexp_end);} + _LIBCPP_INLINE_VISIBILITY + void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, + unsigned __mexp_begin = 0, unsigned __mexp_end = 0) + {__push_loop(__min, numeric_limits<size_t>::max(), __s, + __mexp_begin, __mexp_end, false);} + void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, + size_t __mexp_begin = 0, size_t __mexp_end = 0, + bool __greedy = true); + __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); + void __push_char(value_type __c); + void __push_back_ref(int __i); + void __push_alternation(__owns_one_state<_CharT>* __sa, + __owns_one_state<_CharT>* __sb); + void __push_begin_marked_subexpression(); + void __push_end_marked_subexpression(unsigned); + void __push_empty(); + void __push_word_boundary(bool); + void __push_lookahead(const basic_regex&, bool, unsigned); + + template <class _Allocator> + bool + __search(const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags) const; + + template <class _Allocator> + bool + __match_at_start(const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags, bool) const; + template <class _Allocator> + bool + __match_at_start_ecma(const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags, bool) const; + template <class _Allocator> + bool + __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags, bool) const; + template <class _Allocator> + bool + __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags, bool) const; + + template <class _Bp, class _Ap, class _Cp, class _Tp> + friend + bool + regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, + regex_constants::match_flag_type); + + template <class _Ap, class _Cp, class _Tp> + friend + bool + regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, + const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); + + template <class _Bp, class _Cp, class _Tp> + friend + bool + regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, + regex_constants::match_flag_type); + + template <class _Cp, class _Tp> + friend + bool + regex_search(const _Cp*, const _Cp*, + const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); + + template <class _Cp, class _Ap, class _Tp> + friend + bool + regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&, + regex_constants::match_flag_type); + + template <class _ST, class _SA, class _Cp, class _Tp> + friend + bool + regex_search(const basic_string<_Cp, _ST, _SA>& __s, + const basic_regex<_Cp, _Tp>& __e, + regex_constants::match_flag_type __flags); + + template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> + friend + bool + regex_search(const basic_string<_Cp, _ST, _SA>& __s, + match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, + const basic_regex<_Cp, _Tp>& __e, + regex_constants::match_flag_type __flags); + + template <class _Iter, class _Ap, class _Cp, class _Tp> + friend + bool + regex_search(__wrap_iter<_Iter> __first, + __wrap_iter<_Iter> __last, + match_results<__wrap_iter<_Iter>, _Ap>& __m, + const basic_regex<_Cp, _Tp>& __e, + regex_constants::match_flag_type __flags); + + template <class, class> friend class __lookahead; +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template <class _ForwardIterator, + class = typename enable_if<__is_forward_iterator<_ForwardIterator>::value, nullptr_t>::type +> +basic_regex(_ForwardIterator, _ForwardIterator, + regex_constants::syntax_option_type = regex_constants::ECMAScript) + -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>; +#endif + +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; +template <class _CharT, class _Traits> + const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::swap(basic_regex& __r) +{ + using _VSTD::swap; + swap(__traits_, __r.__traits_); + swap(__flags_, __r.__flags_); + swap(__marked_count_, __r.__marked_count_); + swap(__loop_count_, __r.__loop_count_); + swap(__open_count_, __r.__open_count_); + swap(__start_, __r.__start_); + swap(__end_, __r.__end_); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) +{ + return __x.swap(__y); +} + +// __lookahead + +template <class _CharT, class _Traits> +class __lookahead + : public __owns_one_state<_CharT> +{ + typedef __owns_one_state<_CharT> base; + + basic_regex<_CharT, _Traits> __exp_; + unsigned __mexp_; + bool __invert_; + + __lookahead(const __lookahead&); + __lookahead& operator=(const __lookahead&); +public: + typedef _VSTD::__state<_CharT> __state; + + _LIBCPP_INLINE_VISIBILITY + __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp) + : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {} + + virtual void __exec(__state&) const; +}; + +template <class _CharT, class _Traits> +void +__lookahead<_CharT, _Traits>::__exec(__state& __s) const +{ + match_results<const _CharT*> __m; + __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); + bool __matched = __exp_.__match_at_start_ecma( + __s.__current_, __s.__last_, + __m, + (__s.__flags_ | regex_constants::match_continuous) & + ~regex_constants::__full_match, + __s.__at_first_ && __s.__current_ == __s.__first_); + if (__matched != __invert_) + { + __s.__do_ = __state::__accept_but_not_consume; + __s.__node_ = this->first(); + for (unsigned __i = 1; __i < __m.size(); ++__i) { + __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; + } + } + else + { + __s.__do_ = __state::__reject; + __s.__node_ = nullptr; + } +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, + _ForwardIterator __last) +{ + { + unique_ptr<__node> __h(new __end_state<_CharT>); + __start_.reset(new __empty_state<_CharT>(__h.get())); + __h.release(); + __end_ = __start_.get(); + } + switch (__get_grammar(__flags_)) + { + case ECMAScript: + __first = __parse_ecma_exp(__first, __last); + break; + case basic: + __first = __parse_basic_reg_exp(__first, __last); + break; + case extended: + case awk: + __first = __parse_extended_reg_exp(__first, __last); + break; + case grep: + __first = __parse_grep(__first, __last); + break; + case egrep: + __first = __parse_egrep(__first, __last); + break; + default: + __throw_regex_error<regex_constants::__re_err_grammar>(); + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + if (*__first == '^') + { + __push_l_anchor(); + ++__first; + } + if (__first != __last) + { + __first = __parse_RE_expression(__first, __last); + if (__first != __last) + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp == __last && *__first == '$') + { + __push_r_anchor(); + ++__first; + } + } + } + if (__first != __last) + __throw_regex_error<regex_constants::__re_err_empty>(); + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, + _ForwardIterator __last) +{ + __owns_one_state<_CharT>* __sa = __end_; + _ForwardIterator __temp = __parse_ERE_branch(__first, __last); + if (__temp == __first) + __throw_regex_error<regex_constants::__re_err_empty>(); + __first = __temp; + while (__first != __last && *__first == '|') + { + __owns_one_state<_CharT>* __sb = __end_; + __temp = __parse_ERE_branch(++__first, __last); + if (__temp == __first) + __throw_regex_error<regex_constants::__re_err_empty>(); + __push_alternation(__sa, __sb); + __first = __temp; + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, + _ForwardIterator __last) +{ + _ForwardIterator __temp = __parse_ERE_expression(__first, __last); + if (__temp == __first) + __throw_regex_error<regex_constants::__re_err_empty>(); + do + { + __first = __temp; + __temp = __parse_ERE_expression(__first, __last); + } while (__temp != __first); + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, + _ForwardIterator __last) +{ + __owns_one_state<_CharT>* __e = __end_; + unsigned __mexp_begin = __marked_count_; + _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); + if (__temp == __first && __temp != __last) + { + switch (*__temp) + { + case '^': + __push_l_anchor(); + ++__temp; + break; + case '$': + __push_r_anchor(); + ++__temp; + break; + case '(': + __push_begin_marked_subexpression(); + unsigned __temp_count = __marked_count_; + ++__open_count_; + __temp = __parse_extended_reg_exp(++__temp, __last); + if (__temp == __last || *__temp != ')') + __throw_regex_error<regex_constants::error_paren>(); + __push_end_marked_subexpression(__temp_count); + --__open_count_; + ++__temp; + break; + } + } + if (__temp != __first) + __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, + __marked_count_+1); + __first = __temp; + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, + _ForwardIterator __last) +{ + while (true) + { + _ForwardIterator __temp = __parse_simple_RE(__first, __last); + if (__temp == __first) + break; + __first = __temp; + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + __owns_one_state<_CharT>* __e = __end_; + unsigned __mexp_begin = __marked_count_; + _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); + if (__temp != __first) + __first = __parse_RE_dupl_symbol(__temp, __last, __e, + __mexp_begin+1, __marked_count_+1); + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, + _ForwardIterator __last) +{ + _ForwardIterator __temp = __first; + __first = __parse_one_char_or_coll_elem_RE(__first, __last); + if (__temp == __first) + { + __temp = __parse_Back_open_paren(__first, __last); + if (__temp != __first) + { + __push_begin_marked_subexpression(); + unsigned __temp_count = __marked_count_; + __first = __parse_RE_expression(__temp, __last); + __temp = __parse_Back_close_paren(__first, __last); + if (__temp == __first) + __throw_regex_error<regex_constants::error_paren>(); + __push_end_marked_subexpression(__temp_count); + __first = __temp; + } + else + __first = __parse_BACKREF(__first, __last); + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( + _ForwardIterator __first, + _ForwardIterator __last) +{ + _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); + if (__temp == __first) + { + __temp = __parse_QUOTED_CHAR(__first, __last); + if (__temp == __first) + { + if (__temp != __last && *__temp == '.') + { + __push_match_any(); + ++__temp; + } + else + __temp = __parse_bracket_expression(__first, __last); + } + } + __first = __temp; + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( + _ForwardIterator __first, + _ForwardIterator __last) +{ + _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); + if (__temp == __first) + { + __temp = __parse_QUOTED_CHAR_ERE(__first, __last); + if (__temp == __first) + { + if (__temp != __last && *__temp == '.') + { + __push_match_any(); + ++__temp; + } + else + __temp = __parse_bracket_expression(__first, __last); + } + } + __first = __temp; + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last) + { + if (*__first == '\\' && *__temp == '(') + __first = ++__temp; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last) + { + if (*__first == '\\' && *__temp == ')') + __first = ++__temp; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last) + { + if (*__first == '\\' && *__temp == '{') + __first = ++__temp; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last) + { + if (*__first == '\\' && *__temp == '}') + __first = ++__temp; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last) + { + if (*__first == '\\') + { + int __val = __traits_.value(*__temp, 10); + if (__val >= 1 && __val <= 9) + { + __push_back_ref(__val); + __first = ++__temp; + } + } + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp == __last && *__first == '$') + return __first; + // Not called inside a bracket + if (*__first == '.' || *__first == '\\' || *__first == '[') + return __first; + __push_char(*__first); + ++__first; + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + switch (*__first) + { + case '^': + case '.': + case '[': + case '$': + case '(': + case '|': + case '*': + case '+': + case '?': + case '{': + case '\\': + break; + case ')': + if (__open_count_ == 0) + { + __push_char(*__first); + ++__first; + } + break; + default: + __push_char(*__first); + ++__first; + break; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last) + { + if (*__first == '\\') + { + switch (*__temp) + { + case '^': + case '.': + case '*': + case '[': + case '$': + case '\\': + __push_char(*__temp); + __first = ++__temp; + break; + } + } + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last) + { + if (*__first == '\\') + { + switch (*__temp) + { + case '^': + case '.': + case '*': + case '[': + case '$': + case '\\': + case '(': + case ')': + case '|': + case '+': + case '?': + case '{': + case '}': + __push_char(*__temp); + __first = ++__temp; + break; + default: + if (__get_grammar(__flags_) == awk) + __first = __parse_awk_escape(++__first, __last); + break; + } + } + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, + _ForwardIterator __last, + __owns_one_state<_CharT>* __s, + unsigned __mexp_begin, + unsigned __mexp_end) +{ + if (__first != __last) + { + if (*__first == '*') + { + __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); + ++__first; + } + else + { + _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); + if (__temp != __first) + { + int __min = 0; + __first = __temp; + __temp = __parse_DUP_COUNT(__first, __last, __min); + if (__temp == __first) + __throw_regex_error<regex_constants::error_badbrace>(); + __first = __temp; + if (__first == __last) + __throw_regex_error<regex_constants::error_brace>(); + if (*__first != ',') + { + __temp = __parse_Back_close_brace(__first, __last); + if (__temp == __first) + __throw_regex_error<regex_constants::error_brace>(); + __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, + true); + __first = __temp; + } + else + { + ++__first; // consume ',' + int __max = -1; + __first = __parse_DUP_COUNT(__first, __last, __max); + __temp = __parse_Back_close_brace(__first, __last); + if (__temp == __first) + __throw_regex_error<regex_constants::error_brace>(); + if (__max == -1) + __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); + else + { + if (__max < __min) + __throw_regex_error<regex_constants::error_badbrace>(); + __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, + true); + } + __first = __temp; + } + } + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, + _ForwardIterator __last, + __owns_one_state<_CharT>* __s, + unsigned __mexp_begin, + unsigned __mexp_end) +{ + if (__first != __last) + { + unsigned __grammar = __get_grammar(__flags_); + switch (*__first) + { + case '*': + ++__first; + if (__grammar == ECMAScript && __first != __last && *__first == '?') + { + ++__first; + __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); + } + else + __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); + break; + case '+': + ++__first; + if (__grammar == ECMAScript && __first != __last && *__first == '?') + { + ++__first; + __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); + } + else + __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); + break; + case '?': + ++__first; + if (__grammar == ECMAScript && __first != __last && *__first == '?') + { + ++__first; + __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); + } + else + __push_loop(0, 1, __s, __mexp_begin, __mexp_end); + break; + case '{': + { + int __min; + _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); + if (__temp == __first) + __throw_regex_error<regex_constants::error_badbrace>(); + __first = __temp; + if (__first == __last) + __throw_regex_error<regex_constants::error_brace>(); + switch (*__first) + { + case '}': + ++__first; + if (__grammar == ECMAScript && __first != __last && *__first == '?') + { + ++__first; + __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); + } + else + __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); + break; + case ',': + ++__first; + if (__first == __last) + __throw_regex_error<regex_constants::error_badbrace>(); + if (*__first == '}') + { + ++__first; + if (__grammar == ECMAScript && __first != __last && *__first == '?') + { + ++__first; + __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); + } + else + __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); + } + else + { + int __max = -1; + __temp = __parse_DUP_COUNT(__first, __last, __max); + if (__temp == __first) + __throw_regex_error<regex_constants::error_brace>(); + __first = __temp; + if (__first == __last || *__first != '}') + __throw_regex_error<regex_constants::error_brace>(); + ++__first; + if (__max < __min) + __throw_regex_error<regex_constants::error_badbrace>(); + if (__grammar == ECMAScript && __first != __last && *__first == '?') + { + ++__first; + __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); + } + else + __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); + } + break; + default: + __throw_regex_error<regex_constants::error_badbrace>(); + } + } + break; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last && *__first == '[') + { + ++__first; + if (__first == __last) + __throw_regex_error<regex_constants::error_brack>(); + bool __negate = false; + if (*__first == '^') + { + ++__first; + __negate = true; + } + __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); + // __ml owned by *this + if (__first == __last) + __throw_regex_error<regex_constants::error_brack>(); + if (__get_grammar(__flags_) != ECMAScript && *__first == ']') + { + __ml->__add_char(']'); + ++__first; + } + __first = __parse_follow_list(__first, __last, __ml); + if (__first == __last) + __throw_regex_error<regex_constants::error_brack>(); + if (*__first == '-') + { + __ml->__add_char('-'); + ++__first; + } + if (__first == __last || *__first != ']') + __throw_regex_error<regex_constants::error_brack>(); + ++__first; + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, + _ForwardIterator __last, + __bracket_expression<_CharT, _Traits>* __ml) +{ + if (__first != __last) + { + while (true) + { + _ForwardIterator __temp = __parse_expression_term(__first, __last, + __ml); + if (__temp == __first) + break; + __first = __temp; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, + _ForwardIterator __last, + __bracket_expression<_CharT, _Traits>* __ml) +{ + if (__first != __last && *__first != ']') + { + _ForwardIterator __temp = _VSTD::next(__first); + basic_string<_CharT> __start_range; + if (__temp != __last && *__first == '[') + { + if (*__temp == '=') + return __parse_equivalence_class(++__temp, __last, __ml); + else if (*__temp == ':') + return __parse_character_class(++__temp, __last, __ml); + else if (*__temp == '.') + __first = __parse_collating_symbol(++__temp, __last, __start_range); + } + unsigned __grammar = __get_grammar(__flags_); + if (__start_range.empty()) + { + if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') + { + if (__grammar == ECMAScript) + __first = __parse_class_escape(++__first, __last, __start_range, __ml); + else + __first = __parse_awk_escape(++__first, __last, &__start_range); + } + else + { + __start_range = *__first; + ++__first; + } + } + if (__first != __last && *__first != ']') + { + __temp = _VSTD::next(__first); + if (__temp != __last && *__first == '-' && *__temp != ']') + { + // parse a range + basic_string<_CharT> __end_range; + __first = __temp; + ++__temp; + if (__temp != __last && *__first == '[' && *__temp == '.') + __first = __parse_collating_symbol(++__temp, __last, __end_range); + else + { + if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') + { + if (__grammar == ECMAScript) + __first = __parse_class_escape(++__first, __last, + __end_range, __ml); + else + __first = __parse_awk_escape(++__first, __last, + &__end_range); + } + else + { + __end_range = *__first; + ++__first; + } + } + __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); + } + else if (!__start_range.empty()) + { + if (__start_range.size() == 1) + __ml->__add_char(__start_range[0]); + else + __ml->__add_digraph(__start_range[0], __start_range[1]); + } + } + else if (!__start_range.empty()) + { + if (__start_range.size() == 1) + __ml->__add_char(__start_range[0]); + else + __ml->__add_digraph(__start_range[0], __start_range[1]); + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, + _ForwardIterator __last, + basic_string<_CharT>& __str, + __bracket_expression<_CharT, _Traits>* __ml) +{ + if (__first == __last) + __throw_regex_error<regex_constants::error_escape>(); + switch (*__first) + { + case 0: + __str = *__first; + return ++__first; + case 'b': + __str = _CharT(8); + return ++__first; + case 'd': + __ml->__add_class(ctype_base::digit); + return ++__first; + case 'D': + __ml->__add_neg_class(ctype_base::digit); + return ++__first; + case 's': + __ml->__add_class(ctype_base::space); + return ++__first; + case 'S': + __ml->__add_neg_class(ctype_base::space); + return ++__first; + case 'w': + __ml->__add_class(ctype_base::alnum); + __ml->__add_char('_'); + return ++__first; + case 'W': + __ml->__add_neg_class(ctype_base::alnum); + __ml->__add_neg_char('_'); + return ++__first; + } + __first = __parse_character_escape(__first, __last, &__str); + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, + _ForwardIterator __last, + basic_string<_CharT>* __str) +{ + if (__first == __last) + __throw_regex_error<regex_constants::error_escape>(); + switch (*__first) + { + case '\\': + case '"': + case '/': + if (__str) + *__str = *__first; + else + __push_char(*__first); + return ++__first; + case 'a': + if (__str) + *__str = _CharT(7); + else + __push_char(_CharT(7)); + return ++__first; + case 'b': + if (__str) + *__str = _CharT(8); + else + __push_char(_CharT(8)); + return ++__first; + case 'f': + if (__str) + *__str = _CharT(0xC); + else + __push_char(_CharT(0xC)); + return ++__first; + case 'n': + if (__str) + *__str = _CharT(0xA); + else + __push_char(_CharT(0xA)); + return ++__first; + case 'r': + if (__str) + *__str = _CharT(0xD); + else + __push_char(_CharT(0xD)); + return ++__first; + case 't': + if (__str) + *__str = _CharT(0x9); + else + __push_char(_CharT(0x9)); + return ++__first; + case 'v': + if (__str) + *__str = _CharT(0xB); + else + __push_char(_CharT(0xB)); + return ++__first; + } + if ('0' <= *__first && *__first <= '7') + { + unsigned __val = *__first - '0'; + if (++__first != __last && ('0' <= *__first && *__first <= '7')) + { + __val = 8 * __val + *__first - '0'; + if (++__first != __last && ('0' <= *__first && *__first <= '7')) + __val = 8 * __val + *__first++ - '0'; + } + if (__str) + *__str = _CharT(__val); + else + __push_char(_CharT(__val)); + } + else + __throw_regex_error<regex_constants::error_escape>(); + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, + _ForwardIterator __last, + __bracket_expression<_CharT, _Traits>* __ml) +{ + // Found [= + // This means =] must exist + value_type _Equal_close[2] = {'=', ']'}; + _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, + _Equal_close+2); + if (__temp == __last) + __throw_regex_error<regex_constants::error_brack>(); + // [__first, __temp) contains all text in [= ... =] + string_type __collate_name = + __traits_.lookup_collatename(__first, __temp); + if (__collate_name.empty()) + __throw_regex_error<regex_constants::error_collate>(); + string_type __equiv_name = + __traits_.transform_primary(__collate_name.begin(), + __collate_name.end()); + if (!__equiv_name.empty()) + __ml->__add_equivalence(__equiv_name); + else + { + switch (__collate_name.size()) + { + case 1: + __ml->__add_char(__collate_name[0]); + break; + case 2: + __ml->__add_digraph(__collate_name[0], __collate_name[1]); + break; + default: + __throw_regex_error<regex_constants::error_collate>(); + } + } + __first = _VSTD::next(__temp, 2); + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, + _ForwardIterator __last, + __bracket_expression<_CharT, _Traits>* __ml) +{ + // Found [: + // This means :] must exist + value_type _Colon_close[2] = {':', ']'}; + _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, + _Colon_close+2); + if (__temp == __last) + __throw_regex_error<regex_constants::error_brack>(); + // [__first, __temp) contains all text in [: ... :] + typedef typename _Traits::char_class_type char_class_type; + char_class_type __class_type = + __traits_.lookup_classname(__first, __temp, __flags_ & icase); + if (__class_type == 0) + __throw_regex_error<regex_constants::error_ctype>(); + __ml->__add_class(__class_type); + __first = _VSTD::next(__temp, 2); + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, + _ForwardIterator __last, + basic_string<_CharT>& __col_sym) +{ + // Found [. + // This means .] must exist + value_type _Dot_close[2] = {'.', ']'}; + _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, + _Dot_close+2); + if (__temp == __last) + __throw_regex_error<regex_constants::error_brack>(); + // [__first, __temp) contains all text in [. ... .] + __col_sym = __traits_.lookup_collatename(__first, __temp); + switch (__col_sym.size()) + { + case 1: + case 2: + break; + default: + __throw_regex_error<regex_constants::error_collate>(); + } + __first = _VSTD::next(__temp, 2); + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, + _ForwardIterator __last, + int& __c) +{ + if (__first != __last ) + { + int __val = __traits_.value(*__first, 10); + if ( __val != -1 ) + { + __c = __val; + for (++__first; + __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; + ++__first) + { + if (__c >= std::numeric_limits<int>::max() / 10) + __throw_regex_error<regex_constants::error_badbrace>(); + __c *= 10; + __c += __val; + } + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, + _ForwardIterator __last) +{ + __owns_one_state<_CharT>* __sa = __end_; + _ForwardIterator __temp = __parse_alternative(__first, __last); + if (__temp == __first) + __push_empty(); + __first = __temp; + while (__first != __last && *__first == '|') + { + __owns_one_state<_CharT>* __sb = __end_; + __temp = __parse_alternative(++__first, __last); + if (__temp == __first) + __push_empty(); + __push_alternation(__sa, __sb); + __first = __temp; + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, + _ForwardIterator __last) +{ + while (true) + { + _ForwardIterator __temp = __parse_term(__first, __last); + if (__temp == __first) + break; + __first = __temp; + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, + _ForwardIterator __last) +{ + _ForwardIterator __temp = __parse_assertion(__first, __last); + if (__temp == __first) + { + __owns_one_state<_CharT>* __e = __end_; + unsigned __mexp_begin = __marked_count_; + __temp = __parse_atom(__first, __last); + if (__temp != __first) + __first = __parse_ERE_dupl_symbol(__temp, __last, __e, + __mexp_begin+1, __marked_count_+1); + } + else + __first = __temp; + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + switch (*__first) + { + case '^': + __push_l_anchor(); + ++__first; + break; + case '$': + __push_r_anchor(); + ++__first; + break; + case '\\': + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last) + { + if (*__temp == 'b') + { + __push_word_boundary(false); + __first = ++__temp; + } + else if (*__temp == 'B') + { + __push_word_boundary(true); + __first = ++__temp; + } + } + } + break; + case '(': + { + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last && *__temp == '?') + { + if (++__temp != __last) + { + switch (*__temp) + { + case '=': + { + basic_regex __exp; + __exp.__flags_ = __flags_; + __temp = __exp.__parse(++__temp, __last); + unsigned __mexp = __exp.__marked_count_; + __push_lookahead(_VSTD::move(__exp), false, __marked_count_); + __marked_count_ += __mexp; + if (__temp == __last || *__temp != ')') + __throw_regex_error<regex_constants::error_paren>(); + __first = ++__temp; + } + break; + case '!': + { + basic_regex __exp; + __exp.__flags_ = __flags_; + __temp = __exp.__parse(++__temp, __last); + unsigned __mexp = __exp.__marked_count_; + __push_lookahead(_VSTD::move(__exp), true, __marked_count_); + __marked_count_ += __mexp; + if (__temp == __last || *__temp != ')') + __throw_regex_error<regex_constants::error_paren>(); + __first = ++__temp; + } + break; + } + } + } + } + break; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + switch (*__first) + { + case '.': + __push_match_any_but_newline(); + ++__first; + break; + case '\\': + __first = __parse_atom_escape(__first, __last); + break; + case '[': + __first = __parse_bracket_expression(__first, __last); + break; + case '(': + { + ++__first; + if (__first == __last) + __throw_regex_error<regex_constants::error_paren>(); + _ForwardIterator __temp = _VSTD::next(__first); + if (__temp != __last && *__first == '?' && *__temp == ':') + { + ++__open_count_; + __first = __parse_ecma_exp(++__temp, __last); + if (__first == __last || *__first != ')') + __throw_regex_error<regex_constants::error_paren>(); + --__open_count_; + ++__first; + } + else + { + __push_begin_marked_subexpression(); + unsigned __temp_count = __marked_count_; + ++__open_count_; + __first = __parse_ecma_exp(__first, __last); + if (__first == __last || *__first != ')') + __throw_regex_error<regex_constants::error_paren>(); + __push_end_marked_subexpression(__temp_count); + --__open_count_; + ++__first; + } + } + break; + case '*': + case '+': + case '?': + case '{': + __throw_regex_error<regex_constants::error_badrepeat>(); + break; + default: + __first = __parse_pattern_character(__first, __last); + break; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last && *__first == '\\') + { + _ForwardIterator __t1 = _VSTD::next(__first); + if (__t1 == __last) + __throw_regex_error<regex_constants::error_escape>(); + + _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); + if (__t2 != __t1) + __first = __t2; + else + { + __t2 = __parse_character_class_escape(__t1, __last); + if (__t2 != __t1) + __first = __t2; + else + { + __t2 = __parse_character_escape(__t1, __last); + if (__t2 != __t1) + __first = __t2; + } + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + if (*__first == '0') + { + __push_char(_CharT()); + ++__first; + } + else if ('1' <= *__first && *__first <= '9') + { + unsigned __v = *__first - '0'; + for (++__first; + __first != __last && '0' <= *__first && *__first <= '9'; ++__first) + { + if (__v >= std::numeric_limits<unsigned>::max() / 10) + __throw_regex_error<regex_constants::error_backref>(); + __v = 10 * __v + *__first - '0'; + } + if (__v == 0 || __v > mark_count()) + __throw_regex_error<regex_constants::error_backref>(); + __push_back_ref(__v); + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + __bracket_expression<_CharT, _Traits>* __ml; + switch (*__first) + { + case 'd': + __ml = __start_matching_list(false); + __ml->__add_class(ctype_base::digit); + ++__first; + break; + case 'D': + __ml = __start_matching_list(true); + __ml->__add_class(ctype_base::digit); + ++__first; + break; + case 's': + __ml = __start_matching_list(false); + __ml->__add_class(ctype_base::space); + ++__first; + break; + case 'S': + __ml = __start_matching_list(true); + __ml->__add_class(ctype_base::space); + ++__first; + break; + case 'w': + __ml = __start_matching_list(false); + __ml->__add_class(ctype_base::alnum); + __ml->__add_char('_'); + ++__first; + break; + case 'W': + __ml = __start_matching_list(true); + __ml->__add_class(ctype_base::alnum); + __ml->__add_char('_'); + ++__first; + break; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, + _ForwardIterator __last, + basic_string<_CharT>* __str) +{ + if (__first != __last) + { + _ForwardIterator __t; + unsigned __sum = 0; + int __hd; + switch (*__first) + { + case 'f': + if (__str) + *__str = _CharT(0xC); + else + __push_char(_CharT(0xC)); + ++__first; + break; + case 'n': + if (__str) + *__str = _CharT(0xA); + else + __push_char(_CharT(0xA)); + ++__first; + break; + case 'r': + if (__str) + *__str = _CharT(0xD); + else + __push_char(_CharT(0xD)); + ++__first; + break; + case 't': + if (__str) + *__str = _CharT(0x9); + else + __push_char(_CharT(0x9)); + ++__first; + break; + case 'v': + if (__str) + *__str = _CharT(0xB); + else + __push_char(_CharT(0xB)); + ++__first; + break; + case 'c': + if ((__t = _VSTD::next(__first)) != __last) + { + if (('A' <= *__t && *__t <= 'Z') || + ('a' <= *__t && *__t <= 'z')) + { + if (__str) + *__str = _CharT(*__t % 32); + else + __push_char(_CharT(*__t % 32)); + __first = ++__t; + } + else + __throw_regex_error<regex_constants::error_escape>(); + } + else + __throw_regex_error<regex_constants::error_escape>(); + break; + case 'u': + ++__first; + if (__first == __last) + __throw_regex_error<regex_constants::error_escape>(); + __hd = __traits_.value(*__first, 16); + if (__hd == -1) + __throw_regex_error<regex_constants::error_escape>(); + __sum = 16 * __sum + static_cast<unsigned>(__hd); + ++__first; + if (__first == __last) + __throw_regex_error<regex_constants::error_escape>(); + __hd = __traits_.value(*__first, 16); + if (__hd == -1) + __throw_regex_error<regex_constants::error_escape>(); + __sum = 16 * __sum + static_cast<unsigned>(__hd); + // drop through + case 'x': + ++__first; + if (__first == __last) + __throw_regex_error<regex_constants::error_escape>(); + __hd = __traits_.value(*__first, 16); + if (__hd == -1) + __throw_regex_error<regex_constants::error_escape>(); + __sum = 16 * __sum + static_cast<unsigned>(__hd); + ++__first; + if (__first == __last) + __throw_regex_error<regex_constants::error_escape>(); + __hd = __traits_.value(*__first, 16); + if (__hd == -1) + __throw_regex_error<regex_constants::error_escape>(); + __sum = 16 * __sum + static_cast<unsigned>(__hd); + if (__str) + *__str = _CharT(__sum); + else + __push_char(_CharT(__sum)); + ++__first; + break; + case '0': + if (__str) + *__str = _CharT(0); + else + __push_char(_CharT(0)); + ++__first; + break; + default: + if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) + { + if (__str) + *__str = *__first; + else + __push_char(*__first); + ++__first; + } + else + __throw_regex_error<regex_constants::error_escape>(); + break; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + switch (*__first) + { + case '^': + case '$': + case '\\': + case '.': + case '*': + case '+': + case '?': + case '(': + case ')': + case '[': + case ']': + case '{': + case '}': + case '|': + break; + default: + __push_char(*__first); + ++__first; + break; + } + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, + _ForwardIterator __last) +{ + __owns_one_state<_CharT>* __sa = __end_; + _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); + if (__t1 != __first) + __parse_basic_reg_exp(__first, __t1); + else + __push_empty(); + __first = __t1; + if (__first != __last) + ++__first; + while (__first != __last) + { + __t1 = _VSTD::find(__first, __last, _CharT('\n')); + __owns_one_state<_CharT>* __sb = __end_; + if (__t1 != __first) + __parse_basic_reg_exp(__first, __t1); + else + __push_empty(); + __push_alternation(__sa, __sb); + __first = __t1; + if (__first != __last) + ++__first; + } + return __first; +} + +template <class _CharT, class _Traits> +template <class _ForwardIterator> +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, + _ForwardIterator __last) +{ + __owns_one_state<_CharT>* __sa = __end_; + _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); + if (__t1 != __first) + __parse_extended_reg_exp(__first, __t1); + else + __push_empty(); + __first = __t1; + if (__first != __last) + ++__first; + while (__first != __last) + { + __t1 = _VSTD::find(__first, __last, _CharT('\n')); + __owns_one_state<_CharT>* __sb = __end_; + if (__t1 != __first) + __parse_extended_reg_exp(__first, __t1); + else + __push_empty(); + __push_alternation(__sa, __sb); + __first = __t1; + if (__first != __last) + ++__first; + } + return __first; +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, + __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, + bool __greedy) +{ + unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); + __end_->first() = nullptr; + unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, + __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, + __min, __max)); + __s->first() = nullptr; + __e1.release(); + __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); + __end_ = __e2->second(); + __s->first() = __e2.release(); + ++__loop_count_; +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_char(value_type __c) +{ + if (flags() & icase) + __end_->first() = new __match_char_icase<_CharT, _Traits> + (__traits_, __c, __end_->first()); + else if (flags() & collate) + __end_->first() = new __match_char_collate<_CharT, _Traits> + (__traits_, __c, __end_->first()); + else + __end_->first() = new __match_char<_CharT>(__c, __end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() +{ + if (!(__flags_ & nosubs)) + { + __end_->first() = + new __begin_marked_subexpression<_CharT>(++__marked_count_, + __end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); + } +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) +{ + if (!(__flags_ & nosubs)) + { + __end_->first() = + new __end_marked_subexpression<_CharT>(__sub, __end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); + } +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_l_anchor() +{ + __end_->first() = new __l_anchor<_CharT>(__end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_r_anchor() +{ + __end_->first() = new __r_anchor<_CharT>(__end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_match_any() +{ + __end_->first() = new __match_any<_CharT>(__end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_match_any_but_newline() +{ + __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_empty() +{ + __end_->first() = new __empty_state<_CharT>(__end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) +{ + __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, + __end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_back_ref(int __i) +{ + if (flags() & icase) + __end_->first() = new __back_ref_icase<_CharT, _Traits> + (__traits_, __i, __end_->first()); + else if (flags() & collate) + __end_->first() = new __back_ref_collate<_CharT, _Traits> + (__traits_, __i, __end_->first()); + else + __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, + __owns_one_state<_CharT>* __ea) +{ + __sa->first() = new __alternate<_CharT>( + static_cast<__owns_one_state<_CharT>*>(__sa->first()), + static_cast<__owns_one_state<_CharT>*>(__ea->first())); + __ea->first() = nullptr; + __ea->first() = new __empty_state<_CharT>(__end_->first()); + __end_->first() = nullptr; + __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); +} + +template <class _CharT, class _Traits> +__bracket_expression<_CharT, _Traits>* +basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) +{ + __bracket_expression<_CharT, _Traits>* __r = + new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), + __negate, __flags_ & icase, + __flags_ & collate); + __end_->first() = __r; + __end_ = __r; + return __r; +} + +template <class _CharT, class _Traits> +void +basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, + bool __invert, + unsigned __mexp) +{ + __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, + __end_->first(), __mexp); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + +typedef basic_regex<char> regex; +typedef basic_regex<wchar_t> wregex; + +// sub_match + +template <class _BidirectionalIterator> +class _LIBCPP_TEMPLATE_VIS sub_match + : public pair<_BidirectionalIterator, _BidirectionalIterator> +{ +public: + typedef _BidirectionalIterator iterator; + typedef typename iterator_traits<iterator>::value_type value_type; + typedef typename iterator_traits<iterator>::difference_type difference_type; + typedef basic_string<value_type> string_type; + + bool matched; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR sub_match() : matched() {} + + _LIBCPP_INLINE_VISIBILITY + difference_type length() const + {return matched ? _VSTD::distance(this->first, this->second) : 0;} + _LIBCPP_INLINE_VISIBILITY + string_type str() const + {return matched ? string_type(this->first, this->second) : string_type();} + _LIBCPP_INLINE_VISIBILITY + operator string_type() const + {return str();} + + _LIBCPP_INLINE_VISIBILITY + int compare(const sub_match& __s) const + {return str().compare(__s.str());} + _LIBCPP_INLINE_VISIBILITY + int compare(const string_type& __s) const + {return str().compare(__s);} + _LIBCPP_INLINE_VISIBILITY + int compare(const value_type* __s) const + {return str().compare(__s);} +}; + +typedef sub_match<const char*> csub_match; +typedef sub_match<const wchar_t*> wcsub_match; +typedef sub_match<string::const_iterator> ssub_match; +typedef sub_match<wstring::const_iterator> wssub_match; + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) +{ + return __x.compare(__y) == 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) +{ + return !(__x == __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) +{ + return __x.compare(__y) < 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) +{ + return !(__y < __x); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) +{ + return !(__x < __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) +{ + return __y < __x; +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, + const sub_match<_BiIter>& __y) +{ + return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0; +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, + const sub_match<_BiIter>& __y) +{ + return !(__x == __y); +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, + const sub_match<_BiIter>& __y) +{ + return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0; +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, + const sub_match<_BiIter>& __y) +{ + return __y < __x; +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, + const sub_match<_BiIter>& __y) +{ + return !(__x < __y); +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, + const sub_match<_BiIter>& __y) +{ + return !(__y < __x); +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const sub_match<_BiIter>& __x, + const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) +{ + return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0; +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const sub_match<_BiIter>& __x, + const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) +{ + return !(__x == __y); +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const sub_match<_BiIter>& __x, + const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) +{ + return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0; +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool operator>(const sub_match<_BiIter>& __x, + const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) +{ + return __y < __x; +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const sub_match<_BiIter>& __x, + const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) +{ + return !(__x < __y); +} + +template <class _BiIter, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const sub_match<_BiIter>& __x, + const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) +{ + return !(__y < __x); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(typename iterator_traits<_BiIter>::value_type const* __x, + const sub_match<_BiIter>& __y) +{ + return __y.compare(__x) == 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(typename iterator_traits<_BiIter>::value_type const* __x, + const sub_match<_BiIter>& __y) +{ + return !(__x == __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(typename iterator_traits<_BiIter>::value_type const* __x, + const sub_match<_BiIter>& __y) +{ + return __y.compare(__x) > 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(typename iterator_traits<_BiIter>::value_type const* __x, + const sub_match<_BiIter>& __y) +{ + return __y < __x; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(typename iterator_traits<_BiIter>::value_type const* __x, + const sub_match<_BiIter>& __y) +{ + return !(__x < __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(typename iterator_traits<_BiIter>::value_type const* __x, + const sub_match<_BiIter>& __y) +{ + return !(__y < __x); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const* __y) +{ + return __x.compare(__y) == 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const* __y) +{ + return !(__x == __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const* __y) +{ + return __x.compare(__y) < 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const* __y) +{ + return __y < __x; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const* __y) +{ + return !(__x < __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const* __y) +{ + return !(__y < __x); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(typename iterator_traits<_BiIter>::value_type const& __x, + const sub_match<_BiIter>& __y) +{ + typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; + return __y.compare(string_type(1, __x)) == 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(typename iterator_traits<_BiIter>::value_type const& __x, + const sub_match<_BiIter>& __y) +{ + return !(__x == __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(typename iterator_traits<_BiIter>::value_type const& __x, + const sub_match<_BiIter>& __y) +{ + typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; + return __y.compare(string_type(1, __x)) > 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(typename iterator_traits<_BiIter>::value_type const& __x, + const sub_match<_BiIter>& __y) +{ + return __y < __x; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(typename iterator_traits<_BiIter>::value_type const& __x, + const sub_match<_BiIter>& __y) +{ + return !(__x < __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(typename iterator_traits<_BiIter>::value_type const& __x, + const sub_match<_BiIter>& __y) +{ + return !(__y < __x); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const& __y) +{ + typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; + return __x.compare(string_type(1, __y)) == 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const& __y) +{ + return !(__x == __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const& __y) +{ + typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; + return __x.compare(string_type(1, __y)) < 0; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const& __y) +{ + return __y < __x; +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const& __y) +{ + return !(__x < __y); +} + +template <class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const sub_match<_BiIter>& __x, + typename iterator_traits<_BiIter>::value_type const& __y) +{ + return !(__y < __x); +} + +template <class _CharT, class _ST, class _BiIter> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _ST>& +operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) +{ + return __os << __m.str(); +} + +template <class _BidirectionalIterator, class _Allocator> +class _LIBCPP_TEMPLATE_VIS match_results +{ +public: + typedef _Allocator allocator_type; + typedef sub_match<_BidirectionalIterator> value_type; +private: + typedef vector<value_type, allocator_type> __container_type; + + __container_type __matches_; + value_type __unmatched_; + value_type __prefix_; + value_type __suffix_; + bool __ready_; +public: + _BidirectionalIterator __position_start_; + typedef const value_type& const_reference; + typedef value_type& reference; + typedef typename __container_type::const_iterator const_iterator; + typedef const_iterator iterator; + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; + typedef basic_string<char_type> string_type; + + // construct/copy/destroy: + explicit match_results(const allocator_type& __a = allocator_type()); +// match_results(const match_results&) = default; +// match_results& operator=(const match_results&) = default; +// match_results(match_results&& __m) = default; +// match_results& operator=(match_results&& __m) = default; +// ~match_results() = default; + + _LIBCPP_INLINE_VISIBILITY + bool ready() const {return __ready_;} + + // size: + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __matches_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __matches_.max_size();} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return size() == 0;} + + // element access: + _LIBCPP_INLINE_VISIBILITY + difference_type length(size_type __sub = 0) const + {return (*this)[__sub].length();} + _LIBCPP_INLINE_VISIBILITY + difference_type position(size_type __sub = 0) const + {return _VSTD::distance(__position_start_, (*this)[__sub].first);} + _LIBCPP_INLINE_VISIBILITY + string_type str(size_type __sub = 0) const + {return (*this)[__sub].str();} + _LIBCPP_INLINE_VISIBILITY + const_reference operator[](size_type __n) const + {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} + + _LIBCPP_INLINE_VISIBILITY + const_reference prefix() const {return __prefix_;} + _LIBCPP_INLINE_VISIBILITY + const_reference suffix() const {return __suffix_;} + + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return __matches_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const {return __matches_.end();} + + // format: + template <class _OutputIter> + _OutputIter + format(_OutputIter __output_iter, const char_type* __fmt_first, + const char_type* __fmt_last, + regex_constants::match_flag_type __flags = regex_constants::format_default) const; + template <class _OutputIter, class _ST, class _SA> + _LIBCPP_INLINE_VISIBILITY + _OutputIter + format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt, + regex_constants::match_flag_type __flags = regex_constants::format_default) const + {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} + template <class _ST, class _SA> + _LIBCPP_INLINE_VISIBILITY + basic_string<char_type, _ST, _SA> + format(const basic_string<char_type, _ST, _SA>& __fmt, + regex_constants::match_flag_type __flags = regex_constants::format_default) const + { + basic_string<char_type, _ST, _SA> __r; + format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), + __flags); + return __r; + } + _LIBCPP_INLINE_VISIBILITY + string_type + format(const char_type* __fmt, + regex_constants::match_flag_type __flags = regex_constants::format_default) const + { + string_type __r; + format(back_inserter(__r), __fmt, + __fmt + char_traits<char_type>::length(__fmt), __flags); + return __r; + } + + // allocator: + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const {return __matches_.get_allocator();} + + // swap: + void swap(match_results& __m); + + template <class _Bp, class _Ap> + _LIBCPP_INLINE_VISIBILITY + void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, + const match_results<_Bp, _Ap>& __m, bool __no_update_pos) + { + _Bp __mf = __m.prefix().first; + __matches_.resize(__m.size()); + for (size_type __i = 0; __i < __matches_.size(); ++__i) + { + __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); + __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); + __matches_[__i].matched = __m[__i].matched; + } + __unmatched_.first = __l; + __unmatched_.second = __l; + __unmatched_.matched = false; + __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); + __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); + __prefix_.matched = __m.prefix().matched; + __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); + __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); + __suffix_.matched = __m.suffix().matched; + if (!__no_update_pos) + __position_start_ = __prefix_.first; + __ready_ = __m.ready(); + } + +private: + void __init(unsigned __s, + _BidirectionalIterator __f, _BidirectionalIterator __l, + bool __no_update_pos = false); + + template <class, class> friend class basic_regex; + + template <class _Bp, class _Ap, class _Cp, class _Tp> + friend + bool + regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, + regex_constants::match_flag_type); + + template <class _Bp, class _Ap> + friend + bool + operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); + + template <class, class> friend class __lookahead; +}; + +template <class _BidirectionalIterator, class _Allocator> +match_results<_BidirectionalIterator, _Allocator>::match_results( + const allocator_type& __a) + : __matches_(__a), + __unmatched_(), + __prefix_(), + __suffix_(), + __ready_(false), + __position_start_() +{ +} + +template <class _BidirectionalIterator, class _Allocator> +void +match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, + _BidirectionalIterator __f, _BidirectionalIterator __l, + bool __no_update_pos) +{ + __unmatched_.first = __l; + __unmatched_.second = __l; + __unmatched_.matched = false; + __matches_.assign(__s, __unmatched_); + __prefix_.first = __f; + __prefix_.second = __f; + __prefix_.matched = false; + __suffix_ = __unmatched_; + if (!__no_update_pos) + __position_start_ = __prefix_.first; + __ready_ = true; +} + +template <class _BidirectionalIterator, class _Allocator> +template <class _OutputIter> +_OutputIter +match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter, + const char_type* __fmt_first, const char_type* __fmt_last, + regex_constants::match_flag_type __flags) const +{ + if (__flags & regex_constants::format_sed) + { + for (; __fmt_first != __fmt_last; ++__fmt_first) + { + if (*__fmt_first == '&') + __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, + __output_iter); + else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) + { + ++__fmt_first; + if ('0' <= *__fmt_first && *__fmt_first <= '9') + { + size_t __i = *__fmt_first - '0'; + __output_iter = _VSTD::copy((*this)[__i].first, + (*this)[__i].second, __output_iter); + } + else + { + *__output_iter = *__fmt_first; + ++__output_iter; + } + } + else + { + *__output_iter = *__fmt_first; + ++__output_iter; + } + } + } + else + { + for (; __fmt_first != __fmt_last; ++__fmt_first) + { + if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) + { + switch (__fmt_first[1]) + { + case '$': + *__output_iter = *++__fmt_first; + ++__output_iter; + break; + case '&': + ++__fmt_first; + __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, + __output_iter); + break; + case '`': + ++__fmt_first; + __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter); + break; + case '\'': + ++__fmt_first; + __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter); + break; + default: + if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') + { + ++__fmt_first; + size_t __idx = *__fmt_first - '0'; + if (__fmt_first + 1 != __fmt_last && + '0' <= __fmt_first[1] && __fmt_first[1] <= '9') + { + ++__fmt_first; + if (__idx >= std::numeric_limits<size_t>::max() / 10) + __throw_regex_error<regex_constants::error_escape>(); + __idx = 10 * __idx + *__fmt_first - '0'; + } + __output_iter = _VSTD::copy((*this)[__idx].first, + (*this)[__idx].second, __output_iter); + } + else + { + *__output_iter = *__fmt_first; + ++__output_iter; + } + break; + } + } + else + { + *__output_iter = *__fmt_first; + ++__output_iter; + } + } + } + return __output_iter; +} + +template <class _BidirectionalIterator, class _Allocator> +void +match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) +{ + using _VSTD::swap; + swap(__matches_, __m.__matches_); + swap(__unmatched_, __m.__unmatched_); + swap(__prefix_, __m.__prefix_); + swap(__suffix_, __m.__suffix_); + swap(__position_start_, __m.__position_start_); + swap(__ready_, __m.__ready_); +} + +typedef match_results<const char*> cmatch; +typedef match_results<const wchar_t*> wcmatch; +typedef match_results<string::const_iterator> smatch; +typedef match_results<wstring::const_iterator> wsmatch; + +template <class _BidirectionalIterator, class _Allocator> +bool +operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, + const match_results<_BidirectionalIterator, _Allocator>& __y) +{ + if (__x.__ready_ != __y.__ready_) + return false; + if (!__x.__ready_) + return true; + return __x.__matches_ == __y.__matches_ && + __x.__prefix_ == __y.__prefix_ && + __x.__suffix_ == __y.__suffix_; +} + +template <class _BidirectionalIterator, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, + const match_results<_BidirectionalIterator, _Allocator>& __y) +{ + return !(__x == __y); +} + +template <class _BidirectionalIterator, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(match_results<_BidirectionalIterator, _Allocator>& __x, + match_results<_BidirectionalIterator, _Allocator>& __y) +{ + __x.swap(__y); +} + +// regex_search + +template <class _CharT, class _Traits> +template <class _Allocator> +bool +basic_regex<_CharT, _Traits>::__match_at_start_ecma( + const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags, bool __at_first) const +{ + vector<__state> __states; + __node* __st = __start_.get(); + if (__st) + { + sub_match<const _CharT*> __unmatched; + __unmatched.first = __last; + __unmatched.second = __last; + __unmatched.matched = false; + + __states.push_back(__state()); + __states.back().__do_ = 0; + __states.back().__first_ = __first; + __states.back().__current_ = __first; + __states.back().__last_ = __last; + __states.back().__sub_matches_.resize(mark_count(), __unmatched); + __states.back().__loop_data_.resize(__loop_count()); + __states.back().__node_ = __st; + __states.back().__flags_ = __flags; + __states.back().__at_first_ = __at_first; + int __counter = 0; + int __length = __last - __first; + do + { + ++__counter; + if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && + __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) + __throw_regex_error<regex_constants::error_complexity>(); + __state& __s = __states.back(); + if (__s.__node_) + __s.__node_->__exec(__s); + switch (__s.__do_) + { + case __state::__end_state: + if ((__flags & regex_constants::match_not_null) && + __s.__current_ == __first) + { + __states.pop_back(); + break; + } + if ((__flags & regex_constants::__full_match) && + __s.__current_ != __last) + { + __states.pop_back(); + break; + } + __m.__matches_[0].first = __first; + __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); + __m.__matches_[0].matched = true; + for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) + __m.__matches_[__i+1] = __s.__sub_matches_[__i]; + return true; + case __state::__accept_and_consume: + case __state::__repeat: + case __state::__accept_but_not_consume: + break; + case __state::__split: + { + __state __snext = __s; + __s.__node_->__exec_split(true, __s); + __snext.__node_->__exec_split(false, __snext); + __states.push_back(_VSTD::move(__snext)); + } + break; + case __state::__reject: + __states.pop_back(); + break; + default: + __throw_regex_error<regex_constants::__re_err_unknown>(); + break; + + } + } while (!__states.empty()); + } + return false; +} + +template <class _CharT, class _Traits> +template <class _Allocator> +bool +basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( + const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags, bool __at_first) const +{ + deque<__state> __states; + ptrdiff_t __highest_j = 0; + ptrdiff_t _Np = _VSTD::distance(__first, __last); + __node* __st = __start_.get(); + if (__st) + { + __states.push_back(__state()); + __states.back().__do_ = 0; + __states.back().__first_ = __first; + __states.back().__current_ = __first; + __states.back().__last_ = __last; + __states.back().__loop_data_.resize(__loop_count()); + __states.back().__node_ = __st; + __states.back().__flags_ = __flags; + __states.back().__at_first_ = __at_first; + bool __matched = false; + int __counter = 0; + int __length = __last - __first; + do + { + ++__counter; + if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && + __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) + __throw_regex_error<regex_constants::error_complexity>(); + __state& __s = __states.back(); + if (__s.__node_) + __s.__node_->__exec(__s); + switch (__s.__do_) + { + case __state::__end_state: + if ((__flags & regex_constants::match_not_null) && + __s.__current_ == __first) + { + __states.pop_back(); + break; + } + if ((__flags & regex_constants::__full_match) && + __s.__current_ != __last) + { + __states.pop_back(); + break; + } + if (!__matched || __highest_j < __s.__current_ - __s.__first_) + __highest_j = __s.__current_ - __s.__first_; + __matched = true; + if (__highest_j == _Np) + __states.clear(); + else + __states.pop_back(); + break; + case __state::__consume_input: + break; + case __state::__accept_and_consume: + __states.push_front(_VSTD::move(__s)); + __states.pop_back(); + break; + case __state::__repeat: + case __state::__accept_but_not_consume: + break; + case __state::__split: + { + __state __snext = __s; + __s.__node_->__exec_split(true, __s); + __snext.__node_->__exec_split(false, __snext); + __states.push_back(_VSTD::move(__snext)); + } + break; + case __state::__reject: + __states.pop_back(); + break; + default: + __throw_regex_error<regex_constants::__re_err_unknown>(); + break; + } + } while (!__states.empty()); + if (__matched) + { + __m.__matches_[0].first = __first; + __m.__matches_[0].second = _VSTD::next(__first, __highest_j); + __m.__matches_[0].matched = true; + return true; + } + } + return false; +} + +template <class _CharT, class _Traits> +template <class _Allocator> +bool +basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( + const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags, bool __at_first) const +{ + vector<__state> __states; + __state __best_state; + ptrdiff_t __j = 0; + ptrdiff_t __highest_j = 0; + ptrdiff_t _Np = _VSTD::distance(__first, __last); + __node* __st = __start_.get(); + if (__st) + { + sub_match<const _CharT*> __unmatched; + __unmatched.first = __last; + __unmatched.second = __last; + __unmatched.matched = false; + + __states.push_back(__state()); + __states.back().__do_ = 0; + __states.back().__first_ = __first; + __states.back().__current_ = __first; + __states.back().__last_ = __last; + __states.back().__sub_matches_.resize(mark_count(), __unmatched); + __states.back().__loop_data_.resize(__loop_count()); + __states.back().__node_ = __st; + __states.back().__flags_ = __flags; + __states.back().__at_first_ = __at_first; + const _CharT* __current = __first; + bool __matched = false; + int __counter = 0; + int __length = __last - __first; + do + { + ++__counter; + if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && + __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) + __throw_regex_error<regex_constants::error_complexity>(); + __state& __s = __states.back(); + if (__s.__node_) + __s.__node_->__exec(__s); + switch (__s.__do_) + { + case __state::__end_state: + if ((__flags & regex_constants::match_not_null) && + __s.__current_ == __first) + { + __states.pop_back(); + break; + } + if ((__flags & regex_constants::__full_match) && + __s.__current_ != __last) + { + __states.pop_back(); + break; + } + if (!__matched || __highest_j < __s.__current_ - __s.__first_) + { + __highest_j = __s.__current_ - __s.__first_; + __best_state = __s; + } + __matched = true; + if (__highest_j == _Np) + __states.clear(); + else + __states.pop_back(); + break; + case __state::__accept_and_consume: + __j += __s.__current_ - __current; + __current = __s.__current_; + break; + case __state::__repeat: + case __state::__accept_but_not_consume: + break; + case __state::__split: + { + __state __snext = __s; + __s.__node_->__exec_split(true, __s); + __snext.__node_->__exec_split(false, __snext); + __states.push_back(_VSTD::move(__snext)); + } + break; + case __state::__reject: + __states.pop_back(); + break; + default: + __throw_regex_error<regex_constants::__re_err_unknown>(); + break; + } + } while (!__states.empty()); + if (__matched) + { + __m.__matches_[0].first = __first; + __m.__matches_[0].second = _VSTD::next(__first, __highest_j); + __m.__matches_[0].matched = true; + for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) + __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; + return true; + } + } + return false; +} + +template <class _CharT, class _Traits> +template <class _Allocator> +bool +basic_regex<_CharT, _Traits>::__match_at_start( + const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags, bool __at_first) const +{ + if (__get_grammar(__flags_) == ECMAScript) + return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); + if (mark_count() == 0) + return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); + return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); +} + +template <class _CharT, class _Traits> +template <class _Allocator> +bool +basic_regex<_CharT, _Traits>::__search( + const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + regex_constants::match_flag_type __flags) const +{ + __m.__init(1 + mark_count(), __first, __last, + __flags & regex_constants::__no_update_pos); + if (__match_at_start(__first, __last, __m, __flags, + !(__flags & regex_constants::__no_update_pos))) + { + __m.__prefix_.second = __m[0].first; + __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; + __m.__suffix_.first = __m[0].second; + __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; + return true; + } + if (__first != __last && !(__flags & regex_constants::match_continuous)) + { + __flags |= regex_constants::match_prev_avail; + for (++__first; __first != __last; ++__first) + { + __m.__matches_.assign(__m.size(), __m.__unmatched_); + if (__match_at_start(__first, __last, __m, __flags, false)) + { + __m.__prefix_.second = __m[0].first; + __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; + __m.__suffix_.first = __m[0].second; + __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; + return true; + } + __m.__matches_.assign(__m.size(), __m.__unmatched_); + } + } + __m.__matches_.clear(); + return false; +} + +template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, + match_results<_BidirectionalIterator, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; + basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); + match_results<const _CharT*> __mc; + bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags); + __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); + return __r; +} + +template <class _Iter, class _Allocator, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(__wrap_iter<_Iter> __first, + __wrap_iter<_Iter> __last, + match_results<__wrap_iter<_Iter>, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + match_results<const _CharT*> __mc; + bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); + __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); + return __r; +} + +template <class _Allocator, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(const _CharT* __first, const _CharT* __last, + match_results<const _CharT*, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + return __e.__search(__first, __last, __m, __flags); +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + basic_string<_CharT> __s(__first, __last); + match_results<const _CharT*> __mc; + return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(const _CharT* __first, const _CharT* __last, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + match_results<const _CharT*> __mc; + return __e.__search(__first, __last, __mc, __flags); +} + +template <class _CharT, class _Allocator, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + match_results<const _CharT*> __m; + return _VSTD::regex_search(__str, __m, __e, __flags); +} + +template <class _ST, class _SA, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(const basic_string<_CharT, _ST, _SA>& __s, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + match_results<const _CharT*> __mc; + return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); +} + +template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(const basic_string<_CharT, _ST, _SA>& __s, + match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + match_results<const _CharT*> __mc; + bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); + __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos); + return __r; +} + +#if _LIBCPP_STD_VER > 11 +template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> +bool +regex_search(const basic_string<_Cp, _ST, _SA>&& __s, + match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, + const basic_regex<_Cp, _Tp>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; +#endif + +// regex_match + +template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> +bool +regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, + match_results<_BidirectionalIterator, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + bool __r = _VSTD::regex_search( + __first, __last, __m, __e, + __flags | regex_constants::match_continuous | + regex_constants::__full_match); + if (__r) + { + __r = !__m.suffix().matched; + if (!__r) + __m.__matches_.clear(); + } + return __r; +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + match_results<_BidirectionalIterator> __m; + return _VSTD::regex_match(__first, __last, __m, __e, __flags); +} + +template <class _CharT, class _Allocator, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); +} + +template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_match(const basic_string<_CharT, _ST, _SA>& __s, + match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); +} + +#if _LIBCPP_STD_VER > 11 +template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_match(const basic_string<_CharT, _ST, _SA>&& __s, + match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; +#endif + +template <class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); +} + +template <class _ST, class _SA, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_match(const basic_string<_CharT, _ST, _SA>& __s, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); +} + +// regex_iterator + +template <class _BidirectionalIterator, + class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, + class _Traits = regex_traits<_CharT> > +class _LIBCPP_TEMPLATE_VIS regex_iterator +{ +public: + typedef basic_regex<_CharT, _Traits> regex_type; + typedef match_results<_BidirectionalIterator> value_type; + typedef ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; + typedef forward_iterator_tag iterator_category; + +private: + _BidirectionalIterator __begin_; + _BidirectionalIterator __end_; + const regex_type* __pregex_; + regex_constants::match_flag_type __flags_; + value_type __match_; + +public: + regex_iterator(); + regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, + regex_constants::match_flag_type __m + = regex_constants::match_default); +#if _LIBCPP_STD_VER > 11 + regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type&& __re, + regex_constants::match_flag_type __m + = regex_constants::match_default) = delete; +#endif + + bool operator==(const regex_iterator& __x) const; + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __match_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return _VSTD::addressof(__match_);} + + regex_iterator& operator++(); + _LIBCPP_INLINE_VISIBILITY + regex_iterator operator++(int) + { + regex_iterator __t(*this); + ++(*this); + return __t; + } +}; + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() + : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() +{ +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, regex_constants::match_flag_type __m) + : __begin_(__a), + __end_(__b), + __pregex_(_VSTD::addressof(__re)), + __flags_(__m) +{ + _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +bool +regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: + operator==(const regex_iterator& __x) const +{ + if (__match_.empty() && __x.__match_.empty()) + return true; + if (__match_.empty() || __x.__match_.empty()) + return false; + return __begin_ == __x.__begin_ && + __end_ == __x.__end_ && + __pregex_ == __x.__pregex_ && + __flags_ == __x.__flags_ && + __match_[0] == __x.__match_[0]; +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_iterator<_BidirectionalIterator, _CharT, _Traits>& +regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() +{ + __flags_ |= regex_constants::__no_update_pos; + _BidirectionalIterator __start = __match_[0].second; + if (__match_[0].first == __match_[0].second) + { + if (__start == __end_) + { + __match_ = value_type(); + return *this; + } + else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, + __flags_ | regex_constants::match_not_null | + regex_constants::match_continuous)) + return *this; + else + ++__start; + } + __flags_ |= regex_constants::match_prev_avail; + if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) + __match_ = value_type(); + return *this; +} + +typedef regex_iterator<const char*> cregex_iterator; +typedef regex_iterator<const wchar_t*> wcregex_iterator; +typedef regex_iterator<string::const_iterator> sregex_iterator; +typedef regex_iterator<wstring::const_iterator> wsregex_iterator; + +// regex_token_iterator + +template <class _BidirectionalIterator, + class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, + class _Traits = regex_traits<_CharT> > +class _LIBCPP_TEMPLATE_VIS regex_token_iterator +{ +public: + typedef basic_regex<_CharT, _Traits> regex_type; + typedef sub_match<_BidirectionalIterator> value_type; + typedef ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; + typedef forward_iterator_tag iterator_category; + +private: + typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; + + _Position __position_; + const value_type* __result_; + value_type __suffix_; + ptrdiff_t __n_; + vector<int> __subs_; + +public: + regex_token_iterator(); + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, int __submatch = 0, + regex_constants::match_flag_type __m = + regex_constants::match_default); +#if _LIBCPP_STD_VER > 11 + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type&& __re, int __submatch = 0, + regex_constants::match_flag_type __m = + regex_constants::match_default) = delete; +#endif + + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, const vector<int>& __submatches, + regex_constants::match_flag_type __m = + regex_constants::match_default); +#if _LIBCPP_STD_VER > 11 + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type&& __re, const vector<int>& __submatches, + regex_constants::match_flag_type __m = + regex_constants::match_default) = delete; +#endif + +#ifndef _LIBCPP_CXX03_LANG + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, + initializer_list<int> __submatches, + regex_constants::match_flag_type __m = + regex_constants::match_default); + +#if _LIBCPP_STD_VER > 11 + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type&& __re, + initializer_list<int> __submatches, + regex_constants::match_flag_type __m = + regex_constants::match_default) = delete; +#endif +#endif // _LIBCPP_CXX03_LANG + template <size_t _Np> + regex_token_iterator(_BidirectionalIterator __a, + _BidirectionalIterator __b, + const regex_type& __re, + const int (&__submatches)[_Np], + regex_constants::match_flag_type __m = + regex_constants::match_default); +#if _LIBCPP_STD_VER > 11 + template <std::size_t _Np> + regex_token_iterator(_BidirectionalIterator __a, + _BidirectionalIterator __b, + const regex_type&& __re, + const int (&__submatches)[_Np], + regex_constants::match_flag_type __m = + regex_constants::match_default) = delete; +#endif + + regex_token_iterator(const regex_token_iterator&); + regex_token_iterator& operator=(const regex_token_iterator&); + + bool operator==(const regex_token_iterator& __x) const; + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} + + _LIBCPP_INLINE_VISIBILITY + const value_type& operator*() const {return *__result_;} + _LIBCPP_INLINE_VISIBILITY + const value_type* operator->() const {return __result_;} + + regex_token_iterator& operator++(); + _LIBCPP_INLINE_VISIBILITY + regex_token_iterator operator++(int) + { + regex_token_iterator __t(*this); + ++(*this); + return __t; + } + +private: + void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); + void __establish_result () { + if (__subs_[__n_] == -1) + __result_ = &__position_->prefix(); + else + __result_ = &(*__position_)[__subs_[__n_]]; + } +}; + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator() + : __result_(nullptr), + __suffix_(), + __n_(0) +{ +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +void +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + __init(_BidirectionalIterator __a, _BidirectionalIterator __b) +{ + if (__position_ != _Position()) + __establish_result (); + else if (__subs_[__n_] == -1) + { + __suffix_.matched = true; + __suffix_.first = __a; + __suffix_.second = __b; + __result_ = &__suffix_; + } + else + __result_ = nullptr; +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, int __submatch, + regex_constants::match_flag_type __m) + : __position_(__a, __b, __re, __m), + __n_(0), + __subs_(1, __submatch) +{ + __init(__a, __b); +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, const vector<int>& __submatches, + regex_constants::match_flag_type __m) + : __position_(__a, __b, __re, __m), + __n_(0), + __subs_(__submatches) +{ + __init(__a, __b); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, + initializer_list<int> __submatches, + regex_constants::match_flag_type __m) + : __position_(__a, __b, __re, __m), + __n_(0), + __subs_(__submatches) +{ + __init(__a, __b); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _BidirectionalIterator, class _CharT, class _Traits> +template <size_t _Np> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, + const regex_type& __re, + const int (&__submatches)[_Np], + regex_constants::match_flag_type __m) + : __position_(__a, __b, __re, __m), + __n_(0), + __subs_(begin(__submatches), end(__submatches)) +{ + __init(__a, __b); +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + regex_token_iterator(const regex_token_iterator& __x) + : __position_(__x.__position_), + __result_(__x.__result_), + __suffix_(__x.__suffix_), + __n_(__x.__n_), + __subs_(__x.__subs_) +{ + if (__x.__result_ == &__x.__suffix_) + __result_ = &__suffix_; + else if ( __result_ != nullptr ) + __establish_result (); +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + operator=(const regex_token_iterator& __x) +{ + if (this != &__x) + { + __position_ = __x.__position_; + if (__x.__result_ == &__x.__suffix_) + __result_ = &__suffix_; + else + __result_ = __x.__result_; + __suffix_ = __x.__suffix_; + __n_ = __x.__n_; + __subs_ = __x.__subs_; + + if ( __result_ != nullptr && __result_ != &__suffix_ ) + __establish_result(); + } + return *this; +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +bool +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: + operator==(const regex_token_iterator& __x) const +{ + if (__result_ == nullptr && __x.__result_ == nullptr) + return true; + if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && + __suffix_ == __x.__suffix_) + return true; + if (__result_ == nullptr || __x.__result_ == nullptr) + return false; + if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) + return false; + return __position_ == __x.__position_ && __n_ == __x.__n_ && + __subs_ == __x.__subs_; +} + +template <class _BidirectionalIterator, class _CharT, class _Traits> +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& +regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() +{ + _Position __prev = __position_; + if (__result_ == &__suffix_) + __result_ = nullptr; + else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) + { + ++__n_; + __establish_result(); + } + else + { + __n_ = 0; + ++__position_; + if (__position_ != _Position()) + __establish_result(); + else + { + if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() + && __prev->suffix().length() != 0) + { + __suffix_.matched = true; + __suffix_.first = __prev->suffix().first; + __suffix_.second = __prev->suffix().second; + __result_ = &__suffix_; + } + else + __result_ = nullptr; + } + } + return *this; +} + +typedef regex_token_iterator<const char*> cregex_token_iterator; +typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; +typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; +typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; + +// regex_replace + +template <class _OutputIterator, class _BidirectionalIterator, + class _Traits, class _CharT> +_OutputIterator +regex_replace(_OutputIterator __output_iter, + _BidirectionalIterator __first, _BidirectionalIterator __last, + const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; + _Iter __i(__first, __last, __e, __flags); + _Iter __eof; + if (__i == __eof) + { + if (!(__flags & regex_constants::format_no_copy)) + __output_iter = _VSTD::copy(__first, __last, __output_iter); + } + else + { + sub_match<_BidirectionalIterator> __lm; + for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) + { + if (!(__flags & regex_constants::format_no_copy)) + __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter); + __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags); + __lm = __i->suffix(); + if (__flags & regex_constants::format_first_only) + break; + } + if (!(__flags & regex_constants::format_no_copy)) + __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter); + } + return __output_iter; +} + +template <class _OutputIterator, class _BidirectionalIterator, + class _Traits, class _CharT, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +regex_replace(_OutputIterator __output_iter, + _BidirectionalIterator __first, _BidirectionalIterator __last, + const basic_regex<_CharT, _Traits>& __e, + const basic_string<_CharT, _ST, _SA>& __fmt, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags); +} + +template <class _Traits, class _CharT, class _ST, class _SA, class _FST, + class _FSA> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _ST, _SA> +regex_replace(const basic_string<_CharT, _ST, _SA>& __s, + const basic_regex<_CharT, _Traits>& __e, + const basic_string<_CharT, _FST, _FSA>& __fmt, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + basic_string<_CharT, _ST, _SA> __r; + _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, + __fmt.c_str(), __flags); + return __r; +} + +template <class _Traits, class _CharT, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _ST, _SA> +regex_replace(const basic_string<_CharT, _ST, _SA>& __s, + const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + basic_string<_CharT, _ST, _SA> __r; + _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, + __fmt, __flags); + return __r; +} + +template <class _Traits, class _CharT, class _ST, class _SA> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT> +regex_replace(const _CharT* __s, + const basic_regex<_CharT, _Traits>& __e, + const basic_string<_CharT, _ST, _SA>& __fmt, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + basic_string<_CharT> __r; + _VSTD::regex_replace(back_inserter(__r), __s, + __s + char_traits<_CharT>::length(__s), __e, + __fmt.c_str(), __flags); + return __r; +} + +template <class _Traits, class _CharT> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT> +regex_replace(const _CharT* __s, + const basic_regex<_CharT, _Traits>& __e, + const _CharT* __fmt, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + basic_string<_CharT> __r; + _VSTD::regex_replace(back_inserter(__r), __s, + __s + char_traits<_CharT>::length(__s), __e, + __fmt, __flags); + return __r; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_REGEX diff --git a/android/x86/include/v8/libc++/scoped_allocator b/android/x86/include/v8/libc++/scoped_allocator new file mode 100755 index 00000000..237cd428 --- /dev/null +++ b/android/x86/include/v8/libc++/scoped_allocator @@ -0,0 +1,683 @@ +// -*- C++ -*- +//===-------------------------- scoped_allocator --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SCOPED_ALLOCATOR +#define _LIBCPP_SCOPED_ALLOCATOR + +/* + scoped_allocator synopsis + +namespace std +{ + +template <class OuterAlloc, class... InnerAllocs> +class scoped_allocator_adaptor : public OuterAlloc +{ + typedef allocator_traits<OuterAlloc> OuterTraits; // exposition only + scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only +public: + + typedef OuterAlloc outer_allocator_type; + typedef see below inner_allocator_type; + + typedef typename OuterTraits::value_type value_type; + typedef typename OuterTraits::size_type size_type; + typedef typename OuterTraits::difference_type difference_type; + typedef typename OuterTraits::pointer pointer; + typedef typename OuterTraits::const_pointer const_pointer; + typedef typename OuterTraits::void_pointer void_pointer; + typedef typename OuterTraits::const_void_pointer const_void_pointer; + + typedef see below propagate_on_container_copy_assignment; + typedef see below propagate_on_container_move_assignment; + typedef see below propagate_on_container_swap; + typedef see below is_always_equal; + + template <class Tp> + struct rebind + { + typedef scoped_allocator_adaptor< + OuterTraits::template rebind_alloc<Tp>, InnerAllocs...> other; + }; + + scoped_allocator_adaptor(); + template <class OuterA2> + scoped_allocator_adaptor(OuterA2&& outerAlloc, + const InnerAllocs&... innerAllocs) noexcept; + scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept; + scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept; + template <class OuterA2> + scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept; + template <class OuterA2> + scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept; + + scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default; + scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default; + ~scoped_allocator_adaptor(); + + inner_allocator_type& inner_allocator() noexcept; + const inner_allocator_type& inner_allocator() const noexcept; + + outer_allocator_type& outer_allocator() noexcept; + const outer_allocator_type& outer_allocator() const noexcept; + + pointer allocate(size_type n); // [[nodiscard]] in C++20 + pointer allocate(size_type n, const_void_pointer hint); // [[nodiscard]] in C++20 + void deallocate(pointer p, size_type n) noexcept; + + size_type max_size() const; + template <class T, class... Args> void construct(T* p, Args&& args); + template <class T1, class T2, class... Args1, class... Args2> + void construct(pair<T1, T2>* p, piecewise_construct t, tuple<Args1...> x, + tuple<Args2...> y); + template <class T1, class T2> + void construct(pair<T1, T2>* p); + template <class T1, class T2, class U, class V> + void construct(pair<T1, T2>* p, U&& x, V&& y); + template <class T1, class T2, class U, class V> + void construct(pair<T1, T2>* p, const pair<U, V>& x); + template <class T1, class T2, class U, class V> + void construct(pair<T1, T2>* p, pair<U, V>&& x); + template <class T> void destroy(T* p); + + template <class T> void destroy(T* p) noexcept; + + scoped_allocator_adaptor select_on_container_copy_construction() const noexcept; +}; + +template <class OuterA1, class OuterA2, class... InnerAllocs> + bool + operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, + const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept; + +template <class OuterA1, class OuterA2, class... InnerAllocs> + bool + operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, + const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept; + +} // std + +*/ + +#include <__config> +#include <memory> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_CXX03_LANG) + +// scoped_allocator_adaptor + +template <class ..._Allocs> +class scoped_allocator_adaptor; + +template <class ..._Allocs> struct __get_poc_copy_assignment; + +template <class _A0> +struct __get_poc_copy_assignment<_A0> +{ + static const bool value = allocator_traits<_A0>:: + propagate_on_container_copy_assignment::value; +}; + +template <class _A0, class ..._Allocs> +struct __get_poc_copy_assignment<_A0, _Allocs...> +{ + static const bool value = + allocator_traits<_A0>::propagate_on_container_copy_assignment::value || + __get_poc_copy_assignment<_Allocs...>::value; +}; + +template <class ..._Allocs> struct __get_poc_move_assignment; + +template <class _A0> +struct __get_poc_move_assignment<_A0> +{ + static const bool value = allocator_traits<_A0>:: + propagate_on_container_move_assignment::value; +}; + +template <class _A0, class ..._Allocs> +struct __get_poc_move_assignment<_A0, _Allocs...> +{ + static const bool value = + allocator_traits<_A0>::propagate_on_container_move_assignment::value || + __get_poc_move_assignment<_Allocs...>::value; +}; + +template <class ..._Allocs> struct __get_poc_swap; + +template <class _A0> +struct __get_poc_swap<_A0> +{ + static const bool value = allocator_traits<_A0>:: + propagate_on_container_swap::value; +}; + +template <class _A0, class ..._Allocs> +struct __get_poc_swap<_A0, _Allocs...> +{ + static const bool value = + allocator_traits<_A0>::propagate_on_container_swap::value || + __get_poc_swap<_Allocs...>::value; +}; + +template <class ..._Allocs> struct __get_is_always_equal; + +template <class _A0> +struct __get_is_always_equal<_A0> +{ + static const bool value = allocator_traits<_A0>::is_always_equal::value; +}; + +template <class _A0, class ..._Allocs> +struct __get_is_always_equal<_A0, _Allocs...> +{ + static const bool value = + allocator_traits<_A0>::is_always_equal::value && + __get_is_always_equal<_Allocs...>::value; +}; + +template <class ..._Allocs> +class __scoped_allocator_storage; + +template <class _OuterAlloc, class... _InnerAllocs> +class __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> + : public _OuterAlloc +{ + typedef _OuterAlloc outer_allocator_type; +protected: + typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type; + +private: + inner_allocator_type __inner_; + +protected: + + _LIBCPP_INLINE_VISIBILITY + __scoped_allocator_storage() _NOEXCEPT {} + + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, _OuterA2>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + __scoped_allocator_storage(_OuterA2&& __outerAlloc, + const _InnerAllocs& ...__innerAllocs) _NOEXCEPT + : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)), + __inner_(__innerAllocs...) {} + + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, const _OuterA2&>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + __scoped_allocator_storage( + const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT + : outer_allocator_type(__other.outer_allocator()), + __inner_(__other.inner_allocator()) {} + + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, _OuterA2>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + __scoped_allocator_storage( + __scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT + : outer_allocator_type(_VSTD::move(__other.outer_allocator())), + __inner_(_VSTD::move(__other.inner_allocator())) {} + + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, _OuterA2>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + __scoped_allocator_storage(_OuterA2&& __o, + const inner_allocator_type& __i) _NOEXCEPT + : outer_allocator_type(_VSTD::forward<_OuterA2>(__o)), + __inner_(__i) + { + } + + _LIBCPP_INLINE_VISIBILITY + inner_allocator_type& inner_allocator() _NOEXCEPT {return __inner_;} + _LIBCPP_INLINE_VISIBILITY + const inner_allocator_type& inner_allocator() const _NOEXCEPT {return __inner_;} + + _LIBCPP_INLINE_VISIBILITY + outer_allocator_type& outer_allocator() _NOEXCEPT + {return static_cast<outer_allocator_type&>(*this);} + _LIBCPP_INLINE_VISIBILITY + const outer_allocator_type& outer_allocator() const _NOEXCEPT + {return static_cast<const outer_allocator_type&>(*this);} + + scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...> + _LIBCPP_INLINE_VISIBILITY + select_on_container_copy_construction() const _NOEXCEPT + { + return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...> + ( + allocator_traits<outer_allocator_type>:: + select_on_container_copy_construction(outer_allocator()), + allocator_traits<inner_allocator_type>:: + select_on_container_copy_construction(inner_allocator()) + ); + } + + template <class...> friend class __scoped_allocator_storage; +}; + +template <class _OuterAlloc> +class __scoped_allocator_storage<_OuterAlloc> + : public _OuterAlloc +{ + typedef _OuterAlloc outer_allocator_type; +protected: + typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type; + + _LIBCPP_INLINE_VISIBILITY + __scoped_allocator_storage() _NOEXCEPT {} + + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, _OuterA2>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + __scoped_allocator_storage(_OuterA2&& __outerAlloc) _NOEXCEPT + : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)) {} + + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, const _OuterA2&>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + __scoped_allocator_storage( + const __scoped_allocator_storage<_OuterA2>& __other) _NOEXCEPT + : outer_allocator_type(__other.outer_allocator()) {} + + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, _OuterA2>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + __scoped_allocator_storage( + __scoped_allocator_storage<_OuterA2>&& __other) _NOEXCEPT + : outer_allocator_type(_VSTD::move(__other.outer_allocator())) {} + + _LIBCPP_INLINE_VISIBILITY + inner_allocator_type& inner_allocator() _NOEXCEPT + {return static_cast<inner_allocator_type&>(*this);} + _LIBCPP_INLINE_VISIBILITY + const inner_allocator_type& inner_allocator() const _NOEXCEPT + {return static_cast<const inner_allocator_type&>(*this);} + + _LIBCPP_INLINE_VISIBILITY + outer_allocator_type& outer_allocator() _NOEXCEPT + {return static_cast<outer_allocator_type&>(*this);} + _LIBCPP_INLINE_VISIBILITY + const outer_allocator_type& outer_allocator() const _NOEXCEPT + {return static_cast<const outer_allocator_type&>(*this);} + + _LIBCPP_INLINE_VISIBILITY + scoped_allocator_adaptor<outer_allocator_type> + select_on_container_copy_construction() const _NOEXCEPT + {return scoped_allocator_adaptor<outer_allocator_type>( + allocator_traits<outer_allocator_type>:: + select_on_container_copy_construction(outer_allocator()) + );} + + __scoped_allocator_storage(const outer_allocator_type& __o, + const inner_allocator_type& __i) _NOEXCEPT; + + template <class...> friend class __scoped_allocator_storage; +}; + +// __outermost + +template <class _Alloc> +decltype(declval<_Alloc>().outer_allocator(), true_type()) +__has_outer_allocator_test(_Alloc&& __a); + +template <class _Alloc> +false_type +__has_outer_allocator_test(const volatile _Alloc& __a); + +template <class _Alloc> +struct __has_outer_allocator + : public common_type + < + decltype(__has_outer_allocator_test(declval<_Alloc&>())) + >::type +{ +}; + +template <class _Alloc, bool = __has_outer_allocator<_Alloc>::value> +struct __outermost +{ + typedef _Alloc type; + _LIBCPP_INLINE_VISIBILITY + type& operator()(type& __a) const _NOEXCEPT {return __a;} +}; + +template <class _Alloc> +struct __outermost<_Alloc, true> +{ + typedef typename remove_reference + < + decltype(_VSTD::declval<_Alloc>().outer_allocator()) + >::type _OuterAlloc; + typedef typename __outermost<_OuterAlloc>::type type; + _LIBCPP_INLINE_VISIBILITY + type& operator()(_Alloc& __a) const _NOEXCEPT + {return __outermost<_OuterAlloc>()(__a.outer_allocator());} +}; + +template <class _OuterAlloc, class... _InnerAllocs> +class _LIBCPP_TEMPLATE_VIS scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...> + : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> +{ + typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base; + typedef allocator_traits<_OuterAlloc> _OuterTraits; +public: + typedef _OuterAlloc outer_allocator_type; + typedef typename base::inner_allocator_type inner_allocator_type; + typedef typename _OuterTraits::size_type size_type; + typedef typename _OuterTraits::difference_type difference_type; + typedef typename _OuterTraits::pointer pointer; + typedef typename _OuterTraits::const_pointer const_pointer; + typedef typename _OuterTraits::void_pointer void_pointer; + typedef typename _OuterTraits::const_void_pointer const_void_pointer; + + typedef integral_constant + < + bool, + __get_poc_copy_assignment<outer_allocator_type, + _InnerAllocs...>::value + > propagate_on_container_copy_assignment; + typedef integral_constant + < + bool, + __get_poc_move_assignment<outer_allocator_type, + _InnerAllocs...>::value + > propagate_on_container_move_assignment; + typedef integral_constant + < + bool, + __get_poc_swap<outer_allocator_type, _InnerAllocs...>::value + > propagate_on_container_swap; + typedef integral_constant + < + bool, + __get_is_always_equal<outer_allocator_type, _InnerAllocs...>::value + > is_always_equal; + + template <class _Tp> + struct rebind + { + typedef scoped_allocator_adaptor + < + typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs... + > other; + }; + + _LIBCPP_INLINE_VISIBILITY + scoped_allocator_adaptor() _NOEXCEPT {} + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, _OuterA2>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + scoped_allocator_adaptor(_OuterA2&& __outerAlloc, + const _InnerAllocs& ...__innerAllocs) _NOEXCEPT + : base(_VSTD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {} + // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default; + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, const _OuterA2&>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + scoped_allocator_adaptor( + const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT + : base(__other) {} + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, _OuterA2>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + scoped_allocator_adaptor( + scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT + : base(_VSTD::move(__other)) {} + + // scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default; + // scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default; + // ~scoped_allocator_adaptor() = default; + + _LIBCPP_INLINE_VISIBILITY + inner_allocator_type& inner_allocator() _NOEXCEPT + {return base::inner_allocator();} + _LIBCPP_INLINE_VISIBILITY + const inner_allocator_type& inner_allocator() const _NOEXCEPT + {return base::inner_allocator();} + + _LIBCPP_INLINE_VISIBILITY + outer_allocator_type& outer_allocator() _NOEXCEPT + {return base::outer_allocator();} + _LIBCPP_INLINE_VISIBILITY + const outer_allocator_type& outer_allocator() const _NOEXCEPT + {return base::outer_allocator();} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + pointer allocate(size_type __n) + {return allocator_traits<outer_allocator_type>:: + allocate(outer_allocator(), __n);} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + pointer allocate(size_type __n, const_void_pointer __hint) + {return allocator_traits<outer_allocator_type>:: + allocate(outer_allocator(), __n, __hint);} + + _LIBCPP_INLINE_VISIBILITY + void deallocate(pointer __p, size_type __n) _NOEXCEPT + {allocator_traits<outer_allocator_type>:: + deallocate(outer_allocator(), __p, __n);} + + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const + {return allocator_traits<outer_allocator_type>::max_size(outer_allocator());} + + template <class _Tp, class... _Args> + _LIBCPP_INLINE_VISIBILITY + void construct(_Tp* __p, _Args&& ...__args) + {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(), + __p, _VSTD::forward<_Args>(__args)...);} + + template <class _T1, class _T2, class... _Args1, class... _Args2> + void construct(pair<_T1, _T2>* __p, piecewise_construct_t, + tuple<_Args1...> __x, tuple<_Args2...> __y) + { + typedef __outermost<outer_allocator_type> _OM; + allocator_traits<typename _OM::type>::construct( + _OM()(outer_allocator()), __p, piecewise_construct + , __transform_tuple( + typename __uses_alloc_ctor< + _T1, inner_allocator_type&, _Args1... + >::type() + , _VSTD::move(__x) + , typename __make_tuple_indices<sizeof...(_Args1)>::type{} + ) + , __transform_tuple( + typename __uses_alloc_ctor< + _T2, inner_allocator_type&, _Args2... + >::type() + , _VSTD::move(__y) + , typename __make_tuple_indices<sizeof...(_Args2)>::type{} + ) + ); + } + + template <class _T1, class _T2> + void construct(pair<_T1, _T2>* __p) + { construct(__p, piecewise_construct, tuple<>{}, tuple<>{}); } + + template <class _T1, class _T2, class _Up, class _Vp> + void construct(pair<_T1, _T2>* __p, _Up&& __x, _Vp&& __y) { + construct(__p, piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x)), + _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__y))); + } + + template <class _T1, class _T2, class _Up, class _Vp> + void construct(pair<_T1, _T2>* __p, const pair<_Up, _Vp>& __x) { + construct(__p, piecewise_construct, + _VSTD::forward_as_tuple(__x.first), + _VSTD::forward_as_tuple(__x.second)); + } + + template <class _T1, class _T2, class _Up, class _Vp> + void construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) { + construct(__p, piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x.first)), + _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__x.second))); + } + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + void destroy(_Tp* __p) + { + typedef __outermost<outer_allocator_type> _OM; + allocator_traits<typename _OM::type>:: + destroy(_OM()(outer_allocator()), __p); + } + + _LIBCPP_INLINE_VISIBILITY + scoped_allocator_adaptor select_on_container_copy_construction() const _NOEXCEPT + {return base::select_on_container_copy_construction();} + +private: + + + template <class _OuterA2, + class = typename enable_if< + is_constructible<outer_allocator_type, _OuterA2>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + scoped_allocator_adaptor(_OuterA2&& __o, + const inner_allocator_type& __i) _NOEXCEPT + : base(_VSTD::forward<_OuterA2>(__o), __i) {} + + template <class _Tp, class... _Args> + _LIBCPP_INLINE_VISIBILITY + void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args) + { + typedef __outermost<outer_allocator_type> _OM; + allocator_traits<typename _OM::type>::construct + ( + _OM()(outer_allocator()), + __p, + _VSTD::forward<_Args>(__args)... + ); + } + + template <class _Tp, class... _Args> + _LIBCPP_INLINE_VISIBILITY + void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args) + { + typedef __outermost<outer_allocator_type> _OM; + allocator_traits<typename _OM::type>::construct + ( + _OM()(outer_allocator()), + __p, allocator_arg, inner_allocator(), + _VSTD::forward<_Args>(__args)... + ); + } + + template <class _Tp, class... _Args> + _LIBCPP_INLINE_VISIBILITY + void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args) + { + typedef __outermost<outer_allocator_type> _OM; + allocator_traits<typename _OM::type>::construct + ( + _OM()(outer_allocator()), + __p, + _VSTD::forward<_Args>(__args)..., + inner_allocator() + ); + } + + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<_Args&&...> + __transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t, + __tuple_indices<_Idx...>) + { + return _VSTD::forward_as_tuple(_VSTD::get<_Idx>(_VSTD::move(__t))...); + } + + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<allocator_arg_t, inner_allocator_type&, _Args&&...> + __transform_tuple(integral_constant<int, 1>, tuple<_Args...> && __t, + __tuple_indices<_Idx...>) + { + using _Tup = tuple<allocator_arg_t, inner_allocator_type&, _Args&&...>; + return _Tup(allocator_arg, inner_allocator(), + _VSTD::get<_Idx>(_VSTD::move(__t))...); + } + + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<_Args&&..., inner_allocator_type&> + __transform_tuple(integral_constant<int, 2>, tuple<_Args...> && __t, + __tuple_indices<_Idx...>) + { + using _Tup = tuple<_Args&&..., inner_allocator_type&>; + return _Tup(_VSTD::get<_Idx>(_VSTD::move(__t))..., inner_allocator()); + } + + template <class...> friend class __scoped_allocator_storage; +}; + +template <class _OuterA1, class _OuterA2> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const scoped_allocator_adaptor<_OuterA1>& __a, + const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT +{ + return __a.outer_allocator() == __b.outer_allocator(); +} + +template <class _OuterA1, class _OuterA2, class _InnerA0, class... _InnerAllocs> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const scoped_allocator_adaptor<_OuterA1, _InnerA0, _InnerAllocs...>& __a, + const scoped_allocator_adaptor<_OuterA2, _InnerA0, _InnerAllocs...>& __b) _NOEXCEPT +{ + return __a.outer_allocator() == __b.outer_allocator() && + __a.inner_allocator() == __b.inner_allocator(); +} + +template <class _OuterA1, class _OuterA2, class... _InnerAllocs> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a, + const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) _NOEXCEPT +{ + return !(__a == __b); +} + +#endif // !defined(_LIBCPP_CXX03_LANG) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_SCOPED_ALLOCATOR diff --git a/android/x86/include/v8/libc++/set b/android/x86/include/v8/libc++/set new file mode 100755 index 00000000..4574f69f --- /dev/null +++ b/android/x86/include/v8/libc++/set @@ -0,0 +1,1424 @@ +// -*- C++ -*- +//===---------------------------- set -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SET +#define _LIBCPP_SET + +/* + + set synopsis + +namespace std +{ + +template <class Key, class Compare = less<Key>, + class Allocator = allocator<Key>> +class set +{ +public: + // types: + typedef Key key_type; + typedef key_type value_type; + typedef Compare key_compare; + typedef key_compare value_compare; + typedef Allocator allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + typedef unspecified node_type; // C++17 + typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17 + + // construct/copy/destroy: + set() + noexcept( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_default_constructible<key_compare>::value && + is_nothrow_copy_constructible<key_compare>::value); + explicit set(const value_compare& comp); + set(const value_compare& comp, const allocator_type& a); + template <class InputIterator> + set(InputIterator first, InputIterator last, + const value_compare& comp = value_compare()); + template <class InputIterator> + set(InputIterator first, InputIterator last, const value_compare& comp, + const allocator_type& a); + set(const set& s); + set(set&& s) + noexcept( + is_nothrow_move_constructible<allocator_type>::value && + is_nothrow_move_constructible<key_compare>::value); + explicit set(const allocator_type& a); + set(const set& s, const allocator_type& a); + set(set&& s, const allocator_type& a); + set(initializer_list<value_type> il, const value_compare& comp = value_compare()); + set(initializer_list<value_type> il, const value_compare& comp, + const allocator_type& a); + template <class InputIterator> + set(InputIterator first, InputIterator last, const allocator_type& a) + : set(first, last, Compare(), a) {} // C++14 + set(initializer_list<value_type> il, const allocator_type& a) + : set(il, Compare(), a) {} // C++14 + ~set(); + + set& operator=(const set& s); + set& operator=(set&& s) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value && + is_nothrow_move_assignable<key_compare>::value); + set& operator=(initializer_list<value_type> il); + + // iterators: + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + // modifiers: + template <class... Args> + pair<iterator, bool> emplace(Args&&... args); + template <class... Args> + iterator emplace_hint(const_iterator position, Args&&... args); + pair<iterator,bool> insert(const value_type& v); + pair<iterator,bool> insert(value_type&& v); + iterator insert(const_iterator position, const value_type& v); + iterator insert(const_iterator position, value_type&& v); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + void insert(initializer_list<value_type> il); + + node_type extract(const_iterator position); // C++17 + node_type extract(const key_type& x); // C++17 + insert_return_type insert(node_type&& nh); // C++17 + iterator insert(const_iterator hint, node_type&& nh); // C++17 + + iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + template<class C2> + void merge(set<Key, C2, Allocator>& source); // C++17 + template<class C2> + void merge(set<Key, C2, Allocator>&& source); // C++17 + template<class C2> + void merge(multiset<Key, C2, Allocator>& source); // C++17 + template<class C2> + void merge(multiset<Key, C2, Allocator>&& source); // C++17 + + void swap(set& s) + noexcept( + __is_nothrow_swappable<key_compare>::value && + (!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value)); + + // observers: + allocator_type get_allocator() const noexcept; + key_compare key_comp() const; + value_compare value_comp() const; + + // set operations: + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + template<typename K> + iterator find(const K& x); + template<typename K> + const_iterator find(const K& x) const; // C++14 + template<typename K> + size_type count(const K& x) const; // C++14 + + size_type count(const key_type& k) const; + iterator lower_bound(const key_type& k); + const_iterator lower_bound(const key_type& k) const; + template<typename K> + iterator lower_bound(const K& x); // C++14 + template<typename K> + const_iterator lower_bound(const K& x) const; // C++14 + + iterator upper_bound(const key_type& k); + const_iterator upper_bound(const key_type& k) const; + template<typename K> + iterator upper_bound(const K& x); // C++14 + template<typename K> + const_iterator upper_bound(const K& x) const; // C++14 + pair<iterator,iterator> equal_range(const key_type& k); + pair<const_iterator,const_iterator> equal_range(const key_type& k) const; + template<typename K> + pair<iterator,iterator> equal_range(const K& x); // C++14 + template<typename K> + pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14 +}; + +template <class Key, class Compare, class Allocator> +bool +operator==(const set<Key, Compare, Allocator>& x, + const set<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator< (const set<Key, Compare, Allocator>& x, + const set<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator!=(const set<Key, Compare, Allocator>& x, + const set<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator> (const set<Key, Compare, Allocator>& x, + const set<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator>=(const set<Key, Compare, Allocator>& x, + const set<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator<=(const set<Key, Compare, Allocator>& x, + const set<Key, Compare, Allocator>& y); + +// specialized algorithms: +template <class Key, class Compare, class Allocator> +void +swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y) + noexcept(noexcept(x.swap(y))); + +template <class Key, class Compare, class Allocator, class Predicate> + void erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20 + +template <class Key, class Compare = less<Key>, + class Allocator = allocator<Key>> +class multiset +{ +public: + // types: + typedef Key key_type; + typedef key_type value_type; + typedef Compare key_compare; + typedef key_compare value_compare; + typedef Allocator allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + typedef unspecified node_type; // C++17 + + // construct/copy/destroy: + multiset() + noexcept( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_default_constructible<key_compare>::value && + is_nothrow_copy_constructible<key_compare>::value); + explicit multiset(const value_compare& comp); + multiset(const value_compare& comp, const allocator_type& a); + template <class InputIterator> + multiset(InputIterator first, InputIterator last, + const value_compare& comp = value_compare()); + template <class InputIterator> + multiset(InputIterator first, InputIterator last, + const value_compare& comp, const allocator_type& a); + multiset(const multiset& s); + multiset(multiset&& s) + noexcept( + is_nothrow_move_constructible<allocator_type>::value && + is_nothrow_move_constructible<key_compare>::value); + explicit multiset(const allocator_type& a); + multiset(const multiset& s, const allocator_type& a); + multiset(multiset&& s, const allocator_type& a); + multiset(initializer_list<value_type> il, const value_compare& comp = value_compare()); + multiset(initializer_list<value_type> il, const value_compare& comp, + const allocator_type& a); + template <class InputIterator> + multiset(InputIterator first, InputIterator last, const allocator_type& a) + : set(first, last, Compare(), a) {} // C++14 + multiset(initializer_list<value_type> il, const allocator_type& a) + : set(il, Compare(), a) {} // C++14 + ~multiset(); + + multiset& operator=(const multiset& s); + multiset& operator=(multiset&& s) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value && + is_nothrow_move_assignable<key_compare>::value); + multiset& operator=(initializer_list<value_type> il); + + // iterators: + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + // modifiers: + template <class... Args> + iterator emplace(Args&&... args); + template <class... Args> + iterator emplace_hint(const_iterator position, Args&&... args); + iterator insert(const value_type& v); + iterator insert(value_type&& v); + iterator insert(const_iterator position, const value_type& v); + iterator insert(const_iterator position, value_type&& v); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + void insert(initializer_list<value_type> il); + + node_type extract(const_iterator position); // C++17 + node_type extract(const key_type& x); // C++17 + iterator insert(node_type&& nh); // C++17 + iterator insert(const_iterator hint, node_type&& nh); // C++17 + + iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + template<class C2> + void merge(multiset<Key, C2, Allocator>& source); // C++17 + template<class C2> + void merge(multiset<Key, C2, Allocator>&& source); // C++17 + template<class C2> + void merge(set<Key, C2, Allocator>& source); // C++17 + template<class C2> + void merge(set<Key, C2, Allocator>&& source); // C++17 + + void swap(multiset& s) + noexcept( + __is_nothrow_swappable<key_compare>::value && + (!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value)); + + // observers: + allocator_type get_allocator() const noexcept; + key_compare key_comp() const; + value_compare value_comp() const; + + // set operations: + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + template<typename K> + iterator find(const K& x); + template<typename K> + const_iterator find(const K& x) const; // C++14 + + size_type count(const key_type& k) const; + iterator lower_bound(const key_type& k); + const_iterator lower_bound(const key_type& k) const; + template<typename K> + iterator lower_bound(const K& x); // C++14 + template<typename K> + const_iterator lower_bound(const K& x) const; // C++14 + + iterator upper_bound(const key_type& k); + const_iterator upper_bound(const key_type& k) const; + template<typename K> + iterator upper_bound(const K& x); // C++14 + template<typename K> + const_iterator upper_bound(const K& x) const; // C++14 + + pair<iterator,iterator> equal_range(const key_type& k); + pair<const_iterator,const_iterator> equal_range(const key_type& k) const; + template<typename K> + pair<iterator,iterator> equal_range(const K& x); // C++14 + template<typename K> + pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14 +}; + +template <class Key, class Compare, class Allocator> +bool +operator==(const multiset<Key, Compare, Allocator>& x, + const multiset<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator< (const multiset<Key, Compare, Allocator>& x, + const multiset<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator!=(const multiset<Key, Compare, Allocator>& x, + const multiset<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator> (const multiset<Key, Compare, Allocator>& x, + const multiset<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator>=(const multiset<Key, Compare, Allocator>& x, + const multiset<Key, Compare, Allocator>& y); + +template <class Key, class Compare, class Allocator> +bool +operator<=(const multiset<Key, Compare, Allocator>& x, + const multiset<Key, Compare, Allocator>& y); + +// specialized algorithms: +template <class Key, class Compare, class Allocator> +void +swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y) + noexcept(noexcept(x.swap(y))); + +template <class Key, class Compare, class Allocator, class Predicate> + void erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20 + +} // std + +*/ + +#include <__config> +#include <__tree> +#include <__node_handle> +#include <functional> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Key, class _Compare, class _Allocator> +class multiset; + +template <class _Key, class _Compare = less<_Key>, + class _Allocator = allocator<_Key> > +class _LIBCPP_TEMPLATE_VIS set +{ +public: + // types: + typedef _Key key_type; + typedef key_type value_type; + typedef _Compare key_compare; + typedef key_compare value_compare; + typedef _Allocator allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + + static_assert((is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + +private: + typedef __tree<value_type, value_compare, allocator_type> __base; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __base::__node_holder __node_holder; + + __base __tree_; + +public: + typedef typename __base::pointer pointer; + typedef typename __base::const_pointer const_pointer; + typedef typename __base::size_type size_type; + typedef typename __base::difference_type difference_type; + typedef typename __base::const_iterator iterator; + typedef typename __base::const_iterator const_iterator; + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + +#if _LIBCPP_STD_VER > 14 + typedef __set_node_handle<typename __base::__node, allocator_type> node_type; + typedef __insert_return_type<iterator, node_type> insert_return_type; +#endif + + template <class _Key2, class _Compare2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS set; + template <class _Key2, class _Compare2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS multiset; + + _LIBCPP_INLINE_VISIBILITY + set() + _NOEXCEPT_( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_default_constructible<key_compare>::value && + is_nothrow_copy_constructible<key_compare>::value) + : __tree_(value_compare()) {} + + _LIBCPP_INLINE_VISIBILITY + explicit set(const value_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_copy_constructible<key_compare>::value) + : __tree_(__comp) {} + + _LIBCPP_INLINE_VISIBILITY + explicit set(const value_compare& __comp, const allocator_type& __a) + : __tree_(__comp, __a) {} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + set(_InputIterator __f, _InputIterator __l, + const value_compare& __comp = value_compare()) + : __tree_(__comp) + { + insert(__f, __l); + } + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + set(_InputIterator __f, _InputIterator __l, const value_compare& __comp, + const allocator_type& __a) + : __tree_(__comp, __a) + { + insert(__f, __l); + } + +#if _LIBCPP_STD_VER > 11 + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + set(_InputIterator __f, _InputIterator __l, const allocator_type& __a) + : set(__f, __l, key_compare(), __a) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + set(const set& __s) + : __tree_(__s.__tree_) + { + insert(__s.begin(), __s.end()); + } + + _LIBCPP_INLINE_VISIBILITY + set& operator=(const set& __s) + { + __tree_ = __s.__tree_; + return *this; + } + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + set(set&& __s) + _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) + : __tree_(_VSTD::move(__s.__tree_)) {} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + explicit set(const allocator_type& __a) + : __tree_(__a) {} + + _LIBCPP_INLINE_VISIBILITY + set(const set& __s, const allocator_type& __a) + : __tree_(__s.__tree_.value_comp(), __a) + { + insert(__s.begin(), __s.end()); + } + +#ifndef _LIBCPP_CXX03_LANG + set(set&& __s, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + set(initializer_list<value_type> __il, const value_compare& __comp = value_compare()) + : __tree_(__comp) + { + insert(__il.begin(), __il.end()); + } + + _LIBCPP_INLINE_VISIBILITY + set(initializer_list<value_type> __il, const value_compare& __comp, + const allocator_type& __a) + : __tree_(__comp, __a) + { + insert(__il.begin(), __il.end()); + } + +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + set(initializer_list<value_type> __il, const allocator_type& __a) + : set(__il, key_compare(), __a) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + set& operator=(initializer_list<value_type> __il) + { + __tree_.__assign_unique(__il.begin(), __il.end()); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + set& operator=(set&& __s) + _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) + { + __tree_ = _VSTD::move(__s.__tree_); + return *this; + } +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + ~set() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __tree_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __tree_.end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT {return rend();} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __tree_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __tree_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __tree_.max_size();} + + // modifiers: +#ifndef _LIBCPP_CXX03_LANG + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> emplace(_Args&&... __args) + {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);} + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator emplace_hint(const_iterator __p, _Args&&... __args) + {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + pair<iterator,bool> insert(const value_type& __v) + {return __tree_.__insert_unique(__v);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, const value_type& __v) + {return __tree_.__insert_unique(__p, __v);} + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __f, _InputIterator __l) + { + for (const_iterator __e = cend(); __f != __l; ++__f) + __tree_.__insert_unique(__e, *__f); + } + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + pair<iterator,bool> insert(value_type&& __v) + {return __tree_.__insert_unique(_VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, value_type&& __v) + {return __tree_.__insert_unique(__p, _VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __tree_.erase(__p);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) + {return __tree_.__erase_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __f, const_iterator __l) + {return __tree_.erase(__f, __l);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__tree_.clear();} + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + insert_return_type insert(node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to set::insert()"); + return __tree_.template __node_handle_insert_unique< + node_type, insert_return_type>(_VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __hint, node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to set::insert()"); + return __tree_.template __node_handle_insert_unique<node_type>( + __hint, _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(key_type const& __key) + { + return __tree_.template __node_handle_extract<node_type>(__key); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(const_iterator __it) + { + return __tree_.template __node_handle_extract<node_type>(__it); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(set<key_type, _Compare2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_unique(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(set<key_type, _Compare2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_unique(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(multiset<key_type, _Compare2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_unique(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(multiset<key_type, _Compare2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_unique(__source.__tree_); + } +#endif + + _LIBCPP_INLINE_VISIBILITY + void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) + {__tree_.swap(__s.__tree_);} + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();} + _LIBCPP_INLINE_VISIBILITY + key_compare key_comp() const {return __tree_.value_comp();} + _LIBCPP_INLINE_VISIBILITY + value_compare value_comp() const {return __tree_.value_comp();} + + // set operations: + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __tree_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __tree_.find(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type + find(const _K2& __k) {return __tree_.find(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type + find(const _K2& __k) const {return __tree_.find(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const + {return __tree_.__count_unique(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type + count(const _K2& __k) const {return __tree_.__count_multi(__k);} +#endif + _LIBCPP_INLINE_VISIBILITY + iterator lower_bound(const key_type& __k) + {return __tree_.lower_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator lower_bound(const key_type& __k) const + {return __tree_.lower_bound(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type + lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} + + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type + lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + iterator upper_bound(const key_type& __k) + {return __tree_.upper_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator upper_bound(const key_type& __k) const + {return __tree_.upper_bound(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type + upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type + upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + pair<iterator,iterator> equal_range(const key_type& __k) + {return __tree_.__equal_range_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator,const_iterator> equal_range(const key_type& __k) const + {return __tree_.__equal_range_unique(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type + equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type + equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} +#endif +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Key, class _Compare, class _Allocator> +set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a) + : __tree_(_VSTD::move(__s.__tree_), __a) +{ + if (__a != __s.get_allocator()) + { + const_iterator __e = cend(); + while (!__s.empty()) + insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_)); + } +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const set<_Key, _Compare, _Allocator>& __x, + const set<_Key, _Compare, _Allocator>& __y) +{ + return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const set<_Key, _Compare, _Allocator>& __x, + const set<_Key, _Compare, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const set<_Key, _Compare, _Allocator>& __x, + const set<_Key, _Compare, _Allocator>& __y) +{ + return !(__x == __y); +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const set<_Key, _Compare, _Allocator>& __x, + const set<_Key, _Compare, _Allocator>& __y) +{ + return __y < __x; +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const set<_Key, _Compare, _Allocator>& __x, + const set<_Key, _Compare, _Allocator>& __y) +{ + return !(__x < __y); +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const set<_Key, _Compare, _Allocator>& __x, + const set<_Key, _Compare, _Allocator>& __y) +{ + return !(__y < __x); +} + +// specialized algorithms: +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(set<_Key, _Compare, _Allocator>& __x, + set<_Key, _Compare, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Key, class _Compare, class _Allocator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) +{ __libcpp_erase_if_container(__c, __pred); } +#endif + +template <class _Key, class _Compare = less<_Key>, + class _Allocator = allocator<_Key> > +class _LIBCPP_TEMPLATE_VIS multiset +{ +public: + // types: + typedef _Key key_type; + typedef key_type value_type; + typedef _Compare key_compare; + typedef key_compare value_compare; + typedef _Allocator allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + + static_assert((is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + +private: + typedef __tree<value_type, value_compare, allocator_type> __base; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __base::__node_holder __node_holder; + + __base __tree_; + +public: + typedef typename __base::pointer pointer; + typedef typename __base::const_pointer const_pointer; + typedef typename __base::size_type size_type; + typedef typename __base::difference_type difference_type; + typedef typename __base::const_iterator iterator; + typedef typename __base::const_iterator const_iterator; + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + +#if _LIBCPP_STD_VER > 14 + typedef __set_node_handle<typename __base::__node, allocator_type> node_type; +#endif + + template <class _Key2, class _Compare2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS set; + template <class _Key2, class _Compare2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS multiset; + + // construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY + multiset() + _NOEXCEPT_( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_default_constructible<key_compare>::value && + is_nothrow_copy_constructible<key_compare>::value) + : __tree_(value_compare()) {} + + _LIBCPP_INLINE_VISIBILITY + explicit multiset(const value_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<allocator_type>::value && + is_nothrow_copy_constructible<key_compare>::value) + : __tree_(__comp) {} + + _LIBCPP_INLINE_VISIBILITY + explicit multiset(const value_compare& __comp, const allocator_type& __a) + : __tree_(__comp, __a) {} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + multiset(_InputIterator __f, _InputIterator __l, + const value_compare& __comp = value_compare()) + : __tree_(__comp) + { + insert(__f, __l); + } + +#if _LIBCPP_STD_VER > 11 + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a) + : multiset(__f, __l, key_compare(), __a) {} +#endif + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + multiset(_InputIterator __f, _InputIterator __l, + const value_compare& __comp, const allocator_type& __a) + : __tree_(__comp, __a) + { + insert(__f, __l); + } + + _LIBCPP_INLINE_VISIBILITY + multiset(const multiset& __s) + : __tree_(__s.__tree_.value_comp(), + __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc())) + { + insert(__s.begin(), __s.end()); + } + + _LIBCPP_INLINE_VISIBILITY + multiset& operator=(const multiset& __s) + { + __tree_ = __s.__tree_; + return *this; + } + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + multiset(multiset&& __s) + _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) + : __tree_(_VSTD::move(__s.__tree_)) {} + + multiset(multiset&& __s, const allocator_type& __a); +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit multiset(const allocator_type& __a) + : __tree_(__a) {} + _LIBCPP_INLINE_VISIBILITY + multiset(const multiset& __s, const allocator_type& __a) + : __tree_(__s.__tree_.value_comp(), __a) + { + insert(__s.begin(), __s.end()); + } + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare()) + : __tree_(__comp) + { + insert(__il.begin(), __il.end()); + } + + _LIBCPP_INLINE_VISIBILITY + multiset(initializer_list<value_type> __il, const value_compare& __comp, + const allocator_type& __a) + : __tree_(__comp, __a) + { + insert(__il.begin(), __il.end()); + } + +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + multiset(initializer_list<value_type> __il, const allocator_type& __a) + : multiset(__il, key_compare(), __a) {} +#endif + + _LIBCPP_INLINE_VISIBILITY + multiset& operator=(initializer_list<value_type> __il) + { + __tree_.__assign_multi(__il.begin(), __il.end()); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + multiset& operator=(multiset&& __s) + _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) + { + __tree_ = _VSTD::move(__s.__tree_); + return *this; + } +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + ~multiset() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __tree_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __tree_.end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT {return rend();} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __tree_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __tree_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __tree_.max_size();} + + // modifiers: +#ifndef _LIBCPP_CXX03_LANG + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator emplace(_Args&&... __args) + {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);} + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator emplace_hint(const_iterator __p, _Args&&... __args) + {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __v) + {return __tree_.__insert_multi(__v);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, const value_type& __v) + {return __tree_.__insert_multi(__p, __v);} + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __f, _InputIterator __l) + { + for (const_iterator __e = cend(); __f != __l; ++__f) + __tree_.__insert_multi(__e, *__f); + } + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + iterator insert(value_type&& __v) + {return __tree_.__insert_multi(_VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, value_type&& __v) + {return __tree_.__insert_multi(__p, _VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __tree_.erase(__p);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __f, const_iterator __l) + {return __tree_.erase(__f, __l);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__tree_.clear();} + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + iterator insert(node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to multiset::insert()"); + return __tree_.template __node_handle_insert_multi<node_type>( + _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __hint, node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to multiset::insert()"); + return __tree_.template __node_handle_insert_multi<node_type>( + __hint, _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(key_type const& __key) + { + return __tree_.template __node_handle_extract<node_type>(__key); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(const_iterator __it) + { + return __tree_.template __node_handle_extract<node_type>(__it); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(multiset<key_type, _Compare2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_multi(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(multiset<key_type, _Compare2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_multi(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(set<key_type, _Compare2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_multi(__source.__tree_); + } + template <class _Compare2> + _LIBCPP_INLINE_VISIBILITY + void merge(set<key_type, _Compare2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __tree_.__node_handle_merge_multi(__source.__tree_); + } +#endif + + _LIBCPP_INLINE_VISIBILITY + void swap(multiset& __s) + _NOEXCEPT_(__is_nothrow_swappable<__base>::value) + {__tree_.swap(__s.__tree_);} + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();} + _LIBCPP_INLINE_VISIBILITY + key_compare key_comp() const {return __tree_.value_comp();} + _LIBCPP_INLINE_VISIBILITY + value_compare value_comp() const {return __tree_.value_comp();} + + // set operations: + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __tree_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __tree_.find(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type + find(const _K2& __k) {return __tree_.find(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type + find(const _K2& __k) const {return __tree_.find(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const + {return __tree_.__count_multi(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type + count(const _K2& __k) const {return __tree_.__count_multi(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + iterator lower_bound(const key_type& __k) + {return __tree_.lower_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator lower_bound(const key_type& __k) const + {return __tree_.lower_bound(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type + lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} + + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type + lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + iterator upper_bound(const key_type& __k) + {return __tree_.upper_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator upper_bound(const key_type& __k) const + {return __tree_.upper_bound(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type + upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type + upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} +#endif + + _LIBCPP_INLINE_VISIBILITY + pair<iterator,iterator> equal_range(const key_type& __k) + {return __tree_.__equal_range_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator,const_iterator> equal_range(const key_type& __k) const + {return __tree_.__equal_range_multi(__k);} +#if _LIBCPP_STD_VER > 11 + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type + equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} + template <typename _K2> + _LIBCPP_INLINE_VISIBILITY + typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type + equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} +#endif +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Key, class _Compare, class _Allocator> +multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a) + : __tree_(_VSTD::move(__s.__tree_), __a) +{ + if (__a != __s.get_allocator()) + { + const_iterator __e = cend(); + while (!__s.empty()) + insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_)); + } +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const multiset<_Key, _Compare, _Allocator>& __x, + const multiset<_Key, _Compare, _Allocator>& __y) +{ + return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const multiset<_Key, _Compare, _Allocator>& __x, + const multiset<_Key, _Compare, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const multiset<_Key, _Compare, _Allocator>& __x, + const multiset<_Key, _Compare, _Allocator>& __y) +{ + return !(__x == __y); +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const multiset<_Key, _Compare, _Allocator>& __x, + const multiset<_Key, _Compare, _Allocator>& __y) +{ + return __y < __x; +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const multiset<_Key, _Compare, _Allocator>& __x, + const multiset<_Key, _Compare, _Allocator>& __y) +{ + return !(__x < __y); +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const multiset<_Key, _Compare, _Allocator>& __x, + const multiset<_Key, _Compare, _Allocator>& __y) +{ + return !(__y < __x); +} + +template <class _Key, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(multiset<_Key, _Compare, _Allocator>& __x, + multiset<_Key, _Compare, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Key, class _Compare, class _Allocator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) +{ __libcpp_erase_if_container(__c, __pred); } +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_SET diff --git a/android/x86/include/v8/libc++/setjmp.h b/android/x86/include/v8/libc++/setjmp.h new file mode 100755 index 00000000..f30a8d40 --- /dev/null +++ b/android/x86/include/v8/libc++/setjmp.h @@ -0,0 +1,44 @@ +// -*- C++ -*- +//===--------------------------- setjmp.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SETJMP_H +#define _LIBCPP_SETJMP_H + +/* + setjmp.h synopsis + +Macros: + + setjmp + +Types: + + jmp_buf + +void longjmp(jmp_buf env, int val); + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <setjmp.h> + +#ifdef __cplusplus + +#ifndef setjmp +#define setjmp(env) setjmp(env) +#endif + +#endif // __cplusplus + +#endif // _LIBCPP_SETJMP_H diff --git a/android/x86/include/v8/libc++/shared_mutex b/android/x86/include/v8/libc++/shared_mutex new file mode 100755 index 00000000..fcafd8c0 --- /dev/null +++ b/android/x86/include/v8/libc++/shared_mutex @@ -0,0 +1,508 @@ +// -*- C++ -*- +//===------------------------ shared_mutex --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SHARED_MUTEX +#define _LIBCPP_SHARED_MUTEX + +/* + shared_mutex synopsis + +// C++1y + +namespace std +{ + +class shared_mutex // C++17 +{ +public: + shared_mutex(); + ~shared_mutex(); + + shared_mutex(const shared_mutex&) = delete; + shared_mutex& operator=(const shared_mutex&) = delete; + + // Exclusive ownership + void lock(); // blocking + bool try_lock(); + void unlock(); + + // Shared ownership + void lock_shared(); // blocking + bool try_lock_shared(); + void unlock_shared(); + + typedef implementation-defined native_handle_type; // See 30.2.3 + native_handle_type native_handle(); // See 30.2.3 +}; + +class shared_timed_mutex +{ +public: + shared_timed_mutex(); + ~shared_timed_mutex(); + + shared_timed_mutex(const shared_timed_mutex&) = delete; + shared_timed_mutex& operator=(const shared_timed_mutex&) = delete; + + // Exclusive ownership + void lock(); // blocking + bool try_lock(); + template <class Rep, class Period> + bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + template <class Clock, class Duration> + bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + void unlock(); + + // Shared ownership + void lock_shared(); // blocking + bool try_lock_shared(); + template <class Rep, class Period> + bool + try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time); + template <class Clock, class Duration> + bool + try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time); + void unlock_shared(); +}; + +template <class Mutex> +class shared_lock +{ +public: + typedef Mutex mutex_type; + + // Shared locking + shared_lock() noexcept; + explicit shared_lock(mutex_type& m); // blocking + shared_lock(mutex_type& m, defer_lock_t) noexcept; + shared_lock(mutex_type& m, try_to_lock_t); + shared_lock(mutex_type& m, adopt_lock_t); + template <class Clock, class Duration> + shared_lock(mutex_type& m, + const chrono::time_point<Clock, Duration>& abs_time); + template <class Rep, class Period> + shared_lock(mutex_type& m, + const chrono::duration<Rep, Period>& rel_time); + ~shared_lock(); + + shared_lock(shared_lock const&) = delete; + shared_lock& operator=(shared_lock const&) = delete; + + shared_lock(shared_lock&& u) noexcept; + shared_lock& operator=(shared_lock&& u) noexcept; + + void lock(); // blocking + bool try_lock(); + template <class Rep, class Period> + bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + template <class Clock, class Duration> + bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + void unlock(); + + // Setters + void swap(shared_lock& u) noexcept; + mutex_type* release() noexcept; + + // Getters + bool owns_lock() const noexcept; + explicit operator bool () const noexcept; + mutex_type* mutex() const noexcept; +}; + +template <class Mutex> + void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y) noexcept; + +} // std + +*/ + +#include <__config> +#include <version> + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +#if _LIBCPP_STD_VER > 11 || defined(_LIBCPP_BUILDING_LIBRARY) + +#include <__mutex_base> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_THREADS +#error <shared_mutex> is not supported on this single threaded system +#else // !_LIBCPP_HAS_NO_THREADS + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("shared_mutex")) +__shared_mutex_base +{ + mutex __mut_; + condition_variable __gate1_; + condition_variable __gate2_; + unsigned __state_; + + static const unsigned __write_entered_ = 1U << (sizeof(unsigned)*__CHAR_BIT__ - 1); + static const unsigned __n_readers_ = ~__write_entered_; + + __shared_mutex_base(); + _LIBCPP_INLINE_VISIBILITY ~__shared_mutex_base() = default; + + __shared_mutex_base(const __shared_mutex_base&) = delete; + __shared_mutex_base& operator=(const __shared_mutex_base&) = delete; + + // Exclusive ownership + void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability()); // blocking + bool try_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)); + void unlock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()); + + // Shared ownership + void lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_shared_capability()); // blocking + bool try_lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_shared_capability(true)); + void unlock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_shared_capability()); + +// typedef implementation-defined native_handle_type; // See 30.2.3 +// native_handle_type native_handle(); // See 30.2.3 +}; + + +#if _LIBCPP_STD_VER > 14 +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_mutex +{ + __shared_mutex_base __base; +public: + _LIBCPP_INLINE_VISIBILITY shared_mutex() : __base() {} + _LIBCPP_INLINE_VISIBILITY ~shared_mutex() = default; + + shared_mutex(const shared_mutex&) = delete; + shared_mutex& operator=(const shared_mutex&) = delete; + + // Exclusive ownership + _LIBCPP_INLINE_VISIBILITY void lock() { return __base.lock(); } + _LIBCPP_INLINE_VISIBILITY bool try_lock() { return __base.try_lock(); } + _LIBCPP_INLINE_VISIBILITY void unlock() { return __base.unlock(); } + + // Shared ownership + _LIBCPP_INLINE_VISIBILITY void lock_shared() { return __base.lock_shared(); } + _LIBCPP_INLINE_VISIBILITY bool try_lock_shared() { return __base.try_lock_shared(); } + _LIBCPP_INLINE_VISIBILITY void unlock_shared() { return __base.unlock_shared(); } + +// typedef __shared_mutex_base::native_handle_type native_handle_type; +// _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() { return __base::unlock_shared(); } +}; +#endif + + +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_timed_mutex +{ + __shared_mutex_base __base; +public: + shared_timed_mutex(); + _LIBCPP_INLINE_VISIBILITY ~shared_timed_mutex() = default; + + shared_timed_mutex(const shared_timed_mutex&) = delete; + shared_timed_mutex& operator=(const shared_timed_mutex&) = delete; + + // Exclusive ownership + void lock(); + bool try_lock(); + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + bool + try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time) + { + return try_lock_until(chrono::steady_clock::now() + __rel_time); + } + template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + bool + try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time); + void unlock(); + + // Shared ownership + void lock_shared(); + bool try_lock_shared(); + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + bool + try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rel_time) + { + return try_lock_shared_until(chrono::steady_clock::now() + __rel_time); + } + template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + bool + try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __abs_time); + void unlock_shared(); +}; + +template <class _Clock, class _Duration> +bool +shared_timed_mutex::try_lock_until( + const chrono::time_point<_Clock, _Duration>& __abs_time) +{ + unique_lock<mutex> __lk(__base.__mut_); + if (__base.__state_ & __base.__write_entered_) + { + while (true) + { + cv_status __status = __base.__gate1_.wait_until(__lk, __abs_time); + if ((__base.__state_ & __base.__write_entered_) == 0) + break; + if (__status == cv_status::timeout) + return false; + } + } + __base.__state_ |= __base.__write_entered_; + if (__base.__state_ & __base.__n_readers_) + { + while (true) + { + cv_status __status = __base.__gate2_.wait_until(__lk, __abs_time); + if ((__base.__state_ & __base.__n_readers_) == 0) + break; + if (__status == cv_status::timeout) + { + __base.__state_ &= ~__base.__write_entered_; + __base.__gate1_.notify_all(); + return false; + } + } + } + return true; +} + +template <class _Clock, class _Duration> +bool +shared_timed_mutex::try_lock_shared_until( + const chrono::time_point<_Clock, _Duration>& __abs_time) +{ + unique_lock<mutex> __lk(__base.__mut_); + if ((__base.__state_ & __base.__write_entered_) || (__base.__state_ & __base.__n_readers_) == __base.__n_readers_) + { + while (true) + { + cv_status status = __base.__gate1_.wait_until(__lk, __abs_time); + if ((__base.__state_ & __base.__write_entered_) == 0 && + (__base.__state_ & __base.__n_readers_) < __base.__n_readers_) + break; + if (status == cv_status::timeout) + return false; + } + } + unsigned __num_readers = (__base.__state_ & __base.__n_readers_) + 1; + __base.__state_ &= ~__base.__n_readers_; + __base.__state_ |= __num_readers; + return true; +} + +template <class _Mutex> +class shared_lock +{ +public: + typedef _Mutex mutex_type; + +private: + mutex_type* __m_; + bool __owns_; + +public: + _LIBCPP_INLINE_VISIBILITY + shared_lock() _NOEXCEPT + : __m_(nullptr), + __owns_(false) + {} + + _LIBCPP_INLINE_VISIBILITY + explicit shared_lock(mutex_type& __m) + : __m_(_VSTD::addressof(__m)), + __owns_(true) + {__m_->lock_shared();} + + _LIBCPP_INLINE_VISIBILITY + shared_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT + : __m_(_VSTD::addressof(__m)), + __owns_(false) + {} + + _LIBCPP_INLINE_VISIBILITY + shared_lock(mutex_type& __m, try_to_lock_t) + : __m_(_VSTD::addressof(__m)), + __owns_(__m.try_lock_shared()) + {} + + _LIBCPP_INLINE_VISIBILITY + shared_lock(mutex_type& __m, adopt_lock_t) + : __m_(_VSTD::addressof(__m)), + __owns_(true) + {} + + template <class _Clock, class _Duration> + _LIBCPP_INLINE_VISIBILITY + shared_lock(mutex_type& __m, + const chrono::time_point<_Clock, _Duration>& __abs_time) + : __m_(_VSTD::addressof(__m)), + __owns_(__m.try_lock_shared_until(__abs_time)) + {} + + template <class _Rep, class _Period> + _LIBCPP_INLINE_VISIBILITY + shared_lock(mutex_type& __m, + const chrono::duration<_Rep, _Period>& __rel_time) + : __m_(_VSTD::addressof(__m)), + __owns_(__m.try_lock_shared_for(__rel_time)) + {} + + _LIBCPP_INLINE_VISIBILITY + ~shared_lock() + { + if (__owns_) + __m_->unlock_shared(); + } + + shared_lock(shared_lock const&) = delete; + shared_lock& operator=(shared_lock const&) = delete; + + _LIBCPP_INLINE_VISIBILITY + shared_lock(shared_lock&& __u) _NOEXCEPT + : __m_(__u.__m_), + __owns_(__u.__owns_) + { + __u.__m_ = nullptr; + __u.__owns_ = false; + } + + _LIBCPP_INLINE_VISIBILITY + shared_lock& operator=(shared_lock&& __u) _NOEXCEPT + { + if (__owns_) + __m_->unlock_shared(); + __m_ = nullptr; + __owns_ = false; + __m_ = __u.__m_; + __owns_ = __u.__owns_; + __u.__m_ = nullptr; + __u.__owns_ = false; + return *this; + } + + void lock(); + bool try_lock(); + template <class Rep, class Period> + bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + template <class Clock, class Duration> + bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + void unlock(); + + // Setters + _LIBCPP_INLINE_VISIBILITY + void swap(shared_lock& __u) _NOEXCEPT + { + _VSTD::swap(__m_, __u.__m_); + _VSTD::swap(__owns_, __u.__owns_); + } + + _LIBCPP_INLINE_VISIBILITY + mutex_type* release() _NOEXCEPT + { + mutex_type* __m = __m_; + __m_ = nullptr; + __owns_ = false; + return __m; + } + + // Getters + _LIBCPP_INLINE_VISIBILITY + bool owns_lock() const _NOEXCEPT {return __owns_;} + + _LIBCPP_INLINE_VISIBILITY + explicit operator bool () const _NOEXCEPT {return __owns_;} + + _LIBCPP_INLINE_VISIBILITY + mutex_type* mutex() const _NOEXCEPT {return __m_;} +}; + +template <class _Mutex> +void +shared_lock<_Mutex>::lock() +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "shared_lock::lock: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "shared_lock::lock: already locked"); + __m_->lock_shared(); + __owns_ = true; +} + +template <class _Mutex> +bool +shared_lock<_Mutex>::try_lock() +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "shared_lock::try_lock: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "shared_lock::try_lock: already locked"); + __owns_ = __m_->try_lock_shared(); + return __owns_; +} + +template <class _Mutex> +template <class _Rep, class _Period> +bool +shared_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "shared_lock::try_lock_for: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "shared_lock::try_lock_for: already locked"); + __owns_ = __m_->try_lock_shared_for(__d); + return __owns_; +} + +template <class _Mutex> +template <class _Clock, class _Duration> +bool +shared_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "shared_lock::try_lock_until: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "shared_lock::try_lock_until: already locked"); + __owns_ = __m_->try_lock_shared_until(__t); + return __owns_; +} + +template <class _Mutex> +void +shared_lock<_Mutex>::unlock() +{ + if (!__owns_) + __throw_system_error(EPERM, "shared_lock::unlock: not locked"); + __m_->unlock_shared(); + __owns_ = false; +} + +template <class _Mutex> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) _NOEXCEPT + {__x.swap(__y);} + +_LIBCPP_END_NAMESPACE_STD + +#endif // !_LIBCPP_HAS_NO_THREADS + +#endif // _LIBCPP_STD_VER > 11 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_SHARED_MUTEX diff --git a/android/x86/include/v8/libc++/span b/android/x86/include/v8/libc++/span new file mode 100755 index 00000000..0694f511 --- /dev/null +++ b/android/x86/include/v8/libc++/span @@ -0,0 +1,591 @@ +// -*- C++ -*- +//===------------------------------ span ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP_SPAN +#define _LIBCPP_SPAN + +/* + span synopsis + +namespace std { + +// constants +inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max(); + +// [views.span], class template span +template <class ElementType, size_t Extent = dynamic_extent> + class span; + +// [span.objectrep], views of object representation +template <class ElementType, size_t Extent> + span<const byte, ((Extent == dynamic_extent) ? dynamic_extent : + (sizeof(ElementType) * Extent))> as_bytes(span<ElementType, Extent> s) noexcept; + +template <class ElementType, size_t Extent> + span< byte, ((Extent == dynamic_extent) ? dynamic_extent : + (sizeof(ElementType) * Extent))> as_writable_bytes(span<ElementType, Extent> s) noexcept; + + +namespace std { +template <class ElementType, size_t Extent = dynamic_extent> +class span { +public: + // constants and types + using element_type = ElementType; + using value_type = remove_cv_t<ElementType>; + using index_type = size_t; + using difference_type = ptrdiff_t; + using pointer = element_type*; + using const_pointer = const element_type*; + using reference = element_type&; + using const_reference = const element_type&; + using iterator = implementation-defined; + using const_iterator = implementation-defined; + using reverse_iterator = std::reverse_iterator<iterator>; + using const_reverse_iterator = std::reverse_iterator<const_iterator>; + static constexpr index_type extent = Extent; + + // [span.cons], span constructors, copy, assignment, and destructor + constexpr span() noexcept; + constexpr span(pointer ptr, index_type count); + constexpr span(pointer firstElem, pointer lastElem); + template <size_t N> + constexpr span(element_type (&arr)[N]) noexcept; + template <size_t N> + constexpr span(array<value_type, N>& arr) noexcept; + template <size_t N> + constexpr span(const array<value_type, N>& arr) noexcept; + template <class Container> + constexpr span(Container& cont); + template <class Container> + constexpr span(const Container& cont); + constexpr span(const span& other) noexcept = default; + template <class OtherElementType, size_t OtherExtent> + constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept; + ~span() noexcept = default; + constexpr span& operator=(const span& other) noexcept = default; + + // [span.sub], span subviews + template <size_t Count> + constexpr span<element_type, Count> first() const; + template <size_t Count> + constexpr span<element_type, Count> last() const; + template <size_t Offset, size_t Count = dynamic_extent> + constexpr span<element_type, see below> subspan() const; + + constexpr span<element_type, dynamic_extent> first(index_type count) const; + constexpr span<element_type, dynamic_extent> last(index_type count) const; + constexpr span<element_type, dynamic_extent> subspan(index_type offset, index_type count = dynamic_extent) const; + + // [span.obs], span observers + constexpr index_type size() const noexcept; + constexpr index_type size_bytes() const noexcept; + constexpr bool empty() const noexcept; + + // [span.elem], span element access + constexpr reference operator[](index_type idx) const; + constexpr reference front() const; + constexpr reference back() const; + constexpr pointer data() const noexcept; + + // [span.iterators], span iterator support + constexpr iterator begin() const noexcept; + constexpr iterator end() const noexcept; + constexpr const_iterator cbegin() const noexcept; + constexpr const_iterator cend() const noexcept; + constexpr reverse_iterator rbegin() const noexcept; + constexpr reverse_iterator rend() const noexcept; + constexpr const_reverse_iterator crbegin() const noexcept; + constexpr const_reverse_iterator crend() const noexcept; + +private: + pointer data_; // exposition only + index_type size_; // exposition only +}; + +template<class T, size_t N> + span(T (&)[N]) -> span<T, N>; + +template<class T, size_t N> + span(array<T, N>&) -> span<T, N>; + +template<class T, size_t N> + span(const array<T, N>&) -> span<const T, N>; + +template<class Container> + span(Container&) -> span<typename Container::value_type>; + +template<class Container> + span(const Container&) -> span<const typename Container::value_type>; + +} // namespace std + +*/ + +#include <__config> +#include <cstddef> // for ptrdiff_t +#include <iterator> // for iterators +#include <array> // for array +#include <type_traits> // for remove_cv, etc +#include <cstddef> // for byte + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 + +inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max(); +template <typename _Tp, size_t _Extent = dynamic_extent> class span; + + +template <class _Tp> +struct __is_span_impl : public false_type {}; + +template <class _Tp, size_t _Extent> +struct __is_span_impl<span<_Tp, _Extent>> : public true_type {}; + +template <class _Tp> +struct __is_span : public __is_span_impl<remove_cv_t<_Tp>> {}; + +template <class _Tp> +struct __is_std_array_impl : public false_type {}; + +template <class _Tp, size_t _Sz> +struct __is_std_array_impl<array<_Tp, _Sz>> : public true_type {}; + +template <class _Tp> +struct __is_std_array : public __is_std_array_impl<remove_cv_t<_Tp>> {}; + +template <class _Tp, class _ElementType, class = void> +struct __is_span_compatible_container : public false_type {}; + +template <class _Tp, class _ElementType> +struct __is_span_compatible_container<_Tp, _ElementType, + void_t< + // is not a specialization of span + typename enable_if<!__is_span<_Tp>::value, nullptr_t>::type, + // is not a specialization of array + typename enable_if<!__is_std_array<_Tp>::value, nullptr_t>::type, + // is_array_v<Container> is false, + typename enable_if<!is_array_v<_Tp>, nullptr_t>::type, + // data(cont) and size(cont) are well formed + decltype(data(declval<_Tp>())), + decltype(size(declval<_Tp>())), + // remove_pointer_t<decltype(data(cont))>(*)[] is convertible to ElementType(*)[] + typename enable_if< + is_convertible_v<remove_pointer_t<decltype(data(declval<_Tp &>()))>(*)[], + _ElementType(*)[]>, + nullptr_t>::type + >> + : public true_type {}; + + +template <typename _Tp, size_t _Extent> +class _LIBCPP_TEMPLATE_VIS span { +public: +// constants and types + using element_type = _Tp; + using value_type = remove_cv_t<_Tp>; + using index_type = size_t; + using difference_type = ptrdiff_t; + using pointer = _Tp *; + using const_pointer = const _Tp *; + using reference = _Tp &; + using const_reference = const _Tp &; + using iterator = __wrap_iter<pointer>; + using const_iterator = __wrap_iter<const_pointer>; + using reverse_iterator = _VSTD::reverse_iterator<iterator>; + using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>; + + static constexpr index_type extent = _Extent; + +// [span.cons], span constructors, copy, assignment, and destructor + _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} + { static_assert(_Extent == 0, "Can't default construct a statically sized span with size > 0"); } + + constexpr span (const span&) noexcept = default; + constexpr span& operator=(const span&) noexcept = default; + + _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, index_type __count) : __data{__ptr} + { (void)__count; _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (ptr, len)"); } + _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f} + { (void)__l; _LIBCPP_ASSERT(_Extent == distance(__f, __l), "size mismatch in span's constructor (ptr, ptr)"); } + + _LIBCPP_INLINE_VISIBILITY constexpr span(element_type (&__arr)[_Extent]) noexcept : __data{__arr} {} + _LIBCPP_INLINE_VISIBILITY constexpr span( array<value_type, _Extent>& __arr) noexcept : __data{__arr.data()} {} + _LIBCPP_INLINE_VISIBILITY constexpr span(const array<value_type, _Extent>& __arr) noexcept : __data{__arr.data()} {} + + template <class _OtherElementType> + _LIBCPP_INLINE_VISIBILITY + constexpr span(const span<_OtherElementType, _Extent>& __other, + enable_if_t< + is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, + nullptr_t> = nullptr) + : __data{__other.data()} {} + + template <class _OtherElementType> + _LIBCPP_INLINE_VISIBILITY + constexpr span(const span<_OtherElementType, dynamic_extent>& __other, + enable_if_t< + is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, + nullptr_t> = nullptr) noexcept + : __data{__other.data()} { _LIBCPP_ASSERT(_Extent == __other.size(), "size mismatch in span's constructor (other span)"); } + + +// ~span() noexcept = default; + + template <size_t _Count> + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> first() const noexcept + { + static_assert(_Count <= _Extent, "Count out of range in span::first()"); + return {data(), _Count}; + } + + template <size_t _Count> + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> last() const noexcept + { + static_assert(_Count <= _Extent, "Count out of range in span::last()"); + return {data() + size() - _Count, _Count}; + } + + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, dynamic_extent> first(index_type __count) const noexcept + { + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); + return {data(), __count}; + } + + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, dynamic_extent> last(index_type __count) const noexcept + { + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); + return {data() + size() - __count, __count}; + } + + template <size_t _Offset, size_t _Count = dynamic_extent> + _LIBCPP_INLINE_VISIBILITY + constexpr auto subspan() const noexcept + -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset> + { + static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()"); + return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; + } + + + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, dynamic_extent> + subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept + { + _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)"); + if (__count == dynamic_extent) + return {data() + __offset, size() - __offset}; + _LIBCPP_ASSERT(__offset <= size() - __count, "count + offset out of range in span::subspan(offset, count)"); + return {data() + __offset, __count}; + } + + _LIBCPP_INLINE_VISIBILITY constexpr index_type size() const noexcept { return _Extent; } + _LIBCPP_INLINE_VISIBILITY constexpr index_type size_bytes() const noexcept { return _Extent * sizeof(element_type); } + _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; } + + _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](index_type __idx) const noexcept + { + _LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T,N>[] index out of bounds"); + return __data[__idx]; + } + + _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept + { + static_assert(_Extent > 0, "span<T,N>[].front() on empty span"); + return __data[0]; + } + + _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept + { + static_assert(_Extent > 0, "span<T,N>[].back() on empty span"); + return __data[size()-1]; + } + + _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; } + +// [span.iter], span iterator support + _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); } + _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); } + _LIBCPP_INLINE_VISIBILITY constexpr const_iterator cbegin() const noexcept { return const_iterator(data()); } + _LIBCPP_INLINE_VISIBILITY constexpr const_iterator cend() const noexcept { return const_iterator(data() + size()); } + _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } + _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } + _LIBCPP_INLINE_VISIBILITY constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); } + _LIBCPP_INLINE_VISIBILITY constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); } + + _LIBCPP_INLINE_VISIBILITY constexpr void swap(span &__other) noexcept + { + pointer __p = __data; + __data = __other.__data; + __other.__data = __p; + } + + _LIBCPP_INLINE_VISIBILITY span<const byte, _Extent * sizeof(element_type)> __as_bytes() const noexcept + { return {reinterpret_cast<const byte *>(data()), size_bytes()}; } + + _LIBCPP_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)> __as_writable_bytes() const noexcept + { return {reinterpret_cast<byte *>(data()), size_bytes()}; } + +private: + pointer __data; + +}; + + +template <typename _Tp> +class _LIBCPP_TEMPLATE_VIS span<_Tp, dynamic_extent> { +private: + +public: +// constants and types + using element_type = _Tp; + using value_type = remove_cv_t<_Tp>; + using index_type = size_t; + using difference_type = ptrdiff_t; + using pointer = _Tp *; + using const_pointer = const _Tp *; + using reference = _Tp &; + using const_reference = const _Tp &; + using iterator = __wrap_iter<pointer>; + using const_iterator = __wrap_iter<const_pointer>; + using reverse_iterator = _VSTD::reverse_iterator<iterator>; + using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>; + + static constexpr index_type extent = dynamic_extent; + +// [span.cons], span constructors, copy, assignment, and destructor + _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}, __size{0} {} + + constexpr span (const span&) noexcept = default; + constexpr span& operator=(const span&) noexcept = default; + + _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, index_type __count) : __data{__ptr}, __size{__count} {} + _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast<size_t>(distance(__f, __l))} {} + + template <size_t _Sz> + _LIBCPP_INLINE_VISIBILITY + constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {} + + template <size_t _Sz> + _LIBCPP_INLINE_VISIBILITY + constexpr span(array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} + + template <size_t _Sz> + _LIBCPP_INLINE_VISIBILITY + constexpr span(const array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} + + template <class _Container> + _LIBCPP_INLINE_VISIBILITY + constexpr span( _Container& __c, + enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) + : __data{_VSTD::data(__c)}, __size{(index_type) _VSTD::size(__c)} {} + + template <class _Container> + _LIBCPP_INLINE_VISIBILITY + constexpr span(const _Container& __c, + enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr) + : __data{_VSTD::data(__c)}, __size{(index_type) _VSTD::size(__c)} {} + + + template <class _OtherElementType, size_t _OtherExtent> + _LIBCPP_INLINE_VISIBILITY + constexpr span(const span<_OtherElementType, _OtherExtent>& __other, + enable_if_t< + is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, + nullptr_t> = nullptr) noexcept + : __data{__other.data()}, __size{__other.size()} {} + +// ~span() noexcept = default; + + template <size_t _Count> + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> first() const noexcept + { + _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()"); + return {data(), _Count}; + } + + template <size_t _Count> + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> last() const noexcept + { + _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()"); + return {data() + size() - _Count, _Count}; + } + + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, dynamic_extent> first(index_type __count) const noexcept + { + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); + return {data(), __count}; + } + + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, dynamic_extent> last (index_type __count) const noexcept + { + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); + return {data() + size() - __count, __count}; + } + + template <size_t _Offset, size_t _Count = dynamic_extent> + _LIBCPP_INLINE_VISIBILITY + constexpr span<_Tp, dynamic_extent> subspan() const noexcept + { + _LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()"); + _LIBCPP_ASSERT(_Count == dynamic_extent || _Offset + _Count <= size(), "Count out of range in span::subspan()"); + return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; + } + + constexpr span<element_type, dynamic_extent> + _LIBCPP_INLINE_VISIBILITY + subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept + { + _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)"); + if (__count == dynamic_extent) + return {data() + __offset, size() - __offset}; + _LIBCPP_ASSERT(__offset <= size() - __count, "Offset + count out of range in span::subspan(offset, count)"); + return {data() + __offset, __count}; + } + + _LIBCPP_INLINE_VISIBILITY constexpr index_type size() const noexcept { return __size; } + _LIBCPP_INLINE_VISIBILITY constexpr index_type size_bytes() const noexcept { return __size * sizeof(element_type); } + _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; } + + _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](index_type __idx) const noexcept + { + _LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T>[] index out of bounds"); + return __data[__idx]; + } + + _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept + { + _LIBCPP_ASSERT(!empty(), "span<T>[].front() on empty span"); + return __data[0]; + } + + _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept + { + _LIBCPP_ASSERT(!empty(), "span<T>[].back() on empty span"); + return __data[size()-1]; + } + + + _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; } + +// [span.iter], span iterator support + _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); } + _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); } + _LIBCPP_INLINE_VISIBILITY constexpr const_iterator cbegin() const noexcept { return const_iterator(data()); } + _LIBCPP_INLINE_VISIBILITY constexpr const_iterator cend() const noexcept { return const_iterator(data() + size()); } + _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } + _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } + _LIBCPP_INLINE_VISIBILITY constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); } + _LIBCPP_INLINE_VISIBILITY constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); } + + _LIBCPP_INLINE_VISIBILITY constexpr void swap(span &__other) noexcept + { + pointer __p = __data; + __data = __other.__data; + __other.__data = __p; + + index_type __sz = __size; + __size = __other.__size; + __other.__size = __sz; + } + + _LIBCPP_INLINE_VISIBILITY span<const byte, dynamic_extent> __as_bytes() const noexcept + { return {reinterpret_cast<const byte *>(data()), size_bytes()}; } + + _LIBCPP_INLINE_VISIBILITY span<byte, dynamic_extent> __as_writable_bytes() const noexcept + { return {reinterpret_cast<byte *>(data()), size_bytes()}; } + +private: + pointer __data; + index_type __size; +}; + +// tuple interface +template <class _Tp, size_t _Size> +struct _LIBCPP_TEMPLATE_VIS tuple_size<span<_Tp, _Size>> + : public integral_constant<size_t, _Size> {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_size<span<_Tp, dynamic_extent>>; // declared but not defined + + +template <size_t _Ip, class _Tp, size_t _Size> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, span<_Tp, _Size>> +{ + static_assert( dynamic_extent != _Size, "std::tuple_element<> not supported for std::span<T, dynamic_extent>"); + static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::span)"); + typedef _Tp type; +}; + +template <size_t _Ip, class _Tp, size_t _Size> +_LIBCPP_INLINE_VISIBILITY constexpr +_Tp& +get(span<_Tp, _Size> __s) noexcept +{ + static_assert( dynamic_extent != _Size, "std::get<> not supported for std::span<T, dynamic_extent>"); + static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::span)"); + return __s[_Ip]; +} + + +// as_bytes & as_writable_bytes +template <class _Tp, size_t _Extent> +_LIBCPP_INLINE_VISIBILITY +auto as_bytes(span<_Tp, _Extent> __s) noexcept +-> decltype(__s.__as_bytes()) +{ return __s.__as_bytes(); } + +template <class _Tp, size_t _Extent> +_LIBCPP_INLINE_VISIBILITY +auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept +-> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())> +{ return __s.__as_writable_bytes(); } + +template <class _Tp, size_t _Extent> +_LIBCPP_INLINE_VISIBILITY +constexpr void swap(span<_Tp, _Extent> &__lhs, span<_Tp, _Extent> &__rhs) noexcept +{ __lhs.swap(__rhs); } + + +// Deduction guides +template<class _Tp, size_t _Sz> + span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>; + +template<class _Tp, size_t _Sz> + span(array<_Tp, _Sz>&) -> span<_Tp, _Sz>; + +template<class _Tp, size_t _Sz> + span(const array<_Tp, _Sz>&) -> span<const _Tp, _Sz>; + +template<class _Container> + span(_Container&) -> span<typename _Container::value_type>; + +template<class _Container> + span(const _Container&) -> span<const typename _Container::value_type>; + +#endif // _LIBCPP_STD_VER > 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_SPAN diff --git a/android/x86/include/v8/libc++/sstream b/android/x86/include/v8/libc++/sstream new file mode 100755 index 00000000..14c91971 --- /dev/null +++ b/android/x86/include/v8/libc++/sstream @@ -0,0 +1,985 @@ +// -*- C++ -*- +//===--------------------------- sstream ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SSTREAM +#define _LIBCPP_SSTREAM + +/* + sstream synopsis + +template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > +class basic_stringbuf + : public basic_streambuf<charT, traits> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef Allocator allocator_type; + + // 27.8.1.1 Constructors: + explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); + explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& str, + ios_base::openmode which = ios_base::in | ios_base::out); + basic_stringbuf(basic_stringbuf&& rhs); + + // 27.8.1.2 Assign and swap: + basic_stringbuf& operator=(basic_stringbuf&& rhs); + void swap(basic_stringbuf& rhs); + + // 27.8.1.3 Get and set: + basic_string<char_type, traits_type, allocator_type> str() const; + void str(const basic_string<char_type, traits_type, allocator_type>& s); + +protected: + // 27.8.1.4 Overridden virtual functions: + virtual int_type underflow(); + virtual int_type pbackfail(int_type c = traits_type::eof()); + virtual int_type overflow (int_type c = traits_type::eof()); + virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize); + virtual pos_type seekoff(off_type off, ios_base::seekdir way, + ios_base::openmode which = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type sp, + ios_base::openmode which = ios_base::in | ios_base::out); +}; + +template <class charT, class traits, class Allocator> + void swap(basic_stringbuf<charT, traits, Allocator>& x, + basic_stringbuf<charT, traits, Allocator>& y); + +typedef basic_stringbuf<char> stringbuf; +typedef basic_stringbuf<wchar_t> wstringbuf; + +template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > +class basic_istringstream + : public basic_istream<charT, traits> +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef Allocator allocator_type; + + // 27.8.2.1 Constructors: + explicit basic_istringstream(ios_base::openmode which = ios_base::in); + explicit basic_istringstream(const basic_string<char_type, traits_type,allocator_type>& str, + ios_base::openmode which = ios_base::in); + basic_istringstream(basic_istringstream&& rhs); + + // 27.8.2.2 Assign and swap: + basic_istringstream& operator=(basic_istringstream&& rhs); + void swap(basic_istringstream& rhs); + + // 27.8.2.3 Members: + basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; + basic_string<char_type, traits_type, allocator_type> str() const; + void str(const basic_string<char_type, traits_type, allocator_type>& s); +}; + +template <class charT, class traits, class Allocator> + void swap(basic_istringstream<charT, traits, Allocator>& x, + basic_istringstream<charT, traits, Allocator>& y); + +typedef basic_istringstream<char> istringstream; +typedef basic_istringstream<wchar_t> wistringstream; + +template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > +class basic_ostringstream + : public basic_ostream<charT, traits> +{ +public: + // types: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef Allocator allocator_type; + + // 27.8.3.1 Constructors/destructor: + explicit basic_ostringstream(ios_base::openmode which = ios_base::out); + explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& str, + ios_base::openmode which = ios_base::out); + basic_ostringstream(basic_ostringstream&& rhs); + + // 27.8.3.2 Assign/swap: + basic_ostringstream& operator=(basic_ostringstream&& rhs); + void swap(basic_ostringstream& rhs); + + // 27.8.3.3 Members: + basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; + basic_string<char_type, traits_type, allocator_type> str() const; + void str(const basic_string<char_type, traits_type, allocator_type>& s); +}; + +template <class charT, class traits, class Allocator> + void swap(basic_ostringstream<charT, traits, Allocator>& x, + basic_ostringstream<charT, traits, Allocator>& y); + +typedef basic_ostringstream<char> ostringstream; +typedef basic_ostringstream<wchar_t> wostringstream; + +template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > +class basic_stringstream + : public basic_iostream<charT, traits> +{ +public: + // types: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef Allocator allocator_type; + + // constructors/destructor + explicit basic_stringstream(ios_base::openmode which = ios_base::out|ios_base::in); + explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& str, + ios_base::openmode which = ios_base::out|ios_base::in); + basic_stringstream(basic_stringstream&& rhs); + + // 27.8.5.1 Assign/swap: + basic_stringstream& operator=(basic_stringstream&& rhs); + void swap(basic_stringstream& rhs); + + // Members: + basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; + basic_string<char_type, traits_type, allocator_type> str() const; + void str(const basic_string<char_type, traits_type, allocator_type>& str); +}; + +template <class charT, class traits, class Allocator> + void swap(basic_stringstream<charT, traits, Allocator>& x, + basic_stringstream<charT, traits, Allocator>& y); + +typedef basic_stringstream<char> stringstream; +typedef basic_stringstream<wchar_t> wstringstream; + +} // std + +*/ + +#include <__config> +#include <ostream> +#include <istream> +#include <string> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +// basic_stringbuf + +template <class _CharT, class _Traits, class _Allocator> +class _LIBCPP_TEMPLATE_VIS basic_stringbuf + : public basic_streambuf<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef _Allocator allocator_type; + + typedef basic_string<char_type, traits_type, allocator_type> string_type; + +private: + + string_type __str_; + mutable char_type* __hm_; + ios_base::openmode __mode_; + +public: + // 27.8.1.1 Constructors: + inline _LIBCPP_INLINE_VISIBILITY + explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | ios_base::out); + inline _LIBCPP_INLINE_VISIBILITY + explicit basic_stringbuf(const string_type& __s, + ios_base::openmode __wch = ios_base::in | ios_base::out); +#ifndef _LIBCPP_CXX03_LANG + basic_stringbuf(basic_stringbuf&& __rhs); + + // 27.8.1.2 Assign and swap: + basic_stringbuf& operator=(basic_stringbuf&& __rhs); +#endif + void swap(basic_stringbuf& __rhs); + + // 27.8.1.3 Get and set: + string_type str() const; + void str(const string_type& __s); + +protected: + // 27.8.1.4 Overridden virtual functions: + virtual int_type underflow(); + virtual int_type pbackfail(int_type __c = traits_type::eof()); + virtual int_type overflow (int_type __c = traits_type::eof()); + virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __wch = ios_base::in | ios_base::out); + inline _LIBCPP_INLINE_VISIBILITY + virtual pos_type seekpos(pos_type __sp, + ios_base::openmode __wch = ios_base::in | ios_base::out); +}; + +template <class _CharT, class _Traits, class _Allocator> +basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(ios_base::openmode __wch) + : __hm_(0), + __mode_(__wch) +{ +} + +template <class _CharT, class _Traits, class _Allocator> +basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(const string_type& __s, + ios_base::openmode __wch) + : __str_(__s.get_allocator()), + __hm_(0), + __mode_(__wch) +{ + str(__s); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs) + : __mode_(__rhs.__mode_) +{ + char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); + ptrdiff_t __binp = -1; + ptrdiff_t __ninp = -1; + ptrdiff_t __einp = -1; + if (__rhs.eback() != nullptr) + { + __binp = __rhs.eback() - __p; + __ninp = __rhs.gptr() - __p; + __einp = __rhs.egptr() - __p; + } + ptrdiff_t __bout = -1; + ptrdiff_t __nout = -1; + ptrdiff_t __eout = -1; + if (__rhs.pbase() != nullptr) + { + __bout = __rhs.pbase() - __p; + __nout = __rhs.pptr() - __p; + __eout = __rhs.epptr() - __p; + } + ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; + __str_ = _VSTD::move(__rhs.__str_); + __p = const_cast<char_type*>(__str_.data()); + if (__binp != -1) + this->setg(__p + __binp, __p + __ninp, __p + __einp); + if (__bout != -1) + { + this->setp(__p + __bout, __p + __eout); + this->__pbump(__nout); + } + __hm_ = __hm == -1 ? nullptr : __p + __hm; + __p = const_cast<char_type*>(__rhs.__str_.data()); + __rhs.setg(__p, __p, __p); + __rhs.setp(__p, __p); + __rhs.__hm_ = __p; + this->pubimbue(__rhs.getloc()); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_stringbuf<_CharT, _Traits, _Allocator>& +basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) +{ + char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); + ptrdiff_t __binp = -1; + ptrdiff_t __ninp = -1; + ptrdiff_t __einp = -1; + if (__rhs.eback() != nullptr) + { + __binp = __rhs.eback() - __p; + __ninp = __rhs.gptr() - __p; + __einp = __rhs.egptr() - __p; + } + ptrdiff_t __bout = -1; + ptrdiff_t __nout = -1; + ptrdiff_t __eout = -1; + if (__rhs.pbase() != nullptr) + { + __bout = __rhs.pbase() - __p; + __nout = __rhs.pptr() - __p; + __eout = __rhs.epptr() - __p; + } + ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; + __str_ = _VSTD::move(__rhs.__str_); + __p = const_cast<char_type*>(__str_.data()); + if (__binp != -1) + this->setg(__p + __binp, __p + __ninp, __p + __einp); + else + this->setg(nullptr, nullptr, nullptr); + if (__bout != -1) + { + this->setp(__p + __bout, __p + __eout); + this->__pbump(__nout); + } + else + this->setp(nullptr, nullptr); + + __hm_ = __hm == -1 ? nullptr : __p + __hm; + __mode_ = __rhs.__mode_; + __p = const_cast<char_type*>(__rhs.__str_.data()); + __rhs.setg(__p, __p, __p); + __rhs.setp(__p, __p); + __rhs.__hm_ = __p; + this->pubimbue(__rhs.getloc()); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +void +basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) +{ + char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); + ptrdiff_t __rbinp = -1; + ptrdiff_t __rninp = -1; + ptrdiff_t __reinp = -1; + if (__rhs.eback() != nullptr) + { + __rbinp = __rhs.eback() - __p; + __rninp = __rhs.gptr() - __p; + __reinp = __rhs.egptr() - __p; + } + ptrdiff_t __rbout = -1; + ptrdiff_t __rnout = -1; + ptrdiff_t __reout = -1; + if (__rhs.pbase() != nullptr) + { + __rbout = __rhs.pbase() - __p; + __rnout = __rhs.pptr() - __p; + __reout = __rhs.epptr() - __p; + } + ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; + __p = const_cast<char_type*>(__str_.data()); + ptrdiff_t __lbinp = -1; + ptrdiff_t __lninp = -1; + ptrdiff_t __leinp = -1; + if (this->eback() != nullptr) + { + __lbinp = this->eback() - __p; + __lninp = this->gptr() - __p; + __leinp = this->egptr() - __p; + } + ptrdiff_t __lbout = -1; + ptrdiff_t __lnout = -1; + ptrdiff_t __leout = -1; + if (this->pbase() != nullptr) + { + __lbout = this->pbase() - __p; + __lnout = this->pptr() - __p; + __leout = this->epptr() - __p; + } + ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p; + _VSTD::swap(__mode_, __rhs.__mode_); + __str_.swap(__rhs.__str_); + __p = const_cast<char_type*>(__str_.data()); + if (__rbinp != -1) + this->setg(__p + __rbinp, __p + __rninp, __p + __reinp); + else + this->setg(nullptr, nullptr, nullptr); + if (__rbout != -1) + { + this->setp(__p + __rbout, __p + __reout); + this->__pbump(__rnout); + } + else + this->setp(nullptr, nullptr); + __hm_ = __rhm == -1 ? nullptr : __p + __rhm; + __p = const_cast<char_type*>(__rhs.__str_.data()); + if (__lbinp != -1) + __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp); + else + __rhs.setg(nullptr, nullptr, nullptr); + if (__lbout != -1) + { + __rhs.setp(__p + __lbout, __p + __leout); + __rhs.__pbump(__lnout); + } + else + __rhs.setp(nullptr, nullptr); + __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm; + locale __tl = __rhs.getloc(); + __rhs.pubimbue(this->getloc()); + this->pubimbue(__tl); +} + +template <class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, + basic_stringbuf<_CharT, _Traits, _Allocator>& __y) +{ + __x.swap(__y); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +basic_stringbuf<_CharT, _Traits, _Allocator>::str() const +{ + if (__mode_ & ios_base::out) + { + if (__hm_ < this->pptr()) + __hm_ = this->pptr(); + return string_type(this->pbase(), __hm_, __str_.get_allocator()); + } + else if (__mode_ & ios_base::in) + return string_type(this->eback(), this->egptr(), __str_.get_allocator()); + return string_type(__str_.get_allocator()); +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s) +{ + __str_ = __s; + __hm_ = 0; + if (__mode_ & ios_base::in) + { + __hm_ = const_cast<char_type*>(__str_.data()) + __str_.size(); + this->setg(const_cast<char_type*>(__str_.data()), + const_cast<char_type*>(__str_.data()), + __hm_); + } + if (__mode_ & ios_base::out) + { + typename string_type::size_type __sz = __str_.size(); + __hm_ = const_cast<char_type*>(__str_.data()) + __sz; + __str_.resize(__str_.capacity()); + this->setp(const_cast<char_type*>(__str_.data()), + const_cast<char_type*>(__str_.data()) + __str_.size()); + if (__mode_ & (ios_base::app | ios_base::ate)) + { + while (__sz > INT_MAX) + { + this->pbump(INT_MAX); + __sz -= INT_MAX; + } + if (__sz > 0) + this->pbump(__sz); + } + } +} + +template <class _CharT, class _Traits, class _Allocator> +typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type +basic_stringbuf<_CharT, _Traits, _Allocator>::underflow() +{ + if (__hm_ < this->pptr()) + __hm_ = this->pptr(); + if (__mode_ & ios_base::in) + { + if (this->egptr() < __hm_) + this->setg(this->eback(), this->gptr(), __hm_); + if (this->gptr() < this->egptr()) + return traits_type::to_int_type(*this->gptr()); + } + return traits_type::eof(); +} + +template <class _CharT, class _Traits, class _Allocator> +typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type +basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) +{ + if (__hm_ < this->pptr()) + __hm_ = this->pptr(); + if (this->eback() < this->gptr()) + { + if (traits_type::eq_int_type(__c, traits_type::eof())) + { + this->setg(this->eback(), this->gptr()-1, __hm_); + return traits_type::not_eof(__c); + } + if ((__mode_ & ios_base::out) || + traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) + { + this->setg(this->eback(), this->gptr()-1, __hm_); + *this->gptr() = traits_type::to_char_type(__c); + return __c; + } + } + return traits_type::eof(); +} + +template <class _CharT, class _Traits, class _Allocator> +typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type +basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) +{ + if (!traits_type::eq_int_type(__c, traits_type::eof())) + { + ptrdiff_t __ninp = this->gptr() - this->eback(); + if (this->pptr() == this->epptr()) + { + if (!(__mode_ & ios_base::out)) + return traits_type::eof(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + ptrdiff_t __nout = this->pptr() - this->pbase(); + ptrdiff_t __hm = __hm_ - this->pbase(); + __str_.push_back(char_type()); + __str_.resize(__str_.capacity()); + char_type* __p = const_cast<char_type*>(__str_.data()); + this->setp(__p, __p + __str_.size()); + this->__pbump(__nout); + __hm_ = this->pbase() + __hm; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + return traits_type::eof(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + __hm_ = _VSTD::max(this->pptr() + 1, __hm_); + if (__mode_ & ios_base::in) + { + char_type* __p = const_cast<char_type*>(__str_.data()); + this->setg(__p, __p + __ninp, __hm_); + } + return this->sputc(traits_type::to_char_type(__c)); + } + return traits_type::not_eof(__c); +} + +template <class _CharT, class _Traits, class _Allocator> +typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type +basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, + ios_base::seekdir __way, + ios_base::openmode __wch) +{ + if (__hm_ < this->pptr()) + __hm_ = this->pptr(); + if ((__wch & (ios_base::in | ios_base::out)) == 0) + return pos_type(-1); + if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) + && __way == ios_base::cur) + return pos_type(-1); + const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); + off_type __noff; + switch (__way) + { + case ios_base::beg: + __noff = 0; + break; + case ios_base::cur: + if (__wch & ios_base::in) + __noff = this->gptr() - this->eback(); + else + __noff = this->pptr() - this->pbase(); + break; + case ios_base::end: + __noff = __hm; + break; + default: + return pos_type(-1); + } + __noff += __off; + if (__noff < 0 || __hm < __noff) + return pos_type(-1); + if (__noff != 0) + { + if ((__wch & ios_base::in) && this->gptr() == 0) + return pos_type(-1); + if ((__wch & ios_base::out) && this->pptr() == 0) + return pos_type(-1); + } + if (__wch & ios_base::in) + this->setg(this->eback(), this->eback() + __noff, __hm_); + if (__wch & ios_base::out) + { + this->setp(this->pbase(), this->epptr()); + this->pbump(__noff); + } + return pos_type(__noff); +} + +template <class _CharT, class _Traits, class _Allocator> +typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type +basic_stringbuf<_CharT, _Traits, _Allocator>::seekpos(pos_type __sp, + ios_base::openmode __wch) +{ + return seekoff(__sp, ios_base::beg, __wch); +} + +// basic_istringstream + +template <class _CharT, class _Traits, class _Allocator> +class _LIBCPP_TEMPLATE_VIS basic_istringstream + : public basic_istream<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef _Allocator allocator_type; + + typedef basic_string<char_type, traits_type, allocator_type> string_type; + +private: + basic_stringbuf<char_type, traits_type, allocator_type> __sb_; + +public: + // 27.8.2.1 Constructors: + inline _LIBCPP_INLINE_VISIBILITY + explicit basic_istringstream(ios_base::openmode __wch = ios_base::in); + inline _LIBCPP_INLINE_VISIBILITY + explicit basic_istringstream(const string_type& __s, + ios_base::openmode __wch = ios_base::in); +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY + basic_istringstream(basic_istringstream&& __rhs); + + // 27.8.2.2 Assign and swap: + basic_istringstream& operator=(basic_istringstream&& __rhs); +#endif // _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY + void swap(basic_istringstream& __rhs); + + // 27.8.2.3 Members: + inline _LIBCPP_INLINE_VISIBILITY + basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; + inline _LIBCPP_INLINE_VISIBILITY + string_type str() const; + inline _LIBCPP_INLINE_VISIBILITY + void str(const string_type& __s); +}; + +template <class _CharT, class _Traits, class _Allocator> +basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(ios_base::openmode __wch) + : basic_istream<_CharT, _Traits>(&__sb_), + __sb_(__wch | ios_base::in) +{ +} + +template <class _CharT, class _Traits, class _Allocator> +basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(const string_type& __s, + ios_base::openmode __wch) + : basic_istream<_CharT, _Traits>(&__sb_), + __sb_(__s, __wch | ios_base::in) +{ +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(basic_istringstream&& __rhs) + : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) +{ + basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_istringstream<_CharT, _Traits, _Allocator>& +basic_istringstream<_CharT, _Traits, _Allocator>::operator=(basic_istringstream&& __rhs) +{ + basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +void basic_istringstream<_CharT, _Traits, _Allocator>::swap(basic_istringstream& __rhs) +{ + basic_istream<char_type, traits_type>::swap(__rhs); + __sb_.swap(__rhs.__sb_); +} + +template <class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, + basic_istringstream<_CharT, _Traits, _Allocator>& __y) +{ + __x.swap(__y); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_stringbuf<_CharT, _Traits, _Allocator>* +basic_istringstream<_CharT, _Traits, _Allocator>::rdbuf() const +{ + return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +basic_istringstream<_CharT, _Traits, _Allocator>::str() const +{ + return __sb_.str(); +} + +template <class _CharT, class _Traits, class _Allocator> +void basic_istringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) +{ + __sb_.str(__s); +} + +// basic_ostringstream + +template <class _CharT, class _Traits, class _Allocator> +class _LIBCPP_TEMPLATE_VIS basic_ostringstream + : public basic_ostream<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef _Allocator allocator_type; + + typedef basic_string<char_type, traits_type, allocator_type> string_type; + +private: + basic_stringbuf<char_type, traits_type, allocator_type> __sb_; + +public: + // 27.8.2.1 Constructors: + inline _LIBCPP_INLINE_VISIBILITY + explicit basic_ostringstream(ios_base::openmode __wch = ios_base::out); + inline _LIBCPP_INLINE_VISIBILITY + explicit basic_ostringstream(const string_type& __s, + ios_base::openmode __wch = ios_base::out); +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY + basic_ostringstream(basic_ostringstream&& __rhs); + + // 27.8.2.2 Assign and swap: + basic_ostringstream& operator=(basic_ostringstream&& __rhs); +#endif // _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY + void swap(basic_ostringstream& __rhs); + + // 27.8.2.3 Members: + inline _LIBCPP_INLINE_VISIBILITY + basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; + inline _LIBCPP_INLINE_VISIBILITY + string_type str() const; + inline _LIBCPP_INLINE_VISIBILITY + void str(const string_type& __s); +}; + +template <class _CharT, class _Traits, class _Allocator> +basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(ios_base::openmode __wch) + : basic_ostream<_CharT, _Traits>(&__sb_), + __sb_(__wch | ios_base::out) +{ +} + +template <class _CharT, class _Traits, class _Allocator> +basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(const string_type& __s, + ios_base::openmode __wch) + : basic_ostream<_CharT, _Traits>(&__sb_), + __sb_(__s, __wch | ios_base::out) +{ +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(basic_ostringstream&& __rhs) + : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) +{ + basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_ostringstream<_CharT, _Traits, _Allocator>& +basic_ostringstream<_CharT, _Traits, _Allocator>::operator=(basic_ostringstream&& __rhs) +{ + basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +void +basic_ostringstream<_CharT, _Traits, _Allocator>::swap(basic_ostringstream& __rhs) +{ + basic_ostream<char_type, traits_type>::swap(__rhs); + __sb_.swap(__rhs.__sb_); +} + +template <class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, + basic_ostringstream<_CharT, _Traits, _Allocator>& __y) +{ + __x.swap(__y); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_stringbuf<_CharT, _Traits, _Allocator>* +basic_ostringstream<_CharT, _Traits, _Allocator>::rdbuf() const +{ + return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +basic_ostringstream<_CharT, _Traits, _Allocator>::str() const +{ + return __sb_.str(); +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_ostringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) +{ + __sb_.str(__s); +} + +// basic_stringstream + +template <class _CharT, class _Traits, class _Allocator> +class _LIBCPP_TEMPLATE_VIS basic_stringstream + : public basic_iostream<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef _Allocator allocator_type; + + typedef basic_string<char_type, traits_type, allocator_type> string_type; + +private: + basic_stringbuf<char_type, traits_type, allocator_type> __sb_; + +public: + // 27.8.2.1 Constructors: + inline _LIBCPP_INLINE_VISIBILITY + explicit basic_stringstream(ios_base::openmode __wch = ios_base::in | ios_base::out); + inline _LIBCPP_INLINE_VISIBILITY + explicit basic_stringstream(const string_type& __s, + ios_base::openmode __wch = ios_base::in | ios_base::out); +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY + basic_stringstream(basic_stringstream&& __rhs); + + // 27.8.2.2 Assign and swap: + basic_stringstream& operator=(basic_stringstream&& __rhs); +#endif // _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY + void swap(basic_stringstream& __rhs); + + // 27.8.2.3 Members: + inline _LIBCPP_INLINE_VISIBILITY + basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; + inline _LIBCPP_INLINE_VISIBILITY + string_type str() const; + inline _LIBCPP_INLINE_VISIBILITY + void str(const string_type& __s); +}; + +template <class _CharT, class _Traits, class _Allocator> +basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(ios_base::openmode __wch) + : basic_iostream<_CharT, _Traits>(&__sb_), + __sb_(__wch) +{ +} + +template <class _CharT, class _Traits, class _Allocator> +basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(const string_type& __s, + ios_base::openmode __wch) + : basic_iostream<_CharT, _Traits>(&__sb_), + __sb_(__s, __wch) +{ +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(basic_stringstream&& __rhs) + : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) +{ + basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_stringstream<_CharT, _Traits, _Allocator>& +basic_stringstream<_CharT, _Traits, _Allocator>::operator=(basic_stringstream&& __rhs) +{ + basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +void +basic_stringstream<_CharT, _Traits, _Allocator>::swap(basic_stringstream& __rhs) +{ + basic_iostream<char_type, traits_type>::swap(__rhs); + __sb_.swap(__rhs.__sb_); +} + +template <class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, + basic_stringstream<_CharT, _Traits, _Allocator>& __y) +{ + __x.swap(__y); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_stringbuf<_CharT, _Traits, _Allocator>* +basic_stringstream<_CharT, _Traits, _Allocator>::rdbuf() const +{ + return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +basic_stringstream<_CharT, _Traits, _Allocator>::str() const +{ + return __sb_.str(); +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_stringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) +{ + __sb_.str(__s); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_SSTREAM diff --git a/android/x86/include/v8/libc++/stack b/android/x86/include/v8/libc++/stack new file mode 100755 index 00000000..b50ca5cd --- /dev/null +++ b/android/x86/include/v8/libc++/stack @@ -0,0 +1,321 @@ +// -*- C++ -*- +//===---------------------------- stack -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STACK +#define _LIBCPP_STACK + +/* + stack synopsis + +namespace std +{ + +template <class T, class Container = deque<T>> +class stack +{ +public: + typedef Container container_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::size_type size_type; + +protected: + container_type c; + +public: + stack() = default; + ~stack() = default; + + stack(const stack& q) = default; + stack(stack&& q) = default; + + stack& operator=(const stack& q) = default; + stack& operator=(stack&& q) = default; + + explicit stack(const container_type& c); + explicit stack(container_type&& c); + template <class Alloc> explicit stack(const Alloc& a); + template <class Alloc> stack(const container_type& c, const Alloc& a); + template <class Alloc> stack(container_type&& c, const Alloc& a); + template <class Alloc> stack(const stack& c, const Alloc& a); + template <class Alloc> stack(stack&& c, const Alloc& a); + + bool empty() const; + size_type size() const; + reference top(); + const_reference top() const; + + void push(const value_type& x); + void push(value_type&& x); + template <class... Args> reference emplace(Args&&... args); // reference in C++17 + void pop(); + + void swap(stack& c) noexcept(is_nothrow_swappable_v<Container>) +}; + +template<class Container> + stack(Container) -> stack<typename Container::value_type, Container>; // C++17 + +template<class Container, class Allocator> + stack(Container, Allocator) -> stack<typename Container::value_type, Container>; // C++17 + +template <class T, class Container> + bool operator==(const stack<T, Container>& x, const stack<T, Container>& y); +template <class T, class Container> + bool operator< (const stack<T, Container>& x, const stack<T, Container>& y); +template <class T, class Container> + bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y); +template <class T, class Container> + bool operator> (const stack<T, Container>& x, const stack<T, Container>& y); +template <class T, class Container> + bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y); +template <class T, class Container> + bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y); + +template <class T, class Container> + void swap(stack<T, Container>& x, stack<T, Container>& y) + noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#include <__config> +#include <deque> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS stack; + +template <class _Tp, class _Container> +_LIBCPP_INLINE_VISIBILITY +bool +operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); + +template <class _Tp, class _Container> +_LIBCPP_INLINE_VISIBILITY +bool +operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); + +template <class _Tp, class _Container /*= deque<_Tp>*/> +class _LIBCPP_TEMPLATE_VIS stack +{ +public: + typedef _Container container_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::size_type size_type; + static_assert((is_same<_Tp, value_type>::value), "" ); + +protected: + container_type c; + +public: + _LIBCPP_INLINE_VISIBILITY + stack() + _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) + : c() {} + + _LIBCPP_INLINE_VISIBILITY + stack(const stack& __q) : c(__q.c) {} + + _LIBCPP_INLINE_VISIBILITY + stack& operator=(const stack& __q) {c = __q.c; return *this;} + + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + stack(stack&& __q) + _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value) + : c(_VSTD::move(__q.c)) {} + + _LIBCPP_INLINE_VISIBILITY + stack& operator=(stack&& __q) + _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) + {c = _VSTD::move(__q.c); return *this;} + + _LIBCPP_INLINE_VISIBILITY + explicit stack(container_type&& __c) : c(_VSTD::move(__c)) {} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + explicit stack(const container_type& __c) : c(__c) {} + + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + explicit stack(const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(__a) {} + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + stack(const container_type& __c, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(__c, __a) {} + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + stack(const stack& __s, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(__s.c, __a) {} +#ifndef _LIBCPP_CXX03_LANG + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + stack(container_type&& __c, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(_VSTD::move(__c), __a) {} + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + stack(stack&& __s, const _Alloc& __a, + typename enable_if<uses_allocator<container_type, + _Alloc>::value>::type* = 0) + : c(_VSTD::move(__s.c), __a) {} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const {return c.empty();} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return c.size();} + _LIBCPP_INLINE_VISIBILITY + reference top() {return c.back();} + _LIBCPP_INLINE_VISIBILITY + const_reference top() const {return c.back();} + + _LIBCPP_INLINE_VISIBILITY + void push(const value_type& __v) {c.push_back(__v);} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void push(value_type&& __v) {c.push_back(_VSTD::move(__v));} + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_STD_VER > 14 + decltype(auto) emplace(_Args&&... __args) + { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} +#else + void emplace(_Args&&... __args) + { c.emplace_back(_VSTD::forward<_Args>(__args)...);} +#endif +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + void pop() {c.pop_back();} + + _LIBCPP_INLINE_VISIBILITY + void swap(stack& __s) + _NOEXCEPT_(__is_nothrow_swappable<container_type>::value) + { + using _VSTD::swap; + swap(c, __s.c); + } + + template <class T1, class _C1> + friend + bool + operator==(const stack<T1, _C1>& __x, const stack<T1, _C1>& __y); + + template <class T1, class _C1> + friend + bool + operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y); +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _Container, + class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type +> +stack(_Container) + -> stack<typename _Container::value_type, _Container>; + +template<class _Container, + class _Alloc, + class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type, + class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type + > +stack(_Container, _Alloc) + -> stack<typename _Container::value_type, _Container>; +#endif + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) +{ + return __x.c == __y.c; +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) +{ + return __x.c < __y.c; +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) +{ + return !(__x < __y); +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _Container> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + __is_swappable<_Container>::value, + void +>::type +swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Tp, class _Container, class _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc> + : public uses_allocator<_Container, _Alloc> +{ +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STACK diff --git a/android/x86/include/v8/libc++/stdbool.h b/android/x86/include/v8/libc++/stdbool.h new file mode 100755 index 00000000..81a7cb30 --- /dev/null +++ b/android/x86/include/v8/libc++/stdbool.h @@ -0,0 +1,38 @@ +// -*- C++ -*- +//===--------------------------- stdbool.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_STDBOOL_H +#define _LIBCPP_STDBOOL_H + + +/* + stdbool.h synopsis + +Macros: + + __bool_true_false_are_defined + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <stdbool.h> + +#ifdef __cplusplus +#undef bool +#undef true +#undef false +#undef __bool_true_false_are_defined +#define __bool_true_false_are_defined 1 +#endif + +#endif // _LIBCPP_STDBOOL_H diff --git a/android/x86/include/v8/libc++/stddef.h b/android/x86/include/v8/libc++/stddef.h new file mode 100755 index 00000000..6497dcda --- /dev/null +++ b/android/x86/include/v8/libc++/stddef.h @@ -0,0 +1,62 @@ +// -*- C++ -*- +//===--------------------------- stddef.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#if defined(__need_ptrdiff_t) || defined(__need_size_t) || \ + defined(__need_wchar_t) || defined(__need_NULL) || defined(__need_wint_t) + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <stddef.h> + +#elif !defined(_LIBCPP_STDDEF_H) +#define _LIBCPP_STDDEF_H + +/* + stddef.h synopsis + +Macros: + + offsetof(type,member-designator) + NULL + +Types: + + ptrdiff_t + size_t + max_align_t + nullptr_t + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <stddef.h> + +#ifdef __cplusplus + +extern "C++" { +#include <__nullptr> +using std::nullptr_t; +} + +// Re-use the compiler's <stddef.h> max_align_t where possible. +#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T) && \ + !defined(__DEFINED_max_align_t) && !defined(__NetBSD__) +typedef long double max_align_t; +#endif + +#endif + +#endif // _LIBCPP_STDDEF_H diff --git a/android/x86/include/v8/libc++/stdexcept b/android/x86/include/v8/libc++/stdexcept new file mode 100755 index 00000000..481f9043 --- /dev/null +++ b/android/x86/include/v8/libc++/stdexcept @@ -0,0 +1,304 @@ +// -*- C++ -*- +//===--------------------------- stdexcept --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STDEXCEPT +#define _LIBCPP_STDEXCEPT + +/* + stdexcept synopsis + +namespace std +{ + +class logic_error; + class domain_error; + class invalid_argument; + class length_error; + class out_of_range; +class runtime_error; + class range_error; + class overflow_error; + class underflow_error; + +for each class xxx_error: + +class xxx_error : public exception // at least indirectly +{ +public: + explicit xxx_error(const string& what_arg); + explicit xxx_error(const char* what_arg); + + virtual const char* what() const noexcept // returns what_arg +}; + +} // std + +*/ + +#include <__config> +#include <exception> +#include <iosfwd> // for string forward decl +#ifdef _LIBCPP_NO_EXCEPTIONS +#include <cstdlib> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_ABI_VCRUNTIME +class _LIBCPP_HIDDEN __libcpp_refstring +{ + const char* __imp_; + + bool __uses_refcount() const; +public: + explicit __libcpp_refstring(const char* __msg); + __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT; + __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT; + ~__libcpp_refstring(); + + const char* c_str() const _NOEXCEPT {return __imp_;} +}; +#endif // !_LIBCPP_ABI_VCRUNTIME + +_LIBCPP_END_NAMESPACE_STD + +namespace std // purposefully not using versioning namespace +{ + +class _LIBCPP_EXCEPTION_ABI logic_error + : public exception +{ +#ifndef _LIBCPP_ABI_VCRUNTIME +private: + _VSTD::__libcpp_refstring __imp_; +public: + explicit logic_error(const string&); + explicit logic_error(const char*); + + logic_error(const logic_error&) _NOEXCEPT; + logic_error& operator=(const logic_error&) _NOEXCEPT; + + virtual ~logic_error() _NOEXCEPT; + + virtual const char* what() const _NOEXCEPT; +#else +public: + explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string + _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {} +#endif +}; + +class _LIBCPP_EXCEPTION_ABI runtime_error + : public exception +{ +#ifndef _LIBCPP_ABI_VCRUNTIME +private: + _VSTD::__libcpp_refstring __imp_; +public: + explicit runtime_error(const string&); + explicit runtime_error(const char*); + + runtime_error(const runtime_error&) _NOEXCEPT; + runtime_error& operator=(const runtime_error&) _NOEXCEPT; + + virtual ~runtime_error() _NOEXCEPT; + + virtual const char* what() const _NOEXCEPT; +#else +public: + explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string + _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {} +#endif // _LIBCPP_ABI_VCRUNTIME +}; + +class _LIBCPP_EXCEPTION_ABI domain_error + : public logic_error +{ +public: + _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {} + _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {} + +#ifndef _LIBCPP_ABI_VCRUNTIME + virtual ~domain_error() _NOEXCEPT; +#endif +}; + +class _LIBCPP_EXCEPTION_ABI invalid_argument + : public logic_error +{ +public: + _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {} + _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {} + +#ifndef _LIBCPP_ABI_VCRUNTIME + virtual ~invalid_argument() _NOEXCEPT; +#endif +}; + +class _LIBCPP_EXCEPTION_ABI length_error + : public logic_error +{ +public: + _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {} + _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {} +#ifndef _LIBCPP_ABI_VCRUNTIME + virtual ~length_error() _NOEXCEPT; +#endif +}; + +class _LIBCPP_EXCEPTION_ABI out_of_range + : public logic_error +{ +public: + _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {} + _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {} + +#ifndef _LIBCPP_ABI_VCRUNTIME + virtual ~out_of_range() _NOEXCEPT; +#endif +}; + +class _LIBCPP_EXCEPTION_ABI range_error + : public runtime_error +{ +public: + _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {} + _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {} + +#ifndef _LIBCPP_ABI_VCRUNTIME + virtual ~range_error() _NOEXCEPT; +#endif +}; + +class _LIBCPP_EXCEPTION_ABI overflow_error + : public runtime_error +{ +public: + _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {} + _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {} + +#ifndef _LIBCPP_ABI_VCRUNTIME + virtual ~overflow_error() _NOEXCEPT; +#endif +}; + +class _LIBCPP_EXCEPTION_ABI underflow_error + : public runtime_error +{ +public: + _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {} + _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {} + +#ifndef _LIBCPP_ABI_VCRUNTIME + virtual ~underflow_error() _NOEXCEPT; +#endif +}; + +} // std + +_LIBCPP_BEGIN_NAMESPACE_STD + +// in the dylib +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*); + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_logic_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw logic_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_domain_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw domain_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_invalid_argument(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw invalid_argument(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_length_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw length_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_out_of_range(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_range_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw range_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_overflow_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw overflow_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_underflow_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw underflow_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STDEXCEPT diff --git a/android/x86/include/v8/libc++/stdint.h b/android/x86/include/v8/libc++/stdint.h new file mode 100755 index 00000000..c8922984 --- /dev/null +++ b/android/x86/include/v8/libc++/stdint.h @@ -0,0 +1,120 @@ +// -*- C++ -*- +//===---------------------------- stdint.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STDINT_H +#define _LIBCPP_STDINT_H + +/* + stdint.h synopsis + +Macros: + + INT8_MIN + INT16_MIN + INT32_MIN + INT64_MIN + + INT8_MAX + INT16_MAX + INT32_MAX + INT64_MAX + + UINT8_MAX + UINT16_MAX + UINT32_MAX + UINT64_MAX + + INT_LEAST8_MIN + INT_LEAST16_MIN + INT_LEAST32_MIN + INT_LEAST64_MIN + + INT_LEAST8_MAX + INT_LEAST16_MAX + INT_LEAST32_MAX + INT_LEAST64_MAX + + UINT_LEAST8_MAX + UINT_LEAST16_MAX + UINT_LEAST32_MAX + UINT_LEAST64_MAX + + INT_FAST8_MIN + INT_FAST16_MIN + INT_FAST32_MIN + INT_FAST64_MIN + + INT_FAST8_MAX + INT_FAST16_MAX + INT_FAST32_MAX + INT_FAST64_MAX + + UINT_FAST8_MAX + UINT_FAST16_MAX + UINT_FAST32_MAX + UINT_FAST64_MAX + + INTPTR_MIN + INTPTR_MAX + UINTPTR_MAX + + INTMAX_MIN + INTMAX_MAX + + UINTMAX_MAX + + PTRDIFF_MIN + PTRDIFF_MAX + + SIG_ATOMIC_MIN + SIG_ATOMIC_MAX + + SIZE_MAX + + WCHAR_MIN + WCHAR_MAX + + WINT_MIN + WINT_MAX + + INT8_C(value) + INT16_C(value) + INT32_C(value) + INT64_C(value) + + UINT8_C(value) + UINT16_C(value) + UINT32_C(value) + UINT64_C(value) + + INTMAX_C(value) + UINTMAX_C(value) + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +/* C99 stdlib (e.g. glibc < 2.18) does not provide macros needed + for C++11 unless __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS + are defined +*/ +#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS) +# define __STDC_LIMIT_MACROS +#endif +#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS) +# define __STDC_CONSTANT_MACROS +#endif + +#include_next <stdint.h> + +#endif // _LIBCPP_STDINT_H diff --git a/android/x86/include/v8/libc++/stdio.h b/android/x86/include/v8/libc++/stdio.h new file mode 100755 index 00000000..e08e6bc9 --- /dev/null +++ b/android/x86/include/v8/libc++/stdio.h @@ -0,0 +1,119 @@ +// -*- C++ -*- +//===---------------------------- stdio.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#if defined(__need_FILE) || defined(__need___FILE) + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <stdio.h> + +#elif !defined(_LIBCPP_STDIO_H) +#define _LIBCPP_STDIO_H + +/* + stdio.h synopsis + +Macros: + + BUFSIZ + EOF + FILENAME_MAX + FOPEN_MAX + L_tmpnam + NULL + SEEK_CUR + SEEK_END + SEEK_SET + TMP_MAX + _IOFBF + _IOLBF + _IONBF + stderr + stdin + stdout + +Types: + +FILE +fpos_t +size_t + +int remove(const char* filename); +int rename(const char* old, const char* new); +FILE* tmpfile(void); +char* tmpnam(char* s); +int fclose(FILE* stream); +int fflush(FILE* stream); +FILE* fopen(const char* restrict filename, const char* restrict mode); +FILE* freopen(const char* restrict filename, const char * restrict mode, + FILE * restrict stream); +void setbuf(FILE* restrict stream, char* restrict buf); +int setvbuf(FILE* restrict stream, char* restrict buf, int mode, size_t size); +int fprintf(FILE* restrict stream, const char* restrict format, ...); +int fscanf(FILE* restrict stream, const char * restrict format, ...); +int printf(const char* restrict format, ...); +int scanf(const char* restrict format, ...); +int snprintf(char* restrict s, size_t n, const char* restrict format, ...); // C99 +int sprintf(char* restrict s, const char* restrict format, ...); +int sscanf(const char* restrict s, const char* restrict format, ...); +int vfprintf(FILE* restrict stream, const char* restrict format, va_list arg); +int vfscanf(FILE* restrict stream, const char* restrict format, va_list arg); // C99 +int vprintf(const char* restrict format, va_list arg); +int vscanf(const char* restrict format, va_list arg); // C99 +int vsnprintf(char* restrict s, size_t n, const char* restrict format, // C99 + va_list arg); +int vsprintf(char* restrict s, const char* restrict format, va_list arg); +int vsscanf(const char* restrict s, const char* restrict format, va_list arg); // C99 +int fgetc(FILE* stream); +char* fgets(char* restrict s, int n, FILE* restrict stream); +int fputc(int c, FILE* stream); +int fputs(const char* restrict s, FILE* restrict stream); +int getc(FILE* stream); +int getchar(void); +char* gets(char* s); // removed in C++14 +int putc(int c, FILE* stream); +int putchar(int c); +int puts(const char* s); +int ungetc(int c, FILE* stream); +size_t fread(void* restrict ptr, size_t size, size_t nmemb, + FILE* restrict stream); +size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb, + FILE* restrict stream); +int fgetpos(FILE* restrict stream, fpos_t* restrict pos); +int fseek(FILE* stream, long offset, int whence); +int fsetpos(FILE*stream, const fpos_t* pos); +long ftell(FILE* stream); +void rewind(FILE* stream); +void clearerr(FILE* stream); +int feof(FILE* stream); +int ferror(FILE* stream); +void perror(const char* s); +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <stdio.h> + +#ifdef __cplusplus + +#undef getc +#undef putc +#undef clearerr +#undef feof +#undef ferror + +#endif + +#endif // _LIBCPP_STDIO_H diff --git a/android/x86/include/v8/libc++/stdlib.h b/android/x86/include/v8/libc++/stdlib.h new file mode 100755 index 00000000..2087544d --- /dev/null +++ b/android/x86/include/v8/libc++/stdlib.h @@ -0,0 +1,125 @@ +// -*- C++ -*- +//===--------------------------- stdlib.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#if defined(__need_malloc_and_calloc) + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <stdlib.h> + +#elif !defined(_LIBCPP_STDLIB_H) +#define _LIBCPP_STDLIB_H + +/* + stdlib.h synopsis + +Macros: + + EXIT_FAILURE + EXIT_SUCCESS + MB_CUR_MAX + NULL + RAND_MAX + +Types: + + size_t + div_t + ldiv_t + lldiv_t // C99 + +double atof (const char* nptr); +int atoi (const char* nptr); +long atol (const char* nptr); +long long atoll(const char* nptr); // C99 +double strtod (const char* restrict nptr, char** restrict endptr); +float strtof (const char* restrict nptr, char** restrict endptr); // C99 +long double strtold (const char* restrict nptr, char** restrict endptr); // C99 +long strtol (const char* restrict nptr, char** restrict endptr, int base); +long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99 +unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base); +unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99 +int rand(void); +void srand(unsigned int seed); +void* calloc(size_t nmemb, size_t size); +void free(void* ptr); +void* malloc(size_t size); +void* realloc(void* ptr, size_t size); +void abort(void); +int atexit(void (*func)(void)); +void exit(int status); +void _Exit(int status); +char* getenv(const char* name); +int system(const char* string); +void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); +void qsort(void* base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); +int abs( int j); +long abs( long j); +long long abs(long long j); // C++0X +long labs( long j); +long long llabs(long long j); // C99 +div_t div( int numer, int denom); +ldiv_t div( long numer, long denom); +lldiv_t div(long long numer, long long denom); // C++0X +ldiv_t ldiv( long numer, long denom); +lldiv_t lldiv(long long numer, long long denom); // C99 +int mblen(const char* s, size_t n); +int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n); +int wctomb(char* s, wchar_t wchar); +size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n); +size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n); +int at_quick_exit(void (*func)(void)) // C++11 +void quick_exit(int status); // C++11 +void *aligned_alloc(size_t alignment, size_t size); // C11 + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <stdlib.h> + +#ifdef __cplusplus + +extern "C++" { + +#undef abs +#undef div +#undef labs +#undef ldiv +#ifndef _LIBCPP_HAS_NO_LONG_LONG +#undef llabs +#undef lldiv +#endif + +// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined +#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) +inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);} +#ifndef _LIBCPP_HAS_NO_LONG_LONG +inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);} +#endif // _LIBCPP_HAS_NO_LONG_LONG + +inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);} +#ifndef _LIBCPP_HAS_NO_LONG_LONG +inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);} +#endif // _LIBCPP_HAS_NO_LONG_LONG +#endif // _LIBCPP_MSVCRT / __sun__ / _AIX + +} // extern "C++" + +#endif // __cplusplus + +#endif // _LIBCPP_STDLIB_H diff --git a/android/x86/include/v8/libc++/streambuf b/android/x86/include/v8/libc++/streambuf new file mode 100755 index 00000000..48c07d5e --- /dev/null +++ b/android/x86/include/v8/libc++/streambuf @@ -0,0 +1,500 @@ +// -*- C++ -*- +//===------------------------- streambuf ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STEAMBUF +#define _LIBCPP_STEAMBUF + +/* + streambuf synopsis + +namespace std +{ + +template <class charT, class traits = char_traits<charT> > +class basic_streambuf +{ +public: + // types: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + virtual ~basic_streambuf(); + + // 27.6.2.2.1 locales: + locale pubimbue(const locale& loc); + locale getloc() const; + + // 27.6.2.2.2 buffer and positioning: + basic_streambuf* pubsetbuf(char_type* s, streamsize n); + pos_type pubseekoff(off_type off, ios_base::seekdir way, + ios_base::openmode which = ios_base::in | ios_base::out); + pos_type pubseekpos(pos_type sp, + ios_base::openmode which = ios_base::in | ios_base::out); + int pubsync(); + + // Get and put areas: + // 27.6.2.2.3 Get area: + streamsize in_avail(); + int_type snextc(); + int_type sbumpc(); + int_type sgetc(); + streamsize sgetn(char_type* s, streamsize n); + + // 27.6.2.2.4 Putback: + int_type sputbackc(char_type c); + int_type sungetc(); + + // 27.6.2.2.5 Put area: + int_type sputc(char_type c); + streamsize sputn(const char_type* s, streamsize n); + +protected: + basic_streambuf(); + basic_streambuf(const basic_streambuf& rhs); + basic_streambuf& operator=(const basic_streambuf& rhs); + void swap(basic_streambuf& rhs); + + // 27.6.2.3.2 Get area: + char_type* eback() const; + char_type* gptr() const; + char_type* egptr() const; + void gbump(int n); + void setg(char_type* gbeg, char_type* gnext, char_type* gend); + + // 27.6.2.3.3 Put area: + char_type* pbase() const; + char_type* pptr() const; + char_type* epptr() const; + void pbump(int n); + void setp(char_type* pbeg, char_type* pend); + + // 27.6.2.4 virtual functions: + // 27.6.2.4.1 Locales: + virtual void imbue(const locale& loc); + + // 27.6.2.4.2 Buffer management and positioning: + virtual basic_streambuf* setbuf(char_type* s, streamsize n); + virtual pos_type seekoff(off_type off, ios_base::seekdir way, + ios_base::openmode which = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type sp, + ios_base::openmode which = ios_base::in | ios_base::out); + virtual int sync(); + + // 27.6.2.4.3 Get area: + virtual streamsize showmanyc(); + virtual streamsize xsgetn(char_type* s, streamsize n); + virtual int_type underflow(); + virtual int_type uflow(); + + // 27.6.2.4.4 Putback: + virtual int_type pbackfail(int_type c = traits_type::eof()); + + // 27.6.2.4.5 Put area: + virtual streamsize xsputn(const char_type* s, streamsize n); + virtual int_type overflow (int_type c = traits_type::eof()); +}; + +} // std + +*/ + +#include <__config> +#include <iosfwd> +#include <ios> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _CharT, class _Traits> +class _LIBCPP_TEMPLATE_VIS basic_streambuf +{ +public: + // types: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + static_assert((is_same<_CharT, typename traits_type::char_type>::value), + "traits_type::char_type must be the same type as CharT"); + + virtual ~basic_streambuf(); + + // 27.6.2.2.1 locales: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + locale pubimbue(const locale& __loc) { + imbue(__loc); + locale __r = __loc_; + __loc_ = __loc; + return __r; + } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + locale getloc() const { return __loc_; } + + // 27.6.2.2.2 buffer and positioning: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + basic_streambuf* pubsetbuf(char_type* __s, streamsize __n) + { return setbuf(__s, __n); } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + pos_type pubseekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __which = ios_base::in | ios_base::out) + { return seekoff(__off, __way, __which); } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + pos_type pubseekpos(pos_type __sp, + ios_base::openmode __which = ios_base::in | ios_base::out) + { return seekpos(__sp, __which); } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + int pubsync() { return sync(); } + + // Get and put areas: + // 27.6.2.2.3 Get area: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + streamsize in_avail() { + if (__ninp_ < __einp_) + return static_cast<streamsize>(__einp_ - __ninp_); + return showmanyc(); + } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + int_type snextc() { + if (sbumpc() == traits_type::eof()) + return traits_type::eof(); + return sgetc(); + } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + int_type sbumpc() { + if (__ninp_ == __einp_) + return uflow(); + return traits_type::to_int_type(*__ninp_++); + } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + int_type sgetc() { + if (__ninp_ == __einp_) + return underflow(); + return traits_type::to_int_type(*__ninp_); + } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + streamsize sgetn(char_type* __s, streamsize __n) + { return xsgetn(__s, __n); } + + // 27.6.2.2.4 Putback: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + int_type sputbackc(char_type __c) { + if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1])) + return pbackfail(traits_type::to_int_type(__c)); + return traits_type::to_int_type(*--__ninp_); + } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + int_type sungetc() { + if (__binp_ == __ninp_) + return pbackfail(); + return traits_type::to_int_type(*--__ninp_); + } + + // 27.6.2.2.5 Put area: + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + int_type sputc(char_type __c) { + if (__nout_ == __eout_) + return overflow(traits_type::to_int_type(__c)); + *__nout_++ = __c; + return traits_type::to_int_type(__c); + } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + streamsize sputn(const char_type* __s, streamsize __n) + { return xsputn(__s, __n); } + +protected: + basic_streambuf(); + basic_streambuf(const basic_streambuf& __rhs); + basic_streambuf& operator=(const basic_streambuf& __rhs); + void swap(basic_streambuf& __rhs); + + // 27.6.2.3.2 Get area: + _LIBCPP_INLINE_VISIBILITY char_type* eback() const {return __binp_;} + _LIBCPP_INLINE_VISIBILITY char_type* gptr() const {return __ninp_;} + _LIBCPP_INLINE_VISIBILITY char_type* egptr() const {return __einp_;} + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + void gbump(int __n) { __ninp_ += __n; } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) { + __binp_ = __gbeg; + __ninp_ = __gnext; + __einp_ = __gend; + } + + // 27.6.2.3.3 Put area: + _LIBCPP_INLINE_VISIBILITY char_type* pbase() const {return __bout_;} + _LIBCPP_INLINE_VISIBILITY char_type* pptr() const {return __nout_;} + _LIBCPP_INLINE_VISIBILITY char_type* epptr() const {return __eout_;} + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + void pbump(int __n) { __nout_ += __n; } + + _LIBCPP_INLINE_VISIBILITY + void __pbump(streamsize __n) { __nout_ += __n; } + + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + void setp(char_type* __pbeg, char_type* __pend) { + __bout_ = __nout_ = __pbeg; + __eout_ = __pend; + } + + // 27.6.2.4 virtual functions: + // 27.6.2.4.1 Locales: + virtual void imbue(const locale& __loc); + + // 27.6.2.4.2 Buffer management and positioning: + virtual basic_streambuf* setbuf(char_type* __s, streamsize __n); + virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __which = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type __sp, + ios_base::openmode __which = ios_base::in | ios_base::out); + virtual int sync(); + + // 27.6.2.4.3 Get area: + virtual streamsize showmanyc(); + virtual streamsize xsgetn(char_type* __s, streamsize __n); + virtual int_type underflow(); + virtual int_type uflow(); + + // 27.6.2.4.4 Putback: + virtual int_type pbackfail(int_type __c = traits_type::eof()); + + // 27.6.2.4.5 Put area: + virtual streamsize xsputn(const char_type* __s, streamsize __n); + virtual int_type overflow(int_type __c = traits_type::eof()); + +private: + locale __loc_; + char_type* __binp_; + char_type* __ninp_; + char_type* __einp_; + char_type* __bout_; + char_type* __nout_; + char_type* __eout_; +}; + +template <class _CharT, class _Traits> +basic_streambuf<_CharT, _Traits>::~basic_streambuf() +{ +} + +template <class _CharT, class _Traits> +basic_streambuf<_CharT, _Traits>::basic_streambuf() + : __binp_(0), + __ninp_(0), + __einp_(0), + __bout_(0), + __nout_(0), + __eout_(0) +{ +} + +template <class _CharT, class _Traits> +basic_streambuf<_CharT, _Traits>::basic_streambuf(const basic_streambuf& __sb) + : __loc_(__sb.__loc_), + __binp_(__sb.__binp_), + __ninp_(__sb.__ninp_), + __einp_(__sb.__einp_), + __bout_(__sb.__bout_), + __nout_(__sb.__nout_), + __eout_(__sb.__eout_) +{ +} + +template <class _CharT, class _Traits> +basic_streambuf<_CharT, _Traits>& +basic_streambuf<_CharT, _Traits>::operator=(const basic_streambuf& __sb) +{ + __loc_ = __sb.__loc_; + __binp_ = __sb.__binp_; + __ninp_ = __sb.__ninp_; + __einp_ = __sb.__einp_; + __bout_ = __sb.__bout_; + __nout_ = __sb.__nout_; + __eout_ = __sb.__eout_; + return *this; +} + +template <class _CharT, class _Traits> +void +basic_streambuf<_CharT, _Traits>::swap(basic_streambuf& __sb) +{ + _VSTD::swap(__loc_, __sb.__loc_); + _VSTD::swap(__binp_, __sb.__binp_); + _VSTD::swap(__ninp_, __sb.__ninp_); + _VSTD::swap(__einp_, __sb.__einp_); + _VSTD::swap(__bout_, __sb.__bout_); + _VSTD::swap(__nout_, __sb.__nout_); + _VSTD::swap(__eout_, __sb.__eout_); +} + +template <class _CharT, class _Traits> +void +basic_streambuf<_CharT, _Traits>::imbue(const locale&) +{ +} + +template <class _CharT, class _Traits> +basic_streambuf<_CharT, _Traits>* +basic_streambuf<_CharT, _Traits>::setbuf(char_type*, streamsize) +{ + return this; +} + +template <class _CharT, class _Traits> +typename basic_streambuf<_CharT, _Traits>::pos_type +basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir, + ios_base::openmode) +{ + return pos_type(off_type(-1)); +} + +template <class _CharT, class _Traits> +typename basic_streambuf<_CharT, _Traits>::pos_type +basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode) +{ + return pos_type(off_type(-1)); +} + +template <class _CharT, class _Traits> +int +basic_streambuf<_CharT, _Traits>::sync() +{ + return 0; +} + +template <class _CharT, class _Traits> +streamsize +basic_streambuf<_CharT, _Traits>::showmanyc() +{ + return 0; +} + +template <class _CharT, class _Traits> +streamsize +basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n) +{ + const int_type __eof = traits_type::eof(); + int_type __c; + streamsize __i = 0; + while(__i < __n) + { + if (__ninp_ < __einp_) + { + const streamsize __len = _VSTD::min(static_cast<streamsize>(INT_MAX), + _VSTD::min(__einp_ - __ninp_, __n - __i)); + traits_type::copy(__s, __ninp_, __len); + __s += __len; + __i += __len; + this->gbump(__len); + } + else if ((__c = uflow()) != __eof) + { + *__s = traits_type::to_char_type(__c); + ++__s; + ++__i; + } + else + break; + } + return __i; +} + +template <class _CharT, class _Traits> +typename basic_streambuf<_CharT, _Traits>::int_type +basic_streambuf<_CharT, _Traits>::underflow() +{ + return traits_type::eof(); +} + +template <class _CharT, class _Traits> +typename basic_streambuf<_CharT, _Traits>::int_type +basic_streambuf<_CharT, _Traits>::uflow() +{ + if (underflow() == traits_type::eof()) + return traits_type::eof(); + return traits_type::to_int_type(*__ninp_++); +} + +template <class _CharT, class _Traits> +typename basic_streambuf<_CharT, _Traits>::int_type +basic_streambuf<_CharT, _Traits>::pbackfail(int_type) +{ + return traits_type::eof(); +} + +template <class _CharT, class _Traits> +streamsize +basic_streambuf<_CharT, _Traits>::xsputn(const char_type* __s, streamsize __n) +{ + streamsize __i = 0; + int_type __eof = traits_type::eof(); + while( __i < __n) + { + if (__nout_ >= __eout_) + { + if (overflow(traits_type::to_int_type(*__s)) == __eof) + break; + ++__s; + ++__i; + } + else + { + streamsize __chunk_size = _VSTD::min(__eout_ - __nout_, __n - __i); + traits_type::copy(__nout_, __s, __chunk_size); + __nout_ += __chunk_size; + __s += __chunk_size; + __i += __chunk_size; + } + } + return __i; +} + +template <class _CharT, class _Traits> +typename basic_streambuf<_CharT, _Traits>::int_type +basic_streambuf<_CharT, _Traits>::overflow(int_type) +{ + return traits_type::eof(); +} + +#ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>) + +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>) +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_STEAMBUF diff --git a/android/x86/include/v8/libc++/string b/android/x86/include/v8/libc++/string new file mode 100755 index 00000000..3b01c410 --- /dev/null +++ b/android/x86/include/v8/libc++/string @@ -0,0 +1,4379 @@ +// -*- C++ -*- +//===--------------------------- string -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STRING +#define _LIBCPP_STRING + +/* + string synopsis + +namespace std +{ + +template <class stateT> +class fpos +{ +private: + stateT st; +public: + fpos(streamoff = streamoff()); + + operator streamoff() const; + + stateT state() const; + void state(stateT); + + fpos& operator+=(streamoff); + fpos operator+ (streamoff) const; + fpos& operator-=(streamoff); + fpos operator- (streamoff) const; +}; + +template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y); + +template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y); +template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y); + +template <class charT> +struct char_traits +{ + typedef charT char_type; + typedef ... int_type; + typedef streamoff off_type; + typedef streampos pos_type; + typedef mbstate_t state_type; + + static void assign(char_type& c1, const char_type& c2) noexcept; + static constexpr bool eq(char_type c1, char_type c2) noexcept; + static constexpr bool lt(char_type c1, char_type c2) noexcept; + + static int compare(const char_type* s1, const char_type* s2, size_t n); + static size_t length(const char_type* s); + static const char_type* find(const char_type* s, size_t n, const char_type& a); + static char_type* move(char_type* s1, const char_type* s2, size_t n); + static char_type* copy(char_type* s1, const char_type* s2, size_t n); + static char_type* assign(char_type* s, size_t n, char_type a); + + static constexpr int_type not_eof(int_type c) noexcept; + static constexpr char_type to_char_type(int_type c) noexcept; + static constexpr int_type to_int_type(char_type c) noexcept; + static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; + static constexpr int_type eof() noexcept; +}; + +template <> struct char_traits<char>; +template <> struct char_traits<wchar_t>; + +template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > +class basic_string +{ +public: +// types: + typedef traits traits_type; + typedef typename traits_type::char_type value_type; + typedef Allocator allocator_type; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + static const size_type npos = -1; + + basic_string() + noexcept(is_nothrow_default_constructible<allocator_type>::value); + explicit basic_string(const allocator_type& a); + basic_string(const basic_string& str); + basic_string(basic_string&& str) + noexcept(is_nothrow_move_constructible<allocator_type>::value); + basic_string(const basic_string& str, size_type pos, + const allocator_type& a = allocator_type()); + basic_string(const basic_string& str, size_type pos, size_type n, + const Allocator& a = Allocator()); + template<class T> + basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17 + template <class T> + explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17 + basic_string(const value_type* s, const allocator_type& a = allocator_type()); + basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type()); + basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); + template<class InputIterator> + basic_string(InputIterator begin, InputIterator end, + const allocator_type& a = allocator_type()); + basic_string(initializer_list<value_type>, const Allocator& = Allocator()); + basic_string(const basic_string&, const Allocator&); + basic_string(basic_string&&, const Allocator&); + + ~basic_string(); + + operator basic_string_view<charT, traits>() const noexcept; + + basic_string& operator=(const basic_string& str); + template <class T> + basic_string& operator=(const T& t); // C++17 + basic_string& operator=(basic_string&& str) + noexcept( + allocator_type::propagate_on_container_move_assignment::value || + allocator_type::is_always_equal::value ); // C++17 + basic_string& operator=(const value_type* s); + basic_string& operator=(value_type c); + basic_string& operator=(initializer_list<value_type>); + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + size_type size() const noexcept; + size_type length() const noexcept; + size_type max_size() const noexcept; + size_type capacity() const noexcept; + + void resize(size_type n, value_type c); + void resize(size_type n); + + void reserve(size_type res_arg = 0); + void shrink_to_fit(); + void clear() noexcept; + bool empty() const noexcept; + + const_reference operator[](size_type pos) const; + reference operator[](size_type pos); + + const_reference at(size_type n) const; + reference at(size_type n); + + basic_string& operator+=(const basic_string& str); + template <class T> + basic_string& operator+=(const T& t); // C++17 + basic_string& operator+=(const value_type* s); + basic_string& operator+=(value_type c); + basic_string& operator+=(initializer_list<value_type>); + + basic_string& append(const basic_string& str); + template <class T> + basic_string& append(const T& t); // C++17 + basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14 + template <class T> + basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17 + basic_string& append(const value_type* s, size_type n); + basic_string& append(const value_type* s); + basic_string& append(size_type n, value_type c); + template<class InputIterator> + basic_string& append(InputIterator first, InputIterator last); + basic_string& append(initializer_list<value_type>); + + void push_back(value_type c); + void pop_back(); + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + basic_string& assign(const basic_string& str); + template <class T> + basic_string& assign(const T& t); // C++17 + basic_string& assign(basic_string&& str); + basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14 + template <class T> + basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17 + basic_string& assign(const value_type* s, size_type n); + basic_string& assign(const value_type* s); + basic_string& assign(size_type n, value_type c); + template<class InputIterator> + basic_string& assign(InputIterator first, InputIterator last); + basic_string& assign(initializer_list<value_type>); + + basic_string& insert(size_type pos1, const basic_string& str); + template <class T> + basic_string& insert(size_type pos1, const T& t); + basic_string& insert(size_type pos1, const basic_string& str, + size_type pos2, size_type n); + template <class T> + basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17 + basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14 + basic_string& insert(size_type pos, const value_type* s); + basic_string& insert(size_type pos, size_type n, value_type c); + iterator insert(const_iterator p, value_type c); + iterator insert(const_iterator p, size_type n, value_type c); + template<class InputIterator> + iterator insert(const_iterator p, InputIterator first, InputIterator last); + iterator insert(const_iterator p, initializer_list<value_type>); + + basic_string& erase(size_type pos = 0, size_type n = npos); + iterator erase(const_iterator position); + iterator erase(const_iterator first, const_iterator last); + + basic_string& replace(size_type pos1, size_type n1, const basic_string& str); + template <class T> + basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17 + basic_string& replace(size_type pos1, size_type n1, const basic_string& str, + size_type pos2, size_type n2=npos); // C++14 + template <class T> + basic_string& replace(size_type pos1, size_type n1, const T& t, + size_type pos2, size_type n); // C++17 + basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); + basic_string& replace(size_type pos, size_type n1, const value_type* s); + basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); + basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); + template <class T> + basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17 + basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); + basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); + basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c); + template<class InputIterator> + basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); + basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); + + size_type copy(value_type* s, size_type n, size_type pos = 0) const; + basic_string substr(size_type pos = 0, size_type n = npos) const; + + void swap(basic_string& str) + noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || + allocator_traits<allocator_type>::is_always_equal::value); // C++17 + + const value_type* c_str() const noexcept; + const value_type* data() const noexcept; + value_type* data() noexcept; // C++17 + + allocator_type get_allocator() const noexcept; + + size_type find(const basic_string& str, size_type pos = 0) const noexcept; + template <class T> + size_type find(const T& t, size_type pos = 0) const; // C++17 + size_type find(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find(const value_type* s, size_type pos = 0) const noexcept; + size_type find(value_type c, size_type pos = 0) const noexcept; + + size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; + template <class T> + size_type rfind(const T& t, size_type pos = npos) const; // C++17 + size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; + size_type rfind(const value_type* s, size_type pos = npos) const noexcept; + size_type rfind(value_type c, size_type pos = npos) const noexcept; + + size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; + template <class T> + size_type find_first_of(const T& t, size_type pos = 0) const; // C++17 + size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; + size_type find_first_of(value_type c, size_type pos = 0) const noexcept; + + size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; + template <class T> + size_type find_last_of(const T& t, size_type pos = npos) const noexcept; // C++17 + size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; + size_type find_last_of(value_type c, size_type pos = npos) const noexcept; + + size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; + template <class T> + size_type find_first_not_of(const T& t, size_type pos = 0) const; // C++17 + size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; + size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; + + size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; + template <class T> + size_type find_last_not_of(const T& t, size_type pos = npos) const; // C++17 + size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; + size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; + + int compare(const basic_string& str) const noexcept; + template <class T> + int compare(const T& t) const noexcept; // C++17 + int compare(size_type pos1, size_type n1, const basic_string& str) const; + template <class T> + int compare(size_type pos1, size_type n1, const T& t) const; // C++17 + int compare(size_type pos1, size_type n1, const basic_string& str, + size_type pos2, size_type n2=npos) const; // C++14 + template <class T> + int compare(size_type pos1, size_type n1, const T& t, + size_type pos2, size_type n2=npos) const; // C++17 + int compare(const value_type* s) const noexcept; + int compare(size_type pos1, size_type n1, const value_type* s) const; + int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; + + bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a + bool starts_with(charT c) const noexcept; // C++2a + bool starts_with(const charT* s) const; // C++2a + bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a + bool ends_with(charT c) const noexcept; // C++2a + bool ends_with(const charT* s) const; // C++2a + + bool __invariants() const; +}; + +template<class InputIterator, + class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> +basic_string(InputIterator, InputIterator, Allocator = Allocator()) + -> basic_string<typename iterator_traits<InputIterator>::value_type, + char_traits<typename iterator_traits<InputIterator>::value_type>, + Allocator>; // C++17 + +template<class charT, class traits, class Allocator> +basic_string<charT, traits, Allocator> +operator+(const basic_string<charT, traits, Allocator>& lhs, + const basic_string<charT, traits, Allocator>& rhs); + +template<class charT, class traits, class Allocator> +basic_string<charT, traits, Allocator> +operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); + +template<class charT, class traits, class Allocator> +basic_string<charT, traits, Allocator> +operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> +basic_string<charT, traits, Allocator> +operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); + +template<class charT, class traits, class Allocator> +basic_string<charT, traits, Allocator> +operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); + +template<class charT, class traits, class Allocator> +bool operator==(const basic_string<charT, traits, Allocator>& lhs, + const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator!=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator< (const basic_string<charT, traits, Allocator>& lhs, + const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator> (const basic_string<charT, traits, Allocator>& lhs, + const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator<=(const basic_string<charT, traits, Allocator>& lhs, + const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator>=(const basic_string<charT, traits, Allocator>& lhs, + const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; + +template<class charT, class traits, class Allocator> +bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; + +template<class charT, class traits, class Allocator> +void swap(basic_string<charT, traits, Allocator>& lhs, + basic_string<charT, traits, Allocator>& rhs) + noexcept(noexcept(lhs.swap(rhs))); + +template<class charT, class traits, class Allocator> +basic_istream<charT, traits>& +operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); + +template<class charT, class traits, class Allocator> +basic_ostream<charT, traits>& +operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); + +template<class charT, class traits, class Allocator> +basic_istream<charT, traits>& +getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, + charT delim); + +template<class charT, class traits, class Allocator> +basic_istream<charT, traits>& +getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); + +template<class charT, class traits, class Allocator, class U> +void erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20 +template<class charT, class traits, class Allocator, class Predicate> +void erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20 + +typedef basic_string<char> string; +typedef basic_string<wchar_t> wstring; +typedef basic_string<char16_t> u16string; +typedef basic_string<char32_t> u32string; + +int stoi (const string& str, size_t* idx = 0, int base = 10); +long stol (const string& str, size_t* idx = 0, int base = 10); +unsigned long stoul (const string& str, size_t* idx = 0, int base = 10); +long long stoll (const string& str, size_t* idx = 0, int base = 10); +unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10); + +float stof (const string& str, size_t* idx = 0); +double stod (const string& str, size_t* idx = 0); +long double stold(const string& str, size_t* idx = 0); + +string to_string(int val); +string to_string(unsigned val); +string to_string(long val); +string to_string(unsigned long val); +string to_string(long long val); +string to_string(unsigned long long val); +string to_string(float val); +string to_string(double val); +string to_string(long double val); + +int stoi (const wstring& str, size_t* idx = 0, int base = 10); +long stol (const wstring& str, size_t* idx = 0, int base = 10); +unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10); +long long stoll (const wstring& str, size_t* idx = 0, int base = 10); +unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10); + +float stof (const wstring& str, size_t* idx = 0); +double stod (const wstring& str, size_t* idx = 0); +long double stold(const wstring& str, size_t* idx = 0); + +wstring to_wstring(int val); +wstring to_wstring(unsigned val); +wstring to_wstring(long val); +wstring to_wstring(unsigned long val); +wstring to_wstring(long long val); +wstring to_wstring(unsigned long long val); +wstring to_wstring(float val); +wstring to_wstring(double val); +wstring to_wstring(long double val); + +template <> struct hash<string>; +template <> struct hash<u16string>; +template <> struct hash<u32string>; +template <> struct hash<wstring>; + +basic_string<char> operator "" s( const char *str, size_t len ); // C++14 +basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14 +basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14 +basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14 + +} // std + +*/ + +#include <__config> +#include <string_view> +#include <iosfwd> +#include <cstring> +#include <cstdio> // For EOF. +#include <cwchar> +#include <algorithm> +#include <iterator> +#include <utility> +#include <memory> +#include <stdexcept> +#include <type_traits> +#include <initializer_list> +#include <__functional_base> +#include <version> +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS +#include <cstdint> +#endif + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +// fpos + +template <class _StateT> +class _LIBCPP_TEMPLATE_VIS fpos +{ +private: + _StateT __st_; + streamoff __off_; +public: + _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {} + + _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;} + + _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;} + _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;} + + _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;} + _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;} + _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;} + _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;} +}; + +template <class _StateT> +inline _LIBCPP_INLINE_VISIBILITY +streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) + {return streamoff(__x) - streamoff(__y);} + +template <class _StateT> +inline _LIBCPP_INLINE_VISIBILITY +bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y) + {return streamoff(__x) == streamoff(__y);} + +template <class _StateT> +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) + {return streamoff(__x) != streamoff(__y);} + +// basic_string + +template<class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, + const basic_string<_CharT, _Traits, _Allocator>& __y); + +template<class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); + +template<class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator> +operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); + +template<class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); + +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&)) + +template <bool> +class _LIBCPP_TEMPLATE_VIS __basic_string_common +{ +protected: + _LIBCPP_NORETURN void __throw_length_error() const; + _LIBCPP_NORETURN void __throw_out_of_range() const; +}; + +template <bool __b> +void +__basic_string_common<__b>::__throw_length_error() const +{ + _VSTD::__throw_length_error("basic_string"); +} + +template <bool __b> +void +__basic_string_common<__b>::__throw_out_of_range() const +{ + _VSTD::__throw_out_of_range("basic_string"); +} + +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>) + +#ifdef _LIBCPP_NO_EXCEPTIONS +template <class _Iter> +struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {}; +#elif defined(_LIBCPP_HAS_NO_NOEXCEPT) +template <class _Iter> +struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {}; +#else +template <class _Iter, bool = __is_forward_iterator<_Iter>::value> +struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT(( + noexcept(++(declval<_Iter&>())) && + is_nothrow_assignable<_Iter&, _Iter>::value && + noexcept(declval<_Iter>() == declval<_Iter>()) && + noexcept(*declval<_Iter>()) +)) {}; + +template <class _Iter> +struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {}; +#endif + + +template <class _Iter> +struct __libcpp_string_gets_noexcept_iterator + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {}; + +template <class _CharT, class _Traits, class _Tp> +struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT( + ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && + !is_convertible<const _Tp&, const _CharT*>::value)) {}; + +#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT + +template <class _CharT, size_t = sizeof(_CharT)> +struct __padding +{ + unsigned char __xx[sizeof(_CharT)-1]; +}; + +template <class _CharT> +struct __padding<_CharT, 1> +{ +}; + +#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT + +template<class _CharT, class _Traits, class _Allocator> +class _LIBCPP_TEMPLATE_VIS basic_string + : private __basic_string_common<true> +{ +public: + typedef basic_string __self; + typedef basic_string_view<_CharT, _Traits> __self_view; + typedef _Traits traits_type; + typedef _CharT value_type; + typedef _Allocator allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + + static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array"); + static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout"); + static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial"); + static_assert(( is_same<_CharT, typename traits_type::char_type>::value), + "traits_type::char_type must be the same type as CharT"); + static_assert(( is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + +#if defined(_LIBCPP_RAW_ITERATORS) + typedef pointer iterator; + typedef const_pointer const_iterator; +#else // defined(_LIBCPP_RAW_ITERATORS) + typedef __wrap_iter<pointer> iterator; + typedef __wrap_iter<const_pointer> const_iterator; +#endif // defined(_LIBCPP_RAW_ITERATORS) + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + +private: + +#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT + + struct __long + { + pointer __data_; + size_type __size_; + size_type __cap_; + }; + +#ifdef _LIBCPP_BIG_ENDIAN + static const size_type __short_mask = 0x01; + static const size_type __long_mask = 0x1ul; +#else // _LIBCPP_BIG_ENDIAN + static const size_type __short_mask = 0x80; + static const size_type __long_mask = ~(size_type(~0) >> 1); +#endif // _LIBCPP_BIG_ENDIAN + + enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? + (sizeof(__long) - 1)/sizeof(value_type) : 2}; + + struct __short + { + value_type __data_[__min_cap]; + struct + : __padding<value_type> + { + unsigned char __size_; + }; + }; + +#else + + struct __long + { + size_type __cap_; + size_type __size_; + pointer __data_; + }; + +#ifdef _LIBCPP_BIG_ENDIAN + static const size_type __short_mask = 0x80; + static const size_type __long_mask = ~(size_type(~0) >> 1); +#else // _LIBCPP_BIG_ENDIAN + static const size_type __short_mask = 0x01; + static const size_type __long_mask = 0x1ul; +#endif // _LIBCPP_BIG_ENDIAN + + enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? + (sizeof(__long) - 1)/sizeof(value_type) : 2}; + + struct __short + { + union + { + unsigned char __size_; + value_type __lx; + }; + value_type __data_[__min_cap]; + }; + +#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT + + union __ulx{__long __lx; __short __lxx;}; + + enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; + + struct __raw + { + size_type __words[__n_words]; + }; + + struct __rep + { + union + { + __long __l; + __short __s; + __raw __r; + }; + }; + + __compressed_pair<__rep, allocator_type> __r_; + +public: + static const size_type npos = -1; + + _LIBCPP_INLINE_VISIBILITY basic_string() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + + _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a) +#if _LIBCPP_STD_VER <= 14 + _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); +#else + _NOEXCEPT; +#endif + + basic_string(const basic_string& __str); + basic_string(const basic_string& __str, const allocator_type& __a); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_string(basic_string&& __str) +#if _LIBCPP_STD_VER <= 14 + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); +#else + _NOEXCEPT; +#endif + + _LIBCPP_INLINE_VISIBILITY + basic_string(basic_string&& __str, const allocator_type& __a); +#endif // _LIBCPP_CXX03_LANG + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES + template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type> +#endif + _LIBCPP_INLINE_VISIBILITY + basic_string(const _CharT* __s) { + _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); + __init(__s, traits_type::length(__s)); +# if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +# endif + } + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES + template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type> +#endif + _LIBCPP_INLINE_VISIBILITY + basic_string(const _CharT* __s, const _Allocator& __a); + + _LIBCPP_INLINE_VISIBILITY + basic_string(const _CharT* __s, size_type __n); + _LIBCPP_INLINE_VISIBILITY + basic_string(const _CharT* __s, size_type __n, const _Allocator& __a); + _LIBCPP_INLINE_VISIBILITY + basic_string(size_type __n, _CharT __c); + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES + template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type> +#endif + _LIBCPP_INLINE_VISIBILITY + basic_string(size_type __n, _CharT __c, const _Allocator& __a); + + basic_string(const basic_string& __str, size_type __pos, size_type __n, + const _Allocator& __a = _Allocator()); + _LIBCPP_INLINE_VISIBILITY + basic_string(const basic_string& __str, size_type __pos, + const _Allocator& __a = _Allocator()); + + template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + basic_string(const _Tp& __t, size_type __pos, size_type __n, + const allocator_type& __a = allocator_type()); + + template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + explicit basic_string(const _Tp& __t); + + template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + explicit basic_string(const _Tp& __t, const allocator_type& __a); + + template<class _InputIterator, class = typename enable_if<__is_input_iterator<_InputIterator>::value>::type> + _LIBCPP_INLINE_VISIBILITY + basic_string(_InputIterator __first, _InputIterator __last); + template<class _InputIterator, class = typename enable_if<__is_input_iterator<_InputIterator>::value>::type> + _LIBCPP_INLINE_VISIBILITY + basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_string(initializer_list<_CharT> __il); + _LIBCPP_INLINE_VISIBILITY + basic_string(initializer_list<_CharT> __il, const _Allocator& __a); +#endif // _LIBCPP_CXX03_LANG + + inline ~basic_string(); + + _LIBCPP_INLINE_VISIBILITY + operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } + + basic_string& operator=(const basic_string& __str); + + template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type> + basic_string& operator=(const _Tp& __t) + {__self_view __sv = __t; return assign(__sv);} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_string& operator=(basic_string&& __str) + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); + _LIBCPP_INLINE_VISIBILITY + basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} +#endif + _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);} + basic_string& operator=(value_type __c); + +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT + {return iterator(this, __get_pointer());} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT + {return const_iterator(this, __get_pointer());} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT + {return iterator(this, __get_pointer() + size());} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT + {return const_iterator(this, __get_pointer() + size());} +#else + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT + {return iterator(__get_pointer());} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT + {return const_iterator(__get_pointer());} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT + {return iterator(__get_pointer() + size());} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT + {return const_iterator(__get_pointer() + size());} +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT + {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT + {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT + {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT + {return rend();} + + _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT + {return __is_long() ? __get_long_size() : __get_short_size();} + _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();} + _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT + {return (__is_long() ? __get_long_cap() + : static_cast<size_type>(__min_cap)) - 1;} + + void resize(size_type __n, value_type __c); + _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());} + + void reserve(size_type __res_arg); + _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n); + + _LIBCPP_INLINE_VISIBILITY + void reserve() _NOEXCEPT {reserve(0);} + _LIBCPP_INLINE_VISIBILITY + void shrink_to_fit() _NOEXCEPT {reserve();} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT; + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return size() == 0;} + + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT; + + const_reference at(size_type __n) const; + reference at(size_type __n); + + _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);} + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);} + _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);} + _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + basic_string& append(const basic_string& __str); + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); } + basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos); + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + append(const _Tp& __t, size_type __pos, size_type __n=npos); + basic_string& append(const value_type* __s, size_type __n); + basic_string& append(const value_type* __s); + basic_string& append(size_type __n, value_type __c); + + _LIBCPP_INLINE_VISIBILITY + void __append_default_init(size_type __n); + + template <class _ForwardIterator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator); + template<class _InputIterator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __is_exactly_input_iterator<_InputIterator>::value + || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, + basic_string& + >::type + _LIBCPP_INLINE_VISIBILITY + append(_InputIterator __first, _InputIterator __last) { + const basic_string __temp (__first, __last, __alloc()); + append(__temp.data(), __temp.size()); + return *this; + } + template<class _ForwardIterator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value + && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, + basic_string& + >::type + _LIBCPP_INLINE_VISIBILITY + append(_ForwardIterator __first, _ForwardIterator __last) { + return __append_forward_unsafe(__first, __last); + } + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());} +#endif // _LIBCPP_CXX03_LANG + + void push_back(value_type __c); + _LIBCPP_INLINE_VISIBILITY + void pop_back(); + _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT; + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); } + _LIBCPP_INLINE_VISIBILITY + basic_string& assign(const basic_string& __str) { return *this = __str; } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_string& assign(basic_string&& __str) + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) + {*this = _VSTD::move(__str); return *this;} +#endif + basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos); + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + assign(const _Tp & __t, size_type __pos, size_type __n=npos); + basic_string& assign(const value_type* __s, size_type __n); + basic_string& assign(const value_type* __s); + basic_string& assign(size_type __n, value_type __c); + template<class _InputIterator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __is_exactly_input_iterator<_InputIterator>::value + || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, + basic_string& + >::type + assign(_InputIterator __first, _InputIterator __last); + template<class _ForwardIterator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value + && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, + basic_string& + >::type + assign(_ForwardIterator __first, _ForwardIterator __last); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + basic_string& insert(size_type __pos1, const basic_string& __str); + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + insert(size_type __pos1, const _Tp& __t) + { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); } + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos); + basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos); + basic_string& insert(size_type __pos, const value_type* __s, size_type __n); + basic_string& insert(size_type __pos, const value_type* __s); + basic_string& insert(size_type __pos, size_type __n, value_type __c); + iterator insert(const_iterator __pos, value_type __c); + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __pos, size_type __n, value_type __c); + template<class _InputIterator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __is_exactly_input_iterator<_InputIterator>::value + || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, + iterator + >::type + insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); + template<class _ForwardIterator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value + && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, + iterator + >::type + insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __pos, initializer_list<value_type> __il) + {return insert(__pos, __il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + + basic_string& erase(size_type __pos = 0, size_type __n = npos); + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __pos); + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __first, const_iterator __last); + + _LIBCPP_INLINE_VISIBILITY + basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str); + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); } + basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos); + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos); + basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2); + basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); + basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); + _LIBCPP_INLINE_VISIBILITY + basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str); + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); } + + _LIBCPP_INLINE_VISIBILITY + basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n); + _LIBCPP_INLINE_VISIBILITY + basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s); + _LIBCPP_INLINE_VISIBILITY + basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c); + template<class _InputIterator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __is_input_iterator<_InputIterator>::value, + basic_string& + >::type + replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) + {return replace(__i1, __i2, __il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + + size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; + _LIBCPP_INLINE_VISIBILITY + basic_string substr(size_type __pos = 0, size_type __n = npos) const; + + _LIBCPP_INLINE_VISIBILITY + void swap(basic_string& __str) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT; +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value); +#endif + + _LIBCPP_INLINE_VISIBILITY + const value_type* c_str() const _NOEXCEPT {return data();} + _LIBCPP_INLINE_VISIBILITY + const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} +#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY) + _LIBCPP_INLINE_VISIBILITY + value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} +#endif + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT {return __alloc();} + + _LIBCPP_INLINE_VISIBILITY + size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + size_type + >::type + find(const _Tp& __t, size_type __pos = 0) const; + size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; + size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + size_type + >::type + rfind(const _Tp& __t, size_type __pos = npos) const; + size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; + size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + size_type + >::type + find_first_of(const _Tp& __t, size_type __pos = 0) const; + size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + size_type + >::type + find_last_of(const _Tp& __t, size_type __pos = npos) const; + size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + size_type + >::type + find_first_not_of(const _Tp &__t, size_type __pos = 0) const; + size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + size_type + >::type + find_last_not_of(const _Tp& __t, size_type __pos = npos) const; + size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + int compare(const basic_string& __str) const _NOEXCEPT; + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + int + >::type + compare(const _Tp &__t) const; + + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + int + >::type + compare(size_type __pos1, size_type __n1, const _Tp& __t) const; + + _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, const basic_string& __str) const; + int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const; + + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + int + >::type + compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const; + int compare(const value_type* __s) const _NOEXCEPT; + int compare(size_type __pos1, size_type __n1, const value_type* __s) const; + int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const; + +#if _LIBCPP_STD_VER > 17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(__self_view __sv) const _NOEXCEPT + { return __self_view(data(), size()).starts_with(__sv); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(front(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(const value_type* __s) const _NOEXCEPT + { return starts_with(__self_view(__s)); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(__self_view __sv) const _NOEXCEPT + { return __self_view(data(), size()).ends_with( __sv); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(back(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(const value_type* __s) const _NOEXCEPT + { return ends_with(__self_view(__s)); } +#endif + + _LIBCPP_INLINE_VISIBILITY bool __invariants() const; + + _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + bool __is_long() const _NOEXCEPT + {return bool(__r_.first().__s.__size_ & __short_mask);} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const; + bool __decrementable(const const_iterator* __i) const; + bool __addable(const const_iterator* __i, ptrdiff_t __n) const; + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +private: + _LIBCPP_INLINE_VISIBILITY + allocator_type& __alloc() _NOEXCEPT + {return __r_.second();} + _LIBCPP_INLINE_VISIBILITY + const allocator_type& __alloc() const _NOEXCEPT + {return __r_.second();} + +#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT + + _LIBCPP_INLINE_VISIBILITY + void __set_short_size(size_type __s) _NOEXCEPT +# ifdef _LIBCPP_BIG_ENDIAN + {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} +# else + {__r_.first().__s.__size_ = (unsigned char)(__s);} +# endif + + _LIBCPP_INLINE_VISIBILITY + size_type __get_short_size() const _NOEXCEPT +# ifdef _LIBCPP_BIG_ENDIAN + {return __r_.first().__s.__size_ >> 1;} +# else + {return __r_.first().__s.__size_;} +# endif + +#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT + + _LIBCPP_INLINE_VISIBILITY + void __set_short_size(size_type __s) _NOEXCEPT +# ifdef _LIBCPP_BIG_ENDIAN + {__r_.first().__s.__size_ = (unsigned char)(__s);} +# else + {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} +# endif + + _LIBCPP_INLINE_VISIBILITY + size_type __get_short_size() const _NOEXCEPT +# ifdef _LIBCPP_BIG_ENDIAN + {return __r_.first().__s.__size_;} +# else + {return __r_.first().__s.__size_ >> 1;} +# endif + +#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT + + _LIBCPP_INLINE_VISIBILITY + void __set_long_size(size_type __s) _NOEXCEPT + {__r_.first().__l.__size_ = __s;} + _LIBCPP_INLINE_VISIBILITY + size_type __get_long_size() const _NOEXCEPT + {return __r_.first().__l.__size_;} + _LIBCPP_INLINE_VISIBILITY + void __set_size(size_type __s) _NOEXCEPT + {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} + + _LIBCPP_INLINE_VISIBILITY + void __set_long_cap(size_type __s) _NOEXCEPT + {__r_.first().__l.__cap_ = __long_mask | __s;} + _LIBCPP_INLINE_VISIBILITY + size_type __get_long_cap() const _NOEXCEPT + {return __r_.first().__l.__cap_ & size_type(~__long_mask);} + + _LIBCPP_INLINE_VISIBILITY + void __set_long_pointer(pointer __p) _NOEXCEPT + {__r_.first().__l.__data_ = __p;} + _LIBCPP_INLINE_VISIBILITY + pointer __get_long_pointer() _NOEXCEPT + {return __r_.first().__l.__data_;} + _LIBCPP_INLINE_VISIBILITY + const_pointer __get_long_pointer() const _NOEXCEPT + {return __r_.first().__l.__data_;} + _LIBCPP_INLINE_VISIBILITY + pointer __get_short_pointer() _NOEXCEPT + {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} + _LIBCPP_INLINE_VISIBILITY + const_pointer __get_short_pointer() const _NOEXCEPT + {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} + _LIBCPP_INLINE_VISIBILITY + pointer __get_pointer() _NOEXCEPT + {return __is_long() ? __get_long_pointer() : __get_short_pointer();} + _LIBCPP_INLINE_VISIBILITY + const_pointer __get_pointer() const _NOEXCEPT + {return __is_long() ? __get_long_pointer() : __get_short_pointer();} + + _LIBCPP_INLINE_VISIBILITY + void __zero() _NOEXCEPT + { + size_type (&__a)[__n_words] = __r_.first().__r.__words; + for (unsigned __i = 0; __i < __n_words; ++__i) + __a[__i] = 0; + } + + template <size_type __a> static + _LIBCPP_INLINE_VISIBILITY + size_type __align_it(size_type __s) _NOEXCEPT + {return (__s + (__a-1)) & ~(__a-1);} + enum {__alignment = 16}; + static _LIBCPP_INLINE_VISIBILITY + size_type __recommend(size_type __s) _NOEXCEPT + { + if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1; + size_type __guess = __align_it<sizeof(value_type) < __alignment ? + __alignment/sizeof(value_type) : 1 > (__s+1) - 1; + if (__guess == __min_cap) ++__guess; + return __guess; + } + + inline + void __init(const value_type* __s, size_type __sz, size_type __reserve); + inline + void __init(const value_type* __s, size_type __sz); + inline + void __init(size_type __n, value_type __c); + + template <class _InputIterator> + inline + typename enable_if + < + __is_exactly_input_iterator<_InputIterator>::value, + void + >::type + __init(_InputIterator __first, _InputIterator __last); + + template <class _ForwardIterator> + inline + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + void + >::type + __init(_ForwardIterator __first, _ForwardIterator __last); + + void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, + size_type __n_copy, size_type __n_del, size_type __n_add = 0); + void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, + size_type __n_copy, size_type __n_del, + size_type __n_add, const value_type* __p_new_stuff); + + _LIBCPP_INLINE_VISIBILITY + void __erase_to_end(size_type __pos); + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const basic_string& __str) + {__copy_assign_alloc(__str, integral_constant<bool, + __alloc_traits::propagate_on_container_copy_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const basic_string& __str, true_type) + { + if (__alloc() == __str.__alloc()) + __alloc() = __str.__alloc(); + else + { + if (!__str.__is_long()) + { + __clear_and_shrink(); + __alloc() = __str.__alloc(); + } + else + { + allocator_type __a = __str.__alloc(); + pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap()); + __clear_and_shrink(); + __alloc() = _VSTD::move(__a); + __set_long_pointer(__p); + __set_long_cap(__str.__get_long_cap()); + __set_long_size(__str.size()); + } + } + } + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT + {} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void __move_assign(basic_string& __str, false_type) + _NOEXCEPT_(__alloc_traits::is_always_equal::value); + _LIBCPP_INLINE_VISIBILITY + void __move_assign(basic_string& __str, true_type) +#if _LIBCPP_STD_VER > 14 + _NOEXCEPT; +#else + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); +#endif +#endif + + _LIBCPP_INLINE_VISIBILITY + void + __move_assign_alloc(basic_string& __str) + _NOEXCEPT_( + !__alloc_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<allocator_type>::value) + {__move_assign_alloc(__str, integral_constant<bool, + __alloc_traits::propagate_on_container_move_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(basic_string& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) + { + __alloc() = _VSTD::move(__c.__alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(basic_string&, false_type) + _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); + _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type); + + friend basic_string operator+<>(const basic_string&, const basic_string&); + friend basic_string operator+<>(const value_type*, const basic_string&); + friend basic_string operator+<>(value_type, const basic_string&); + friend basic_string operator+<>(const basic_string&, const value_type*); + friend basic_string operator+<>(const basic_string&, value_type); +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _CharT = typename iterator_traits<_InputIterator>::value_type, + class _Allocator = allocator<_CharT>, + class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type + > +basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) + -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; + +template<class _CharT, + class _Traits, + class _Allocator = allocator<_CharT>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type + > +explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) + -> basic_string<_CharT, _Traits, _Allocator>; + +template<class _CharT, + class _Traits, + class _Allocator = allocator<_CharT>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type, + class _Sz = typename allocator_traits<_Allocator>::size_type + > +basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator()) + -> basic_string<_CharT, _Traits, _Allocator>; +#endif + + +template <class _CharT, class _Traits, class _Allocator> +inline +void +basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif // _LIBCPP_DEBUG_LEVEL >= 2 +} + +template <class _CharT, class _Traits, class _Allocator> +inline +void +basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type +#if _LIBCPP_DEBUG_LEVEL >= 2 + __pos +#endif + ) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + if (__c) + { + const_pointer __new_last = __get_pointer() + __pos; + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); + if (__i->base() > __new_last) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); + } +#endif // _LIBCPP_DEBUG_LEVEL >= 2 +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __zero(); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a) +#if _LIBCPP_STD_VER <= 14 + _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) +#else + _NOEXCEPT +#endif +: __r_(__second_tag(), __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __zero(); +} + +template <class _CharT, class _Traits, class _Allocator> +void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, + size_type __sz, + size_type __reserve) +{ + if (__reserve > max_size()) + this->__throw_length_error(); + pointer __p; + if (__reserve < __min_cap) + { + __set_short_size(__sz); + __p = __get_short_pointer(); + } + else + { + size_type __cap = __recommend(__reserve); + __p = __alloc_traits::allocate(__alloc(), __cap+1); + __set_long_pointer(__p); + __set_long_cap(__cap+1); + __set_long_size(__sz); + } + traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); + traits_type::assign(__p[__sz], value_type()); +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) +{ + if (__sz > max_size()) + this->__throw_length_error(); + pointer __p; + if (__sz < __min_cap) + { + __set_short_size(__sz); + __p = __get_short_pointer(); + } + else + { + size_type __cap = __recommend(__sz); + __p = __alloc_traits::allocate(__alloc(), __cap+1); + __set_long_pointer(__p); + __set_long_cap(__cap+1); + __set_long_size(__sz); + } + traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); + traits_type::assign(__p[__sz], value_type()); +} + +template <class _CharT, class _Traits, class _Allocator> +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template <class> +#endif +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) + : __r_(__second_tag(), __a) +{ + _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); + __init(__s, traits_type::length(__s)); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n) +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); + __init(__s, __n); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) + : __r_(__second_tag(), __a) +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); + __init(__s, __n); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) + : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) +{ + if (!__str.__is_long()) + __r_.first().__r = __str.__r_.first().__r; + else + __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>::basic_string( + const basic_string& __str, const allocator_type& __a) + : __r_(__second_tag(), __a) +{ + if (!__str.__is_long()) + __r_.first().__r = __str.__r_.first().__r; + else + __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) +#if _LIBCPP_STD_VER <= 14 + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) +#else + _NOEXCEPT +#endif + : __r_(_VSTD::move(__str.__r_)) +{ + __str.__zero(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + if (__is_long()) + __get_db()->swap(this, &__str); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a) + : __r_(__second_tag(), __a) +{ + if (__str.__is_long() && __a != __str.__alloc()) // copy, not move + __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); + else + { + __r_.first().__r = __str.__r_.first().__r; + __str.__zero(); + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + if (__is_long()) + __get_db()->swap(this, &__str); +#endif +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +void +basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) +{ + if (__n > max_size()) + this->__throw_length_error(); + pointer __p; + if (__n < __min_cap) + { + __set_short_size(__n); + __p = __get_short_pointer(); + } + else + { + size_type __cap = __recommend(__n); + __p = __alloc_traits::allocate(__alloc(), __cap+1); + __set_long_pointer(__p); + __set_long_cap(__cap+1); + __set_long_size(__n); + } + traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c); + traits_type::assign(__p[__n], value_type()); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c) +{ + __init(__n, __c); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template <class> +#endif +basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a) + : __r_(__second_tag(), __a) +{ + __init(__n, __c); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, + size_type __pos, size_type __n, + const _Allocator& __a) + : __r_(__second_tag(), __a) +{ + size_type __str_sz = __str.size(); + if (__pos > __str_sz) + this->__throw_out_of_range(); + __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos)); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, + const _Allocator& __a) + : __r_(__second_tag(), __a) +{ + size_type __str_sz = __str.size(); + if (__pos > __str_sz) + this->__throw_out_of_range(); + __init(__str.data() + __pos, __str_sz - __pos); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp, class> +basic_string<_CharT, _Traits, _Allocator>::basic_string( + const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a) + : __r_(__second_tag(), __a) +{ + __self_view __sv0 = __t; + __self_view __sv = __sv0.substr(__pos, __n); + __init(__sv.data(), __sv.size()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp, class> +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) +{ + __self_view __sv = __t; + __init(__sv.data(), __sv.size()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp, class> +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a) + : __r_(__second_tag(), __a) +{ + __self_view __sv = __t; + __init(__sv.data(), __sv.size()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _InputIterator> +typename enable_if +< + __is_exactly_input_iterator<_InputIterator>::value, + void +>::type +basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) +{ + __zero(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __first != __last; ++__first) + push_back(*__first); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + if (__is_long()) + __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value, + void +>::type +basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) +{ + size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last)); + if (__sz > max_size()) + this->__throw_length_error(); + pointer __p; + if (__sz < __min_cap) + { + __set_short_size(__sz); + __p = __get_short_pointer(); + } + else + { + size_type __cap = __recommend(__sz); + __p = __alloc_traits::allocate(__alloc(), __cap+1); + __set_long_pointer(__p); + __set_long_cap(__cap+1); + __set_long_size(__sz); + } + for (; __first != __last; ++__first, (void) ++__p) + traits_type::assign(*__p, *__first); + traits_type::assign(*__p, value_type()); +} + +template <class _CharT, class _Traits, class _Allocator> +template<class _InputIterator, class> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) +{ + __init(__first, __last); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +template<class _InputIterator, class> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, + const allocator_type& __a) + : __r_(__second_tag(), __a) +{ + __init(__first, __last); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>::basic_string( + initializer_list<_CharT> __il) +{ + __init(__il.begin(), __il.end()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +inline + +basic_string<_CharT, _Traits, _Allocator>::basic_string( + initializer_list<_CharT> __il, const _Allocator& __a) + : __r_(__second_tag(), __a) +{ + __init(__il.begin(), __il.end()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>::~basic_string() +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__erase_c(this); +#endif + if (__is_long()) + __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace + (size_type __old_cap, size_type __delta_cap, size_type __old_sz, + size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff) +{ + size_type __ms = max_size(); + if (__delta_cap > __ms - __old_cap - 1) + this->__throw_length_error(); + pointer __old_p = __get_pointer(); + size_type __cap = __old_cap < __ms / 2 - __alignment ? + __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : + __ms - 1; + pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); + __invalidate_all_iterators(); + if (__n_copy != 0) + traits_type::copy(_VSTD::__to_raw_pointer(__p), + _VSTD::__to_raw_pointer(__old_p), __n_copy); + if (__n_add != 0) + traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add); + size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; + if (__sec_cp_sz != 0) + traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, + _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz); + if (__old_cap+1 != __min_cap) + __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); + __set_long_pointer(__p); + __set_long_cap(__cap+1); + __old_sz = __n_copy + __n_add + __sec_cp_sz; + __set_long_size(__old_sz); + traits_type::assign(__p[__old_sz], value_type()); +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, + size_type __n_copy, size_type __n_del, size_type __n_add) +{ + size_type __ms = max_size(); + if (__delta_cap > __ms - __old_cap) + this->__throw_length_error(); + pointer __old_p = __get_pointer(); + size_type __cap = __old_cap < __ms / 2 - __alignment ? + __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : + __ms - 1; + pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); + __invalidate_all_iterators(); + if (__n_copy != 0) + traits_type::copy(_VSTD::__to_raw_pointer(__p), + _VSTD::__to_raw_pointer(__old_p), __n_copy); + size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; + if (__sec_cp_sz != 0) + traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, + _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, + __sec_cp_sz); + if (__old_cap+1 != __min_cap) + __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); + __set_long_pointer(__p); + __set_long_cap(__cap+1); +} + +// assign + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); + size_type __cap = capacity(); + if (__cap >= __n) + { + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); + traits_type::move(__p, __s, __n); + traits_type::assign(__p[__n], value_type()); + __set_size(__n); + __invalidate_iterators_past(__n); + } + else + { + size_type __sz = size(); + __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); + } + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) +{ + size_type __cap = capacity(); + if (__cap < __n) + { + size_type __sz = size(); + __grow_by(__cap, __n - __cap, __sz, 0, __sz); + } + else + __invalidate_iterators_past(__n); + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); + traits_type::assign(__p, __n, __c); + traits_type::assign(__p[__n], value_type()); + __set_size(__n); + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) +{ + pointer __p; + if (__is_long()) + { + __p = __get_long_pointer(); + __set_long_size(1); + } + else + { + __p = __get_short_pointer(); + __set_short_size(1); + } + traits_type::assign(*__p, __c); + traits_type::assign(*++__p, value_type()); + __invalidate_iterators_past(1); + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) +{ + if (this != &__str) + { + __copy_assign_alloc(__str); + assign(__str.data(), __str.size()); + } + return *this; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _CharT, class _Traits, class _Allocator> +inline +void +basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) + _NOEXCEPT_(__alloc_traits::is_always_equal::value) +{ + if (__alloc() != __str.__alloc()) + assign(__str); + else + __move_assign(__str, true_type()); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +void +basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) +#if _LIBCPP_STD_VER > 14 + _NOEXCEPT +#else + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) +#endif +{ + __clear_and_shrink(); + __r_.first() = __str.__r_.first(); + __move_assign_alloc(__str); + __str.__zero(); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) +{ + __move_assign(__str, integral_constant<bool, + __alloc_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +#endif + +template <class _CharT, class _Traits, class _Allocator> +template<class _InputIterator> +typename enable_if +< + __is_exactly_input_iterator <_InputIterator>::value + || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, + basic_string<_CharT, _Traits, _Allocator>& +>::type +basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) +{ + const basic_string __temp(__first, __last, __alloc()); + assign(__temp.data(), __temp.size()); + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +template<class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value + && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, + basic_string<_CharT, _Traits, _Allocator>& +>::type +basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) +{ + size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); + size_type __cap = capacity(); + if (__cap < __n) + { + size_type __sz = size(); + __grow_by(__cap, __n - __cap, __sz, 0, __sz); + } + else + __invalidate_iterators_past(__n); + pointer __p = __get_pointer(); + for (; __first != __last; ++__first, ++__p) + traits_type::assign(*__p, *__first); + traits_type::assign(*__p, value_type()); + __set_size(__n); + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) +{ + size_type __sz = __str.size(); + if (__pos > __sz) + this->__throw_out_of_range(); + return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string<_CharT, _Traits, _Allocator>& +>::type +basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n) +{ + __self_view __sv = __t; + size_type __sz = __sv.size(); + if (__pos > __sz) + this->__throw_out_of_range(); + return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos)); +} + + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) +{ + _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); + return assign(__s, traits_type::length(__s)); +} + +// append + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr"); + size_type __cap = capacity(); + size_type __sz = size(); + if (__cap - __sz >= __n) + { + if (__n) + { + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); + traits_type::copy(__p + __sz, __s, __n); + __sz += __n; + __set_size(__sz); + traits_type::assign(__p[__sz], value_type()); + } + } + else + __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) +{ + if (__n) + { + size_type __cap = capacity(); + size_type __sz = size(); + if (__cap - __sz < __n) + __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); + pointer __p = __get_pointer(); + traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c); + __sz += __n; + __set_size(__sz); + traits_type::assign(__p[__sz], value_type()); + } + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +inline void +basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) +{ + if (__n) + { + size_type __cap = capacity(); + size_type __sz = size(); + if (__cap - __sz < __n) + __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); + pointer __p = __get_pointer(); + __sz += __n; + __set_size(__sz); + traits_type::assign(__p[__sz], value_type()); + } +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) +{ + bool __is_short = !__is_long(); + size_type __cap; + size_type __sz; + if (__is_short) + { + __cap = __min_cap - 1; + __sz = __get_short_size(); + } + else + { + __cap = __get_long_cap() - 1; + __sz = __get_long_size(); + } + if (__sz == __cap) + { + __grow_by(__cap, 1, __sz, __sz, 0); + __is_short = !__is_long(); + } + pointer __p; + if (__is_short) + { + __p = __get_short_pointer() + __sz; + __set_short_size(__sz+1); + } + else + { + __p = __get_long_pointer() + __sz; + __set_long_size(__sz+1); + } + traits_type::assign(*__p, __c); + traits_type::assign(*++__p, value_type()); +} + +template <class _Tp> +bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last) +{ + return __first <= __p && __p < __last; +} + +template <class _Tp1, class _Tp2> +bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*) +{ + return false; +} + +template <class _CharT, class _Traits, class _Allocator> +template<class _ForwardIterator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe( + _ForwardIterator __first, _ForwardIterator __last) +{ + static_assert(__is_forward_iterator<_ForwardIterator>::value, + "function requires a ForwardIterator"); + size_type __sz = size(); + size_type __cap = capacity(); + size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); + if (__n) + { + typedef typename iterator_traits<_ForwardIterator>::reference _CharRef; + _CharRef __tmp_ref = *__first; + if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size())) + { + const basic_string __temp (__first, __last, __alloc()); + append(__temp.data(), __temp.size()); + } + else + { + if (__cap - __sz < __n) + __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); + pointer __p = __get_pointer() + __sz; + for (; __first != __last; ++__p, ++__first) + traits_type::assign(*__p, *__first); + traits_type::assign(*__p, value_type()); + __set_size(__sz + __n); + } + } + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str) +{ + return append(__str.data(), __str.size()); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) +{ + size_type __sz = __str.size(); + if (__pos > __sz) + this->__throw_out_of_range(); + return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string<_CharT, _Traits, _Allocator>& + >::type +basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n) +{ + __self_view __sv = __t; + size_type __sz = __sv.size(); + if (__pos > __sz) + this->__throw_out_of_range(); + return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos)); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) +{ + _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr"); + return append(__s, traits_type::length(__s)); +} + +// insert + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n) +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr"); + size_type __sz = size(); + if (__pos > __sz) + this->__throw_out_of_range(); + size_type __cap = capacity(); + if (__cap - __sz >= __n) + { + if (__n) + { + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); + size_type __n_move = __sz - __pos; + if (__n_move != 0) + { + if (__p + __pos <= __s && __s < __p + __sz) + __s += __n; + traits_type::move(__p + __pos + __n, __p + __pos, __n_move); + } + traits_type::move(__p + __pos, __s, __n); + __sz += __n; + __set_size(__sz); + traits_type::assign(__p[__sz], value_type()); + } + } + else + __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) +{ + size_type __sz = size(); + if (__pos > __sz) + this->__throw_out_of_range(); + if (__n) + { + size_type __cap = capacity(); + value_type* __p; + if (__cap - __sz >= __n) + { + __p = _VSTD::__to_raw_pointer(__get_pointer()); + size_type __n_move = __sz - __pos; + if (__n_move != 0) + traits_type::move(__p + __pos + __n, __p + __pos, __n_move); + } + else + { + __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); + __p = _VSTD::__to_raw_pointer(__get_long_pointer()); + } + traits_type::assign(__p + __pos, __n, __c); + __sz += __n; + __set_size(__sz); + traits_type::assign(__p[__sz], value_type()); + } + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +template<class _InputIterator> +typename enable_if +< + __is_exactly_input_iterator<_InputIterator>::value + || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, + typename basic_string<_CharT, _Traits, _Allocator>::iterator +>::type +basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, + "string::insert(iterator, range) called with an iterator not" + " referring to this string"); +#endif + const basic_string __temp(__first, __last, __alloc()); + return insert(__pos, __temp.data(), __temp.data() + __temp.size()); +} + +template <class _CharT, class _Traits, class _Allocator> +template<class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value + && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, + typename basic_string<_CharT, _Traits, _Allocator>::iterator +>::type +basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, + "string::insert(iterator, range) called with an iterator not" + " referring to this string"); +#endif + size_type __ip = static_cast<size_type>(__pos - begin()); + size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); + if (__n) + { + typedef typename iterator_traits<_ForwardIterator>::reference _CharRef; + _CharRef __tmp_char = *__first; + if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size())) + { + const basic_string __temp(__first, __last, __alloc()); + return insert(__pos, __temp.data(), __temp.data() + __temp.size()); + } + + size_type __sz = size(); + size_type __cap = capacity(); + value_type* __p; + if (__cap - __sz >= __n) + { + __p = _VSTD::__to_raw_pointer(__get_pointer()); + size_type __n_move = __sz - __ip; + if (__n_move != 0) + traits_type::move(__p + __ip + __n, __p + __ip, __n_move); + } + else + { + __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); + __p = _VSTD::__to_raw_pointer(__get_long_pointer()); + } + __sz += __n; + __set_size(__sz); + traits_type::assign(__p[__sz], value_type()); + for (__p += __ip; __first != __last; ++__p, ++__first) + traits_type::assign(*__p, *__first); + } + return begin() + __ip; +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str) +{ + return insert(__pos1, __str.data(), __str.size()); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, + size_type __pos2, size_type __n) +{ + size_type __str_sz = __str.size(); + if (__pos2 > __str_sz) + this->__throw_out_of_range(); + return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2)); +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string<_CharT, _Traits, _Allocator>& +>::type +basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, + size_type __pos2, size_type __n) +{ + __self_view __sv = __t; + size_type __str_sz = __sv.size(); + if (__pos2 > __str_sz) + this->__throw_out_of_range(); + return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2)); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) +{ + _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr"); + return insert(__pos, __s, traits_type::length(__s)); +} + +template <class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::iterator +basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) +{ + size_type __ip = static_cast<size_type>(__pos - begin()); + size_type __sz = size(); + size_type __cap = capacity(); + value_type* __p; + if (__cap == __sz) + { + __grow_by(__cap, 1, __sz, __ip, 0, 1); + __p = _VSTD::__to_raw_pointer(__get_long_pointer()); + } + else + { + __p = _VSTD::__to_raw_pointer(__get_pointer()); + size_type __n_move = __sz - __ip; + if (__n_move != 0) + traits_type::move(__p + __ip + 1, __p + __ip, __n_move); + } + traits_type::assign(__p[__ip], __c); + traits_type::assign(__p[++__sz], value_type()); + __set_size(__sz); + return begin() + static_cast<difference_type>(__ip); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::iterator +basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, + "string::insert(iterator, n, value) called with an iterator not" + " referring to this string"); +#endif + difference_type __p = __pos - begin(); + insert(static_cast<size_type>(__p), __n, __c); + return begin() + __p; +} + +// replace + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ + _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); + size_type __sz = size(); + if (__pos > __sz) + this->__throw_out_of_range(); + __n1 = _VSTD::min(__n1, __sz - __pos); + size_type __cap = capacity(); + if (__cap - __sz + __n1 >= __n2) + { + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); + if (__n1 != __n2) + { + size_type __n_move = __sz - __pos - __n1; + if (__n_move != 0) + { + if (__n1 > __n2) + { + traits_type::move(__p + __pos, __s, __n2); + traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); + goto __finish; + } + if (__p + __pos < __s && __s < __p + __sz) + { + if (__p + __pos + __n1 <= __s) + __s += __n2 - __n1; + else // __p + __pos < __s < __p + __pos + __n1 + { + traits_type::move(__p + __pos, __s, __n1); + __pos += __n1; + __s += __n2; + __n2 -= __n1; + __n1 = 0; + } + } + traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); + } + } + traits_type::move(__p + __pos, __s, __n2); +__finish: +// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow, +// but this is a safe operation, so we disable the check. + __sz += __n2 - __n1; + __set_size(__sz); + __invalidate_iterators_past(__sz); + traits_type::assign(__p[__sz], value_type()); + } + else + __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ + size_type __sz = size(); + if (__pos > __sz) + this->__throw_out_of_range(); + __n1 = _VSTD::min(__n1, __sz - __pos); + size_type __cap = capacity(); + value_type* __p; + if (__cap - __sz + __n1 >= __n2) + { + __p = _VSTD::__to_raw_pointer(__get_pointer()); + if (__n1 != __n2) + { + size_type __n_move = __sz - __pos - __n1; + if (__n_move != 0) + traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); + } + } + else + { + __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); + __p = _VSTD::__to_raw_pointer(__get_long_pointer()); + } + traits_type::assign(__p + __pos, __n2, __c); + __sz += __n2 - __n1; + __set_size(__sz); + __invalidate_iterators_past(__sz); + traits_type::assign(__p[__sz], value_type()); + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +template<class _InputIterator> +typename enable_if +< + __is_input_iterator<_InputIterator>::value, + basic_string<_CharT, _Traits, _Allocator>& +>::type +basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, + _InputIterator __j1, _InputIterator __j2) +{ + const basic_string __temp(__j1, __j2, __alloc()); + return this->replace(__i1, __i2, __temp); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str) +{ + return replace(__pos1, __n1, __str.data(), __str.size()); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, + size_type __pos2, size_type __n2) +{ + size_type __str_sz = __str.size(); + if (__pos2 > __str_sz) + this->__throw_out_of_range(); + return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2)); +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string<_CharT, _Traits, _Allocator>& +>::type +basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t, + size_type __pos2, size_type __n2) +{ + __self_view __sv = __t; + size_type __str_sz = __sv.size(); + if (__pos2 > __str_sz) + this->__throw_out_of_range(); + return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2)); +} + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s) +{ + _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr"); + return replace(__pos, __n1, __s, traits_type::length(__s)); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str) +{ + return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), + __str.data(), __str.size()); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n) +{ + return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s) +{ + return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c) +{ + return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); +} + +// erase + +template <class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n) +{ + size_type __sz = size(); + if (__pos > __sz) + this->__throw_out_of_range(); + if (__n) + { + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); + __n = _VSTD::min(__n, __sz - __pos); + size_type __n_move = __sz - __pos - __n; + if (__n_move != 0) + traits_type::move(__p + __pos, __p + __pos + __n, __n_move); + __sz -= __n; + __set_size(__sz); + __invalidate_iterators_past(__sz); + traits_type::assign(__p[__sz], value_type()); + } + return *this; +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::iterator +basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, + "string::erase(iterator) called with an iterator not" + " referring to this string"); +#endif + _LIBCPP_ASSERT(__pos != end(), + "string::erase(iterator) called with a non-dereferenceable iterator"); + iterator __b = begin(); + size_type __r = static_cast<size_type>(__pos - __b); + erase(__r, 1); + return __b + static_cast<difference_type>(__r); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::iterator +basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, + "string::erase(iterator, iterator) called with an iterator not" + " referring to this string"); +#endif + _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); + iterator __b = begin(); + size_type __r = static_cast<size_type>(__first - __b); + erase(__r, static_cast<size_type>(__last - __first)); + return __b + static_cast<difference_type>(__r); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +void +basic_string<_CharT, _Traits, _Allocator>::pop_back() +{ + _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); + size_type __sz; + if (__is_long()) + { + __sz = __get_long_size() - 1; + __set_long_size(__sz); + traits_type::assign(*(__get_long_pointer() + __sz), value_type()); + } + else + { + __sz = __get_short_size() - 1; + __set_short_size(__sz); + traits_type::assign(*(__get_short_pointer() + __sz), value_type()); + } + __invalidate_iterators_past(__sz); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +void +basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT +{ + __invalidate_all_iterators(); + if (__is_long()) + { + traits_type::assign(*__get_long_pointer(), value_type()); + __set_long_size(0); + } + else + { + traits_type::assign(*__get_short_pointer(), value_type()); + __set_short_size(0); + } +} + +template <class _CharT, class _Traits, class _Allocator> +inline +void +basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) +{ + if (__is_long()) + { + traits_type::assign(*(__get_long_pointer() + __pos), value_type()); + __set_long_size(__pos); + } + else + { + traits_type::assign(*(__get_short_pointer() + __pos), value_type()); + __set_short_size(__pos); + } + __invalidate_iterators_past(__pos); +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) +{ + size_type __sz = size(); + if (__n > __sz) + append(__n - __sz, __c); + else + __erase_to_end(__n); +} + +template <class _CharT, class _Traits, class _Allocator> +inline void +basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n) +{ + size_type __sz = size(); + if (__n > __sz) { + __append_default_init(__n - __sz); + } else + __erase_to_end(__n); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT +{ + size_type __m = __alloc_traits::max_size(__alloc()); +#ifdef _LIBCPP_BIG_ENDIAN + return (__m <= ~__long_mask ? __m : __m/2) - __alignment; +#else + return __m - __alignment; +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg) +{ + if (__res_arg > max_size()) + this->__throw_length_error(); + size_type __cap = capacity(); + size_type __sz = size(); + __res_arg = _VSTD::max(__res_arg, __sz); + __res_arg = __recommend(__res_arg); + if (__res_arg != __cap) + { + pointer __new_data, __p; + bool __was_long, __now_long; + if (__res_arg == __min_cap - 1) + { + __was_long = true; + __now_long = false; + __new_data = __get_short_pointer(); + __p = __get_long_pointer(); + } + else + { + if (__res_arg > __cap) + __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); + else + { + #ifndef _LIBCPP_NO_EXCEPTIONS + try + { + #endif // _LIBCPP_NO_EXCEPTIONS + __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); + #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + return; + } + #else // _LIBCPP_NO_EXCEPTIONS + if (__new_data == nullptr) + return; + #endif // _LIBCPP_NO_EXCEPTIONS + } + __now_long = true; + __was_long = __is_long(); + __p = __get_pointer(); + } + traits_type::copy(_VSTD::__to_raw_pointer(__new_data), + _VSTD::__to_raw_pointer(__p), size()+1); + if (__was_long) + __alloc_traits::deallocate(__alloc(), __p, __cap+1); + if (__now_long) + { + __set_long_cap(__res_arg+1); + __set_long_size(__sz); + __set_long_pointer(__new_data); + } + else + __set_short_size(__sz); + __invalidate_all_iterators(); + } +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::const_reference +basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); + return *(data() + __pos); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::reference +basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT +{ + _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); + return *(__get_pointer() + __pos); +} + +template <class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::const_reference +basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const +{ + if (__n >= size()) + this->__throw_out_of_range(); + return (*this)[__n]; +} + +template <class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::reference +basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) +{ + if (__n >= size()) + this->__throw_out_of_range(); + return (*this)[__n]; +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::reference +basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT +{ + _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); + return *__get_pointer(); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::const_reference +basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT +{ + _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); + return *data(); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::reference +basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT +{ + _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); + return *(__get_pointer() + size() - 1); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::const_reference +basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT +{ + _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); + return *(data() + size() - 1); +} + +template <class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const +{ + size_type __sz = size(); + if (__pos > __sz) + this->__throw_out_of_range(); + size_type __rlen = _VSTD::min(__n, __sz - __pos); + traits_type::copy(__s, data() + __pos, __rlen); + return __rlen; +} + +template <class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator> +basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const +{ + return basic_string(*this, __pos, __n, __alloc()); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +void +basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value) +#endif +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + if (!__is_long()) + __get_db()->__invalidate_all(this); + if (!__str.__is_long()) + __get_db()->__invalidate_all(&__str); + __get_db()->swap(this, &__str); +#endif + _LIBCPP_ASSERT( + __alloc_traits::propagate_on_container_swap::value || + __alloc_traits::is_always_equal::value || + __alloc() == __str.__alloc(), "swapping non-equal allocators"); + _VSTD::swap(__r_.first(), __str.__r_.first()); + __swap_allocator(__alloc(), __str.__alloc()); +} + +// find + +template <class _Traits> +struct _LIBCPP_HIDDEN __traits_eq +{ + typedef typename _Traits::char_type char_type; + _LIBCPP_INLINE_VISIBILITY + bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT + {return _Traits::eq(__x, __y);} +}; + +template<class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, + size_type __pos, + size_type __n) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, + size_type __pos) const _NOEXCEPT +{ + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __str.data(), __pos, __str.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + typename basic_string<_CharT, _Traits, _Allocator>::size_type +>::type +basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t, + size_type __pos) const +{ + __self_view __sv = __t; + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, + size_type __pos) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); +} + +template<class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, + size_type __pos) const _NOEXCEPT +{ + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); +} + +// rfind + +template<class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, + size_type __pos, + size_type __n) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, + size_type __pos) const _NOEXCEPT +{ + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __str.data(), __pos, __str.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + typename basic_string<_CharT, _Traits, _Allocator>::size_type +>::type +basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t, + size_type __pos) const +{ + __self_view __sv = __t; + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, + size_type __pos) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); +} + +template<class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, + size_type __pos) const _NOEXCEPT +{ + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); +} + +// find_first_of + +template<class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, + size_type __pos, + size_type __n) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, + size_type __pos) const _NOEXCEPT +{ + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __str.data(), __pos, __str.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + typename basic_string<_CharT, _Traits, _Allocator>::size_type +>::type +basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t, + size_type __pos) const +{ + __self_view __sv = __t; + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, + size_type __pos) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, + size_type __pos) const _NOEXCEPT +{ + return find(__c, __pos); +} + +// find_last_of + +template<class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, + size_type __pos, + size_type __n) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, + size_type __pos) const _NOEXCEPT +{ + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __str.data(), __pos, __str.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + typename basic_string<_CharT, _Traits, _Allocator>::size_type +>::type +basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t, + size_type __pos) const +{ + __self_view __sv = __t; + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, + size_type __pos) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, + size_type __pos) const _NOEXCEPT +{ + return rfind(__c, __pos); +} + +// find_first_not_of + +template<class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, + size_type __pos, + size_type __n) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, + size_type __pos) const _NOEXCEPT +{ + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __str.data(), __pos, __str.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + typename basic_string<_CharT, _Traits, _Allocator>::size_type +>::type +basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t, + size_type __pos) const +{ + __self_view __sv = __t; + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, + size_type __pos) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, + size_type __pos) const _NOEXCEPT +{ + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); +} + +// find_last_not_of + +template<class _CharT, class _Traits, class _Allocator> +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, + size_type __pos, + size_type __n) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, + size_type __pos) const _NOEXCEPT +{ + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __str.data(), __pos, __str.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + typename basic_string<_CharT, _Traits, _Allocator>::size_type +>::type +basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t, + size_type __pos) const +{ + __self_view __sv = __t; + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, + size_type __pos) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); +} + +template<class _CharT, class _Traits, class _Allocator> +inline +typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, + size_type __pos) const _NOEXCEPT +{ + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); +} + +// compare + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + int +>::type +basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const +{ + __self_view __sv = __t; + size_t __lhs_sz = size(); + size_t __rhs_sz = __sv.size(); + int __result = traits_type::compare(data(), __sv.data(), + _VSTD::min(__lhs_sz, __rhs_sz)); + if (__result != 0) + return __result; + if (__lhs_sz < __rhs_sz) + return -1; + if (__lhs_sz > __rhs_sz) + return 1; + return 0; +} + +template <class _CharT, class _Traits, class _Allocator> +inline +int +basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT +{ + return compare(__self_view(__str)); +} + +template <class _CharT, class _Traits, class _Allocator> +int +basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, + size_type __n1, + const value_type* __s, + size_type __n2) const +{ + _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); + size_type __sz = size(); + if (__pos1 > __sz || __n2 == npos) + this->__throw_out_of_range(); + size_type __rlen = _VSTD::min(__n1, __sz - __pos1); + int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2)); + if (__r == 0) + { + if (__rlen < __n2) + __r = -1; + else if (__rlen > __n2) + __r = 1; + } + return __r; +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + int +>::type +basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, + size_type __n1, + const _Tp& __t) const +{ + __self_view __sv = __t; + return compare(__pos1, __n1, __sv.data(), __sv.size()); +} + +template <class _CharT, class _Traits, class _Allocator> +inline +int +basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, + size_type __n1, + const basic_string& __str) const +{ + return compare(__pos1, __n1, __str.data(), __str.size()); +} + +template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + int +>::type +basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, + size_type __n1, + const _Tp& __t, + size_type __pos2, + size_type __n2) const +{ + __self_view __sv = __t; + return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); +} + +template <class _CharT, class _Traits, class _Allocator> +int +basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, + size_type __n1, + const basic_string& __str, + size_type __pos2, + size_type __n2) const +{ + return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); +} + +template <class _CharT, class _Traits, class _Allocator> +int +basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); + return compare(0, npos, __s, traits_type::length(__s)); +} + +template <class _CharT, class _Traits, class _Allocator> +int +basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, + size_type __n1, + const value_type* __s) const +{ + _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); + return compare(__pos1, __n1, __s, traits_type::length(__s)); +} + +// __invariants + +template<class _CharT, class _Traits, class _Allocator> +inline +bool +basic_string<_CharT, _Traits, _Allocator>::__invariants() const +{ + if (size() > capacity()) + return false; + if (capacity() < __min_cap - 1) + return false; + if (data() == 0) + return false; + if (data()[size()] != value_type(0)) + return false; + return true; +} + +// __clear_and_shrink + +template<class _CharT, class _Traits, class _Allocator> +inline +void +basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT +{ + clear(); + if(__is_long()) + { + __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); + __set_long_cap(0); + __set_short_size(0); + } +} + +// operator== + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + size_t __lhs_sz = __lhs.size(); + return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), + __rhs.data(), + __lhs_sz) == 0; +} + +template<class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, + const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT +{ + size_t __lhs_sz = __lhs.size(); + if (__lhs_sz != __rhs.size()) + return false; + const char* __lp = __lhs.data(); + const char* __rp = __rhs.data(); + if (__lhs.__is_long()) + return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; + for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) + if (*__lp != *__rp) + return false; + return true; +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const _CharT* __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + typedef basic_string<_CharT, _Traits, _Allocator> _String; + _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); + size_t __lhs_len = _Traits::length(__lhs); + if (__lhs_len != __rhs.size()) return false; + return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, + const _CharT* __rhs) _NOEXCEPT +{ + typedef basic_string<_CharT, _Traits, _Allocator> _String; + _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); + size_t __rhs_len = _Traits::length(__rhs); + if (__rhs_len != __lhs.size()) return false; + return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return !(__lhs == __rhs); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const _CharT* __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return !(__lhs == __rhs); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const _CharT* __rhs) _NOEXCEPT +{ + return !(__lhs == __rhs); +} + +// operator< + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) < 0; +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const _CharT* __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) < 0; +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const _CharT* __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return __rhs.compare(__lhs) > 0; +} + +// operator> + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return __rhs < __lhs; +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const _CharT* __rhs) _NOEXCEPT +{ + return __rhs < __lhs; +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const _CharT* __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return __rhs < __lhs; +} + +// operator<= + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return !(__rhs < __lhs); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const _CharT* __rhs) _NOEXCEPT +{ + return !(__rhs < __lhs); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const _CharT* __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return !(__rhs < __lhs); +} + +// operator>= + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return !(__lhs < __rhs); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const _CharT* __rhs) _NOEXCEPT +{ + return !(__lhs < __rhs); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const _CharT* __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return !(__lhs < __rhs); +} + +// operator + + +template<class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) +{ + basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); + typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); + typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); + __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz); + __r.append(__rhs.data(), __rhs_sz); + return __r; +} + +template<class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) +{ + basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator()); + typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs); + typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); + __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz); + __r.append(__rhs.data(), __rhs_sz); + return __r; +} + +template<class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) +{ + basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator()); + typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); + __r.__init(&__lhs, 1, 1 + __rhs_sz); + __r.append(__rhs.data(), __rhs_sz); + return __r; +} + +template<class _CharT, class _Traits, class _Allocator> +inline +basic_string<_CharT, _Traits, _Allocator> +operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) +{ + basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); + typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); + typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs); + __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz); + __r.append(__rhs, __rhs_sz); + return __r; +} + +template<class _CharT, class _Traits, class _Allocator> +basic_string<_CharT, _Traits, _Allocator> +operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) +{ + basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); + typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); + __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1); + __r.push_back(__rhs); + return __r; +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator> +operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) +{ + return _VSTD::move(__lhs.append(__rhs)); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator> +operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) +{ + return _VSTD::move(__rhs.insert(0, __lhs)); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator> +operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) +{ + return _VSTD::move(__lhs.append(__rhs)); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator> +operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) +{ + return _VSTD::move(__rhs.insert(0, __lhs)); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator> +operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) +{ + __rhs.insert(__rhs.begin(), __lhs); + return _VSTD::move(__rhs); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator> +operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) +{ + return _VSTD::move(__lhs.append(__rhs)); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator> +operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) +{ + __lhs.push_back(__rhs); + return _VSTD::move(__lhs); +} + +#endif // _LIBCPP_CXX03_LANG + +// swap + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, + basic_string<_CharT, _Traits, _Allocator>& __rhs) + _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) +{ + __lhs.swap(__rhs); +} + +#ifndef _LIBCPP_NO_HAS_CHAR8_T +typedef basic_string<char8_t> u8string; +#endif + +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS +typedef basic_string<char16_t> u16string; +typedef basic_string<char32_t> u32string; +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10); + +_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0); +_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0); +_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0); + +_LIBCPP_FUNC_VIS string to_string(int __val); +_LIBCPP_FUNC_VIS string to_string(unsigned __val); +_LIBCPP_FUNC_VIS string to_string(long __val); +_LIBCPP_FUNC_VIS string to_string(unsigned long __val); +_LIBCPP_FUNC_VIS string to_string(long long __val); +_LIBCPP_FUNC_VIS string to_string(unsigned long long __val); +_LIBCPP_FUNC_VIS string to_string(float __val); +_LIBCPP_FUNC_VIS string to_string(double __val); +_LIBCPP_FUNC_VIS string to_string(long double __val); + +_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10); + +_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0); +_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0); +_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0); + +_LIBCPP_FUNC_VIS wstring to_wstring(int __val); +_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); +_LIBCPP_FUNC_VIS wstring to_wstring(long __val); +_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val); +_LIBCPP_FUNC_VIS wstring to_wstring(long long __val); +_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val); +_LIBCPP_FUNC_VIS wstring to_wstring(float __val); +_LIBCPP_FUNC_VIS wstring to_wstring(double __val); +_LIBCPP_FUNC_VIS wstring to_wstring(long double __val); + +template<class _CharT, class _Traits, class _Allocator> + const typename basic_string<_CharT, _Traits, _Allocator>::size_type + basic_string<_CharT, _Traits, _Allocator>::npos; + +template<class _CharT, class _Traits, class _Allocator> +struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> > + : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t> +{ + size_t + operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT; +}; + +template<class _CharT, class _Traits, class _Allocator> +size_t +hash<basic_string<_CharT, _Traits, _Allocator> >::operator()( + const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT +{ + return __do_string_hash(__val.data(), __val.data() + __val.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const basic_string<_CharT, _Traits, _Allocator>& __str); + +template<class _CharT, class _Traits, class _Allocator> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + basic_string<_CharT, _Traits, _Allocator>& __str); + +template<class _CharT, class _Traits, class _Allocator> +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>& __is, + basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>& __is, + basic_string<_CharT, _Traits, _Allocator>& __str); + +#ifndef _LIBCPP_CXX03_LANG + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>&& __is, + basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>&& __is, + basic_string<_CharT, _Traits, _Allocator>& __str); + +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 17 +template<class _CharT, class _Traits, class _Allocator, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +void erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) +{ __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end()); } + +template<class _CharT, class _Traits, class _Allocator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred) +{ __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred), __str.end()); } +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 2 + +template<class _CharT, class _Traits, class _Allocator> +bool +basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const +{ + return this->data() <= _VSTD::__to_raw_pointer(__i->base()) && + _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size(); +} + +template<class _CharT, class _Traits, class _Allocator> +bool +basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const +{ + return this->data() < _VSTD::__to_raw_pointer(__i->base()) && + _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size(); +} + +template<class _CharT, class _Traits, class _Allocator> +bool +basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const +{ + const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n; + return this->data() <= __p && __p <= this->data() + this->size(); +} + +template<class _CharT, class _Traits, class _Allocator> +bool +basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const +{ + const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n; + return this->data() <= __p && __p < this->data() + this->size(); +} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>) + +#if _LIBCPP_STD_VER > 11 +// Literal suffixes for basic_string [basic.string.literals] +inline namespace literals +{ + inline namespace string_literals + { + inline _LIBCPP_INLINE_VISIBILITY + basic_string<char> operator "" s( const char *__str, size_t __len ) + { + return basic_string<char> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY + basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len ) + { + return basic_string<wchar_t> (__str, __len); + } + +#ifndef _LIBCPP_NO_HAS_CHAR8_T + inline _LIBCPP_INLINE_VISIBILITY + basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT + { + return basic_string<char8_t> (__str, __len); + } +#endif + + inline _LIBCPP_INLINE_VISIBILITY + basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len ) + { + return basic_string<char16_t> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY + basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) + { + return basic_string<char32_t> (__str, __len); + } + } +} +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_STRING diff --git a/android/x86/include/v8/libc++/string.h b/android/x86/include/v8/libc++/string.h new file mode 100755 index 00000000..e09251d0 --- /dev/null +++ b/android/x86/include/v8/libc++/string.h @@ -0,0 +1,109 @@ +// -*- C++ -*- +//===--------------------------- string.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STRING_H +#define _LIBCPP_STRING_H + +/* + string.h synopsis + +Macros: + + NULL + +Types: + + size_t + +void* memcpy(void* restrict s1, const void* restrict s2, size_t n); +void* memmove(void* s1, const void* s2, size_t n); +char* strcpy (char* restrict s1, const char* restrict s2); +char* strncpy(char* restrict s1, const char* restrict s2, size_t n); +char* strcat (char* restrict s1, const char* restrict s2); +char* strncat(char* restrict s1, const char* restrict s2, size_t n); +int memcmp(const void* s1, const void* s2, size_t n); +int strcmp (const char* s1, const char* s2); +int strncmp(const char* s1, const char* s2, size_t n); +int strcoll(const char* s1, const char* s2); +size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n); +const void* memchr(const void* s, int c, size_t n); + void* memchr( void* s, int c, size_t n); +const char* strchr(const char* s, int c); + char* strchr( char* s, int c); +size_t strcspn(const char* s1, const char* s2); +const char* strpbrk(const char* s1, const char* s2); + char* strpbrk( char* s1, const char* s2); +const char* strrchr(const char* s, int c); + char* strrchr( char* s, int c); +size_t strspn(const char* s1, const char* s2); +const char* strstr(const char* s1, const char* s2); + char* strstr( char* s1, const char* s2); +char* strtok(char* restrict s1, const char* restrict s2); +void* memset(void* s, int c, size_t n); +char* strerror(int errnum); +size_t strlen(const char* s); + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <string.h> + +// MSVCRT, GNU libc and its derivates may already have the correct prototype in +// <string.h>. This macro can be defined by users if their C library provides +// the right signature. +#if defined(__CORRECT_ISO_CPP_STRING_H_PROTO) || defined(_LIBCPP_MSVCRT) || \ + defined(__sun__) || defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_) +#define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS +#endif + +#if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD) +extern "C++" { +inline _LIBCPP_INLINE_VISIBILITY +char* __libcpp_strchr(const char* __s, int __c) {return (char*)strchr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const char* strchr(const char* __s, int __c) {return __libcpp_strchr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + char* strchr( char* __s, int __c) {return __libcpp_strchr(__s, __c);} + +inline _LIBCPP_INLINE_VISIBILITY +char* __libcpp_strpbrk(const char* __s1, const char* __s2) {return (char*)strpbrk(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const char* strpbrk(const char* __s1, const char* __s2) {return __libcpp_strpbrk(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + char* strpbrk( char* __s1, const char* __s2) {return __libcpp_strpbrk(__s1, __s2);} + +inline _LIBCPP_INLINE_VISIBILITY +char* __libcpp_strrchr(const char* __s, int __c) {return (char*)strrchr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const char* strrchr(const char* __s, int __c) {return __libcpp_strrchr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + char* strrchr( char* __s, int __c) {return __libcpp_strrchr(__s, __c);} + +inline _LIBCPP_INLINE_VISIBILITY +void* __libcpp_memchr(const void* __s, int __c, size_t __n) {return (void*)memchr(__s, __c, __n);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const void* memchr(const void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + void* memchr( void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);} + +inline _LIBCPP_INLINE_VISIBILITY +char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const char* strstr(const char* __s1, const char* __s2) {return __libcpp_strstr(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + char* strstr( char* __s1, const char* __s2) {return __libcpp_strstr(__s1, __s2);} +} +#endif + +#endif // _LIBCPP_STRING_H diff --git a/android/x86/include/v8/libc++/string_view b/android/x86/include/v8/libc++/string_view new file mode 100755 index 00000000..9a6eb0c2 --- /dev/null +++ b/android/x86/include/v8/libc++/string_view @@ -0,0 +1,833 @@ +// -*- C++ -*- +//===------------------------ string_view ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STRING_VIEW +#define _LIBCPP_STRING_VIEW + +/* +string_view synopsis + +namespace std { + + // 7.2, Class template basic_string_view + template<class charT, class traits = char_traits<charT>> + class basic_string_view; + + // 7.9, basic_string_view non-member comparison functions + template<class charT, class traits> + constexpr bool operator==(basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator!=(basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator< (basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator> (basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator<=(basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator>=(basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + // see below, sufficient additional overloads of comparison functions + + // 7.10, Inserters and extractors + template<class charT, class traits> + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + basic_string_view<charT, traits> str); + + // basic_string_view typedef names + typedef basic_string_view<char> string_view; + typedef basic_string_view<char16_t> u16string_view; + typedef basic_string_view<char32_t> u32string_view; + typedef basic_string_view<wchar_t> wstring_view; + + template<class charT, class traits = char_traits<charT>> + class basic_string_view { + public: + // types + typedef traits traits_type; + typedef charT value_type; + typedef charT* pointer; + typedef const charT* const_pointer; + typedef charT& reference; + typedef const charT& const_reference; + typedef implementation-defined const_iterator; + typedef const_iterator iterator; + typedef reverse_iterator<const_iterator> const_reverse_iterator; + typedef const_reverse_iterator reverse_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + static constexpr size_type npos = size_type(-1); + + // 7.3, basic_string_view constructors and assignment operators + constexpr basic_string_view() noexcept; + constexpr basic_string_view(const basic_string_view&) noexcept = default; + basic_string_view& operator=(const basic_string_view&) noexcept = default; + template<class Allocator> + constexpr basic_string_view(const charT* str); + constexpr basic_string_view(const charT* str, size_type len); + + // 7.4, basic_string_view iterator support + constexpr const_iterator begin() const noexcept; + constexpr const_iterator end() const noexcept; + constexpr const_iterator cbegin() const noexcept; + constexpr const_iterator cend() const noexcept; + const_reverse_iterator rbegin() const noexcept; + const_reverse_iterator rend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // 7.5, basic_string_view capacity + constexpr size_type size() const noexcept; + constexpr size_type length() const noexcept; + constexpr size_type max_size() const noexcept; + constexpr bool empty() const noexcept; + + // 7.6, basic_string_view element access + constexpr const_reference operator[](size_type pos) const; + constexpr const_reference at(size_type pos) const; + constexpr const_reference front() const; + constexpr const_reference back() const; + constexpr const_pointer data() const noexcept; + + // 7.7, basic_string_view modifiers + constexpr void remove_prefix(size_type n); + constexpr void remove_suffix(size_type n); + constexpr void swap(basic_string_view& s) noexcept; + + size_type copy(charT* s, size_type n, size_type pos = 0) const; + + constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; + constexpr int compare(basic_string_view s) const noexcept; + constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const; + constexpr int compare(size_type pos1, size_type n1, + basic_string_view s, size_type pos2, size_type n2) const; + constexpr int compare(const charT* s) const; + constexpr int compare(size_type pos1, size_type n1, const charT* s) const; + constexpr int compare(size_type pos1, size_type n1, + const charT* s, size_type n2) const; + constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept; + constexpr size_type find(charT c, size_type pos = 0) const noexcept; + constexpr size_type find(const charT* s, size_type pos, size_type n) const; + constexpr size_type find(const charT* s, size_type pos = 0) const; + constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept; + constexpr size_type rfind(charT c, size_type pos = npos) const noexcept; + constexpr size_type rfind(const charT* s, size_type pos, size_type n) const; + constexpr size_type rfind(const charT* s, size_type pos = npos) const; + constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept; + constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept; + constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_first_of(const charT* s, size_type pos = 0) const; + constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept; + constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept; + constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_last_of(const charT* s, size_type pos = npos) const; + constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; + constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept; + constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const; + constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept; + constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept; + constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const; + + constexpr bool starts_with(basic_string_view s) const noexcept; // C++2a + constexpr bool starts_with(charT c) const noexcept; // C++2a + constexpr bool starts_with(const charT* s) const; // C++2a + constexpr bool ends_with(basic_string_view s) const noexcept; // C++2a + constexpr bool ends_with(charT c) const noexcept; // C++2a + constexpr bool ends_with(const charT* s) const; // C++2a + + private: + const_pointer data_; // exposition only + size_type size_; // exposition only + }; + + // 7.11, Hash support + template <class T> struct hash; + template <> struct hash<string_view>; + template <> struct hash<u16string_view>; + template <> struct hash<u32string_view>; + template <> struct hash<wstring_view>; + + constexpr basic_string_view<char> operator "" sv( const char *str, size_t len ) noexcept; + constexpr basic_string_view<wchar_t> operator "" sv( const wchar_t *str, size_t len ) noexcept; + constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept; + constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept; + +} // namespace std + + +*/ + +#include <__config> +#include <__string> +#include <algorithm> +#include <iterator> +#include <limits> +#include <stdexcept> +#include <version> +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _CharT, class _Traits = char_traits<_CharT> > +class _LIBCPP_TEMPLATE_VIS basic_string_view { +public: + // types + typedef _Traits traits_type; + typedef _CharT value_type; + typedef _CharT* pointer; + typedef const _CharT* const_pointer; + typedef _CharT& reference; + typedef const _CharT& const_reference; + typedef const_pointer const_iterator; // See [string.view.iterators] + typedef const_iterator iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + typedef const_reverse_iterator reverse_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1); + + static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array"); + static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout"); + static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial"); + static_assert((is_same<_CharT, typename traits_type::char_type>::value), + "traits_type::char_type must be the same type as CharT"); + + // [string.view.cons], construct/copy + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {} + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view(const basic_string_view&) _NOEXCEPT = default; + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default; + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT + : __data(__s), __size(__len) + { +// #if _LIBCPP_STD_VER > 11 +// _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); +// #endif + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view(const _CharT* __s) + : __data(__s), __size(_Traits::length(__s)) {} + + // [string.view.iterators], iterators + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT { return cbegin(); } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT { return cend(); } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT { return __data; } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT { return __data + __size; } + + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } + + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } + + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } + + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } + + // [string.view.capacity], capacity + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT { return __size; } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + size_type length() const _NOEXCEPT { return __size; } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + bool empty() const _NOEXCEPT { return __size == 0; } + + // [string.view.access], element access + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference operator[](size_type __pos) const _NOEXCEPT { return __data[__pos]; } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference at(size_type __pos) const + { + return __pos >= size() + ? (__throw_out_of_range("string_view::at"), __data[0]) + : __data[__pos]; + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference front() const _NOEXCEPT + { + return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0]; + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference back() const _NOEXCEPT + { + return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1]; + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_pointer data() const _NOEXCEPT { return __data; } + + // [string.view.modifiers], modifiers: + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + void remove_prefix(size_type __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()"); + __data += __n; + __size -= __n; + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + void remove_suffix(size_type __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()"); + __size -= __n; + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + void swap(basic_string_view& __other) _NOEXCEPT + { + const value_type *__p = __data; + __data = __other.__data; + __other.__data = __p; + + size_type __sz = __size; + __size = __other.__size; + __other.__size = __sz; + } + + _LIBCPP_INLINE_VISIBILITY + size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const + { + if (__pos > size()) + __throw_out_of_range("string_view::copy"); + size_type __rlen = _VSTD::min(__n, size() - __pos); + _Traits::copy(__s, data() + __pos, __rlen); + return __rlen; + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view substr(size_type __pos = 0, size_type __n = npos) const + { + return __pos > size() + ? (__throw_out_of_range("string_view::substr"), basic_string_view()) + : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos)); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT + { + size_type __rlen = _VSTD::min( size(), __sv.size()); + int __retval = _Traits::compare(data(), __sv.data(), __rlen); + if ( __retval == 0 ) // first __rlen chars matched + __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 ); + return __retval; + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const + { + return substr(__pos1, __n1).compare(__sv); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare( size_type __pos1, size_type __n1, + basic_string_view __sv, size_type __pos2, size_type __n2) const + { + return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(const _CharT* __s) const _NOEXCEPT + { + return compare(basic_string_view(__s)); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, const _CharT* __s) const + { + return substr(__pos1, __n1).compare(basic_string_view(__s)); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const + { + return substr(__pos1, __n1).compare(basic_string_view(__s, __n2)); + } + + // find + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT + { + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(const _CharT* __s, size_type __pos = 0) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // rfind + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT + { + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_first_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr"); + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT + { return find(__c, __pos); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(const _CharT* __s, size_type __pos=0) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_last_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr"); + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT + { return rfind(__c, __pos); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_first_not_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr"); + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT + { + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_last_not_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr"); + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT + { + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + +#if _LIBCPP_STD_VER > 17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(basic_string_view __s) const _NOEXCEPT + { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(front(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(const value_type* __s) const _NOEXCEPT + { return starts_with(basic_string_view(__s)); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(basic_string_view __s) const _NOEXCEPT + { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(back(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(const value_type* __s) const _NOEXCEPT + { return ends_with(basic_string_view(__s)); } +#endif + +private: + const value_type* __data; + size_type __size; +}; + + +// [string.view.comparison] +// operator == +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator==(basic_string_view<_CharT, _Traits> __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator==(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; +} + + +// operator != +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator!=(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; +} + + +// operator < +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) < 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) < 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) < 0; +} + + +// operator > +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) > 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) > 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) > 0; +} + + +// operator <= +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) <= 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<=(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) <= 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) <= 0; +} + + +// operator >= +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) >= 0; +} + + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>=(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) >= 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) >= 0; +} + +typedef basic_string_view<char> string_view; +#ifndef _LIBCPP_NO_HAS_CHAR8_T +typedef basic_string_view<char8_t> u8string_view; +#endif +typedef basic_string_view<char16_t> u16string_view; +typedef basic_string_view<char32_t> u32string_view; +typedef basic_string_view<wchar_t> wstring_view; + +// [string.view.hash] +template<class _CharT, class _Traits> +struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, _Traits> > + : public unary_function<basic_string_view<_CharT, _Traits>, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const basic_string_view<_CharT, _Traits> __val) const _NOEXCEPT { + return __do_string_hash(__val.data(), __val.data() + __val.size()); + } +}; + + +#if _LIBCPP_STD_VER > 11 +inline namespace literals +{ + inline namespace string_view_literals + { + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT + { + return basic_string_view<char> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT + { + return basic_string_view<wchar_t> (__str, __len); + } + +#ifndef _LIBCPP_NO_HAS_CHAR8_T + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT + { + return basic_string_view<char8_t> (__str, __len); + } +#endif + + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT + { + return basic_string_view<char16_t> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT + { + return basic_string_view<char32_t> (__str, __len); + } + } +} +#endif +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_STRING_VIEW diff --git a/android/x86/include/v8/libc++/strstream b/android/x86/include/v8/libc++/strstream new file mode 100755 index 00000000..31999bba --- /dev/null +++ b/android/x86/include/v8/libc++/strstream @@ -0,0 +1,399 @@ +// -*- C++ -*- +//===--------------------------- strstream --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STRSTREAM +#define _LIBCPP_STRSTREAM + +/* + strstream synopsis + +class strstreambuf + : public basic_streambuf<char> +{ +public: + explicit strstreambuf(streamsize alsize_arg = 0); + strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*)); + strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = 0); + strstreambuf(const char* gnext_arg, streamsize n); + + strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = 0); + strstreambuf(const signed char* gnext_arg, streamsize n); + strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = 0); + strstreambuf(const unsigned char* gnext_arg, streamsize n); + + strstreambuf(strstreambuf&& rhs); + strstreambuf& operator=(strstreambuf&& rhs); + + virtual ~strstreambuf(); + + void swap(strstreambuf& rhs); + + void freeze(bool freezefl = true); + char* str(); + int pcount() const; + +protected: + virtual int_type overflow (int_type c = EOF); + virtual int_type pbackfail(int_type c = EOF); + virtual int_type underflow(); + virtual pos_type seekoff(off_type off, ios_base::seekdir way, + ios_base::openmode which = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type sp, + ios_base::openmode which = ios_base::in | ios_base::out); + virtual streambuf* setbuf(char* s, streamsize n); + +private: + typedef T1 strstate; // exposition only + static const strstate allocated; // exposition only + static const strstate constant; // exposition only + static const strstate dynamic; // exposition only + static const strstate frozen; // exposition only + strstate strmode; // exposition only + streamsize alsize; // exposition only + void* (*palloc)(size_t); // exposition only + void (*pfree)(void*); // exposition only +}; + +class istrstream + : public basic_istream<char> +{ +public: + explicit istrstream(const char* s); + explicit istrstream(char* s); + istrstream(const char* s, streamsize n); + istrstream(char* s, streamsize n); + + virtual ~istrstream(); + + strstreambuf* rdbuf() const; + char *str(); + +private: + strstreambuf sb; // exposition only +}; + +class ostrstream + : public basic_ostream<char> +{ +public: + ostrstream(); + ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out); + + virtual ~ostrstream(); + + strstreambuf* rdbuf() const; + void freeze(bool freezefl = true); + char* str(); + int pcount() const; + +private: + strstreambuf sb; // exposition only +}; + +class strstream + : public basic_iostream<char> +{ +public: + // Types + typedef char char_type; + typedef char_traits<char>::int_type int_type; + typedef char_traits<char>::pos_type pos_type; + typedef char_traits<char>::off_type off_type; + + // constructors/destructor + strstream(); + strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out); + + virtual ~strstream(); + + // Members: + strstreambuf* rdbuf() const; + void freeze(bool freezefl = true); + int pcount() const; + char* str(); + +private: + strstreambuf sb; // exposition only +}; + +} // std + +*/ + +#include <__config> +#include <ostream> +#include <istream> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +class _LIBCPP_TYPE_VIS strstreambuf + : public streambuf +{ +public: + explicit strstreambuf(streamsize __alsize = 0); + strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*)); + strstreambuf(char* __gnext, streamsize __n, char* __pbeg = 0); + strstreambuf(const char* __gnext, streamsize __n); + + strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = 0); + strstreambuf(const signed char* __gnext, streamsize __n); + strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = 0); + strstreambuf(const unsigned char* __gnext, streamsize __n); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + strstreambuf(strstreambuf&& __rhs); + _LIBCPP_INLINE_VISIBILITY + strstreambuf& operator=(strstreambuf&& __rhs); +#endif // _LIBCPP_CXX03_LANG + + virtual ~strstreambuf(); + + void swap(strstreambuf& __rhs); + + void freeze(bool __freezefl = true); + char* str(); + int pcount() const; + +protected: + virtual int_type overflow (int_type __c = EOF); + virtual int_type pbackfail(int_type __c = EOF); + virtual int_type underflow(); + virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __which = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type __sp, + ios_base::openmode __which = ios_base::in | ios_base::out); + +private: + typedef unsigned __mode_type; + static const __mode_type __allocated = 0x01; + static const __mode_type __constant = 0x02; + static const __mode_type __dynamic = 0x04; + static const __mode_type __frozen = 0x08; + static const streamsize __default_alsize = 4096; + + __mode_type __strmode_; + streamsize __alsize_; + void* (*__palloc_)(size_t); + void (*__pfree_)(void*); + + void __init(char* __gnext, streamsize __n, char* __pbeg); +}; + +#ifndef _LIBCPP_CXX03_LANG + +inline _LIBCPP_INLINE_VISIBILITY +strstreambuf::strstreambuf(strstreambuf&& __rhs) + : streambuf(__rhs), + __strmode_(__rhs.__strmode_), + __alsize_(__rhs.__alsize_), + __palloc_(__rhs.__palloc_), + __pfree_(__rhs.__pfree_) +{ + __rhs.setg(nullptr, nullptr, nullptr); + __rhs.setp(nullptr, nullptr); +} + +inline _LIBCPP_INLINE_VISIBILITY +strstreambuf& +strstreambuf::operator=(strstreambuf&& __rhs) +{ + if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0) + { + if (__pfree_) + __pfree_(eback()); + else + delete [] eback(); + } + streambuf::operator=(__rhs); + __strmode_ = __rhs.__strmode_; + __alsize_ = __rhs.__alsize_; + __palloc_ = __rhs.__palloc_; + __pfree_ = __rhs.__pfree_; + __rhs.setg(nullptr, nullptr, nullptr); + __rhs.setp(nullptr, nullptr); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +class _LIBCPP_TYPE_VIS istrstream + : public istream +{ +public: + _LIBCPP_INLINE_VISIBILITY + explicit istrstream(const char* __s) + : istream(&__sb_), __sb_(__s, 0) {} + _LIBCPP_INLINE_VISIBILITY + explicit istrstream(char* __s) + : istream(&__sb_), __sb_(__s, 0) {} + _LIBCPP_INLINE_VISIBILITY + istrstream(const char* __s, streamsize __n) + : istream(&__sb_), __sb_(__s, __n) {} + _LIBCPP_INLINE_VISIBILITY + istrstream(char* __s, streamsize __n) + : istream(&__sb_), __sb_(__s, __n) {} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + istrstream(istrstream&& __rhs) + : istream(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) + { + istream::set_rdbuf(&__sb_); + } + + _LIBCPP_INLINE_VISIBILITY + istrstream& operator=(istrstream&& __rhs) + { + istream::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; + } +#endif // _LIBCPP_CXX03_LANG + + virtual ~istrstream(); + + _LIBCPP_INLINE_VISIBILITY + void swap(istrstream& __rhs) + { + istream::swap(__rhs); + __sb_.swap(__rhs.__sb_); + } + + _LIBCPP_INLINE_VISIBILITY + strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);} + _LIBCPP_INLINE_VISIBILITY + char *str() {return __sb_.str();} + +private: + strstreambuf __sb_; +}; + +class _LIBCPP_TYPE_VIS ostrstream + : public ostream +{ +public: + _LIBCPP_INLINE_VISIBILITY + ostrstream() + : ostream(&__sb_) {} + _LIBCPP_INLINE_VISIBILITY + ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out) + : ostream(&__sb_), + __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0)) + {} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + ostrstream(ostrstream&& __rhs) + : ostream(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) + { + ostream::set_rdbuf(&__sb_); + } + + _LIBCPP_INLINE_VISIBILITY + ostrstream& operator=(ostrstream&& __rhs) + { + ostream::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; + } +#endif // _LIBCPP_CXX03_LANG + + virtual ~ostrstream(); + + _LIBCPP_INLINE_VISIBILITY + void swap(ostrstream& __rhs) + { + ostream::swap(__rhs); + __sb_.swap(__rhs.__sb_); + } + + _LIBCPP_INLINE_VISIBILITY + strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);} + _LIBCPP_INLINE_VISIBILITY + void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);} + _LIBCPP_INLINE_VISIBILITY + char* str() {return __sb_.str();} + _LIBCPP_INLINE_VISIBILITY + int pcount() const {return __sb_.pcount();} + +private: + strstreambuf __sb_; // exposition only +}; + +class _LIBCPP_TYPE_VIS strstream + : public iostream +{ +public: + // Types + typedef char char_type; + typedef char_traits<char>::int_type int_type; + typedef char_traits<char>::pos_type pos_type; + typedef char_traits<char>::off_type off_type; + + // constructors/destructor + _LIBCPP_INLINE_VISIBILITY + strstream() + : iostream(&__sb_) {} + _LIBCPP_INLINE_VISIBILITY + strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out) + : iostream(&__sb_), + __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0)) + {} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + strstream(strstream&& __rhs) + : iostream(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) + { + iostream::set_rdbuf(&__sb_); + } + + _LIBCPP_INLINE_VISIBILITY + strstream& operator=(strstream&& __rhs) + { + iostream::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; + } +#endif // _LIBCPP_CXX03_LANG + + virtual ~strstream(); + + _LIBCPP_INLINE_VISIBILITY + void swap(strstream& __rhs) + { + iostream::swap(__rhs); + __sb_.swap(__rhs.__sb_); + } + + // Members: + _LIBCPP_INLINE_VISIBILITY + strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);} + _LIBCPP_INLINE_VISIBILITY + void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);} + _LIBCPP_INLINE_VISIBILITY + int pcount() const {return __sb_.pcount();} + _LIBCPP_INLINE_VISIBILITY + char* str() {return __sb_.str();} + +private: + strstreambuf __sb_; // exposition only +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STRSTREAM diff --git a/android/x86/include/v8/libc++/support/android/locale_bionic.h b/android/x86/include/v8/libc++/support/android/locale_bionic.h new file mode 100755 index 00000000..5b16071d --- /dev/null +++ b/android/x86/include/v8/libc++/support/android/locale_bionic.h @@ -0,0 +1,67 @@ +// -*- C++ -*- +//===------------------- support/android/locale_bionic.h ------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H +#define _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H + +#if defined(__BIONIC__) + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdlib.h> +#include <xlocale.h> + +#ifdef __cplusplus +} +#endif + +#if defined(__ANDROID__) + +#include <android/api-level.h> +#include <android/ndk-version.h> +#include <support/xlocale/__posix_l_fallback.h> +// In NDK versions later than 16, locale-aware functions are provided by +// legacy_stdlib_inlines.h +#if __NDK_MAJOR__ <= 16 +#if __ANDROID_API__ < 21 +#include <support/xlocale/__strtonum_fallback.h> +#elif __ANDROID_API__ < 26 + +#if defined(__cplusplus) +extern "C" { +#endif + +inline _LIBCPP_INLINE_VISIBILITY float strtof_l(const char* __nptr, char** __endptr, + locale_t) { + return ::strtof(__nptr, __endptr); +} + +inline _LIBCPP_INLINE_VISIBILITY double strtod_l(const char* __nptr, + char** __endptr, locale_t) { + return ::strtod(__nptr, __endptr); +} + +inline _LIBCPP_INLINE_VISIBILITY long strtol_l(const char* __nptr, char** __endptr, + int __base, locale_t) { + return ::strtol(__nptr, __endptr, __base); +} + +#if defined(__cplusplus) +} +#endif + +#endif // __ANDROID_API__ < 26 + +#endif // __NDK_MAJOR__ <= 16 +#endif // defined(__ANDROID__) + +#endif // defined(__BIONIC__) +#endif // _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H diff --git a/android/x86/include/v8/libc++/support/fuchsia/xlocale.h b/android/x86/include/v8/libc++/support/fuchsia/xlocale.h new file mode 100755 index 00000000..b86ce9ef --- /dev/null +++ b/android/x86/include/v8/libc++/support/fuchsia/xlocale.h @@ -0,0 +1,22 @@ +// -*- C++ -*- +//===------------------- support/fuchsia/xlocale.h ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_FUCHSIA_XLOCALE_H +#define _LIBCPP_SUPPORT_FUCHSIA_XLOCALE_H + +#if defined(__Fuchsia__) + +#include <cstdlib> +#include <cwchar> +#include <support/xlocale/__posix_l_fallback.h> +#include <support/xlocale/__strtonum_fallback.h> + +#endif // defined(__Fuchsia__) + +#endif // _LIBCPP_SUPPORT_FUCHSIA_XLOCALE_H diff --git a/android/x86/include/v8/libc++/support/ibm/limits.h b/android/x86/include/v8/libc++/support/ibm/limits.h new file mode 100755 index 00000000..d1c59f06 --- /dev/null +++ b/android/x86/include/v8/libc++/support/ibm/limits.h @@ -0,0 +1,98 @@ +// -*- C++ -*- +//===--------------------- support/ibm/limits.h ---------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_IBM_LIMITS_H +#define _LIBCPP_SUPPORT_IBM_LIMITS_H + +#if !defined(_AIX) // Linux +#include <math.h> // for HUGE_VAL, HUGE_VALF, HUGE_VALL, and NAN + +static const unsigned int _QNAN_F = 0x7fc00000; +#define NANF (*((float *)(&_QNAN_F))) +static const unsigned int _QNAN_LDBL128[4] = {0x7ff80000, 0x0, 0x0, 0x0}; +#define NANL (*((long double *)(&_QNAN_LDBL128))) +static const unsigned int _SNAN_F= 0x7f855555; +#define NANSF (*((float *)(&_SNAN_F))) +static const unsigned int _SNAN_D[2] = {0x7ff55555, 0x55555555}; +#define NANS (*((double *)(&_SNAN_D))) +static const unsigned int _SNAN_LDBL128[4] = {0x7ff55555, 0x55555555, 0x0, 0x0}; +#define NANSL (*((long double *)(&_SNAN_LDBL128))) + +#define __builtin_huge_val() HUGE_VAL +#define __builtin_huge_valf() HUGE_VALF +#define __builtin_huge_vall() HUGE_VALL +#define __builtin_nan(__dummy) NAN +#define __builtin_nanf(__dummy) NANF +#define __builtin_nanl(__dummy) NANL +#define __builtin_nans(__dummy) NANS +#define __builtin_nansf(__dummy) NANSF +#define __builtin_nansl(__dummy) NANSL + +#else + +#include <math.h> +#include <float.h> // limit constants + +#define __builtin_huge_val() HUGE_VAL //0x7ff0000000000000 +#define __builtin_huge_valf() HUGE_VALF //0x7f800000 +#define __builtin_huge_vall() HUGE_VALL //0x7ff0000000000000 +#define __builtin_nan(__dummy) nan(__dummy) //0x7ff8000000000000 +#define __builtin_nanf(__dummy) nanf(__dummy) // 0x7ff80000 +#define __builtin_nanl(__dummy) nanl(__dummy) //0x7ff8000000000000 +#define __builtin_nans(__dummy) DBL_SNAN //0x7ff5555555555555 +#define __builtin_nansf(__dummy) FLT_SNAN //0x7f855555 +#define __builtin_nansl(__dummy) DBL_SNAN //0x7ff5555555555555 + +#define __FLT_MANT_DIG__ FLT_MANT_DIG +#define __FLT_DIG__ FLT_DIG +#define __FLT_RADIX__ FLT_RADIX +#define __FLT_MIN_EXP__ FLT_MIN_EXP +#define __FLT_MIN_10_EXP__ FLT_MIN_10_EXP +#define __FLT_MAX_EXP__ FLT_MAX_EXP +#define __FLT_MAX_10_EXP__ FLT_MAX_10_EXP +#define __FLT_MIN__ FLT_MIN +#define __FLT_MAX__ FLT_MAX +#define __FLT_EPSILON__ FLT_EPSILON +// predefined by XLC on LoP +#define __FLT_DENORM_MIN__ 1.40129846e-45F + +#define __DBL_MANT_DIG__ DBL_MANT_DIG +#define __DBL_DIG__ DBL_DIG +#define __DBL_MIN_EXP__ DBL_MIN_EXP +#define __DBL_MIN_10_EXP__ DBL_MIN_10_EXP +#define __DBL_MAX_EXP__ DBL_MAX_EXP +#define __DBL_MAX_10_EXP__ DBL_MAX_10_EXP +#define __DBL_MIN__ DBL_MIN +#define __DBL_MAX__ DBL_MAX +#define __DBL_EPSILON__ DBL_EPSILON +// predefined by XLC on LoP +#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 + +#define __LDBL_MANT_DIG__ LDBL_MANT_DIG +#define __LDBL_DIG__ LDBL_DIG +#define __LDBL_MIN_EXP__ LDBL_MIN_EXP +#define __LDBL_MIN_10_EXP__ LDBL_MIN_10_EXP +#define __LDBL_MAX_EXP__ LDBL_MAX_EXP +#define __LDBL_MAX_10_EXP__ LDBL_MAX_10_EXP +#define __LDBL_MIN__ LDBL_MIN +#define __LDBL_MAX__ LDBL_MAX +#define __LDBL_EPSILON__ LDBL_EPSILON +// predefined by XLC on LoP +#if __LONGDOUBLE128 +#define __LDBL_DENORM_MIN__ 4.94065645841246544176568792868221e-324L +#else +#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L +#endif + +// predefined by XLC on LoP +#define __CHAR_BIT__ 8 + +#endif // _AIX + +#endif // _LIBCPP_SUPPORT_IBM_LIMITS_H diff --git a/android/x86/include/v8/libc++/support/ibm/locale_mgmt_aix.h b/android/x86/include/v8/libc++/support/ibm/locale_mgmt_aix.h new file mode 100755 index 00000000..e452dc32 --- /dev/null +++ b/android/x86/include/v8/libc++/support/ibm/locale_mgmt_aix.h @@ -0,0 +1,84 @@ +// -*- C++ -*- +//===------------------- support/ibm/locale_mgmt_aix.h --------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H +#define _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H + +#if defined(_AIX) +#include "cstdlib" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_AIX71) +// AIX 7.1 and higher has these definitions. Definitions and stubs +// are provied here as a temporary workaround on AIX 6.1. + +#define LC_COLLATE_MASK 1 +#define LC_CTYPE_MASK 2 +#define LC_MESSAGES_MASK 4 +#define LC_MONETARY_MASK 8 +#define LC_NUMERIC_MASK 16 +#define LC_TIME_MASK 32 +#define LC_ALL_MASK (LC_COLLATE_MASK | LC_CTYPE_MASK | \ + LC_MESSAGES_MASK | LC_MONETARY_MASK |\ + LC_NUMERIC_MASK | LC_TIME_MASK) + +typedef void* locale_t; + +// The following are stubs. They are not supported on AIX 6.1. +static inline +locale_t newlocale(int category_mask, const char *locale, locale_t base) +{ + _LC_locale_t *newloc, *loc; + if ((loc = (_LC_locale_t *)__xopen_locale(locale)) == NULL) + { + errno = EINVAL; + return (locale_t)0; + } + if ((newloc = (_LC_locale_t *)calloc(1, sizeof(_LC_locale_t))) == NULL) + { + errno = ENOMEM; + return (locale_t)0; + } + if (!base) + base = (_LC_locale_t *)__xopen_locale("C"); + memcpy(newloc, base, sizeof (_LC_locale_t)); + if (category_mask & LC_COLLATE_MASK) + newloc->lc_collate = loc->lc_collate; + if (category_mask & LC_CTYPE_MASK) + newloc->lc_ctype = loc->lc_ctype; + //if (category_mask & LC_MESSAGES_MASK) + // newloc->lc_messages = loc->lc_messages; + if (category_mask & LC_MONETARY_MASK) + newloc->lc_monetary = loc->lc_monetary; + if (category_mask & LC_TIME_MASK) + newloc->lc_time = loc->lc_time; + if (category_mask & LC_NUMERIC_MASK) + newloc->lc_numeric = loc->lc_numeric; + return (locale_t)newloc; +} +static inline +void freelocale(locale_t locobj) +{ + free(locobj); +} +static inline +locale_t uselocale(locale_t newloc) +{ + return (locale_t)0; +} +#endif // !defined(_AIX71) + +#ifdef __cplusplus +} +#endif +#endif // defined(_AIX) +#endif // _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H diff --git a/android/x86/include/v8/libc++/support/ibm/support.h b/android/x86/include/v8/libc++/support/ibm/support.h new file mode 100755 index 00000000..0569cbe7 --- /dev/null +++ b/android/x86/include/v8/libc++/support/ibm/support.h @@ -0,0 +1,53 @@ +// -*- C++ -*- +//===----------------------- support/ibm/support.h ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_IBM_SUPPORT_H +#define _LIBCPP_SUPPORT_IBM_SUPPORT_H + +extern "builtin" int __popcnt4(unsigned int); +extern "builtin" int __popcnt8(unsigned long long); +extern "builtin" unsigned int __cnttz4(unsigned int); +extern "builtin" unsigned int __cnttz8(unsigned long long); +extern "builtin" unsigned int __cntlz4(unsigned int); +extern "builtin" unsigned int __cntlz8(unsigned long long); + +// Builtin functions for counting population +#define __builtin_popcount(x) __popcnt4(x) +#define __builtin_popcountll(x) __popcnt8(x) +#if defined(__64BIT__) +#define __builtin_popcountl(x) __builtin_popcountll(x) +#else +#define __builtin_popcountl(x) __builtin_popcount(x) +#endif + +// Builtin functions for counting trailing zeros +#define __builtin_ctz(x) __cnttz4(x) +#define __builtin_ctzll(x) __cnttz8(x) +#if defined(__64BIT__) +#define __builtin_ctzl(x) __builtin_ctzll(x) +#else +#define __builtin_ctzl(x) __builtin_ctz(x) +#endif + +// Builtin functions for counting leading zeros +#define __builtin_clz(x) __cntlz4(x) +#define __builtin_clzll(x) __cntlz8(x) +#if defined(__64BIT__) +#define __builtin_clzl(x) __builtin_clzll(x) +#else +#define __builtin_clzl(x) __builtin_clz(x) +#endif + +#if defined(__64BIT__) +#define __SIZE_WIDTH__ 64 +#else +#define __SIZE_WIDTH__ 32 +#endif + +#endif // _LIBCPP_SUPPORT_IBM_SUPPORT_H diff --git a/android/x86/include/v8/libc++/support/ibm/xlocale.h b/android/x86/include/v8/libc++/support/ibm/xlocale.h new file mode 100755 index 00000000..9f0522c1 --- /dev/null +++ b/android/x86/include/v8/libc++/support/ibm/xlocale.h @@ -0,0 +1,270 @@ +// -*- C++ -*- +//===--------------------- support/ibm/xlocale.h -------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_IBM_XLOCALE_H +#define _LIBCPP_SUPPORT_IBM_XLOCALE_H +#include <support/ibm/locale_mgmt_aix.h> + +#if defined(_AIX) +#include "cstdlib" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_AIX71) +// AIX 7.1 and higher has these definitions. Definitions and stubs +// are provied here as a temporary workaround on AIX 6.1. +static inline +int isalnum_l(int c, locale_t locale) +{ + return __xisalnum(locale, c); +} +static inline +int isalpha_l(int c, locale_t locale) +{ + return __xisalpha(locale, c); +} +static inline +int isblank_l(int c, locale_t locale) +{ + return __xisblank(locale, c); +} +static inline +int iscntrl_l(int c, locale_t locale) +{ + return __xiscntrl(locale, c); +} +static inline +int isdigit_l(int c, locale_t locale) +{ + return __xisdigit(locale, c); +} +static inline +int isgraph_l(int c, locale_t locale) +{ + return __xisgraph(locale, c); +} +static inline +int islower_l(int c, locale_t locale) +{ + return __xislower(locale, c); +} +static inline +int isprint_l(int c, locale_t locale) +{ + return __xisprint(locale, c); +} + +static inline +int ispunct_l(int c, locale_t locale) +{ + return __xispunct(locale, c); +} +static inline +int isspace_l(int c, locale_t locale) +{ + return __xisspace(locale, c); +} +static inline +int isupper_l(int c, locale_t locale) +{ + return __xisupper(locale, c); +} + +static inline +int isxdigit_l(int c, locale_t locale) +{ + return __xisxdigit(locale, c); +} + +static inline +int iswalnum_l(wchar_t wc, locale_t locale) +{ + return __xiswalnum(locale, wc); +} + +static inline +int iswalpha_l(wchar_t wc, locale_t locale) +{ + return __xiswalpha(locale, wc); +} + +static inline +int iswblank_l(wchar_t wc, locale_t locale) +{ + return __xiswblank(locale, wc); +} + +static inline +int iswcntrl_l(wchar_t wc, locale_t locale) +{ + return __xiswcntrl(locale, wc); +} + +static inline +int iswdigit_l(wchar_t wc, locale_t locale) +{ + return __xiswdigit(locale, wc); +} + +static inline +int iswgraph_l(wchar_t wc, locale_t locale) +{ + return __xiswgraph(locale, wc); +} + +static inline +int iswlower_l(wchar_t wc, locale_t locale) +{ + return __xiswlower(locale, wc); +} + +static inline +int iswprint_l(wchar_t wc, locale_t locale) +{ + return __xiswprint(locale, wc); +} + +static inline +int iswpunct_l(wchar_t wc, locale_t locale) +{ + return __xiswpunct(locale, wc); +} + +static inline +int iswspace_l(wchar_t wc, locale_t locale) +{ + return __xiswspace(locale, wc); +} + +static inline +int iswupper_l(wchar_t wc, locale_t locale) +{ + return __xiswupper(locale, wc); +} + +static inline +int iswxdigit_l(wchar_t wc, locale_t locale) +{ + return __xiswxdigit(locale, wc); +} + +static inline +int iswctype_l(wint_t wc, wctype_t desc, locale_t locale) +{ + return __xiswctype(locale, wc, desc); +} + +static inline +int toupper_l(int c, locale_t locale) +{ + return __xtoupper(locale, c); +} +static inline +int tolower_l(int c, locale_t locale) +{ + return __xtolower(locale, c); +} +static inline +wint_t towupper_l(wint_t wc, locale_t locale) +{ + return __xtowupper(locale, wc); +} +static inline +wint_t towlower_l(wint_t wc, locale_t locale) +{ + return __xtowlower(locale, wc); +} + +static inline +int strcoll_l(const char *__s1, const char *__s2, locale_t locale) +{ + return __xstrcoll(locale, __s1, __s2); +} +static inline +int wcscoll_l(const wchar_t *__s1, const wchar_t *__s2, locale_t locale) +{ + return __xwcscoll(locale, __s1, __s2); +} +static inline +size_t strxfrm_l(char *__s1, const char *__s2, size_t __n, locale_t locale) +{ + return __xstrxfrm(locale, __s1, __s2, __n); +} + +static inline +size_t wcsxfrm_l(wchar_t *__ws1, const wchar_t *__ws2, size_t __n, + locale_t locale) +{ + return __xwcsxfrm(locale, __ws1, __ws2, __n); +} +#endif // !defined(_AIX71) + +// strftime_l() is defined by POSIX. However, AIX 7.1 does not have it +// implemented yet. +static inline +size_t strftime_l(char *__s, size_t __size, const char *__fmt, + const struct tm *__tm, locale_t locale) { + return __xstrftime(locale, __s, __size, __fmt, __tm); +} + +// The following are not POSIX routines. These are quick-and-dirty hacks +// to make things pretend to work +static inline +long long strtoll_l(const char *__nptr, char **__endptr, + int __base, locale_t locale) { + return strtoll(__nptr, __endptr, __base); +} +static inline +long strtol_l(const char *__nptr, char **__endptr, + int __base, locale_t locale) { + return strtol(__nptr, __endptr, __base); +} +static inline +long double strtold_l(const char *__nptr, char **__endptr, + locale_t locale) { + return strtold(__nptr, __endptr); +} +static inline +unsigned long long strtoull_l(const char *__nptr, char **__endptr, + int __base, locale_t locale) { + return strtoull(__nptr, __endptr, __base); +} +static inline +unsigned long strtoul_l(const char *__nptr, char **__endptr, + int __base, locale_t locale) { + return strtoul(__nptr, __endptr, __base); +} + +static inline +int vasprintf(char **strp, const char *fmt, va_list ap) +{ + const size_t buff_size = 256; + int str_size; + if ((*strp = (char *)malloc(buff_size)) == NULL) + { + return -1; + } + if ((str_size = vsnprintf(*strp, buff_size, fmt, ap)) >= buff_size) + { + if ((*strp = (char *)realloc(*strp, str_size + 1)) == NULL) + { + return -1; + } + str_size = vsnprintf(*strp, str_size + 1, fmt, ap); + } + return str_size; +} + +#ifdef __cplusplus +} +#endif +#endif // defined(_AIX) +#endif // _LIBCPP_SUPPORT_IBM_XLOCALE_H diff --git a/android/x86/include/v8/libc++/support/musl/xlocale.h b/android/x86/include/v8/libc++/support/musl/xlocale.h new file mode 100755 index 00000000..722d13fa --- /dev/null +++ b/android/x86/include/v8/libc++/support/musl/xlocale.h @@ -0,0 +1,57 @@ +// -*- C++ -*- +//===------------------- support/musl/xlocale.h ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// This adds support for the extended locale functions that are currently +// missing from the Musl C library. +// +// This only works when the specified locale is "C" or "POSIX", but that's +// about as good as we can do without implementing full xlocale support +// in Musl. +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_MUSL_XLOCALE_H +#define _LIBCPP_SUPPORT_MUSL_XLOCALE_H + +#include <cstdlib> +#include <cwchar> + +#ifdef __cplusplus +extern "C" { +#endif + +static inline long long strtoll_l(const char *nptr, char **endptr, int base, + locale_t) { + return strtoll(nptr, endptr, base); +} + +static inline unsigned long long strtoull_l(const char *nptr, char **endptr, + int base, locale_t) { + return strtoull(nptr, endptr, base); +} + +static inline long long wcstoll_l(const wchar_t *nptr, wchar_t **endptr, + int base, locale_t) { + return wcstoll(nptr, endptr, base); +} + +static inline unsigned long long wcstoull_l(const wchar_t *nptr, + wchar_t **endptr, int base, + locale_t) { + return wcstoull(nptr, endptr, base); +} + +static inline long double wcstold_l(const wchar_t *nptr, wchar_t **endptr, + locale_t) { + return wcstold(nptr, endptr); +} + +#ifdef __cplusplus +} +#endif + +#endif // _LIBCPP_SUPPORT_MUSL_XLOCALE_H diff --git a/android/x86/include/v8/libc++/support/newlib/xlocale.h b/android/x86/include/v8/libc++/support/newlib/xlocale.h new file mode 100755 index 00000000..25fa798b --- /dev/null +++ b/android/x86/include/v8/libc++/support/newlib/xlocale.h @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H +#define _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H + +#if defined(_NEWLIB_VERSION) + +#include <cstdlib> +#include <clocale> +#include <cwctype> +#include <ctype.h> +#if !defined(__NEWLIB__) || __NEWLIB__ < 2 || \ + __NEWLIB__ == 2 && __NEWLIB_MINOR__ < 5 +#include <support/xlocale/__nop_locale_mgmt.h> +#include <support/xlocale/__posix_l_fallback.h> +#include <support/xlocale/__strtonum_fallback.h> +#endif + +#endif // _NEWLIB_VERSION + +#endif diff --git a/android/x86/include/v8/libc++/support/solaris/floatingpoint.h b/android/x86/include/v8/libc++/support/solaris/floatingpoint.h new file mode 100755 index 00000000..5f1628fb --- /dev/null +++ b/android/x86/include/v8/libc++/support/solaris/floatingpoint.h @@ -0,0 +1,13 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#define atof sun_atof +#define strtod sun_strtod +#include_next "floatingpoint.h" +#undef atof +#undef strtod diff --git a/android/x86/include/v8/libc++/support/solaris/wchar.h b/android/x86/include/v8/libc++/support/solaris/wchar.h new file mode 100755 index 00000000..9dc9ac3f --- /dev/null +++ b/android/x86/include/v8/libc++/support/solaris/wchar.h @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#define iswalpha sun_iswalpha +#define iswupper sun_iswupper +#define iswlower sun_iswlower +#define iswdigit sun_iswdigit +#define iswxdigit sun_iswxdigit +#define iswalnum sun_iswalnum +#define iswspace sun_iswspace +#define iswpunct sun_iswpunct +#define iswprint sun_iswprint +#define iswgraph sun_iswgraph +#define iswcntrl sun_iswcntrl +#define iswctype sun_iswctype +#define towlower sun_towlower +#define towupper sun_towupper +#define wcswcs sun_wcswcs +#define wcswidth sun_wcswidth +#define wcwidth sun_wcwidth +#define wctype sun_wctype +#define _WCHAR_T 1 +#include_next "wchar.h" +#undef iswalpha +#undef iswupper +#undef iswlower +#undef iswdigit +#undef iswxdigit +#undef iswalnum +#undef iswspace +#undef iswpunct +#undef iswprint +#undef iswgraph +#undef iswcntrl +#undef iswctype +#undef towlower +#undef towupper +#undef wcswcs +#undef wcswidth +#undef wcwidth +#undef wctype diff --git a/android/x86/include/v8/libc++/support/solaris/xlocale.h b/android/x86/include/v8/libc++/support/solaris/xlocale.h new file mode 100755 index 00000000..05131f02 --- /dev/null +++ b/android/x86/include/v8/libc++/support/solaris/xlocale.h @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//////////////////////////////////////////////////////////////////////////////// +// Minimal xlocale implementation for Solaris. This implements the subset of +// the xlocale APIs that libc++ depends on. +//////////////////////////////////////////////////////////////////////////////// +#ifndef __XLOCALE_H_INCLUDED +#define __XLOCALE_H_INCLUDED + +#include <stdlib.h> + +#ifdef __cplusplus +extern "C" { +#endif + + +int snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...); +int asprintf_l(char **__s, locale_t __l, const char *__format, ...); + +int sscanf_l(const char *__s, locale_t __l, const char *__format, ...); + +int toupper_l(int __c, locale_t __l); +int tolower_l(int __c, locale_t __l); + +struct lconv *localeconv(void); +struct lconv *localeconv_l(locale_t __l); + +// FIXME: These are quick-and-dirty hacks to make things pretend to work +static inline +long long strtoll_l(const char *__nptr, char **__endptr, + int __base, locale_t __loc) { + return strtoll(__nptr, __endptr, __base); +} +static inline +long strtol_l(const char *__nptr, char **__endptr, + int __base, locale_t __loc) { + return strtol(__nptr, __endptr, __base); +} +static inline +unsigned long long strtoull_l(const char *__nptr, char **__endptr, + int __base, locale_t __loc) { + return strtoull(__nptr, __endptr, __base); +} +static inline +unsigned long strtoul_l(const char *__nptr, char **__endptr, + int __base, locale_t __loc) { + return strtoul(__nptr, __endptr, __base); +} +static inline +float strtof_l(const char *__nptr, char **__endptr, + locale_t __loc) { + return strtof(__nptr, __endptr); +} +static inline +double strtod_l(const char *__nptr, char **__endptr, + locale_t __loc) { + return strtod(__nptr, __endptr); +} +static inline +long double strtold_l(const char *__nptr, char **__endptr, + locale_t __loc) { + return strtold(__nptr, __endptr); +} + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/android/x86/include/v8/libc++/support/win32/limits_msvc_win32.h b/android/x86/include/v8/libc++/support/win32/limits_msvc_win32.h new file mode 100755 index 00000000..7bb83555 --- /dev/null +++ b/android/x86/include/v8/libc++/support/win32/limits_msvc_win32.h @@ -0,0 +1,71 @@ +// -*- C++ -*- +//===------------------ support/win32/limits_msvc_win32.h -----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H +#define _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H + +#if !defined(_LIBCPP_MSVCRT) +#error "This header complements the Microsoft C Runtime library, and should not be included otherwise." +#endif +#if defined(__clang__) +#error "This header should only be included when using Microsofts C1XX frontend" +#endif + +#include <limits.h> // CHAR_BIT +#include <float.h> // limit constants +#include <math.h> // HUGE_VAL +#include <ymath.h> // internal MSVC header providing the needed functionality + +#define __CHAR_BIT__ CHAR_BIT + +#define __FLT_MANT_DIG__ FLT_MANT_DIG +#define __FLT_DIG__ FLT_DIG +#define __FLT_RADIX__ FLT_RADIX +#define __FLT_MIN_EXP__ FLT_MIN_EXP +#define __FLT_MIN_10_EXP__ FLT_MIN_10_EXP +#define __FLT_MAX_EXP__ FLT_MAX_EXP +#define __FLT_MAX_10_EXP__ FLT_MAX_10_EXP +#define __FLT_MIN__ FLT_MIN +#define __FLT_MAX__ FLT_MAX +#define __FLT_EPSILON__ FLT_EPSILON +// predefined by MinGW GCC +#define __FLT_DENORM_MIN__ 1.40129846432481707092e-45F + +#define __DBL_MANT_DIG__ DBL_MANT_DIG +#define __DBL_DIG__ DBL_DIG +#define __DBL_RADIX__ DBL_RADIX +#define __DBL_MIN_EXP__ DBL_MIN_EXP +#define __DBL_MIN_10_EXP__ DBL_MIN_10_EXP +#define __DBL_MAX_EXP__ DBL_MAX_EXP +#define __DBL_MAX_10_EXP__ DBL_MAX_10_EXP +#define __DBL_MIN__ DBL_MIN +#define __DBL_MAX__ DBL_MAX +#define __DBL_EPSILON__ DBL_EPSILON +// predefined by MinGW GCC +#define __DBL_DENORM_MIN__ double(4.94065645841246544177e-324L) + +#define __LDBL_MANT_DIG__ LDBL_MANT_DIG +#define __LDBL_DIG__ LDBL_DIG +#define __LDBL_RADIX__ LDBL_RADIX +#define __LDBL_MIN_EXP__ LDBL_MIN_EXP +#define __LDBL_MIN_10_EXP__ LDBL_MIN_10_EXP +#define __LDBL_MAX_EXP__ LDBL_MAX_EXP +#define __LDBL_MAX_10_EXP__ LDBL_MAX_10_EXP +#define __LDBL_MIN__ LDBL_MIN +#define __LDBL_MAX__ LDBL_MAX +#define __LDBL_EPSILON__ LDBL_EPSILON +// predefined by MinGW GCC +#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L + +// __builtin replacements/workarounds +#define __builtin_huge_vall() _LInf._Long_double +#define __builtin_nanl(__dummmy) _LNan._Long_double +#define __builtin_nansl(__dummy) _LSnan._Long_double + +#endif // _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H diff --git a/android/x86/include/v8/libc++/support/win32/locale_win32.h b/android/x86/include/v8/libc++/support/win32/locale_win32.h new file mode 100755 index 00000000..0d03d834 --- /dev/null +++ b/android/x86/include/v8/libc++/support/win32/locale_win32.h @@ -0,0 +1,198 @@ +// -*- C++ -*- +//===--------------------- support/win32/locale_win32.h -------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H +#define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H + +#include <__config> +#include <stdio.h> +#include <xlocinfo.h> // _locale_t +#include <__nullptr> + +#define LC_COLLATE_MASK _M_COLLATE +#define LC_CTYPE_MASK _M_CTYPE +#define LC_MONETARY_MASK _M_MONETARY +#define LC_NUMERIC_MASK _M_NUMERIC +#define LC_TIME_MASK _M_TIME +#define LC_MESSAGES_MASK _M_MESSAGES +#define LC_ALL_MASK ( LC_COLLATE_MASK \ + | LC_CTYPE_MASK \ + | LC_MESSAGES_MASK \ + | LC_MONETARY_MASK \ + | LC_NUMERIC_MASK \ + | LC_TIME_MASK ) + +class locale_t { +public: + locale_t() + : __locale(nullptr), __locale_str(nullptr) {} + locale_t(std::nullptr_t) + : __locale(nullptr), __locale_str(nullptr) {} + locale_t(_locale_t __xlocale, const char* __xlocale_str) + : __locale(__xlocale), __locale_str(__xlocale_str) {} + + friend bool operator==(const locale_t& __left, const locale_t& __right) { + return __left.__locale == __right.__locale; + } + + friend bool operator==(const locale_t& __left, int __right) { + return __left.__locale == nullptr && __right == 0; + } + + friend bool operator==(const locale_t& __left, long long __right) { + return __left.__locale == nullptr && __right == 0; + } + + friend bool operator==(const locale_t& __left, std::nullptr_t) { + return __left.__locale == nullptr; + } + + friend bool operator==(int __left, const locale_t& __right) { + return __left == 0 && nullptr == __right.__locale; + } + + friend bool operator==(std::nullptr_t, const locale_t& __right) { + return nullptr == __right.__locale; + } + + friend bool operator!=(const locale_t& __left, const locale_t& __right) { + return !(__left == __right); + } + + friend bool operator!=(const locale_t& __left, int __right) { + return !(__left == __right); + } + + friend bool operator!=(const locale_t& __left, long long __right) { + return !(__left == __right); + } + + friend bool operator!=(const locale_t& __left, std::nullptr_t __right) { + return !(__left == __right); + } + + friend bool operator!=(int __left, const locale_t& __right) { + return !(__left == __right); + } + + friend bool operator!=(std::nullptr_t __left, const locale_t& __right) { + return !(__left == __right); + } + + operator bool() const { + return __locale != nullptr; + } + + const char* __get_locale() const { return __locale_str; } + + operator _locale_t() const { + return __locale; + } +private: + _locale_t __locale; + const char* __locale_str; +}; + +// Locale management functions +#define freelocale _free_locale +// FIXME: base currently unused. Needs manual work to construct the new locale +locale_t newlocale( int mask, const char * locale, locale_t base ); +// uselocale can't be implemented on Windows because Windows allows partial modification +// of thread-local locale and so _get_current_locale() returns a copy while uselocale does +// not create any copies. +// We can still implement raii even without uselocale though. + + +lconv *localeconv_l( locale_t loc ); +size_t mbrlen_l( const char *__restrict s, size_t n, + mbstate_t *__restrict ps, locale_t loc); +size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src, + size_t len, mbstate_t *__restrict ps, locale_t loc ); +size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps, + locale_t loc); +size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s, + size_t n, mbstate_t *__restrict ps, locale_t loc); +size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src, + size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc); +size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src, + size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc); +wint_t btowc_l( int c, locale_t loc ); +int wctob_l( wint_t c, locale_t loc ); + +decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ); + +// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+ +#define mbtowc_l _mbtowc_l +#define strtoll_l _strtoi64_l +#define strtoull_l _strtoui64_l +#define strtod_l _strtod_l +#if defined(_LIBCPP_MSVCRT) +#define strtof_l _strtof_l +#define strtold_l _strtold_l +#else +float strtof_l(const char*, char**, locale_t); +long double strtold_l(const char*, char**, locale_t); +#endif +inline _LIBCPP_INLINE_VISIBILITY +int +islower_l(int c, _locale_t loc) +{ + return _islower_l((int)c, loc); +} + +inline _LIBCPP_INLINE_VISIBILITY +int +isupper_l(int c, _locale_t loc) +{ + return _isupper_l((int)c, loc); +} + +#define isdigit_l _isdigit_l +#define isxdigit_l _isxdigit_l +#define strcoll_l _strcoll_l +#define strxfrm_l _strxfrm_l +#define wcscoll_l _wcscoll_l +#define wcsxfrm_l _wcsxfrm_l +#define toupper_l _toupper_l +#define tolower_l _tolower_l +#define iswspace_l _iswspace_l +#define iswprint_l _iswprint_l +#define iswcntrl_l _iswcntrl_l +#define iswupper_l _iswupper_l +#define iswlower_l _iswlower_l +#define iswalpha_l _iswalpha_l +#define iswdigit_l _iswdigit_l +#define iswpunct_l _iswpunct_l +#define iswxdigit_l _iswxdigit_l +#define towupper_l _towupper_l +#define towlower_l _towlower_l +#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800 +#define strftime_l( __s, __l, __f, __tm, __loc ) strftime( __s, __l, __f, __tm ) +#else +#define strftime_l _strftime_l +#endif +#define sscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ ) +#define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ ) +#define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ ) +#define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ ) +_LIBCPP_FUNC_VIS int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...); +_LIBCPP_FUNC_VIS int asprintf_l( char **ret, locale_t loc, const char *format, ... ); +_LIBCPP_FUNC_VIS int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap ); + +// not-so-pressing FIXME: use locale to determine blank characters +inline int isblank_l( int c, locale_t /*loc*/ ) +{ + return ( c == ' ' || c == '\t' ); +} +inline int iswblank_l( wint_t c, locale_t /*loc*/ ) +{ + return ( c == L' ' || c == L'\t' ); +} + +#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H diff --git a/android/x86/include/v8/libc++/support/xlocale/__nop_locale_mgmt.h b/android/x86/include/v8/libc++/support/xlocale/__nop_locale_mgmt.h new file mode 100755 index 00000000..f33d3894 --- /dev/null +++ b/android/x86/include/v8/libc++/support/xlocale/__nop_locale_mgmt.h @@ -0,0 +1,51 @@ +// -*- C++ -*- +//===------------ support/xlocale/__nop_locale_mgmt.h -----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H +#define _LIBCPP_SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H + +#ifdef __cplusplus +extern "C" { +#endif + +// Patch over lack of extended locale support +typedef void *locale_t; +static inline locale_t duplocale(locale_t) { + return NULL; +} + +static inline void freelocale(locale_t) { +} + +static inline locale_t newlocale(int, const char *, locale_t) { + return NULL; +} + +static inline locale_t uselocale(locale_t) { + return NULL; +} + +#define LC_COLLATE_MASK (1 << LC_COLLATE) +#define LC_CTYPE_MASK (1 << LC_CTYPE) +#define LC_MESSAGES_MASK (1 << LC_MESSAGES) +#define LC_MONETARY_MASK (1 << LC_MONETARY) +#define LC_NUMERIC_MASK (1 << LC_NUMERIC) +#define LC_TIME_MASK (1 << LC_TIME) +#define LC_ALL_MASK (LC_COLLATE_MASK|\ + LC_CTYPE_MASK|\ + LC_MONETARY_MASK|\ + LC_NUMERIC_MASK|\ + LC_TIME_MASK|\ + LC_MESSAGES_MASK) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _LIBCPP_SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H diff --git a/android/x86/include/v8/libc++/support/xlocale/__posix_l_fallback.h b/android/x86/include/v8/libc++/support/xlocale/__posix_l_fallback.h new file mode 100755 index 00000000..f3df6c46 --- /dev/null +++ b/android/x86/include/v8/libc++/support/xlocale/__posix_l_fallback.h @@ -0,0 +1,164 @@ +// -*- C++ -*- +//===--------------- support/xlocale/__posix_l_fallback.h -----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// These are reimplementations of some extended locale functions ( *_l ) that +// are normally part of POSIX. This shared implementation provides parts of the +// extended locale support for libc's that normally don't have any (like +// Android's bionic and Newlib). +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H +#define _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H + +#ifdef __cplusplus +extern "C" { +#endif + +inline _LIBCPP_INLINE_VISIBILITY int isalnum_l(int c, locale_t) { + return ::isalnum(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int isalpha_l(int c, locale_t) { + return ::isalpha(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int isblank_l(int c, locale_t) { + return ::isblank(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iscntrl_l(int c, locale_t) { + return ::iscntrl(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int isdigit_l(int c, locale_t) { + return ::isdigit(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int isgraph_l(int c, locale_t) { + return ::isgraph(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int islower_l(int c, locale_t) { + return ::islower(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int isprint_l(int c, locale_t) { + return ::isprint(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int ispunct_l(int c, locale_t) { + return ::ispunct(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int isspace_l(int c, locale_t) { + return ::isspace(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int isupper_l(int c, locale_t) { + return ::isupper(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int isxdigit_l(int c, locale_t) { + return ::isxdigit(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswalnum_l(wint_t c, locale_t) { + return ::iswalnum(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswalpha_l(wint_t c, locale_t) { + return ::iswalpha(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswblank_l(wint_t c, locale_t) { + return ::iswblank(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswcntrl_l(wint_t c, locale_t) { + return ::iswcntrl(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswdigit_l(wint_t c, locale_t) { + return ::iswdigit(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswgraph_l(wint_t c, locale_t) { + return ::iswgraph(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswlower_l(wint_t c, locale_t) { + return ::iswlower(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswprint_l(wint_t c, locale_t) { + return ::iswprint(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswpunct_l(wint_t c, locale_t) { + return ::iswpunct(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswspace_l(wint_t c, locale_t) { + return ::iswspace(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswupper_l(wint_t c, locale_t) { + return ::iswupper(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int iswxdigit_l(wint_t c, locale_t) { + return ::iswxdigit(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int toupper_l(int c, locale_t) { + return ::toupper(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int tolower_l(int c, locale_t) { + return ::tolower(c); +} + +inline _LIBCPP_INLINE_VISIBILITY wint_t towupper_l(wint_t c, locale_t) { + return ::towupper(c); +} + +inline _LIBCPP_INLINE_VISIBILITY wint_t towlower_l(wint_t c, locale_t) { + return ::towlower(c); +} + +inline _LIBCPP_INLINE_VISIBILITY int strcoll_l(const char *s1, const char *s2, + locale_t) { + return ::strcoll(s1, s2); +} + +inline _LIBCPP_INLINE_VISIBILITY size_t strxfrm_l(char *dest, const char *src, + size_t n, locale_t) { + return ::strxfrm(dest, src, n); +} + +inline _LIBCPP_INLINE_VISIBILITY size_t strftime_l(char *s, size_t max, + const char *format, + const struct tm *tm, locale_t) { + return ::strftime(s, max, format, tm); +} + +inline _LIBCPP_INLINE_VISIBILITY int wcscoll_l(const wchar_t *ws1, + const wchar_t *ws2, locale_t) { + return ::wcscoll(ws1, ws2); +} + +inline _LIBCPP_INLINE_VISIBILITY size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src, + size_t n, locale_t) { + return ::wcsxfrm(dest, src, n); +} + +#ifdef __cplusplus +} +#endif + +#endif // _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H diff --git a/android/x86/include/v8/libc++/support/xlocale/__strtonum_fallback.h b/android/x86/include/v8/libc++/support/xlocale/__strtonum_fallback.h new file mode 100755 index 00000000..df385980 --- /dev/null +++ b/android/x86/include/v8/libc++/support/xlocale/__strtonum_fallback.h @@ -0,0 +1,66 @@ +// -*- C++ -*- +//===-------------- support/xlocale/__strtonum_fallback.h -----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// These are reimplementations of some extended locale functions ( *_l ) that +// aren't part of POSIX. They are widely available though (GLIBC, BSD, maybe +// others). The unifying aspect in this case is that all of these functions +// convert strings to some numeric type. +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_XLOCALE_STRTONUM_FALLBACK_H +#define _LIBCPP_SUPPORT_XLOCALE_STRTONUM_FALLBACK_H + +#ifdef __cplusplus +extern "C" { +#endif + +inline _LIBCPP_INLINE_VISIBILITY float strtof_l(const char *nptr, + char **endptr, locale_t) { + return ::strtof(nptr, endptr); +} + +inline _LIBCPP_INLINE_VISIBILITY double strtod_l(const char *nptr, + char **endptr, locale_t) { + return ::strtod(nptr, endptr); +} + +inline _LIBCPP_INLINE_VISIBILITY long double strtold_l(const char *nptr, + char **endptr, locale_t) { + return ::strtold(nptr, endptr); +} + +inline _LIBCPP_INLINE_VISIBILITY long long +strtoll_l(const char *nptr, char **endptr, int base, locale_t) { + return ::strtoll(nptr, endptr, base); +} + +inline _LIBCPP_INLINE_VISIBILITY unsigned long long +strtoull_l(const char *nptr, char **endptr, int base, locale_t) { + return ::strtoull(nptr, endptr, base); +} + +inline _LIBCPP_INLINE_VISIBILITY long long +wcstoll_l(const wchar_t *nptr, wchar_t **endptr, int base, locale_t) { + return ::wcstoll(nptr, endptr, base); +} + +inline _LIBCPP_INLINE_VISIBILITY unsigned long long +wcstoull_l(const wchar_t *nptr, wchar_t **endptr, int base, locale_t) { + return ::wcstoull(nptr, endptr, base); +} + +inline _LIBCPP_INLINE_VISIBILITY long double wcstold_l(const wchar_t *nptr, + wchar_t **endptr, locale_t) { + return ::wcstold(nptr, endptr); +} + +#ifdef __cplusplus +} +#endif + +#endif // _LIBCPP_SUPPORT_XLOCALE_STRTONUM_FALLBACK_H diff --git a/android/x86/include/v8/libc++/system_error b/android/x86/include/v8/libc++/system_error new file mode 100755 index 00000000..05ef0795 --- /dev/null +++ b/android/x86/include/v8/libc++/system_error @@ -0,0 +1,486 @@ +// -*- C++ -*- +//===---------------------------- system_error ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SYSTEM_ERROR +#define _LIBCPP_SYSTEM_ERROR + +/* + system_error synopsis + +namespace std +{ + +class error_category +{ +public: + virtual ~error_category() noexcept; + + constexpr error_category(); + error_category(const error_category&) = delete; + error_category& operator=(const error_category&) = delete; + + virtual const char* name() const noexcept = 0; + virtual error_condition default_error_condition(int ev) const noexcept; + virtual bool equivalent(int code, const error_condition& condition) const noexcept; + virtual bool equivalent(const error_code& code, int condition) const noexcept; + virtual string message(int ev) const = 0; + + bool operator==(const error_category& rhs) const noexcept; + bool operator!=(const error_category& rhs) const noexcept; + bool operator<(const error_category& rhs) const noexcept; +}; + +const error_category& generic_category() noexcept; +const error_category& system_category() noexcept; + +template <class T> struct is_error_code_enum + : public false_type {}; + +template <class T> struct is_error_condition_enum + : public false_type {}; + +template <class _Tp> +inline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17 + +template <class _Tp> +inline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17 + +class error_code +{ +public: + // constructors: + error_code() noexcept; + error_code(int val, const error_category& cat) noexcept; + template <class ErrorCodeEnum> + error_code(ErrorCodeEnum e) noexcept; + + // modifiers: + void assign(int val, const error_category& cat) noexcept; + template <class ErrorCodeEnum> + error_code& operator=(ErrorCodeEnum e) noexcept; + void clear() noexcept; + + // observers: + int value() const noexcept; + const error_category& category() const noexcept; + error_condition default_error_condition() const noexcept; + string message() const; + explicit operator bool() const noexcept; +}; + +// non-member functions: +bool operator<(const error_code& lhs, const error_code& rhs) noexcept; +template <class charT, class traits> + basic_ostream<charT,traits>& + operator<<(basic_ostream<charT,traits>& os, const error_code& ec); + +class error_condition +{ +public: + // constructors: + error_condition() noexcept; + error_condition(int val, const error_category& cat) noexcept; + template <class ErrorConditionEnum> + error_condition(ErrorConditionEnum e) noexcept; + + // modifiers: + void assign(int val, const error_category& cat) noexcept; + template <class ErrorConditionEnum> + error_condition& operator=(ErrorConditionEnum e) noexcept; + void clear() noexcept; + + // observers: + int value() const noexcept; + const error_category& category() const noexcept; + string message() const noexcept; + explicit operator bool() const noexcept; +}; + +bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept; + +class system_error + : public runtime_error +{ +public: + system_error(error_code ec, const string& what_arg); + system_error(error_code ec, const char* what_arg); + system_error(error_code ec); + system_error(int ev, const error_category& ecat, const string& what_arg); + system_error(int ev, const error_category& ecat, const char* what_arg); + system_error(int ev, const error_category& ecat); + + const error_code& code() const noexcept; + const char* what() const noexcept; +}; + +template <> struct is_error_condition_enum<errc> + : true_type { } + +error_code make_error_code(errc e) noexcept; +error_condition make_error_condition(errc e) noexcept; + +// Comparison operators: +bool operator==(const error_code& lhs, const error_code& rhs) noexcept; +bool operator==(const error_code& lhs, const error_condition& rhs) noexcept; +bool operator==(const error_condition& lhs, const error_code& rhs) noexcept; +bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept; +bool operator!=(const error_code& lhs, const error_code& rhs) noexcept; +bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept; +bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept; +bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept; + +template <> struct hash<std::error_code>; +template <> struct hash<std::error_condition>; + +} // std + +*/ + +#include <__errc> +#include <type_traits> +#include <stdexcept> +#include <__functional_base> +#include <string> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// is_error_code_enum + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum + : public false_type {}; + +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; +#endif + +// is_error_condition_enum + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum + : public false_type {}; + +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; +#endif + +template <> +struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc> + : true_type { }; + +#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS +template <> +struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx> + : true_type { }; +#endif + +class _LIBCPP_TYPE_VIS error_condition; +class _LIBCPP_TYPE_VIS error_code; + +// class error_category + +class _LIBCPP_HIDDEN __do_message; + +class _LIBCPP_TYPE_VIS error_category +{ +public: + virtual ~error_category() _NOEXCEPT; + +#if defined(_LIBCPP_BUILDING_LIBRARY) && \ + defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) + error_category() _NOEXCEPT; +#else + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT +#endif +private: + error_category(const error_category&);// = delete; + error_category& operator=(const error_category&);// = delete; + +public: + virtual const char* name() const _NOEXCEPT = 0; + virtual error_condition default_error_condition(int __ev) const _NOEXCEPT; + virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT; + virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT; + virtual string message(int __ev) const = 0; + + _LIBCPP_INLINE_VISIBILITY + bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;} + + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);} + + _LIBCPP_INLINE_VISIBILITY + bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;} + + friend class _LIBCPP_HIDDEN __do_message; +}; + +class _LIBCPP_HIDDEN __do_message + : public error_category +{ +public: + virtual string message(int ev) const; +}; + +_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT; +_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT; + +class _LIBCPP_TYPE_VIS error_condition +{ + int __val_; + const error_category* __cat_; +public: + _LIBCPP_INLINE_VISIBILITY + error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {} + + _LIBCPP_INLINE_VISIBILITY + error_condition(int __val, const error_category& __cat) _NOEXCEPT + : __val_(__val), __cat_(&__cat) {} + + template <class _Ep> + _LIBCPP_INLINE_VISIBILITY + error_condition(_Ep __e, + typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0 + ) _NOEXCEPT + {*this = make_error_condition(__e);} + + _LIBCPP_INLINE_VISIBILITY + void assign(int __val, const error_category& __cat) _NOEXCEPT + { + __val_ = __val; + __cat_ = &__cat; + } + + template <class _Ep> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + is_error_condition_enum<_Ep>::value, + error_condition& + >::type + operator=(_Ep __e) _NOEXCEPT + {*this = make_error_condition(__e); return *this;} + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT + { + __val_ = 0; + __cat_ = &generic_category(); + } + + _LIBCPP_INLINE_VISIBILITY + int value() const _NOEXCEPT {return __val_;} + + _LIBCPP_INLINE_VISIBILITY + const error_category& category() const _NOEXCEPT {return *__cat_;} + string message() const; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT + operator bool() const _NOEXCEPT {return __val_ != 0;} +}; + +inline _LIBCPP_INLINE_VISIBILITY +error_condition +make_error_condition(errc __e) _NOEXCEPT +{ + return error_condition(static_cast<int>(__e), generic_category()); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT +{ + return __x.category() < __y.category() + || (__x.category() == __y.category() && __x.value() < __y.value()); +} + +// error_code + +class _LIBCPP_TYPE_VIS error_code +{ + int __val_; + const error_category* __cat_; +public: + _LIBCPP_INLINE_VISIBILITY + error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {} + + _LIBCPP_INLINE_VISIBILITY + error_code(int __val, const error_category& __cat) _NOEXCEPT + : __val_(__val), __cat_(&__cat) {} + + template <class _Ep> + _LIBCPP_INLINE_VISIBILITY + error_code(_Ep __e, + typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0 + ) _NOEXCEPT + {*this = make_error_code(__e);} + + _LIBCPP_INLINE_VISIBILITY + void assign(int __val, const error_category& __cat) _NOEXCEPT + { + __val_ = __val; + __cat_ = &__cat; + } + + template <class _Ep> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + is_error_code_enum<_Ep>::value, + error_code& + >::type + operator=(_Ep __e) _NOEXCEPT + {*this = make_error_code(__e); return *this;} + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT + { + __val_ = 0; + __cat_ = &system_category(); + } + + _LIBCPP_INLINE_VISIBILITY + int value() const _NOEXCEPT {return __val_;} + + _LIBCPP_INLINE_VISIBILITY + const error_category& category() const _NOEXCEPT {return *__cat_;} + + _LIBCPP_INLINE_VISIBILITY + error_condition default_error_condition() const _NOEXCEPT + {return __cat_->default_error_condition(__val_);} + + string message() const; + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT + operator bool() const _NOEXCEPT {return __val_ != 0;} +}; + +inline _LIBCPP_INLINE_VISIBILITY +error_code +make_error_code(errc __e) _NOEXCEPT +{ + return error_code(static_cast<int>(__e), generic_category()); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const error_code& __x, const error_code& __y) _NOEXCEPT +{ + return __x.category() < __y.category() + || (__x.category() == __y.category() && __x.value() < __y.value()); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const error_code& __x, const error_code& __y) _NOEXCEPT +{ + return __x.category() == __y.category() && __x.value() == __y.value(); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT +{ + return __x.category().equivalent(__x.value(), __y) + || __y.category().equivalent(__x, __y.value()); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT +{ + return __y == __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT +{ + return __x.category() == __y.category() && __x.value() == __y.value(); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT +{return !(__x == __y);} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT +{return !(__x == __y);} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT +{return !(__x == __y);} + +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT +{return !(__x == __y);} + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<error_code> + : public unary_function<error_code, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const error_code& __ec) const _NOEXCEPT + { + return static_cast<size_t>(__ec.value()); + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<error_condition> + : public unary_function<error_condition, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const error_condition& __ec) const _NOEXCEPT + { + return static_cast<size_t>(__ec.value()); + } +}; + +// system_error + +class _LIBCPP_TYPE_VIS system_error + : public runtime_error +{ + error_code __ec_; +public: + system_error(error_code __ec, const string& __what_arg); + system_error(error_code __ec, const char* __what_arg); + system_error(error_code __ec); + system_error(int __ev, const error_category& __ecat, const string& __what_arg); + system_error(int __ev, const error_category& __ecat, const char* __what_arg); + system_error(int __ev, const error_category& __ecat); + ~system_error() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + const error_code& code() const _NOEXCEPT {return __ec_;} + +private: + static string __init(const error_code&, string); +}; + +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS +void __throw_system_error(int ev, const char* what_arg); + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_SYSTEM_ERROR diff --git a/android/x86/include/v8/libc++/tgmath.h b/android/x86/include/v8/libc++/tgmath.h new file mode 100755 index 00000000..2dc1f771 --- /dev/null +++ b/android/x86/include/v8/libc++/tgmath.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===-------------------------- tgmath.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_TGMATH_H +#define _LIBCPP_TGMATH_H + +/* + tgmath.h synopsis + +#include <ctgmath> + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef __cplusplus + +#include <ctgmath> + +#else // __cplusplus + +#include_next <tgmath.h> + +#endif // __cplusplus + +#endif // _LIBCPP_TGMATH_H diff --git a/android/x86/include/v8/libc++/thread b/android/x86/include/v8/libc++/thread new file mode 100755 index 00000000..3d8d2ac9 --- /dev/null +++ b/android/x86/include/v8/libc++/thread @@ -0,0 +1,488 @@ +// -*- C++ -*- +//===--------------------------- thread -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_THREAD +#define _LIBCPP_THREAD + +/* + + thread synopsis + +#define __STDCPP_THREADS__ __cplusplus + +namespace std +{ + +class thread +{ +public: + class id; + typedef pthread_t native_handle_type; + + thread() noexcept; + template <class F, class ...Args> explicit thread(F&& f, Args&&... args); + ~thread(); + + thread(const thread&) = delete; + thread(thread&& t) noexcept; + + thread& operator=(const thread&) = delete; + thread& operator=(thread&& t) noexcept; + + void swap(thread& t) noexcept; + + bool joinable() const noexcept; + void join(); + void detach(); + id get_id() const noexcept; + native_handle_type native_handle(); + + static unsigned hardware_concurrency() noexcept; +}; + +void swap(thread& x, thread& y) noexcept; + +class thread::id +{ +public: + id() noexcept; +}; + +bool operator==(thread::id x, thread::id y) noexcept; +bool operator!=(thread::id x, thread::id y) noexcept; +bool operator< (thread::id x, thread::id y) noexcept; +bool operator<=(thread::id x, thread::id y) noexcept; +bool operator> (thread::id x, thread::id y) noexcept; +bool operator>=(thread::id x, thread::id y) noexcept; + +template<class charT, class traits> +basic_ostream<charT, traits>& +operator<<(basic_ostream<charT, traits>& out, thread::id id); + +namespace this_thread +{ + +thread::id get_id() noexcept; + +void yield() noexcept; + +template <class Clock, class Duration> +void sleep_until(const chrono::time_point<Clock, Duration>& abs_time); + +template <class Rep, class Period> +void sleep_for(const chrono::duration<Rep, Period>& rel_time); + +} // this_thread + +} // std + +*/ + +#include <__config> +#include <iosfwd> +#include <__functional_base> +#include <type_traits> +#include <cstddef> +#include <functional> +#include <memory> +#include <system_error> +#include <chrono> +#include <__mutex_base> +#ifndef _LIBCPP_CXX03_LANG +#include <tuple> +#endif +#include <__threading_support> +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#define __STDCPP_THREADS__ __cplusplus + +#ifdef _LIBCPP_HAS_NO_THREADS +#error <thread> is not supported on this single threaded system +#else // !_LIBCPP_HAS_NO_THREADS + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> class __thread_specific_ptr; +class _LIBCPP_TYPE_VIS __thread_struct; +class _LIBCPP_HIDDEN __thread_struct_imp; +class __assoc_sub_state; + +_LIBCPP_FUNC_VIS __thread_specific_ptr<__thread_struct>& __thread_local_data(); + +class _LIBCPP_TYPE_VIS __thread_struct +{ + __thread_struct_imp* __p_; + + __thread_struct(const __thread_struct&); + __thread_struct& operator=(const __thread_struct&); +public: + __thread_struct(); + ~__thread_struct(); + + void notify_all_at_thread_exit(condition_variable*, mutex*); + void __make_ready_at_thread_exit(__assoc_sub_state*); +}; + +template <class _Tp> +class __thread_specific_ptr +{ + __libcpp_tls_key __key_; + + // Only __thread_local_data() may construct a __thread_specific_ptr + // and only with _Tp == __thread_struct. + static_assert((is_same<_Tp, __thread_struct>::value), ""); + __thread_specific_ptr(); + friend _LIBCPP_FUNC_VIS __thread_specific_ptr<__thread_struct>& __thread_local_data(); + + __thread_specific_ptr(const __thread_specific_ptr&); + __thread_specific_ptr& operator=(const __thread_specific_ptr&); + + _LIBCPP_HIDDEN static void _LIBCPP_TLS_DESTRUCTOR_CC __at_thread_exit(void*); + +public: + typedef _Tp* pointer; + + ~__thread_specific_ptr(); + + _LIBCPP_INLINE_VISIBILITY + pointer get() const {return static_cast<_Tp*>(__libcpp_tls_get(__key_));} + _LIBCPP_INLINE_VISIBILITY + pointer operator*() const {return *get();} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return get();} + void set_pointer(pointer __p); +}; + +template <class _Tp> +void _LIBCPP_TLS_DESTRUCTOR_CC +__thread_specific_ptr<_Tp>::__at_thread_exit(void* __p) +{ + delete static_cast<pointer>(__p); +} + +template <class _Tp> +__thread_specific_ptr<_Tp>::__thread_specific_ptr() +{ + int __ec = + __libcpp_tls_create(&__key_, &__thread_specific_ptr::__at_thread_exit); + if (__ec) + __throw_system_error(__ec, "__thread_specific_ptr construction failed"); +} + +template <class _Tp> +__thread_specific_ptr<_Tp>::~__thread_specific_ptr() +{ + // __thread_specific_ptr is only created with a static storage duration + // so this destructor is only invoked during program termination. Invoking + // pthread_key_delete(__key_) may prevent other threads from deleting their + // thread local data. For this reason we leak the key. +} + +template <class _Tp> +void +__thread_specific_ptr<_Tp>::set_pointer(pointer __p) +{ + _LIBCPP_ASSERT(get() == nullptr, + "Attempting to overwrite thread local data"); + __libcpp_tls_set(__key_, __p); +} + +class _LIBCPP_TYPE_VIS thread; +class _LIBCPP_TYPE_VIS __thread_id; + +namespace this_thread +{ + +_LIBCPP_INLINE_VISIBILITY __thread_id get_id() _NOEXCEPT; + +} // this_thread + +template<> struct hash<__thread_id>; + +class _LIBCPP_TEMPLATE_VIS __thread_id +{ + // FIXME: pthread_t is a pointer on Darwin but a long on Linux. + // NULL is the no-thread value on Darwin. Someone needs to check + // on other platforms. We assume 0 works everywhere for now. + __libcpp_thread_id __id_; + +public: + _LIBCPP_INLINE_VISIBILITY + __thread_id() _NOEXCEPT : __id_(0) {} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT + {return __libcpp_thread_id_equal(__x.__id_, __y.__id_);} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(__thread_id __x, __thread_id __y) _NOEXCEPT + {return !(__x == __y);} + friend _LIBCPP_INLINE_VISIBILITY + bool operator< (__thread_id __x, __thread_id __y) _NOEXCEPT + {return __libcpp_thread_id_less(__x.__id_, __y.__id_);} + friend _LIBCPP_INLINE_VISIBILITY + bool operator<=(__thread_id __x, __thread_id __y) _NOEXCEPT + {return !(__y < __x);} + friend _LIBCPP_INLINE_VISIBILITY + bool operator> (__thread_id __x, __thread_id __y) _NOEXCEPT + {return __y < __x ;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator>=(__thread_id __x, __thread_id __y) _NOEXCEPT + {return !(__x < __y);} + + template<class _CharT, class _Traits> + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id) + {return __os << __id.__id_;} + +private: + _LIBCPP_INLINE_VISIBILITY + __thread_id(__libcpp_thread_id __id) : __id_(__id) {} + + friend __thread_id this_thread::get_id() _NOEXCEPT; + friend class _LIBCPP_TYPE_VIS thread; + friend struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>; +}; + +template<> +struct _LIBCPP_TEMPLATE_VIS hash<__thread_id> + : public unary_function<__thread_id, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(__thread_id __v) const _NOEXCEPT + { + return hash<__libcpp_thread_id>()(__v.__id_); + } +}; + +namespace this_thread +{ + +inline _LIBCPP_INLINE_VISIBILITY +__thread_id +get_id() _NOEXCEPT +{ + return __libcpp_thread_get_current_id(); +} + +} // this_thread + +class _LIBCPP_TYPE_VIS thread +{ + __libcpp_thread_t __t_; + + thread(const thread&); + thread& operator=(const thread&); +public: + typedef __thread_id id; + typedef __libcpp_thread_t native_handle_type; + + _LIBCPP_INLINE_VISIBILITY + thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {} +#ifndef _LIBCPP_CXX03_LANG + template <class _Fp, class ..._Args, + class = typename enable_if + < + !is_same<typename __uncvref<_Fp>::type, thread>::value + >::type + > + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + explicit thread(_Fp&& __f, _Args&&... __args); +#else // _LIBCPP_CXX03_LANG + template <class _Fp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + explicit thread(_Fp __f); +#endif + ~thread(); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {__t.__t_ = _LIBCPP_NULL_THREAD;} + _LIBCPP_INLINE_VISIBILITY + thread& operator=(thread&& __t) _NOEXCEPT; +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + void swap(thread& __t) _NOEXCEPT {_VSTD::swap(__t_, __t.__t_);} + + _LIBCPP_INLINE_VISIBILITY + bool joinable() const _NOEXCEPT {return !__libcpp_thread_isnull(&__t_);} + void join(); + void detach(); + _LIBCPP_INLINE_VISIBILITY + id get_id() const _NOEXCEPT {return __libcpp_thread_get_id(&__t_);} + _LIBCPP_INLINE_VISIBILITY + native_handle_type native_handle() _NOEXCEPT {return __t_;} + + static unsigned hardware_concurrency() _NOEXCEPT; +}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _TSp, class _Fp, class ..._Args, size_t ..._Indices> +inline _LIBCPP_INLINE_VISIBILITY +void +__thread_execute(tuple<_TSp, _Fp, _Args...>& __t, __tuple_indices<_Indices...>) +{ + __invoke(_VSTD::move(_VSTD::get<1>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...); +} + +template <class _Fp> +void* __thread_proxy(void* __vp) +{ + // _Fp = std::tuple< unique_ptr<__thread_struct>, Functor, Args...> + std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp)); + __thread_local_data().set_pointer(_VSTD::get<0>(*__p).release()); + typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 2>::type _Index; + __thread_execute(*__p, _Index()); + return nullptr; +} + +template <class _Fp, class ..._Args, + class + > +thread::thread(_Fp&& __f, _Args&&... __args) +{ + typedef unique_ptr<__thread_struct> _TSPtr; + _TSPtr __tsp(new __thread_struct); + typedef tuple<_TSPtr, typename decay<_Fp>::type, typename decay<_Args>::type...> _Gp; + _VSTD::unique_ptr<_Gp> __p( + new _Gp(std::move(__tsp), + __decay_copy(_VSTD::forward<_Fp>(__f)), + __decay_copy(_VSTD::forward<_Args>(__args))...)); + int __ec = __libcpp_thread_create(&__t_, &__thread_proxy<_Gp>, __p.get()); + if (__ec == 0) + __p.release(); + else + __throw_system_error(__ec, "thread constructor failed"); +} + +inline +thread& +thread::operator=(thread&& __t) _NOEXCEPT +{ + if (!__libcpp_thread_isnull(&__t_)) + terminate(); + __t_ = __t.__t_; + __t.__t_ = _LIBCPP_NULL_THREAD; + return *this; +} + +#else // _LIBCPP_CXX03_LANG + +template <class _Fp> +struct __thread_invoke_pair { + // This type is used to pass memory for thread local storage and a functor + // to a newly created thread because std::pair doesn't work with + // std::unique_ptr in C++03. + __thread_invoke_pair(_Fp& __f) : __tsp_(new __thread_struct), __fn_(__f) {} + unique_ptr<__thread_struct> __tsp_; + _Fp __fn_; +}; + +template <class _Fp> +void* __thread_proxy_cxx03(void* __vp) +{ + std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp)); + __thread_local_data().set_pointer(__p->__tsp_.release()); + (__p->__fn_)(); + return nullptr; +} + +template <class _Fp> +thread::thread(_Fp __f) +{ + + typedef __thread_invoke_pair<_Fp> _InvokePair; + typedef std::unique_ptr<_InvokePair> _PairPtr; + _PairPtr __pp(new _InvokePair(__f)); + int __ec = __libcpp_thread_create(&__t_, &__thread_proxy_cxx03<_InvokePair>, __pp.get()); + if (__ec == 0) + __pp.release(); + else + __throw_system_error(__ec, "thread constructor failed"); +} + +#endif // _LIBCPP_CXX03_LANG + +inline _LIBCPP_INLINE_VISIBILITY +void swap(thread& __x, thread& __y) _NOEXCEPT {__x.swap(__y);} + +namespace this_thread +{ + +_LIBCPP_FUNC_VIS void sleep_for(const chrono::nanoseconds& __ns); + +template <class _Rep, class _Period> +void +sleep_for(const chrono::duration<_Rep, _Period>& __d) +{ + using namespace chrono; + if (__d > duration<_Rep, _Period>::zero()) + { +#if defined(_LIBCPP_COMPILER_GCC) && (__powerpc__ || __POWERPC__) + // GCC's long double const folding is incomplete for IBM128 long doubles. + _LIBCPP_CONSTEXPR duration<long double> _Max = nanoseconds::max(); +#else + _LIBCPP_CONSTEXPR duration<long double> _Max = duration<long double>(ULLONG_MAX/1000000000ULL) ; +#endif + nanoseconds __ns; + if (__d < _Max) + { + __ns = duration_cast<nanoseconds>(__d); + if (__ns < __d) + ++__ns; + } + else + __ns = nanoseconds::max(); + sleep_for(__ns); + } +} + +template <class _Clock, class _Duration> +void +sleep_until(const chrono::time_point<_Clock, _Duration>& __t) +{ + using namespace chrono; + mutex __mut; + condition_variable __cv; + unique_lock<mutex> __lk(__mut); + while (_Clock::now() < __t) + __cv.wait_until(__lk, __t); +} + +template <class _Duration> +inline _LIBCPP_INLINE_VISIBILITY +void +sleep_until(const chrono::time_point<chrono::steady_clock, _Duration>& __t) +{ + using namespace chrono; + sleep_for(__t - steady_clock::now()); +} + +inline _LIBCPP_INLINE_VISIBILITY +void yield() _NOEXCEPT {__libcpp_thread_yield();} + +} // this_thread + +_LIBCPP_END_NAMESPACE_STD + +#endif // !_LIBCPP_HAS_NO_THREADS + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_THREAD diff --git a/android/x86/include/v8/libc++/tuple b/android/x86/include/v8/libc++/tuple new file mode 100755 index 00000000..335e59e6 --- /dev/null +++ b/android/x86/include/v8/libc++/tuple @@ -0,0 +1,1396 @@ +// -*- C++ -*- +//===--------------------------- tuple ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_TUPLE +#define _LIBCPP_TUPLE + +/* + tuple synopsis + +namespace std +{ + +template <class... T> +class tuple { +public: + constexpr tuple(); + explicit tuple(const T&...); // constexpr in C++14 + template <class... U> + explicit tuple(U&&...); // constexpr in C++14 + tuple(const tuple&) = default; + tuple(tuple&&) = default; + template <class... U> + tuple(const tuple<U...>&); // constexpr in C++14 + template <class... U> + tuple(tuple<U...>&&); // constexpr in C++14 + template <class U1, class U2> + tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14 + template <class U1, class U2> + tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14 + + // allocator-extended constructors + template <class Alloc> + tuple(allocator_arg_t, const Alloc& a); + template <class Alloc> + tuple(allocator_arg_t, const Alloc& a, const T&...); + template <class Alloc, class... U> + tuple(allocator_arg_t, const Alloc& a, U&&...); + template <class Alloc> + tuple(allocator_arg_t, const Alloc& a, const tuple&); + template <class Alloc> + tuple(allocator_arg_t, const Alloc& a, tuple&&); + template <class Alloc, class... U> + tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); + template <class Alloc, class... U> + tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); + template <class Alloc, class U1, class U2> + tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); + template <class Alloc, class U1, class U2> + tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); + + tuple& operator=(const tuple&); + tuple& + operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...)); + template <class... U> + tuple& operator=(const tuple<U...>&); + template <class... U> + tuple& operator=(tuple<U...>&&); + template <class U1, class U2> + tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 + template <class U1, class U2> + tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 + + void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); +}; + +inline constexpr unspecified ignore; + +template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14 +template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14 +template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14 +template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14 + +// [tuple.apply], calling a function with a tuple of arguments: +template <class F, class Tuple> + constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17 +template <class T, class Tuple> + constexpr T make_from_tuple(Tuple&& t); // C++17 + +// 20.4.1.4, tuple helper classes: +template <class T> struct tuple_size; // undefined +template <class... T> struct tuple_size<tuple<T...>>; +template <class T> + inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17 +template <size_t I, class T> struct tuple_element; // undefined +template <size_t I, class... T> struct tuple_element<I, tuple<T...>>; +template <size_t I, class T> + using tuple_element_t = typename tuple_element <I, T>::type; // C++14 + +// 20.4.1.5, element access: +template <size_t I, class... T> + typename tuple_element<I, tuple<T...>>::type& + get(tuple<T...>&) noexcept; // constexpr in C++14 +template <size_t I, class... T> + const typename tuple_element<I, tuple<T...>>::type& + get(const tuple<T...>&) noexcept; // constexpr in C++14 +template <size_t I, class... T> + typename tuple_element<I, tuple<T...>>::type&& + get(tuple<T...>&&) noexcept; // constexpr in C++14 +template <size_t I, class... T> + const typename tuple_element<I, tuple<T...>>::type&& + get(const tuple<T...>&&) noexcept; // constexpr in C++14 + +template <class T1, class... T> + constexpr T1& get(tuple<T...>&) noexcept; // C++14 +template <class T1, class... T> + constexpr const T1& get(const tuple<T...>&) noexcept; // C++14 +template <class T1, class... T> + constexpr T1&& get(tuple<T...>&&) noexcept; // C++14 +template <class T1, class... T> + constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14 + +// 20.4.1.6, relational operators: +template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 + +template <class... Types, class Alloc> + struct uses_allocator<tuple<Types...>, Alloc>; + +template <class... Types> + void + swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#include <__config> +#include <__tuple> +#include <cstddef> +#include <type_traits> +#include <__functional_base> +#include <utility> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + + +// __tuple_leaf + +template <size_t _Ip, class _Hp, + bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value + > +class __tuple_leaf; + +template <size_t _Ip, class _Hp, bool _Ep> +inline _LIBCPP_INLINE_VISIBILITY +void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) + _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value) +{ + swap(__x.get(), __y.get()); +} + +template <size_t _Ip, class _Hp, bool> +class __tuple_leaf +{ + _Hp __value_; + + template <class _Tp> + static constexpr bool __can_bind_reference() { +#if __has_keyword(__reference_binds_to_temporary) + return !__reference_binds_to_temporary(_Hp, _Tp); +#else + return true; +#endif + } + + __tuple_leaf& operator=(const __tuple_leaf&); +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf() + _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_() + {static_assert(!is_reference<_Hp>::value, + "Attempted to default construct a reference element in a tuple");} + + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant<int, 0>, const _Alloc&) + : __value_() + {static_assert(!is_reference<_Hp>::value, + "Attempted to default construct a reference element in a tuple");} + + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) + : __value_(allocator_arg_t(), __a) + {static_assert(!is_reference<_Hp>::value, + "Attempted to default construct a reference element in a tuple");} + + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) + : __value_(__a) + {static_assert(!is_reference<_Hp>::value, + "Attempted to default construct a reference element in a tuple");} + + template <class _Tp, + class = typename enable_if< + __lazy_and< + __lazy_not<is_same<typename __uncvref<_Tp>::type, __tuple_leaf>> + , is_constructible<_Hp, _Tp> + >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) + : __value_(_VSTD::forward<_Tp>(__t)) + {static_assert(__can_bind_reference<_Tp&&>(), + "Attempted construction of reference element binds to a temporary whose lifetime has ended");} + + template <class _Tp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) + : __value_(_VSTD::forward<_Tp>(__t)) + {static_assert(__can_bind_reference<_Tp&&>(), + "Attempted construction of reference element binds to a temporary whose lifetime has ended");} + + template <class _Tp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) + : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) + {static_assert(!is_reference<_Hp>::value, + "Attempted to uses-allocator construct a reference element in a tuple");} + + template <class _Tp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) + : __value_(_VSTD::forward<_Tp>(__t), __a) + {static_assert(!is_reference<_Hp>::value, + "Attempted to uses-allocator construct a reference element in a tuple");} + + __tuple_leaf(const __tuple_leaf& __t) = default; + __tuple_leaf(__tuple_leaf&& __t) = default; + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf& + operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value)) + { + __value_ = _VSTD::forward<_Tp>(__t); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value) + { + _VSTD::swap(*this, __t); + return 0; + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;} +}; + +template <size_t _Ip, class _Hp> +class __tuple_leaf<_Ip, _Hp, true> + : private _Hp +{ + + __tuple_leaf& operator=(const __tuple_leaf&); +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf() + _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {} + + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {} + + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) + : _Hp(allocator_arg_t(), __a) {} + + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) + : _Hp(__a) {} + + template <class _Tp, + class = typename enable_if< + __lazy_and< + __lazy_not<is_same<typename __uncvref<_Tp>::type, __tuple_leaf>> + , is_constructible<_Hp, _Tp> + >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) + : _Hp(_VSTD::forward<_Tp>(__t)) {} + + template <class _Tp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) + : _Hp(_VSTD::forward<_Tp>(__t)) {} + + template <class _Tp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) + : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {} + + template <class _Tp, class _Alloc> + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) + : _Hp(_VSTD::forward<_Tp>(__t), __a) {} + + __tuple_leaf(__tuple_leaf const &) = default; + __tuple_leaf(__tuple_leaf &&) = default; + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf& + operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value)) + { + _Hp::operator=(_VSTD::forward<_Tp>(__t)); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + int + swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value) + { + _VSTD::swap(*this, __t); + return 0; + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);} +}; + +template <class ..._Tp> +_LIBCPP_INLINE_VISIBILITY +void __swallow(_Tp&&...) _NOEXCEPT {} + +template <class ..._Tp> +struct __lazy_all : __all<_Tp::value...> {}; + +template <class _Tp> +struct __all_default_constructible; + +template <class ..._Tp> +struct __all_default_constructible<__tuple_types<_Tp...>> + : __all<is_default_constructible<_Tp>::value...> +{ }; + +// __tuple_impl + +template<class _Indx, class ..._Tp> struct __tuple_impl; + +template<size_t ..._Indx, class ..._Tp> +struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...> + : public __tuple_leaf<_Indx, _Tp>... +{ + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __tuple_impl() + _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} + + template <size_t ..._Uf, class ..._Tf, + size_t ..._Ul, class ..._Tl, class ..._Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit + __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>, + __tuple_indices<_Ul...>, __tuple_types<_Tl...>, + _Up&&... __u) + _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value && + __all<is_nothrow_default_constructible<_Tl>::value...>::value)) : + __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))..., + __tuple_leaf<_Ul, _Tl>()... + {} + + template <class _Alloc, size_t ..._Uf, class ..._Tf, + size_t ..._Ul, class ..._Tl, class ..._Up> + _LIBCPP_INLINE_VISIBILITY + explicit + __tuple_impl(allocator_arg_t, const _Alloc& __a, + __tuple_indices<_Uf...>, __tuple_types<_Tf...>, + __tuple_indices<_Ul...>, __tuple_types<_Tl...>, + _Up&&... __u) : + __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a, + _VSTD::forward<_Up>(__u))..., + __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)... + {} + + template <class _Tuple, + class = typename enable_if + < + __tuple_constructible<_Tuple, tuple<_Tp...> >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx, + typename __make_tuple_types<_Tuple>::type>::type>::value...>::value)) + : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx, + typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))... + {} + + template <class _Alloc, class _Tuple, + class = typename enable_if + < + __tuple_constructible<_Tuple, tuple<_Tp...> >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) + : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx, + typename __make_tuple_types<_Tuple>::type>::type>(), __a, + _VSTD::forward<typename tuple_element<_Indx, + typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))... + {} + + template <class _Tuple> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __tuple_assignable<_Tuple, tuple<_Tp...> >::value, + __tuple_impl& + >::type + operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx, + typename __make_tuple_types<_Tuple>::type>::type>::value...>::value)) + { + __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx, + typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...); + return *this; + } + + __tuple_impl(const __tuple_impl&) = default; + __tuple_impl(__tuple_impl&&) = default; + + _LIBCPP_INLINE_VISIBILITY + __tuple_impl& + operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value)) + { + __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __tuple_impl& + operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value)) + { + __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + void swap(__tuple_impl& __t) + _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) + { + __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...); + } +}; + + + +template <class ..._Tp> +class _LIBCPP_TEMPLATE_VIS tuple +{ + typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT; + + _BaseT __base_; + +#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION) + static constexpr bool _EnableImplicitReducedArityExtension = true; +#else + static constexpr bool _EnableImplicitReducedArityExtension = false; +#endif + + template <class ..._Args> + struct _PackExpandsToThisTuple : false_type {}; + + template <class _Arg> + struct _PackExpandsToThisTuple<_Arg> + : is_same<typename __uncvref<_Arg>::type, tuple> {}; + + template <bool _MaybeEnable, class _Dummy = void> + struct _CheckArgsConstructor : __check_tuple_constructor_fail {}; + + template <class _Dummy> + struct _CheckArgsConstructor<true, _Dummy> + { + template <class ..._Args> + static constexpr bool __enable_default() { + return __all<is_default_constructible<_Args>::value...>::value; + } + + template <class ..._Args> + static constexpr bool __enable_explicit() { + return + __tuple_constructible< + tuple<_Args...>, + typename __make_tuple_types<tuple, + sizeof...(_Args) < sizeof...(_Tp) ? + sizeof...(_Args) : + sizeof...(_Tp)>::type + >::value && + !__tuple_convertible< + tuple<_Args...>, + typename __make_tuple_types<tuple, + sizeof...(_Args) < sizeof...(_Tp) ? + sizeof...(_Args) : + sizeof...(_Tp)>::type + >::value && + __all_default_constructible< + typename __make_tuple_types<tuple, sizeof...(_Tp), + sizeof...(_Args) < sizeof...(_Tp) ? + sizeof...(_Args) : + sizeof...(_Tp)>::type + >::value; + } + + template <class ..._Args> + static constexpr bool __enable_implicit() { + return + __tuple_convertible< + tuple<_Args...>, + typename __make_tuple_types<tuple, + sizeof...(_Args) < sizeof...(_Tp) ? + sizeof...(_Args) : + sizeof...(_Tp)>::type + >::value && + __all_default_constructible< + typename __make_tuple_types<tuple, sizeof...(_Tp), + sizeof...(_Args) < sizeof...(_Tp) ? + sizeof...(_Args) : + sizeof...(_Tp)>::type + >::value; + } + }; + + template <bool _MaybeEnable, + bool = sizeof...(_Tp) == 1, + class _Dummy = void> + struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {}; + + template <class _Dummy> + struct _CheckTupleLikeConstructor<true, false, _Dummy> + { + template <class _Tuple> + static constexpr bool __enable_implicit() { + return __tuple_convertible<_Tuple, tuple>::value; + } + + template <class _Tuple> + static constexpr bool __enable_explicit() { + return __tuple_constructible<_Tuple, tuple>::value + && !__tuple_convertible<_Tuple, tuple>::value; + } + }; + + template <class _Dummy> + struct _CheckTupleLikeConstructor<true, true, _Dummy> + { + // This trait is used to disable the tuple-like constructor when + // the UTypes... constructor should be selected instead. + // See LWG issue #2549. + template <class _Tuple> + using _PreferTupleLikeConstructor = __lazy_or< + // Don't attempt the two checks below if the tuple we are given + // has the same type as this tuple. + is_same<typename __uncvref<_Tuple>::type, tuple>, + __lazy_and< + __lazy_not<is_constructible<_Tp..., _Tuple>>, + __lazy_not<is_convertible<_Tuple, _Tp...>> + > + >; + + template <class _Tuple> + static constexpr bool __enable_implicit() { + return __lazy_and< + __tuple_convertible<_Tuple, tuple>, + _PreferTupleLikeConstructor<_Tuple> + >::value; + } + + template <class _Tuple> + static constexpr bool __enable_explicit() { + return __lazy_and< + __tuple_constructible<_Tuple, tuple>, + _PreferTupleLikeConstructor<_Tuple>, + __lazy_not<__tuple_convertible<_Tuple, tuple>> + >::value; + } + }; + + template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 + typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT; + template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 + const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT; + template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 + typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT; + template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 + const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT; +public: + + template <bool _Dummy = true, class = typename enable_if< + _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>() + >::type> + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR tuple() + _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} + + tuple(tuple const&) = default; + tuple(tuple&&) = default; + + template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if< + __lazy_and< + is_same<allocator_arg_t, _AllocArgT>, + __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...> + >::value + >::type> + _LIBCPP_INLINE_VISIBILITY + tuple(_AllocArgT, _Alloc const& __a) + : __base_(allocator_arg_t(), __a, + __tuple_indices<>(), __tuple_types<>(), + typename __make_tuple_indices<sizeof...(_Tp), 0>::type(), + __tuple_types<_Tp...>()) {} + + template <bool _Dummy = true, + typename enable_if + < + _CheckArgsConstructor< + _Dummy + >::template __enable_implicit<_Tp const&...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) + : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), + typename __make_tuple_indices<0>::type(), + typename __make_tuple_types<tuple, 0>::type(), + __t... + ) {} + + template <bool _Dummy = true, + typename enable_if + < + _CheckArgsConstructor< + _Dummy + >::template __enable_explicit<_Tp const&...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) + : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), + typename __make_tuple_indices<0>::type(), + typename __make_tuple_types<tuple, 0>::type(), + __t... + ) {} + + template <class _Alloc, bool _Dummy = true, + typename enable_if + < + _CheckArgsConstructor< + _Dummy + >::template __enable_implicit<_Tp const&...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) + : __base_(allocator_arg_t(), __a, + typename __make_tuple_indices<sizeof...(_Tp)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), + typename __make_tuple_indices<0>::type(), + typename __make_tuple_types<tuple, 0>::type(), + __t... + ) {} + + template <class _Alloc, bool _Dummy = true, + typename enable_if + < + _CheckArgsConstructor< + _Dummy + >::template __enable_explicit<_Tp const&...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + explicit + tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) + : __base_(allocator_arg_t(), __a, + typename __make_tuple_indices<sizeof...(_Tp)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), + typename __make_tuple_indices<0>::type(), + typename __make_tuple_types<tuple, 0>::type(), + __t... + ) {} + + template <class ..._Up, + bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value, + typename enable_if + < + _CheckArgsConstructor< + sizeof...(_Up) == sizeof...(_Tp) + && !_PackIsTuple + >::template __enable_implicit<_Up...>() || + _CheckArgsConstructor< + _EnableImplicitReducedArityExtension + && sizeof...(_Up) < sizeof...(_Tp) + && !_PackIsTuple + >::template __enable_implicit<_Up...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + tuple(_Up&&... __u) + _NOEXCEPT_(( + is_nothrow_constructible<_BaseT, + typename __make_tuple_indices<sizeof...(_Up)>::type, + typename __make_tuple_types<tuple, sizeof...(_Up)>::type, + typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type, + typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type, + _Up... + >::value + )) + : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), + typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), + _VSTD::forward<_Up>(__u)...) {} + + template <class ..._Up, + typename enable_if + < + _CheckArgsConstructor< + sizeof...(_Up) <= sizeof...(_Tp) + && !_PackExpandsToThisTuple<_Up...>::value + >::template __enable_explicit<_Up...>() || + _CheckArgsConstructor< + !_EnableImplicitReducedArityExtension + && sizeof...(_Up) < sizeof...(_Tp) + && !_PackExpandsToThisTuple<_Up...>::value + >::template __enable_implicit<_Up...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit + tuple(_Up&&... __u) + _NOEXCEPT_(( + is_nothrow_constructible<_BaseT, + typename __make_tuple_indices<sizeof...(_Up)>::type, + typename __make_tuple_types<tuple, sizeof...(_Up)>::type, + typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type, + typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type, + _Up... + >::value + )) + : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), + typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), + _VSTD::forward<_Up>(__u)...) {} + + template <class _Alloc, class ..._Up, + typename enable_if + < + _CheckArgsConstructor< + sizeof...(_Up) == sizeof...(_Tp) && + !_PackExpandsToThisTuple<_Up...>::value + >::template __enable_implicit<_Up...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) + : __base_(allocator_arg_t(), __a, + typename __make_tuple_indices<sizeof...(_Up)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), + typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), + _VSTD::forward<_Up>(__u)...) {} + + template <class _Alloc, class ..._Up, + typename enable_if + < + _CheckArgsConstructor< + sizeof...(_Up) == sizeof...(_Tp) && + !_PackExpandsToThisTuple<_Up...>::value + >::template __enable_explicit<_Up...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + explicit + tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) + : __base_(allocator_arg_t(), __a, + typename __make_tuple_indices<sizeof...(_Up)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), + typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), + typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), + _VSTD::forward<_Up>(__u)...) {} + + template <class _Tuple, + typename enable_if + < + _CheckTupleLikeConstructor< + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + && !_PackExpandsToThisTuple<_Tuple>::value + >::template __enable_implicit<_Tuple>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value)) + : __base_(_VSTD::forward<_Tuple>(__t)) {} + + template <class _Tuple, + typename enable_if + < + _CheckTupleLikeConstructor< + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + && !_PackExpandsToThisTuple<_Tuple>::value + >::template __enable_explicit<_Tuple>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit + tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value)) + : __base_(_VSTD::forward<_Tuple>(__t)) {} + + template <class _Alloc, class _Tuple, + typename enable_if + < + _CheckTupleLikeConstructor< + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + >::template __enable_implicit<_Tuple>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) + : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} + + template <class _Alloc, class _Tuple, + typename enable_if + < + _CheckTupleLikeConstructor< + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + >::template __enable_explicit<_Tuple>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + explicit + tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) + : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} + + using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>; + using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>; + + _LIBCPP_INLINE_VISIBILITY + tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t) + _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value)) + { + __base_.operator=(__t.__base_); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t) + _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value)) + { + __base_.operator=(static_cast<_BaseT&&>(__t.__base_)); + return *this; + } + + template <class _Tuple, + class = typename enable_if + < + __tuple_assignable<_Tuple, tuple>::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + tuple& + operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value)) + { + __base_.operator=(_VSTD::forward<_Tuple>(__t)); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) + {__base_.swap(__t.__base_);} +}; + +template <> +class _LIBCPP_TEMPLATE_VIS tuple<> +{ +public: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {} + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {} + template <class _Alloc> + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + tuple(array<_Up, 0>) _NOEXCEPT {} + template <class _Alloc, class _Up> + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + void swap(tuple&) _NOEXCEPT {} +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +// NOTE: These are not yet standardized, but are required to simulate the +// implicit deduction guide that should be generated had libc++ declared the +// tuple-like constructors "correctly" +template <class _Alloc, class ..._Args> +tuple(allocator_arg_t, const _Alloc&, tuple<_Args...> const&) -> tuple<_Args...>; +template <class _Alloc, class ..._Args> +tuple(allocator_arg_t, const _Alloc&, tuple<_Args...>&&) -> tuple<_Args...>; +#endif + +template <class ..._Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __all<__is_swappable<_Tp>::value...>::value, + void +>::type +swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) + _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) + {__t.swap(__u);} + +// get + +template <size_t _Ip, class ..._Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(tuple<_Tp...>& __t) _NOEXCEPT +{ + typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get(); +} + +template <size_t _Ip, class ..._Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(const tuple<_Tp...>& __t) _NOEXCEPT +{ + typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get(); +} + +template <size_t _Ip, class ..._Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(tuple<_Tp...>&& __t) _NOEXCEPT +{ + typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + return static_cast<type&&>( + static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get()); +} + +template <size_t _Ip, class ..._Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(const tuple<_Tp...>&& __t) _NOEXCEPT +{ + typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + return static_cast<const type&&>( + static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get()); +} + +#if _LIBCPP_STD_VER > 11 + +namespace __find_detail { + +static constexpr size_t __not_found = -1; +static constexpr size_t __ambiguous = __not_found - 1; + +inline _LIBCPP_INLINE_VISIBILITY +constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) { + return !__matches ? __res : + (__res == __not_found ? __curr_i : __ambiguous); +} + +template <size_t _Nx> +inline _LIBCPP_INLINE_VISIBILITY +constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) { + return __i == _Nx ? __not_found : + __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]); +} + +template <class _T1, class ..._Args> +struct __find_exactly_one_checked { + static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...}; + static constexpr size_t value = __find_detail::__find_idx(0, __matches); + static_assert(value != __not_found, "type not found in type list" ); + static_assert(value != __ambiguous, "type occurs more than once in type list"); +}; + +template <class _T1> +struct __find_exactly_one_checked<_T1> { + static_assert(!is_same<_T1, _T1>::value, "type not in empty type list"); +}; + +} // namespace __find_detail; + +template <typename _T1, typename... _Args> +struct __find_exactly_one_t + : public __find_detail::__find_exactly_one_checked<_T1, _Args...> { +}; + +template <class _T1, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1& get(tuple<_Args...>& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); +} + +template <class _T1, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); +} + +template <class _T1, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup)); +} + +template <class _T1, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup)); +} + +#endif + +// tie + +template <class ..._Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple<_Tp&...> +tie(_Tp&... __t) _NOEXCEPT +{ + return tuple<_Tp&...>(__t...); +} + +template <class _Up> +struct __ignore_t +{ + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + const __ignore_t& operator=(_Tp&&) const {return *this;} +}; + +namespace { + _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); +} + +template <class... _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple<typename __unwrap_ref_decay<_Tp>::type...> +make_tuple(_Tp&&... __t) +{ + return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...); +} + +template <class... _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple<_Tp&&...> +forward_as_tuple(_Tp&&... __t) _NOEXCEPT +{ + return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...); +} + +template <size_t _Ip> +struct __tuple_equal +{ + template <class _Tp, class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _Tp& __x, const _Up& __y) + { + return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y); + } +}; + +template <> +struct __tuple_equal<0> +{ + template <class _Tp, class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _Tp&, const _Up&) + { + return true; + } +}; + +template <class ..._Tp, class ..._Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); + return __tuple_equal<sizeof...(_Tp)>()(__x, __y); +} + +template <class ..._Tp, class ..._Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return !(__x == __y); +} + +template <size_t _Ip> +struct __tuple_less +{ + template <class _Tp, class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _Tp& __x, const _Up& __y) + { + const size_t __idx = tuple_size<_Tp>::value - _Ip; + if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y)) + return true; + if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x)) + return false; + return __tuple_less<_Ip-1>()(__x, __y); + } +}; + +template <> +struct __tuple_less<0> +{ + template <class _Tp, class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _Tp&, const _Up&) + { + return false; + } +}; + +template <class ..._Tp, class ..._Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); + return __tuple_less<sizeof...(_Tp)>()(__x, __y); +} + +template <class ..._Tp, class ..._Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return __y < __x; +} + +template <class ..._Tp, class ..._Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return !(__x < __y); +} + +template <class ..._Tp, class ..._Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return !(__y < __x); +} + +// tuple_cat + +template <class _Tp, class _Up> struct __tuple_cat_type; + +template <class ..._Ttypes, class ..._Utypes> +struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> > +{ + typedef tuple<_Ttypes..., _Utypes...> type; +}; + +template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples> +struct __tuple_cat_return_1 +{ +}; + +template <class ..._Types, class _Tuple0> +struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0> +{ + typedef typename __tuple_cat_type<tuple<_Types...>, + typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type + type; +}; + +template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples> +struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...> + : public __tuple_cat_return_1< + typename __tuple_cat_type< + tuple<_Types...>, + typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type + >::type, + __tuple_like<typename remove_reference<_Tuple1>::type>::value, + _Tuple1, _Tuples...> +{ +}; + +template <class ..._Tuples> struct __tuple_cat_return; + +template <class _Tuple0, class ..._Tuples> +struct __tuple_cat_return<_Tuple0, _Tuples...> + : public __tuple_cat_return_1<tuple<>, + __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0, + _Tuples...> +{ +}; + +template <> +struct __tuple_cat_return<> +{ + typedef tuple<> type; +}; + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple<> +tuple_cat() +{ + return tuple<>(); +} + +template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples> +struct __tuple_cat_return_ref_imp; + +template <class ..._Types, size_t ..._I0, class _Tuple0> +struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0> +{ + typedef typename remove_reference<_Tuple0>::type _T0; + typedef tuple<_Types..., typename __apply_cv<_Tuple0, + typename tuple_element<_I0, _T0>::type>::type&&...> type; +}; + +template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples> +struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, + _Tuple0, _Tuple1, _Tuples...> + : public __tuple_cat_return_ref_imp< + tuple<_Types..., typename __apply_cv<_Tuple0, + typename tuple_element<_I0, + typename remove_reference<_Tuple0>::type>::type>::type&&...>, + typename __make_tuple_indices<tuple_size<typename + remove_reference<_Tuple1>::type>::value>::type, + _Tuple1, _Tuples...> +{ +}; + +template <class _Tuple0, class ..._Tuples> +struct __tuple_cat_return_ref + : public __tuple_cat_return_ref_imp<tuple<>, + typename __make_tuple_indices< + tuple_size<typename remove_reference<_Tuple0>::type>::value + >::type, _Tuple0, _Tuples...> +{ +}; + +template <class _Types, class _I0, class _J0> +struct __tuple_cat; + +template <class ..._Types, size_t ..._I0, size_t ..._J0> +struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> > +{ + template <class _Tuple0> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type + operator()(tuple<_Types...> __t, _Tuple0&& __t0) + { + return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))..., + _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...); + } + + template <class _Tuple0, class _Tuple1, class ..._Tuples> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type + operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls) + { + typedef typename remove_reference<_Tuple0>::type _T0; + typedef typename remove_reference<_Tuple1>::type _T1; + return __tuple_cat< + tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>, + typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type, + typename __make_tuple_indices<tuple_size<_T1>::value>::type>() + (forward_as_tuple( + _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))..., + _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))... + ), + _VSTD::forward<_Tuple1>(__t1), + _VSTD::forward<_Tuples>(__tpls)...); + } +}; + +template <class _Tuple0, class... _Tuples> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename __tuple_cat_return<_Tuple0, _Tuples...>::type +tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) +{ + typedef typename remove_reference<_Tuple0>::type _T0; + return __tuple_cat<tuple<>, __tuple_indices<>, + typename __make_tuple_indices<tuple_size<_T0>::value>::type>() + (tuple<>(), _VSTD::forward<_Tuple0>(__t0), + _VSTD::forward<_Tuples>(__tpls)...); +} + +template <class ..._Tp, class _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc> + : true_type {}; + +template <class _T1, class _T2> +template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2> +inline _LIBCPP_INLINE_VISIBILITY +pair<_T1, _T2>::pair(piecewise_construct_t, + tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, + __tuple_indices<_I1...>, __tuple_indices<_I2...>) + : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...), + second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) +{ +} + +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value; + +#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } + +template <class _Fn, class _Tuple, size_t ..._Id> +inline _LIBCPP_INLINE_VISIBILITY +constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t, + __tuple_indices<_Id...>) +_LIBCPP_NOEXCEPT_RETURN( + _VSTD::__invoke_constexpr( + _VSTD::forward<_Fn>(__f), + _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...) +) + +template <class _Fn, class _Tuple> +inline _LIBCPP_INLINE_VISIBILITY +constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t) +_LIBCPP_NOEXCEPT_RETURN( + _VSTD::__apply_tuple_impl( + _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t), + typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{}) +) + +template <class _Tp, class _Tuple, size_t... _Idx> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>) +_LIBCPP_NOEXCEPT_RETURN( + _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...) +) + +template <class _Tp, class _Tuple> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp make_from_tuple(_Tuple&& __t) +_LIBCPP_NOEXCEPT_RETURN( + _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t), + typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{}) +) + +#undef _LIBCPP_NOEXCEPT_RETURN + +#endif // _LIBCPP_STD_VER > 14 + +#endif // !defined(_LIBCPP_CXX03_LANG) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_TUPLE diff --git a/android/x86/include/v8/libc++/type_traits b/android/x86/include/v8/libc++/type_traits new file mode 100755 index 00000000..43faf275 --- /dev/null +++ b/android/x86/include/v8/libc++/type_traits @@ -0,0 +1,4912 @@ +// -*- C++ -*- +//===------------------------ type_traits ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_TYPE_TRAITS +#define _LIBCPP_TYPE_TRAITS + +/* + type_traits synopsis + +namespace std +{ + + // helper class: + template <class T, T v> struct integral_constant; + typedef integral_constant<bool, true> true_type; // C++11 + typedef integral_constant<bool, false> false_type; // C++11 + + template <bool B> // C++14 + using bool_constant = integral_constant<bool, B>; // C++14 + typedef bool_constant<true> true_type; // C++14 + typedef bool_constant<false> false_type; // C++14 + + // helper traits + template <bool, class T = void> struct enable_if; + template <bool, class T, class F> struct conditional; + + // Primary classification traits: + template <class T> struct is_void; + template <class T> struct is_null_pointer; // C++14 + template <class T> struct is_integral; + template <class T> struct is_floating_point; + template <class T> struct is_array; + template <class T> struct is_pointer; + template <class T> struct is_lvalue_reference; + template <class T> struct is_rvalue_reference; + template <class T> struct is_member_object_pointer; + template <class T> struct is_member_function_pointer; + template <class T> struct is_enum; + template <class T> struct is_union; + template <class T> struct is_class; + template <class T> struct is_function; + + // Secondary classification traits: + template <class T> struct is_reference; + template <class T> struct is_arithmetic; + template <class T> struct is_fundamental; + template <class T> struct is_member_pointer; + template <class T> struct is_scalar; + template <class T> struct is_object; + template <class T> struct is_compound; + + // Const-volatile properties and transformations: + template <class T> struct is_const; + template <class T> struct is_volatile; + template <class T> struct remove_const; + template <class T> struct remove_volatile; + template <class T> struct remove_cv; + template <class T> struct add_const; + template <class T> struct add_volatile; + template <class T> struct add_cv; + + // Reference transformations: + template <class T> struct remove_reference; + template <class T> struct add_lvalue_reference; + template <class T> struct add_rvalue_reference; + + // Pointer transformations: + template <class T> struct remove_pointer; + template <class T> struct add_pointer; + + template<class T> struct type_identity; // C++20 + template<class T> + using type_identity_t = typename type_identity<T>::type; // C++20 + + // Integral properties: + template <class T> struct is_signed; + template <class T> struct is_unsigned; + template <class T> struct make_signed; + template <class T> struct make_unsigned; + + // Array properties and transformations: + template <class T> struct rank; + template <class T, unsigned I = 0> struct extent; + template <class T> struct remove_extent; + template <class T> struct remove_all_extents; + + template <class T> struct is_bounded_array; // C++20 + template <class T> struct is_unbounded_array; // C++20 + + // Member introspection: + template <class T> struct is_pod; + template <class T> struct is_trivial; + template <class T> struct is_trivially_copyable; + template <class T> struct is_standard_layout; + template <class T> struct is_literal_type; + template <class T> struct is_empty; + template <class T> struct is_polymorphic; + template <class T> struct is_abstract; + template <class T> struct is_final; // C++14 + template <class T> struct is_aggregate; // C++17 + + template <class T, class... Args> struct is_constructible; + template <class T> struct is_default_constructible; + template <class T> struct is_copy_constructible; + template <class T> struct is_move_constructible; + template <class T, class U> struct is_assignable; + template <class T> struct is_copy_assignable; + template <class T> struct is_move_assignable; + template <class T, class U> struct is_swappable_with; // C++17 + template <class T> struct is_swappable; // C++17 + template <class T> struct is_destructible; + + template <class T, class... Args> struct is_trivially_constructible; + template <class T> struct is_trivially_default_constructible; + template <class T> struct is_trivially_copy_constructible; + template <class T> struct is_trivially_move_constructible; + template <class T, class U> struct is_trivially_assignable; + template <class T> struct is_trivially_copy_assignable; + template <class T> struct is_trivially_move_assignable; + template <class T> struct is_trivially_destructible; + + template <class T, class... Args> struct is_nothrow_constructible; + template <class T> struct is_nothrow_default_constructible; + template <class T> struct is_nothrow_copy_constructible; + template <class T> struct is_nothrow_move_constructible; + template <class T, class U> struct is_nothrow_assignable; + template <class T> struct is_nothrow_copy_assignable; + template <class T> struct is_nothrow_move_assignable; + template <class T, class U> struct is_nothrow_swappable_with; // C++17 + template <class T> struct is_nothrow_swappable; // C++17 + template <class T> struct is_nothrow_destructible; + + template <class T> struct has_virtual_destructor; + + template<class T> struct has_unique_object_representations; // C++17 + + // Relationships between types: + template <class T, class U> struct is_same; + template <class Base, class Derived> struct is_base_of; + + template <class From, class To> struct is_convertible; + template <typename From, typename To> struct is_nothrow_convertible; // C++20 + template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20 + + template <class Fn, class... ArgTypes> struct is_invocable; + template <class R, class Fn, class... ArgTypes> struct is_invocable_r; + + template <class Fn, class... ArgTypes> struct is_nothrow_invocable; + template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r; + + // Alignment properties and transformations: + template <class T> struct alignment_of; + template <size_t Len, size_t Align = most_stringent_alignment_requirement> + struct aligned_storage; + template <size_t Len, class... Types> struct aligned_union; + template <class T> struct remove_cvref; // C++20 + + template <class T> struct decay; + template <class... T> struct common_type; + template <class T> struct underlying_type; + template <class> class result_of; // undefined + template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; + template <class Fn, class... ArgTypes> struct invoke_result; // C++17 + + // const-volatile modifications: + template <class T> + using remove_const_t = typename remove_const<T>::type; // C++14 + template <class T> + using remove_volatile_t = typename remove_volatile<T>::type; // C++14 + template <class T> + using remove_cv_t = typename remove_cv<T>::type; // C++14 + template <class T> + using add_const_t = typename add_const<T>::type; // C++14 + template <class T> + using add_volatile_t = typename add_volatile<T>::type; // C++14 + template <class T> + using add_cv_t = typename add_cv<T>::type; // C++14 + + // reference modifications: + template <class T> + using remove_reference_t = typename remove_reference<T>::type; // C++14 + template <class T> + using add_lvalue_reference_t = typename add_lvalue_reference<T>::type; // C++14 + template <class T> + using add_rvalue_reference_t = typename add_rvalue_reference<T>::type; // C++14 + + // sign modifications: + template <class T> + using make_signed_t = typename make_signed<T>::type; // C++14 + template <class T> + using make_unsigned_t = typename make_unsigned<T>::type; // C++14 + + // array modifications: + template <class T> + using remove_extent_t = typename remove_extent<T>::type; // C++14 + template <class T> + using remove_all_extents_t = typename remove_all_extents<T>::type; // C++14 + + template <class T> + inline constexpr bool is_bounded_array_v + = is_bounded_array<T>::value; // C++20 + inline constexpr bool is_unbounded_array_v + = is_unbounded_array<T>::value; // C++20 + + // pointer modifications: + template <class T> + using remove_pointer_t = typename remove_pointer<T>::type; // C++14 + template <class T> + using add_pointer_t = typename add_pointer<T>::type; // C++14 + + // other transformations: + template <size_t Len, std::size_t Align=default-alignment> + using aligned_storage_t = typename aligned_storage<Len,Align>::type; // C++14 + template <std::size_t Len, class... Types> + using aligned_union_t = typename aligned_union<Len,Types...>::type; // C++14 + template <class T> + using remove_cvref_t = typename remove_cvref<T>::type; // C++20 + template <class T> + using decay_t = typename decay<T>::type; // C++14 + template <bool b, class T=void> + using enable_if_t = typename enable_if<b,T>::type; // C++14 + template <bool b, class T, class F> + using conditional_t = typename conditional<b,T,F>::type; // C++14 + template <class... T> + using common_type_t = typename common_type<T...>::type; // C++14 + template <class T> + using underlying_type_t = typename underlying_type<T>::type; // C++14 + template <class T> + using result_of_t = typename result_of<T>::type; // C++14 + template <class Fn, class... ArgTypes> + using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type; // C++17 + + template <class...> + using void_t = void; // C++17 + + // See C++14 20.10.4.1, primary type categories + template <class T> inline constexpr bool is_void_v + = is_void<T>::value; // C++17 + template <class T> inline constexpr bool is_null_pointer_v + = is_null_pointer<T>::value; // C++17 + template <class T> inline constexpr bool is_integral_v + = is_integral<T>::value; // C++17 + template <class T> inline constexpr bool is_floating_point_v + = is_floating_point<T>::value; // C++17 + template <class T> inline constexpr bool is_array_v + = is_array<T>::value; // C++17 + template <class T> inline constexpr bool is_pointer_v + = is_pointer<T>::value; // C++17 + template <class T> inline constexpr bool is_lvalue_reference_v + = is_lvalue_reference<T>::value; // C++17 + template <class T> inline constexpr bool is_rvalue_reference_v + = is_rvalue_reference<T>::value; // C++17 + template <class T> inline constexpr bool is_member_object_pointer_v + = is_member_object_pointer<T>::value; // C++17 + template <class T> inline constexpr bool is_member_function_pointer_v + = is_member_function_pointer<T>::value; // C++17 + template <class T> inline constexpr bool is_enum_v + = is_enum<T>::value; // C++17 + template <class T> inline constexpr bool is_union_v + = is_union<T>::value; // C++17 + template <class T> inline constexpr bool is_class_v + = is_class<T>::value; // C++17 + template <class T> inline constexpr bool is_function_v + = is_function<T>::value; // C++17 + + // See C++14 20.10.4.2, composite type categories + template <class T> inline constexpr bool is_reference_v + = is_reference<T>::value; // C++17 + template <class T> inline constexpr bool is_arithmetic_v + = is_arithmetic<T>::value; // C++17 + template <class T> inline constexpr bool is_fundamental_v + = is_fundamental<T>::value; // C++17 + template <class T> inline constexpr bool is_object_v + = is_object<T>::value; // C++17 + template <class T> inline constexpr bool is_scalar_v + = is_scalar<T>::value; // C++17 + template <class T> inline constexpr bool is_compound_v + = is_compound<T>::value; // C++17 + template <class T> inline constexpr bool is_member_pointer_v + = is_member_pointer<T>::value; // C++17 + + // See C++14 20.10.4.3, type properties + template <class T> inline constexpr bool is_const_v + = is_const<T>::value; // C++17 + template <class T> inline constexpr bool is_volatile_v + = is_volatile<T>::value; // C++17 + template <class T> inline constexpr bool is_trivial_v + = is_trivial<T>::value; // C++17 + template <class T> inline constexpr bool is_trivially_copyable_v + = is_trivially_copyable<T>::value; // C++17 + template <class T> inline constexpr bool is_standard_layout_v + = is_standard_layout<T>::value; // C++17 + template <class T> inline constexpr bool is_pod_v + = is_pod<T>::value; // C++17 + template <class T> inline constexpr bool is_literal_type_v + = is_literal_type<T>::value; // C++17 + template <class T> inline constexpr bool is_empty_v + = is_empty<T>::value; // C++17 + template <class T> inline constexpr bool is_polymorphic_v + = is_polymorphic<T>::value; // C++17 + template <class T> inline constexpr bool is_abstract_v + = is_abstract<T>::value; // C++17 + template <class T> inline constexpr bool is_final_v + = is_final<T>::value; // C++17 + template <class T> inline constexpr bool is_aggregate_v + = is_aggregate<T>::value; // C++17 + template <class T> inline constexpr bool is_signed_v + = is_signed<T>::value; // C++17 + template <class T> inline constexpr bool is_unsigned_v + = is_unsigned<T>::value; // C++17 + template <class T, class... Args> inline constexpr bool is_constructible_v + = is_constructible<T, Args...>::value; // C++17 + template <class T> inline constexpr bool is_default_constructible_v + = is_default_constructible<T>::value; // C++17 + template <class T> inline constexpr bool is_copy_constructible_v + = is_copy_constructible<T>::value; // C++17 + template <class T> inline constexpr bool is_move_constructible_v + = is_move_constructible<T>::value; // C++17 + template <class T, class U> inline constexpr bool is_assignable_v + = is_assignable<T, U>::value; // C++17 + template <class T> inline constexpr bool is_copy_assignable_v + = is_copy_assignable<T>::value; // C++17 + template <class T> inline constexpr bool is_move_assignable_v + = is_move_assignable<T>::value; // C++17 + template <class T, class U> inline constexpr bool is_swappable_with_v + = is_swappable_with<T, U>::value; // C++17 + template <class T> inline constexpr bool is_swappable_v + = is_swappable<T>::value; // C++17 + template <class T> inline constexpr bool is_destructible_v + = is_destructible<T>::value; // C++17 + template <class T, class... Args> inline constexpr bool is_trivially_constructible_v + = is_trivially_constructible<T, Args...>::value; // C++17 + template <class T> inline constexpr bool is_trivially_default_constructible_v + = is_trivially_default_constructible<T>::value; // C++17 + template <class T> inline constexpr bool is_trivially_copy_constructible_v + = is_trivially_copy_constructible<T>::value; // C++17 + template <class T> inline constexpr bool is_trivially_move_constructible_v + = is_trivially_move_constructible<T>::value; // C++17 + template <class T, class U> inline constexpr bool is_trivially_assignable_v + = is_trivially_assignable<T, U>::value; // C++17 + template <class T> inline constexpr bool is_trivially_copy_assignable_v + = is_trivially_copy_assignable<T>::value; // C++17 + template <class T> inline constexpr bool is_trivially_move_assignable_v + = is_trivially_move_assignable<T>::value; // C++17 + template <class T> inline constexpr bool is_trivially_destructible_v + = is_trivially_destructible<T>::value; // C++17 + template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v + = is_nothrow_constructible<T, Args...>::value; // C++17 + template <class T> inline constexpr bool is_nothrow_default_constructible_v + = is_nothrow_default_constructible<T>::value; // C++17 + template <class T> inline constexpr bool is_nothrow_copy_constructible_v + = is_nothrow_copy_constructible<T>::value; // C++17 + template <class T> inline constexpr bool is_nothrow_move_constructible_v + = is_nothrow_move_constructible<T>::value; // C++17 + template <class T, class U> inline constexpr bool is_nothrow_assignable_v + = is_nothrow_assignable<T, U>::value; // C++17 + template <class T> inline constexpr bool is_nothrow_copy_assignable_v + = is_nothrow_copy_assignable<T>::value; // C++17 + template <class T> inline constexpr bool is_nothrow_move_assignable_v + = is_nothrow_move_assignable<T>::value; // C++17 + template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v + = is_nothrow_swappable_with<T, U>::value; // C++17 + template <class T> inline constexpr bool is_nothrow_swappable_v + = is_nothrow_swappable<T>::value; // C++17 + template <class T> inline constexpr bool is_nothrow_destructible_v + = is_nothrow_destructible<T>::value; // C++17 + template <class T> inline constexpr bool has_virtual_destructor_v + = has_virtual_destructor<T>::value; // C++17 + template<class T> inline constexpr bool has_unique_object_representations_v // C++17 + = has_unique_object_representations<T>::value; + + // See C++14 20.10.5, type property queries + template <class T> inline constexpr size_t alignment_of_v + = alignment_of<T>::value; // C++17 + template <class T> inline constexpr size_t rank_v + = rank<T>::value; // C++17 + template <class T, unsigned I = 0> inline constexpr size_t extent_v + = extent<T, I>::value; // C++17 + + // See C++14 20.10.6, type relations + template <class T, class U> inline constexpr bool is_same_v + = is_same<T, U>::value; // C++17 + template <class Base, class Derived> inline constexpr bool is_base_of_v + = is_base_of<Base, Derived>::value; // C++17 + template <class From, class To> inline constexpr bool is_convertible_v + = is_convertible<From, To>::value; // C++17 + template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v + = is_invocable<Fn, ArgTypes...>::value; // C++17 + template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v + = is_invocable_r<R, Fn, ArgTypes...>::value; // C++17 + template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v + = is_nothrow_invocable<Fn, ArgTypes...>::value; // C++17 + template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v + = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value; // C++17 + + // [meta.logical], logical operator traits: + template<class... B> struct conjunction; // C++17 + template<class... B> + inline constexpr bool conjunction_v = conjunction<B...>::value; // C++17 + template<class... B> struct disjunction; // C++17 + template<class... B> + inline constexpr bool disjunction_v = disjunction<B...>::value; // C++17 + template<class B> struct negation; // C++17 + template<class B> + inline constexpr bool negation_v = negation<B>::value; // C++17 + +} + +*/ +#include <__config> +#include <cstddef> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS pair; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS reference_wrapper; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash; + +template <class> +struct __void_t { typedef void type; }; + +template <class _Tp> +struct __identity { typedef _Tp type; }; + +template <class _Tp, bool> +struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {}; + +template <bool _Bp, class _If, class _Then> + struct _LIBCPP_TEMPLATE_VIS conditional {typedef _If type;}; +template <class _If, class _Then> + struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> {typedef _Then type;}; + +#if _LIBCPP_STD_VER > 11 +template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type; +#endif + +template <bool, class _Tp> struct _LIBCPP_TEMPLATE_VIS __lazy_enable_if {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __lazy_enable_if<true, _Tp> {typedef typename _Tp::type type;}; + +template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;}; + +#if _LIBCPP_STD_VER > 11 +template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type; +#endif + +// addressof +#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF + +template <class _Tp> +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY +_Tp* +addressof(_Tp& __x) _NOEXCEPT +{ + return __builtin_addressof(__x); +} + +#else + +template <class _Tp> +inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY +_Tp* +addressof(_Tp& __x) _NOEXCEPT +{ + return reinterpret_cast<_Tp *>( + const_cast<char *>(&reinterpret_cast<const volatile char &>(__x))); +} + +#endif // _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF + +#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) +// Objective-C++ Automatic Reference Counting uses qualified pointers +// that require special addressof() signatures. When +// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler +// itself is providing these definitions. Otherwise, we provide them. +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__strong _Tp* +addressof(__strong _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__weak _Tp* +addressof(__weak _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__autoreleasing _Tp* +addressof(__autoreleasing _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__unsafe_unretained _Tp* +addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +#if !defined(_LIBCPP_CXX03_LANG) +template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete; +#endif + +struct __two {char __lx[2];}; + +// helper class: + +template <class _Tp, _Tp __v> +struct _LIBCPP_TEMPLATE_VIS integral_constant +{ + static _LIBCPP_CONSTEXPR const _Tp value = __v; + typedef _Tp value_type; + typedef integral_constant type; + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;} +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + constexpr value_type operator ()() const _NOEXCEPT {return value;} +#endif +}; + +template <class _Tp, _Tp __v> +_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value; + +#if _LIBCPP_STD_VER > 14 +template <bool __b> +using bool_constant = integral_constant<bool, __b>; +#define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)> +#else +#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)> +#endif + +typedef _LIBCPP_BOOL_CONSTANT(true) true_type; +typedef _LIBCPP_BOOL_CONSTANT(false) false_type; + +#if !defined(_LIBCPP_CXX03_LANG) + +// __lazy_and + +template <bool _Last, class ..._Preds> +struct __lazy_and_impl; + +template <class ..._Preds> +struct __lazy_and_impl<false, _Preds...> : false_type {}; + +template <> +struct __lazy_and_impl<true> : true_type {}; + +template <class _Pred> +struct __lazy_and_impl<true, _Pred> : integral_constant<bool, _Pred::type::value> {}; + +template <class _Hp, class ..._Tp> +struct __lazy_and_impl<true, _Hp, _Tp...> : __lazy_and_impl<_Hp::type::value, _Tp...> {}; + +template <class _P1, class ..._Pr> +struct __lazy_and : __lazy_and_impl<_P1::type::value, _Pr...> {}; + +// __lazy_or + +template <bool _List, class ..._Preds> +struct __lazy_or_impl; + +template <class ..._Preds> +struct __lazy_or_impl<true, _Preds...> : true_type {}; + +template <> +struct __lazy_or_impl<false> : false_type {}; + +template <class _Hp, class ..._Tp> +struct __lazy_or_impl<false, _Hp, _Tp...> + : __lazy_or_impl<_Hp::type::value, _Tp...> {}; + +template <class _P1, class ..._Pr> +struct __lazy_or : __lazy_or_impl<_P1::type::value, _Pr...> {}; + +// __lazy_not + +template <class _Pred> +struct __lazy_not : integral_constant<bool, !_Pred::type::value> {}; + +// __and_ +template<class...> struct __and_; +template<> struct __and_<> : true_type {}; + +template<class _B0> struct __and_<_B0> : _B0 {}; + +template<class _B0, class _B1> +struct __and_<_B0, _B1> : conditional<_B0::value, _B1, _B0>::type {}; + +template<class _B0, class _B1, class _B2, class... _Bn> +struct __and_<_B0, _B1, _B2, _Bn...> + : conditional<_B0::value, __and_<_B1, _B2, _Bn...>, _B0>::type {}; + +// __or_ +template<class...> struct __or_; +template<> struct __or_<> : false_type {}; + +template<class _B0> struct __or_<_B0> : _B0 {}; + +template<class _B0, class _B1> +struct __or_<_B0, _B1> : conditional<_B0::value, _B0, _B1>::type {}; + +template<class _B0, class _B1, class _B2, class... _Bn> +struct __or_<_B0, _B1, _B2, _Bn...> + : conditional<_B0::value, _B0, __or_<_B1, _B2, _Bn...> >::type {}; + +// __not_ +template<class _Tp> +struct __not_ : conditional<_Tp::value, false_type, true_type>::type {}; + +#endif // !defined(_LIBCPP_CXX03_LANG) + +// is_const + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v + = is_const<_Tp>::value; +#endif + +// is_volatile + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v + = is_volatile<_Tp>::value; +#endif + +// remove_const + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const<const _Tp> {typedef _Tp type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type; +#endif + +// remove_volatile + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type; +#endif + +// remove_cv + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv +{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type; +#endif + +// is_void + +template <class _Tp> struct __libcpp_is_void : public false_type {}; +template <> struct __libcpp_is_void<void> : public true_type {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void + : public __libcpp_is_void<typename remove_cv<_Tp>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v + = is_void<_Tp>::value; +#endif + +// __is_nullptr_t + +template <class _Tp> struct __is_nullptr_t_impl : public false_type {}; +template <> struct __is_nullptr_t_impl<nullptr_t> : public true_type {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __is_nullptr_t + : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_null_pointer + : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_null_pointer_v + = is_null_pointer<_Tp>::value; +#endif +#endif + +// is_integral + +template <class _Tp> struct __libcpp_is_integral : public false_type {}; +template <> struct __libcpp_is_integral<bool> : public true_type {}; +template <> struct __libcpp_is_integral<char> : public true_type {}; +template <> struct __libcpp_is_integral<signed char> : public true_type {}; +template <> struct __libcpp_is_integral<unsigned char> : public true_type {}; +template <> struct __libcpp_is_integral<wchar_t> : public true_type {}; +#ifndef _LIBCPP_NO_HAS_CHAR8_T +template <> struct __libcpp_is_integral<char8_t> : public true_type {}; +#endif +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS +template <> struct __libcpp_is_integral<char16_t> : public true_type {}; +template <> struct __libcpp_is_integral<char32_t> : public true_type {}; +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS +template <> struct __libcpp_is_integral<short> : public true_type {}; +template <> struct __libcpp_is_integral<unsigned short> : public true_type {}; +template <> struct __libcpp_is_integral<int> : public true_type {}; +template <> struct __libcpp_is_integral<unsigned int> : public true_type {}; +template <> struct __libcpp_is_integral<long> : public true_type {}; +template <> struct __libcpp_is_integral<unsigned long> : public true_type {}; +template <> struct __libcpp_is_integral<long long> : public true_type {}; +template <> struct __libcpp_is_integral<unsigned long long> : public true_type {}; +#ifndef _LIBCPP_HAS_NO_INT128 +template <> struct __libcpp_is_integral<__int128_t> : public true_type {}; +template <> struct __libcpp_is_integral<__uint128_t> : public true_type {}; +#endif + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral + : public __libcpp_is_integral<typename remove_cv<_Tp>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v + = is_integral<_Tp>::value; +#endif + +// is_floating_point + +template <class _Tp> struct __libcpp_is_floating_point : public false_type {}; +template <> struct __libcpp_is_floating_point<float> : public true_type {}; +template <> struct __libcpp_is_floating_point<double> : public true_type {}; +template <> struct __libcpp_is_floating_point<long double> : public true_type {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_floating_point + : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_floating_point_v + = is_floating_point<_Tp>::value; +#endif + +// is_array + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array + : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]> + : public true_type {}; +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]> + : public true_type {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v + = is_array<_Tp>::value; +#endif + +// is_pointer + +template <class _Tp> struct __libcpp_is_pointer : public false_type {}; +template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {}; + +template <class _Tp> struct __libcpp_remove_objc_qualifiers { typedef _Tp type; }; +#if defined(_LIBCPP_HAS_OBJC_ARC) +template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; }; +template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; }; +template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; }; +template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; }; +#endif + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer + : public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<typename remove_cv<_Tp>::type>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pointer_v + = is_pointer<_Tp>::value; +#endif + +// is_reference + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : public false_type {}; +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference<_Tp&&> : public true_type {}; +#endif + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&> : public true_type {}; +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {}; +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_reference_v + = is_reference<_Tp>::value; + +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_lvalue_reference_v + = is_lvalue_reference<_Tp>::value; + +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v + = is_rvalue_reference<_Tp>::value; +#endif +// is_union + +#if __has_feature(is_union) || (_GNUC_VER >= 403) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union + : public integral_constant<bool, __is_union(_Tp)> {}; + +#else + +template <class _Tp> struct __libcpp_union : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union + : public __libcpp_union<typename remove_cv<_Tp>::type> {}; + +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_union_v + = is_union<_Tp>::value; +#endif + +// is_class + +#if __has_feature(is_class) || (_GNUC_VER >= 403) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class + : public integral_constant<bool, __is_class(_Tp)> {}; + +#else + +namespace __is_class_imp +{ +template <class _Tp> char __test(int _Tp::*); +template <class _Tp> __two __test(...); +} + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class + : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {}; + +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_class_v + = is_class<_Tp>::value; +#endif + +// is_same + +template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp, class _Up> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v + = is_same<_Tp, _Up>::value; +#endif + +// is_function + +namespace __libcpp_is_function_imp +{ +struct __dummy_type {}; +template <class _Tp> char __test(_Tp*); +template <class _Tp> char __test(__dummy_type); +template <class _Tp> __two __test(...); +template <class _Tp> _Tp& __source(int); +template <class _Tp> __dummy_type __source(...); +} + +template <class _Tp, bool = is_class<_Tp>::value || + is_union<_Tp>::value || + is_void<_Tp>::value || + is_reference<_Tp>::value || + __is_nullptr_t<_Tp>::value > +struct __libcpp_is_function + : public integral_constant<bool, sizeof(__libcpp_is_function_imp::__test<_Tp>(__libcpp_is_function_imp::__source<_Tp>(0))) == 1> + {}; +template <class _Tp> struct __libcpp_is_function<_Tp, true> : public false_type {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_function + : public __libcpp_is_function<_Tp> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_function_v + = is_function<_Tp>::value; +#endif + +// is_member_function_pointer + +// template <class _Tp> struct __libcpp_is_member_function_pointer : public false_type {}; +// template <class _Tp, class _Up> struct __libcpp_is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {}; +// + +template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr> +struct __member_pointer_traits_imp +{ // forward declaration; specializations later +}; + + +template <class _Tp> struct __libcpp_is_member_function_pointer + : public false_type {}; + +template <class _Ret, class _Class> +struct __libcpp_is_member_function_pointer<_Ret _Class::*> + : public is_function<_Ret> {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer + : public __libcpp_is_member_function_pointer<typename remove_cv<_Tp>::type>::type {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v + = is_member_function_pointer<_Tp>::value; +#endif + +// is_member_pointer + +template <class _Tp> struct __libcpp_is_member_pointer : public false_type {}; +template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> : public true_type {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer + : public __libcpp_is_member_pointer<typename remove_cv<_Tp>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v + = is_member_pointer<_Tp>::value; +#endif + +// is_member_object_pointer + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer + : public integral_constant<bool, is_member_pointer<_Tp>::value && + !is_member_function_pointer<_Tp>::value> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v + = is_member_object_pointer<_Tp>::value; +#endif + +// is_enum + +#if __has_feature(is_enum) || (_GNUC_VER >= 403) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum + : public integral_constant<bool, __is_enum(_Tp)> {}; + +#else + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum + : public integral_constant<bool, !is_void<_Tp>::value && + !is_integral<_Tp>::value && + !is_floating_point<_Tp>::value && + !is_array<_Tp>::value && + !is_pointer<_Tp>::value && + !is_reference<_Tp>::value && + !is_member_pointer<_Tp>::value && + !is_union<_Tp>::value && + !is_class<_Tp>::value && + !is_function<_Tp>::value > {}; + +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_enum_v + = is_enum<_Tp>::value; +#endif + +// is_arithmetic + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic + : public integral_constant<bool, is_integral<_Tp>::value || + is_floating_point<_Tp>::value> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_arithmetic_v + = is_arithmetic<_Tp>::value; +#endif + +// is_fundamental + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental + : public integral_constant<bool, is_void<_Tp>::value || + __is_nullptr_t<_Tp>::value || + is_arithmetic<_Tp>::value> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v + = is_fundamental<_Tp>::value; +#endif + +// is_scalar + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar + : public integral_constant<bool, is_arithmetic<_Tp>::value || + is_member_pointer<_Tp>::value || + is_pointer<_Tp>::value || + __is_nullptr_t<_Tp>::value || + is_enum<_Tp>::value > {}; + +template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v + = is_scalar<_Tp>::value; +#endif + +// is_object + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object + : public integral_constant<bool, is_scalar<_Tp>::value || + is_array<_Tp>::value || + is_union<_Tp>::value || + is_class<_Tp>::value > {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v + = is_object<_Tp>::value; +#endif + +// is_compound + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound + : public integral_constant<bool, !is_fundamental<_Tp>::value> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v + = is_compound<_Tp>::value; +#endif + + +// __is_referenceable [defns.referenceable] + +struct __is_referenceable_impl { + template <class _Tp> static _Tp& __test(int); + template <class _Tp> static __two __test(...); +}; + +template <class _Tp> +struct __is_referenceable : integral_constant<bool, + !is_same<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {}; + + +// add_const + +template <class _Tp, bool = is_reference<_Tp>::value || + is_function<_Tp>::value || + is_const<_Tp>::value > +struct __add_const {typedef _Tp type;}; + +template <class _Tp> +struct __add_const<_Tp, false> {typedef const _Tp type;}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const + {typedef typename __add_const<_Tp>::type type;}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_const_t = typename add_const<_Tp>::type; +#endif + +// add_volatile + +template <class _Tp, bool = is_reference<_Tp>::value || + is_function<_Tp>::value || + is_volatile<_Tp>::value > +struct __add_volatile {typedef _Tp type;}; + +template <class _Tp> +struct __add_volatile<_Tp, false> {typedef volatile _Tp type;}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile + {typedef typename __add_volatile<_Tp>::type type;}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type; +#endif + +// add_cv + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv + {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type; +#endif + +// remove_reference + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _Tp type;}; +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _Tp type;}; +#endif + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type; +#endif + +// add_lvalue_reference + +template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _Tp type; }; +template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _Tp& type; }; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference +{typedef typename __add_lvalue_reference_impl<_Tp>::type type;}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type; +#endif + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _Tp type; }; +template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _Tp&& type; }; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference +{typedef typename __add_rvalue_reference_impl<_Tp>::type type;}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type; +#endif + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp> _Tp&& __declval(int); +template <class _Tp> _Tp __declval(long); + +template <class _Tp> +decltype(_VSTD::__declval<_Tp>(0)) +declval() _NOEXCEPT; + +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp> +typename add_lvalue_reference<_Tp>::type +declval(); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +// __uncvref + +template <class _Tp> +struct __uncvref { + typedef typename remove_cv<typename remove_reference<_Tp>::type>::type type; +}; + +template <class _Tp> +struct __unconstref { + typedef typename remove_const<typename remove_reference<_Tp>::type>::type type; +}; + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp> +using __uncvref_t = typename __uncvref<_Tp>::type; +#endif + +// __is_same_uncvref + +template <class _Tp, class _Up> +struct __is_same_uncvref : is_same<typename __uncvref<_Tp>::type, + typename __uncvref<_Up>::type> {}; + +#if _LIBCPP_STD_VER > 17 +// remove_cvref - same as __uncvref +template <class _Tp> +struct remove_cvref : public __uncvref<_Tp> {}; + +template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type; +#endif + + +struct __any +{ + __any(...); +}; + +// remove_pointer + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _Tp type;}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type; +#endif + +// add_pointer + +template <class _Tp, + bool = __is_referenceable<_Tp>::value || + is_same<typename remove_cv<_Tp>::type, void>::value> +struct __add_pointer_impl + {typedef typename remove_reference<_Tp>::type* type;}; +template <class _Tp> struct __add_pointer_impl<_Tp, false> + {typedef _Tp type;}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer + {typedef typename __add_pointer_impl<_Tp>::type type;}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type; +#endif + +// type_identity +#if _LIBCPP_STD_VER > 17 +template<class _Tp> struct type_identity { typedef _Tp type; }; +template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type; +#endif + +// is_signed + +template <class _Tp, bool = is_integral<_Tp>::value> +struct __libcpp_is_signed_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(-1) < _Tp(0)) {}; + +template <class _Tp> +struct __libcpp_is_signed_impl<_Tp, false> : public true_type {}; // floating point + +template <class _Tp, bool = is_arithmetic<_Tp>::value> +struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {}; + +template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v + = is_signed<_Tp>::value; +#endif + +// is_unsigned + +template <class _Tp, bool = is_integral<_Tp>::value> +struct __libcpp_is_unsigned_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(0) < _Tp(-1)) {}; + +template <class _Tp> +struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point + +template <class _Tp, bool = is_arithmetic<_Tp>::value> +struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {}; + +template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v + = is_unsigned<_Tp>::value; +#endif + +// rank + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank + : public integral_constant<size_t, 0> {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]> + : public integral_constant<size_t, rank<_Tp>::value + 1> {}; +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]> + : public integral_constant<size_t, rank<_Tp>::value + 1> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t rank_v + = rank<_Tp>::value; +#endif + +// extent + +template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS extent + : public integral_constant<size_t, 0> {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0> + : public integral_constant<size_t, 0> {}; +template <class _Tp, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], _Ip> + : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {}; +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0> + : public integral_constant<size_t, _Np> {}; +template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip> + : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp, unsigned _Ip = 0> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t extent_v + = extent<_Tp, _Ip>::value; +#endif + +// remove_extent + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent + {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[]> + {typedef _Tp type;}; +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[_Np]> + {typedef _Tp type;}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type; +#endif + +// remove_all_extents + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents + {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[]> + {typedef typename remove_all_extents<_Tp>::type type;}; +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[_Np]> + {typedef typename remove_all_extents<_Tp>::type type;}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type; +#endif + +#if _LIBCPP_STD_VER > 17 +// is_bounded_array + +template <class> struct _LIBCPP_TEMPLATE_VIS is_bounded_array : false_type {}; +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {}; + +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR +bool is_bounded_array_v = is_bounded_array<_Tp>::value; + +// is_unbounded_array + +template <class> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array : false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {}; + +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR +bool is_unbounded_array_v = is_unbounded_array<_Tp>::value; +#endif + +// decay + +template <class _Up, bool> +struct __decay { + typedef typename remove_cv<_Up>::type type; +}; + +template <class _Up> +struct __decay<_Up, true> { +public: + typedef typename conditional + < + is_array<_Up>::value, + typename remove_extent<_Up>::type*, + typename conditional + < + is_function<_Up>::value, + typename add_pointer<_Up>::type, + typename remove_cv<_Up>::type + >::type + >::type type; +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS decay +{ +private: + typedef typename remove_reference<_Tp>::type _Up; +public: + typedef typename __decay<_Up, __is_referenceable<_Up>::value>::type type; +}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using decay_t = typename decay<_Tp>::type; +#endif + +// is_abstract + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract + : public integral_constant<bool, __is_abstract(_Tp)> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_abstract_v + = is_abstract<_Tp>::value; +#endif + +// is_final + +#if defined(_LIBCPP_HAS_IS_FINAL) +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS +__libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {}; +#else +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS +__libcpp_is_final : public false_type {}; +#endif + +#if defined(_LIBCPP_HAS_IS_FINAL) && _LIBCPP_STD_VER > 11 +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS +is_final : public integral_constant<bool, __is_final(_Tp)> {}; +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_final_v + = is_final<_Tp>::value; +#endif + +// is_aggregate +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS +is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {}; + +#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr bool is_aggregate_v + = is_aggregate<_Tp>::value; +#endif + +#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + +// is_base_of + +#ifdef _LIBCPP_HAS_IS_BASE_OF + +template <class _Bp, class _Dp> +struct _LIBCPP_TEMPLATE_VIS is_base_of + : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {}; + +#else // _LIBCPP_HAS_IS_BASE_OF + +namespace __is_base_of_imp +{ +template <class _Tp> +struct _Dst +{ + _Dst(const volatile _Tp &); +}; +template <class _Tp> +struct _Src +{ + operator const volatile _Tp &(); + template <class _Up> operator const _Dst<_Up> &(); +}; +template <size_t> struct __one { typedef char type; }; +template <class _Bp, class _Dp> typename __one<sizeof(_Dst<_Bp>(declval<_Src<_Dp> >()))>::type __test(int); +template <class _Bp, class _Dp> __two __test(...); +} + +template <class _Bp, class _Dp> +struct _LIBCPP_TEMPLATE_VIS is_base_of + : public integral_constant<bool, is_class<_Bp>::value && + sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {}; + +#endif // _LIBCPP_HAS_IS_BASE_OF + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Bp, class _Dp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_base_of_v + = is_base_of<_Bp, _Dp>::value; +#endif + +// is_convertible + +#if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) + +template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible + : public integral_constant<bool, __is_convertible_to(_T1, _T2) && + !is_abstract<_T2>::value> {}; + +#else // __has_feature(is_convertible_to) + +namespace __is_convertible_imp +{ +template <class _Tp> void __test_convert(_Tp); + +template <class _From, class _To, class = void> +struct __is_convertible_test : public false_type {}; + +template <class _From, class _To> +struct __is_convertible_test<_From, _To, + decltype(_VSTD::__is_convertible_imp::__test_convert<_To>(_VSTD::declval<_From>()))> : public true_type +{}; + +template <class _Tp, bool _IsArray = is_array<_Tp>::value, + bool _IsFunction = is_function<_Tp>::value, + bool _IsVoid = is_void<_Tp>::value> + struct __is_array_function_or_void {enum {value = 0};}; +template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};}; +template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};}; +template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};}; +} + +template <class _Tp, + unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value> +struct __is_convertible_check +{ + static const size_t __v = 0; +}; + +template <class _Tp> +struct __is_convertible_check<_Tp, 0> +{ + static const size_t __v = sizeof(_Tp); +}; + +template <class _T1, class _T2, + unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value, + unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value> +struct __is_convertible + : public integral_constant<bool, + __is_convertible_imp::__is_convertible_test<_T1, _T2>::value +#if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + && !(!is_function<_T1>::value && !is_reference<_T1>::value && is_reference<_T2>::value + && (!is_const<typename remove_reference<_T2>::type>::value + || is_volatile<typename remove_reference<_T2>::type>::value) + && (is_same<typename remove_cv<_T1>::type, + typename remove_cv<typename remove_reference<_T2>::type>::type>::value + || is_base_of<typename remove_reference<_T2>::type, _T1>::value)) +#endif + > +{}; + +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {}; +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {}; +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {}; +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {}; + +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {}; +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {}; +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {}; +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {}; + +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {}; +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {}; +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {}; +template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {}; + +template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible + : public __is_convertible<_T1, _T2> +{ + static const size_t __complete_check1 = __is_convertible_check<_T1>::__v; + static const size_t __complete_check2 = __is_convertible_check<_T2>::__v; +}; + +#endif // __has_feature(is_convertible_to) + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _From, class _To> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_convertible_v + = is_convertible<_From, _To>::value; +#endif + +// is_nothrow_convertible + +#if _LIBCPP_STD_VER > 17 + +template <typename _Tp> +static void __test_noexcept(_Tp) noexcept; + +template<typename _Fm, typename _To> +static bool_constant<noexcept(__test_noexcept<_To>(declval<_Fm>()))> +__is_nothrow_convertible_test(); + +template <typename _Fm, typename _To> +struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>()) +{ }; + +template <typename _Fm, typename _To> +struct is_nothrow_convertible : __or_< + __and_<is_void<_To>, is_void<_Fm>>, + __and_<is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>> +>::type { }; + +template <typename _Fm, typename _To> +inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value; + +#endif // _LIBCPP_STD_VER > 17 + +// is_empty + +#if __has_feature(is_empty) || (_GNUC_VER >= 407) + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_empty + : public integral_constant<bool, __is_empty(_Tp)> {}; + +#else // __has_feature(is_empty) + +template <class _Tp> +struct __is_empty1 + : public _Tp +{ + double __lx; +}; + +struct __is_empty2 +{ + double __lx; +}; + +template <class _Tp, bool = is_class<_Tp>::value> +struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {}; + +template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_empty : public __libcpp_empty<_Tp> {}; + +#endif // __has_feature(is_empty) + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_empty_v + = is_empty<_Tp>::value; +#endif + +// is_polymorphic + +#if __has_feature(is_polymorphic) || defined(_LIBCPP_COMPILER_MSVC) + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_polymorphic + : public integral_constant<bool, __is_polymorphic(_Tp)> {}; + +#else + +template<typename _Tp> char &__is_polymorphic_impl( + typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0, + int>::type); +template<typename _Tp> __two &__is_polymorphic_impl(...); + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_polymorphic + : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {}; + +#endif // __has_feature(is_polymorphic) + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_polymorphic_v + = is_polymorphic<_Tp>::value; +#endif + +// has_virtual_destructor + +#if __has_feature(has_virtual_destructor) || (_GNUC_VER >= 403) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor + : public integral_constant<bool, __has_virtual_destructor(_Tp)> {}; + +#else + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor + : public false_type {}; + +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_virtual_destructor_v + = has_virtual_destructor<_Tp>::value; +#endif + +// has_unique_object_representations + +#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations + : public integral_constant<bool, + __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {}; + +#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_unique_object_representations_v + = has_unique_object_representations<_Tp>::value; +#endif + +#endif + +// alignment_of + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of + : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t alignment_of_v + = alignment_of<_Tp>::value; +#endif + +// aligned_storage + +template <class _Hp, class _Tp> +struct __type_list +{ + typedef _Hp _Head; + typedef _Tp _Tail; +}; + +struct __nat +{ +#ifndef _LIBCPP_CXX03_LANG + __nat() = delete; + __nat(const __nat&) = delete; + __nat& operator=(const __nat&) = delete; + ~__nat() = delete; +#endif +}; + +template <class _Tp> +struct __align_type +{ + static const size_t value = _LIBCPP_PREFERRED_ALIGNOF(_Tp); + typedef _Tp type; +}; + +struct __struct_double {long double __lx;}; +struct __struct_double4 {double __lx[4];}; + +typedef + __type_list<__align_type<unsigned char>, + __type_list<__align_type<unsigned short>, + __type_list<__align_type<unsigned int>, + __type_list<__align_type<unsigned long>, + __type_list<__align_type<unsigned long long>, + __type_list<__align_type<double>, + __type_list<__align_type<long double>, + __type_list<__align_type<__struct_double>, + __type_list<__align_type<__struct_double4>, + __type_list<__align_type<int*>, + __nat + > > > > > > > > > > __all_types; + +template <class _TL, size_t _Align> struct __find_pod; + +template <class _Hp, size_t _Align> +struct __find_pod<__type_list<_Hp, __nat>, _Align> +{ + typedef typename conditional< + _Align == _Hp::value, + typename _Hp::type, + void + >::type type; +}; + +template <class _Hp, class _Tp, size_t _Align> +struct __find_pod<__type_list<_Hp, _Tp>, _Align> +{ + typedef typename conditional< + _Align == _Hp::value, + typename _Hp::type, + typename __find_pod<_Tp, _Align>::type + >::type type; +}; + +template <class _TL, size_t _Len> struct __find_max_align; + +template <class _Hp, size_t _Len> +struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {}; + +template <size_t _Len, size_t _A1, size_t _A2> +struct __select_align +{ +private: + static const size_t __min = _A2 < _A1 ? _A2 : _A1; + static const size_t __max = _A1 < _A2 ? _A2 : _A1; +public: + static const size_t value = _Len < __max ? __min : __max; +}; + +template <class _Hp, class _Tp, size_t _Len> +struct __find_max_align<__type_list<_Hp, _Tp>, _Len> + : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {}; + +template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value> +struct _LIBCPP_TEMPLATE_VIS aligned_storage +{ + typedef typename __find_pod<__all_types, _Align>::type _Aligner; + static_assert(!is_void<_Aligner>::value, ""); + union type + { + _Aligner __align; + unsigned char __data[(_Len + _Align - 1)/_Align * _Align]; + }; +}; + +#if _LIBCPP_STD_VER > 11 +template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value> + using aligned_storage_t = typename aligned_storage<_Len, _Align>::type; +#endif + +#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \ +template <size_t _Len>\ +struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\ +{\ + struct _ALIGNAS(n) type\ + {\ + unsigned char __lx[(_Len + n - 1)/n * n];\ + };\ +} + +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000); +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000); +// PE/COFF does not support alignment beyond 8192 (=0x2000) +#if !defined(_LIBCPP_OBJECT_FORMAT_COFF) +_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000); +#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF) + +#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +// aligned_union + +template <size_t _I0, size_t ..._In> +struct __static_max; + +template <size_t _I0> +struct __static_max<_I0> +{ + static const size_t value = _I0; +}; + +template <size_t _I0, size_t _I1, size_t ..._In> +struct __static_max<_I0, _I1, _In...> +{ + static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value : + __static_max<_I1, _In...>::value; +}; + +template <size_t _Len, class _Type0, class ..._Types> +struct aligned_union +{ + static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0), + _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value; + static const size_t __len = __static_max<_Len, sizeof(_Type0), + sizeof(_Types)...>::value; + typedef typename aligned_storage<__len, alignment_value>::type type; +}; + +#if _LIBCPP_STD_VER > 11 +template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type; +#endif + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template <class _Tp> +struct __numeric_type +{ + static void __test(...); + static float __test(float); + static double __test(char); + static double __test(int); + static double __test(unsigned); + static double __test(long); + static double __test(unsigned long); + static double __test(long long); + static double __test(unsigned long long); + static double __test(double); + static long double __test(long double); + + typedef decltype(__test(declval<_Tp>())) type; + static const bool value = !is_same<type, void>::value; +}; + +template <> +struct __numeric_type<void> +{ + static const bool value = true; +}; + +// __promote + +template <class _A1, class _A2 = void, class _A3 = void, + bool = __numeric_type<_A1>::value && + __numeric_type<_A2>::value && + __numeric_type<_A3>::value> +class __promote_imp +{ +public: + static const bool value = false; +}; + +template <class _A1, class _A2, class _A3> +class __promote_imp<_A1, _A2, _A3, true> +{ +private: + typedef typename __promote_imp<_A1>::type __type1; + typedef typename __promote_imp<_A2>::type __type2; + typedef typename __promote_imp<_A3>::type __type3; +public: + typedef decltype(__type1() + __type2() + __type3()) type; + static const bool value = true; +}; + +template <class _A1, class _A2> +class __promote_imp<_A1, _A2, void, true> +{ +private: + typedef typename __promote_imp<_A1>::type __type1; + typedef typename __promote_imp<_A2>::type __type2; +public: + typedef decltype(__type1() + __type2()) type; + static const bool value = true; +}; + +template <class _A1> +class __promote_imp<_A1, void, void, true> +{ +public: + typedef typename __numeric_type<_A1>::type type; + static const bool value = true; +}; + +template <class _A1, class _A2 = void, class _A3 = void> +class __promote : public __promote_imp<_A1, _A2, _A3> {}; + +// make_signed / make_unsigned + +typedef + __type_list<signed char, + __type_list<signed short, + __type_list<signed int, + __type_list<signed long, + __type_list<signed long long, +#ifndef _LIBCPP_HAS_NO_INT128 + __type_list<__int128_t, +#endif + __nat +#ifndef _LIBCPP_HAS_NO_INT128 + > +#endif + > > > > > __signed_types; + +typedef + __type_list<unsigned char, + __type_list<unsigned short, + __type_list<unsigned int, + __type_list<unsigned long, + __type_list<unsigned long long, +#ifndef _LIBCPP_HAS_NO_INT128 + __type_list<__uint128_t, +#endif + __nat +#ifndef _LIBCPP_HAS_NO_INT128 + > +#endif + > > > > > __unsigned_types; + +template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first; + +template <class _Hp, class _Tp, size_t _Size> +struct __find_first<__type_list<_Hp, _Tp>, _Size, true> +{ + typedef _Hp type; +}; + +template <class _Hp, class _Tp, size_t _Size> +struct __find_first<__type_list<_Hp, _Tp>, _Size, false> +{ + typedef typename __find_first<_Tp, _Size>::type type; +}; + +template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value, + bool = is_volatile<typename remove_reference<_Tp>::type>::value> +struct __apply_cv +{ + typedef _Up type; +}; + +template <class _Tp, class _Up> +struct __apply_cv<_Tp, _Up, true, false> +{ + typedef const _Up type; +}; + +template <class _Tp, class _Up> +struct __apply_cv<_Tp, _Up, false, true> +{ + typedef volatile _Up type; +}; + +template <class _Tp, class _Up> +struct __apply_cv<_Tp, _Up, true, true> +{ + typedef const volatile _Up type; +}; + +template <class _Tp, class _Up> +struct __apply_cv<_Tp&, _Up, false, false> +{ + typedef _Up& type; +}; + +template <class _Tp, class _Up> +struct __apply_cv<_Tp&, _Up, true, false> +{ + typedef const _Up& type; +}; + +template <class _Tp, class _Up> +struct __apply_cv<_Tp&, _Up, false, true> +{ + typedef volatile _Up& type; +}; + +template <class _Tp, class _Up> +struct __apply_cv<_Tp&, _Up, true, true> +{ + typedef const volatile _Up& type; +}; + +template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value> +struct __make_signed {}; + +template <class _Tp> +struct __make_signed<_Tp, true> +{ + typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type; +}; + +template <> struct __make_signed<bool, true> {}; +template <> struct __make_signed< signed short, true> {typedef short type;}; +template <> struct __make_signed<unsigned short, true> {typedef short type;}; +template <> struct __make_signed< signed int, true> {typedef int type;}; +template <> struct __make_signed<unsigned int, true> {typedef int type;}; +template <> struct __make_signed< signed long, true> {typedef long type;}; +template <> struct __make_signed<unsigned long, true> {typedef long type;}; +template <> struct __make_signed< signed long long, true> {typedef long long type;}; +template <> struct __make_signed<unsigned long long, true> {typedef long long type;}; +#ifndef _LIBCPP_HAS_NO_INT128 +template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;}; +template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;}; +#endif + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS make_signed +{ + typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type; +}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type; +#endif + +template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value> +struct __make_unsigned {}; + +template <class _Tp> +struct __make_unsigned<_Tp, true> +{ + typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type; +}; + +template <> struct __make_unsigned<bool, true> {}; +template <> struct __make_unsigned< signed short, true> {typedef unsigned short type;}; +template <> struct __make_unsigned<unsigned short, true> {typedef unsigned short type;}; +template <> struct __make_unsigned< signed int, true> {typedef unsigned int type;}; +template <> struct __make_unsigned<unsigned int, true> {typedef unsigned int type;}; +template <> struct __make_unsigned< signed long, true> {typedef unsigned long type;}; +template <> struct __make_unsigned<unsigned long, true> {typedef unsigned long type;}; +template <> struct __make_unsigned< signed long long, true> {typedef unsigned long long type;}; +template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;}; +#ifndef _LIBCPP_HAS_NO_INT128 +template <> struct __make_unsigned<__int128_t, true> {typedef __uint128_t type;}; +template <> struct __make_unsigned<__uint128_t, true> {typedef __uint128_t type;}; +#endif + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS make_unsigned +{ + typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type; +}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type; +#endif + +template <class _Tp, class _Up, class = void> +struct __common_type2_imp {}; + +template <class _Tp, class _Up> +struct __common_type2_imp<_Tp, _Up, + typename __void_t<decltype( + true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>() + )>::type> +{ + typedef typename decay<decltype( + true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>() + )>::type type; +}; + +template <class, class = void> +struct __common_type_impl {}; + +// Clang provides variadic templates in C++03 as an extension. +#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__) +# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__ +template <class... Tp> +struct __common_types; +template <class... _Tp> +struct _LIBCPP_TEMPLATE_VIS common_type; +#else +# define _LIBCPP_OPTIONAL_PACK(...) +struct __no_arg; +template <class _Tp, class _Up, class = __no_arg> +struct __common_types; +template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg, + class _Unused = __no_arg> +struct common_type { + static_assert(sizeof(_Unused) == 0, + "common_type accepts at most 3 arguments in C++03"); +}; +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Up> +struct __common_type_impl< + __common_types<_Tp, _Up>, + typename __void_t<typename common_type<_Tp, _Up>::type>::type> +{ + typedef typename common_type<_Tp, _Up>::type type; +}; + +template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)> +struct __common_type_impl< + __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>, + typename __void_t<typename common_type<_Tp, _Up>::type>::type> + : __common_type_impl<__common_types<typename common_type<_Tp, _Up>::type, + _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > { +}; + +// bullet 1 - sizeof...(Tp) == 0 + +template <> +struct _LIBCPP_TEMPLATE_VIS common_type<> {}; + +// bullet 2 - sizeof...(Tp) == 1 + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS common_type<_Tp> + : public common_type<_Tp, _Tp> {}; + +// bullet 3 - sizeof...(Tp) == 2 + +template <class _Tp, class _Up> +struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up> + : conditional< + is_same<_Tp, typename decay<_Tp>::type>::value && is_same<_Up, typename decay<_Up>::type>::value, + __common_type2_imp<_Tp, _Up>, + common_type<typename decay<_Tp>::type, typename decay<_Up>::type> + >::type +{}; + +// bullet 4 - sizeof...(Tp) > 2 + +template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)> +struct _LIBCPP_TEMPLATE_VIS + common_type<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> + : __common_type_impl< + __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {}; + +#undef _LIBCPP_OPTIONAL_PACK + +#if _LIBCPP_STD_VER > 11 +template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type; +#endif + +// is_assignable + +template<typename, typename _Tp> struct __select_2nd { typedef _Tp type; }; + +template <class _Tp, class _Arg> +typename __select_2nd<decltype((_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>())), true_type>::type +__is_assignable_test(int); + +template <class, class> +false_type __is_assignable_test(...); + + +template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value> +struct __is_assignable_imp + : public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {}; + +template <class _Tp, class _Arg> +struct __is_assignable_imp<_Tp, _Arg, true> + : public false_type +{ +}; + +template <class _Tp, class _Arg> +struct is_assignable + : public __is_assignable_imp<_Tp, _Arg> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp, class _Arg> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_assignable_v + = is_assignable<_Tp, _Arg>::value; +#endif + +// is_copy_assignable + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable + : public is_assignable<typename add_lvalue_reference<_Tp>::type, + typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_assignable_v + = is_copy_assignable<_Tp>::value; +#endif + +// is_move_assignable + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + : public is_assignable<typename add_lvalue_reference<_Tp>::type, + typename add_rvalue_reference<_Tp>::type> {}; +#else + : public is_copy_assignable<_Tp> {}; +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_assignable_v + = is_move_assignable<_Tp>::value; +#endif + +// is_destructible + +// if it's a reference, return true +// if it's a function, return false +// if it's void, return false +// if it's an array of unknown bound, return false +// Otherwise, return "std::declval<_Up&>().~_Up()" is well-formed +// where _Up is remove_all_extents<_Tp>::type + +template <class> +struct __is_destructible_apply { typedef int type; }; + +template <typename _Tp> +struct __is_destructor_wellformed { + template <typename _Tp1> + static char __test ( + typename __is_destructible_apply<decltype(_VSTD::declval<_Tp1&>().~_Tp1())>::type + ); + + template <typename _Tp1> + static __two __test (...); + + static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char); +}; + +template <class _Tp, bool> +struct __destructible_imp; + +template <class _Tp> +struct __destructible_imp<_Tp, false> + : public _VSTD::integral_constant<bool, + __is_destructor_wellformed<typename _VSTD::remove_all_extents<_Tp>::type>::value> {}; + +template <class _Tp> +struct __destructible_imp<_Tp, true> + : public _VSTD::true_type {}; + +template <class _Tp, bool> +struct __destructible_false; + +template <class _Tp> +struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, _VSTD::is_reference<_Tp>::value> {}; + +template <class _Tp> +struct __destructible_false<_Tp, true> : public _VSTD::false_type {}; + +template <class _Tp> +struct is_destructible + : public __destructible_false<_Tp, _VSTD::is_function<_Tp>::value> {}; + +template <class _Tp> +struct is_destructible<_Tp[]> + : public _VSTD::false_type {}; + +template <> +struct is_destructible<void> + : public _VSTD::false_type {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v + = is_destructible<_Tp>::value; +#endif + +// move + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename remove_reference<_Tp>::type&& +move(_Tp&& __t) _NOEXCEPT +{ + typedef typename remove_reference<_Tp>::type _Up; + return static_cast<_Up&&>(__t); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +_Tp&& +forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT +{ + return static_cast<_Tp&&>(__t); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +_Tp&& +forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT +{ + static_assert(!is_lvalue_reference<_Tp>::value, + "can not forward an rvalue as an lvalue"); + return static_cast<_Tp&&>(__t); +} + +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp& +move(_Tp& __t) +{ + return __t; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +const _Tp& +move(const _Tp& __t) +{ + return __t; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp& +forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT +{ + return __t; +} + + +template <class _Tp> +class __rv +{ + typedef typename remove_reference<_Tp>::type _Trr; + _Trr& t_; +public: + _LIBCPP_INLINE_VISIBILITY + _Trr* operator->() {return &t_;} + _LIBCPP_INLINE_VISIBILITY + explicit __rv(_Trr& __t) : t_(__t) {} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename decay<_Tp>::type +__decay_copy(_Tp&& __t) +{ + return _VSTD::forward<_Tp>(__t); +} + +#else + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename decay<_Tp>::type +__decay_copy(const _Tp& __t) +{ + return _VSTD::forward<_Tp>(__t); +} + +#endif + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +#if __has_feature(cxx_reference_qualified_functions) || \ + (defined(_GNUC_VER) && _GNUC_VER >= 409) + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false> +{ + typedef _Class& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false> +{ + typedef _Class& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false> +{ + typedef _Class const& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false> +{ + typedef _Class const& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false> +{ + typedef _Class volatile& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false> +{ + typedef _Class volatile& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false> +{ + typedef _Class const volatile& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false> +{ + typedef _Class const volatile& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false> +{ + typedef _Class&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false> +{ + typedef _Class&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false> +{ + typedef _Class const&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false> +{ + typedef _Class const&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false> +{ + typedef _Class volatile&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false> +{ + typedef _Class volatile&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false> +{ + typedef _Class const volatile&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param...); +}; + +template <class _Rp, class _Class, class ..._Param> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false> +{ + typedef _Class const volatile&& _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_Param..., ...); +}; + +#endif // __has_feature(cxx_reference_qualified_functions) || _GNUC_VER >= 409 + +#else // _LIBCPP_HAS_NO_VARIADICS + +template <class _Rp, class _Class> +struct __member_pointer_traits_imp<_Rp (_Class::*)(), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (); +}; + +template <class _Rp, class _Class> +struct __member_pointer_traits_imp<_Rp (_Class::*)(...), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (...); +}; + +template <class _Rp, class _Class, class _P0> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0); +}; + +template <class _Rp, class _Class, class _P0> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, ...); +}; + +template <class _Rp, class _Class, class _P0, class _P1> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1); +}; + +template <class _Rp, class _Class, class _P0, class _P1> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, ...); +}; + +template <class _Rp, class _Class, class _P0, class _P1, class _P2> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, _P2); +}; + +template <class _Rp, class _Class, class _P0, class _P1, class _P2> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...), true, false> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, _P2, ...); +}; + +template <class _Rp, class _Class> +struct __member_pointer_traits_imp<_Rp (_Class::*)() const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (); +}; + +template <class _Rp, class _Class> +struct __member_pointer_traits_imp<_Rp (_Class::*)(...) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (...); +}; + +template <class _Rp, class _Class, class _P0> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0); +}; + +template <class _Rp, class _Class, class _P0> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, ...); +}; + +template <class _Rp, class _Class, class _P0, class _P1> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1); +}; + +template <class _Rp, class _Class, class _P0, class _P1> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, ...); +}; + +template <class _Rp, class _Class, class _P0, class _P1, class _P2> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, _P2); +}; + +template <class _Rp, class _Class, class _P0, class _P1, class _P2> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const, true, false> +{ + typedef _Class const _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, _P2, ...); +}; + +template <class _Rp, class _Class> +struct __member_pointer_traits_imp<_Rp (_Class::*)() volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (); +}; + +template <class _Rp, class _Class> +struct __member_pointer_traits_imp<_Rp (_Class::*)(...) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (...); +}; + +template <class _Rp, class _Class, class _P0> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0); +}; + +template <class _Rp, class _Class, class _P0> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, ...); +}; + +template <class _Rp, class _Class, class _P0, class _P1> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1); +}; + +template <class _Rp, class _Class, class _P0, class _P1> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, ...); +}; + +template <class _Rp, class _Class, class _P0, class _P1, class _P2> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, _P2); +}; + +template <class _Rp, class _Class, class _P0, class _P1, class _P2> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) volatile, true, false> +{ + typedef _Class volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, _P2, ...); +}; + +template <class _Rp, class _Class> +struct __member_pointer_traits_imp<_Rp (_Class::*)() const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (); +}; + +template <class _Rp, class _Class> +struct __member_pointer_traits_imp<_Rp (_Class::*)(...) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (...); +}; + +template <class _Rp, class _Class, class _P0> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0); +}; + +template <class _Rp, class _Class, class _P0> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, ...); +}; + +template <class _Rp, class _Class, class _P0, class _P1> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1); +}; + +template <class _Rp, class _Class, class _P0, class _P1> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, ...); +}; + +template <class _Rp, class _Class, class _P0, class _P1, class _P2> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, _P2); +}; + +template <class _Rp, class _Class, class _P0, class _P1, class _P2> +struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const volatile, true, false> +{ + typedef _Class const volatile _ClassType; + typedef _Rp _ReturnType; + typedef _Rp (_FnType) (_P0, _P1, _P2, ...); +}; + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template <class _Rp, class _Class> +struct __member_pointer_traits_imp<_Rp _Class::*, false, true> +{ + typedef _Class _ClassType; + typedef _Rp _ReturnType; +}; + +template <class _MP> +struct __member_pointer_traits + : public __member_pointer_traits_imp<typename remove_cv<_MP>::type, + is_member_function_pointer<_MP>::value, + is_member_object_pointer<_MP>::value> +{ +// typedef ... _ClassType; +// typedef ... _ReturnType; +// typedef ... _FnType; +}; + + +template <class _DecayedFp> +struct __member_pointer_class_type {}; + +template <class _Ret, class _ClassType> +struct __member_pointer_class_type<_Ret _ClassType::*> { + typedef _ClassType type; +}; + +// result_of + +template <class _Callable> class result_of; + +#ifdef _LIBCPP_HAS_NO_VARIADICS + +template <class _Fn, bool, bool> +class __result_of +{ +}; + +template <class _Fn> +class __result_of<_Fn(), true, false> +{ +public: + typedef decltype(declval<_Fn>()()) type; +}; + +template <class _Fn, class _A0> +class __result_of<_Fn(_A0), true, false> +{ +public: + typedef decltype(declval<_Fn>()(declval<_A0>())) type; +}; + +template <class _Fn, class _A0, class _A1> +class __result_of<_Fn(_A0, _A1), true, false> +{ +public: + typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type; +}; + +template <class _Fn, class _A0, class _A1, class _A2> +class __result_of<_Fn(_A0, _A1, _A2), true, false> +{ +public: + typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type; +}; + +template <class _MP, class _Tp, bool _IsMemberFunctionPtr> +struct __result_of_mp; + +// member function pointer + +template <class _MP, class _Tp> +struct __result_of_mp<_MP, _Tp, true> + : public __identity<typename __member_pointer_traits<_MP>::_ReturnType> +{ +}; + +// member data pointer + +template <class _MP, class _Tp, bool> +struct __result_of_mdp; + +template <class _Rp, class _Class, class _Tp> +struct __result_of_mdp<_Rp _Class::*, _Tp, false> +{ + typedef typename __apply_cv<decltype(*_VSTD::declval<_Tp>()), _Rp>::type& type; +}; + +template <class _Rp, class _Class, class _Tp> +struct __result_of_mdp<_Rp _Class::*, _Tp, true> +{ + typedef typename __apply_cv<_Tp, _Rp>::type& type; +}; + +template <class _Rp, class _Class, class _Tp> +struct __result_of_mp<_Rp _Class::*, _Tp, false> + : public __result_of_mdp<_Rp _Class::*, _Tp, + is_base_of<_Class, typename remove_reference<_Tp>::type>::value> +{ +}; + + + +template <class _Fn, class _Tp> +class __result_of<_Fn(_Tp), false, true> // _Fn must be member pointer + : public __result_of_mp<typename remove_reference<_Fn>::type, + _Tp, + is_member_function_pointer<typename remove_reference<_Fn>::type>::value> +{ +}; + +template <class _Fn, class _Tp, class _A0> +class __result_of<_Fn(_Tp, _A0), false, true> // _Fn must be member pointer + : public __result_of_mp<typename remove_reference<_Fn>::type, + _Tp, + is_member_function_pointer<typename remove_reference<_Fn>::type>::value> +{ +}; + +template <class _Fn, class _Tp, class _A0, class _A1> +class __result_of<_Fn(_Tp, _A0, _A1), false, true> // _Fn must be member pointer + : public __result_of_mp<typename remove_reference<_Fn>::type, + _Tp, + is_member_function_pointer<typename remove_reference<_Fn>::type>::value> +{ +}; + +template <class _Fn, class _Tp, class _A0, class _A1, class _A2> +class __result_of<_Fn(_Tp, _A0, _A1, _A2), false, true> // _Fn must be member pointer + : public __result_of_mp<typename remove_reference<_Fn>::type, + _Tp, + is_member_function_pointer<typename remove_reference<_Fn>::type>::value> +{ +}; + +// result_of + +template <class _Fn> +class _LIBCPP_TEMPLATE_VIS result_of<_Fn()> + : public __result_of<_Fn(), + is_class<typename remove_reference<_Fn>::type>::value || + is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value, + is_member_pointer<typename remove_reference<_Fn>::type>::value + > +{ +}; + +template <class _Fn, class _A0> +class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0)> + : public __result_of<_Fn(_A0), + is_class<typename remove_reference<_Fn>::type>::value || + is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value, + is_member_pointer<typename remove_reference<_Fn>::type>::value + > +{ +}; + +template <class _Fn, class _A0, class _A1> +class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0, _A1)> + : public __result_of<_Fn(_A0, _A1), + is_class<typename remove_reference<_Fn>::type>::value || + is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value, + is_member_pointer<typename remove_reference<_Fn>::type>::value + > +{ +}; + +template <class _Fn, class _A0, class _A1, class _A2> +class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0, _A1, _A2)> + : public __result_of<_Fn(_A0, _A1, _A2), + is_class<typename remove_reference<_Fn>::type>::value || + is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value, + is_member_pointer<typename remove_reference<_Fn>::type>::value + > +{ +}; + +#endif // _LIBCPP_HAS_NO_VARIADICS + +// template <class T, class... Args> struct is_constructible; + +namespace __is_construct +{ +struct __nat {}; +} + +#if !defined(_LIBCPP_CXX03_LANG) && (!__has_feature(is_constructible) || \ + defined(_LIBCPP_TESTING_FALLBACK_IS_CONSTRUCTIBLE)) + +template <class _Tp, class... _Args> +struct __libcpp_is_constructible; + +template <class _To, class _From> +struct __is_invalid_base_to_derived_cast { + static_assert(is_reference<_To>::value, "Wrong specialization"); + using _RawFrom = __uncvref_t<_From>; + using _RawTo = __uncvref_t<_To>; + static const bool value = __lazy_and< + __lazy_not<is_same<_RawFrom, _RawTo>>, + is_base_of<_RawFrom, _RawTo>, + __lazy_not<__libcpp_is_constructible<_RawTo, _From>> + >::value; +}; + +template <class _To, class _From> +struct __is_invalid_lvalue_to_rvalue_cast : false_type { + static_assert(is_reference<_To>::value, "Wrong specialization"); +}; + +template <class _ToRef, class _FromRef> +struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> { + using _RawFrom = __uncvref_t<_FromRef>; + using _RawTo = __uncvref_t<_ToRef>; + static const bool value = __lazy_and< + __lazy_not<is_function<_RawTo>>, + __lazy_or< + is_same<_RawFrom, _RawTo>, + is_base_of<_RawTo, _RawFrom>> + >::value; +}; + +struct __is_constructible_helper +{ + template <class _To> + static void __eat(_To); + + // This overload is needed to work around a Clang bug that disallows + // static_cast<T&&>(e) for non-reference-compatible types. + // Example: static_cast<int&&>(declval<double>()); + // NOTE: The static_cast implementation below is required to support + // classes with explicit conversion operators. + template <class _To, class _From, + class = decltype(__eat<_To>(_VSTD::declval<_From>()))> + static true_type __test_cast(int); + + template <class _To, class _From, + class = decltype(static_cast<_To>(_VSTD::declval<_From>()))> + static integral_constant<bool, + !__is_invalid_base_to_derived_cast<_To, _From>::value && + !__is_invalid_lvalue_to_rvalue_cast<_To, _From>::value + > __test_cast(long); + + template <class, class> + static false_type __test_cast(...); + + template <class _Tp, class ..._Args, + class = decltype(_Tp(_VSTD::declval<_Args>()...))> + static true_type __test_nary(int); + template <class _Tp, class...> + static false_type __test_nary(...); + + template <class _Tp, class _A0, class = decltype(::new _Tp(_VSTD::declval<_A0>()))> + static is_destructible<_Tp> __test_unary(int); + template <class, class> + static false_type __test_unary(...); +}; + +template <class _Tp, bool = is_void<_Tp>::value> +struct __is_default_constructible + : decltype(__is_constructible_helper::__test_nary<_Tp>(0)) +{}; + +template <class _Tp> +struct __is_default_constructible<_Tp, true> : false_type {}; + +template <class _Tp> +struct __is_default_constructible<_Tp[], false> : false_type {}; + +template <class _Tp, size_t _Nx> +struct __is_default_constructible<_Tp[_Nx], false> + : __is_default_constructible<typename remove_all_extents<_Tp>::type> {}; + +template <class _Tp, class... _Args> +struct __libcpp_is_constructible +{ + static_assert(sizeof...(_Args) > 1, "Wrong specialization"); + typedef decltype(__is_constructible_helper::__test_nary<_Tp, _Args...>(0)) + type; +}; + +template <class _Tp> +struct __libcpp_is_constructible<_Tp> : __is_default_constructible<_Tp> {}; + +template <class _Tp, class _A0> +struct __libcpp_is_constructible<_Tp, _A0> + : public decltype(__is_constructible_helper::__test_unary<_Tp, _A0>(0)) +{}; + +template <class _Tp, class _A0> +struct __libcpp_is_constructible<_Tp&, _A0> + : public decltype(__is_constructible_helper:: + __test_cast<_Tp&, _A0>(0)) +{}; + +template <class _Tp, class _A0> +struct __libcpp_is_constructible<_Tp&&, _A0> + : public decltype(__is_constructible_helper:: + __test_cast<_Tp&&, _A0>(0)) +{}; + +#endif + +#if __has_feature(is_constructible) +template <class _Tp, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_constructible + : public integral_constant<bool, __is_constructible(_Tp, _Args...)> + {}; +#elif !defined(_LIBCPP_CXX03_LANG) +template <class _Tp, class... _Args> +struct _LIBCPP_TEMPLATE_VIS is_constructible + : public __libcpp_is_constructible<_Tp, _Args...>::type {}; +#else +// template <class T> struct is_constructible0; + +// main is_constructible0 test + +template <class _Tp> +decltype((_Tp(), true_type())) +__is_constructible0_test(_Tp&); + +false_type +__is_constructible0_test(__any); + +template <class _Tp, class _A0> +decltype((_Tp(_VSTD::declval<_A0>()), true_type())) +__is_constructible1_test(_Tp&, _A0&); + +template <class _A0> +false_type +__is_constructible1_test(__any, _A0&); + +template <class _Tp, class _A0, class _A1> +decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>()), true_type())) +__is_constructible2_test(_Tp&, _A0&, _A1&); + +template <class _A0, class _A1> +false_type +__is_constructible2_test(__any, _A0&, _A1&); + +template <class _Tp, class _A0, class _A1, class _A2> +decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>(), _VSTD::declval<_A2>()), true_type())) +__is_constructible3_test(_Tp&, _A0&, _A1&, _A2&); + +template <class _A0, class _A1, class _A2> +false_type +__is_constructible3_test(__any, _A0&, _A1&, _A2&); + +template <bool, class _Tp> +struct __is_constructible0_imp // false, _Tp is not a scalar + : public common_type + < + decltype(__is_constructible0_test(declval<_Tp&>())) + >::type + {}; + +template <bool, class _Tp, class _A0> +struct __is_constructible1_imp // false, _Tp is not a scalar + : public common_type + < + decltype(__is_constructible1_test(declval<_Tp&>(), declval<_A0&>())) + >::type + {}; + +template <bool, class _Tp, class _A0, class _A1> +struct __is_constructible2_imp // false, _Tp is not a scalar + : public common_type + < + decltype(__is_constructible2_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>())) + >::type + {}; + +template <bool, class _Tp, class _A0, class _A1, class _A2> +struct __is_constructible3_imp // false, _Tp is not a scalar + : public common_type + < + decltype(__is_constructible3_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>(), declval<_A2>())) + >::type + {}; + +// handle scalars and reference types + +// Scalars are default constructible, references are not + +template <class _Tp> +struct __is_constructible0_imp<true, _Tp> + : public is_scalar<_Tp> + {}; + +template <class _Tp, class _A0> +struct __is_constructible1_imp<true, _Tp, _A0> + : public is_convertible<_A0, _Tp> + {}; + +template <class _Tp, class _A0, class _A1> +struct __is_constructible2_imp<true, _Tp, _A0, _A1> + : public false_type + {}; + +template <class _Tp, class _A0, class _A1, class _A2> +struct __is_constructible3_imp<true, _Tp, _A0, _A1, _A2> + : public false_type + {}; + +// Treat scalars and reference types separately + +template <bool, class _Tp> +struct __is_constructible0_void_check + : public __is_constructible0_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, + _Tp> + {}; + +template <bool, class _Tp, class _A0> +struct __is_constructible1_void_check + : public __is_constructible1_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, + _Tp, _A0> + {}; + +template <bool, class _Tp, class _A0, class _A1> +struct __is_constructible2_void_check + : public __is_constructible2_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, + _Tp, _A0, _A1> + {}; + +template <bool, class _Tp, class _A0, class _A1, class _A2> +struct __is_constructible3_void_check + : public __is_constructible3_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, + _Tp, _A0, _A1, _A2> + {}; + +// If any of T or Args is void, is_constructible should be false + +template <class _Tp> +struct __is_constructible0_void_check<true, _Tp> + : public false_type + {}; + +template <class _Tp, class _A0> +struct __is_constructible1_void_check<true, _Tp, _A0> + : public false_type + {}; + +template <class _Tp, class _A0, class _A1> +struct __is_constructible2_void_check<true, _Tp, _A0, _A1> + : public false_type + {}; + +template <class _Tp, class _A0, class _A1, class _A2> +struct __is_constructible3_void_check<true, _Tp, _A0, _A1, _A2> + : public false_type + {}; + +// is_constructible entry point + +template <class _Tp, class _A0 = __is_construct::__nat, + class _A1 = __is_construct::__nat, + class _A2 = __is_construct::__nat> +struct _LIBCPP_TEMPLATE_VIS is_constructible + : public __is_constructible3_void_check<is_void<_Tp>::value + || is_abstract<_Tp>::value + || is_function<_Tp>::value + || is_void<_A0>::value + || is_void<_A1>::value + || is_void<_A2>::value, + _Tp, _A0, _A1, _A2> + {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat> + : public __is_constructible0_void_check<is_void<_Tp>::value + || is_abstract<_Tp>::value + || is_function<_Tp>::value, + _Tp> + {}; + +template <class _Tp, class _A0> +struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, _A0, __is_construct::__nat> + : public __is_constructible1_void_check<is_void<_Tp>::value + || is_abstract<_Tp>::value + || is_function<_Tp>::value + || is_void<_A0>::value, + _Tp, _A0> + {}; + +template <class _Tp, class _A0, class _A1> +struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, _A0, _A1, __is_construct::__nat> + : public __is_constructible2_void_check<is_void<_Tp>::value + || is_abstract<_Tp>::value + || is_function<_Tp>::value + || is_void<_A0>::value + || is_void<_A1>::value, + _Tp, _A0, _A1> + {}; + +// Array types are default constructible if their element type +// is default constructible + +template <class _Ap, size_t _Np> +struct __is_constructible0_imp<false, _Ap[_Np]> + : public is_constructible<typename remove_all_extents<_Ap>::type> + {}; + +template <class _Ap, size_t _Np, class _A0> +struct __is_constructible1_imp<false, _Ap[_Np], _A0> + : public false_type + {}; + +template <class _Ap, size_t _Np, class _A0, class _A1> +struct __is_constructible2_imp<false, _Ap[_Np], _A0, _A1> + : public false_type + {}; + +template <class _Ap, size_t _Np, class _A0, class _A1, class _A2> +struct __is_constructible3_imp<false, _Ap[_Np], _A0, _A1, _A2> + : public false_type + {}; + +// Incomplete array types are not constructible + +template <class _Ap> +struct __is_constructible0_imp<false, _Ap[]> + : public false_type + {}; + +template <class _Ap, class _A0> +struct __is_constructible1_imp<false, _Ap[], _A0> + : public false_type + {}; + +template <class _Ap, class _A0, class _A1> +struct __is_constructible2_imp<false, _Ap[], _A0, _A1> + : public false_type + {}; + +template <class _Ap, class _A0, class _A1, class _A2> +struct __is_constructible3_imp<false, _Ap[], _A0, _A1, _A2> + : public false_type + {}; + +#endif // __has_feature(is_constructible) + + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +template <class _Tp, class ..._Args> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_constructible_v + = is_constructible<_Tp, _Args...>::value; +#endif + +// is_default_constructible + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_default_constructible + : public is_constructible<_Tp> + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_default_constructible_v + = is_default_constructible<_Tp>::value; +#endif + +// is_copy_constructible + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_copy_constructible + : public is_constructible<_Tp, + typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_constructible_v + = is_copy_constructible<_Tp>::value; +#endif + +// is_move_constructible + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_move_constructible +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type> +#else + : public is_copy_constructible<_Tp> +#endif + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_constructible_v + = is_move_constructible<_Tp>::value; +#endif + +// is_trivially_constructible + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +#if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501 + +template <class _Tp, class... _Args> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible + : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)> +{ +}; + +#else // !__has_feature(is_trivially_constructible) + +template <class _Tp, class... _Args> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible + : false_type +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp> +#if __has_feature(has_trivial_constructor) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_trivial_constructor(_Tp)> +#else + : integral_constant<bool, is_scalar<_Tp>::value> +#endif +{ +}; + +template <class _Tp> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&&> +#else +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp> +#endif + : integral_constant<bool, is_scalar<_Tp>::value> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&> + : integral_constant<bool, is_scalar<_Tp>::value> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&> + : integral_constant<bool, is_scalar<_Tp>::value> +{ +}; + +#endif // !__has_feature(is_trivially_constructible) + +#else // _LIBCPP_HAS_NO_VARIADICS + +template <class _Tp, class _A0 = __is_construct::__nat, + class _A1 = __is_construct::__nat> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible + : false_type +{ +}; + +#if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501 + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, __is_construct::__nat, + __is_construct::__nat> + : integral_constant<bool, __is_trivially_constructible(_Tp)> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp, + __is_construct::__nat> + : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&, + __is_construct::__nat> + : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&, + __is_construct::__nat> + : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)> +{ +}; + +#else // !__has_feature(is_trivially_constructible) + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, __is_construct::__nat, + __is_construct::__nat> + : integral_constant<bool, is_scalar<_Tp>::value> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp, + __is_construct::__nat> + : integral_constant<bool, is_scalar<_Tp>::value> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&, + __is_construct::__nat> + : integral_constant<bool, is_scalar<_Tp>::value> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&, + __is_construct::__nat> + : integral_constant<bool, is_scalar<_Tp>::value> +{ +}; + +#endif // !__has_feature(is_trivially_constructible) + +#endif // _LIBCPP_HAS_NO_VARIADICS + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +template <class _Tp, class... _Args> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_constructible_v + = is_trivially_constructible<_Tp, _Args...>::value; +#endif + +// is_trivially_default_constructible + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible + : public is_trivially_constructible<_Tp> + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_default_constructible_v + = is_trivially_default_constructible<_Tp>::value; +#endif + +// is_trivially_copy_constructible + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible + : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type> + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v + = is_trivially_copy_constructible<_Tp>::value; +#endif + +// is_trivially_move_constructible + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type> +#else + : public is_trivially_copy_constructible<_Tp> +#endif + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_constructible_v + = is_trivially_move_constructible<_Tp>::value; +#endif + +// is_trivially_assignable + +#if __has_feature(is_trivially_assignable) || _GNUC_VER >= 501 + +template <class _Tp, class _Arg> +struct is_trivially_assignable + : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)> +{ +}; + +#else // !__has_feature(is_trivially_assignable) + +template <class _Tp, class _Arg> +struct is_trivially_assignable + : public false_type {}; + +template <class _Tp> +struct is_trivially_assignable<_Tp&, _Tp> + : integral_constant<bool, is_scalar<_Tp>::value> {}; + +template <class _Tp> +struct is_trivially_assignable<_Tp&, _Tp&> + : integral_constant<bool, is_scalar<_Tp>::value> {}; + +template <class _Tp> +struct is_trivially_assignable<_Tp&, const _Tp&> + : integral_constant<bool, is_scalar<_Tp>::value> {}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp> +struct is_trivially_assignable<_Tp&, _Tp&&> + : integral_constant<bool, is_scalar<_Tp>::value> {}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // !__has_feature(is_trivially_assignable) + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp, class _Arg> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_assignable_v + = is_trivially_assignable<_Tp, _Arg>::value; +#endif + +// is_trivially_copy_assignable + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable + : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type, + typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v + = is_trivially_copy_assignable<_Tp>::value; +#endif + +// is_trivially_move_assignable + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable + : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type, +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + typename add_rvalue_reference<_Tp>::type> +#else + typename add_lvalue_reference<_Tp>::type> +#endif + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v + = is_trivially_move_assignable<_Tp>::value; +#endif + +// is_trivially_destructible + +#if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible + : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {}; + +#else + +template <class _Tp> struct __libcpp_trivial_destructor + : public integral_constant<bool, is_scalar<_Tp>::value || + is_reference<_Tp>::value> {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible + : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]> + : public false_type {}; + +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_destructible_v + = is_trivially_destructible<_Tp>::value; +#endif + +// is_nothrow_constructible + +#if 0 +template <class _Tp, class... _Args> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible + : public integral_constant<bool, __is_nothrow_constructible(_Tp(_Args...))> +{ +}; + +#else + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) + +template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible; + +template <class _Tp, class... _Args> +struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...> + : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))> +{ +}; + +template <class _Tp> +void __implicit_conversion_to(_Tp) noexcept { } + +template <class _Tp, class _Arg> +struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg> + : public integral_constant<bool, noexcept(__implicit_conversion_to<_Tp>(declval<_Arg>()))> +{ +}; + +template <class _Tp, bool _IsReference, class... _Args> +struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...> + : public false_type +{ +}; + +template <class _Tp, class... _Args> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible + : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...> +{ +}; + +template <class _Tp, size_t _Ns> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]> + : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp> +{ +}; + +#else // __has_feature(cxx_noexcept) + +template <class _Tp, class... _Args> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible + : false_type +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp> +#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_constructor(_Tp)> +#else + : integral_constant<bool, is_scalar<_Tp>::value> +#endif +{ +}; + +template <class _Tp> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&&> +#else +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp> +#endif +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_copy(_Tp)> +#else + : integral_constant<bool, is_scalar<_Tp>::value> +#endif +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, const _Tp&> +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_copy(_Tp)> +#else + : integral_constant<bool, is_scalar<_Tp>::value> +#endif +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&> +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_copy(_Tp)> +#else + : integral_constant<bool, is_scalar<_Tp>::value> +#endif +{ +}; + +#endif // __has_feature(cxx_noexcept) + +#else // _LIBCPP_HAS_NO_VARIADICS + +template <class _Tp, class _A0 = __is_construct::__nat, + class _A1 = __is_construct::__nat> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible + : false_type +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, __is_construct::__nat, + __is_construct::__nat> +#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_constructor(_Tp)> +#else + : integral_constant<bool, is_scalar<_Tp>::value> +#endif +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp, + __is_construct::__nat> +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_copy(_Tp)> +#else + : integral_constant<bool, is_scalar<_Tp>::value> +#endif +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, const _Tp&, + __is_construct::__nat> +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_copy(_Tp)> +#else + : integral_constant<bool, is_scalar<_Tp>::value> +#endif +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&, + __is_construct::__nat> +#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_copy(_Tp)> +#else + : integral_constant<bool, is_scalar<_Tp>::value> +#endif +{ +}; + +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // __has_feature(is_nothrow_constructible) + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +template <class _Tp, class ..._Args> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v + = is_nothrow_constructible<_Tp, _Args...>::value; +#endif + +// is_nothrow_default_constructible + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible + : public is_nothrow_constructible<_Tp> + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_default_constructible_v + = is_nothrow_default_constructible<_Tp>::value; +#endif + +// is_nothrow_copy_constructible + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible + : public is_nothrow_constructible<_Tp, + typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v + = is_nothrow_copy_constructible<_Tp>::value; +#endif + +// is_nothrow_move_constructible + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type> +#else + : public is_nothrow_copy_constructible<_Tp> +#endif + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_constructible_v + = is_nothrow_move_constructible<_Tp>::value; +#endif + +// is_nothrow_assignable + +#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) + +template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable; + +template <class _Tp, class _Arg> +struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg> + : public false_type +{ +}; + +template <class _Tp, class _Arg> +struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg> + : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>()) > +{ +}; + +template <class _Tp, class _Arg> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable + : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg> +{ +}; + +#else // __has_feature(cxx_noexcept) + +template <class _Tp, class _Arg> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable + : public false_type {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, _Tp> +#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; +#else + : integral_constant<bool, is_scalar<_Tp>::value> {}; +#endif + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, _Tp&> +#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; +#else + : integral_constant<bool, is_scalar<_Tp>::value> {}; +#endif + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, const _Tp&> +#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; +#else + : integral_constant<bool, is_scalar<_Tp>::value> {}; +#endif + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp> +struct is_nothrow_assignable<_Tp&, _Tp&&> +#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) + : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; +#else + : integral_constant<bool, is_scalar<_Tp>::value> {}; +#endif + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // __has_feature(cxx_noexcept) + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp, class _Arg> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_assignable_v + = is_nothrow_assignable<_Tp, _Arg>::value; +#endif + +// is_nothrow_copy_assignable + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable + : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type, + typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v + = is_nothrow_copy_assignable<_Tp>::value; +#endif + +// is_nothrow_move_assignable + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable + : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type, +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + typename add_rvalue_reference<_Tp>::type> +#else + typename add_lvalue_reference<_Tp>::type> +#endif + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v + = is_nothrow_move_assignable<_Tp>::value; +#endif + +// is_nothrow_destructible + +#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) + +template <bool, class _Tp> struct __libcpp_is_nothrow_destructible; + +template <class _Tp> +struct __libcpp_is_nothrow_destructible<false, _Tp> + : public false_type +{ +}; + +template <class _Tp> +struct __libcpp_is_nothrow_destructible<true, _Tp> + : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>().~_Tp()) > +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible + : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp> +{ +}; + +template <class _Tp, size_t _Ns> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]> + : public is_nothrow_destructible<_Tp> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&> + : public true_type +{ +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&> + : public true_type +{ +}; + +#endif + +#else + +template <class _Tp> struct __libcpp_nothrow_destructor + : public integral_constant<bool, is_scalar<_Tp>::value || + is_reference<_Tp>::value> {}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible + : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]> + : public false_type {}; + +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v + = is_nothrow_destructible<_Tp>::value; +#endif + +// is_pod + +#if __has_feature(is_pod) || (_GNUC_VER >= 403) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod + : public integral_constant<bool, __is_pod(_Tp)> {}; + +#else + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod + : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value && + is_trivially_copy_constructible<_Tp>::value && + is_trivially_copy_assignable<_Tp>::value && + is_trivially_destructible<_Tp>::value> {}; + +#endif + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pod_v + = is_pod<_Tp>::value; +#endif + +// is_literal_type; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_literal_type +#ifdef _LIBCPP_IS_LITERAL + : public integral_constant<bool, _LIBCPP_IS_LITERAL(_Tp)> +#else + : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value || + is_reference<typename remove_all_extents<_Tp>::type>::value> +#endif + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_literal_type_v + = is_literal_type<_Tp>::value; +#endif + +// is_standard_layout; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout +#if __has_feature(is_standard_layout) || (_GNUC_VER >= 407) + : public integral_constant<bool, __is_standard_layout(_Tp)> +#else + : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value> +#endif + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_standard_layout_v + = is_standard_layout<_Tp>::value; +#endif + +// is_trivially_copyable; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable +#if __has_feature(is_trivially_copyable) + : public integral_constant<bool, __is_trivially_copyable(_Tp)> +#elif _GNUC_VER >= 501 + : public integral_constant<bool, !is_volatile<_Tp>::value && __is_trivially_copyable(_Tp)> +#else + : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value> +#endif + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copyable_v + = is_trivially_copyable<_Tp>::value; +#endif + +// is_trivial; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial +#if __has_feature(is_trivial) || _GNUC_VER >= 407 + : public integral_constant<bool, __is_trivial(_Tp)> +#else + : integral_constant<bool, is_trivially_copyable<_Tp>::value && + is_trivially_default_constructible<_Tp>::value> +#endif + {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivial_v + = is_trivial<_Tp>::value; +#endif + +template <class _Tp> struct __is_reference_wrapper_impl : public false_type {}; +template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {}; +template <class _Tp> struct __is_reference_wrapper + : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {}; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Fp, class _A0, + class _DecayFp = typename decay<_Fp>::type, + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet1 = typename enable_if + < + is_member_function_pointer<_DecayFp>::value + && is_base_of<_ClassT, _DecayA0>::value + >::type; + +template <class _Fp, class _A0, + class _DecayFp = typename decay<_Fp>::type, + class _DecayA0 = typename decay<_A0>::type> +using __enable_if_bullet2 = typename enable_if + < + is_member_function_pointer<_DecayFp>::value + && __is_reference_wrapper<_DecayA0>::value + >::type; + +template <class _Fp, class _A0, + class _DecayFp = typename decay<_Fp>::type, + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet3 = typename enable_if + < + is_member_function_pointer<_DecayFp>::value + && !is_base_of<_ClassT, _DecayA0>::value + && !__is_reference_wrapper<_DecayA0>::value + >::type; + +template <class _Fp, class _A0, + class _DecayFp = typename decay<_Fp>::type, + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet4 = typename enable_if + < + is_member_object_pointer<_DecayFp>::value + && is_base_of<_ClassT, _DecayA0>::value + >::type; + +template <class _Fp, class _A0, + class _DecayFp = typename decay<_Fp>::type, + class _DecayA0 = typename decay<_A0>::type> +using __enable_if_bullet5 = typename enable_if + < + is_member_object_pointer<_DecayFp>::value + && __is_reference_wrapper<_DecayA0>::value + >::type; + +template <class _Fp, class _A0, + class _DecayFp = typename decay<_Fp>::type, + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet6 = typename enable_if + < + is_member_object_pointer<_DecayFp>::value + && !is_base_of<_ClassT, _DecayA0>::value + && !__is_reference_wrapper<_DecayA0>::value + >::type; + +// __invoke forward declarations + +// fall back - none of the bullets + +#define _LIBCPP_INVOKE_RETURN(...) \ + noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \ + { return __VA_ARGS__; } + +template <class ..._Args> +auto __invoke(__any, _Args&& ...__args) -> __nat; + +template <class ..._Args> +auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat; + +// bullets 1, 2 and 3 + +template <class _Fp, class _A0, class ..._Args, + class = __enable_if_bullet1<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)) + +template <class _Fp, class _A0, class ..._Args, + class = __enable_if_bullet1<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)) + +template <class _Fp, class _A0, class ..._Args, + class = __enable_if_bullet2<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...)) + +template <class _Fp, class _A0, class ..._Args, + class = __enable_if_bullet2<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...)) + +template <class _Fp, class _A0, class ..._Args, + class = __enable_if_bullet3<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) + +template <class _Fp, class _A0, class ..._Args, + class = __enable_if_bullet3<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) + +// bullets 4, 5 and 6 + +template <class _Fp, class _A0, + class = __enable_if_bullet4<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f) + +template <class _Fp, class _A0, + class = __enable_if_bullet4<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f) + +template <class _Fp, class _A0, + class = __enable_if_bullet5<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN(__a0.get().*__f) + +template <class _Fp, class _A0, + class = __enable_if_bullet5<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN(__a0.get().*__f) + +template <class _Fp, class _A0, + class = __enable_if_bullet6<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f) + +template <class _Fp, class _A0, + class = __enable_if_bullet6<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f) + +// bullet 7 + +template <class _Fp, class ..._Args> +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_Fp&& __f, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)) + +template <class _Fp, class ..._Args> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)) + +#undef _LIBCPP_INVOKE_RETURN + +// __invokable +template <class _Ret, class _Fp, class ..._Args> +struct __invokable_r +{ + template <class _XFp, class ..._XArgs> + static auto __try_call(int) -> decltype( + _VSTD::__invoke(_VSTD::declval<_XFp>(), _VSTD::declval<_XArgs>()...)); + template <class _XFp, class ..._XArgs> + static __nat __try_call(...); + + // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void, + // or incomplete array types as required by the standard. + using _Result = decltype(__try_call<_Fp, _Args...>(0)); + + using type = + typename conditional< + !is_same<_Result, __nat>::value, + typename conditional< + is_void<_Ret>::value, + true_type, + is_convertible<_Result, _Ret> + >::type, + false_type + >::type; + static const bool value = type::value; +}; +template <class _Fp, class ..._Args> +using __invokable = __invokable_r<void, _Fp, _Args...>; + +template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args> +struct __nothrow_invokable_r_imp { + static const bool value = false; +}; + +template <class _Ret, class _Fp, class ..._Args> +struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...> +{ + typedef __nothrow_invokable_r_imp _ThisT; + + template <class _Tp> + static void __test_noexcept(_Tp) noexcept; + + static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>( + _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...))); +}; + +template <class _Ret, class _Fp, class ..._Args> +struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...> +{ + static const bool value = noexcept( + _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)); +}; + +template <class _Ret, class _Fp, class ..._Args> +using __nothrow_invokable_r = + __nothrow_invokable_r_imp< + __invokable_r<_Ret, _Fp, _Args...>::value, + is_void<_Ret>::value, + _Ret, _Fp, _Args... + >; + +template <class _Fp, class ..._Args> +using __nothrow_invokable = + __nothrow_invokable_r_imp< + __invokable<_Fp, _Args...>::value, + true, void, _Fp, _Args... + >; + +template <class _Fp, class ..._Args> +struct __invoke_of + : public enable_if< + __invokable<_Fp, _Args...>::value, + typename __invokable_r<void, _Fp, _Args...>::_Result> +{ +}; + +// result_of + +template <class _Fp, class ..._Args> +class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)> + : public __invoke_of<_Fp, _Args...> +{ +}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using result_of_t = typename result_of<_Tp>::type; +#endif + +#if _LIBCPP_STD_VER > 14 + +// invoke_result + +template <class _Fn, class... _Args> +struct _LIBCPP_TEMPLATE_VIS invoke_result + : __invoke_of<_Fn, _Args...> +{ +}; + +template <class _Fn, class... _Args> +using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; + +// is_invocable + +template <class _Fn, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_invocable + : integral_constant<bool, __invokable<_Fn, _Args...>::value> {}; + +template <class _Ret, class _Fn, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_invocable_r + : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {}; + +template <class _Fn, class ..._Args> +_LIBCPP_INLINE_VAR constexpr bool is_invocable_v + = is_invocable<_Fn, _Args...>::value; + +template <class _Ret, class _Fn, class ..._Args> +_LIBCPP_INLINE_VAR constexpr bool is_invocable_r_v + = is_invocable_r<_Ret, _Fn, _Args...>::value; + +// is_nothrow_invocable + +template <class _Fn, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable + : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {}; + +template <class _Ret, class _Fn, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r + : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {}; + +template <class _Fn, class ..._Args> +_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_v + = is_nothrow_invocable<_Fn, _Args...>::value; + +template <class _Ret, class _Fn, class ..._Args> +_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v + = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value; + +#endif // _LIBCPP_STD_VER > 14 + +#endif // !defined(_LIBCPP_CXX03_LANG) + +template <class _Tp> struct __is_swappable; +template <class _Tp> struct __is_nothrow_swappable; + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_CXX03_LANG +typename enable_if +< + is_move_constructible<_Tp>::value && + is_move_assignable<_Tp>::value +>::type +#else +void +#endif +swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value && + is_nothrow_move_assignable<_Tp>::value) +{ + _Tp __t(_VSTD::move(__x)); + __x = _VSTD::move(__y); + __y = _VSTD::move(__t); +} + +template<class _Tp, size_t _Np> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + __is_swappable<_Tp>::value +>::type +swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value); + +template <class _ForwardIterator1, class _ForwardIterator2> +inline _LIBCPP_INLINE_VISIBILITY +void +iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) + // _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b))) + _NOEXCEPT_(_NOEXCEPT_(swap(*_VSTD::declval<_ForwardIterator1>(), + *_VSTD::declval<_ForwardIterator2>()))) +{ + swap(*__a, *__b); +} + +// __swappable + +namespace __detail +{ +// ALL generic swap overloads MUST already have a declaration available at this point. + +template <class _Tp, class _Up = _Tp, + bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value> +struct __swappable_with +{ + template <class _LHS, class _RHS> + static decltype(swap(_VSTD::declval<_LHS>(), _VSTD::declval<_RHS>())) + __test_swap(int); + template <class, class> + static __nat __test_swap(long); + + // Extra parens are needed for the C++03 definition of decltype. + typedef decltype((__test_swap<_Tp, _Up>(0))) __swap1; + typedef decltype((__test_swap<_Up, _Tp>(0))) __swap2; + + static const bool value = !is_same<__swap1, __nat>::value + && !is_same<__swap2, __nat>::value; +}; + +template <class _Tp, class _Up> +struct __swappable_with<_Tp, _Up, false> : false_type {}; + +template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value> +struct __nothrow_swappable_with { + static const bool value = +#ifndef _LIBCPP_HAS_NO_NOEXCEPT + noexcept(swap(_VSTD::declval<_Tp>(), _VSTD::declval<_Up>())) + && noexcept(swap(_VSTD::declval<_Up>(), _VSTD::declval<_Tp>())); +#else + false; +#endif +}; + +template <class _Tp, class _Up> +struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {}; + +} // __detail + +template <class _Tp> +struct __is_swappable + : public integral_constant<bool, __detail::__swappable_with<_Tp&>::value> +{ +}; + +template <class _Tp> +struct __is_nothrow_swappable + : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value> +{ +}; + +#if _LIBCPP_STD_VER > 14 + +template <class _Tp, class _Up> +struct _LIBCPP_TEMPLATE_VIS is_swappable_with + : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_swappable + : public conditional< + __is_referenceable<_Tp>::value, + is_swappable_with< + typename add_lvalue_reference<_Tp>::type, + typename add_lvalue_reference<_Tp>::type>, + false_type + >::type +{ +}; + +template <class _Tp, class _Up> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable_with + : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value> +{ +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable + : public conditional< + __is_referenceable<_Tp>::value, + is_nothrow_swappable_with< + typename add_lvalue_reference<_Tp>::type, + typename add_lvalue_reference<_Tp>::type>, + false_type + >::type +{ +}; + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VAR constexpr bool is_swappable_with_v + = is_swappable_with<_Tp, _Up>::value; + +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr bool is_swappable_v + = is_swappable<_Tp>::value; + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_with_v + = is_nothrow_swappable_with<_Tp, _Up>::value; + +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_v + = is_nothrow_swappable<_Tp>::value; + +#endif // _LIBCPP_STD_VER > 14 + +#ifdef _LIBCPP_UNDERLYING_TYPE + +template <class _Tp> +struct underlying_type +{ + typedef _LIBCPP_UNDERLYING_TYPE(_Tp) type; +}; + +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type; +#endif + +#else // _LIBCPP_UNDERLYING_TYPE + +template <class _Tp, bool _Support = false> +struct underlying_type +{ + static_assert(_Support, "The underyling_type trait requires compiler " + "support. Either no such support exists or " + "libc++ does not know how to use it."); +}; + +#endif // _LIBCPP_UNDERLYING_TYPE + + +template <class _Tp, bool = is_enum<_Tp>::value> +struct __sfinae_underlying_type +{ + typedef typename underlying_type<_Tp>::type type; + typedef decltype(((type)1) + 0) __promoted_type; +}; + +template <class _Tp> +struct __sfinae_underlying_type<_Tp, false> {}; + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __convert_to_integral(int __val) { return __val; } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +unsigned __convert_to_integral(unsigned __val) { return __val; } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +long __convert_to_integral(long __val) { return __val; } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +unsigned long __convert_to_integral(unsigned long __val) { return __val; } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +long long __convert_to_integral(long long __val) { return __val; } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +unsigned long long __convert_to_integral(unsigned long long __val) {return __val; } + +template<typename _Fp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if<is_floating_point<_Fp>::value, long long>::type + __convert_to_integral(_Fp __val) { return __val; } + +#ifndef _LIBCPP_HAS_NO_INT128 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +__int128_t __convert_to_integral(__int128_t __val) { return __val; } + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +__uint128_t __convert_to_integral(__uint128_t __val) { return __val; } +#endif + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename __sfinae_underlying_type<_Tp>::__promoted_type +__convert_to_integral(_Tp __val) { return __val; } + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp> +struct __has_operator_addressof_member_imp +{ + template <class _Up> + static auto __test(int) + -> typename __select_2nd<decltype(_VSTD::declval<_Up>().operator&()), true_type>::type; + template <class> + static auto __test(long) -> false_type; + + static const bool value = decltype(__test<_Tp>(0))::value; +}; + +template <class _Tp> +struct __has_operator_addressof_free_imp +{ + template <class _Up> + static auto __test(int) + -> typename __select_2nd<decltype(operator&(_VSTD::declval<_Up>())), true_type>::type; + template <class> + static auto __test(long) -> false_type; + + static const bool value = decltype(__test<_Tp>(0))::value; +}; + +template <class _Tp> +struct __has_operator_addressof + : public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value + || __has_operator_addressof_free_imp<_Tp>::value> +{}; + +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 14 + +template <class...> using void_t = void; + +# ifndef _LIBCPP_HAS_NO_VARIADICS +template <class... _Args> +struct conjunction : __and_<_Args...> {}; +template<class... _Args> +_LIBCPP_INLINE_VAR constexpr bool conjunction_v + = conjunction<_Args...>::value; + +template <class... _Args> +struct disjunction : __or_<_Args...> {}; +template<class... _Args> +_LIBCPP_INLINE_VAR constexpr bool disjunction_v + = disjunction<_Args...>::value; + +template <class _Tp> +struct negation : __not_<_Tp> {}; +template<class _Tp> +_LIBCPP_INLINE_VAR constexpr bool negation_v + = negation<_Tp>::value; +# endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_STD_VER > 14 + +// These traits are used in __tree and __hash_table +#ifndef _LIBCPP_CXX03_LANG +struct __extract_key_fail_tag {}; +struct __extract_key_self_tag {}; +struct __extract_key_first_tag {}; + +template <class _ValTy, class _Key, + class _RawValTy = typename __unconstref<_ValTy>::type> +struct __can_extract_key + : conditional<is_same<_RawValTy, _Key>::value, __extract_key_self_tag, + __extract_key_fail_tag>::type {}; + +template <class _Pair, class _Key, class _First, class _Second> +struct __can_extract_key<_Pair, _Key, pair<_First, _Second>> + : conditional<is_same<typename remove_const<_First>::type, _Key>::value, + __extract_key_first_tag, __extract_key_fail_tag>::type {}; + +// __can_extract_map_key uses true_type/false_type instead of the tags. +// It returns true if _Key != _ContainerValueTy (the container is a map not a set) +// and _ValTy == _Key. +template <class _ValTy, class _Key, class _ContainerValueTy, + class _RawValTy = typename __unconstref<_ValTy>::type> +struct __can_extract_map_key + : integral_constant<bool, is_same<_RawValTy, _Key>::value> {}; + +// This specialization returns __extract_key_fail_tag for non-map containers +// because _Key == _ContainerValueTy +template <class _ValTy, class _Key, class _RawValTy> +struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy> + : false_type {}; + +#endif + +#if _LIBCPP_STD_VER > 17 +enum class endian +{ + little = 0xDEAD, + big = 0xFACE, +#if defined(_LIBCPP_LITTLE_ENDIAN) + native = little +#elif defined(_LIBCPP_BIG_ENDIAN) + native = big +#else + native = 0xCAFE +#endif +}; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 +// std::byte +namespace std // purposefully not versioned +{ +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type & + operator<<=(byte& __lhs, _Integer __shift) noexcept + { return __lhs = __lhs << __shift; } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type + operator<< (byte __lhs, _Integer __shift) noexcept + { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type & + operator>>=(byte& __lhs, _Integer __shift) noexcept + { return __lhs = __lhs >> __shift; } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type + operator>> (byte __lhs, _Integer __shift) noexcept + { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, _Integer>::type + to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } + +} +#endif + +#endif // _LIBCPP_TYPE_TRAITS diff --git a/android/x86/include/v8/libc++/typeindex b/android/x86/include/v8/libc++/typeindex new file mode 100755 index 00000000..bff1e65a --- /dev/null +++ b/android/x86/include/v8/libc++/typeindex @@ -0,0 +1,102 @@ +// -*- C++ -*- +//===-------------------------- typeindex ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_TYPEINDEX +#define _LIBCPP_TYPEINDEX + +/* + + typeindex synopsis + +namespace std +{ + +class type_index +{ +public: + type_index(const type_info& rhs) noexcept; + + bool operator==(const type_index& rhs) const noexcept; + bool operator!=(const type_index& rhs) const noexcept; + bool operator< (const type_index& rhs) const noexcept; + bool operator<=(const type_index& rhs) const noexcept; + bool operator> (const type_index& rhs) const noexcept; + bool operator>=(const type_index& rhs) const noexcept; + + size_t hash_code() const noexcept; + const char* name() const noexcept; +}; + +template <> +struct hash<type_index> + : public unary_function<type_index, size_t> +{ + size_t operator()(type_index index) const noexcept; +}; + +} // std + +*/ + +#include <__config> +#include <typeinfo> +#include <__functional_base> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +class _LIBCPP_TEMPLATE_VIS type_index +{ + const type_info* __t_; +public: + _LIBCPP_INLINE_VISIBILITY + type_index(const type_info& __y) _NOEXCEPT : __t_(&__y) {} + + _LIBCPP_INLINE_VISIBILITY + bool operator==(const type_index& __y) const _NOEXCEPT + {return *__t_ == *__y.__t_;} + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const type_index& __y) const _NOEXCEPT + {return *__t_ != *__y.__t_;} + _LIBCPP_INLINE_VISIBILITY + bool operator< (const type_index& __y) const _NOEXCEPT + {return __t_->before(*__y.__t_);} + _LIBCPP_INLINE_VISIBILITY + bool operator<=(const type_index& __y) const _NOEXCEPT + {return !__y.__t_->before(*__t_);} + _LIBCPP_INLINE_VISIBILITY + bool operator> (const type_index& __y) const _NOEXCEPT + {return __y.__t_->before(*__t_);} + _LIBCPP_INLINE_VISIBILITY + bool operator>=(const type_index& __y) const _NOEXCEPT + {return !__t_->before(*__y.__t_);} + + _LIBCPP_INLINE_VISIBILITY + size_t hash_code() const _NOEXCEPT {return __t_->hash_code();} + _LIBCPP_INLINE_VISIBILITY + const char* name() const _NOEXCEPT {return __t_->name();} +}; + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<type_index> + : public unary_function<type_index, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(type_index __index) const _NOEXCEPT + {return __index.hash_code();} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_TYPEINDEX diff --git a/android/x86/include/v8/libc++/typeinfo b/android/x86/include/v8/libc++/typeinfo new file mode 100755 index 00000000..a52c9849 --- /dev/null +++ b/android/x86/include/v8/libc++/typeinfo @@ -0,0 +1,279 @@ +// -*- C++ -*- +//===-------------------------- typeinfo ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef __LIBCPP_TYPEINFO +#define __LIBCPP_TYPEINFO + +/* + + typeinfo synopsis + +namespace std { + +class type_info +{ +public: + virtual ~type_info(); + + bool operator==(const type_info& rhs) const noexcept; + bool operator!=(const type_info& rhs) const noexcept; + + bool before(const type_info& rhs) const noexcept; + size_t hash_code() const noexcept; + const char* name() const noexcept; + + type_info(const type_info& rhs) = delete; + type_info& operator=(const type_info& rhs) = delete; +}; + +class bad_cast + : public exception +{ +public: + bad_cast() noexcept; + bad_cast(const bad_cast&) noexcept; + bad_cast& operator=(const bad_cast&) noexcept; + virtual const char* what() const noexcept; +}; + +class bad_typeid + : public exception +{ +public: + bad_typeid() noexcept; + bad_typeid(const bad_typeid&) noexcept; + bad_typeid& operator=(const bad_typeid&) noexcept; + virtual const char* what() const noexcept; +}; + +} // std + +*/ + +#include <__config> +#include <exception> +#include <cstddef> +#include <cstdint> +#ifdef _LIBCPP_NO_EXCEPTIONS +#include <cstdlib> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if defined(_LIBCPP_ABI_VCRUNTIME) +#include <vcruntime_typeinfo.h> +#else + +#if defined(_LIBCPP_NONUNIQUE_RTTI_BIT) && !defined(_LIBCPP_ABI_MICROSOFT) +# define _LIBCPP_HAS_NONUNIQUE_TYPEINFO +#endif + +namespace std // purposefully not using versioning namespace +{ + +#if defined(_LIBCPP_ABI_MICROSOFT) + +class _LIBCPP_EXCEPTION_ABI type_info +{ + type_info& operator=(const type_info&); + type_info(const type_info&); + + mutable struct { + const char *__undecorated_name; + const char __decorated_name[1]; + } __data; + + int __compare(const type_info &__rhs) const _NOEXCEPT; + +public: + _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE + virtual ~type_info(); + + const char *name() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + bool before(const type_info& __arg) const _NOEXCEPT { + return __compare(__arg) < 0; + } + + size_t hash_code() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + bool operator==(const type_info& __arg) const _NOEXCEPT { + return __compare(__arg) == 0; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const type_info& __arg) const _NOEXCEPT + { return !operator==(__arg); } +}; + +#elif defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO) + +// This implementation of type_info does not assume always a unique copy of +// the RTTI for a given type inside a program. It packs the pointer to the +// type name into a uintptr_t and reserves the high bit of that pointer (which +// is assumed to be free for use under the ABI in use) to represent whether +// that specific copy of the RTTI can be assumed unique inside the program. +// To implement equality-comparison of type_infos, we check whether BOTH +// type_infos are guaranteed unique, and if so, we simply compare the addresses +// of their type names instead of doing a deep string comparison, which is +// faster. If at least one of the type_infos can't guarantee uniqueness, we +// have no choice but to fall back to a deep string comparison. +// +// Note that the compiler is the one setting (or unsetting) the high bit of +// the pointer when it constructs the type_info, depending on whether it can +// guarantee uniqueness for that specific type_info. +class _LIBCPP_EXCEPTION_ABI type_info +{ + type_info& operator=(const type_info&); + type_info(const type_info&); + + _LIBCPP_INLINE_VISIBILITY + int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT + { return __builtin_strcmp(name(), __arg.name()); } + +protected: + uintptr_t __type_name; + + _LIBCPP_INLINE_VISIBILITY + explicit type_info(const char* __n) + : __type_name(reinterpret_cast<uintptr_t>(__n)) {} + +public: + _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE + virtual ~type_info(); + + _LIBCPP_INLINE_VISIBILITY + const char* name() const _NOEXCEPT + { + return reinterpret_cast<const char*>(__type_name & + ~_LIBCPP_NONUNIQUE_RTTI_BIT); + } + + _LIBCPP_INLINE_VISIBILITY + bool before(const type_info& __arg) const _NOEXCEPT + { + if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT)) + return __type_name < __arg.__type_name; + return __compare_nonunique_names(__arg) < 0; + } + + _LIBCPP_INLINE_VISIBILITY + size_t hash_code() const _NOEXCEPT + { + if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT)) + return __type_name; + + const char* __ptr = name(); + size_t __hash = 5381; + while (unsigned char __c = static_cast<unsigned char>(*__ptr++)) + __hash = (__hash * 33) ^ __c; + return __hash; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator==(const type_info& __arg) const _NOEXCEPT + { + if (__type_name == __arg.__type_name) + return true; + + if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT)) + return false; + return __compare_nonunique_names(__arg) == 0; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const type_info& __arg) const _NOEXCEPT + { return !operator==(__arg); } +}; + +#else // !_LIBCPP_ABI_MICROSOFT && !_LIBCPP_HAS_NONUNIQUE_TYPEINFO + +// This implementation of type_info assumes a unique copy of the RTTI for a +// given type inside a program. This is a valid assumption when abiding to +// Itanium ABI (http://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-components). +// Under this assumption, we can always compare the addresses of the type names +// to implement equality-comparison of type_infos instead of having to perform +// a deep string comparison. +class _LIBCPP_EXCEPTION_ABI type_info +{ + type_info& operator=(const type_info&); + type_info(const type_info&); + +protected: + const char *__type_name; + + _LIBCPP_INLINE_VISIBILITY + explicit type_info(const char* __n) : __type_name(__n) {} + +public: + _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE + virtual ~type_info(); + + _LIBCPP_INLINE_VISIBILITY + const char* name() const _NOEXCEPT + { return __type_name; } + + _LIBCPP_INLINE_VISIBILITY + bool before(const type_info& __arg) const _NOEXCEPT + { return __type_name < __arg.__type_name; } + + _LIBCPP_INLINE_VISIBILITY + size_t hash_code() const _NOEXCEPT + { return reinterpret_cast<size_t>(__type_name); } + + _LIBCPP_INLINE_VISIBILITY + bool operator==(const type_info& __arg) const _NOEXCEPT + { return __type_name == __arg.__type_name; } + + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const type_info& __arg) const _NOEXCEPT + { return !operator==(__arg); } +}; + +#endif + +class _LIBCPP_EXCEPTION_ABI bad_cast + : public exception +{ +public: + bad_cast() _NOEXCEPT; + virtual ~bad_cast() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +class _LIBCPP_EXCEPTION_ABI bad_typeid + : public exception +{ +public: + bad_typeid() _NOEXCEPT; + virtual ~bad_typeid() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +} // std + +#endif // defined(_LIBCPP_ABI_VCRUNTIME) + +_LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_bad_cast() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_cast(); +#else + _VSTD::abort(); +#endif +} +_LIBCPP_END_NAMESPACE_STD + +#endif // __LIBCPP_TYPEINFO diff --git a/android/x86/include/v8/libc++/unordered_map b/android/x86/include/v8/libc++/unordered_map new file mode 100755 index 00000000..42057c5d --- /dev/null +++ b/android/x86/include/v8/libc++/unordered_map @@ -0,0 +1,2301 @@ +// -*- C++ -*- +//===-------------------------- unordered_map -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_UNORDERED_MAP +#define _LIBCPP_UNORDERED_MAP + +/* + + unordered_map synopsis + +#include <initializer_list> + +namespace std +{ + +template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, + class Alloc = allocator<pair<const Key, T>>> +class unordered_map +{ +public: + // types + typedef Key key_type; + typedef T mapped_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef pair<const key_type, mapped_type> value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + typedef /unspecified/ local_iterator; + typedef /unspecified/ const_local_iterator; + + typedef unspecified node_type; // C++17 + typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17 + + unordered_map() + noexcept( + is_nothrow_default_constructible<hasher>::value && + is_nothrow_default_constructible<key_equal>::value && + is_nothrow_default_constructible<allocator_type>::value); + explicit unordered_map(size_type n, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template <class InputIterator> + unordered_map(InputIterator f, InputIterator l, + size_type n = 0, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + explicit unordered_map(const allocator_type&); + unordered_map(const unordered_map&); + unordered_map(const unordered_map&, const Allocator&); + unordered_map(unordered_map&&) + noexcept( + is_nothrow_move_constructible<hasher>::value && + is_nothrow_move_constructible<key_equal>::value && + is_nothrow_move_constructible<allocator_type>::value); + unordered_map(unordered_map&&, const Allocator&); + unordered_map(initializer_list<value_type>, size_type n = 0, + const hasher& hf = hasher(), const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + unordered_map(size_type n, const allocator_type& a) + : unordered_map(n, hasher(), key_equal(), a) {} // C++14 + unordered_map(size_type n, const hasher& hf, const allocator_type& a) + : unordered_map(n, hf, key_equal(), a) {} // C++14 + template <class InputIterator> + unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a) + : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14 + template <class InputIterator> + unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf, + const allocator_type& a) + : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14 + unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a) + : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14 + unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf, + const allocator_type& a) + : unordered_map(il, n, hf, key_equal(), a) {} // C++14 + ~unordered_map(); + unordered_map& operator=(const unordered_map&); + unordered_map& operator=(unordered_map&&) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value && + is_nothrow_move_assignable<hasher>::value && + is_nothrow_move_assignable<key_equal>::value); + unordered_map& operator=(initializer_list<value_type>); + + allocator_type get_allocator() const noexcept; + + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + iterator begin() noexcept; + iterator end() noexcept; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + template <class... Args> + pair<iterator, bool> emplace(Args&&... args); + template <class... Args> + iterator emplace_hint(const_iterator position, Args&&... args); + pair<iterator, bool> insert(const value_type& obj); + template <class P> + pair<iterator, bool> insert(P&& obj); + iterator insert(const_iterator hint, const value_type& obj); + template <class P> + iterator insert(const_iterator hint, P&& obj); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + void insert(initializer_list<value_type>); + + node_type extract(const_iterator position); // C++17 + node_type extract(const key_type& x); // C++17 + insert_return_type insert(node_type&& nh); // C++17 + iterator insert(const_iterator hint, node_type&& nh); // C++17 + + template <class... Args> + pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17 + template <class... Args> + pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17 + template <class... Args> + iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17 + template <class... Args> + iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17 + template <class M> + pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17 + template <class M> + pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17 + template <class M> + iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17 + template <class M> + iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17 + + iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + template<class H2, class P2> + void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17 + template<class H2, class P2> + void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17 + template<class H2, class P2> + void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source); // C++17 + template<class H2, class P2> + void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17 + + void swap(unordered_map&) + noexcept( + (!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value) && + __is_nothrow_swappable<hasher>::value && + __is_nothrow_swappable<key_equal>::value); + + hasher hash_function() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair<iterator, iterator> equal_range(const key_type& k); + pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + + mapped_type& operator[](const key_type& k); + mapped_type& operator[](key_type&& k); + + mapped_type& at(const key_type& k); + const mapped_type& at(const key_type& k) const; + + size_type bucket_count() const noexcept; + size_type max_bucket_count() const noexcept; + + size_type bucket_size(size_type n) const; + size_type bucket(const key_type& k) const; + + local_iterator begin(size_type n); + local_iterator end(size_type n); + const_local_iterator begin(size_type n) const; + const_local_iterator end(size_type n) const; + const_local_iterator cbegin(size_type n) const; + const_local_iterator cend(size_type n) const; + + float load_factor() const noexcept; + float max_load_factor() const noexcept; + void max_load_factor(float z); + void rehash(size_type n); + void reserve(size_type n); +}; + +template <class Key, class T, class Hash, class Pred, class Alloc> + void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x, + unordered_map<Key, T, Hash, Pred, Alloc>& y) + noexcept(noexcept(x.swap(y))); + +template <class Key, class T, class Hash, class Pred, class Alloc> + bool + operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x, + const unordered_map<Key, T, Hash, Pred, Alloc>& y); + +template <class Key, class T, class Hash, class Pred, class Alloc> + bool + operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x, + const unordered_map<Key, T, Hash, Pred, Alloc>& y); + +template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, + class Alloc = allocator<pair<const Key, T>>> +class unordered_multimap +{ +public: + // types + typedef Key key_type; + typedef T mapped_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef pair<const key_type, mapped_type> value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + typedef /unspecified/ local_iterator; + typedef /unspecified/ const_local_iterator; + + typedef unspecified node_type; // C++17 + + unordered_multimap() + noexcept( + is_nothrow_default_constructible<hasher>::value && + is_nothrow_default_constructible<key_equal>::value && + is_nothrow_default_constructible<allocator_type>::value); + explicit unordered_multimap(size_type n, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template <class InputIterator> + unordered_multimap(InputIterator f, InputIterator l, + size_type n = 0, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + explicit unordered_multimap(const allocator_type&); + unordered_multimap(const unordered_multimap&); + unordered_multimap(const unordered_multimap&, const Allocator&); + unordered_multimap(unordered_multimap&&) + noexcept( + is_nothrow_move_constructible<hasher>::value && + is_nothrow_move_constructible<key_equal>::value && + is_nothrow_move_constructible<allocator_type>::value); + unordered_multimap(unordered_multimap&&, const Allocator&); + unordered_multimap(initializer_list<value_type>, size_type n = 0, + const hasher& hf = hasher(), const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + unordered_multimap(size_type n, const allocator_type& a) + : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14 + unordered_multimap(size_type n, const hasher& hf, const allocator_type& a) + : unordered_multimap(n, hf, key_equal(), a) {} // C++14 + template <class InputIterator> + unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a) + : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14 + template <class InputIterator> + unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf, + const allocator_type& a) + : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14 + unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a) + : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14 + unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf, + const allocator_type& a) + : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14 + ~unordered_multimap(); + unordered_multimap& operator=(const unordered_multimap&); + unordered_multimap& operator=(unordered_multimap&&) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value && + is_nothrow_move_assignable<hasher>::value && + is_nothrow_move_assignable<key_equal>::value); + unordered_multimap& operator=(initializer_list<value_type>); + + allocator_type get_allocator() const noexcept; + + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + iterator begin() noexcept; + iterator end() noexcept; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + template <class... Args> + iterator emplace(Args&&... args); + template <class... Args> + iterator emplace_hint(const_iterator position, Args&&... args); + iterator insert(const value_type& obj); + template <class P> + iterator insert(P&& obj); + iterator insert(const_iterator hint, const value_type& obj); + template <class P> + iterator insert(const_iterator hint, P&& obj); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + void insert(initializer_list<value_type>); + + node_type extract(const_iterator position); // C++17 + node_type extract(const key_type& x); // C++17 + iterator insert(node_type&& nh); // C++17 + iterator insert(const_iterator hint, node_type&& nh); // C++17 + + iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + template<class H2, class P2> + void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source); // C++17 + template<class H2, class P2> + void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17 + template<class H2, class P2> + void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17 + template<class H2, class P2> + void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17 + + void swap(unordered_multimap&) + noexcept( + (!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value) && + __is_nothrow_swappable<hasher>::value && + __is_nothrow_swappable<key_equal>::value); + + hasher hash_function() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair<iterator, iterator> equal_range(const key_type& k); + pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + + size_type bucket_count() const noexcept; + size_type max_bucket_count() const noexcept; + + size_type bucket_size(size_type n) const; + size_type bucket(const key_type& k) const; + + local_iterator begin(size_type n); + local_iterator end(size_type n); + const_local_iterator begin(size_type n) const; + const_local_iterator end(size_type n) const; + const_local_iterator cbegin(size_type n) const; + const_local_iterator cend(size_type n) const; + + float load_factor() const noexcept; + float max_load_factor() const noexcept; + void max_load_factor(float z); + void rehash(size_type n); + void reserve(size_type n); +}; + +template <class Key, class T, class Hash, class Pred, class Alloc> + void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x, + unordered_multimap<Key, T, Hash, Pred, Alloc>& y) + noexcept(noexcept(x.swap(y))); + +template <class K, class T, class H, class P, class A, class Predicate> + void erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20 + +template <class K, class T, class H, class P, class A, class Predicate> + void erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20 + +template <class Key, class T, class Hash, class Pred, class Alloc> + bool + operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, + const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); + +template <class Key, class T, class Hash, class Pred, class Alloc> + bool + operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, + const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); + +} // std + +*/ + +#include <__config> +#include <__hash_table> +#include <__node_handle> +#include <functional> +#include <stdexcept> +#include <tuple> +#include <version> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Key, class _Cp, class _Hash, + bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value> +class __unordered_map_hasher + : private _Hash +{ +public: + _LIBCPP_INLINE_VISIBILITY + __unordered_map_hasher() + _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) + : _Hash() {} + _LIBCPP_INLINE_VISIBILITY + __unordered_map_hasher(const _Hash& __h) + _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) + : _Hash(__h) {} + _LIBCPP_INLINE_VISIBILITY + const _Hash& hash_function() const _NOEXCEPT {return *this;} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const _Cp& __x) const + {return static_cast<const _Hash&>(*this)(__x.__get_value().first);} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const _Key& __x) const + {return static_cast<const _Hash&>(*this)(__x);} + void swap(__unordered_map_hasher&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) + { + using _VSTD::swap; + swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y)); + } +}; + +template <class _Key, class _Cp, class _Hash> +class __unordered_map_hasher<_Key, _Cp, _Hash, false> +{ + _Hash __hash_; +public: + _LIBCPP_INLINE_VISIBILITY + __unordered_map_hasher() + _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) + : __hash_() {} + _LIBCPP_INLINE_VISIBILITY + __unordered_map_hasher(const _Hash& __h) + _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) + : __hash_(__h) {} + _LIBCPP_INLINE_VISIBILITY + const _Hash& hash_function() const _NOEXCEPT {return __hash_;} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const _Cp& __x) const + {return __hash_(__x.__get_value().first);} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const _Key& __x) const + {return __hash_(__x);} + void swap(__unordered_map_hasher&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) + { + using _VSTD::swap; + swap(__hash_, __y.__hash_); + } +}; + +template <class _Key, class _Cp, class _Hash, bool __b> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x, + __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Key, class _Cp, class _Pred, + bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value> +class __unordered_map_equal + : private _Pred +{ +public: + _LIBCPP_INLINE_VISIBILITY + __unordered_map_equal() + _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) + : _Pred() {} + _LIBCPP_INLINE_VISIBILITY + __unordered_map_equal(const _Pred& __p) + _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) + : _Pred(__p) {} + _LIBCPP_INLINE_VISIBILITY + const _Pred& key_eq() const _NOEXCEPT {return *this;} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Cp& __x, const _Cp& __y) const + {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Cp& __x, const _Key& __y) const + {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _Cp& __y) const + {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);} + void swap(__unordered_map_equal&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) + { + using _VSTD::swap; + swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y)); + } +}; + +template <class _Key, class _Cp, class _Pred> +class __unordered_map_equal<_Key, _Cp, _Pred, false> +{ + _Pred __pred_; +public: + _LIBCPP_INLINE_VISIBILITY + __unordered_map_equal() + _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) + : __pred_() {} + _LIBCPP_INLINE_VISIBILITY + __unordered_map_equal(const _Pred& __p) + _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) + : __pred_(__p) {} + _LIBCPP_INLINE_VISIBILITY + const _Pred& key_eq() const _NOEXCEPT {return __pred_;} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Cp& __x, const _Cp& __y) const + {return __pred_(__x.__get_value().first, __y.__get_value().first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Cp& __x, const _Key& __y) const + {return __pred_(__x.__get_value().first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _Cp& __y) const + {return __pred_(__x, __y.__get_value().first);} + void swap(__unordered_map_equal&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) + { + using _VSTD::swap; + swap(__pred_, __y.__pred_); + } +}; + +template <class _Key, class _Cp, class _Pred, bool __b> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x, + __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Alloc> +class __hash_map_node_destructor +{ + typedef _Alloc allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + +public: + + typedef typename __alloc_traits::pointer pointer; +private: + + allocator_type& __na_; + + __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); + +public: + bool __first_constructed; + bool __second_constructed; + + _LIBCPP_INLINE_VISIBILITY + explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT + : __na_(__na), + __first_constructed(false), + __second_constructed(false) + {} + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) + _NOEXCEPT + : __na_(__x.__na_), + __first_constructed(__x.__value_constructed), + __second_constructed(__x.__value_constructed) + { + __x.__value_constructed = false; + } +#else // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) + : __na_(__x.__na_), + __first_constructed(__x.__value_constructed), + __second_constructed(__x.__value_constructed) + { + const_cast<bool&>(__x.__value_constructed) = false; + } +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + if (__second_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second)); + if (__first_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } +}; + +#ifndef _LIBCPP_CXX03_LANG +template <class _Key, class _Tp> +struct __hash_value_type +{ + typedef _Key key_type; + typedef _Tp mapped_type; + typedef pair<const key_type, mapped_type> value_type; + typedef pair<key_type&, mapped_type&> __nc_ref_pair_type; + typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type; + +private: + value_type __cc; + +public: + _LIBCPP_INLINE_VISIBILITY + value_type& __get_value() + { +#if _LIBCPP_STD_VER > 14 + return *_VSTD::launder(_VSTD::addressof(__cc)); +#else + return __cc; +#endif + } + + _LIBCPP_INLINE_VISIBILITY + const value_type& __get_value() const + { +#if _LIBCPP_STD_VER > 14 + return *_VSTD::launder(_VSTD::addressof(__cc)); +#else + return __cc; +#endif + } + + _LIBCPP_INLINE_VISIBILITY + __nc_ref_pair_type __ref() + { + value_type& __v = __get_value(); + return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second); + } + + _LIBCPP_INLINE_VISIBILITY + __nc_rref_pair_type __move() + { + value_type& __v = __get_value(); + return __nc_rref_pair_type( + _VSTD::move(const_cast<key_type&>(__v.first)), + _VSTD::move(__v.second)); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_value_type& operator=(const __hash_value_type& __v) + { + __ref() = __v.__get_value(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __hash_value_type& operator=(__hash_value_type&& __v) + { + __ref() = __v.__move(); + return *this; + } + + template <class _ValueTp, + class = typename enable_if< + __is_same_uncvref<_ValueTp, value_type>::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + __hash_value_type& operator=(_ValueTp&& __v) + { + __ref() = _VSTD::forward<_ValueTp>(__v); + return *this; + } + +private: + __hash_value_type(const __hash_value_type& __v) = delete; + __hash_value_type(__hash_value_type&& __v) = delete; + template <class ..._Args> + explicit __hash_value_type(_Args&& ...__args) = delete; + + ~__hash_value_type() = delete; +}; + +#else + +template <class _Key, class _Tp> +struct __hash_value_type +{ + typedef _Key key_type; + typedef _Tp mapped_type; + typedef pair<const key_type, mapped_type> value_type; + +private: + value_type __cc; + +public: + _LIBCPP_INLINE_VISIBILITY + value_type& __get_value() { return __cc; } + _LIBCPP_INLINE_VISIBILITY + const value_type& __get_value() const { return __cc; } + +private: + ~__hash_value_type(); +}; + +#endif + +template <class _HashIterator> +class _LIBCPP_TEMPLATE_VIS __hash_map_iterator +{ + _HashIterator __i_; + + typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__map_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__map_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY + __hash_map_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __i_->__get_value();} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} + + _LIBCPP_INLINE_VISIBILITY + __hash_map_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __hash_map_iterator operator++(int) + { + __hash_map_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; +}; + +template <class _HashIterator> +class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator +{ + _HashIterator __i_; + + typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename _NodeTypes::__map_value_type value_type; + typedef typename _NodeTypes::difference_type difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_map_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator( + __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) + _NOEXCEPT + : __i_(__i.__i_) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __i_->__get_value();} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} + + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator operator++(int) + { + __hash_map_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; +}; + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +class unordered_multimap; + +template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, + class _Alloc = allocator<pair<const _Key, _Tp> > > +class _LIBCPP_TEMPLATE_VIS unordered_map +{ +public: + // types + typedef _Key key_type; + typedef _Tp mapped_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef pair<const key_type, mapped_type> value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + static_assert((is_same<value_type, typename allocator_type::value_type>::value), + "Invalid allocator::value_type"); + +private: + typedef __hash_value_type<key_type, mapped_type> __value_type; + typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; + typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; + typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, + __value_type>::type __allocator_type; + + typedef __hash_table<__value_type, __hasher, + __key_equal, __allocator_type> __table; + + __table __table_; + + typedef typename __table::_NodeTypes _NodeTypes; + typedef typename __table::__node_pointer __node_pointer; + typedef typename __table::__node_const_pointer __node_const_pointer; + typedef typename __table::__node_traits __node_traits; + typedef typename __table::__node_allocator __node_allocator; + typedef typename __table::__node __node; + typedef __hash_map_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + typedef allocator_traits<allocator_type> __alloc_traits; + + static_assert((is_same<typename __table::__container_value_type, value_type>::value), ""); + static_assert((is_same<typename __table::__node_value_type, __value_type>::value), ""); +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __table::size_type size_type; + typedef typename __table::difference_type difference_type; + + typedef __hash_map_iterator<typename __table::iterator> iterator; + typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; + typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; + typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; + +#if _LIBCPP_STD_VER > 14 + typedef __map_node_handle<__node, allocator_type> node_type; + typedef __insert_return_type<iterator, node_type> insert_return_type; +#endif + + template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; + + _LIBCPP_INLINE_VISIBILITY + unordered_map() + _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + explicit unordered_map(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + unordered_map(size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + template <class _InputIterator> + unordered_map(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + unordered_map(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template <class _InputIterator> + unordered_map(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + explicit unordered_map(const allocator_type& __a); + unordered_map(const unordered_map& __u); + unordered_map(const unordered_map& __u, const allocator_type& __a); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + unordered_map(unordered_map&& __u) + _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); + unordered_map(unordered_map&& __u, const allocator_type& __a); + unordered_map(initializer_list<value_type> __il); + unordered_map(initializer_list<value_type> __il, size_type __n, + const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); + unordered_map(initializer_list<value_type> __il, size_type __n, + const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); +#endif // _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + unordered_map(size_type __n, const allocator_type& __a) + : unordered_map(__n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_map(__n, __hf, key_equal(), __a) {} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) + : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, + const allocator_type& __a) + : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) + : unordered_map(__il, __n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const allocator_type& __a) + : unordered_map(__il, __n, __hf, key_equal(), __a) {} +#endif + _LIBCPP_INLINE_VISIBILITY + ~unordered_map() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); + } + + _LIBCPP_INLINE_VISIBILITY + unordered_map& operator=(const unordered_map& __u) + { +#ifndef _LIBCPP_CXX03_LANG + __table_ = __u.__table_; +#else + if (this != &__u) { + __table_.clear(); + __table_.hash_function() = __u.__table_.hash_function(); + __table_.key_eq() = __u.__table_.key_eq(); + __table_.max_load_factor() = __u.__table_.max_load_factor(); + __table_.__copy_assign_alloc(__u.__table_); + insert(__u.begin(), __u.end()); + } +#endif + return *this; + } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + unordered_map& operator=(unordered_map&& __u) + _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); + _LIBCPP_INLINE_VISIBILITY + unordered_map& operator=(initializer_list<value_type> __il); +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert(const value_type& __x) + {return __table_.__insert_unique(__x);} + + iterator insert(const_iterator __p, const value_type& __x) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" + " referring to this unordered_map"); +#else + ((void)__p); +#endif + return insert(__x).first; + } + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __first, _InputIterator __last); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert(value_type&& __x) + {return __table_.__insert_unique(_VSTD::move(__x));} + + iterator insert(const_iterator __p, value_type&& __x) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" + " referring to this unordered_map"); +#else + ((void)__p); +#endif + return __table_.__insert_unique(_VSTD::move(__x)).first; + } + + template <class _Pp, + class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert(_Pp&& __x) + {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));} + + template <class _Pp, + class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, _Pp&& __x) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::insert(const_iterator, value_type&&) called with an iterator not" + " referring to this unordered_map"); +#else + ((void)__p); +#endif + return insert(_VSTD::forward<_Pp>(__x)).first; + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> emplace(_Args&&... __args) { + return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator emplace_hint(const_iterator __p, _Args&&... __args) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered_map"); +#else + ((void)__p); +#endif + return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; + } + +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 14 + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) + { + return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(__k), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) + { + return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::move(__k)), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this, + "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not" + " referring to this unordered_map"); +#else + ((void)__h); +#endif + return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first; + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this, + "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not" + " referring to this unordered_map"); +#else + ((void)__h); +#endif + return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first; + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) + { + pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k, + __k, _VSTD::forward<_Vp>(__v)); + if (!__res.second) { + __res.first->second = _VSTD::forward<_Vp>(__v); + } + return __res; + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) + { + pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k, + _VSTD::move(__k), _VSTD::forward<_Vp>(__v)); + if (!__res.second) { + __res.first->second = _VSTD::forward<_Vp>(__v); + } + return __res; + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v) + { + // FIXME: Add debug mode checking for the iterator input + return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first; + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v) + { + // FIXME: Add debug mode checking for the iterator input + return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first; + } +#endif // _LIBCPP_STD_VER > 14 + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(iterator __p) {return __table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __first, const_iterator __last) + {return __table_.erase(__first.__i_, __last.__i_);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__table_.clear();} + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + insert_return_type insert(node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to unordered_map::insert()"); + return __table_.template __node_handle_insert_unique< + node_type, insert_return_type>(_VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __hint, node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to unordered_map::insert()"); + return __table_.template __node_handle_insert_unique<node_type>( + __hint.__i_, _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(key_type const& __key) + { + return __table_.template __node_handle_extract<node_type>(__key); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(const_iterator __it) + { + return __table_.template __node_handle_extract<node_type>( + __it.__i_); + } + + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_unique(__source.__table_); + } + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_unique(__source.__table_); + } + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_unique(__source.__table_); + } + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_unique(__source.__table_); + } +#endif + + _LIBCPP_INLINE_VISIBILITY + void swap(unordered_map& __u) + _NOEXCEPT_(__is_nothrow_swappable<__table>::value) + { __table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_function() const + {return __table_.hash_function().hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const + {return __table_.key_eq().key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<iterator, iterator> equal_range(const key_type& __k) + {return __table_.__equal_range_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + {return __table_.__equal_range_unique(__k);} + + mapped_type& operator[](const key_type& __k); +#ifndef _LIBCPP_CXX03_LANG + mapped_type& operator[](key_type&& __k); +#endif + + mapped_type& at(const key_type& __k); + const mapped_type& at(const key_type& __k) const; + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_size(size_type __n) const + {return __table_.bucket_size(__n);} + _LIBCPP_INLINE_VISIBILITY + size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} + + _LIBCPP_INLINE_VISIBILITY + local_iterator begin(size_type __n) {return __table_.begin(__n);} + _LIBCPP_INLINE_VISIBILITY + local_iterator end(size_type __n) {return __table_.end(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator end(size_type __n) const {return __table_.cend(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} + + _LIBCPP_INLINE_VISIBILITY + float load_factor() const _NOEXCEPT {return __table_.load_factor();} + _LIBCPP_INLINE_VISIBILITY + float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} + _LIBCPP_INLINE_VISIBILITY + void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} + _LIBCPP_INLINE_VISIBILITY + void rehash(size_type __n) {__table_.rehash(__n);} + _LIBCPP_INLINE_VISIBILITY + void reserve(size_type __n) {__table_.reserve(__n);} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const + {return __table_.__dereferenceable(&__i->__i_);} + bool __decrementable(const const_iterator* __i) const + {return __table_.__decrementable(&__i->__i_);} + bool __addable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(&__i->__i_, __n);} + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(&__i->__i_, __n);} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +private: + +#ifdef _LIBCPP_CXX03_LANG + __node_holder __construct_node_with_key(const key_type& __k); +#endif +}; + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + size_type __n, const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a) + : __table_(__hf, __eql, typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + const allocator_type& __a) + : __table_(typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + _InputIterator __first, _InputIterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + const unordered_map& __u) + : __table_(__u.__table_) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + const unordered_map& __u, const allocator_type& __a) + : __table_(__u.__table_, typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + unordered_map&& __u) + _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) + : __table_(_VSTD::move(__u.__table_)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); +#endif +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + unordered_map&& __u, const allocator_type& __a) + : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__a != __u.get_allocator()) + { + iterator __i = __u.begin(); + while (__u.size() != 0) { + __table_.__emplace_unique( + __u.__table_.remove((__i++).__i_)->__value_.__move()); + } + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + initializer_list<value_type> __il) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + insert(__il.begin(), __il.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__il.begin(), __il.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( + initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__il.begin(), __il.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u) + _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) +{ + __table_ = _VSTD::move(__u.__table_); + return *this; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( + initializer_list<value_type> __il) +{ + __table_.__assign_unique(__il.begin(), __il.end()); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +inline +void +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_unique(*__first); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +_Tp& +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) +{ + return __table_.__emplace_unique_key_args(__k, + std::piecewise_construct, std::forward_as_tuple(__k), + std::forward_as_tuple()).first->__get_value().second; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +_Tp& +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k) +{ + return __table_.__emplace_unique_key_args(__k, + std::piecewise_construct, std::forward_as_tuple(std::move(__k)), + std::forward_as_tuple()).first->__get_value().second; +} +#else // _LIBCPP_CXX03_LANG + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k) +{ + __node_allocator& __na = __table_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second)); + __h.get_deleter().__second_constructed = true; + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +_Tp& +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) +{ + iterator __i = find(__k); + if (__i != end()) + return __i->second; + __node_holder __h = __construct_node_with_key(__k); + pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); + __h.release(); + return __r.first->second; +} + +#endif // _LIBCPP_CXX03_MODE + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +_Tp& +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) +{ + iterator __i = find(__k); + if (__i == end()) + __throw_out_of_range("unordered_map::at: key not found"); + return __i->second; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +const _Tp& +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const +{ + const_iterator __i = find(__k); + if (__i == end()) + __throw_out_of_range("unordered_map::at: key not found"); + return __i->second; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) +{ __libcpp_erase_if_container(__c, __pred); } +#endif + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +bool +operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); + __i != __ex; ++__i) + { + const_iterator __j = __y.find(__i->first); + if (__j == __ey || !(*__i == *__j)) + return false; + } + return true; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, + class _Alloc = allocator<pair<const _Key, _Tp> > > +class _LIBCPP_TEMPLATE_VIS unordered_multimap +{ +public: + // types + typedef _Key key_type; + typedef _Tp mapped_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef pair<const key_type, mapped_type> value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + static_assert((is_same<value_type, typename allocator_type::value_type>::value), + "Invalid allocator::value_type"); + +private: + typedef __hash_value_type<key_type, mapped_type> __value_type; + typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; + typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; + typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, + __value_type>::type __allocator_type; + + typedef __hash_table<__value_type, __hasher, + __key_equal, __allocator_type> __table; + + __table __table_; + + typedef typename __table::_NodeTypes _NodeTypes; + typedef typename __table::__node_traits __node_traits; + typedef typename __table::__node_allocator __node_allocator; + typedef typename __table::__node __node; + typedef __hash_map_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + typedef allocator_traits<allocator_type> __alloc_traits; + static_assert((is_same<typename __node_traits::size_type, + typename __alloc_traits::size_type>::value), + "Allocator uses different size_type for different types"); +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __table::size_type size_type; + typedef typename __table::difference_type difference_type; + + typedef __hash_map_iterator<typename __table::iterator> iterator; + typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; + typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; + typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; + +#if _LIBCPP_STD_VER > 14 + typedef __map_node_handle<__node, allocator_type> node_type; +#endif + + template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; + + _LIBCPP_INLINE_VISIBILITY + unordered_multimap() + _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + unordered_multimap(size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + template <class _InputIterator> + unordered_multimap(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + unordered_multimap(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template <class _InputIterator> + unordered_multimap(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + explicit unordered_multimap(const allocator_type& __a); + unordered_multimap(const unordered_multimap& __u); + unordered_multimap(const unordered_multimap& __u, const allocator_type& __a); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(unordered_multimap&& __u) + _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); + unordered_multimap(unordered_multimap&& __u, const allocator_type& __a); + unordered_multimap(initializer_list<value_type> __il); + unordered_multimap(initializer_list<value_type> __il, size_type __n, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + unordered_multimap(initializer_list<value_type> __il, size_type __n, + const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); +#endif // _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(size_type __n, const allocator_type& __a) + : unordered_multimap(__n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_multimap(__n, __hf, key_equal(), __a) {} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) + : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {} + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, + const allocator_type& __a) + : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) + : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const allocator_type& __a) + : unordered_multimap(__il, __n, __hf, key_equal(), __a) {} +#endif + _LIBCPP_INLINE_VISIBILITY + ~unordered_multimap() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); + } + + _LIBCPP_INLINE_VISIBILITY + unordered_multimap& operator=(const unordered_multimap& __u) + { +#ifndef _LIBCPP_CXX03_LANG + __table_ = __u.__table_; +#else + if (this != &__u) { + __table_.clear(); + __table_.hash_function() = __u.__table_.hash_function(); + __table_.key_eq() = __u.__table_.key_eq(); + __table_.max_load_factor() = __u.__table_.max_load_factor(); + __table_.__copy_assign_alloc(__u.__table_); + insert(__u.begin(), __u.end()); + } +#endif + return *this; + } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + unordered_multimap& operator=(unordered_multimap&& __u) + _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); + _LIBCPP_INLINE_VISIBILITY + unordered_multimap& operator=(initializer_list<value_type> __il); +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, const value_type& __x) + {return __table_.__insert_multi(__p.__i_, __x);} + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __first, _InputIterator __last); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} + _LIBCPP_INLINE_VISIBILITY + iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, value_type&& __x) + {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));} + + template <class _Pp, + class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator insert(_Pp&& __x) + {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));} + + template <class _Pp, + class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, _Pp&& __x) + {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));} + + template <class... _Args> + iterator emplace(_Args&&... __args) { + return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...); + } + + template <class... _Args> + iterator emplace_hint(const_iterator __p, _Args&&... __args) { + return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...); + } +#endif // _LIBCPP_CXX03_LANG + + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(iterator __p) {return __table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __first, const_iterator __last) + {return __table_.erase(__first.__i_, __last.__i_);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__table_.clear();} + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + iterator insert(node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to unordered_multimap::insert()"); + return __table_.template __node_handle_insert_multi<node_type>( + _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __hint, node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to unordered_multimap::insert()"); + return __table_.template __node_handle_insert_multi<node_type>( + __hint.__i_, _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(key_type const& __key) + { + return __table_.template __node_handle_extract<node_type>(__key); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(const_iterator __it) + { + return __table_.template __node_handle_extract<node_type>( + __it.__i_); + } + + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_multi(__source.__table_); + } + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_multi(__source.__table_); + } + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_multi(__source.__table_); + } + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_multi(__source.__table_); + } +#endif + + _LIBCPP_INLINE_VISIBILITY + void swap(unordered_multimap& __u) + _NOEXCEPT_(__is_nothrow_swappable<__table>::value) + {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_function() const + {return __table_.hash_function().hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const + {return __table_.key_eq().key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<iterator, iterator> equal_range(const key_type& __k) + {return __table_.__equal_range_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + {return __table_.__equal_range_multi(__k);} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const _NOEXCEPT + {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_size(size_type __n) const + {return __table_.bucket_size(__n);} + _LIBCPP_INLINE_VISIBILITY + size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} + + _LIBCPP_INLINE_VISIBILITY + local_iterator begin(size_type __n) {return __table_.begin(__n);} + _LIBCPP_INLINE_VISIBILITY + local_iterator end(size_type __n) {return __table_.end(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator end(size_type __n) const {return __table_.cend(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} + + _LIBCPP_INLINE_VISIBILITY + float load_factor() const _NOEXCEPT {return __table_.load_factor();} + _LIBCPP_INLINE_VISIBILITY + float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} + _LIBCPP_INLINE_VISIBILITY + void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} + _LIBCPP_INLINE_VISIBILITY + void rehash(size_type __n) {__table_.rehash(__n);} + _LIBCPP_INLINE_VISIBILITY + void reserve(size_type __n) {__table_.reserve(__n);} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const + {return __table_.__dereferenceable(&__i->__i_);} + bool __decrementable(const const_iterator* __i) const + {return __table_.__decrementable(&__i->__i_);} + bool __addable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(&__i->__i_, __n);} + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(&__i->__i_, __n);} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + +}; + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + size_type __n, const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a) + : __table_(__hf, __eql, typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + _InputIterator __first, _InputIterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + const allocator_type& __a) + : __table_(typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + const unordered_multimap& __u) + : __table_(__u.__table_) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + const unordered_multimap& __u, const allocator_type& __a) + : __table_(__u.__table_, typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + unordered_multimap&& __u) + _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) + : __table_(_VSTD::move(__u.__table_)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); +#endif +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + unordered_multimap&& __u, const allocator_type& __a) + : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__a != __u.get_allocator()) + { + iterator __i = __u.begin(); + while (__u.size() != 0) + { + __table_.__insert_multi( + __u.__table_.remove((__i++).__i_)->__value_.__move()); + } + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + initializer_list<value_type> __il) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + insert(__il.begin(), __il.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__il.begin(), __il.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( + initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, typename __table::allocator_type(__a)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__il.begin(), __il.end()); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u) + _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) +{ + __table_ = _VSTD::move(__u.__table_); + return *this; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( + initializer_list<value_type> __il) +{ + __table_.__assign_multi(__il.begin(), __il.end()); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + + + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +inline +void +unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_multi(*__first); +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) +{ __libcpp_erase_if_container(__c, __pred); } +#endif + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +bool +operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + typedef pair<const_iterator, const_iterator> _EqRng; + for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) + { + _EqRng __xeq = __x.equal_range(__i->first); + _EqRng __yeq = __y.equal_range(__i->first); + if (_VSTD::distance(__xeq.first, __xeq.second) != + _VSTD::distance(__yeq.first, __yeq.second) || + !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) + return false; + __i = __xeq.second; + } + return true; +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_UNORDERED_MAP diff --git a/android/x86/include/v8/libc++/unordered_set b/android/x86/include/v8/libc++/unordered_set new file mode 100755 index 00000000..b32e4cae --- /dev/null +++ b/android/x86/include/v8/libc++/unordered_set @@ -0,0 +1,1560 @@ +// -*- C++ -*- +//===-------------------------- unordered_set -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_UNORDERED_SET +#define _LIBCPP_UNORDERED_SET + +/* + + unordered_set synopsis + +#include <initializer_list> + +namespace std +{ + +template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, + class Alloc = allocator<Value>> +class unordered_set +{ +public: + // types + typedef Value key_type; + typedef key_type value_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + typedef /unspecified/ local_iterator; + typedef /unspecified/ const_local_iterator; + + typedef unspecified node_type unspecified; // C++17 + typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17 + + unordered_set() + noexcept( + is_nothrow_default_constructible<hasher>::value && + is_nothrow_default_constructible<key_equal>::value && + is_nothrow_default_constructible<allocator_type>::value); + explicit unordered_set(size_type n, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template <class InputIterator> + unordered_set(InputIterator f, InputIterator l, + size_type n = 0, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + explicit unordered_set(const allocator_type&); + unordered_set(const unordered_set&); + unordered_set(const unordered_set&, const Allocator&); + unordered_set(unordered_set&&) + noexcept( + is_nothrow_move_constructible<hasher>::value && + is_nothrow_move_constructible<key_equal>::value && + is_nothrow_move_constructible<allocator_type>::value); + unordered_set(unordered_set&&, const Allocator&); + unordered_set(initializer_list<value_type>, size_type n = 0, + const hasher& hf = hasher(), const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + unordered_set(size_type n, const allocator_type& a); // C++14 + unordered_set(size_type n, const hasher& hf, const allocator_type& a); // C++14 + template <class InputIterator> + unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14 + template <class InputIterator> + unordered_set(InputIterator f, InputIterator l, size_type n, + const hasher& hf, const allocator_type& a); // C++14 + unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14 + unordered_set(initializer_list<value_type> il, size_type n, + const hasher& hf, const allocator_type& a); // C++14 + ~unordered_set(); + unordered_set& operator=(const unordered_set&); + unordered_set& operator=(unordered_set&&) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value && + is_nothrow_move_assignable<hasher>::value && + is_nothrow_move_assignable<key_equal>::value); + unordered_set& operator=(initializer_list<value_type>); + + allocator_type get_allocator() const noexcept; + + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + iterator begin() noexcept; + iterator end() noexcept; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + template <class... Args> + pair<iterator, bool> emplace(Args&&... args); + template <class... Args> + iterator emplace_hint(const_iterator position, Args&&... args); + pair<iterator, bool> insert(const value_type& obj); + pair<iterator, bool> insert(value_type&& obj); + iterator insert(const_iterator hint, const value_type& obj); + iterator insert(const_iterator hint, value_type&& obj); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + void insert(initializer_list<value_type>); + + node_type extract(const_iterator position); // C++17 + node_type extract(const key_type& x); // C++17 + insert_return_type insert(node_type&& nh); // C++17 + iterator insert(const_iterator hint, node_type&& nh); // C++17 + + iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + template<class H2, class P2> + void merge(unordered_set<Key, H2, P2, Allocator>& source); // C++17 + template<class H2, class P2> + void merge(unordered_set<Key, H2, P2, Allocator>&& source); // C++17 + template<class H2, class P2> + void merge(unordered_multiset<Key, H2, P2, Allocator>& source); // C++17 + template<class H2, class P2> + void merge(unordered_multiset<Key, H2, P2, Allocator>&& source); // C++17 + + void swap(unordered_set&) + noexcept(allocator_traits<Allocator>::is_always_equal::value && + noexcept(swap(declval<hasher&>(), declval<hasher&>())) && + noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17 + + hasher hash_function() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair<iterator, iterator> equal_range(const key_type& k); + pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + + size_type bucket_count() const noexcept; + size_type max_bucket_count() const noexcept; + + size_type bucket_size(size_type n) const; + size_type bucket(const key_type& k) const; + + local_iterator begin(size_type n); + local_iterator end(size_type n); + const_local_iterator begin(size_type n) const; + const_local_iterator end(size_type n) const; + const_local_iterator cbegin(size_type n) const; + const_local_iterator cend(size_type n) const; + + float load_factor() const noexcept; + float max_load_factor() const noexcept; + void max_load_factor(float z); + void rehash(size_type n); + void reserve(size_type n); +}; + +template <class Value, class Hash, class Pred, class Alloc> + void swap(unordered_set<Value, Hash, Pred, Alloc>& x, + unordered_set<Value, Hash, Pred, Alloc>& y) + noexcept(noexcept(x.swap(y))); + +template <class Value, class Hash, class Pred, class Alloc> + bool + operator==(const unordered_set<Value, Hash, Pred, Alloc>& x, + const unordered_set<Value, Hash, Pred, Alloc>& y); + +template <class Value, class Hash, class Pred, class Alloc> + bool + operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x, + const unordered_set<Value, Hash, Pred, Alloc>& y); + +template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, + class Alloc = allocator<Value>> +class unordered_multiset +{ +public: + // types + typedef Value key_type; + typedef key_type value_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits<allocator_type>::pointer pointer; + typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; + typedef typename allocator_traits<allocator_type>::size_type size_type; + typedef typename allocator_traits<allocator_type>::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + typedef /unspecified/ local_iterator; + typedef /unspecified/ const_local_iterator; + + typedef unspecified node_type unspecified; // C++17 + + unordered_multiset() + noexcept( + is_nothrow_default_constructible<hasher>::value && + is_nothrow_default_constructible<key_equal>::value && + is_nothrow_default_constructible<allocator_type>::value); + explicit unordered_multiset(size_type n, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template <class InputIterator> + unordered_multiset(InputIterator f, InputIterator l, + size_type n = 0, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + explicit unordered_multiset(const allocator_type&); + unordered_multiset(const unordered_multiset&); + unordered_multiset(const unordered_multiset&, const Allocator&); + unordered_multiset(unordered_multiset&&) + noexcept( + is_nothrow_move_constructible<hasher>::value && + is_nothrow_move_constructible<key_equal>::value && + is_nothrow_move_constructible<allocator_type>::value); + unordered_multiset(unordered_multiset&&, const Allocator&); + unordered_multiset(initializer_list<value_type>, size_type n = /see below/, + const hasher& hf = hasher(), const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + unordered_multiset(size_type n, const allocator_type& a); // C++14 + unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14 + template <class InputIterator> + unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14 + template <class InputIterator> + unordered_multiset(InputIterator f, InputIterator l, size_type n, + const hasher& hf, const allocator_type& a); // C++14 + unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14 + unordered_multiset(initializer_list<value_type> il, size_type n, + const hasher& hf, const allocator_type& a); // C++14 + ~unordered_multiset(); + unordered_multiset& operator=(const unordered_multiset&); + unordered_multiset& operator=(unordered_multiset&&) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value && + is_nothrow_move_assignable<hasher>::value && + is_nothrow_move_assignable<key_equal>::value); + unordered_multiset& operator=(initializer_list<value_type>); + + allocator_type get_allocator() const noexcept; + + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + iterator begin() noexcept; + iterator end() noexcept; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + template <class... Args> + iterator emplace(Args&&... args); + template <class... Args> + iterator emplace_hint(const_iterator position, Args&&... args); + iterator insert(const value_type& obj); + iterator insert(value_type&& obj); + iterator insert(const_iterator hint, const value_type& obj); + iterator insert(const_iterator hint, value_type&& obj); + template <class InputIterator> + void insert(InputIterator first, InputIterator last); + void insert(initializer_list<value_type>); + + node_type extract(const_iterator position); // C++17 + node_type extract(const key_type& x); // C++17 + iterator insert(node_type&& nh); // C++17 + iterator insert(const_iterator hint, node_type&& nh); // C++17 + + iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + template<class H2, class P2> + void merge(unordered_multiset<Key, H2, P2, Allocator>& source); // C++17 + template<class H2, class P2> + void merge(unordered_multiset<Key, H2, P2, Allocator>&& source); // C++17 + template<class H2, class P2> + void merge(unordered_set<Key, H2, P2, Allocator>& source); // C++17 + template<class H2, class P2> + void merge(unordered_set<Key, H2, P2, Allocator>&& source); // C++17 + + void swap(unordered_multiset&) + noexcept(allocator_traits<Allocator>::is_always_equal::value && + noexcept(swap(declval<hasher&>(), declval<hasher&>())) && + noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17 + + hasher hash_function() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair<iterator, iterator> equal_range(const key_type& k); + pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + + size_type bucket_count() const noexcept; + size_type max_bucket_count() const noexcept; + + size_type bucket_size(size_type n) const; + size_type bucket(const key_type& k) const; + + local_iterator begin(size_type n); + local_iterator end(size_type n); + const_local_iterator begin(size_type n) const; + const_local_iterator end(size_type n) const; + const_local_iterator cbegin(size_type n) const; + const_local_iterator cend(size_type n) const; + + float load_factor() const noexcept; + float max_load_factor() const noexcept; + void max_load_factor(float z); + void rehash(size_type n); + void reserve(size_type n); +}; + +template <class Value, class Hash, class Pred, class Alloc> + void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x, + unordered_multiset<Value, Hash, Pred, Alloc>& y) + noexcept(noexcept(x.swap(y))); + +template <class K, class T, class H, class P, class A, class Predicate> + void erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20 + +template <class K, class T, class H, class P, class A, class Predicate> + void erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20 + + +template <class Value, class Hash, class Pred, class Alloc> + bool + operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x, + const unordered_multiset<Value, Hash, Pred, Alloc>& y); + +template <class Value, class Hash, class Pred, class Alloc> + bool + operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x, + const unordered_multiset<Value, Hash, Pred, Alloc>& y); +} // std + +*/ + +#include <__config> +#include <__hash_table> +#include <__node_handle> +#include <functional> +#include <version> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Value, class _Hash, class _Pred, class _Alloc> +class unordered_multiset; + +template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, + class _Alloc = allocator<_Value> > +class _LIBCPP_TEMPLATE_VIS unordered_set +{ +public: + // types + typedef _Value key_type; + typedef key_type value_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + static_assert((is_same<value_type, typename allocator_type::value_type>::value), + "Invalid allocator::value_type"); + +private: + typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; + + __table __table_; + +public: + typedef typename __table::pointer pointer; + typedef typename __table::const_pointer const_pointer; + typedef typename __table::size_type size_type; + typedef typename __table::difference_type difference_type; + + typedef typename __table::const_iterator iterator; + typedef typename __table::const_iterator const_iterator; + typedef typename __table::const_local_iterator local_iterator; + typedef typename __table::const_local_iterator const_local_iterator; + +#if _LIBCPP_STD_VER > 14 + typedef __set_node_handle<typename __table::__node, allocator_type> node_type; + typedef __insert_return_type<iterator, node_type> insert_return_type; +#endif + + template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS unordered_set; + template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS unordered_multiset; + + _LIBCPP_INLINE_VISIBILITY + unordered_set() + _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + explicit unordered_set(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); +#if _LIBCPP_STD_VER > 11 + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(size_type __n, const allocator_type& __a) + : unordered_set(__n, hasher(), key_equal(), __a) {} + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_set(__n, __hf, key_equal(), __a) {} +#endif + unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); + template <class _InputIterator> + unordered_set(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + unordered_set(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template <class _InputIterator> + unordered_set(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + template <class _InputIterator> + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(_InputIterator __first, _InputIterator __last, + size_type __n, const allocator_type& __a) + : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {} + template <class _InputIterator> + unordered_set(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit unordered_set(const allocator_type& __a); + unordered_set(const unordered_set& __u); + unordered_set(const unordered_set& __u, const allocator_type& __a); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + unordered_set(unordered_set&& __u) + _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); + unordered_set(unordered_set&& __u, const allocator_type& __a); + unordered_set(initializer_list<value_type> __il); + unordered_set(initializer_list<value_type> __il, size_type __n, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + unordered_set(initializer_list<value_type> __il, size_type __n, + const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(initializer_list<value_type> __il, size_type __n, + const allocator_type& __a) + : unordered_set(__il, __n, hasher(), key_equal(), __a) {} + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(initializer_list<value_type> __il, size_type __n, + const hasher& __hf, const allocator_type& __a) + : unordered_set(__il, __n, __hf, key_equal(), __a) {} +#endif +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + ~unordered_set() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); + } + + _LIBCPP_INLINE_VISIBILITY + unordered_set& operator=(const unordered_set& __u) + { + __table_ = __u.__table_; + return *this; + } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + unordered_set& operator=(unordered_set&& __u) + _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); + _LIBCPP_INLINE_VISIBILITY + unordered_set& operator=(initializer_list<value_type> __il); +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return __table_.end();} + +#ifndef _LIBCPP_CXX03_LANG + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> emplace(_Args&&... __args) + {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);} + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator emplace_hint(const_iterator __p, _Args&&... __args) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered_set"); + return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; + } +#else + iterator emplace_hint(const_iterator, _Args&&... __args) + {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;} +#endif + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert(value_type&& __x) + {return __table_.__insert_unique(_VSTD::move(__x));} + _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator insert(const_iterator __p, value_type&& __x) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_set::insert(const_iterator, value_type&&) called with an iterator not" + " referring to this unordered_set"); + return insert(_VSTD::move(__x)).first; + } +#else + iterator insert(const_iterator, value_type&& __x) + {return insert(_VSTD::move(__x)).first;} +#endif + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert(const value_type& __x) + {return __table_.__insert_unique(__x);} + + _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator insert(const_iterator __p, const value_type& __x) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_set::insert(const_iterator, const value_type&) called with an iterator not" + " referring to this unordered_set"); + return insert(__x).first; + } +#else + iterator insert(const_iterator, const value_type& __x) + {return insert(__x).first;} +#endif + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __table_.erase(__p);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __first, const_iterator __last) + {return __table_.erase(__first, __last);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__table_.clear();} + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + insert_return_type insert(node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to unordered_set::insert()"); + return __table_.template __node_handle_insert_unique< + node_type, insert_return_type>(_VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __h, node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to unordered_set::insert()"); + return __table_.template __node_handle_insert_unique<node_type>( + __h, _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(key_type const& __key) + { + return __table_.template __node_handle_extract<node_type>(__key); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(const_iterator __it) + { + return __table_.template __node_handle_extract<node_type>(__it); + } + + template<class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __table_.__node_handle_merge_unique(__source.__table_); + } + template<class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __table_.__node_handle_merge_unique(__source.__table_); + } + template<class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __table_.__node_handle_merge_unique(__source.__table_); + } + template<class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + __table_.__node_handle_merge_unique(__source.__table_); + } +#endif + + _LIBCPP_INLINE_VISIBILITY + void swap(unordered_set& __u) + _NOEXCEPT_(__is_nothrow_swappable<__table>::value) + {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_function() const {return __table_.hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const {return __table_.key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<iterator, iterator> equal_range(const key_type& __k) + {return __table_.__equal_range_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + {return __table_.__equal_range_unique(__k);} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);} + _LIBCPP_INLINE_VISIBILITY + size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} + + _LIBCPP_INLINE_VISIBILITY + local_iterator begin(size_type __n) {return __table_.begin(__n);} + _LIBCPP_INLINE_VISIBILITY + local_iterator end(size_type __n) {return __table_.end(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator end(size_type __n) const {return __table_.cend(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} + + _LIBCPP_INLINE_VISIBILITY + float load_factor() const _NOEXCEPT {return __table_.load_factor();} + _LIBCPP_INLINE_VISIBILITY + float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} + _LIBCPP_INLINE_VISIBILITY + void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} + _LIBCPP_INLINE_VISIBILITY + void rehash(size_type __n) {__table_.rehash(__n);} + _LIBCPP_INLINE_VISIBILITY + void reserve(size_type __n) {__table_.reserve(__n);} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const + {return __table_.__dereferenceable(__i);} + bool __decrementable(const const_iterator* __i) const + {return __table_.__decrementable(__i);} + bool __addable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(__i, __n);} + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(__i, __n);} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +}; + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + _InputIterator __first, _InputIterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + const allocator_type& __a) + : __table_(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + const unordered_set& __u) + : __table_(__u.__table_) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + const unordered_set& __u, const allocator_type& __a) + : __table_(__u.__table_, __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + unordered_set&& __u) + _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) + : __table_(_VSTD::move(__u.__table_)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); +#endif +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + unordered_set&& __u, const allocator_type& __a) + : __table_(_VSTD::move(__u.__table_), __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__a != __u.get_allocator()) + { + iterator __i = __u.begin(); + while (__u.size() != 0) + __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_)); + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + initializer_list<value_type> __il) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + insert(__il.begin(), __il.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__il.begin(), __il.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( + initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__il.begin(), __il.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline +unordered_set<_Value, _Hash, _Pred, _Alloc>& +unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u) + _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) +{ + __table_ = _VSTD::move(__u.__table_); + return *this; +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline +unordered_set<_Value, _Hash, _Pred, _Alloc>& +unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=( + initializer_list<value_type> __il) +{ + __table_.__assign_unique(__il.begin(), __il.end()); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +inline +void +unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_unique(*__first); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, + unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) +{ __libcpp_erase_if_container(__c, __pred); } +#endif + +template <class _Value, class _Hash, class _Pred, class _Alloc> +bool +operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, + const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); + __i != __ex; ++__i) + { + const_iterator __j = __y.find(*__i); + if (__j == __ey || !(*__i == *__j)) + return false; + } + return true; +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, + const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, + class _Alloc = allocator<_Value> > +class _LIBCPP_TEMPLATE_VIS unordered_multiset +{ +public: + // types + typedef _Value key_type; + typedef key_type value_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + static_assert((is_same<value_type, typename allocator_type::value_type>::value), + "Invalid allocator::value_type"); + +private: + typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; + + __table __table_; + +public: + typedef typename __table::pointer pointer; + typedef typename __table::const_pointer const_pointer; + typedef typename __table::size_type size_type; + typedef typename __table::difference_type difference_type; + + typedef typename __table::const_iterator iterator; + typedef typename __table::const_iterator const_iterator; + typedef typename __table::const_local_iterator local_iterator; + typedef typename __table::const_local_iterator const_local_iterator; + +#if _LIBCPP_STD_VER > 14 + typedef __set_node_handle<typename __table::__node, allocator_type> node_type; +#endif + + template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS unordered_set; + template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> + friend class _LIBCPP_TEMPLATE_VIS unordered_multiset; + + _LIBCPP_INLINE_VISIBILITY + unordered_multiset() + _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + unordered_multiset(size_type __n, const hasher& __hf, + const key_equal& __eql, const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(size_type __n, const allocator_type& __a) + : unordered_multiset(__n, hasher(), key_equal(), __a) {} + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_multiset(__n, __hf, key_equal(), __a) {} +#endif + template <class _InputIterator> + unordered_multiset(_InputIterator __first, _InputIterator __last); + template <class _InputIterator> + unordered_multiset(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template <class _InputIterator> + unordered_multiset(_InputIterator __first, _InputIterator __last, + size_type __n , const hasher& __hf, + const key_equal& __eql, const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + template <class _InputIterator> + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(_InputIterator __first, _InputIterator __last, + size_type __n, const allocator_type& __a) + : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {} + template <class _InputIterator> + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit unordered_multiset(const allocator_type& __a); + unordered_multiset(const unordered_multiset& __u); + unordered_multiset(const unordered_multiset& __u, const allocator_type& __a); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + unordered_multiset(unordered_multiset&& __u) + _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); + unordered_multiset(unordered_multiset&& __u, const allocator_type& __a); + unordered_multiset(initializer_list<value_type> __il); + unordered_multiset(initializer_list<value_type> __il, size_type __n, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + unordered_multiset(initializer_list<value_type> __il, size_type __n, + const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) + : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {} + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_multiset(__il, __n, __hf, key_equal(), __a) {} +#endif +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + ~unordered_multiset() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); + } + + _LIBCPP_INLINE_VISIBILITY + unordered_multiset& operator=(const unordered_multiset& __u) + { + __table_ = __u.__table_; + return *this; + } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + unordered_multiset& operator=(unordered_multiset&& __u) + _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); + unordered_multiset& operator=(initializer_list<value_type> __il); +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return __table_.end();} + +#ifndef _LIBCPP_CXX03_LANG + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator emplace(_Args&&... __args) + {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);} + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator emplace_hint(const_iterator __p, _Args&&... __args) + {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, value_type&& __x) + {return __table_.__insert_multi(__p, _VSTD::move(__x));} + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, const value_type& __x) + {return __table_.__insert_multi(__p, __x);} + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __first, _InputIterator __last); + +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY + iterator insert(node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to unordered_multiset::insert()"); + return __table_.template __node_handle_insert_multi<node_type>( + _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __hint, node_type&& __nh) + { + _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), + "node_type with incompatible allocator passed to unordered_multiset::insert()"); + return __table_.template __node_handle_insert_multi<node_type>( + __hint, _VSTD::move(__nh)); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(const_iterator __position) + { + return __table_.template __node_handle_extract<node_type>( + __position); + } + _LIBCPP_INLINE_VISIBILITY + node_type extract(key_type const& __key) + { + return __table_.template __node_handle_extract<node_type>(__key); + } + + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_multi(__source.__table_); + } + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_multi(__source.__table_); + } + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_multi(__source.__table_); + } + template <class _H2, class _P2> + _LIBCPP_INLINE_VISIBILITY + void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source) + { + _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), + "merging container with incompatible allocator"); + return __table_.__node_handle_merge_multi(__source.__table_); + } +#endif + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __table_.erase(__p);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __first, const_iterator __last) + {return __table_.erase(__first, __last);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__table_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(unordered_multiset& __u) + _NOEXCEPT_(__is_nothrow_swappable<__table>::value) + {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_function() const {return __table_.hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const {return __table_.key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<iterator, iterator> equal_range(const key_type& __k) + {return __table_.__equal_range_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + {return __table_.__equal_range_multi(__k);} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);} + _LIBCPP_INLINE_VISIBILITY + size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} + + _LIBCPP_INLINE_VISIBILITY + local_iterator begin(size_type __n) {return __table_.begin(__n);} + _LIBCPP_INLINE_VISIBILITY + local_iterator end(size_type __n) {return __table_.end(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator end(size_type __n) const {return __table_.cend(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} + _LIBCPP_INLINE_VISIBILITY + const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} + + _LIBCPP_INLINE_VISIBILITY + float load_factor() const _NOEXCEPT {return __table_.load_factor();} + _LIBCPP_INLINE_VISIBILITY + float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} + _LIBCPP_INLINE_VISIBILITY + void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} + _LIBCPP_INLINE_VISIBILITY + void rehash(size_type __n) {__table_.rehash(__n);} + _LIBCPP_INLINE_VISIBILITY + void reserve(size_type __n) {__table_.reserve(__n);} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const + {return __table_.__dereferenceable(__i);} + bool __decrementable(const const_iterator* __i) const + {return __table_.__decrementable(__i);} + bool __addable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(__i, __n);} + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(__i, __n);} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +}; + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + size_type __n, const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + _InputIterator __first, _InputIterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__first, __last); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + const allocator_type& __a) + : __table_(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + const unordered_multiset& __u) + : __table_(__u.__table_) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + const unordered_multiset& __u, const allocator_type& __a) + : __table_(__u.__table_, __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + unordered_multiset&& __u) + _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) + : __table_(_VSTD::move(__u.__table_)) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); +#endif +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + unordered_multiset&& __u, const allocator_type& __a) + : __table_(_VSTD::move(__u.__table_), __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__a != __u.get_allocator()) + { + iterator __i = __u.begin(); + while (__u.size() != 0) + __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_)); + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + initializer_list<value_type> __il) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + insert(__il.begin(), __il.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const key_equal& __eql) + : __table_(__hf, __eql) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__il.begin(), __il.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( + initializer_list<value_type> __il, size_type __n, const hasher& __hf, + const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + __table_.rehash(__n); + insert(__il.begin(), __il.end()); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline +unordered_multiset<_Value, _Hash, _Pred, _Alloc>& +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( + unordered_multiset&& __u) + _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) +{ + __table_ = _VSTD::move(__u.__table_); + return *this; +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline +unordered_multiset<_Value, _Hash, _Pred, _Alloc>& +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( + initializer_list<value_type> __il) +{ + __table_.__assign_multi(__il.begin(), __il.end()); + return *this; +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Value, class _Hash, class _Pred, class _Alloc> +template <class _InputIterator> +inline +void +unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_multi(*__first); +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) +{ __libcpp_erase_if_container(__c, __pred); } +#endif + +template <class _Value, class _Hash, class _Pred, class _Alloc> +bool +operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + typedef pair<const_iterator, const_iterator> _EqRng; + for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) + { + _EqRng __xeq = __x.equal_range(*__i); + _EqRng __yeq = __y.equal_range(*__i); + if (_VSTD::distance(__xeq.first, __xeq.second) != + _VSTD::distance(__yeq.first, __yeq.second) || + !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) + return false; + __i = __xeq.second; + } + return true; +} + +template <class _Value, class _Hash, class _Pred, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_UNORDERED_SET diff --git a/android/x86/include/v8/libc++/utility b/android/x86/include/v8/libc++/utility new file mode 100755 index 00000000..3eea6f3c --- /dev/null +++ b/android/x86/include/v8/libc++/utility @@ -0,0 +1,1622 @@ +// -*- C++ -*- +//===-------------------------- utility -----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_UTILITY +#define _LIBCPP_UTILITY + +/* + utility synopsis + +#include <initializer_list> + +namespace std +{ + +template <class T> + void + swap(T& a, T& b); + +namespace rel_ops +{ + template<class T> bool operator!=(const T&, const T&); + template<class T> bool operator> (const T&, const T&); + template<class T> bool operator<=(const T&, const T&); + template<class T> bool operator>=(const T&, const T&); +} + +template<class T> +void +swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value && + is_nothrow_move_assignable<T>::value); + +template <class T, size_t N> +void +swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); + +template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14 +template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14 + +template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14 + +template <class T> + typename conditional + < + !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, + const T&, + T&& + >::type + move_if_noexcept(T& x) noexcept; // constexpr in C++14 + +template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17 +template <class T> void as_const(const T&&) = delete; // C++17 + +template <class T> typename add_rvalue_reference<T>::type declval() noexcept; + +template <class T1, class T2> +struct pair +{ + typedef T1 first_type; + typedef T2 second_type; + + T1 first; + T2 second; + + pair(const pair&) = default; + pair(pair&&) = default; + constexpr pair(); + pair(const T1& x, const T2& y); // constexpr in C++14 + template <class U, class V> pair(U&& x, V&& y); // constexpr in C++14 + template <class U, class V> pair(const pair<U, V>& p); // constexpr in C++14 + template <class U, class V> pair(pair<U, V>&& p); // constexpr in C++14 + template <class... Args1, class... Args2> + pair(piecewise_construct_t, tuple<Args1...> first_args, + tuple<Args2...> second_args); + + template <class U, class V> pair& operator=(const pair<U, V>& p); + pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && + is_nothrow_move_assignable<T2>::value); + template <class U, class V> pair& operator=(pair<U, V>&& p); + + void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> && + is_nothrow_swappable_v<T2>); +}; + +template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 + +template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 +template <class T1, class T2> +void +swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); + +struct piecewise_construct_t { }; +inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); + +template <class T> struct tuple_size; +template <size_t I, class T> struct tuple_element; + +template <class T1, class T2> struct tuple_size<pair<T1, T2> >; +template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; +template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; + +template<size_t I, class T1, class T2> + typename tuple_element<I, pair<T1, T2> >::type& + get(pair<T1, T2>&) noexcept; // constexpr in C++14 + +template<size_t I, class T1, class T2> + const typename tuple_element<I, pair<T1, T2> >::type& + get(const pair<T1, T2>&) noexcept; // constexpr in C++14 + +template<size_t I, class T1, class T2> + typename tuple_element<I, pair<T1, T2> >::type&& + get(pair<T1, T2>&&) noexcept; // constexpr in C++14 + +template<size_t I, class T1, class T2> + const typename tuple_element<I, pair<T1, T2> >::type&& + get(const pair<T1, T2>&&) noexcept; // constexpr in C++14 + +template<class T1, class T2> + constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 + +template<class T1, class T2> + constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14 + +template<class T1, class T2> + constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 + +template<class T1, class T2> + constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14 + +template<class T1, class T2> + constexpr T1& get(pair<T2, T1>&) noexcept; // C++14 + +template<class T1, class T2> + constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14 + +template<class T1, class T2> + constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14 + +template<class T1, class T2> + constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14 + +// C++14 + +template<class T, T... I> +struct integer_sequence +{ + typedef T value_type; + + static constexpr size_t size() noexcept; +}; + +template<size_t... I> + using index_sequence = integer_sequence<size_t, I...>; + +template<class T, T N> + using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; +template<size_t N> + using make_index_sequence = make_integer_sequence<size_t, N>; + +template<class... T> + using index_sequence_for = make_index_sequence<sizeof...(T)>; + +template<class T, class U=T> + T exchange(T& obj, U&& new_value); + +// 20.2.7, in-place construction // C++17 +struct in_place_t { + explicit in_place_t() = default; +}; +inline constexpr in_place_t in_place{}; +template <class T> + struct in_place_type_t { + explicit in_place_type_t() = default; + }; +template <class T> + inline constexpr in_place_type_t<T> in_place_type{}; +template <size_t I> + struct in_place_index_t { + explicit in_place_index_t() = default; + }; +template <size_t I> + inline constexpr in_place_index_t<I> in_place_index{}; + +} // std + +*/ + +#include <__config> +#include <__tuple> +#include <type_traits> +#include <initializer_list> +#include <cstddef> +#include <cstring> +#include <cstdint> +#include <version> +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace rel_ops +{ + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const _Tp& __x, const _Tp& __y) +{ + return !(__x == __y); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const _Tp& __x, const _Tp& __y) +{ + return __y < __x; +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const _Tp& __x, const _Tp& __y) +{ + return !(__y < __x); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const _Tp& __x, const _Tp& __y) +{ + return !(__x < __y); +} + +} // rel_ops + +// swap_ranges + + +template <class _ForwardIterator1, class _ForwardIterator2> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator2 +swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) +{ + for(; __first1 != __last1; ++__first1, (void) ++__first2) + swap(*__first1, *__first2); + return __first2; +} + +// forward declared in <type_traits> +template<class _Tp, size_t _Np> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if< + __is_swappable<_Tp>::value +>::type +swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) +{ + _VSTD::swap_ranges(__a, __a + _Np, __b); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +#ifndef _LIBCPP_CXX03_LANG +typename conditional +< + !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, + const _Tp&, + _Tp&& +>::type +#else // _LIBCPP_CXX03_LANG +const _Tp& +#endif +move_if_noexcept(_Tp& __x) _NOEXCEPT +{ + return _VSTD::move(__x); +} + +#if _LIBCPP_STD_VER > 14 +template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } +template <class _Tp> void as_const(const _Tp&&) = delete; +#endif + +struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { }; +#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) +extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); +#else +/* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); +#endif + +#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) +template <class, class> +struct __non_trivially_copyable_base { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + __non_trivially_copyable_base() _NOEXCEPT {} + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {} +}; +#endif + +template <class _T1, class _T2> +struct _LIBCPP_TEMPLATE_VIS pair +#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) +: private __non_trivially_copyable_base<_T1, _T2> +#endif +{ + typedef _T1 first_type; + typedef _T2 second_type; + + _T1 first; + _T2 second; + +#if !defined(_LIBCPP_CXX03_LANG) + pair(pair const&) = default; + pair(pair&&) = default; +#else + // Use the implicitly declared copy constructor in C++03 +#endif + +#ifdef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + pair() : first(), second() {} + + _LIBCPP_INLINE_VISIBILITY + pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {} + + template <class _U1, class _U2> + _LIBCPP_INLINE_VISIBILITY + pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {} + + _LIBCPP_INLINE_VISIBILITY + pair& operator=(pair const& __p) { + first = __p.first; + second = __p.second; + return *this; + } +#else + template <bool _Val> + using _EnableB = typename enable_if<_Val, bool>::type; + + struct _CheckArgs { + template <class _U1, class _U2> + static constexpr bool __enable_default() { + return is_default_constructible<_U1>::value + && is_default_constructible<_U2>::value; + } + + template <class _U1, class _U2> + static constexpr bool __enable_explicit() { + return is_constructible<first_type, _U1>::value + && is_constructible<second_type, _U2>::value + && (!is_convertible<_U1, first_type>::value + || !is_convertible<_U2, second_type>::value); + } + + template <class _U1, class _U2> + static constexpr bool __enable_implicit() { + return is_constructible<first_type, _U1>::value + && is_constructible<second_type, _U2>::value + && is_convertible<_U1, first_type>::value + && is_convertible<_U2, second_type>::value; + } + }; + + template <bool _MaybeEnable> + using _CheckArgsDep = typename conditional< + _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type; + + struct _CheckTupleLikeConstructor { + template <class _Tuple> + static constexpr bool __enable_implicit() { + return __tuple_convertible<_Tuple, pair>::value; + } + + template <class _Tuple> + static constexpr bool __enable_explicit() { + return __tuple_constructible<_Tuple, pair>::value + && !__tuple_convertible<_Tuple, pair>::value; + } + + template <class _Tuple> + static constexpr bool __enable_assign() { + return __tuple_assignable<_Tuple, pair>::value; + } + }; + + template <class _Tuple> + using _CheckTLC = typename conditional< + __tuple_like_with_size<_Tuple, 2>::value + && !is_same<typename decay<_Tuple>::type, pair>::value, + _CheckTupleLikeConstructor, + __check_tuple_constructor_fail + >::type; + + template<bool _Dummy = true, _EnableB< + _CheckArgsDep<_Dummy>::template __enable_default<_T1, _T2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value && + is_nothrow_default_constructible<second_type>::value) + : first(), second() {} + + template <bool _Dummy = true, _EnableB< + _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(_T1 const& __t1, _T2 const& __t2) + _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && + is_nothrow_copy_constructible<second_type>::value) + : first(__t1), second(__t2) {} + + template<bool _Dummy = true, _EnableB< + _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(_T1 const& __t1, _T2 const& __t2) + _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && + is_nothrow_copy_constructible<second_type>::value) + : first(__t1), second(__t2) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_explicit<_U1, _U2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(_U1&& __u1, _U2&& __u2) + _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value && + is_nothrow_constructible<second_type, _U2>::value)) + : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_implicit<_U1, _U2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(_U1&& __u1, _U2&& __u2) + _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value && + is_nothrow_constructible<second_type, _U2>::value)) + : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(pair<_U1, _U2> const& __p) + _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value && + is_nothrow_constructible<second_type, _U2 const&>::value)) + : first(__p.first), second(__p.second) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(pair<_U1, _U2> const& __p) + _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value && + is_nothrow_constructible<second_type, _U2 const&>::value)) + : first(__p.first), second(__p.second) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_explicit<_U1, _U2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(pair<_U1, _U2>&&__p) + _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value && + is_nothrow_constructible<second_type, _U2&&>::value)) + : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_implicit<_U1, _U2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(pair<_U1, _U2>&& __p) + _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value && + is_nothrow_constructible<second_type, _U2&&>::value)) + : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} + + template<class _Tuple, _EnableB< + _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(_Tuple&& __p) + : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))), + second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {} + + template<class _Tuple, _EnableB< + _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(_Tuple&& __p) + : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))), + second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {} + + template <class... _Args1, class... _Args2> + _LIBCPP_INLINE_VISIBILITY + pair(piecewise_construct_t __pc, + tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) + _NOEXCEPT_((is_nothrow_constructible<first_type, _Args1...>::value && + is_nothrow_constructible<second_type, _Args2...>::value)) + : pair(__pc, __first_args, __second_args, + typename __make_tuple_indices<sizeof...(_Args1)>::type(), + typename __make_tuple_indices<sizeof...(_Args2) >::type()) {} + + _LIBCPP_INLINE_VISIBILITY + pair& operator=(typename conditional< + is_copy_assignable<first_type>::value && + is_copy_assignable<second_type>::value, + pair, __nat>::type const& __p) + _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && + is_nothrow_copy_assignable<second_type>::value) + { + first = __p.first; + second = __p.second; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + pair& operator=(typename conditional< + is_move_assignable<first_type>::value && + is_move_assignable<second_type>::value, + pair, __nat>::type&& __p) + _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && + is_nothrow_move_assignable<second_type>::value) + { + first = _VSTD::forward<first_type>(__p.first); + second = _VSTD::forward<second_type>(__p.second); + return *this; + } + + template <class _Tuple, _EnableB< + _CheckTLC<_Tuple>::template __enable_assign<_Tuple>() + > = false> + _LIBCPP_INLINE_VISIBILITY + pair& operator=(_Tuple&& __p) { + first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p)); + second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p)); + return *this; + } +#endif + + _LIBCPP_INLINE_VISIBILITY + void + swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && + __is_nothrow_swappable<second_type>::value) + { + using _VSTD::swap; + swap(first, __p.first); + swap(second, __p.second); + } +private: + +#ifndef _LIBCPP_CXX03_LANG + template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> + _LIBCPP_INLINE_VISIBILITY + pair(piecewise_construct_t, + tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, + __tuple_indices<_I1...>, __tuple_indices<_I2...>); +#endif +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _T1, class _T2> +pair(_T1, _T2) -> pair<_T1, _T2>; +#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) +{ + return __x.first == __y.first && __x.second == __y.second; +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) +{ + return !(__x == __y); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) +{ + return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) +{ + return __y < __x; +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) +{ + return !(__x < __y); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) +{ + return !(__y < __x); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_swappable<_T1>::value && + __is_swappable<_T2>::value, + void +>::type +swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) + _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && + __is_nothrow_swappable<_T2>::value)) +{ + __x.swap(__y); +} + +template <class _Tp> +struct __unwrap_reference { typedef _Tp type; }; + +template <class _Tp> +struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _Tp& type; }; + +#if _LIBCPP_STD_VER > 17 +template <class _Tp> +struct unwrap_reference : __unwrap_reference<_Tp> { }; + +template <class _Tp> +struct unwrap_ref_decay : unwrap_reference<typename decay<_Tp>::type> { }; +#endif // > C++17 + +template <class _Tp> +struct __unwrap_ref_decay +#if _LIBCPP_STD_VER > 17 + : unwrap_ref_decay<_Tp> +#else + : __unwrap_reference<typename decay<_Tp>::type> +#endif +{ }; + +#ifndef _LIBCPP_CXX03_LANG + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type> +make_pair(_T1&& __t1, _T2&& __t2) +{ + return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type> + (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); +} + +#else // _LIBCPP_CXX03_LANG + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +pair<_T1,_T2> +make_pair(_T1 __x, _T2 __y) +{ + return pair<_T1, _T2>(__x, __y); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _T1, class _T2> + struct _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> > + : public integral_constant<size_t, 2> {}; + +template <size_t _Ip, class _T1, class _T2> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > +{ + static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>"); +}; + +template <class _T1, class _T2> +struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > +{ + typedef _T1 type; +}; + +template <class _T1, class _T2> +struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > +{ + typedef _T2 type; +}; + +template <size_t _Ip> struct __get_pair; + +template <> +struct __get_pair<0> +{ + template <class _T1, class _T2> + static + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _T1& + get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} + + template <class _T1, class _T2> + static + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + const _T1& + get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} + +#ifndef _LIBCPP_CXX03_LANG + template <class _T1, class _T2> + static + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _T1&& + get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} + + template <class _T1, class _T2> + static + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + const _T1&& + get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);} +#endif // _LIBCPP_CXX03_LANG +}; + +template <> +struct __get_pair<1> +{ + template <class _T1, class _T2> + static + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _T2& + get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} + + template <class _T1, class _T2> + static + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + const _T2& + get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} + +#ifndef _LIBCPP_CXX03_LANG + template <class _T1, class _T2> + static + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _T2&& + get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} + + template <class _T1, class _T2> + static + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + const _T2&& + get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);} +#endif // _LIBCPP_CXX03_LANG +}; + +template <size_t _Ip, class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(pair<_T1, _T2>& __p) _NOEXCEPT +{ + return __get_pair<_Ip>::get(__p); +} + +template <size_t _Ip, class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(const pair<_T1, _T2>& __p) _NOEXCEPT +{ + return __get_pair<_Ip>::get(__p); +} + +#ifndef _LIBCPP_CXX03_LANG +template <size_t _Ip, class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(pair<_T1, _T2>&& __p) _NOEXCEPT +{ + return __get_pair<_Ip>::get(_VSTD::move(__p)); +} + +template <size_t _Ip, class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(const pair<_T1, _T2>&& __p) _NOEXCEPT +{ + return __get_pair<_Ip>::get(_VSTD::move(__p)); +} +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 11 +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT +{ + return __get_pair<0>::get(__p); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT +{ + return __get_pair<0>::get(__p); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT +{ + return __get_pair<0>::get(_VSTD::move(__p)); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT +{ + return __get_pair<0>::get(_VSTD::move(__p)); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT +{ + return __get_pair<1>::get(__p); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT +{ + return __get_pair<1>::get(__p); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT +{ + return __get_pair<1>::get(_VSTD::move(__p)); +} + +template <class _T1, class _T2> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT +{ + return __get_pair<1>::get(_VSTD::move(__p)); +} + +#endif + +#if _LIBCPP_STD_VER > 11 + +template<class _Tp, _Tp... _Ip> +struct _LIBCPP_TEMPLATE_VIS integer_sequence +{ + typedef _Tp value_type; + static_assert( is_integral<_Tp>::value, + "std::integer_sequence can only be instantiated with an integral type" ); + static + _LIBCPP_INLINE_VISIBILITY + constexpr + size_t + size() noexcept { return sizeof...(_Ip); } +}; + +template<size_t... _Ip> + using index_sequence = integer_sequence<size_t, _Ip...>; + +#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) + +template <class _Tp, _Tp _Ep> +using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>; + +#else + +template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked = + typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>; + +template <class _Tp, _Tp _Ep> +struct __make_integer_sequence_checked +{ + static_assert(is_integral<_Tp>::value, + "std::make_integer_sequence can only be instantiated with an integral type" ); + static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length"); + // Workaround GCC bug by preventing bad installations when 0 <= _Ep + // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929 + typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; +}; + +template <class _Tp, _Tp _Ep> +using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type; + +#endif + +template<class _Tp, _Tp _Np> + using make_integer_sequence = __make_integer_sequence<_Tp, _Np>; + +template<size_t _Np> + using make_index_sequence = make_integer_sequence<size_t, _Np>; + +template<class... _Tp> + using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; + +#endif // _LIBCPP_STD_VER > 11 + +#if _LIBCPP_STD_VER > 11 +template<class _T1, class _T2 = _T1> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_T1 exchange(_T1& __obj, _T2 && __new_value) +{ + _T1 __old_value = _VSTD::move(__obj); + __obj = _VSTD::forward<_T2>(__new_value); + return __old_value; +} +#endif // _LIBCPP_STD_VER > 11 + +#if _LIBCPP_STD_VER > 14 + +struct _LIBCPP_TYPE_VIS in_place_t { + explicit in_place_t() = default; +}; +_LIBCPP_INLINE_VAR constexpr in_place_t in_place{}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS in_place_type_t { + explicit in_place_type_t() = default; +}; +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{}; + +template <size_t _Idx> +struct _LIBCPP_TYPE_VIS in_place_index_t { + explicit in_place_index_t() = default; +}; +template <size_t _Idx> +_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{}; + +template <class _Tp> struct __is_inplace_type_imp : false_type {}; +template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {}; + +template <class _Tp> +using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>; + +template <class _Tp> struct __is_inplace_index_imp : false_type {}; +template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {}; + +template <class _Tp> +using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>; + +#endif // _LIBCPP_STD_VER > 14 + +template <class _Arg, class _Result> +struct _LIBCPP_TEMPLATE_VIS unary_function +{ + typedef _Arg argument_type; + typedef _Result result_type; +}; + +template <class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_Size +__loadword(const void* __p) +{ + _Size __r; + std::memcpy(&__r, __p, sizeof(__r)); + return __r; +} + +// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t +// is 64 bits. This is because cityhash64 uses 64bit x 64bit +// multiplication, which can be very slow on 32-bit systems. +template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__> +struct __murmur2_or_cityhash; + +template <class _Size> +struct __murmur2_or_cityhash<_Size, 32> +{ + inline _Size operator()(const void* __key, _Size __len) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; +}; + +// murmur2 +template <class _Size> +_Size +__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) +{ + const _Size __m = 0x5bd1e995; + const _Size __r = 24; + _Size __h = __len; + const unsigned char* __data = static_cast<const unsigned char*>(__key); + for (; __len >= 4; __data += 4, __len -= 4) + { + _Size __k = __loadword<_Size>(__data); + __k *= __m; + __k ^= __k >> __r; + __k *= __m; + __h *= __m; + __h ^= __k; + } + switch (__len) + { + case 3: + __h ^= __data[2] << 16; + _LIBCPP_FALLTHROUGH(); + case 2: + __h ^= __data[1] << 8; + _LIBCPP_FALLTHROUGH(); + case 1: + __h ^= __data[0]; + __h *= __m; + } + __h ^= __h >> 13; + __h *= __m; + __h ^= __h >> 15; + return __h; +} + +template <class _Size> +struct __murmur2_or_cityhash<_Size, 64> +{ + inline _Size operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; + + private: + // Some primes between 2^63 and 2^64. + static const _Size __k0 = 0xc3a5c85c97cb3127ULL; + static const _Size __k1 = 0xb492b66fbe98f273ULL; + static const _Size __k2 = 0x9ae16a3b2f90404fULL; + static const _Size __k3 = 0xc949d7c7509e6557ULL; + + static _Size __rotate(_Size __val, int __shift) { + return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift))); + } + + static _Size __rotate_by_at_least_1(_Size __val, int __shift) { + return (__val >> __shift) | (__val << (64 - __shift)); + } + + static _Size __shift_mix(_Size __val) { + return __val ^ (__val >> 47); + } + + static _Size __hash_len_16(_Size __u, _Size __v) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + const _Size __mul = 0x9ddfea08eb382d69ULL; + _Size __a = (__u ^ __v) * __mul; + __a ^= (__a >> 47); + _Size __b = (__v ^ __a) * __mul; + __b ^= (__b >> 47); + __b *= __mul; + return __b; + } + + static _Size __hash_len_0_to_16(const char* __s, _Size __len) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + if (__len > 8) { + const _Size __a = __loadword<_Size>(__s); + const _Size __b = __loadword<_Size>(__s + __len - 8); + return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b; + } + if (__len >= 4) { + const uint32_t __a = __loadword<uint32_t>(__s); + const uint32_t __b = __loadword<uint32_t>(__s + __len - 4); + return __hash_len_16(__len + (__a << 3), __b); + } + if (__len > 0) { + const unsigned char __a = __s[0]; + const unsigned char __b = __s[__len >> 1]; + const unsigned char __c = __s[__len - 1]; + const uint32_t __y = static_cast<uint32_t>(__a) + + (static_cast<uint32_t>(__b) << 8); + const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2); + return __shift_mix(__y * __k2 ^ __z * __k3) * __k2; + } + return __k2; + } + + static _Size __hash_len_17_to_32(const char *__s, _Size __len) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + const _Size __a = __loadword<_Size>(__s) * __k1; + const _Size __b = __loadword<_Size>(__s + 8); + const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2; + const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0; + return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d, + __a + __rotate(__b ^ __k3, 20) - __c + __len); + } + + // Return a 16-byte hash for 48 bytes. Quick and dirty. + // Callers do best to use "random-looking" values for a and b. + static pair<_Size, _Size> __weak_hash_len_32_with_seeds( + _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + __a += __w; + __b = __rotate(__b + __a + __z, 21); + const _Size __c = __a; + __a += __x; + __a += __y; + __b += __rotate(__a, 44); + return pair<_Size, _Size>(__a + __z, __b + __c); + } + + // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. + static pair<_Size, _Size> __weak_hash_len_32_with_seeds( + const char* __s, _Size __a, _Size __b) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s), + __loadword<_Size>(__s + 8), + __loadword<_Size>(__s + 16), + __loadword<_Size>(__s + 24), + __a, + __b); + } + + // Return an 8-byte hash for 33 to 64 bytes. + static _Size __hash_len_33_to_64(const char *__s, size_t __len) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + _Size __z = __loadword<_Size>(__s + 24); + _Size __a = __loadword<_Size>(__s) + + (__len + __loadword<_Size>(__s + __len - 16)) * __k0; + _Size __b = __rotate(__a + __z, 52); + _Size __c = __rotate(__a, 37); + __a += __loadword<_Size>(__s + 8); + __c += __rotate(__a, 7); + __a += __loadword<_Size>(__s + 16); + _Size __vf = __a + __z; + _Size __vs = __b + __rotate(__a, 31) + __c; + __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32); + __z += __loadword<_Size>(__s + __len - 8); + __b = __rotate(__a + __z, 52); + __c = __rotate(__a, 37); + __a += __loadword<_Size>(__s + __len - 24); + __c += __rotate(__a, 7); + __a += __loadword<_Size>(__s + __len - 16); + _Size __wf = __a + __z; + _Size __ws = __b + __rotate(__a, 31) + __c; + _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0); + return __shift_mix(__r * __k0 + __vs) * __k2; + } +}; + +// cityhash64 +template <class _Size> +_Size +__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) +{ + const char* __s = static_cast<const char*>(__key); + if (__len <= 32) { + if (__len <= 16) { + return __hash_len_0_to_16(__s, __len); + } else { + return __hash_len_17_to_32(__s, __len); + } + } else if (__len <= 64) { + return __hash_len_33_to_64(__s, __len); + } + + // For strings over 64 bytes we hash the end first, and then as we + // loop we keep 56 bytes of state: v, w, x, y, and z. + _Size __x = __loadword<_Size>(__s + __len - 40); + _Size __y = __loadword<_Size>(__s + __len - 16) + + __loadword<_Size>(__s + __len - 56); + _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len, + __loadword<_Size>(__s + __len - 24)); + pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); + pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); + __x = __x * __k1 + __loadword<_Size>(__s); + + // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. + __len = (__len - 1) & ~static_cast<_Size>(63); + do { + __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1; + __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; + __x ^= __w.second; + __y += __v.first + __loadword<_Size>(__s + 40); + __z = __rotate(__z + __w.first, 33) * __k1; + __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first); + __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second, + __y + __loadword<_Size>(__s + 16)); + std::swap(__z, __x); + __s += 64; + __len -= 64; + } while (__len != 0); + return __hash_len_16( + __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z, + __hash_len_16(__v.second, __w.second) + __x); +} + +template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)> +struct __scalar_hash; + +template <class _Tp> +struct __scalar_hash<_Tp, 0> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + size_t __a; + } __u; + __u.__a = 0; + __u.__t = __v; + return __u.__a; + } +}; + +template <class _Tp> +struct __scalar_hash<_Tp, 1> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + size_t __a; + } __u; + __u.__t = __v; + return __u.__a; + } +}; + +template <class _Tp> +struct __scalar_hash<_Tp, 2> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + struct + { + size_t __a; + size_t __b; + } __s; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); + } +}; + +template <class _Tp> +struct __scalar_hash<_Tp, 3> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + struct + { + size_t __a; + size_t __b; + size_t __c; + } __s; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); + } +}; + +template <class _Tp> +struct __scalar_hash<_Tp, 4> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + struct + { + size_t __a; + size_t __b; + size_t __c; + size_t __d; + } __s; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); + } +}; + +struct _PairT { + size_t first; + size_t second; +}; + +_LIBCPP_INLINE_VISIBILITY +inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT { + typedef __scalar_hash<_PairT> _HashT; + const _PairT __p = {__lhs, __rhs}; + return _HashT()(__p); +} + +template<class _Tp> +struct _LIBCPP_TEMPLATE_VIS hash<_Tp*> + : public unary_function<_Tp*, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp* __v) const _NOEXCEPT + { + union + { + _Tp* __t; + size_t __a; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); + } +}; + + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<bool> + : public unary_function<bool, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<char> + : public unary_function<char, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<signed char> + : public unary_function<signed char, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> + : public unary_function<unsigned char, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<char16_t> + : public unary_function<char16_t, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<char32_t> + : public unary_function<char32_t, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<wchar_t> + : public unary_function<wchar_t, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<short> + : public unary_function<short, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> + : public unary_function<unsigned short, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<int> + : public unary_function<int, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> + : public unary_function<unsigned int, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<long> + : public unary_function<long, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> + : public unary_function<unsigned long, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<long long> + : public __scalar_hash<long long> +{ +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned long long> + : public __scalar_hash<unsigned long long> +{ +}; + +#ifndef _LIBCPP_HAS_NO_INT128 + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<__int128_t> + : public __scalar_hash<__int128_t> +{ +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<__uint128_t> + : public __scalar_hash<__uint128_t> +{ +}; + +#endif + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<float> + : public __scalar_hash<float> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(float __v) const _NOEXCEPT + { + // -0.0 and 0.0 should return same hash + if (__v == 0.0) + return 0; + return __scalar_hash<float>::operator()(__v); + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<double> + : public __scalar_hash<double> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(double __v) const _NOEXCEPT + { + // -0.0 and 0.0 should return same hash + if (__v == 0.0) + return 0; + return __scalar_hash<double>::operator()(__v); + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<long double> + : public __scalar_hash<long double> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(long double __v) const _NOEXCEPT + { + // -0.0 and 0.0 should return same hash + if (__v == 0.0) + return 0; +#if defined(__i386__) + // Zero out padding bits + union + { + long double __t; + struct + { + size_t __a; + size_t __b; + size_t __c; + size_t __d; + } __s; + } __u; + __u.__s.__a = 0; + __u.__s.__b = 0; + __u.__s.__c = 0; + __u.__s.__d = 0; + __u.__t = __v; + return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; +#elif defined(__x86_64__) + // Zero out padding bits + union + { + long double __t; + struct + { + size_t __a; + size_t __b; + } __s; + } __u; + __u.__s.__a = 0; + __u.__s.__b = 0; + __u.__t = __v; + return __u.__s.__a ^ __u.__s.__b; +#else + return __scalar_hash<long double>::operator()(__v); +#endif + } +}; + +#if _LIBCPP_STD_VER > 11 + +template <class _Tp, bool = is_enum<_Tp>::value> +struct _LIBCPP_TEMPLATE_VIS __enum_hash + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + typedef typename underlying_type<_Tp>::type type; + return hash<type>{}(static_cast<type>(__v)); + } +}; +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> { + __enum_hash() = delete; + __enum_hash(__enum_hash const&) = delete; + __enum_hash& operator=(__enum_hash const&) = delete; +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp> +{ +}; +#endif + +#if _LIBCPP_STD_VER > 14 + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t> + : public unary_function<nullptr_t, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(nullptr_t) const _NOEXCEPT { + return 662607004ull; + } +}; +#endif + +#ifndef _LIBCPP_CXX03_LANG +template <class _Key, class _Hash> +using __check_hash_requirements = integral_constant<bool, + is_copy_constructible<_Hash>::value && + is_move_constructible<_Hash>::value && + __invokable_r<size_t, _Hash, _Key const&>::value +>; + +template <class _Key, class _Hash = std::hash<_Key> > +using __has_enabled_hash = integral_constant<bool, + __check_hash_requirements<_Key, _Hash>::value && + is_default_constructible<_Hash>::value +>; + +#if _LIBCPP_STD_VER > 14 +template <class _Type, class> +using __enable_hash_helper_imp = _Type; + +template <class _Type, class ..._Keys> +using __enable_hash_helper = __enable_hash_helper_imp<_Type, + typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type +>; +#else +template <class _Type, class ...> +using __enable_hash_helper = _Type; +#endif + +#endif // !_LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_UTILITY diff --git a/android/x86/include/v8/libc++/valarray b/android/x86/include/v8/libc++/valarray new file mode 100755 index 00000000..1c4875ef --- /dev/null +++ b/android/x86/include/v8/libc++/valarray @@ -0,0 +1,4944 @@ +// -*- C++ -*- +//===-------------------------- valarray ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_VALARRAY +#define _LIBCPP_VALARRAY + +/* + valarray synopsis + +namespace std +{ + +template<class T> +class valarray +{ +public: + typedef T value_type; + + // construct/destroy: + valarray(); + explicit valarray(size_t n); + valarray(const value_type& x, size_t n); + valarray(const value_type* px, size_t n); + valarray(const valarray& v); + valarray(valarray&& v) noexcept; + valarray(const slice_array<value_type>& sa); + valarray(const gslice_array<value_type>& ga); + valarray(const mask_array<value_type>& ma); + valarray(const indirect_array<value_type>& ia); + valarray(initializer_list<value_type> il); + ~valarray(); + + // assignment: + valarray& operator=(const valarray& v); + valarray& operator=(valarray&& v) noexcept; + valarray& operator=(initializer_list<value_type> il); + valarray& operator=(const value_type& x); + valarray& operator=(const slice_array<value_type>& sa); + valarray& operator=(const gslice_array<value_type>& ga); + valarray& operator=(const mask_array<value_type>& ma); + valarray& operator=(const indirect_array<value_type>& ia); + + // element access: + const value_type& operator[](size_t i) const; + value_type& operator[](size_t i); + + // subset operations: + valarray operator[](slice s) const; + slice_array<value_type> operator[](slice s); + valarray operator[](const gslice& gs) const; + gslice_array<value_type> operator[](const gslice& gs); + valarray operator[](const valarray<bool>& vb) const; + mask_array<value_type> operator[](const valarray<bool>& vb); + valarray operator[](const valarray<size_t>& vs) const; + indirect_array<value_type> operator[](const valarray<size_t>& vs); + + // unary operators: + valarray operator+() const; + valarray operator-() const; + valarray operator~() const; + valarray<bool> operator!() const; + + // computed assignment: + valarray& operator*= (const value_type& x); + valarray& operator/= (const value_type& x); + valarray& operator%= (const value_type& x); + valarray& operator+= (const value_type& x); + valarray& operator-= (const value_type& x); + valarray& operator^= (const value_type& x); + valarray& operator&= (const value_type& x); + valarray& operator|= (const value_type& x); + valarray& operator<<=(const value_type& x); + valarray& operator>>=(const value_type& x); + + valarray& operator*= (const valarray& v); + valarray& operator/= (const valarray& v); + valarray& operator%= (const valarray& v); + valarray& operator+= (const valarray& v); + valarray& operator-= (const valarray& v); + valarray& operator^= (const valarray& v); + valarray& operator|= (const valarray& v); + valarray& operator&= (const valarray& v); + valarray& operator<<=(const valarray& v); + valarray& operator>>=(const valarray& v); + + // member functions: + void swap(valarray& v) noexcept; + + size_t size() const; + + value_type sum() const; + value_type min() const; + value_type max() const; + + valarray shift (int i) const; + valarray cshift(int i) const; + valarray apply(value_type f(value_type)) const; + valarray apply(value_type f(const value_type&)) const; + void resize(size_t n, value_type x = value_type()); +}; + +class slice +{ +public: + slice(); + slice(size_t start, size_t size, size_t stride); + + size_t start() const; + size_t size() const; + size_t stride() const; +}; + +template <class T> +class slice_array +{ +public: + typedef T value_type; + + const slice_array& operator=(const slice_array& sa) const; + void operator= (const valarray<value_type>& v) const; + void operator*= (const valarray<value_type>& v) const; + void operator/= (const valarray<value_type>& v) const; + void operator%= (const valarray<value_type>& v) const; + void operator+= (const valarray<value_type>& v) const; + void operator-= (const valarray<value_type>& v) const; + void operator^= (const valarray<value_type>& v) const; + void operator&= (const valarray<value_type>& v) const; + void operator|= (const valarray<value_type>& v) const; + void operator<<=(const valarray<value_type>& v) const; + void operator>>=(const valarray<value_type>& v) const; + + void operator=(const value_type& x) const; + + slice_array() = delete; +}; + +class gslice +{ +public: + gslice(); + gslice(size_t start, const valarray<size_t>& size, + const valarray<size_t>& stride); + + size_t start() const; + valarray<size_t> size() const; + valarray<size_t> stride() const; +}; + +template <class T> +class gslice_array +{ +public: + typedef T value_type; + + void operator= (const valarray<value_type>& v) const; + void operator*= (const valarray<value_type>& v) const; + void operator/= (const valarray<value_type>& v) const; + void operator%= (const valarray<value_type>& v) const; + void operator+= (const valarray<value_type>& v) const; + void operator-= (const valarray<value_type>& v) const; + void operator^= (const valarray<value_type>& v) const; + void operator&= (const valarray<value_type>& v) const; + void operator|= (const valarray<value_type>& v) const; + void operator<<=(const valarray<value_type>& v) const; + void operator>>=(const valarray<value_type>& v) const; + + gslice_array(const gslice_array& ga); + ~gslice_array(); + const gslice_array& operator=(const gslice_array& ga) const; + void operator=(const value_type& x) const; + + gslice_array() = delete; +}; + +template <class T> +class mask_array +{ +public: + typedef T value_type; + + void operator= (const valarray<value_type>& v) const; + void operator*= (const valarray<value_type>& v) const; + void operator/= (const valarray<value_type>& v) const; + void operator%= (const valarray<value_type>& v) const; + void operator+= (const valarray<value_type>& v) const; + void operator-= (const valarray<value_type>& v) const; + void operator^= (const valarray<value_type>& v) const; + void operator&= (const valarray<value_type>& v) const; + void operator|= (const valarray<value_type>& v) const; + void operator<<=(const valarray<value_type>& v) const; + void operator>>=(const valarray<value_type>& v) const; + + mask_array(const mask_array& ma); + ~mask_array(); + const mask_array& operator=(const mask_array& ma) const; + void operator=(const value_type& x) const; + + mask_array() = delete; +}; + +template <class T> +class indirect_array +{ +public: + typedef T value_type; + + void operator= (const valarray<value_type>& v) const; + void operator*= (const valarray<value_type>& v) const; + void operator/= (const valarray<value_type>& v) const; + void operator%= (const valarray<value_type>& v) const; + void operator+= (const valarray<value_type>& v) const; + void operator-= (const valarray<value_type>& v) const; + void operator^= (const valarray<value_type>& v) const; + void operator&= (const valarray<value_type>& v) const; + void operator|= (const valarray<value_type>& v) const; + void operator<<=(const valarray<value_type>& v) const; + void operator>>=(const valarray<value_type>& v) const; + + indirect_array(const indirect_array& ia); + ~indirect_array(); + const indirect_array& operator=(const indirect_array& ia) const; + void operator=(const value_type& x) const; + + indirect_array() = delete; +}; + +template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept; + +template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator* (const valarray<T>& x, const T& y); +template<class T> valarray<T> operator* (const T& x, const valarray<T>& y); + +template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y); +template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y); + +template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator% (const valarray<T>& x, const T& y); +template<class T> valarray<T> operator% (const T& x, const valarray<T>& y); + +template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y); +template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y); + +template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator- (const valarray<T>& x, const T& y); +template<class T> valarray<T> operator- (const T& x, const valarray<T>& y); + +template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y); +template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y); + +template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator& (const valarray<T>& x, const T& y); +template<class T> valarray<T> operator& (const T& x, const valarray<T>& y); + +template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator| (const valarray<T>& x, const T& y); +template<class T> valarray<T> operator| (const T& x, const valarray<T>& y); + +template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y); +template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y); + +template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y); +template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y); + +template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y); +template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y); + +template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y); +template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y); + +template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y); +template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y); + +template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y); +template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y); + +template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y); +template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y); + +template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y); +template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y); + +template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y); +template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y); + +template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y); +template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y); + +template<class T> valarray<T> abs (const valarray<T>& x); +template<class T> valarray<T> acos (const valarray<T>& x); +template<class T> valarray<T> asin (const valarray<T>& x); +template<class T> valarray<T> atan (const valarray<T>& x); + +template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> atan2(const valarray<T>& x, const T& y); +template<class T> valarray<T> atan2(const T& x, const valarray<T>& y); + +template<class T> valarray<T> cos (const valarray<T>& x); +template<class T> valarray<T> cosh (const valarray<T>& x); +template<class T> valarray<T> exp (const valarray<T>& x); +template<class T> valarray<T> log (const valarray<T>& x); +template<class T> valarray<T> log10(const valarray<T>& x); + +template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y); +template<class T> valarray<T> pow(const valarray<T>& x, const T& y); +template<class T> valarray<T> pow(const T& x, const valarray<T>& y); + +template<class T> valarray<T> sin (const valarray<T>& x); +template<class T> valarray<T> sinh (const valarray<T>& x); +template<class T> valarray<T> sqrt (const valarray<T>& x); +template<class T> valarray<T> tan (const valarray<T>& x); +template<class T> valarray<T> tanh (const valarray<T>& x); + +template <class T> unspecified1 begin(valarray<T>& v); +template <class T> unspecified2 begin(const valarray<T>& v); +template <class T> unspecified1 end(valarray<T>& v); +template <class T> unspecified2 end(const valarray<T>& v); + +} // std + +*/ + +#include <__config> +#include <cstddef> +#include <cmath> +#include <initializer_list> +#include <algorithm> +#include <functional> +#include <new> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray; + +class _LIBCPP_TEMPLATE_VIS slice +{ + size_t __start_; + size_t __size_; + size_t __stride_; +public: + _LIBCPP_INLINE_VISIBILITY + slice() + : __start_(0), + __size_(0), + __stride_(0) + {} + + _LIBCPP_INLINE_VISIBILITY + slice(size_t __start, size_t __size, size_t __stride) + : __start_(__start), + __size_(__size), + __stride_(__stride) + {} + + _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;} + _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;} + _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;} +}; + +template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array; +class _LIBCPP_TYPE_VIS gslice; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array; + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +begin(valarray<_Tp>& __v); + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +const _Tp* +begin(const valarray<_Tp>& __v); + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* +end(valarray<_Tp>& __v); + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY +const _Tp* +end(const valarray<_Tp>& __v); + +template <class _Op, class _A0> +struct _UnaryOp +{ + typedef typename _Op::result_type result_type; + typedef typename _A0::value_type value_type; + + _Op __op_; + _A0 __a0_; + + _LIBCPP_INLINE_VISIBILITY + _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {} + + _LIBCPP_INLINE_VISIBILITY + result_type operator[](size_t __i) const {return __op_(__a0_[__i]);} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __a0_.size();} +}; + +template <class _Op, class _A0, class _A1> +struct _BinaryOp +{ + typedef typename _Op::result_type result_type; + typedef typename _A0::value_type value_type; + + _Op __op_; + _A0 __a0_; + _A1 __a1_; + + _LIBCPP_INLINE_VISIBILITY + _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1) + : __op_(__op), __a0_(__a0), __a1_(__a1) {} + + _LIBCPP_INLINE_VISIBILITY + value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __a0_.size();} +}; + +template <class _Tp> +class __scalar_expr +{ +public: + typedef _Tp value_type; + typedef const _Tp& result_type; +private: + const value_type& __t_; + size_t __s_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {} + + _LIBCPP_INLINE_VISIBILITY + result_type operator[](size_t) const {return __t_;} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __s_;} +}; + +template <class _Tp> +struct __unary_plus : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return +__x;} +}; + +template <class _Tp> +struct __bit_not : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return ~__x;} +}; + +template <class _Tp> +struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x << __y;} +}; + +template <class _Tp> +struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x >> __y;} +}; + +template <class _Tp, class _Fp> +struct __apply_expr : unary_function<_Tp, _Tp> +{ +private: + _Fp __f_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __apply_expr(_Fp __f) : __f_(__f) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return __f_(__x);} +}; + +template <class _Tp> +struct __abs_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return abs(__x);} +}; + +template <class _Tp> +struct __acos_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return acos(__x);} +}; + +template <class _Tp> +struct __asin_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return asin(__x);} +}; + +template <class _Tp> +struct __atan_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return atan(__x);} +}; + +template <class _Tp> +struct __atan2_expr : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return atan2(__x, __y);} +}; + +template <class _Tp> +struct __cos_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return cos(__x);} +}; + +template <class _Tp> +struct __cosh_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return cosh(__x);} +}; + +template <class _Tp> +struct __exp_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return exp(__x);} +}; + +template <class _Tp> +struct __log_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return log(__x);} +}; + +template <class _Tp> +struct __log10_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return log10(__x);} +}; + +template <class _Tp> +struct __pow_expr : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return pow(__x, __y);} +}; + +template <class _Tp> +struct __sin_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return sin(__x);} +}; + +template <class _Tp> +struct __sinh_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return sinh(__x);} +}; + +template <class _Tp> +struct __sqrt_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return sqrt(__x);} +}; + +template <class _Tp> +struct __tan_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return tan(__x);} +}; + +template <class _Tp> +struct __tanh_expr : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return tanh(__x);} +}; + +template <class _ValExpr> +class __slice_expr +{ + typedef typename remove_reference<_ValExpr>::type _RmExpr; +public: + typedef typename _RmExpr::value_type value_type; + typedef value_type result_type; + +private: + _ValExpr __expr_; + size_t __start_; + size_t __size_; + size_t __stride_; + + _LIBCPP_INLINE_VISIBILITY + __slice_expr(const slice& __sl, const _RmExpr& __e) + : __expr_(__e), + __start_(__sl.start()), + __size_(__sl.size()), + __stride_(__sl.stride()) + {} +public: + + _LIBCPP_INLINE_VISIBILITY + result_type operator[](size_t __i) const + {return __expr_[__start_ + __i * __stride_];} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __size_;} + + template <class> friend class __val_expr; + template <class> friend class _LIBCPP_TEMPLATE_VIS valarray; +}; + +template <class _ValExpr> +class __mask_expr; + +template <class _ValExpr> +class __indirect_expr; + +template <class _ValExpr> +class __shift_expr +{ + typedef typename remove_reference<_ValExpr>::type _RmExpr; +public: + typedef typename _RmExpr::value_type value_type; + typedef value_type result_type; + +private: + _ValExpr __expr_; + size_t __size_; + ptrdiff_t __ul_; + ptrdiff_t __sn_; + ptrdiff_t __n_; + static const ptrdiff_t _Np = static_cast<ptrdiff_t>( + sizeof(ptrdiff_t) * __CHAR_BIT__ - 1); + + _LIBCPP_INLINE_VISIBILITY + __shift_expr(int __n, const _RmExpr& __e) + : __expr_(__e), + __size_(__e.size()), + __n_(__n) + { + ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np); + __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np); + __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n); + } +public: + + _LIBCPP_INLINE_VISIBILITY + result_type operator[](size_t __j) const + { + ptrdiff_t __i = static_cast<ptrdiff_t>(__j); + ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np; + return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m); + } + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __size_;} + + template <class> friend class __val_expr; +}; + +template <class _ValExpr> +class __cshift_expr +{ + typedef typename remove_reference<_ValExpr>::type _RmExpr; +public: + typedef typename _RmExpr::value_type value_type; + typedef value_type result_type; + +private: + _ValExpr __expr_; + size_t __size_; + size_t __m_; + size_t __o1_; + size_t __o2_; + + _LIBCPP_INLINE_VISIBILITY + __cshift_expr(int __n, const _RmExpr& __e) + : __expr_(__e), + __size_(__e.size()) + { + __n %= static_cast<int>(__size_); + if (__n >= 0) + { + __m_ = __size_ - __n; + __o1_ = __n; + __o2_ = __n - __size_; + } + else + { + __m_ = -__n; + __o1_ = __n + __size_; + __o2_ = __n; + } + } +public: + + _LIBCPP_INLINE_VISIBILITY + result_type operator[](size_t __i) const + { + if (__i < __m_) + return __expr_[__i + __o1_]; + return __expr_[__i + __o2_]; + } + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __size_;} + + template <class> friend class __val_expr; +}; + +template<class _ValExpr> +class __val_expr; + +template<class _ValExpr> +struct __is_val_expr : false_type {}; + +template<class _ValExpr> +struct __is_val_expr<__val_expr<_ValExpr> > : true_type {}; + +template<class _Tp> +struct __is_val_expr<valarray<_Tp> > : true_type {}; + +template<class _Tp> +class _LIBCPP_TEMPLATE_VIS valarray +{ +public: + typedef _Tp value_type; + typedef _Tp result_type; + +private: + value_type* __begin_; + value_type* __end_; + +public: + // construct/destroy: + _LIBCPP_INLINE_VISIBILITY + valarray() : __begin_(0), __end_(0) {} + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + explicit valarray(size_t __n); + _LIBCPP_INLINE_VISIBILITY + valarray(const value_type& __x, size_t __n); + valarray(const value_type* __p, size_t __n); + valarray(const valarray& __v); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + valarray(valarray&& __v) _NOEXCEPT; + valarray(initializer_list<value_type> __il); +#endif // _LIBCPP_CXX03_LANG + valarray(const slice_array<value_type>& __sa); + valarray(const gslice_array<value_type>& __ga); + valarray(const mask_array<value_type>& __ma); + valarray(const indirect_array<value_type>& __ia); + inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 + ~valarray(); + + // assignment: + valarray& operator=(const valarray& __v); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + valarray& operator=(valarray&& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + valarray& operator=(initializer_list<value_type>); +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + valarray& operator=(const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator=(const slice_array<value_type>& __sa); + _LIBCPP_INLINE_VISIBILITY + valarray& operator=(const gslice_array<value_type>& __ga); + _LIBCPP_INLINE_VISIBILITY + valarray& operator=(const mask_array<value_type>& __ma); + _LIBCPP_INLINE_VISIBILITY + valarray& operator=(const indirect_array<value_type>& __ia); + template <class _ValExpr> + _LIBCPP_INLINE_VISIBILITY + valarray& operator=(const __val_expr<_ValExpr>& __v); + + // element access: + _LIBCPP_INLINE_VISIBILITY + const value_type& operator[](size_t __i) const {return __begin_[__i];} + + _LIBCPP_INLINE_VISIBILITY + value_type& operator[](size_t __i) {return __begin_[__i];} + + // subset operations: + _LIBCPP_INLINE_VISIBILITY + __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const; + _LIBCPP_INLINE_VISIBILITY + slice_array<value_type> operator[](slice __s); + _LIBCPP_INLINE_VISIBILITY + __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const; + _LIBCPP_INLINE_VISIBILITY + gslice_array<value_type> operator[](const gslice& __gs); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const; + _LIBCPP_INLINE_VISIBILITY + gslice_array<value_type> operator[](gslice&& __gs); +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const; + _LIBCPP_INLINE_VISIBILITY + mask_array<value_type> operator[](const valarray<bool>& __vb); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const; + _LIBCPP_INLINE_VISIBILITY + mask_array<value_type> operator[](valarray<bool>&& __vb); +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const; + _LIBCPP_INLINE_VISIBILITY + indirect_array<value_type> operator[](const valarray<size_t>& __vs); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const; + _LIBCPP_INLINE_VISIBILITY + indirect_array<value_type> operator[](valarray<size_t>&& __vs); +#endif // _LIBCPP_CXX03_LANG + + // unary operators: + valarray operator+() const; + valarray operator-() const; + valarray operator~() const; + valarray<bool> operator!() const; + + // computed assignment: + _LIBCPP_INLINE_VISIBILITY + valarray& operator*= (const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator/= (const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator%= (const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator+= (const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator-= (const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator^= (const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator&= (const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator|= (const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator<<=(const value_type& __x); + _LIBCPP_INLINE_VISIBILITY + valarray& operator>>=(const value_type& __x); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator*= (const _Expr& __v); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator/= (const _Expr& __v); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator%= (const _Expr& __v); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator+= (const _Expr& __v); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator-= (const _Expr& __v); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator^= (const _Expr& __v); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator|= (const _Expr& __v); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator&= (const _Expr& __v); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator<<= (const _Expr& __v); + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + valarray& + >::type + _LIBCPP_INLINE_VISIBILITY + operator>>= (const _Expr& __v); + + // member functions: + _LIBCPP_INLINE_VISIBILITY + void swap(valarray& __v) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return static_cast<size_t>(__end_ - __begin_);} + + _LIBCPP_INLINE_VISIBILITY + value_type sum() const; + _LIBCPP_INLINE_VISIBILITY + value_type min() const; + _LIBCPP_INLINE_VISIBILITY + value_type max() const; + + valarray shift (int __i) const; + valarray cshift(int __i) const; + valarray apply(value_type __f(value_type)) const; + valarray apply(value_type __f(const value_type&)) const; + void resize(size_t __n, value_type __x = value_type()); + +private: + template <class> friend class _LIBCPP_TEMPLATE_VIS valarray; + template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array; + template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array; + template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array; + template <class> friend class __mask_expr; + template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array; + template <class> friend class __indirect_expr; + template <class> friend class __val_expr; + + template <class _Up> + friend + _Up* + begin(valarray<_Up>& __v); + + template <class _Up> + friend + const _Up* + begin(const valarray<_Up>& __v); + + template <class _Up> + friend + _Up* + end(valarray<_Up>& __v); + + template <class _Up> + friend + const _Up* + end(const valarray<_Up>& __v); + + _LIBCPP_INLINE_VISIBILITY + void __clear(size_t __capacity); + valarray& __assign_range(const value_type* __f, const value_type* __l); +}; + +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::~valarray()) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t)) + +template <class _Op, class _Tp> +struct _UnaryOp<_Op, valarray<_Tp> > +{ + typedef typename _Op::result_type result_type; + typedef _Tp value_type; + + _Op __op_; + const valarray<_Tp>& __a0_; + + _LIBCPP_INLINE_VISIBILITY + _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {} + + _LIBCPP_INLINE_VISIBILITY + result_type operator[](size_t __i) const {return __op_(__a0_[__i]);} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __a0_.size();} +}; + +template <class _Op, class _Tp, class _A1> +struct _BinaryOp<_Op, valarray<_Tp>, _A1> +{ + typedef typename _Op::result_type result_type; + typedef _Tp value_type; + + _Op __op_; + const valarray<_Tp>& __a0_; + _A1 __a1_; + + _LIBCPP_INLINE_VISIBILITY + _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1) + : __op_(__op), __a0_(__a0), __a1_(__a1) {} + + _LIBCPP_INLINE_VISIBILITY + value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __a0_.size();} +}; + +template <class _Op, class _A0, class _Tp> +struct _BinaryOp<_Op, _A0, valarray<_Tp> > +{ + typedef typename _Op::result_type result_type; + typedef _Tp value_type; + + _Op __op_; + _A0 __a0_; + const valarray<_Tp>& __a1_; + + _LIBCPP_INLINE_VISIBILITY + _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1) + : __op_(__op), __a0_(__a0), __a1_(__a1) {} + + _LIBCPP_INLINE_VISIBILITY + value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __a0_.size();} +}; + +template <class _Op, class _Tp> +struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> > +{ + typedef typename _Op::result_type result_type; + typedef _Tp value_type; + + _Op __op_; + const valarray<_Tp>& __a0_; + const valarray<_Tp>& __a1_; + + _LIBCPP_INLINE_VISIBILITY + _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1) + : __op_(__op), __a0_(__a0), __a1_(__a1) {} + + _LIBCPP_INLINE_VISIBILITY + value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __a0_.size();} +}; + +// slice_array + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS slice_array +{ +public: + typedef _Tp value_type; + +private: + value_type* __vp_; + size_t __size_; + size_t __stride_; + +public: + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator*=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator/=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator%=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator+=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator-=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator^=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator&=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator|=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator<<=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator>>=(const _Expr& __v) const; + + _LIBCPP_INLINE_VISIBILITY + const slice_array& operator=(const slice_array& __sa) const; + + _LIBCPP_INLINE_VISIBILITY + void operator=(const value_type& __x) const; + +private: + _LIBCPP_INLINE_VISIBILITY + slice_array(const slice& __sl, const valarray<value_type>& __v) + : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())), + __size_(__sl.size()), + __stride_(__sl.stride()) + {} + + template <class> friend class valarray; + template <class> friend class sliceExpr; +}; + +template <class _Tp> +inline +const slice_array<_Tp>& +slice_array<_Tp>::operator=(const slice_array& __sa) const +{ + value_type* __t = __vp_; + const value_type* __s = __sa.__vp_; + for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_) + *__t = *__s; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t = __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator*=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t *= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator/=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t /= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator%=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t %= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator+=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t += __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator-=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t -= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator^=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t ^= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator&=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t &= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator|=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t |= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator<<=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t <<= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +slice_array<_Tp>::operator>>=(const _Expr& __v) const +{ + value_type* __t = __vp_; + for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) + *__t >>= __v[__i]; +} + +template <class _Tp> +inline +void +slice_array<_Tp>::operator=(const value_type& __x) const +{ + value_type* __t = __vp_; + for (size_t __n = __size_; __n; --__n, __t += __stride_) + *__t = __x; +} + +// gslice + +class _LIBCPP_TYPE_VIS gslice +{ + valarray<size_t> __size_; + valarray<size_t> __stride_; + valarray<size_t> __1d_; + +public: + _LIBCPP_INLINE_VISIBILITY + gslice() {} + + _LIBCPP_INLINE_VISIBILITY + gslice(size_t __start, const valarray<size_t>& __size, + const valarray<size_t>& __stride) + : __size_(__size), + __stride_(__stride) + {__init(__start);} + +#ifndef _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + gslice(size_t __start, const valarray<size_t>& __size, + valarray<size_t>&& __stride) + : __size_(__size), + __stride_(move(__stride)) + {__init(__start);} + + _LIBCPP_INLINE_VISIBILITY + gslice(size_t __start, valarray<size_t>&& __size, + const valarray<size_t>& __stride) + : __size_(move(__size)), + __stride_(__stride) + {__init(__start);} + + _LIBCPP_INLINE_VISIBILITY + gslice(size_t __start, valarray<size_t>&& __size, + valarray<size_t>&& __stride) + : __size_(move(__size)), + __stride_(move(__stride)) + {__init(__start);} + +#endif // _LIBCPP_CXX03_LANG + +// gslice(const gslice&) = default; +// gslice(gslice&&) = default; +// gslice& operator=(const gslice&) = default; +// gslice& operator=(gslice&&) = default; + + _LIBCPP_INLINE_VISIBILITY + size_t start() const {return __1d_.size() ? __1d_[0] : 0;} + + _LIBCPP_INLINE_VISIBILITY + valarray<size_t> size() const {return __size_;} + + _LIBCPP_INLINE_VISIBILITY + valarray<size_t> stride() const {return __stride_;} + +private: + void __init(size_t __start); + + template <class> friend class gslice_array; + template <class> friend class valarray; + template <class> friend class __val_expr; +}; + +// gslice_array + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS gslice_array +{ +public: + typedef _Tp value_type; + +private: + value_type* __vp_; + valarray<size_t> __1d_; + +public: + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator*=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator/=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator%=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator+=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator-=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator^=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator&=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator|=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator<<=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator>>=(const _Expr& __v) const; + + _LIBCPP_INLINE_VISIBILITY + const gslice_array& operator=(const gslice_array& __ga) const; + + _LIBCPP_INLINE_VISIBILITY + void operator=(const value_type& __x) const; + +// gslice_array(const gslice_array&) = default; +// gslice_array(gslice_array&&) = default; +// gslice_array& operator=(const gslice_array&) = default; +// gslice_array& operator=(gslice_array&&) = default; + +private: + gslice_array(const gslice& __gs, const valarray<value_type>& __v) + : __vp_(const_cast<value_type*>(__v.__begin_)), + __1d_(__gs.__1d_) + {} + +#ifndef _LIBCPP_CXX03_LANG + gslice_array(gslice&& __gs, const valarray<value_type>& __v) + : __vp_(const_cast<value_type*>(__v.__begin_)), + __1d_(move(__gs.__1d_)) + {} +#endif // _LIBCPP_CXX03_LANG + + template <class> friend class valarray; +}; + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] = __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator*=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] *= __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator/=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] /= __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator%=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] %= __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator+=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] += __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator-=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] -= __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator^=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] ^= __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator&=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] &= __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator|=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] |= __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator<<=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] <<= __v[__j]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +gslice_array<_Tp>::operator>>=(const _Expr& __v) const +{ + typedef const size_t* _Ip; + size_t __j = 0; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) + __vp_[*__i] >>= __v[__j]; +} + +template <class _Tp> +inline +const gslice_array<_Tp>& +gslice_array<_Tp>::operator=(const gslice_array& __ga) const +{ + typedef const size_t* _Ip; + const value_type* __s = __ga.__vp_; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_; + __i != __e; ++__i, ++__j) + __vp_[*__i] = __s[*__j]; + return *this; +} + +template <class _Tp> +inline +void +gslice_array<_Tp>::operator=(const value_type& __x) const +{ + typedef const size_t* _Ip; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) + __vp_[*__i] = __x; +} + +// mask_array + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS mask_array +{ +public: + typedef _Tp value_type; + +private: + value_type* __vp_; + valarray<size_t> __1d_; + +public: + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator*=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator/=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator%=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator+=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator-=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator^=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator&=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator|=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator<<=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator>>=(const _Expr& __v) const; + + _LIBCPP_INLINE_VISIBILITY + const mask_array& operator=(const mask_array& __ma) const; + + _LIBCPP_INLINE_VISIBILITY + void operator=(const value_type& __x) const; + +// mask_array(const mask_array&) = default; +// mask_array(mask_array&&) = default; +// mask_array& operator=(const mask_array&) = default; +// mask_array& operator=(mask_array&&) = default; + +private: + _LIBCPP_INLINE_VISIBILITY + mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v) + : __vp_(const_cast<value_type*>(__v.__begin_)), + __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) + { + size_t __j = 0; + for (size_t __i = 0; __i < __vb.size(); ++__i) + if (__vb[__i]) + __1d_[__j++] = __i; + } + + template <class> friend class valarray; +}; + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] = __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator*=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] *= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator/=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] /= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator%=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] %= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator+=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] += __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator-=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] -= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator^=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] ^= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator&=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] &= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator|=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] |= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator<<=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] <<= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +mask_array<_Tp>::operator>>=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] >>= __v[__i]; +} + +template <class _Tp> +inline +const mask_array<_Tp>& +mask_array<_Tp>::operator=(const mask_array& __ma) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]]; + return *this; +} + +template <class _Tp> +inline +void +mask_array<_Tp>::operator=(const value_type& __x) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] = __x; +} + +template <class _ValExpr> +class __mask_expr +{ + typedef typename remove_reference<_ValExpr>::type _RmExpr; +public: + typedef typename _RmExpr::value_type value_type; + typedef value_type result_type; + +private: + _ValExpr __expr_; + valarray<size_t> __1d_; + + _LIBCPP_INLINE_VISIBILITY + __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e) + : __expr_(__e), + __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) + { + size_t __j = 0; + for (size_t __i = 0; __i < __vb.size(); ++__i) + if (__vb[__i]) + __1d_[__j++] = __i; + } + +public: + _LIBCPP_INLINE_VISIBILITY + result_type operator[](size_t __i) const + {return __expr_[__1d_[__i]];} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __1d_.size();} + + template <class> friend class __val_expr; + template <class> friend class valarray; +}; + +// indirect_array + +template <class _Tp> +class _LIBCPP_TEMPLATE_VIS indirect_array +{ +public: + typedef _Tp value_type; + +private: + value_type* __vp_; + valarray<size_t> __1d_; + +public: + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator*=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator/=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator%=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator+=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator-=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator^=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator&=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator|=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator<<=(const _Expr& __v) const; + + template <class _Expr> + typename enable_if + < + __is_val_expr<_Expr>::value, + void + >::type + _LIBCPP_INLINE_VISIBILITY + operator>>=(const _Expr& __v) const; + + _LIBCPP_INLINE_VISIBILITY + const indirect_array& operator=(const indirect_array& __ia) const; + + _LIBCPP_INLINE_VISIBILITY + void operator=(const value_type& __x) const; + +// indirect_array(const indirect_array&) = default; +// indirect_array(indirect_array&&) = default; +// indirect_array& operator=(const indirect_array&) = default; +// indirect_array& operator=(indirect_array&&) = default; + +private: + _LIBCPP_INLINE_VISIBILITY + indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v) + : __vp_(const_cast<value_type*>(__v.__begin_)), + __1d_(__ia) + {} + +#ifndef _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v) + : __vp_(const_cast<value_type*>(__v.__begin_)), + __1d_(move(__ia)) + {} + +#endif // _LIBCPP_CXX03_LANG + + template <class> friend class valarray; +}; + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] = __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator*=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] *= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator/=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] /= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator%=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] %= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator+=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] += __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator-=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] -= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator^=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] ^= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator&=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] &= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator|=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] |= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator<<=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] <<= __v[__i]; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + void +>::type +indirect_array<_Tp>::operator>>=(const _Expr& __v) const +{ + size_t __n = __1d_.size(); + for (size_t __i = 0; __i < __n; ++__i) + __vp_[__1d_[__i]] >>= __v[__i]; +} + +template <class _Tp> +inline +const indirect_array<_Tp>& +indirect_array<_Tp>::operator=(const indirect_array& __ia) const +{ + typedef const size_t* _Ip; + const value_type* __s = __ia.__vp_; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_; + __i != __e; ++__i, ++__j) + __vp_[*__i] = __s[*__j]; + return *this; +} + +template <class _Tp> +inline +void +indirect_array<_Tp>::operator=(const value_type& __x) const +{ + typedef const size_t* _Ip; + for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) + __vp_[*__i] = __x; +} + +template <class _ValExpr> +class __indirect_expr +{ + typedef typename remove_reference<_ValExpr>::type _RmExpr; +public: + typedef typename _RmExpr::value_type value_type; + typedef value_type result_type; + +private: + _ValExpr __expr_; + valarray<size_t> __1d_; + + _LIBCPP_INLINE_VISIBILITY + __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e) + : __expr_(__e), + __1d_(__ia) + {} + +#ifndef _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e) + : __expr_(__e), + __1d_(move(__ia)) + {} + +#endif // _LIBCPP_CXX03_LANG + +public: + _LIBCPP_INLINE_VISIBILITY + result_type operator[](size_t __i) const + {return __expr_[__1d_[__i]];} + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __1d_.size();} + + template <class> friend class __val_expr; + template <class> friend class _LIBCPP_TEMPLATE_VIS valarray; +}; + +template<class _ValExpr> +class __val_expr +{ + typedef typename remove_reference<_ValExpr>::type _RmExpr; + + _ValExpr __expr_; +public: + typedef typename _RmExpr::value_type value_type; + typedef typename _RmExpr::result_type result_type; + + _LIBCPP_INLINE_VISIBILITY + explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {} + + _LIBCPP_INLINE_VISIBILITY + result_type operator[](size_t __i) const + {return __expr_[__i];} + + _LIBCPP_INLINE_VISIBILITY + __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const + { + typedef __slice_expr<_ValExpr> _NewExpr; + return __val_expr< _NewExpr >(_NewExpr(__s, __expr_)); + } + + _LIBCPP_INLINE_VISIBILITY + __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const + { + typedef __indirect_expr<_ValExpr> _NewExpr; + return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_)); + } + + _LIBCPP_INLINE_VISIBILITY + __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const + { + typedef __mask_expr<_ValExpr> _NewExpr; + return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_)); + } + + _LIBCPP_INLINE_VISIBILITY + __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const + { + typedef __indirect_expr<_ValExpr> _NewExpr; + return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_)); + } + + _LIBCPP_INLINE_VISIBILITY + __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> > + operator+() const + { + typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr; + return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_)); + } + + _LIBCPP_INLINE_VISIBILITY + __val_expr<_UnaryOp<negate<value_type>, _ValExpr> > + operator-() const + { + typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr; + return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_)); + } + + _LIBCPP_INLINE_VISIBILITY + __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> > + operator~() const + { + typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr; + return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_)); + } + + _LIBCPP_INLINE_VISIBILITY + __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> > + operator!() const + { + typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr; + return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_)); + } + + operator valarray<result_type>() const; + + _LIBCPP_INLINE_VISIBILITY + size_t size() const {return __expr_.size();} + + _LIBCPP_INLINE_VISIBILITY + result_type sum() const + { + size_t __n = __expr_.size(); + result_type __r = __n ? __expr_[0] : result_type(); + for (size_t __i = 1; __i < __n; ++__i) + __r += __expr_[__i]; + return __r; + } + + _LIBCPP_INLINE_VISIBILITY + result_type min() const + { + size_t __n = size(); + result_type __r = __n ? (*this)[0] : result_type(); + for (size_t __i = 1; __i < __n; ++__i) + { + result_type __x = __expr_[__i]; + if (__x < __r) + __r = __x; + } + return __r; + } + + _LIBCPP_INLINE_VISIBILITY + result_type max() const + { + size_t __n = size(); + result_type __r = __n ? (*this)[0] : result_type(); + for (size_t __i = 1; __i < __n; ++__i) + { + result_type __x = __expr_[__i]; + if (__r < __x) + __r = __x; + } + return __r; + } + + _LIBCPP_INLINE_VISIBILITY + __val_expr<__shift_expr<_ValExpr> > shift (int __i) const + {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));} + + _LIBCPP_INLINE_VISIBILITY + __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const + {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));} + + _LIBCPP_INLINE_VISIBILITY + __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> > + apply(value_type __f(value_type)) const + { + typedef __apply_expr<value_type, value_type(*)(value_type)> _Op; + typedef _UnaryOp<_Op, _ValExpr> _NewExpr; + return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); + } + + _LIBCPP_INLINE_VISIBILITY + __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> > + apply(value_type __f(const value_type&)) const + { + typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op; + typedef _UnaryOp<_Op, _ValExpr> _NewExpr; + return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); + } +}; + +template<class _ValExpr> +__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const +{ + valarray<result_type> __r; + size_t __n = __expr_.size(); + if (__n) + { + __r.__begin_ = + __r.__end_ = + static_cast<result_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(result_type), _LIBCPP_ALIGNOF(result_type))); + for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i) + ::new (__r.__end_) result_type(__expr_[__i]); + } + return __r; +} + +// valarray + +template <class _Tp> +inline +valarray<_Tp>::valarray(size_t __n) + : __begin_(0), + __end_(0) +{ + if (__n) + { + __begin_ = __end_ = static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) + ::new (__end_) value_type(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __clear(__n); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Tp> +inline +valarray<_Tp>::valarray(const value_type& __x, size_t __n) + : __begin_(0), + __end_(0) +{ + resize(__n, __x); +} + +template <class _Tp> +valarray<_Tp>::valarray(const value_type* __p, size_t __n) + : __begin_(0), + __end_(0) +{ + if (__n) + { + __begin_ = __end_ = static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left) + ::new (__end_) value_type(*__p); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __clear(__n); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Tp> +valarray<_Tp>::valarray(const valarray& __v) + : __begin_(0), + __end_(0) +{ + if (__v.size()) + { + __begin_ = __end_ = static_cast<value_type*>( + _VSTD::__libcpp_allocate(__v.size() * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p) + ::new (__end_) value_type(*__p); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __clear(__v.size()); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp> +inline +valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT + : __begin_(__v.__begin_), + __end_(__v.__end_) +{ + __v.__begin_ = __v.__end_ = nullptr; +} + +template <class _Tp> +valarray<_Tp>::valarray(initializer_list<value_type> __il) + : __begin_(0), + __end_(0) +{ + const size_t __n = __il.size(); + if (__n) + { + __begin_ = __end_ = static_cast<value_type*>( +_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + size_t __n_left = __n; + for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left) + ::new (__end_) value_type(*__p); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __clear(__n); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp> +valarray<_Tp>::valarray(const slice_array<value_type>& __sa) + : __begin_(0), + __end_(0) +{ + const size_t __n = __sa.__size_; + if (__n) + { + __begin_ = __end_ = static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + size_t __n_left = __n; + for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left) + ::new (__end_) value_type(*__p); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __clear(__n); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Tp> +valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) + : __begin_(0), + __end_(0) +{ + const size_t __n = __ga.__1d_.size(); + if (__n) + { + __begin_ = __end_ = static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef const size_t* _Ip; + const value_type* __s = __ga.__vp_; + for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; + __i != __e; ++__i, ++__end_) + ::new (__end_) value_type(__s[*__i]); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __clear(__n); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Tp> +valarray<_Tp>::valarray(const mask_array<value_type>& __ma) + : __begin_(0), + __end_(0) +{ + const size_t __n = __ma.__1d_.size(); + if (__n) + { + __begin_ = __end_ = static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef const size_t* _Ip; + const value_type* __s = __ma.__vp_; + for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; + __i != __e; ++__i, ++__end_) + ::new (__end_) value_type(__s[*__i]); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __clear(__n); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Tp> +valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) + : __begin_(0), + __end_(0) +{ + const size_t __n = __ia.__1d_.size(); + if (__n) + { + __begin_ = __end_ = static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typedef const size_t* _Ip; + const value_type* __s = __ia.__vp_; + for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; + __i != __e; ++__i, ++__end_) + ::new (__end_) value_type(__s[*__i]); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __clear(__n); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Tp> +inline +valarray<_Tp>::~valarray() +{ + __clear(size()); +} + +template <class _Tp> +valarray<_Tp>& +valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l) +{ + size_t __n = __l - __f; + if (size() != __n) + { + __clear(size()); + __begin_ = static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); + __end_ = __begin_ + __n; + _VSTD::uninitialized_copy(__f, __l, __begin_); + } else { + _VSTD::copy(__f, __l, __begin_); + } + return *this; +} + +template <class _Tp> +valarray<_Tp>& +valarray<_Tp>::operator=(const valarray& __v) +{ + if (this != &__v) + return __assign_range(__v.__begin_, __v.__end_); + return *this; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT +{ + __clear(size()); + __begin_ = __v.__begin_; + __end_ = __v.__end_; + __v.__begin_ = nullptr; + __v.__end_ = nullptr; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator=(initializer_list<value_type> __il) +{ + return __assign_range(__il.begin(), __il.end()); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator=(const value_type& __x) +{ + _VSTD::fill(__begin_, __end_, __x); + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator=(const slice_array<value_type>& __sa) +{ + value_type* __t = __begin_; + const value_type* __s = __sa.__vp_; + for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t) + *__t = *__s; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator=(const gslice_array<value_type>& __ga) +{ + typedef const size_t* _Ip; + value_type* __t = __begin_; + const value_type* __s = __ga.__vp_; + for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; + __i != __e; ++__i, ++__t) + *__t = __s[*__i]; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator=(const mask_array<value_type>& __ma) +{ + typedef const size_t* _Ip; + value_type* __t = __begin_; + const value_type* __s = __ma.__vp_; + for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; + __i != __e; ++__i, ++__t) + *__t = __s[*__i]; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator=(const indirect_array<value_type>& __ia) +{ + typedef const size_t* _Ip; + value_type* __t = __begin_; + const value_type* __s = __ia.__vp_; + for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; + __i != __e; ++__i, ++__t) + *__t = __s[*__i]; + return *this; +} + +template <class _Tp> +template <class _ValExpr> +inline +valarray<_Tp>& +valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v) +{ + size_t __n = __v.size(); + if (size() != __n) + resize(__n); + value_type* __t = __begin_; + for (size_t __i = 0; __i != __n; ++__t, ++__i) + *__t = result_type(__v[__i]); + return *this; +} + +template <class _Tp> +inline +__val_expr<__slice_expr<const valarray<_Tp>&> > +valarray<_Tp>::operator[](slice __s) const +{ + return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this)); +} + +template <class _Tp> +inline +slice_array<_Tp> +valarray<_Tp>::operator[](slice __s) +{ + return slice_array<value_type>(__s, *this); +} + +template <class _Tp> +inline +__val_expr<__indirect_expr<const valarray<_Tp>&> > +valarray<_Tp>::operator[](const gslice& __gs) const +{ + return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this)); +} + +template <class _Tp> +inline +gslice_array<_Tp> +valarray<_Tp>::operator[](const gslice& __gs) +{ + return gslice_array<value_type>(__gs, *this); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp> +inline +__val_expr<__indirect_expr<const valarray<_Tp>&> > +valarray<_Tp>::operator[](gslice&& __gs) const +{ + return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this)); +} + +template <class _Tp> +inline +gslice_array<_Tp> +valarray<_Tp>::operator[](gslice&& __gs) +{ + return gslice_array<value_type>(move(__gs), *this); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp> +inline +__val_expr<__mask_expr<const valarray<_Tp>&> > +valarray<_Tp>::operator[](const valarray<bool>& __vb) const +{ + return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this)); +} + +template <class _Tp> +inline +mask_array<_Tp> +valarray<_Tp>::operator[](const valarray<bool>& __vb) +{ + return mask_array<value_type>(__vb, *this); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp> +inline +__val_expr<__mask_expr<const valarray<_Tp>&> > +valarray<_Tp>::operator[](valarray<bool>&& __vb) const +{ + return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this)); +} + +template <class _Tp> +inline +mask_array<_Tp> +valarray<_Tp>::operator[](valarray<bool>&& __vb) +{ + return mask_array<value_type>(move(__vb), *this); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp> +inline +__val_expr<__indirect_expr<const valarray<_Tp>&> > +valarray<_Tp>::operator[](const valarray<size_t>& __vs) const +{ + return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this)); +} + +template <class _Tp> +inline +indirect_array<_Tp> +valarray<_Tp>::operator[](const valarray<size_t>& __vs) +{ + return indirect_array<value_type>(__vs, *this); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp> +inline +__val_expr<__indirect_expr<const valarray<_Tp>&> > +valarray<_Tp>::operator[](valarray<size_t>&& __vs) const +{ + return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this)); +} + +template <class _Tp> +inline +indirect_array<_Tp> +valarray<_Tp>::operator[](valarray<size_t>&& __vs) +{ + return indirect_array<value_type>(move(__vs), *this); +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp> +valarray<_Tp> +valarray<_Tp>::operator+() const +{ + valarray<value_type> __r; + size_t __n = size(); + if (__n) + { + __r.__begin_ = + __r.__end_ = + static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); + for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) + ::new (__r.__end_) value_type(+*__p); + } + return __r; +} + +template <class _Tp> +valarray<_Tp> +valarray<_Tp>::operator-() const +{ + valarray<value_type> __r; + size_t __n = size(); + if (__n) + { + __r.__begin_ = + __r.__end_ = + static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); + for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) + ::new (__r.__end_) value_type(-*__p); + } + return __r; +} + +template <class _Tp> +valarray<_Tp> +valarray<_Tp>::operator~() const +{ + valarray<value_type> __r; + size_t __n = size(); + if (__n) + { + __r.__begin_ = + __r.__end_ = + static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); + for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) + ::new (__r.__end_) value_type(~*__p); + } + return __r; +} + +template <class _Tp> +valarray<bool> +valarray<_Tp>::operator!() const +{ + valarray<bool> __r; + size_t __n = size(); + if (__n) + { + __r.__begin_ = + __r.__end_ = + static_cast<bool*>(_VSTD::__libcpp_allocate(__n * sizeof(bool), _LIBCPP_ALIGNOF(bool))); + for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) + ::new (__r.__end_) bool(!*__p); + } + return __r; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator*=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p *= __x; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator/=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p /= __x; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator%=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p %= __x; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator+=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p += __x; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator-=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p -= __x; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator^=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p ^= __x; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator&=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p &= __x; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator|=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p |= __x; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator<<=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p <<= __x; + return *this; +} + +template <class _Tp> +inline +valarray<_Tp>& +valarray<_Tp>::operator>>=(const value_type& __x) +{ + for (value_type* __p = __begin_; __p != __end_; ++__p) + *__p >>= __x; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator*=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t *= __v[__i]; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator/=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t /= __v[__i]; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator%=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t %= __v[__i]; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator+=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t += __v[__i]; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator-=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t -= __v[__i]; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator^=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t ^= __v[__i]; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator|=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t |= __v[__i]; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator&=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t &= __v[__i]; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator<<=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t <<= __v[__i]; + return *this; +} + +template <class _Tp> +template <class _Expr> +inline +typename enable_if +< + __is_val_expr<_Expr>::value, + valarray<_Tp>& +>::type +valarray<_Tp>::operator>>=(const _Expr& __v) +{ + size_t __i = 0; + for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) + *__t >>= __v[__i]; + return *this; +} + +template <class _Tp> +inline +void +valarray<_Tp>::swap(valarray& __v) _NOEXCEPT +{ + _VSTD::swap(__begin_, __v.__begin_); + _VSTD::swap(__end_, __v.__end_); +} + +template <class _Tp> +inline +_Tp +valarray<_Tp>::sum() const +{ + if (__begin_ == __end_) + return value_type(); + const value_type* __p = __begin_; + _Tp __r = *__p; + for (++__p; __p != __end_; ++__p) + __r += *__p; + return __r; +} + +template <class _Tp> +inline +_Tp +valarray<_Tp>::min() const +{ + if (__begin_ == __end_) + return value_type(); + return *_VSTD::min_element(__begin_, __end_); +} + +template <class _Tp> +inline +_Tp +valarray<_Tp>::max() const +{ + if (__begin_ == __end_) + return value_type(); + return *_VSTD::max_element(__begin_, __end_); +} + +template <class _Tp> +valarray<_Tp> +valarray<_Tp>::shift(int __i) const +{ + valarray<value_type> __r; + size_t __n = size(); + if (__n) + { + __r.__begin_ = + __r.__end_ = + static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); + const value_type* __sb; + value_type* __tb; + value_type* __te; + if (__i >= 0) + { + __i = _VSTD::min(__i, static_cast<int>(__n)); + __sb = __begin_ + __i; + __tb = __r.__begin_; + __te = __r.__begin_ + (__n - __i); + } + else + { + __i = _VSTD::min(-__i, static_cast<int>(__n)); + __sb = __begin_; + __tb = __r.__begin_ + __i; + __te = __r.__begin_ + __n; + } + for (; __r.__end_ != __tb; ++__r.__end_) + ::new (__r.__end_) value_type(); + for (; __r.__end_ != __te; ++__r.__end_, ++__sb) + ::new (__r.__end_) value_type(*__sb); + for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_) + ::new (__r.__end_) value_type(); + } + return __r; +} + +template <class _Tp> +valarray<_Tp> +valarray<_Tp>::cshift(int __i) const +{ + valarray<value_type> __r; + size_t __n = size(); + if (__n) + { + __r.__begin_ = + __r.__end_ = + static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); + __i %= static_cast<int>(__n); + const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i; + for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s) + ::new (__r.__end_) value_type(*__s); + for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s) + ::new (__r.__end_) value_type(*__s); + } + return __r; +} + +template <class _Tp> +valarray<_Tp> +valarray<_Tp>::apply(value_type __f(value_type)) const +{ + valarray<value_type> __r; + size_t __n = size(); + if (__n) + { + __r.__begin_ = + __r.__end_ = + static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); + for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) + ::new (__r.__end_) value_type(__f(*__p)); + } + return __r; +} + +template <class _Tp> +valarray<_Tp> +valarray<_Tp>::apply(value_type __f(const value_type&)) const +{ + valarray<value_type> __r; + size_t __n = size(); + if (__n) + { + __r.__begin_ = + __r.__end_ = + static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); + for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) + ::new (__r.__end_) value_type(__f(*__p)); + } + return __r; +} + +template <class _Tp> +inline +void valarray<_Tp>::__clear(size_t __capacity) +{ + if (__begin_ != nullptr) + { + while (__end_ != __begin_) + (--__end_)->~value_type(); + _VSTD::__libcpp_deallocate(__begin_, __capacity * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)); + __begin_ = __end_ = nullptr; + } +} + +template <class _Tp> +void +valarray<_Tp>::resize(size_t __n, value_type __x) +{ + __clear(size()); + if (__n) + { + __begin_ = __end_ = static_cast<value_type*>( + _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) + ::new (__end_) value_type(__x); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __clear(__n); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT +{ + __x.swap(__y); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator*(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator*(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(multiplies<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator*(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(multiplies<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator/(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<divides<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator/(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(divides<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<divides<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator/(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(divides<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator%(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator%(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(modulus<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator%(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(modulus<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator+(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<plus<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator+(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(plus<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<plus<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator+(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(plus<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator-(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<minus<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator-(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(minus<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<minus<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator-(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(minus<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator^(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator^(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(bit_xor<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator^(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(bit_xor<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator&(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator&(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(bit_and<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator&(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(bit_and<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator|(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator|(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(bit_or<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator|(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(bit_or<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator<<(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator<<(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator<<(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator>>(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator>>(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator>>(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator&&(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator&&(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(logical_and<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator&&(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(logical_and<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator||(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator||(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(logical_or<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator||(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(logical_or<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator==(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator==(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(equal_to<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator==(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(equal_to<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator!=(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator!=(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(not_equal_to<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator!=(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(not_equal_to<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator<(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(less<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<less<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator<(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(less<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<less<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator<(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(less<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator>(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<greater<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator>(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(greater<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<greater<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator>(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(greater<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator<=(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator<=(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(less_equal<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator<=(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(less_equal<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +operator>=(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +operator>=(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(greater_equal<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +operator>=(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(greater_equal<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> > +>::type +abs(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> > +>::type +acos(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> > +>::type +asin(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> > +>::type +atan(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +atan2(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +atan2(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +atan2(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> > +>::type +cos(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> > +>::type +cosh(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> > +>::type +exp(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> > +>::type +log(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> > +>::type +log10(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x)); +} + +template<class _Expr1, class _Expr2> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, + __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > +>::type +pow(const _Expr1& __x, const _Expr2& __y) +{ + typedef typename _Expr1::value_type value_type; + typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op; + return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, + _Expr, __scalar_expr<typename _Expr::value_type> > > +>::type +pow(const _Expr& __x, const typename _Expr::value_type& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; + return __val_expr<_Op>(_Op(__pow_expr<value_type>(), + __x, __scalar_expr<value_type>(__y, __x.size()))); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, + __scalar_expr<typename _Expr::value_type>, _Expr> > +>::type +pow(const typename _Expr::value_type& __x, const _Expr& __y) +{ + typedef typename _Expr::value_type value_type; + typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__pow_expr<value_type>(), + __scalar_expr<value_type>(__x, __y.size()), __y)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> > +>::type +sin(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> > +>::type +sinh(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> > +>::type +sqrt(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> > +>::type +tan(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x)); +} + +template<class _Expr> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_val_expr<_Expr>::value, + __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> > +>::type +tanh(const _Expr& __x) +{ + typedef typename _Expr::value_type value_type; + typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op; + return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x)); +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +begin(valarray<_Tp>& __v) +{ + return __v.__begin_; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +const _Tp* +begin(const valarray<_Tp>& __v) +{ + return __v.__begin_; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +end(valarray<_Tp>& __v) +{ + return __v.__end_; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +const _Tp* +end(const valarray<_Tp>& __v) +{ + return __v.__end_; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_VALARRAY diff --git a/android/x86/include/v8/libc++/variant b/android/x86/include/v8/libc++/variant new file mode 100755 index 00000000..5d0722b6 --- /dev/null +++ b/android/x86/include/v8/libc++/variant @@ -0,0 +1,1615 @@ +// -*- C++ -*- +//===------------------------------ variant -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_VARIANT +#define _LIBCPP_VARIANT + +/* + variant synopsis + +namespace std { + + // 20.7.2, class template variant + template <class... Types> + class variant { + public: + + // 20.7.2.1, constructors + constexpr variant() noexcept(see below); + variant(const variant&); // constexpr in C++20 + variant(variant&&) noexcept(see below); // constexpr in C++20 + + template <class T> constexpr variant(T&&) noexcept(see below); + + template <class T, class... Args> + constexpr explicit variant(in_place_type_t<T>, Args&&...); + + template <class T, class U, class... Args> + constexpr explicit variant( + in_place_type_t<T>, initializer_list<U>, Args&&...); + + template <size_t I, class... Args> + constexpr explicit variant(in_place_index_t<I>, Args&&...); + + template <size_t I, class U, class... Args> + constexpr explicit variant( + in_place_index_t<I>, initializer_list<U>, Args&&...); + + // 20.7.2.2, destructor + ~variant(); + + // 20.7.2.3, assignment + variant& operator=(const variant&); // constexpr in C++20 + variant& operator=(variant&&) noexcept(see below); // constexpr in C++20 + + template <class T> variant& operator=(T&&) noexcept(see below); + + // 20.7.2.4, modifiers + template <class T, class... Args> + T& emplace(Args&&...); + + template <class T, class U, class... Args> + T& emplace(initializer_list<U>, Args&&...); + + template <size_t I, class... Args> + variant_alternative_t<I, variant>& emplace(Args&&...); + + template <size_t I, class U, class... Args> + variant_alternative_t<I, variant>& emplace(initializer_list<U>, Args&&...); + + // 20.7.2.5, value status + constexpr bool valueless_by_exception() const noexcept; + constexpr size_t index() const noexcept; + + // 20.7.2.6, swap + void swap(variant&) noexcept(see below); + }; + + // 20.7.3, variant helper classes + template <class T> struct variant_size; // undefined + + template <class T> + inline constexpr size_t variant_size_v = variant_size<T>::value; + + template <class T> struct variant_size<const T>; + template <class T> struct variant_size<volatile T>; + template <class T> struct variant_size<const volatile T>; + + template <class... Types> + struct variant_size<variant<Types...>>; + + template <size_t I, class T> struct variant_alternative; // undefined + + template <size_t I, class T> + using variant_alternative_t = typename variant_alternative<I, T>::type; + + template <size_t I, class T> struct variant_alternative<I, const T>; + template <size_t I, class T> struct variant_alternative<I, volatile T>; + template <size_t I, class T> struct variant_alternative<I, const volatile T>; + + template <size_t I, class... Types> + struct variant_alternative<I, variant<Types...>>; + + inline constexpr size_t variant_npos = -1; + + // 20.7.4, value access + template <class T, class... Types> + constexpr bool holds_alternative(const variant<Types...>&) noexcept; + + template <size_t I, class... Types> + constexpr variant_alternative_t<I, variant<Types...>>& + get(variant<Types...>&); + + template <size_t I, class... Types> + constexpr variant_alternative_t<I, variant<Types...>>&& + get(variant<Types...>&&); + + template <size_t I, class... Types> + constexpr variant_alternative_t<I, variant<Types...>> const& + get(const variant<Types...>&); + + template <size_t I, class... Types> + constexpr variant_alternative_t<I, variant<Types...>> const&& + get(const variant<Types...>&&); + + template <class T, class... Types> + constexpr T& get(variant<Types...>&); + + template <class T, class... Types> + constexpr T&& get(variant<Types...>&&); + + template <class T, class... Types> + constexpr const T& get(const variant<Types...>&); + + template <class T, class... Types> + constexpr const T&& get(const variant<Types...>&&); + + template <size_t I, class... Types> + constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>> + get_if(variant<Types...>*) noexcept; + + template <size_t I, class... Types> + constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>> + get_if(const variant<Types...>*) noexcept; + + template <class T, class... Types> + constexpr add_pointer_t<T> + get_if(variant<Types...>*) noexcept; + + template <class T, class... Types> + constexpr add_pointer_t<const T> + get_if(const variant<Types...>*) noexcept; + + // 20.7.5, relational operators + template <class... Types> + constexpr bool operator==(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator!=(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator<(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator>(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator<=(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&); + + // 20.7.6, visitation + template <class Visitor, class... Variants> + constexpr see below visit(Visitor&&, Variants&&...); + + // 20.7.7, class monostate + struct monostate; + + // 20.7.8, monostate relational operators + constexpr bool operator<(monostate, monostate) noexcept; + constexpr bool operator>(monostate, monostate) noexcept; + constexpr bool operator<=(monostate, monostate) noexcept; + constexpr bool operator>=(monostate, monostate) noexcept; + constexpr bool operator==(monostate, monostate) noexcept; + constexpr bool operator!=(monostate, monostate) noexcept; + + // 20.7.9, specialized algorithms + template <class... Types> + void swap(variant<Types...>&, variant<Types...>&) noexcept(see below); + + // 20.7.10, class bad_variant_access + class bad_variant_access; + + // 20.7.11, hash support + template <class T> struct hash; + template <class... Types> struct hash<variant<Types...>>; + template <> struct hash<monostate>; + +} // namespace std + +*/ + +#include <__config> +#include <__tuple> +#include <array> +#include <exception> +#include <functional> +#include <initializer_list> +#include <new> +#include <tuple> +#include <type_traits> +#include <utility> +#include <limits> +#include <version> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +namespace std { // explicitly not using versioning namespace + +class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS bad_variant_access : public exception { +public: + virtual const char* what() const _NOEXCEPT; +}; + +} // namespace std + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_NORETURN +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +void __throw_bad_variant_access() { +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_variant_access(); +#else + _VSTD::abort(); +#endif +} + +template <class... _Types> +class _LIBCPP_TEMPLATE_VIS variant; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_size; + +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t variant_size_v = variant_size<_Tp>::value; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_size<const _Tp> : variant_size<_Tp> {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_size<volatile _Tp> : variant_size<_Tp> {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_size<const volatile _Tp> + : variant_size<_Tp> {}; + +template <class... _Types> +struct _LIBCPP_TEMPLATE_VIS variant_size<variant<_Types...>> + : integral_constant<size_t, sizeof...(_Types)> {}; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_alternative; + +template <size_t _Ip, class _Tp> +using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const _Tp> + : add_const<variant_alternative_t<_Ip, _Tp>> {}; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, volatile _Tp> + : add_volatile<variant_alternative_t<_Ip, _Tp>> {}; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp> + : add_cv<variant_alternative_t<_Ip, _Tp>> {}; + +template <size_t _Ip, class... _Types> +struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> { + static_assert(_Ip < sizeof...(_Types), "Index out of bounds in std::variant_alternative<>"); + using type = __type_pack_element<_Ip, _Types...>; +}; + +_LIBCPP_INLINE_VAR constexpr size_t variant_npos = static_cast<size_t>(-1); + +constexpr int __choose_index_type(unsigned int __num_elem) { + if (__num_elem < std::numeric_limits<unsigned char>::max()) + return 0; + if (__num_elem < std::numeric_limits<unsigned short>::max()) + return 1; + return 2; +} + +template <size_t _NumAlts> +using __variant_index_t = +#ifndef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION + unsigned int; +#else + std::tuple_element_t< + __choose_index_type(_NumAlts), + std::tuple<unsigned char, unsigned short, unsigned int> + >; +#endif + +template <class _IndexType> +constexpr _IndexType __variant_npos = static_cast<_IndexType>(-1); + +namespace __find_detail { + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr size_t __find_index() { + constexpr bool __matches[] = {is_same_v<_Tp, _Types>...}; + size_t __result = __not_found; + for (size_t __i = 0; __i < sizeof...(_Types); ++__i) { + if (__matches[__i]) { + if (__result != __not_found) { + return __ambiguous; + } + __result = __i; + } + } + return __result; +} + +template <size_t _Index> +struct __find_unambiguous_index_sfinae_impl + : integral_constant<size_t, _Index> {}; + +template <> +struct __find_unambiguous_index_sfinae_impl<__not_found> {}; + +template <> +struct __find_unambiguous_index_sfinae_impl<__ambiguous> {}; + +template <class _Tp, class... _Types> +struct __find_unambiguous_index_sfinae + : __find_unambiguous_index_sfinae_impl<__find_index<_Tp, _Types...>()> {}; + +} // namespace __find_detail + +namespace __variant_detail { + +struct __valueless_t {}; + +enum class _Trait { _TriviallyAvailable, _Available, _Unavailable }; + +template <typename _Tp, + template <typename> class _IsTriviallyAvailable, + template <typename> class _IsAvailable> +constexpr _Trait __trait = + _IsTriviallyAvailable<_Tp>::value + ? _Trait::_TriviallyAvailable + : _IsAvailable<_Tp>::value ? _Trait::_Available : _Trait::_Unavailable; + +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Trait __common_trait(initializer_list<_Trait> __traits) { + _Trait __result = _Trait::_TriviallyAvailable; + for (_Trait __t : __traits) { + if (static_cast<int>(__t) > static_cast<int>(__result)) { + __result = __t; + } + } + return __result; +} + +template <typename... _Types> +struct __traits { + static constexpr _Trait __copy_constructible_trait = + __common_trait({__trait<_Types, + is_trivially_copy_constructible, + is_copy_constructible>...}); + + static constexpr _Trait __move_constructible_trait = + __common_trait({__trait<_Types, + is_trivially_move_constructible, + is_move_constructible>...}); + + static constexpr _Trait __copy_assignable_trait = __common_trait( + {__copy_constructible_trait, + __trait<_Types, is_trivially_copy_assignable, is_copy_assignable>...}); + + static constexpr _Trait __move_assignable_trait = __common_trait( + {__move_constructible_trait, + __trait<_Types, is_trivially_move_assignable, is_move_assignable>...}); + + static constexpr _Trait __destructible_trait = __common_trait( + {__trait<_Types, is_trivially_destructible, is_destructible>...}); +}; + +namespace __access { + +struct __union { + template <class _Vp> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<0>) { + return _VSTD::forward<_Vp>(__v).__head; + } + + template <class _Vp, size_t _Ip> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<_Ip>) { + return __get_alt(_VSTD::forward<_Vp>(__v).__tail, in_place_index<_Ip - 1>); + } +}; + +struct __base { + template <size_t _Ip, class _Vp> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v) { + return __union::__get_alt(_VSTD::forward<_Vp>(__v).__data, + in_place_index<_Ip>); + } +}; + +struct __variant { + template <size_t _Ip, class _Vp> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v) { + return __base::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v).__impl); + } +}; + +} // namespace __access + +namespace __visitation { + +struct __base { + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) + __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { + constexpr auto __fdiagonal = + __make_fdiagonal<_Visitor&&, + decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>(); + return __fdiagonal[__index](_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__as_base()...); + } + + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, + _Vs&&... __vs) { + constexpr auto __fmatrix = + __make_fmatrix<_Visitor&&, + decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>(); + return __at(__fmatrix, __vs.index()...)( + _VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__as_base()...); + } + +private: + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr const _Tp& __at(const _Tp& __elem) { return __elem; } + + template <class _Tp, size_t _Np, typename... _Indices> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __at(const array<_Tp, _Np>& __elems, + size_t __index, _Indices... __indices) { + return __at(__elems[__index], __indices...); + } + + template <class _Fp, class... _Fs> + static constexpr void __std_visit_visitor_return_type_check() { + static_assert( + __all<is_same_v<_Fp, _Fs>...>::value, + "`std::visit` requires the visitor to have a single return type."); + } + + template <class... _Fs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_farray(_Fs&&... __fs) { + __std_visit_visitor_return_type_check<__uncvref_t<_Fs>...>(); + using __result = array<common_type_t<__uncvref_t<_Fs>...>, sizeof...(_Fs)>; + return __result{{_VSTD::forward<_Fs>(__fs)...}}; + } + + template <std::size_t... _Is> + struct __dispatcher { + template <class _Fp, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) { + return __invoke_constexpr( + static_cast<_Fp>(__f), + __access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...); + } + }; + + template <class _Fp, class... _Vs, size_t... _Is> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_dispatch(index_sequence<_Is...>) { + return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>; + } + + template <size_t _Ip, class _Fp, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fdiagonal_impl() { + return __make_dispatch<_Fp, _Vs...>( + index_sequence<(__identity<_Vs>{}, _Ip)...>{}); + } + + template <class _Fp, class... _Vs, size_t... _Is> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fdiagonal_impl(index_sequence<_Is...>) { + return __base::__make_farray(__make_fdiagonal_impl<_Is, _Fp, _Vs...>()...); + } + + template <class _Fp, class _Vp, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fdiagonal() { + constexpr size_t _Np = __uncvref_t<_Vp>::__size(); + static_assert(__all<(_Np == __uncvref_t<_Vs>::__size())...>::value); + return __make_fdiagonal_impl<_Fp, _Vp, _Vs...>(make_index_sequence<_Np>{}); + } + + template <class _Fp, class... _Vs, size_t... _Is> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fmatrix_impl(index_sequence<_Is...> __is) { + return __make_dispatch<_Fp, _Vs...>(__is); + } + + template <class _Fp, class... _Vs, size_t... _Is, size_t... _Js, class... _Ls> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fmatrix_impl(index_sequence<_Is...>, + index_sequence<_Js...>, + _Ls... __ls) { + return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>( + index_sequence<_Is..., _Js>{}, __ls...)...); + } + + template <class _Fp, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fmatrix() { + return __make_fmatrix_impl<_Fp, _Vs...>( + index_sequence<>{}, make_index_sequence<__uncvref_t<_Vs>::__size()>{}...); + } +}; + +struct __variant { + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) + __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { + return __base::__visit_alt_at(__index, + _VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__impl...); + } + + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, + _Vs&&... __vs) { + return __base::__visit_alt(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__impl...); + } + + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) + __visit_value_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { + return __visit_alt_at( + __index, + __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)), + _VSTD::forward<_Vs>(__vs)...); + } + + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __visit_value(_Visitor&& __visitor, + _Vs&&... __vs) { + return __visit_alt( + __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)), + _VSTD::forward<_Vs>(__vs)...); + } + +private: + template <class _Visitor, class... _Values> + static constexpr void __std_visit_exhaustive_visitor_check() { + static_assert(is_invocable_v<_Visitor, _Values...>, + "`std::visit` requires the visitor to be exhaustive."); + } + + template <class _Visitor> + struct __value_visitor { + template <class... _Alts> + inline _LIBCPP_INLINE_VISIBILITY + constexpr decltype(auto) operator()(_Alts&&... __alts) const { + __std_visit_exhaustive_visitor_check< + _Visitor, + decltype((_VSTD::forward<_Alts>(__alts).__value))...>(); + return __invoke_constexpr(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Alts>(__alts).__value...); + } + _Visitor&& __visitor; + }; + + template <class _Visitor> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_value_visitor(_Visitor&& __visitor) { + return __value_visitor<_Visitor>{_VSTD::forward<_Visitor>(__visitor)}; + } +}; + +} // namespace __visitation + +template <size_t _Index, class _Tp> +struct _LIBCPP_TEMPLATE_VIS __alt { + using __value_type = _Tp; + + template <class... _Args> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr __alt(in_place_t, _Args&&... __args) + : __value(_VSTD::forward<_Args>(__args)...) {} + + __value_type __value; +}; + +template <_Trait _DestructibleTrait, size_t _Index, class... _Types> +union _LIBCPP_TEMPLATE_VIS __union; + +template <_Trait _DestructibleTrait, size_t _Index> +union _LIBCPP_TEMPLATE_VIS __union<_DestructibleTrait, _Index> {}; + +#define _LIBCPP_VARIANT_UNION(destructible_trait, destructor) \ + template <size_t _Index, class _Tp, class... _Types> \ + union _LIBCPP_TEMPLATE_VIS __union<destructible_trait, \ + _Index, \ + _Tp, \ + _Types...> { \ + public: \ + inline _LIBCPP_INLINE_VISIBILITY \ + explicit constexpr __union(__valueless_t) noexcept : __dummy{} {} \ + \ + template <class... _Args> \ + inline _LIBCPP_INLINE_VISIBILITY \ + explicit constexpr __union(in_place_index_t<0>, _Args&&... __args) \ + : __head(in_place, _VSTD::forward<_Args>(__args)...) {} \ + \ + template <size_t _Ip, class... _Args> \ + inline _LIBCPP_INLINE_VISIBILITY \ + explicit constexpr __union(in_place_index_t<_Ip>, _Args&&... __args) \ + : __tail(in_place_index<_Ip - 1>, _VSTD::forward<_Args>(__args)...) {} \ + \ + __union(const __union&) = default; \ + __union(__union&&) = default; \ + \ + destructor \ + \ + __union& operator=(const __union&) = default; \ + __union& operator=(__union&&) = default; \ + \ + private: \ + char __dummy; \ + __alt<_Index, _Tp> __head; \ + __union<destructible_trait, _Index + 1, _Types...> __tail; \ + \ + friend struct __access::__union; \ + } + +_LIBCPP_VARIANT_UNION(_Trait::_TriviallyAvailable, ~__union() = default;); +_LIBCPP_VARIANT_UNION(_Trait::_Available, ~__union() {}); +_LIBCPP_VARIANT_UNION(_Trait::_Unavailable, ~__union() = delete;); + +#undef _LIBCPP_VARIANT_UNION + +template <_Trait _DestructibleTrait, class... _Types> +class _LIBCPP_TEMPLATE_VIS __base { +public: + using __index_t = __variant_index_t<sizeof...(_Types)>; + + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr __base(__valueless_t tag) noexcept + : __data(tag), __index(__variant_npos<__index_t>) {} + + template <size_t _Ip, class... _Args> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr __base(in_place_index_t<_Ip>, _Args&&... __args) + : + __data(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...), + __index(_Ip) {} + + inline _LIBCPP_INLINE_VISIBILITY + constexpr bool valueless_by_exception() const noexcept { + return index() == variant_npos; + } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr size_t index() const noexcept { + return __index == __variant_npos<__index_t> ? variant_npos : __index; + } + +protected: + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() & { return *this; } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() && { return _VSTD::move(*this); } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() const & { return *this; } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() const && { return _VSTD::move(*this); } + + inline _LIBCPP_INLINE_VISIBILITY + static constexpr size_t __size() { return sizeof...(_Types); } + + __union<_DestructibleTrait, 0, _Types...> __data; + __index_t __index; + + friend struct __access::__base; + friend struct __visitation::__base; +}; + +template <class _Traits, _Trait = _Traits::__destructible_trait> +class _LIBCPP_TEMPLATE_VIS __destructor; + +#define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor, destroy) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __destructor<__traits<_Types...>, \ + destructible_trait> \ + : public __base<destructible_trait, _Types...> { \ + using __base_type = __base<destructible_trait, _Types...>; \ + using __index_t = typename __base_type::__index_t; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __destructor(const __destructor&) = default; \ + __destructor(__destructor&&) = default; \ + destructor \ + __destructor& operator=(const __destructor&) = default; \ + __destructor& operator=(__destructor&&) = default; \ + \ + protected: \ + inline _LIBCPP_INLINE_VISIBILITY \ + destroy \ + } + +_LIBCPP_VARIANT_DESTRUCTOR( + _Trait::_TriviallyAvailable, + ~__destructor() = default;, + void __destroy() noexcept { this->__index = __variant_npos<__index_t>; }); + +_LIBCPP_VARIANT_DESTRUCTOR( + _Trait::_Available, + ~__destructor() { __destroy(); }, + void __destroy() noexcept { + if (!this->valueless_by_exception()) { + __visitation::__base::__visit_alt( + [](auto& __alt) noexcept { + using __alt_type = __uncvref_t<decltype(__alt)>; + __alt.~__alt_type(); + }, + *this); + } + this->__index = __variant_npos<__index_t>; + }); + +_LIBCPP_VARIANT_DESTRUCTOR( + _Trait::_Unavailable, + ~__destructor() = delete;, + void __destroy() noexcept = delete;); + +#undef _LIBCPP_VARIANT_DESTRUCTOR + +template <class _Traits> +class _LIBCPP_TEMPLATE_VIS __constructor : public __destructor<_Traits> { + using __base_type = __destructor<_Traits>; + +public: + using __base_type::__base_type; + using __base_type::operator=; + +protected: + template <size_t _Ip, class _Tp, class... _Args> + inline _LIBCPP_INLINE_VISIBILITY + static _Tp& __construct_alt(__alt<_Ip, _Tp>& __a, _Args&&... __args) { + ::new ((void*)_VSTD::addressof(__a)) + __alt<_Ip, _Tp>(in_place, _VSTD::forward<_Args>(__args)...); + return __a.__value; + } + + template <class _Rhs> + inline _LIBCPP_INLINE_VISIBILITY + static void __generic_construct(__constructor& __lhs, _Rhs&& __rhs) { + __lhs.__destroy(); + if (!__rhs.valueless_by_exception()) { + __visitation::__base::__visit_alt_at( + __rhs.index(), + [](auto& __lhs_alt, auto&& __rhs_alt) { + __construct_alt( + __lhs_alt, + _VSTD::forward<decltype(__rhs_alt)>(__rhs_alt).__value); + }, + __lhs, _VSTD::forward<_Rhs>(__rhs)); + __lhs.__index = __rhs.index(); + } + } +}; + +template <class _Traits, _Trait = _Traits::__move_constructible_trait> +class _LIBCPP_TEMPLATE_VIS __move_constructor; + +#define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, \ + move_constructor) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __move_constructor<__traits<_Types...>, \ + move_constructible_trait> \ + : public __constructor<__traits<_Types...>> { \ + using __base_type = __constructor<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __move_constructor(const __move_constructor&) = default; \ + move_constructor \ + ~__move_constructor() = default; \ + __move_constructor& operator=(const __move_constructor&) = default; \ + __move_constructor& operator=(__move_constructor&&) = default; \ + } + +_LIBCPP_VARIANT_MOVE_CONSTRUCTOR( + _Trait::_TriviallyAvailable, + __move_constructor(__move_constructor&& __that) = default;); + +_LIBCPP_VARIANT_MOVE_CONSTRUCTOR( + _Trait::_Available, + __move_constructor(__move_constructor&& __that) noexcept( + __all<is_nothrow_move_constructible_v<_Types>...>::value) + : __move_constructor(__valueless_t{}) { + this->__generic_construct(*this, _VSTD::move(__that)); + }); + +_LIBCPP_VARIANT_MOVE_CONSTRUCTOR( + _Trait::_Unavailable, + __move_constructor(__move_constructor&&) = delete;); + +#undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR + +template <class _Traits, _Trait = _Traits::__copy_constructible_trait> +class _LIBCPP_TEMPLATE_VIS __copy_constructor; + +#define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, \ + copy_constructor) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __copy_constructor<__traits<_Types...>, \ + copy_constructible_trait> \ + : public __move_constructor<__traits<_Types...>> { \ + using __base_type = __move_constructor<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + copy_constructor \ + __copy_constructor(__copy_constructor&&) = default; \ + ~__copy_constructor() = default; \ + __copy_constructor& operator=(const __copy_constructor&) = default; \ + __copy_constructor& operator=(__copy_constructor&&) = default; \ + } + +_LIBCPP_VARIANT_COPY_CONSTRUCTOR( + _Trait::_TriviallyAvailable, + __copy_constructor(const __copy_constructor& __that) = default;); + +_LIBCPP_VARIANT_COPY_CONSTRUCTOR( + _Trait::_Available, + __copy_constructor(const __copy_constructor& __that) + : __copy_constructor(__valueless_t{}) { + this->__generic_construct(*this, __that); + }); + +_LIBCPP_VARIANT_COPY_CONSTRUCTOR( + _Trait::_Unavailable, + __copy_constructor(const __copy_constructor&) = delete;); + +#undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR + +template <class _Traits> +class _LIBCPP_TEMPLATE_VIS __assignment : public __copy_constructor<_Traits> { + using __base_type = __copy_constructor<_Traits>; + +public: + using __base_type::__base_type; + using __base_type::operator=; + + template <size_t _Ip, class... _Args> + inline _LIBCPP_INLINE_VISIBILITY + auto& __emplace(_Args&&... __args) { + this->__destroy(); + auto& __res = this->__construct_alt(__access::__base::__get_alt<_Ip>(*this), + _VSTD::forward<_Args>(__args)...); + this->__index = _Ip; + return __res; + } + +protected: + template <size_t _Ip, class _Tp, class _Arg> + inline _LIBCPP_INLINE_VISIBILITY + void __assign_alt(__alt<_Ip, _Tp>& __a, _Arg&& __arg) { + if (this->index() == _Ip) { + __a.__value = _VSTD::forward<_Arg>(__arg); + } else { + struct { + void operator()(true_type) const { + __this->__emplace<_Ip>(_VSTD::forward<_Arg>(__arg)); + } + void operator()(false_type) const { + __this->__emplace<_Ip>(_Tp(_VSTD::forward<_Arg>(__arg))); + } + __assignment* __this; + _Arg&& __arg; + } __impl{this, _VSTD::forward<_Arg>(__arg)}; + __impl(bool_constant<is_nothrow_constructible_v<_Tp, _Arg> || + !is_nothrow_move_constructible_v<_Tp>>{}); + } + } + + template <class _That> + inline _LIBCPP_INLINE_VISIBILITY + void __generic_assign(_That&& __that) { + if (this->valueless_by_exception() && __that.valueless_by_exception()) { + // do nothing. + } else if (__that.valueless_by_exception()) { + this->__destroy(); + } else { + __visitation::__base::__visit_alt_at( + __that.index(), + [this](auto& __this_alt, auto&& __that_alt) { + this->__assign_alt( + __this_alt, + _VSTD::forward<decltype(__that_alt)>(__that_alt).__value); + }, + *this, _VSTD::forward<_That>(__that)); + } + } +}; + +template <class _Traits, _Trait = _Traits::__move_assignable_trait> +class _LIBCPP_TEMPLATE_VIS __move_assignment; + +#define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, \ + move_assignment) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __move_assignment<__traits<_Types...>, \ + move_assignable_trait> \ + : public __assignment<__traits<_Types...>> { \ + using __base_type = __assignment<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __move_assignment(const __move_assignment&) = default; \ + __move_assignment(__move_assignment&&) = default; \ + ~__move_assignment() = default; \ + __move_assignment& operator=(const __move_assignment&) = default; \ + move_assignment \ + } + +_LIBCPP_VARIANT_MOVE_ASSIGNMENT( + _Trait::_TriviallyAvailable, + __move_assignment& operator=(__move_assignment&& __that) = default;); + +_LIBCPP_VARIANT_MOVE_ASSIGNMENT( + _Trait::_Available, + __move_assignment& operator=(__move_assignment&& __that) noexcept( + __all<(is_nothrow_move_constructible_v<_Types> && + is_nothrow_move_assignable_v<_Types>)...>::value) { + this->__generic_assign(_VSTD::move(__that)); + return *this; + }); + +_LIBCPP_VARIANT_MOVE_ASSIGNMENT( + _Trait::_Unavailable, + __move_assignment& operator=(__move_assignment&&) = delete;); + +#undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT + +template <class _Traits, _Trait = _Traits::__copy_assignable_trait> +class _LIBCPP_TEMPLATE_VIS __copy_assignment; + +#define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, \ + copy_assignment) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __copy_assignment<__traits<_Types...>, \ + copy_assignable_trait> \ + : public __move_assignment<__traits<_Types...>> { \ + using __base_type = __move_assignment<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __copy_assignment(const __copy_assignment&) = default; \ + __copy_assignment(__copy_assignment&&) = default; \ + ~__copy_assignment() = default; \ + copy_assignment \ + __copy_assignment& operator=(__copy_assignment&&) = default; \ + } + +_LIBCPP_VARIANT_COPY_ASSIGNMENT( + _Trait::_TriviallyAvailable, + __copy_assignment& operator=(const __copy_assignment& __that) = default;); + +_LIBCPP_VARIANT_COPY_ASSIGNMENT( + _Trait::_Available, + __copy_assignment& operator=(const __copy_assignment& __that) { + this->__generic_assign(__that); + return *this; + }); + +_LIBCPP_VARIANT_COPY_ASSIGNMENT( + _Trait::_Unavailable, + __copy_assignment& operator=(const __copy_assignment&) = delete;); + +#undef _LIBCPP_VARIANT_COPY_ASSIGNMENT + +template <class... _Types> +class _LIBCPP_TEMPLATE_VIS __impl + : public __copy_assignment<__traits<_Types...>> { + using __base_type = __copy_assignment<__traits<_Types...>>; + +public: + using __base_type::__base_type; + using __base_type::operator=; + + template <size_t _Ip, class _Arg> + inline _LIBCPP_INLINE_VISIBILITY + void __assign(_Arg&& __arg) { + this->__assign_alt(__access::__base::__get_alt<_Ip>(*this), + _VSTD::forward<_Arg>(__arg)); + } + + inline _LIBCPP_INLINE_VISIBILITY + void __swap(__impl& __that) { + if (this->valueless_by_exception() && __that.valueless_by_exception()) { + // do nothing. + } else if (this->index() == __that.index()) { + __visitation::__base::__visit_alt_at( + this->index(), + [](auto& __this_alt, auto& __that_alt) { + using _VSTD::swap; + swap(__this_alt.__value, __that_alt.__value); + }, + *this, + __that); + } else { + __impl* __lhs = this; + __impl* __rhs = _VSTD::addressof(__that); + if (__lhs->__move_nothrow() && !__rhs->__move_nothrow()) { + _VSTD::swap(__lhs, __rhs); + } + __impl __tmp(_VSTD::move(*__rhs)); +#ifndef _LIBCPP_NO_EXCEPTIONS + // EXTENSION: When the move construction of `__lhs` into `__rhs` throws + // and `__tmp` is nothrow move constructible then we move `__tmp` back + // into `__rhs` and provide the strong exception safety guarantee. + try { + this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); + } catch (...) { + if (__tmp.__move_nothrow()) { + this->__generic_construct(*__rhs, _VSTD::move(__tmp)); + } + throw; + } +#else + this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); +#endif + this->__generic_construct(*__lhs, _VSTD::move(__tmp)); + } + } + +private: + inline _LIBCPP_INLINE_VISIBILITY + bool __move_nothrow() const { + constexpr bool __results[] = {is_nothrow_move_constructible_v<_Types>...}; + return this->valueless_by_exception() || __results[this->index()]; + } +}; + +template <class... _Types> +struct __overload; + +template <> +struct __overload<> { void operator()() const; }; + +template <class _Tp, class... _Types> +struct __overload<_Tp, _Types...> : __overload<_Types...> { + using __overload<_Types...>::operator(); + __identity<_Tp> operator()(_Tp) const; +}; + +template <class _Tp, class... _Types> +using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type; + +} // __variant_detail + +template <class... _Types> +class _LIBCPP_TEMPLATE_VIS variant + : private __sfinae_ctor_base< + __all<is_copy_constructible_v<_Types>...>::value, + __all<is_move_constructible_v<_Types>...>::value>, + private __sfinae_assign_base< + __all<(is_copy_constructible_v<_Types> && + is_copy_assignable_v<_Types>)...>::value, + __all<(is_move_constructible_v<_Types> && + is_move_assignable_v<_Types>)...>::value> { + static_assert(0 < sizeof...(_Types), + "variant must consist of at least one alternative."); + + static_assert(__all<!is_array_v<_Types>...>::value, + "variant can not have an array type as an alternative."); + + static_assert(__all<!is_reference_v<_Types>...>::value, + "variant can not have a reference type as an alternative."); + + static_assert(__all<!is_void_v<_Types>...>::value, + "variant can not have a void type as an alternative."); + + using __first_type = variant_alternative_t<0, variant>; + +public: + template <bool _Dummy = true, + enable_if_t<__dependent_type<is_default_constructible<__first_type>, + _Dummy>::value, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + constexpr variant() noexcept(is_nothrow_default_constructible_v<__first_type>) + : __impl(in_place_index<0>) {} + + variant(const variant&) = default; + variant(variant&&) = default; + + template < + class _Arg, + enable_if_t<!is_same_v<__uncvref_t<_Arg>, variant>, int> = 0, + enable_if_t<!__is_inplace_type<__uncvref_t<_Arg>>::value, int> = 0, + enable_if_t<!__is_inplace_index<__uncvref_t<_Arg>>::value, int> = 0, + class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, _Arg>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + constexpr variant(_Arg&& __arg) noexcept( + is_nothrow_constructible_v<_Tp, _Arg>) + : __impl(in_place_index<_Ip>, _VSTD::forward<_Arg>(__arg)) {} + + template <size_t _Ip, class... _Args, + class = enable_if_t<(_Ip < sizeof...(_Types)), int>, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant( + in_place_index_t<_Ip>, + _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, _Args...>) + : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} + + template < + size_t _Ip, + class _Up, + class... _Args, + enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant( + in_place_index_t<_Ip>, + initializer_list<_Up> __il, + _Args&&... __args) noexcept( + is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>) + : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {} + + template < + class _Tp, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant(in_place_type_t<_Tp>, _Args&&... __args) noexcept( + is_nothrow_constructible_v<_Tp, _Args...>) + : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} + + template < + class _Tp, + class _Up, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant( + in_place_type_t<_Tp>, + initializer_list<_Up> __il, + _Args&&... __args) noexcept( + is_nothrow_constructible_v<_Tp, initializer_list< _Up>&, _Args...>) + : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {} + + ~variant() = default; + + variant& operator=(const variant&) = default; + variant& operator=(variant&&) = default; + + template < + class _Arg, + enable_if_t<!is_same_v<__uncvref_t<_Arg>, variant>, int> = 0, + class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_assignable_v<_Tp&, _Arg> && is_constructible_v<_Tp, _Arg>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + variant& operator=(_Arg&& __arg) noexcept( + is_nothrow_assignable_v<_Tp&, _Arg> && + is_nothrow_constructible_v<_Tp, _Arg>) { + __impl.template __assign<_Ip>(_VSTD::forward<_Arg>(__arg)); + return *this; + } + + template < + size_t _Ip, + class... _Args, + enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(_Args&&... __args) { + return __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...); + } + + template < + size_t _Ip, + class _Up, + class... _Args, + enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) { + return __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...); + } + + template < + class _Tp, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(_Args&&... __args) { + return __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...); + } + + template < + class _Tp, + class _Up, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) { + return __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...); + } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr bool valueless_by_exception() const noexcept { + return __impl.valueless_by_exception(); + } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr size_t index() const noexcept { return __impl.index(); } + + template < + bool _Dummy = true, + enable_if_t< + __all<( + __dependent_type<is_move_constructible<_Types>, _Dummy>::value && + __dependent_type<is_swappable<_Types>, _Dummy>::value)...>::value, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + void swap(variant& __that) noexcept( + __all<(is_nothrow_move_constructible_v<_Types> && + is_nothrow_swappable_v<_Types>)...>::value) { + __impl.__swap(__that.__impl); + } + +private: + __variant_detail::__impl<_Types...> __impl; + + friend struct __variant_detail::__access::__variant; + friend struct __variant_detail::__visitation::__variant; +}; + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool __holds_alternative(const variant<_Types...>& __v) noexcept { + return __v.index() == _Ip; +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept { + return __holds_alternative<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <size_t _Ip, class _Vp> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr auto&& __generic_get(_Vp&& __v) { + using __variant_detail::__access::__variant; + if (!__holds_alternative<_Ip>(__v)) { + __throw_bad_variant_access(); + } + return __variant::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v)).__value; +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr variant_alternative_t<_Ip, variant<_Types...>>& get( + variant<_Types...>& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get<_Ip>(__v); +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr variant_alternative_t<_Ip, variant<_Types...>>&& get( + variant<_Types...>&& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get<_Ip>(_VSTD::move(__v)); +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr const variant_alternative_t<_Ip, variant<_Types...>>& get( + const variant<_Types...>& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get<_Ip>(__v); +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& get( + const variant<_Types...>&& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get<_Ip>(_VSTD::move(__v)); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr _Tp& get(variant<_Types...>& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr _Tp&& get(variant<_Types...>&& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>( + _VSTD::move(__v)); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr const _Tp& get(const variant<_Types...>& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr const _Tp&& get(const variant<_Types...>&& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>( + _VSTD::move(__v)); +} + +template <size_t _Ip, class _Vp> +inline _LIBCPP_INLINE_VISIBILITY +constexpr auto* __generic_get_if(_Vp* __v) noexcept { + using __variant_detail::__access::__variant; + return __v && __holds_alternative<_Ip>(*__v) + ? _VSTD::addressof(__variant::__get_alt<_Ip>(*__v).__value) + : nullptr; +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t<variant_alternative_t<_Ip, variant<_Types...>>> +get_if(variant<_Types...>* __v) noexcept { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get_if<_Ip>(__v); +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t<const variant_alternative_t<_Ip, variant<_Types...>>> +get_if(const variant<_Types...>* __v) noexcept { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get_if<_Ip>(__v); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t<_Tp> +get_if(variant<_Types...>* __v) noexcept { + static_assert(!is_void_v<_Tp>); + return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t<const _Tp> +get_if(const variant<_Types...>* __v) noexcept { + static_assert(!is_void_v<_Tp>); + return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <class _Operator> +struct __convert_to_bool { + template <class _T1, class _T2> + _LIBCPP_INLINE_VISIBILITY constexpr bool operator()(_T1 && __t1, _T2&& __t2) const { + static_assert(std::is_convertible<decltype(_Operator{}(_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2))), bool>::value, + "the relational operator does not return a type which is implicitly convertible to bool"); + return _Operator{}(_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); + } +}; + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.index() != __rhs.index()) return false; + if (__lhs.valueless_by_exception()) return true; + return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<equal_to<>>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.index() != __rhs.index()) return true; + if (__lhs.valueless_by_exception()) return false; + return __variant::__visit_value_at( + __lhs.index(), __convert_to_bool<not_equal_to<>>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__rhs.valueless_by_exception()) return false; + if (__lhs.valueless_by_exception()) return true; + if (__lhs.index() < __rhs.index()) return true; + if (__lhs.index() > __rhs.index()) return false; + return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<less<>>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.valueless_by_exception()) return false; + if (__rhs.valueless_by_exception()) return true; + if (__lhs.index() > __rhs.index()) return true; + if (__lhs.index() < __rhs.index()) return false; + return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<greater<>>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.valueless_by_exception()) return true; + if (__rhs.valueless_by_exception()) return false; + if (__lhs.index() < __rhs.index()) return true; + if (__lhs.index() > __rhs.index()) return false; + return __variant::__visit_value_at( + __lhs.index(), __convert_to_bool<less_equal<>>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__rhs.valueless_by_exception()) return true; + if (__lhs.valueless_by_exception()) return false; + if (__lhs.index() > __rhs.index()) return true; + if (__lhs.index() < __rhs.index()) return false; + return __variant::__visit_value_at( + __lhs.index(), __convert_to_bool<greater_equal<>>{}, __lhs, __rhs); +} + +template <class _Visitor, class... _Vs> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS +constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) { + using __variant_detail::__visitation::__variant; + bool __results[] = {__vs.valueless_by_exception()...}; + for (bool __result : __results) { + if (__result) { + __throw_bad_variant_access(); + } + } + return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs)...); +} + +struct _LIBCPP_TEMPLATE_VIS monostate {}; + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<(monostate, monostate) noexcept { return false; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>(monostate, monostate) noexcept { return false; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(monostate, monostate) noexcept { return true; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(monostate, monostate) noexcept { return true; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(monostate, monostate) noexcept { return true; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(monostate, monostate) noexcept { return false; } + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +auto swap(variant<_Types...>& __lhs, + variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs))) + -> decltype(__lhs.swap(__rhs)) { + __lhs.swap(__rhs); +} + +template <class... _Types> +struct _LIBCPP_TEMPLATE_VIS hash< + __enable_hash_helper<variant<_Types...>, remove_const_t<_Types>...>> { + using argument_type = variant<_Types...>; + using result_type = size_t; + + inline _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type& __v) const { + using __variant_detail::__visitation::__variant; + size_t __res = + __v.valueless_by_exception() + ? 299792458 // Random value chosen by the universe upon creation + : __variant::__visit_alt( + [](const auto& __alt) { + using __alt_type = __uncvref_t<decltype(__alt)>; + using __value_type = remove_const_t< + typename __alt_type::__value_type>; + return hash<__value_type>{}(__alt.__value); + }, + __v); + return __hash_combine(__res, hash<size_t>{}(__v.index())); + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<monostate> { + using argument_type = monostate; + using result_type = size_t; + + inline _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type&) const _NOEXCEPT { + return 66740831; // return a fundamentally attractive random value. + } +}; + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_VARIANT diff --git a/android/x86/include/v8/libc++/vector b/android/x86/include/v8/libc++/vector new file mode 100755 index 00000000..82bf6e00 --- /dev/null +++ b/android/x86/include/v8/libc++/vector @@ -0,0 +1,3436 @@ +// -*- C++ -*- +//===------------------------------ vector --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_VECTOR +#define _LIBCPP_VECTOR + +/* + vector synopsis + +namespace std +{ + +template <class T, class Allocator = allocator<T> > +class vector +{ +public: + typedef T value_type; + typedef Allocator allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + vector() + noexcept(is_nothrow_default_constructible<allocator_type>::value); + explicit vector(const allocator_type&); + explicit vector(size_type n); + explicit vector(size_type n, const allocator_type&); // C++14 + vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); + template <class InputIterator> + vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); + vector(const vector& x); + vector(vector&& x) + noexcept(is_nothrow_move_constructible<allocator_type>::value); + vector(initializer_list<value_type> il); + vector(initializer_list<value_type> il, const allocator_type& a); + ~vector(); + vector& operator=(const vector& x); + vector& operator=(vector&& x) + noexcept( + allocator_type::propagate_on_container_move_assignment::value || + allocator_type::is_always_equal::value); // C++17 + vector& operator=(initializer_list<value_type> il); + template <class InputIterator> + void assign(InputIterator first, InputIterator last); + void assign(size_type n, const value_type& u); + void assign(initializer_list<value_type> il); + + allocator_type get_allocator() const noexcept; + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + size_type size() const noexcept; + size_type max_size() const noexcept; + size_type capacity() const noexcept; + bool empty() const noexcept; + void reserve(size_type n); + void shrink_to_fit() noexcept; + + reference operator[](size_type n); + const_reference operator[](size_type n) const; + reference at(size_type n); + const_reference at(size_type n) const; + + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + value_type* data() noexcept; + const value_type* data() const noexcept; + + void push_back(const value_type& x); + void push_back(value_type&& x); + template <class... Args> + reference emplace_back(Args&&... args); // reference in C++17 + void pop_back(); + + template <class... Args> iterator emplace(const_iterator position, Args&&... args); + iterator insert(const_iterator position, const value_type& x); + iterator insert(const_iterator position, value_type&& x); + iterator insert(const_iterator position, size_type n, const value_type& x); + template <class InputIterator> + iterator insert(const_iterator position, InputIterator first, InputIterator last); + iterator insert(const_iterator position, initializer_list<value_type> il); + + iterator erase(const_iterator position); + iterator erase(const_iterator first, const_iterator last); + + void clear() noexcept; + + void resize(size_type sz); + void resize(size_type sz, const value_type& c); + + void swap(vector&) + noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || + allocator_traits<allocator_type>::is_always_equal::value); // C++17 + + bool __invariants() const; +}; + +template <class Allocator = allocator<T> > +class vector<bool, Allocator> +{ +public: + typedef bool value_type; + typedef Allocator allocator_type; + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + typedef iterator pointer; + typedef const_iterator const_pointer; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + class reference + { + public: + reference(const reference&) noexcept; + operator bool() const noexcept; + reference& operator=(const bool x) noexcept; + reference& operator=(const reference& x) noexcept; + iterator operator&() const noexcept; + void flip() noexcept; + }; + + class const_reference + { + public: + const_reference(const reference&) noexcept; + operator bool() const noexcept; + const_iterator operator&() const noexcept; + }; + + vector() + noexcept(is_nothrow_default_constructible<allocator_type>::value); + explicit vector(const allocator_type&); + explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 + vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); + template <class InputIterator> + vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); + vector(const vector& x); + vector(vector&& x) + noexcept(is_nothrow_move_constructible<allocator_type>::value); + vector(initializer_list<value_type> il); + vector(initializer_list<value_type> il, const allocator_type& a); + ~vector(); + vector& operator=(const vector& x); + vector& operator=(vector&& x) + noexcept( + allocator_type::propagate_on_container_move_assignment::value || + allocator_type::is_always_equal::value); // C++17 + vector& operator=(initializer_list<value_type> il); + template <class InputIterator> + void assign(InputIterator first, InputIterator last); + void assign(size_type n, const value_type& u); + void assign(initializer_list<value_type> il); + + allocator_type get_allocator() const noexcept; + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + size_type size() const noexcept; + size_type max_size() const noexcept; + size_type capacity() const noexcept; + bool empty() const noexcept; + void reserve(size_type n); + void shrink_to_fit() noexcept; + + reference operator[](size_type n); + const_reference operator[](size_type n) const; + reference at(size_type n); + const_reference at(size_type n) const; + + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + void push_back(const value_type& x); + template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17 + void pop_back(); + + template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14 + iterator insert(const_iterator position, const value_type& x); + iterator insert(const_iterator position, size_type n, const value_type& x); + template <class InputIterator> + iterator insert(const_iterator position, InputIterator first, InputIterator last); + iterator insert(const_iterator position, initializer_list<value_type> il); + + iterator erase(const_iterator position); + iterator erase(const_iterator first, const_iterator last); + + void clear() noexcept; + + void resize(size_type sz); + void resize(size_type sz, value_type x); + + void swap(vector&) + noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || + allocator_traits<allocator_type>::is_always_equal::value); // C++17 + void flip() noexcept; + + bool __invariants() const; +}; + +template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> + vector(InputIterator, InputIterator, Allocator = Allocator()) + -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; + +template <class Allocator> struct hash<std::vector<bool, Allocator>>; + +template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); + +template <class T, class Allocator> +void swap(vector<T,Allocator>& x, vector<T,Allocator>& y) + noexcept(noexcept(x.swap(y))); + +template <class T, class Allocator, class U> + void erase(vector<T, Allocator>& c, const U& value); // C++20 +template <class T, class Allocator, class Predicate> + void erase_if(vector<T, Allocator>& c, Predicate pred); // C++20 + +} // std + +*/ + +#include <__config> +#include <iosfwd> // for forward declaration of vector +#include <__bit_reference> +#include <type_traits> +#include <climits> +#include <limits> +#include <initializer_list> +#include <memory> +#include <stdexcept> +#include <algorithm> +#include <cstring> +#include <version> +#include <__split_buffer> +#include <__functional_base> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <bool> +class __vector_base_common +{ +protected: + _LIBCPP_INLINE_VISIBILITY __vector_base_common() {} + _LIBCPP_NORETURN void __throw_length_error() const; + _LIBCPP_NORETURN void __throw_out_of_range() const; +}; + +template <bool __b> +void +__vector_base_common<__b>::__throw_length_error() const +{ + _VSTD::__throw_length_error("vector"); +} + +template <bool __b> +void +__vector_base_common<__b>::__throw_out_of_range() const +{ + _VSTD::__throw_out_of_range("vector"); +} + +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>) + +template <class _Tp, class _Allocator> +class __vector_base + : protected __vector_base_common<true> +{ +public: + typedef _Allocator allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __alloc_traits::size_type size_type; +protected: + typedef _Tp value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::difference_type difference_type; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef pointer iterator; + typedef const_pointer const_iterator; + + pointer __begin_; + pointer __end_; + __compressed_pair<pointer, allocator_type> __end_cap_; + + _LIBCPP_INLINE_VISIBILITY + allocator_type& __alloc() _NOEXCEPT + {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY + const allocator_type& __alloc() const _NOEXCEPT + {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY + pointer& __end_cap() _NOEXCEPT + {return __end_cap_.first();} + _LIBCPP_INLINE_VISIBILITY + const pointer& __end_cap() const _NOEXCEPT + {return __end_cap_.first();} + + _LIBCPP_INLINE_VISIBILITY + __vector_base() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT; +#endif + ~__vector_base(); + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__destruct_at_end(__begin_);} + _LIBCPP_INLINE_VISIBILITY + size_type capacity() const _NOEXCEPT + {return static_cast<size_type>(__end_cap() - __begin_);} + + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __vector_base& __c) + {__copy_assign_alloc(__c, integral_constant<bool, + __alloc_traits::propagate_on_container_copy_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__vector_base& __c) + _NOEXCEPT_( + !__alloc_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<allocator_type>::value) + {__move_assign_alloc(__c, integral_constant<bool, + __alloc_traits::propagate_on_container_move_assignment::value>());} +private: + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __vector_base& __c, true_type) + { + if (__alloc() != __c.__alloc()) + { + clear(); + __alloc_traits::deallocate(__alloc(), __begin_, capacity()); + __begin_ = __end_ = __end_cap() = nullptr; + } + __alloc() = __c.__alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __vector_base&, false_type) + {} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__vector_base& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) + { + __alloc() = _VSTD::move(__c.__alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__vector_base&, false_type) + _NOEXCEPT + {} +}; + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT +{ + pointer __soon_to_be_end = __end_; + while (__new_last != __soon_to_be_end) + __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__soon_to_be_end)); + __end_ = __new_last; +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +__vector_base<_Tp, _Allocator>::__vector_base() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + : __begin_(nullptr), + __end_(nullptr), + __end_cap_(nullptr) +{ +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) + : __begin_(nullptr), + __end_(nullptr), + __end_cap_(nullptr, __a) +{ +} + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +__vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT + : __begin_(nullptr), + __end_(nullptr), + __end_cap_(nullptr, std::move(__a)) {} +#endif + +template <class _Tp, class _Allocator> +__vector_base<_Tp, _Allocator>::~__vector_base() +{ + if (__begin_ != nullptr) + { + clear(); + __alloc_traits::deallocate(__alloc(), __begin_, capacity()); + } +} + +template <class _Tp, class _Allocator /* = allocator<_Tp> */> +class _LIBCPP_TEMPLATE_VIS vector + : private __vector_base<_Tp, _Allocator> +{ +private: + typedef __vector_base<_Tp, _Allocator> __base; + typedef allocator<_Tp> __default_allocator_type; +public: + typedef vector __self; + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef typename __base::__alloc_traits __alloc_traits; + typedef typename __base::reference reference; + typedef typename __base::const_reference const_reference; + typedef typename __base::size_type size_type; + typedef typename __base::difference_type difference_type; + typedef typename __base::pointer pointer; + typedef typename __base::const_pointer const_pointer; + typedef __wrap_iter<pointer> iterator; + typedef __wrap_iter<const_pointer> const_iterator; + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + + static_assert((is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + + _LIBCPP_INLINE_VISIBILITY + vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) +#if _LIBCPP_STD_VER <= 14 + _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) +#else + _NOEXCEPT +#endif + : __base(__a) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + explicit vector(size_type __n); +#if _LIBCPP_STD_VER > 11 + explicit vector(size_type __n, const allocator_type& __a); +#endif + vector(size_type __n, const value_type& __x); + vector(size_type __n, const value_type& __x, const allocator_type& __a); + template <class _InputIterator> + vector(_InputIterator __first, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_InputIterator>::reference>::value, + _InputIterator>::type __last); + template <class _InputIterator> + vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); + template <class _ForwardIterator> + vector(_ForwardIterator __first, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_ForwardIterator>::reference>::value, + _ForwardIterator>::type __last); + template <class _ForwardIterator> + vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); + + _LIBCPP_INLINE_VISIBILITY + ~vector() + { + __annotate_delete(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__erase_c(this); +#endif + } + + vector(const vector& __x); + vector(const vector& __x, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + vector& operator=(const vector& __x); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + vector(initializer_list<value_type> __il); + + _LIBCPP_INLINE_VISIBILITY + vector(initializer_list<value_type> __il, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + vector(vector&& __x) +#if _LIBCPP_STD_VER > 14 + _NOEXCEPT; +#else + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); +#endif + + _LIBCPP_INLINE_VISIBILITY + vector(vector&& __x, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + vector& operator=(vector&& __x) + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); + + _LIBCPP_INLINE_VISIBILITY + vector& operator=(initializer_list<value_type> __il) + {assign(__il.begin(), __il.end()); return *this;} + +#endif // !_LIBCPP_CXX03_LANG + + template <class _InputIterator> + typename enable_if + < + __is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_InputIterator>::reference>::value, + void + >::type + assign(_InputIterator __first, _InputIterator __last); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_ForwardIterator>::reference>::value, + void + >::type + assign(_ForwardIterator __first, _ForwardIterator __last); + + void assign(size_type __n, const_reference __u); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list<value_type> __il) + {assign(__il.begin(), __il.end());} +#endif + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT + {return this->__alloc();} + + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT + {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT + {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT + {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT + {return rend();} + + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT + {return static_cast<size_type>(this->__end_ - this->__begin_);} + _LIBCPP_INLINE_VISIBILITY + size_type capacity() const _NOEXCEPT + {return __base::capacity();} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT + {return this->__begin_ == this->__end_;} + size_type max_size() const _NOEXCEPT; + void reserve(size_type __n); + void shrink_to_fit() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT; + reference at(size_type __n); + const_reference at(size_type __n) const; + + _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT + { + _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); + return *this->__begin_; + } + _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT + { + _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); + return *this->__begin_; + } + _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT + { + _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); + return *(this->__end_ - 1); + } + _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT + { + _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); + return *(this->__end_ - 1); + } + + _LIBCPP_INLINE_VISIBILITY + value_type* data() _NOEXCEPT + {return _VSTD::__to_raw_pointer(this->__begin_);} + _LIBCPP_INLINE_VISIBILITY + const value_type* data() const _NOEXCEPT + {return _VSTD::__to_raw_pointer(this->__begin_);} + +#ifdef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void __emplace_back(const value_type& __x) { push_back(__x); } +#else + template <class _Arg> + _LIBCPP_INLINE_VISIBILITY + void __emplace_back(_Arg&& __arg) { + emplace_back(_VSTD::forward<_Arg>(__arg)); + } +#endif + + _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_STD_VER > 14 + reference emplace_back(_Args&&... __args); +#else + void emplace_back(_Args&&... __args); +#endif +#endif // !_LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + void pop_back(); + + iterator insert(const_iterator __position, const_reference __x); + +#ifndef _LIBCPP_CXX03_LANG + iterator insert(const_iterator __position, value_type&& __x); + template <class... _Args> + iterator emplace(const_iterator __position, _Args&&... __args); +#endif // !_LIBCPP_CXX03_LANG + + iterator insert(const_iterator __position, size_type __n, const_reference __x); + template <class _InputIterator> + typename enable_if + < + __is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_InputIterator>::reference>::value, + iterator + >::type + insert(const_iterator __position, _InputIterator __first, _InputIterator __last); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_ForwardIterator>::reference>::value, + iterator + >::type + insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __position, initializer_list<value_type> __il) + {return insert(__position, __il.begin(), __il.end());} +#endif + + _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); + iterator erase(const_iterator __first, const_iterator __last); + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT + { + size_type __old_size = size(); + __base::clear(); + __annotate_shrink(__old_size); + __invalidate_all_iterators(); + } + + void resize(size_type __sz); + void resize(size_type __sz, const_reference __x); + + void swap(vector&) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT; +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value); +#endif + + bool __invariants() const; + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const; + bool __decrementable(const const_iterator* __i) const; + bool __addable(const const_iterator* __i, ptrdiff_t __n) const; + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +private: + _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); + _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last); + void __vallocate(size_type __n); + void __vdeallocate() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; + void __construct_at_end(size_type __n); + _LIBCPP_INLINE_VISIBILITY + void __construct_at_end(size_type __n, const_reference __x); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + void + >::type + __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n); + void __append(size_type __n); + void __append(size_type __n, const_reference __x); + _LIBCPP_INLINE_VISIBILITY + iterator __make_iter(pointer __p) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; + void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); + pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); + void __move_range(pointer __from_s, pointer __from_e, pointer __to); + void __move_assign(vector& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); + void __move_assign(vector& __c, false_type) + _NOEXCEPT_(__alloc_traits::is_always_equal::value); + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last) _NOEXCEPT + { + __invalidate_iterators_past(__new_last); + size_type __old_size = size(); + __base::__destruct_at_end(__new_last); + __annotate_shrink(__old_size); + } + +#ifndef _LIBCPP_CXX03_LANG + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + inline void __push_back_slow_path(_Up&& __x); + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + inline void __emplace_back_slow_path(_Args&&... __args); +#else + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + inline void __push_back_slow_path(_Up& __x); +#endif + + // The following functions are no-ops outside of AddressSanitizer mode. + // We call annotatations only for the default Allocator because other allocators + // may not meet the AddressSanitizer alignment constraints. + // See the documentation for __sanitizer_annotate_contiguous_container for more details. +#ifndef _LIBCPP_HAS_NO_ASAN + void __annotate_contiguous_container(const void *__beg, const void *__end, + const void *__old_mid, + const void *__new_mid) const + { + + if (__beg && is_same<allocator_type, __default_allocator_type>::value) + __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); + } +#else + _LIBCPP_INLINE_VISIBILITY + void __annotate_contiguous_container(const void*, const void*, const void*, + const void*) const {} +#endif + _LIBCPP_INLINE_VISIBILITY + void __annotate_new(size_type __current_size) const { + __annotate_contiguous_container(data(), data() + capacity(), + data() + capacity(), data() + __current_size); + } + + _LIBCPP_INLINE_VISIBILITY + void __annotate_delete() const { + __annotate_contiguous_container(data(), data() + capacity(), + data() + size(), data() + capacity()); + } + + _LIBCPP_INLINE_VISIBILITY + void __annotate_increase(size_type __n) const + { + __annotate_contiguous_container(data(), data() + capacity(), + data() + size(), data() + size() + __n); + } + + _LIBCPP_INLINE_VISIBILITY + void __annotate_shrink(size_type __old_size) const + { + __annotate_contiguous_container(data(), data() + capacity(), + data() + __old_size, data() + size()); + } +#ifndef _LIBCPP_HAS_NO_ASAN + // The annotation for size increase should happen before the actual increase, + // but if an exception is thrown after that the annotation has to be undone. + struct __RAII_IncreaseAnnotator { + __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1) + : __commit(false), __v(__v), __old_size(__v.size() + __n) { + __v.__annotate_increase(__n); + } + void __done() { __commit = true; } + ~__RAII_IncreaseAnnotator() { + if (__commit) return; + __v.__annotate_shrink(__old_size); + } + bool __commit; + const vector &__v; + size_type __old_size; + }; +#else + struct __RAII_IncreaseAnnotator { + _LIBCPP_INLINE_VISIBILITY + __RAII_IncreaseAnnotator(const vector &, size_type = 1) {} + _LIBCPP_INLINE_VISIBILITY void __done() {} + }; +#endif + +}; + +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +vector(_InputIterator, _InputIterator) + -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>; + +template<class _InputIterator, + class _Alloc, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +vector(_InputIterator, _InputIterator, _Alloc) + -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>; +#endif + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) +{ + __annotate_delete(); + __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_); + _VSTD::swap(this->__begin_, __v.__begin_); + _VSTD::swap(this->__end_, __v.__end_); + _VSTD::swap(this->__end_cap(), __v.__end_cap()); + __v.__first_ = __v.__begin_; + __annotate_new(size()); + __invalidate_all_iterators(); +} + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::pointer +vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) +{ + __annotate_delete(); + pointer __r = __v.__begin_; + __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_); + __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_); + _VSTD::swap(this->__begin_, __v.__begin_); + _VSTD::swap(this->__end_, __v.__end_); + _VSTD::swap(this->__end_cap(), __v.__end_cap()); + __v.__first_ = __v.__begin_; + __annotate_new(size()); + __invalidate_all_iterators(); + return __r; +} + +// Allocate space for __n objects +// throws length_error if __n > max_size() +// throws (probably bad_alloc) if memory run out +// Precondition: __begin_ == __end_ == __end_cap() == 0 +// Precondition: __n > 0 +// Postcondition: capacity() == __n +// Postcondition: size() == 0 +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__vallocate(size_type __n) +{ + if (__n > max_size()) + this->__throw_length_error(); + this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); + this->__end_cap() = this->__begin_ + __n; + __annotate_new(0); +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT +{ + if (this->__begin_ != nullptr) + { + clear(); + __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); + this->__begin_ = this->__end_ = this->__end_cap() = nullptr; + } +} + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::size_type +vector<_Tp, _Allocator>::max_size() const _NOEXCEPT +{ + return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), + numeric_limits<difference_type>::max()); +} + +// Precondition: __new_size > capacity() +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::size_type +vector<_Tp, _Allocator>::__recommend(size_type __new_size) const +{ + const size_type __ms = max_size(); + if (__new_size > __ms) + this->__throw_length_error(); + const size_type __cap = capacity(); + if (__cap >= __ms / 2) + return __ms; + return _VSTD::max<size_type>(2*__cap, __new_size); +} + +// Default constructs __n objects starting at __end_ +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == size() + __n +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__construct_at_end(size_type __n) +{ + allocator_type& __a = this->__alloc(); + do + { + __RAII_IncreaseAnnotator __annotator(*this); + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); + ++this->__end_; + --__n; + __annotator.__done(); + } while (__n > 0); +} + +// Copy constructs __n objects starting at __end_ from __x +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == old size() + __n +// Postcondition: [i] == __x for all i in [size() - __n, __n) +template <class _Tp, class _Allocator> +inline +void +vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) +{ + allocator_type& __a = this->__alloc(); + do + { + __RAII_IncreaseAnnotator __annotator(*this); + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); + ++this->__end_; + --__n; + __annotator.__done(); + } while (__n > 0); +} + +template <class _Tp, class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value, + void +>::type +vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) +{ + allocator_type& __a = this->__alloc(); + __RAII_IncreaseAnnotator __annotator(*this, __n); + __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_); + __annotator.__done(); +} + +// Default constructs __n objects starting at __end_ +// throws if construction throws +// Postcondition: size() == size() + __n +// Exception safety: strong. +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__append(size_type __n) +{ + if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) + this->__construct_at_end(__n); + else + { + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); + __v.__construct_at_end(__n); + __swap_out_circular_buffer(__v); + } +} + +// Default constructs __n objects starting at __end_ +// throws if construction throws +// Postcondition: size() == size() + __n +// Exception safety: strong. +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) +{ + if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) + this->__construct_at_end(__n, __x); + else + { + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); + __v.__construct_at_end(__n, __x); + __swap_out_circular_buffer(__v); + } +} + +template <class _Tp, class _Allocator> +vector<_Tp, _Allocator>::vector(size_type __n) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__n); + } +} + +#if _LIBCPP_STD_VER > 11 +template <class _Tp, class _Allocator> +vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) + : __base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__n); + } +} +#endif + +template <class _Tp, class _Allocator> +vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__n, __x); + } +} + +template <class _Tp, class _Allocator> +vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) + : __base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__n, __x); + } +} + +template <class _Tp, class _Allocator> +template <class _InputIterator> +vector<_Tp, _Allocator>::vector(_InputIterator __first, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_InputIterator>::reference>::value, + _InputIterator>::type __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __first != __last; ++__first) + __emplace_back(*__first); +} + +template <class _Tp, class _Allocator> +template <class _InputIterator> +vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_InputIterator>::reference>::value>::type*) + : __base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __first != __last; ++__first) + __emplace_back(*__first); +} + +template <class _Tp, class _Allocator> +template <class _ForwardIterator> +vector<_Tp, _Allocator>::vector(_ForwardIterator __first, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_ForwardIterator>::reference>::value, + _ForwardIterator>::type __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__first, __last, __n); + } +} + +template <class _Tp, class _Allocator> +template <class _ForwardIterator> +vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value && + is_constructible< + value_type, + typename iterator_traits<_ForwardIterator>::reference>::value>::type*) + : __base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__first, __last, __n); + } +} + +template <class _Tp, class _Allocator> +vector<_Tp, _Allocator>::vector(const vector& __x) + : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc())) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + size_type __n = __x.size(); + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__x.__begin_, __x.__end_, __n); + } +} + +template <class _Tp, class _Allocator> +vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a) + : __base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + size_type __n = __x.size(); + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__x.__begin_, __x.__end_, __n); + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +vector<_Tp, _Allocator>::vector(vector&& __x) +#if _LIBCPP_STD_VER > 14 + _NOEXCEPT +#else + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) +#endif + : __base(_VSTD::move(__x.__alloc())) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + __get_db()->swap(this, &__x); +#endif + this->__begin_ = __x.__begin_; + this->__end_ = __x.__end_; + this->__end_cap() = __x.__end_cap(); + __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a) + : __base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__a == __x.__alloc()) + { + this->__begin_ = __x.__begin_; + this->__end_ = __x.__end_; + this->__end_cap() = __x.__end_cap(); + __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->swap(this, &__x); +#endif + } + else + { + typedef move_iterator<iterator> _Ip; + assign(_Ip(__x.begin()), _Ip(__x.end())); + } +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__il.size() > 0) + { + __vallocate(__il.size()); + __construct_at_end(__il.begin(), __il.end(), __il.size()); + } +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) + : __base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__il.size() > 0) + { + __vallocate(__il.size()); + __construct_at_end(__il.begin(), __il.end(), __il.size()); + } +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +vector<_Tp, _Allocator>& +vector<_Tp, _Allocator>::operator=(vector&& __x) + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) +{ + __move_assign(__x, integral_constant<bool, + __alloc_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) + _NOEXCEPT_(__alloc_traits::is_always_equal::value) +{ + if (__base::__alloc() != __c.__alloc()) + { + typedef move_iterator<iterator> _Ip; + assign(_Ip(__c.begin()), _Ip(__c.end())); + } + else + __move_assign(__c, true_type()); +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) +{ + __vdeallocate(); + __base::__move_assign_alloc(__c); // this can throw + this->__begin_ = __c.__begin_; + this->__end_ = __c.__end_; + this->__end_cap() = __c.__end_cap(); + __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->swap(this, &__c); +#endif +} + +#endif // !_LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +vector<_Tp, _Allocator>& +vector<_Tp, _Allocator>::operator=(const vector& __x) +{ + if (this != &__x) + { + __base::__copy_assign_alloc(__x); + assign(__x.__begin_, __x.__end_); + } + return *this; +} + +template <class _Tp, class _Allocator> +template <class _InputIterator> +typename enable_if +< + __is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value && + is_constructible< + _Tp, + typename iterator_traits<_InputIterator>::reference>::value, + void +>::type +vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) +{ + clear(); + for (; __first != __last; ++__first) + __emplace_back(*__first); +} + +template <class _Tp, class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value && + is_constructible< + _Tp, + typename iterator_traits<_ForwardIterator>::reference>::value, + void +>::type +vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) +{ + size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last)); + if (__new_size <= capacity()) + { + _ForwardIterator __mid = __last; + bool __growing = false; + if (__new_size > size()) + { + __growing = true; + __mid = __first; + _VSTD::advance(__mid, size()); + } + pointer __m = _VSTD::copy(__first, __mid, this->__begin_); + if (__growing) + __construct_at_end(__mid, __last, __new_size - size()); + else + this->__destruct_at_end(__m); + } + else + { + __vdeallocate(); + __vallocate(__recommend(__new_size)); + __construct_at_end(__first, __last, __new_size); + } + __invalidate_all_iterators(); +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) +{ + if (__n <= capacity()) + { + size_type __s = size(); + _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); + if (__n > __s) + __construct_at_end(__n - __s, __u); + else + this->__destruct_at_end(this->__begin_ + __n); + } + else + { + __vdeallocate(); + __vallocate(__recommend(static_cast<size_type>(__n))); + __construct_at_end(__n, __u); + } + __invalidate_all_iterators(); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::iterator +vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(this, __p); +#else + return iterator(__p); +#endif +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::const_iterator +vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(this, __p); +#else + return const_iterator(__p); +#endif +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::iterator +vector<_Tp, _Allocator>::begin() _NOEXCEPT +{ + return __make_iter(this->__begin_); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::const_iterator +vector<_Tp, _Allocator>::begin() const _NOEXCEPT +{ + return __make_iter(this->__begin_); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::iterator +vector<_Tp, _Allocator>::end() _NOEXCEPT +{ + return __make_iter(this->__end_); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::const_iterator +vector<_Tp, _Allocator>::end() const _NOEXCEPT +{ + return __make_iter(this->__end_); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::reference +vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT +{ + _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); + return this->__begin_[__n]; +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::const_reference +vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT +{ + _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); + return this->__begin_[__n]; +} + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::reference +vector<_Tp, _Allocator>::at(size_type __n) +{ + if (__n >= size()) + this->__throw_out_of_range(); + return this->__begin_[__n]; +} + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::const_reference +vector<_Tp, _Allocator>::at(size_type __n) const +{ + if (__n >= size()) + this->__throw_out_of_range(); + return this->__begin_[__n]; +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::reserve(size_type __n) +{ + if (__n > capacity()) + { + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); + __swap_out_circular_buffer(__v); + } +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT +{ + if (capacity() > size()) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); + __swap_out_circular_buffer(__v); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Tp, class _Allocator> +template <class _Up> +void +#ifndef _LIBCPP_CXX03_LANG +vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) +#else +vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x) +#endif +{ + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); + // __v.push_back(_VSTD::forward<_Up>(__x)); + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x)); + __v.__end_++; + __swap_out_circular_buffer(__v); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +vector<_Tp, _Allocator>::push_back(const_reference __x) +{ + if (this->__end_ != this->__end_cap()) + { + __RAII_IncreaseAnnotator __annotator(*this); + __alloc_traits::construct(this->__alloc(), + _VSTD::__to_raw_pointer(this->__end_), __x); + __annotator.__done(); + ++this->__end_; + } + else + __push_back_slow_path(__x); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +vector<_Tp, _Allocator>::push_back(value_type&& __x) +{ + if (this->__end_ < this->__end_cap()) + { + __RAII_IncreaseAnnotator __annotator(*this); + __alloc_traits::construct(this->__alloc(), + _VSTD::__to_raw_pointer(this->__end_), + _VSTD::move(__x)); + __annotator.__done(); + ++this->__end_; + } + else + __push_back_slow_path(_VSTD::move(__x)); +} + +template <class _Tp, class _Allocator> +template <class... _Args> +void +vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) +{ + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); +// __v.emplace_back(_VSTD::forward<_Args>(__args)...); + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...); + __v.__end_++; + __swap_out_circular_buffer(__v); +} + +template <class _Tp, class _Allocator> +template <class... _Args> +inline +#if _LIBCPP_STD_VER > 14 +typename vector<_Tp, _Allocator>::reference +#else +void +#endif +vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) +{ + if (this->__end_ < this->__end_cap()) + { + __RAII_IncreaseAnnotator __annotator(*this); + __alloc_traits::construct(this->__alloc(), + _VSTD::__to_raw_pointer(this->__end_), + _VSTD::forward<_Args>(__args)...); + __annotator.__done(); + ++this->__end_; + } + else + __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); +#if _LIBCPP_STD_VER > 14 + return this->back(); +#endif +} + +#endif // !_LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +inline +void +vector<_Tp, _Allocator>::pop_back() +{ + _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector"); + this->__destruct_at_end(this->__end_ - 1); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<_Tp, _Allocator>::iterator +vector<_Tp, _Allocator>::erase(const_iterator __position) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, + "vector::erase(iterator) called with an iterator not" + " referring to this vector"); +#endif + _LIBCPP_ASSERT(__position != end(), + "vector::erase(iterator) called with a non-dereferenceable iterator"); + difference_type __ps = __position - cbegin(); + pointer __p = this->__begin_ + __ps; + this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); + this->__invalidate_iterators_past(__p-1); + iterator __r = __make_iter(__p); + return __r; +} + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::iterator +vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, + "vector::erase(iterator, iterator) called with an iterator not" + " referring to this vector"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, + "vector::erase(iterator, iterator) called with an iterator not" + " referring to this vector"); +#endif + _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); + pointer __p = this->__begin_ + (__first - begin()); + if (__first != __last) { + this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); + this->__invalidate_iterators_past(__p - 1); + } + iterator __r = __make_iter(__p); + return __r; +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) +{ + pointer __old_last = this->__end_; + difference_type __n = __old_last - __to; + for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_) + __alloc_traits::construct(this->__alloc(), + _VSTD::__to_raw_pointer(this->__end_), + _VSTD::move(*__i)); + _VSTD::move_backward(__from_s, __from_s + __n, __old_last); +} + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::iterator +vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, + "vector::insert(iterator, x) called with an iterator not" + " referring to this vector"); +#endif + pointer __p = this->__begin_ + (__position - begin()); + if (this->__end_ < this->__end_cap()) + { + __RAII_IncreaseAnnotator __annotator(*this); + if (__p == this->__end_) + { + __alloc_traits::construct(this->__alloc(), + _VSTD::__to_raw_pointer(this->__end_), __x); + ++this->__end_; + } + else + { + __move_range(__p, this->__end_, __p + 1); + const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); + if (__p <= __xr && __xr < this->__end_) + ++__xr; + *__p = *__xr; + } + __annotator.__done(); + } + else + { + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); + __v.push_back(__x); + __p = __swap_out_circular_buffer(__v, __p); + } + return __make_iter(__p); +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::iterator +vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, + "vector::insert(iterator, x) called with an iterator not" + " referring to this vector"); +#endif + pointer __p = this->__begin_ + (__position - begin()); + if (this->__end_ < this->__end_cap()) + { + __RAII_IncreaseAnnotator __annotator(*this); + if (__p == this->__end_) + { + __alloc_traits::construct(this->__alloc(), + _VSTD::__to_raw_pointer(this->__end_), + _VSTD::move(__x)); + ++this->__end_; + } + else + { + __move_range(__p, this->__end_, __p + 1); + *__p = _VSTD::move(__x); + } + __annotator.__done(); + } + else + { + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); + __v.push_back(_VSTD::move(__x)); + __p = __swap_out_circular_buffer(__v, __p); + } + return __make_iter(__p); +} + +template <class _Tp, class _Allocator> +template <class... _Args> +typename vector<_Tp, _Allocator>::iterator +vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, + "vector::emplace(iterator, x) called with an iterator not" + " referring to this vector"); +#endif + pointer __p = this->__begin_ + (__position - begin()); + if (this->__end_ < this->__end_cap()) + { + __RAII_IncreaseAnnotator __annotator(*this); + if (__p == this->__end_) + { + __alloc_traits::construct(this->__alloc(), + _VSTD::__to_raw_pointer(this->__end_), + _VSTD::forward<_Args>(__args)...); + ++this->__end_; + } + else + { + __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); + __move_range(__p, this->__end_, __p + 1); + *__p = _VSTD::move(__tmp.get()); + } + __annotator.__done(); + } + else + { + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); + __v.emplace_back(_VSTD::forward<_Args>(__args)...); + __p = __swap_out_circular_buffer(__v, __p); + } + return __make_iter(__p); +} + +#endif // !_LIBCPP_CXX03_LANG + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::iterator +vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, + "vector::insert(iterator, n, x) called with an iterator not" + " referring to this vector"); +#endif + pointer __p = this->__begin_ + (__position - begin()); + if (__n > 0) + { + if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_)) + { + size_type __old_n = __n; + pointer __old_last = this->__end_; + if (__n > static_cast<size_type>(this->__end_ - __p)) + { + size_type __cx = __n - (this->__end_ - __p); + __construct_at_end(__cx, __x); + __n -= __cx; + } + if (__n > 0) + { + __RAII_IncreaseAnnotator __annotator(*this, __n); + __move_range(__p, __old_last, __p + __old_n); + __annotator.__done(); + const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); + if (__p <= __xr && __xr < this->__end_) + __xr += __old_n; + _VSTD::fill_n(__p, __n, *__xr); + } + } + else + { + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); + __v.__construct_at_end(__n, __x); + __p = __swap_out_circular_buffer(__v, __p); + } + } + return __make_iter(__p); +} + +template <class _Tp, class _Allocator> +template <class _InputIterator> +typename enable_if +< + __is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value && + is_constructible< + _Tp, + typename iterator_traits<_InputIterator>::reference>::value, + typename vector<_Tp, _Allocator>::iterator +>::type +vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, + "vector::insert(iterator, range) called with an iterator not" + " referring to this vector"); +#endif + difference_type __off = __position - begin(); + pointer __p = this->__begin_ + __off; + allocator_type& __a = this->__alloc(); + pointer __old_last = this->__end_; + for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) + { + __RAII_IncreaseAnnotator __annotator(*this); + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), + *__first); + ++this->__end_; + __annotator.__done(); + } + __split_buffer<value_type, allocator_type&> __v(__a); + if (__first != __last) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __v.__construct_at_end(__first, __last); + difference_type __old_size = __old_last - this->__begin_; + difference_type __old_p = __p - this->__begin_; + reserve(__recommend(size() + __v.size())); + __p = this->__begin_ + __old_p; + __old_last = this->__begin_ + __old_size; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + erase(__make_iter(__old_last), end()); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + __p = _VSTD::rotate(__p, __old_last, this->__end_); + insert(__make_iter(__p), make_move_iterator(__v.begin()), + make_move_iterator(__v.end())); + return begin() + __off; +} + +template <class _Tp, class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value && + is_constructible< + _Tp, + typename iterator_traits<_ForwardIterator>::reference>::value, + typename vector<_Tp, _Allocator>::iterator +>::type +vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, + "vector::insert(iterator, range) called with an iterator not" + " referring to this vector"); +#endif + pointer __p = this->__begin_ + (__position - begin()); + difference_type __n = _VSTD::distance(__first, __last); + if (__n > 0) + { + if (__n <= this->__end_cap() - this->__end_) + { + size_type __old_n = __n; + pointer __old_last = this->__end_; + _ForwardIterator __m = __last; + difference_type __dx = this->__end_ - __p; + if (__n > __dx) + { + __m = __first; + difference_type __diff = this->__end_ - __p; + _VSTD::advance(__m, __diff); + __construct_at_end(__m, __last, __n - __diff); + __n = __dx; + } + if (__n > 0) + { + __RAII_IncreaseAnnotator __annotator(*this, __n); + __move_range(__p, __old_last, __p + __old_n); + __annotator.__done(); + _VSTD::copy(__first, __m, __p); + } + } + else + { + allocator_type& __a = this->__alloc(); + __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); + __v.__construct_at_end(__first, __last); + __p = __swap_out_circular_buffer(__v, __p); + } + } + return __make_iter(__p); +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::resize(size_type __sz) +{ + size_type __cs = size(); + if (__cs < __sz) + this->__append(__sz - __cs); + else if (__cs > __sz) + this->__destruct_at_end(this->__begin_ + __sz); +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) +{ + size_type __cs = size(); + if (__cs < __sz) + this->__append(__sz - __cs, __x); + else if (__cs > __sz) + this->__destruct_at_end(this->__begin_ + __sz); +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::swap(vector& __x) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value) +#endif +{ + _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || + this->__alloc() == __x.__alloc(), + "vector::swap: Either propagate_on_container_swap must be true" + " or the allocators must compare equal"); + _VSTD::swap(this->__begin_, __x.__begin_); + _VSTD::swap(this->__end_, __x.__end_); + _VSTD::swap(this->__end_cap(), __x.__end_cap()); + __swap_allocator(this->__alloc(), __x.__alloc(), + integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->swap(this, &__x); +#endif // _LIBCPP_DEBUG_LEVEL >= 2 +} + +template <class _Tp, class _Allocator> +bool +vector<_Tp, _Allocator>::__invariants() const +{ + if (this->__begin_ == nullptr) + { + if (this->__end_ != nullptr || this->__end_cap() != nullptr) + return false; + } + else + { + if (this->__begin_ > this->__end_) + return false; + if (this->__begin_ == this->__end_cap()) + return false; + if (this->__end_ > this->__end_cap()) + return false; + } + return true; +} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + +template <class _Tp, class _Allocator> +bool +vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const +{ + return this->__begin_ <= __i->base() && __i->base() < this->__end_; +} + +template <class _Tp, class _Allocator> +bool +vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const +{ + return this->__begin_ < __i->base() && __i->base() <= this->__end_; +} + +template <class _Tp, class _Allocator> +bool +vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const +{ + const_pointer __p = __i->base() + __n; + return this->__begin_ <= __p && __p <= this->__end_; +} + +template <class _Tp, class _Allocator> +bool +vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const +{ + const_pointer __p = __i->base() + __n; + return this->__begin_ <= __p && __p < this->__end_; +} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +vector<_Tp, _Allocator>::__invalidate_all_iterators() +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif // _LIBCPP_DEBUG_LEVEL >= 2 +} + + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) { + --__p; + const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); + if (__i->base() > __new_last) { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#else + ((void)__new_last); +#endif +} + +// vector<bool> + +template <class _Allocator> class vector<bool, _Allocator>; + +template <class _Allocator> struct hash<vector<bool, _Allocator> >; + +template <class _Allocator> +struct __has_storage_type<vector<bool, _Allocator> > +{ + static const bool value = true; +}; + +template <class _Allocator> +class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> + : private __vector_base_common<true> +{ +public: + typedef vector __self; + typedef bool value_type; + typedef _Allocator allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef size_type __storage_type; + typedef __bit_iterator<vector, false> pointer; + typedef __bit_iterator<vector, true> const_pointer; + typedef pointer iterator; + typedef const_pointer const_iterator; + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + +private: + typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; + typedef allocator_traits<__storage_allocator> __storage_traits; + typedef typename __storage_traits::pointer __storage_pointer; + typedef typename __storage_traits::const_pointer __const_storage_pointer; + + __storage_pointer __begin_; + size_type __size_; + __compressed_pair<size_type, __storage_allocator> __cap_alloc_; +public: + typedef __bit_reference<vector> reference; + typedef __bit_const_reference<vector> const_reference; +private: + _LIBCPP_INLINE_VISIBILITY + size_type& __cap() _NOEXCEPT + {return __cap_alloc_.first();} + _LIBCPP_INLINE_VISIBILITY + const size_type& __cap() const _NOEXCEPT + {return __cap_alloc_.first();} + _LIBCPP_INLINE_VISIBILITY + __storage_allocator& __alloc() _NOEXCEPT + {return __cap_alloc_.second();} + _LIBCPP_INLINE_VISIBILITY + const __storage_allocator& __alloc() const _NOEXCEPT + {return __cap_alloc_.second();} + + static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); + + _LIBCPP_INLINE_VISIBILITY + static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT + {return __n * __bits_per_word;} + _LIBCPP_INLINE_VISIBILITY + static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT + {return (__n - 1) / __bits_per_word + 1;} + +public: + _LIBCPP_INLINE_VISIBILITY + vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + + _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) +#if _LIBCPP_STD_VER <= 14 + _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); +#else + _NOEXCEPT; +#endif + ~vector(); + explicit vector(size_type __n); +#if _LIBCPP_STD_VER > 11 + explicit vector(size_type __n, const allocator_type& __a); +#endif + vector(size_type __n, const value_type& __v); + vector(size_type __n, const value_type& __v, const allocator_type& __a); + template <class _InputIterator> + vector(_InputIterator __first, _InputIterator __last, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value>::type* = 0); + template <class _InputIterator> + vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value>::type* = 0); + template <class _ForwardIterator> + vector(_ForwardIterator __first, _ForwardIterator __last, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); + template <class _ForwardIterator> + vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); + + vector(const vector& __v); + vector(const vector& __v, const allocator_type& __a); + vector& operator=(const vector& __v); + +#ifndef _LIBCPP_CXX03_LANG + vector(initializer_list<value_type> __il); + vector(initializer_list<value_type> __il, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + vector(vector&& __v) +#if _LIBCPP_STD_VER > 14 + _NOEXCEPT; +#else + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); +#endif + vector(vector&& __v, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + vector& operator=(vector&& __v) + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); + + _LIBCPP_INLINE_VISIBILITY + vector& operator=(initializer_list<value_type> __il) + {assign(__il.begin(), __il.end()); return *this;} + +#endif // !_LIBCPP_CXX03_LANG + + template <class _InputIterator> + typename enable_if + < + __is_input_iterator<_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value, + void + >::type + assign(_InputIterator __first, _InputIterator __last); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + void + >::type + assign(_ForwardIterator __first, _ForwardIterator __last); + + void assign(size_type __n, const value_type& __x); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list<value_type> __il) + {assign(__il.begin(), __il.end());} +#endif + + _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT + {return allocator_type(this->__alloc());} + + size_type max_size() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type capacity() const _NOEXCEPT + {return __internal_cap_to_external(__cap());} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT + {return __size_;} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT + {return __size_ == 0;} + void reserve(size_type __n); + void shrink_to_fit() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT + {return __make_iter(0);} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT + {return __make_iter(0);} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT + {return __make_iter(__size_);} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT + {return __make_iter(__size_);} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT + {return __make_iter(0);} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT + {return __make_iter(__size_);} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT + {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT + {return rend();} + + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} + reference at(size_type __n); + const_reference at(size_type __n) const; + + _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} + _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} + _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} + _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} + + void push_back(const value_type& __x); +#if _LIBCPP_STD_VER > 11 + template <class... _Args> +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args) +#else + _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) +#endif + { + push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); +#if _LIBCPP_STD_VER > 14 + return this->back(); +#endif + } +#endif + + _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} + +#if _LIBCPP_STD_VER > 11 + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args) + { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); } +#endif + + iterator insert(const_iterator __position, const value_type& __x); + iterator insert(const_iterator __position, size_type __n, const value_type& __x); + iterator insert(const_iterator __position, size_type __n, const_reference __x); + template <class _InputIterator> + typename enable_if + < + __is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value, + iterator + >::type + insert(const_iterator __position, _InputIterator __first, _InputIterator __last); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + iterator + >::type + insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __position, initializer_list<value_type> __il) + {return insert(__position, __il.begin(), __il.end());} +#endif + + _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); + iterator erase(const_iterator __first, const_iterator __last); + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__size_ = 0;} + + void swap(vector&) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT; +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value); +#endif + static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } + + void resize(size_type __sz, value_type __x = false); + void flip() _NOEXCEPT; + + bool __invariants() const; + +private: + _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); + void __vallocate(size_type __n); + void __vdeallocate() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static size_type __align_it(size_type __new_size) _NOEXCEPT + {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);} + _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; + _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + void + >::type + __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); + void __append(size_type __n, const_reference __x); + _LIBCPP_INLINE_VISIBILITY + reference __make_ref(size_type __pos) _NOEXCEPT + {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY + const_reference __make_ref(size_type __pos) const _NOEXCEPT + {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY + iterator __make_iter(size_type __pos) _NOEXCEPT + {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} + _LIBCPP_INLINE_VISIBILITY + const_iterator __make_iter(size_type __pos) const _NOEXCEPT + {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} + _LIBCPP_INLINE_VISIBILITY + iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT + {return begin() + (__p - cbegin());} + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const vector& __v) + {__copy_assign_alloc(__v, integral_constant<bool, + __storage_traits::propagate_on_container_copy_assignment::value>());} + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const vector& __c, true_type) + { + if (__alloc() != __c.__alloc()) + __vdeallocate(); + __alloc() = __c.__alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const vector&, false_type) + {} + + void __move_assign(vector& __c, false_type); + void __move_assign(vector& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(vector& __c) + _NOEXCEPT_( + !__storage_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<allocator_type>::value) + {__move_assign_alloc(__c, integral_constant<bool, + __storage_traits::propagate_on_container_move_assignment::value>());} + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(vector& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) + { + __alloc() = _VSTD::move(__c.__alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(vector&, false_type) + _NOEXCEPT + {} + + size_t __hash_code() const _NOEXCEPT; + + friend class __bit_reference<vector>; + friend class __bit_const_reference<vector>; + friend class __bit_iterator<vector, false>; + friend class __bit_iterator<vector, true>; + friend struct __bit_array<vector>; + friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; +}; + +template <class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +vector<bool, _Allocator>::__invalidate_all_iterators() +{ +} + +// Allocate space for __n objects +// throws length_error if __n > max_size() +// throws (probably bad_alloc) if memory run out +// Precondition: __begin_ == __end_ == __cap() == 0 +// Precondition: __n > 0 +// Postcondition: capacity() == __n +// Postcondition: size() == 0 +template <class _Allocator> +void +vector<bool, _Allocator>::__vallocate(size_type __n) +{ + if (__n > max_size()) + this->__throw_length_error(); + __n = __external_cap_to_internal(__n); + this->__begin_ = __storage_traits::allocate(this->__alloc(), __n); + this->__size_ = 0; + this->__cap() = __n; +} + +template <class _Allocator> +void +vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT +{ + if (this->__begin_ != nullptr) + { + __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); + __invalidate_all_iterators(); + this->__begin_ = nullptr; + this->__size_ = this->__cap() = 0; + } +} + +template <class _Allocator> +typename vector<bool, _Allocator>::size_type +vector<bool, _Allocator>::max_size() const _NOEXCEPT +{ + size_type __amax = __storage_traits::max_size(__alloc()); + size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always + if (__nmax / __bits_per_word <= __amax) + return __nmax; + return __internal_cap_to_external(__amax); +} + +// Precondition: __new_size > capacity() +template <class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<bool, _Allocator>::size_type +vector<bool, _Allocator>::__recommend(size_type __new_size) const +{ + const size_type __ms = max_size(); + if (__new_size > __ms) + this->__throw_length_error(); + const size_type __cap = capacity(); + if (__cap >= __ms / 2) + return __ms; + return _VSTD::max(2*__cap, __align_it(__new_size)); +} + +// Default constructs __n objects starting at __end_ +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == size() + __n +template <class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) +{ + size_type __old_size = this->__size_; + this->__size_ += __n; + if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) + { + if (this->__size_ <= __bits_per_word) + this->__begin_[0] = __storage_type(0); + else + this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); + } + _VSTD::fill_n(__make_iter(__old_size), __n, __x); +} + +template <class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value, + void +>::type +vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) +{ + size_type __old_size = this->__size_; + this->__size_ += _VSTD::distance(__first, __last); + if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) + { + if (this->__size_ <= __bits_per_word) + this->__begin_[0] = __storage_type(0); + else + this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); + } + _VSTD::copy(__first, __last, __make_iter(__old_size)); +} + +template <class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +vector<bool, _Allocator>::vector() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0) +{ +} + +template <class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +vector<bool, _Allocator>::vector(const allocator_type& __a) +#if _LIBCPP_STD_VER <= 14 + _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) +#else + _NOEXCEPT +#endif + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, static_cast<__storage_allocator>(__a)) +{ +} + +template <class _Allocator> +vector<bool, _Allocator>::vector(size_type __n) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0) +{ + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__n, false); + } +} + +#if _LIBCPP_STD_VER > 11 +template <class _Allocator> +vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, static_cast<__storage_allocator>(__a)) +{ + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__n, false); + } +} +#endif + +template <class _Allocator> +vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0) +{ + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__n, __x); + } +} + +template <class _Allocator> +vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, static_cast<__storage_allocator>(__a)) +{ + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__n, __x); + } +} + +template <class _Allocator> +template <class _InputIterator> +vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value>::type*) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __first != __last; ++__first) + push_back(*__first); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + if (__begin_ != nullptr) + __storage_traits::deallocate(__alloc(), __begin_, __cap()); + __invalidate_all_iterators(); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template <class _Allocator> +template <class _InputIterator> +vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value>::type*) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, static_cast<__storage_allocator>(__a)) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __first != __last; ++__first) + push_back(*__first); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + if (__begin_ != nullptr) + __storage_traits::deallocate(__alloc(), __begin_, __cap()); + __invalidate_all_iterators(); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template <class _Allocator> +template <class _ForwardIterator> +vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0) +{ + size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__first, __last); + } +} + +template <class _Allocator> +template <class _ForwardIterator> +vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, static_cast<__storage_allocator>(__a)) +{ + size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__first, __last); + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Allocator> +vector<bool, _Allocator>::vector(initializer_list<value_type> __il) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0) +{ + size_type __n = static_cast<size_type>(__il.size()); + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__il.begin(), __il.end()); + } +} + +template <class _Allocator> +vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, static_cast<__storage_allocator>(__a)) +{ + size_type __n = static_cast<size_type>(__il.size()); + if (__n > 0) + { + __vallocate(__n); + __construct_at_end(__il.begin(), __il.end()); + } +} + +#endif // _LIBCPP_CXX03_LANG + +template <class _Allocator> +vector<bool, _Allocator>::~vector() +{ + if (__begin_ != nullptr) + __storage_traits::deallocate(__alloc(), __begin_, __cap()); + __invalidate_all_iterators(); +} + +template <class _Allocator> +vector<bool, _Allocator>::vector(const vector& __v) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) +{ + if (__v.size() > 0) + { + __vallocate(__v.size()); + __construct_at_end(__v.begin(), __v.end()); + } +} + +template <class _Allocator> +vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, __a) +{ + if (__v.size() > 0) + { + __vallocate(__v.size()); + __construct_at_end(__v.begin(), __v.end()); + } +} + +template <class _Allocator> +vector<bool, _Allocator>& +vector<bool, _Allocator>::operator=(const vector& __v) +{ + if (this != &__v) + { + __copy_assign_alloc(__v); + if (__v.__size_) + { + if (__v.__size_ > capacity()) + { + __vdeallocate(); + __vallocate(__v.__size_); + } + _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); + } + __size_ = __v.__size_; + } + return *this; +} + +#ifndef _LIBCPP_CXX03_LANG + +template <class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v) +#if _LIBCPP_STD_VER > 14 + _NOEXCEPT +#else + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) +#endif + : __begin_(__v.__begin_), + __size_(__v.__size_), + __cap_alloc_(std::move(__v.__cap_alloc_)) { + __v.__begin_ = nullptr; + __v.__size_ = 0; + __v.__cap() = 0; +} + +template <class _Allocator> +vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, __a) +{ + if (__a == allocator_type(__v.__alloc())) + { + this->__begin_ = __v.__begin_; + this->__size_ = __v.__size_; + this->__cap() = __v.__cap(); + __v.__begin_ = nullptr; + __v.__cap() = __v.__size_ = 0; + } + else if (__v.size() > 0) + { + __vallocate(__v.size()); + __construct_at_end(__v.begin(), __v.end()); + } +} + +template <class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +vector<bool, _Allocator>& +vector<bool, _Allocator>::operator=(vector&& __v) + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) +{ + __move_assign(__v, integral_constant<bool, + __storage_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +template <class _Allocator> +void +vector<bool, _Allocator>::__move_assign(vector& __c, false_type) +{ + if (__alloc() != __c.__alloc()) + assign(__c.begin(), __c.end()); + else + __move_assign(__c, true_type()); +} + +template <class _Allocator> +void +vector<bool, _Allocator>::__move_assign(vector& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) +{ + __vdeallocate(); + __move_assign_alloc(__c); + this->__begin_ = __c.__begin_; + this->__size_ = __c.__size_; + this->__cap() = __c.__cap(); + __c.__begin_ = nullptr; + __c.__cap() = __c.__size_ = 0; +} + +#endif // !_LIBCPP_CXX03_LANG + +template <class _Allocator> +void +vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) +{ + __size_ = 0; + if (__n > 0) + { + size_type __c = capacity(); + if (__n <= __c) + __size_ = __n; + else + { + vector __v(__alloc()); + __v.reserve(__recommend(__n)); + __v.__size_ = __n; + swap(__v); + } + _VSTD::fill_n(begin(), __n, __x); + } + __invalidate_all_iterators(); +} + +template <class _Allocator> +template <class _InputIterator> +typename enable_if +< + __is_input_iterator<_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value, + void +>::type +vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) +{ + clear(); + for (; __first != __last; ++__first) + push_back(*__first); +} + +template <class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value, + void +>::type +vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) +{ + clear(); + difference_type __ns = _VSTD::distance(__first, __last); + _LIBCPP_ASSERT(__ns >= 0, "invalid range specified"); + const size_t __n = static_cast<size_type>(__ns); + if (__n) + { + if (__n > capacity()) + { + __vdeallocate(); + __vallocate(__n); + } + __construct_at_end(__first, __last); + } +} + +template <class _Allocator> +void +vector<bool, _Allocator>::reserve(size_type __n) +{ + if (__n > capacity()) + { + vector __v(this->__alloc()); + __v.__vallocate(__n); + __v.__construct_at_end(this->begin(), this->end()); + swap(__v); + __invalidate_all_iterators(); + } +} + +template <class _Allocator> +void +vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT +{ + if (__external_cap_to_internal(size()) > __cap()) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + vector(*this, allocator_type(__alloc())).swap(*this); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Allocator> +typename vector<bool, _Allocator>::reference +vector<bool, _Allocator>::at(size_type __n) +{ + if (__n >= size()) + this->__throw_out_of_range(); + return (*this)[__n]; +} + +template <class _Allocator> +typename vector<bool, _Allocator>::const_reference +vector<bool, _Allocator>::at(size_type __n) const +{ + if (__n >= size()) + this->__throw_out_of_range(); + return (*this)[__n]; +} + +template <class _Allocator> +void +vector<bool, _Allocator>::push_back(const value_type& __x) +{ + if (this->__size_ == this->capacity()) + reserve(__recommend(this->__size_ + 1)); + ++this->__size_; + back() = __x; +} + +template <class _Allocator> +typename vector<bool, _Allocator>::iterator +vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) +{ + iterator __r; + if (size() < capacity()) + { + const_iterator __old_end = end(); + ++__size_; + _VSTD::copy_backward(__position, __old_end, end()); + __r = __const_iterator_cast(__position); + } + else + { + vector __v(__alloc()); + __v.reserve(__recommend(__size_ + 1)); + __v.__size_ = __size_ + 1; + __r = _VSTD::copy(cbegin(), __position, __v.begin()); + _VSTD::copy_backward(__position, cend(), __v.end()); + swap(__v); + } + *__r = __x; + return __r; +} + +template <class _Allocator> +typename vector<bool, _Allocator>::iterator +vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) +{ + iterator __r; + size_type __c = capacity(); + if (__n <= __c && size() <= __c - __n) + { + const_iterator __old_end = end(); + __size_ += __n; + _VSTD::copy_backward(__position, __old_end, end()); + __r = __const_iterator_cast(__position); + } + else + { + vector __v(__alloc()); + __v.reserve(__recommend(__size_ + __n)); + __v.__size_ = __size_ + __n; + __r = _VSTD::copy(cbegin(), __position, __v.begin()); + _VSTD::copy_backward(__position, cend(), __v.end()); + swap(__v); + } + _VSTD::fill_n(__r, __n, __x); + return __r; +} + +template <class _Allocator> +template <class _InputIterator> +typename enable_if +< + __is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value, + typename vector<bool, _Allocator>::iterator +>::type +vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) +{ + difference_type __off = __position - begin(); + iterator __p = __const_iterator_cast(__position); + iterator __old_end = end(); + for (; size() != capacity() && __first != __last; ++__first) + { + ++this->__size_; + back() = *__first; + } + vector __v(__alloc()); + if (__first != __last) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __v.assign(__first, __last); + difference_type __old_size = static_cast<difference_type>(__old_end - begin()); + difference_type __old_p = __p - begin(); + reserve(__recommend(size() + __v.size())); + __p = begin() + __old_p; + __old_end = begin() + __old_size; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + erase(__old_end, end()); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + __p = _VSTD::rotate(__p, __old_end, end()); + insert(__p, __v.begin(), __v.end()); + return begin() + __off; +} + +template <class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value, + typename vector<bool, _Allocator>::iterator +>::type +vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) +{ + const difference_type __n_signed = _VSTD::distance(__first, __last); + _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified"); + const size_type __n = static_cast<size_type>(__n_signed); + iterator __r; + size_type __c = capacity(); + if (__n <= __c && size() <= __c - __n) + { + const_iterator __old_end = end(); + __size_ += __n; + _VSTD::copy_backward(__position, __old_end, end()); + __r = __const_iterator_cast(__position); + } + else + { + vector __v(__alloc()); + __v.reserve(__recommend(__size_ + __n)); + __v.__size_ = __size_ + __n; + __r = _VSTD::copy(cbegin(), __position, __v.begin()); + _VSTD::copy_backward(__position, cend(), __v.end()); + swap(__v); + } + _VSTD::copy(__first, __last, __r); + return __r; +} + +template <class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename vector<bool, _Allocator>::iterator +vector<bool, _Allocator>::erase(const_iterator __position) +{ + iterator __r = __const_iterator_cast(__position); + _VSTD::copy(__position + 1, this->cend(), __r); + --__size_; + return __r; +} + +template <class _Allocator> +typename vector<bool, _Allocator>::iterator +vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) +{ + iterator __r = __const_iterator_cast(__first); + difference_type __d = __last - __first; + _VSTD::copy(__last, this->cend(), __r); + __size_ -= __d; + return __r; +} + +template <class _Allocator> +void +vector<bool, _Allocator>::swap(vector& __x) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value) +#endif +{ + _VSTD::swap(this->__begin_, __x.__begin_); + _VSTD::swap(this->__size_, __x.__size_); + _VSTD::swap(this->__cap(), __x.__cap()); + __swap_allocator(this->__alloc(), __x.__alloc(), + integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); +} + +template <class _Allocator> +void +vector<bool, _Allocator>::resize(size_type __sz, value_type __x) +{ + size_type __cs = size(); + if (__cs < __sz) + { + iterator __r; + size_type __c = capacity(); + size_type __n = __sz - __cs; + if (__n <= __c && __cs <= __c - __n) + { + __r = end(); + __size_ += __n; + } + else + { + vector __v(__alloc()); + __v.reserve(__recommend(__size_ + __n)); + __v.__size_ = __size_ + __n; + __r = _VSTD::copy(cbegin(), cend(), __v.begin()); + swap(__v); + } + _VSTD::fill_n(__r, __n, __x); + } + else + __size_ = __sz; +} + +template <class _Allocator> +void +vector<bool, _Allocator>::flip() _NOEXCEPT +{ + // do middle whole words + size_type __n = __size_; + __storage_pointer __p = __begin_; + for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) + *__p = ~*__p; + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__p & __m; + *__p &= ~__m; + *__p |= ~__b & __m; + } +} + +template <class _Allocator> +bool +vector<bool, _Allocator>::__invariants() const +{ + if (this->__begin_ == nullptr) + { + if (this->__size_ != 0 || this->__cap() != 0) + return false; + } + else + { + if (this->__cap() == 0) + return false; + if (this->__size_ > this->capacity()) + return false; + } + return true; +} + +template <class _Allocator> +size_t +vector<bool, _Allocator>::__hash_code() const _NOEXCEPT +{ + size_t __h = 0; + // do middle whole words + size_type __n = __size_; + __storage_pointer __p = __begin_; + for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) + __h ^= *__p; + // do last partial word + if (__n > 0) + { + const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __h ^= *__p & __m; + } + return __h; +} + +template <class _Allocator> +struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > + : public unary_function<vector<bool, _Allocator>, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT + {return __vec.__hash_code();} +}; + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) +{ + const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); + return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) +{ + return !(__x < __y); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +#if _LIBCPP_STD_VER > 17 +template <class _Tp, class _Allocator, class _Up> +inline _LIBCPP_INLINE_VISIBILITY +void erase(vector<_Tp, _Allocator>& __c, const _Up& __v) +{ __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); } + +template <class _Tp, class _Allocator, class _Predicate> +inline _LIBCPP_INLINE_VISIBILITY +void erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) +{ __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); } +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_VECTOR diff --git a/android/x86/include/v8/libc++/version b/android/x86/include/v8/libc++/version new file mode 100755 index 00000000..1037ee5d --- /dev/null +++ b/android/x86/include/v8/libc++/version @@ -0,0 +1,231 @@ +// -*- C++ -*- +//===--------------------------- version ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_VERSIONH +#define _LIBCPP_VERSIONH + +/* + version synopsis + +Macro name Value Headers +__cpp_lib_addressof_constexpr 201603L <memory> +__cpp_lib_allocator_traits_is_always_equal 201411L <memory> <scoped_allocator> <string> + <deque> <forward_list> <list> + <vector> <map> <set> + <unordered_map> <unordered_set> +__cpp_lib_any 201606L <any> +__cpp_lib_apply 201603L <tuple> +__cpp_lib_array_constexpr 201603L <iterator> <array> +__cpp_lib_as_const 201510L <utility> +__cpp_lib_atomic_is_always_lock_free 201603L <atomic> +__cpp_lib_atomic_ref 201806L <atomic> +__cpp_lib_bind_front 201811L <functional> +__cpp_lib_bit_cast 201806L <bit> +__cpp_lib_bool_constant 201505L <type_traits> +__cpp_lib_boyer_moore_searcher 201603L <functional> +__cpp_lib_byte 201603L <cstddef> +__cpp_lib_char8_t 201811L <atomic> <filesystem> <istream> + <limits> <locale> <ostream> + <string> <string_view> +__cpp_lib_chrono 201611L <chrono> +__cpp_lib_chrono_udls 201304L <chrono> +__cpp_lib_clamp 201603L <algorithm> +__cpp_lib_complex_udls 201309L <complex> +__cpp_lib_concepts 201806L <concepts> +__cpp_lib_constexpr_misc 201811L <array> <functional> <iterator> + <string_view> <tuple> <utility> +__cpp_lib_constexpr_swap_algorithms 201806L <algorithm> +__cpp_lib_destroying_delete 201806L <new> +__cpp_lib_enable_shared_from_this 201603L <memory> +__cpp_lib_erase_if 201811L <string> <deque> <forward_list> + <list> <vector> <map> + <set> <unordered_map> <unordered_set> +__cpp_lib_exchange_function 201304L <utility> +__cpp_lib_execution 201603L <execution> +__cpp_lib_filesystem 201703L <filesystem> +__cpp_lib_gcd_lcm 201606L <numeric> +__cpp_lib_generic_associative_lookup 201304L <map> <set> +__cpp_lib_generic_unordered_lookup 201811L <unordered_map> <unordered_set> +__cpp_lib_hardware_interference_size 201703L <new> +__cpp_lib_has_unique_object_representations 201606L <type_traits> +__cpp_lib_hypot 201603L <cmath> +__cpp_lib_incomplete_container_elements 201505L <forward_list> <list> <vector> +__cpp_lib_integer_sequence 201304L <utility> +__cpp_lib_integral_constant_callable 201304L <type_traits> +__cpp_lib_invoke 201411L <functional> +__cpp_lib_is_aggregate 201703L <type_traits> +__cpp_lib_is_constant_evaluated 201811L <type_traits> +__cpp_lib_is_final 201402L <type_traits> +__cpp_lib_is_invocable 201703L <type_traits> +__cpp_lib_is_null_pointer 201309L <type_traits> +__cpp_lib_is_swappable 201603L <type_traits> +__cpp_lib_launder 201606L <new> +__cpp_lib_list_remove_return_type 201806L <forward_list> <list> +__cpp_lib_logical_traits 201510L <type_traits> +__cpp_lib_make_from_tuple 201606L <tuple> +__cpp_lib_make_reverse_iterator 201402L <iterator> +__cpp_lib_make_unique 201304L <memory> +__cpp_lib_map_try_emplace 201411L <map> +__cpp_lib_math_special_functions 201603L <cmath> +__cpp_lib_memory_resource 201603L <memory_resource> +__cpp_lib_node_extract 201606L <map> <set> <unordered_map> + <unordered_set> +__cpp_lib_nonmember_container_access 201411L <iterator> <array> <deque> + <forward_list> <list> <map> + <regex> <set> <string> + <unordered_map> <unordered_set> <vector> +__cpp_lib_not_fn 201603L <functional> +__cpp_lib_null_iterators 201304L <iterator> +__cpp_lib_optional 201606L <optional> +__cpp_lib_parallel_algorithm 201603L <algorithm> <numeric> +__cpp_lib_quoted_string_io 201304L <iomanip> +__cpp_lib_ranges 201811L <algorithm> <functional> <iterator> + <memory> <ranges> +__cpp_lib_raw_memory_algorithms 201606L <memory> +__cpp_lib_result_of_sfinae 201210L <functional> <type_traits> +__cpp_lib_robust_nonmodifying_seq_ops 201304L <algorithm> +__cpp_lib_sample 201603L <algorithm> +__cpp_lib_scoped_lock 201703L <mutex> +__cpp_lib_shared_mutex 201505L <shared_mutex> +__cpp_lib_shared_ptr_arrays 201611L <memory> +__cpp_lib_shared_ptr_weak_type 201606L <memory> +__cpp_lib_shared_timed_mutex 201402L <shared_mutex> +__cpp_lib_string_udls 201304L <string> +__cpp_lib_string_view 201606L <string> <string_view> +__cpp_lib_three_way_comparison 201711L <compare> +__cpp_lib_to_chars 201611L <utility> +__cpp_lib_transformation_trait_aliases 201304L <type_traits> +__cpp_lib_transparent_operators 201510L <functional> + 201210L // C++14 +__cpp_lib_tuple_element_t 201402L <tuple> +__cpp_lib_tuples_by_type 201304L <utility> <tuple> +__cpp_lib_type_trait_variable_templates 201510L <type_traits> +__cpp_lib_uncaught_exceptions 201411L <exception> +__cpp_lib_unordered_map_try_emplace 201411L <unordered_map> +__cpp_lib_variant 201606L <variant> +__cpp_lib_void_t 201411L <type_traits> + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 11 +# define __cpp_lib_chrono_udls 201304L +# define __cpp_lib_complex_udls 201309L +# define __cpp_lib_exchange_function 201304L +# define __cpp_lib_generic_associative_lookup 201304L +# define __cpp_lib_integer_sequence 201304L +# define __cpp_lib_integral_constant_callable 201304L +# define __cpp_lib_is_final 201402L +# define __cpp_lib_is_null_pointer 201309L +# define __cpp_lib_make_reverse_iterator 201402L +# define __cpp_lib_make_unique 201304L +# define __cpp_lib_null_iterators 201304L +# define __cpp_lib_quoted_string_io 201304L +# define __cpp_lib_result_of_sfinae 201210L +# define __cpp_lib_robust_nonmodifying_seq_ops 201304L +# if !defined(_LIBCPP_HAS_NO_THREADS) +# define __cpp_lib_shared_timed_mutex 201402L +# endif +# define __cpp_lib_string_udls 201304L +# define __cpp_lib_transformation_trait_aliases 201304L +# define __cpp_lib_transparent_operators 201210L +# define __cpp_lib_tuple_element_t 201402L +# define __cpp_lib_tuples_by_type 201304L +#endif + +#if _LIBCPP_STD_VER > 14 +# if !defined(_LIBCPP_HAS_NO_BUILTIN_ADDRESSOF) +# define __cpp_lib_addressof_constexpr 201603L +# endif +# define __cpp_lib_allocator_traits_is_always_equal 201411L +# define __cpp_lib_any 201606L +# define __cpp_lib_apply 201603L +# define __cpp_lib_array_constexpr 201603L +# define __cpp_lib_as_const 201510L +# if !defined(_LIBCPP_HAS_NO_THREADS) +# define __cpp_lib_atomic_is_always_lock_free 201603L +# endif +# define __cpp_lib_bool_constant 201505L +// # define __cpp_lib_boyer_moore_searcher 201603L +# define __cpp_lib_byte 201603L +# define __cpp_lib_chrono 201611L +# define __cpp_lib_clamp 201603L +# define __cpp_lib_enable_shared_from_this 201603L +// # define __cpp_lib_execution 201603L +# define __cpp_lib_filesystem 201703L +# define __cpp_lib_gcd_lcm 201606L +# define __cpp_lib_hardware_interference_size 201703L +# if defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS) +# define __cpp_lib_has_unique_object_representations 201606L +# endif +# define __cpp_lib_hypot 201603L +# define __cpp_lib_incomplete_container_elements 201505L +# define __cpp_lib_invoke 201411L +# if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) +# define __cpp_lib_is_aggregate 201703L +# endif +# define __cpp_lib_is_invocable 201703L +# define __cpp_lib_is_swappable 201603L +# define __cpp_lib_launder 201606L +# define __cpp_lib_logical_traits 201510L +# define __cpp_lib_make_from_tuple 201606L +# define __cpp_lib_map_try_emplace 201411L +// # define __cpp_lib_math_special_functions 201603L +// # define __cpp_lib_memory_resource 201603L +# define __cpp_lib_node_extract 201606L +# define __cpp_lib_nonmember_container_access 201411L +# define __cpp_lib_not_fn 201603L +# define __cpp_lib_optional 201606L +// # define __cpp_lib_parallel_algorithm 201603L +# define __cpp_lib_raw_memory_algorithms 201606L +# define __cpp_lib_sample 201603L +# define __cpp_lib_scoped_lock 201703L +# if !defined(_LIBCPP_HAS_NO_THREADS) +# define __cpp_lib_shared_mutex 201505L +# endif +// # define __cpp_lib_shared_ptr_arrays 201611L +# define __cpp_lib_shared_ptr_weak_type 201606L +# define __cpp_lib_string_view 201606L +// # define __cpp_lib_to_chars 201611L +# undef __cpp_lib_transparent_operators +# define __cpp_lib_transparent_operators 201510L +# define __cpp_lib_type_trait_variable_templates 201510L +# define __cpp_lib_uncaught_exceptions 201411L +# define __cpp_lib_unordered_map_try_emplace 201411L +# define __cpp_lib_variant 201606L +# define __cpp_lib_void_t 201411L +#endif + +#if _LIBCPP_STD_VER > 17 +# if !defined(_LIBCPP_HAS_NO_THREADS) +// # define __cpp_lib_atomic_ref 201806L +# endif +// # define __cpp_lib_bind_front 201811L +// # define __cpp_lib_bit_cast 201806L +# if !defined(_LIBCPP_NO_HAS_CHAR8_T) +# define __cpp_lib_char8_t 201811L +# endif +// # define __cpp_lib_concepts 201806L +// # define __cpp_lib_constexpr_misc 201811L +// # define __cpp_lib_constexpr_swap_algorithms 201806L +// # define __cpp_lib_destroying_delete 201806L +# define __cpp_lib_erase_if 201811L +// # define __cpp_lib_generic_unordered_lookup 201811L +// # define __cpp_lib_is_constant_evaluated 201811L +// # define __cpp_lib_list_remove_return_type 201806L +// # define __cpp_lib_ranges 201811L +// # define __cpp_lib_three_way_comparison 201711L +#endif + +#endif // _LIBCPP_VERSIONH diff --git a/android/x86/include/v8/libc++/wchar.h b/android/x86/include/v8/libc++/wchar.h new file mode 100755 index 00000000..353c979d --- /dev/null +++ b/android/x86/include/v8/libc++/wchar.h @@ -0,0 +1,181 @@ +// -*- C++ -*- +//===--------------------------- wchar.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#if defined(__need_wint_t) || defined(__need_mbstate_t) + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <wchar.h> + +#elif !defined(_LIBCPP_WCHAR_H) +#define _LIBCPP_WCHAR_H + +/* + wchar.h synopsis + +Macros: + + NULL + WCHAR_MAX + WCHAR_MIN + WEOF + +Types: + + mbstate_t + size_t + tm + wint_t + +int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...); +int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...); +int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, ...); +int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...); +int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); +int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); // C99 +int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, va_list arg); +int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, va_list arg); // C99 +int vwprintf(const wchar_t* restrict format, va_list arg); +int vwscanf(const wchar_t* restrict format, va_list arg); // C99 +int wprintf(const wchar_t* restrict format, ...); +int wscanf(const wchar_t* restrict format, ...); +wint_t fgetwc(FILE* stream); +wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream); +wint_t fputwc(wchar_t c, FILE* stream); +int fputws(const wchar_t* restrict s, FILE* restrict stream); +int fwide(FILE* stream, int mode); +wint_t getwc(FILE* stream); +wint_t getwchar(); +wint_t putwc(wchar_t c, FILE* stream); +wint_t putwchar(wchar_t c); +wint_t ungetwc(wint_t c, FILE* stream); +double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr); +float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99 +long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99 +long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); +long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99 +unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); +unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99 +wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2); +wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +wchar_t* wcscat(wchar_t* restrict s1, const wchar_t* restrict s2); +wchar_t* wcsncat(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +int wcscmp(const wchar_t* s1, const wchar_t* s2); +int wcscoll(const wchar_t* s1, const wchar_t* s2); +int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n); +size_t wcsxfrm(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +const wchar_t* wcschr(const wchar_t* s, wchar_t c); + wchar_t* wcschr( wchar_t* s, wchar_t c); +size_t wcscspn(const wchar_t* s1, const wchar_t* s2); +size_t wcslen(const wchar_t* s); +const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2); + wchar_t* wcspbrk( wchar_t* s1, const wchar_t* s2); +const wchar_t* wcsrchr(const wchar_t* s, wchar_t c); + wchar_t* wcsrchr( wchar_t* s, wchar_t c); +size_t wcsspn(const wchar_t* s1, const wchar_t* s2); +const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2); + wchar_t* wcsstr( wchar_t* s1, const wchar_t* s2); +wchar_t* wcstok(wchar_t* restrict s1, const wchar_t* restrict s2, wchar_t** restrict ptr); +const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n); + wchar_t* wmemchr( wchar_t* s, wchar_t c, size_t n); +int wmemcmp(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +wchar_t* wmemcpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n); +wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n); +size_t wcsftime(wchar_t* restrict s, size_t maxsize, const wchar_t* restrict format, + const tm* restrict timeptr); +wint_t btowc(int c); +int wctob(wint_t c); +int mbsinit(const mbstate_t* ps); +size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps); +size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, mbstate_t* restrict ps); +size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps); +size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src, size_t len, + mbstate_t* restrict ps); +size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, + mbstate_t* restrict ps); + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef __cplusplus +#define __CORRECT_ISO_CPP_WCHAR_H_PROTO +#endif + +#include_next <wchar.h> + +// Determine whether we have const-correct overloads for wcschr and friends. +#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_) +# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 +#elif defined(__GLIBC_PREREQ) +# if __GLIBC_PREREQ(2, 10) +# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 +# endif +#elif defined(_LIBCPP_MSVCRT) +# if defined(_CRT_CONST_CORRECT_OVERLOADS) +# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 +# endif +#endif + +#if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD) +extern "C++" { +inline _LIBCPP_INLINE_VISIBILITY +wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcschr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} + +inline _LIBCPP_INLINE_VISIBILITY +wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcspbrk(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + wchar_t* wcspbrk( wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);} + +inline _LIBCPP_INLINE_VISIBILITY +wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcsrchr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + wchar_t* wcsrchr( wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);} + +inline _LIBCPP_INLINE_VISIBILITY +wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + wchar_t* wcsstr( wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);} + +inline _LIBCPP_INLINE_VISIBILITY +wchar_t* __libcpp_wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return (wchar_t*)wmemchr(__s, __c, __n);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD +const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);} +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD + wchar_t* wmemchr( wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);} +} +#endif + +#if defined(__cplusplus) && defined(_LIBCPP_MSVCRT_LIKE) +extern "C" { +size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src, + size_t nmc, size_t len, mbstate_t *__restrict ps); +size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src, + size_t nwc, size_t len, mbstate_t *__restrict ps); +} // extern "C++" +#endif // __cplusplus && _LIBCPP_MSVCRT + +#endif // _LIBCPP_WCHAR_H diff --git a/android/x86/include/v8/libc++/wctype.h b/android/x86/include/v8/libc++/wctype.h new file mode 100755 index 00000000..bdcf3723 --- /dev/null +++ b/android/x86/include/v8/libc++/wctype.h @@ -0,0 +1,78 @@ +// -*- C++ -*- +//===--------------------------- wctype.h ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_WCTYPE_H +#define _LIBCPP_WCTYPE_H + +/* + wctype.h synopsis + +Macros: + + WEOF + +Types: + + wint_t + wctrans_t + wctype_t + +int iswalnum(wint_t wc); +int iswalpha(wint_t wc); +int iswblank(wint_t wc); // C99 +int iswcntrl(wint_t wc); +int iswdigit(wint_t wc); +int iswgraph(wint_t wc); +int iswlower(wint_t wc); +int iswprint(wint_t wc); +int iswpunct(wint_t wc); +int iswspace(wint_t wc); +int iswupper(wint_t wc); +int iswxdigit(wint_t wc); +int iswctype(wint_t wc, wctype_t desc); +wctype_t wctype(const char* property); +wint_t towlower(wint_t wc); +wint_t towupper(wint_t wc); +wint_t towctrans(wint_t wc, wctrans_t desc); +wctrans_t wctrans(const char* property); + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <wctype.h> + +#ifdef __cplusplus + +#undef iswalnum +#undef iswalpha +#undef iswblank +#undef iswcntrl +#undef iswdigit +#undef iswgraph +#undef iswlower +#undef iswprint +#undef iswpunct +#undef iswspace +#undef iswupper +#undef iswxdigit +#undef iswctype +#undef wctype +#undef towlower +#undef towupper +#undef towctrans +#undef wctrans + +#endif // __cplusplus + +#endif // _LIBCPP_WCTYPE_H diff --git a/android/x86/include/v8/libplatform/DEPS b/android/x86/include/v8/libplatform/DEPS new file mode 100755 index 00000000..d8bcf998 --- /dev/null +++ b/android/x86/include/v8/libplatform/DEPS @@ -0,0 +1,9 @@ +include_rules = [ + "+libplatform/libplatform-export.h", +] + +specific_include_rules = { + "libplatform\.h": [ + "+libplatform/v8-tracing.h", + ], +} diff --git a/android/x86/include/v8/libplatform/libplatform-export.h b/android/x86/include/v8/libplatform/libplatform-export.h new file mode 100755 index 00000000..15618434 --- /dev/null +++ b/android/x86/include/v8/libplatform/libplatform-export.h @@ -0,0 +1,29 @@ +// Copyright 2016 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_ +#define V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_ + +#if defined(_WIN32) + +#ifdef BUILDING_V8_PLATFORM_SHARED +#define V8_PLATFORM_EXPORT __declspec(dllexport) +#elif USING_V8_PLATFORM_SHARED +#define V8_PLATFORM_EXPORT __declspec(dllimport) +#else +#define V8_PLATFORM_EXPORT +#endif // BUILDING_V8_PLATFORM_SHARED + +#else // defined(_WIN32) + +// Setup for Linux shared library export. +#ifdef BUILDING_V8_PLATFORM_SHARED +#define V8_PLATFORM_EXPORT __attribute__((visibility("default"))) +#else +#define V8_PLATFORM_EXPORT +#endif + +#endif // defined(_WIN32) + +#endif // V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_ diff --git a/android/x86/include/v8/libplatform/libplatform.h b/android/x86/include/v8/libplatform/libplatform.h new file mode 100755 index 00000000..6908aeaa --- /dev/null +++ b/android/x86/include/v8/libplatform/libplatform.h @@ -0,0 +1,82 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_LIBPLATFORM_LIBPLATFORM_H_ +#define V8_LIBPLATFORM_LIBPLATFORM_H_ + +#include "libplatform/libplatform-export.h" +#include "libplatform/v8-tracing.h" +#include "v8-platform.h" // NOLINT(build/include) +#include "v8config.h" // NOLINT(build/include) + +namespace v8 { +namespace platform { + +enum class IdleTaskSupport { kDisabled, kEnabled }; +enum class InProcessStackDumping { kDisabled, kEnabled }; + +enum class MessageLoopBehavior : bool { + kDoNotWait = false, + kWaitForWork = true +}; + +/** + * Returns a new instance of the default v8::Platform implementation. + * + * The caller will take ownership of the returned pointer. |thread_pool_size| + * is the number of worker threads to allocate for background jobs. If a value + * of zero is passed, a suitable default based on the current number of + * processors online will be chosen. + * If |idle_task_support| is enabled then the platform will accept idle + * tasks (IdleTasksEnabled will return true) and will rely on the embedder + * calling v8::platform::RunIdleTasks to process the idle tasks. + * If |tracing_controller| is nullptr, the default platform will create a + * v8::platform::TracingController instance and use it. + */ +V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform( + int thread_pool_size = 0, + IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled, + InProcessStackDumping in_process_stack_dumping = + InProcessStackDumping::kDisabled, + std::unique_ptr<v8::TracingController> tracing_controller = {}); + +/** + * Pumps the message loop for the given isolate. + * + * The caller has to make sure that this is called from the right thread. + * Returns true if a task was executed, and false otherwise. Unless requested + * through the |behavior| parameter, this call does not block if no task is + * pending. The |platform| has to be created using |NewDefaultPlatform|. + */ +V8_PLATFORM_EXPORT bool PumpMessageLoop( + v8::Platform* platform, v8::Isolate* isolate, + MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait); + +/** + * Runs pending idle tasks for at most |idle_time_in_seconds| seconds. + * + * The caller has to make sure that this is called from the right thread. + * This call does not block if no task is pending. The |platform| has to be + * created using |NewDefaultPlatform|. + */ +V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform, + v8::Isolate* isolate, + double idle_time_in_seconds); + +/** + * Attempts to set the tracing controller for the given platform. + * + * The |platform| has to be created using |NewDefaultPlatform|. + * + */ +V8_PLATFORM_EXPORT V8_DEPRECATE_SOON( + "Access the DefaultPlatform directly", + void SetTracingController( + v8::Platform* platform, + v8::platform::tracing::TracingController* tracing_controller)); + +} // namespace platform +} // namespace v8 + +#endif // V8_LIBPLATFORM_LIBPLATFORM_H_ diff --git a/android/x86/include/v8/libplatform/v8-tracing.h b/android/x86/include/v8/libplatform/v8-tracing.h new file mode 100755 index 00000000..bc249cb9 --- /dev/null +++ b/android/x86/include/v8/libplatform/v8-tracing.h @@ -0,0 +1,295 @@ +// Copyright 2016 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_LIBPLATFORM_V8_TRACING_H_ +#define V8_LIBPLATFORM_V8_TRACING_H_ + +#include <atomic> +#include <fstream> +#include <memory> +#include <unordered_set> +#include <vector> + +#include "libplatform/libplatform-export.h" +#include "v8-platform.h" // NOLINT(build/include) + +namespace v8 { + +namespace base { +class Mutex; +} // namespace base + +namespace platform { +namespace tracing { + +const int kTraceMaxNumArgs = 2; + +class V8_PLATFORM_EXPORT TraceObject { + public: + union ArgValue { + bool as_bool; + uint64_t as_uint; + int64_t as_int; + double as_double; + const void* as_pointer; + const char* as_string; + }; + + TraceObject() = default; + ~TraceObject(); + void Initialize( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, + unsigned int flags, int64_t timestamp, int64_t cpu_timestamp); + void UpdateDuration(int64_t timestamp, int64_t cpu_timestamp); + void InitializeForTesting( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, + unsigned int flags, int pid, int tid, int64_t ts, int64_t tts, + uint64_t duration, uint64_t cpu_duration); + + int pid() const { return pid_; } + int tid() const { return tid_; } + char phase() const { return phase_; } + const uint8_t* category_enabled_flag() const { + return category_enabled_flag_; + } + const char* name() const { return name_; } + const char* scope() const { return scope_; } + uint64_t id() const { return id_; } + uint64_t bind_id() const { return bind_id_; } + int num_args() const { return num_args_; } + const char** arg_names() { return arg_names_; } + uint8_t* arg_types() { return arg_types_; } + ArgValue* arg_values() { return arg_values_; } + std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables() { + return arg_convertables_; + } + unsigned int flags() const { return flags_; } + int64_t ts() { return ts_; } + int64_t tts() { return tts_; } + uint64_t duration() { return duration_; } + uint64_t cpu_duration() { return cpu_duration_; } + + private: + int pid_; + int tid_; + char phase_; + const char* name_; + const char* scope_; + const uint8_t* category_enabled_flag_; + uint64_t id_; + uint64_t bind_id_; + int num_args_ = 0; + const char* arg_names_[kTraceMaxNumArgs]; + uint8_t arg_types_[kTraceMaxNumArgs]; + ArgValue arg_values_[kTraceMaxNumArgs]; + std::unique_ptr<v8::ConvertableToTraceFormat> + arg_convertables_[kTraceMaxNumArgs]; + char* parameter_copy_storage_ = nullptr; + unsigned int flags_; + int64_t ts_; + int64_t tts_; + uint64_t duration_; + uint64_t cpu_duration_; + + // Disallow copy and assign + TraceObject(const TraceObject&) = delete; + void operator=(const TraceObject&) = delete; +}; + +class V8_PLATFORM_EXPORT TraceWriter { + public: + TraceWriter() = default; + virtual ~TraceWriter() = default; + virtual void AppendTraceEvent(TraceObject* trace_event) = 0; + virtual void Flush() = 0; + + static TraceWriter* CreateJSONTraceWriter(std::ostream& stream); + static TraceWriter* CreateJSONTraceWriter(std::ostream& stream, + const std::string& tag); + + private: + // Disallow copy and assign + TraceWriter(const TraceWriter&) = delete; + void operator=(const TraceWriter&) = delete; +}; + +class V8_PLATFORM_EXPORT TraceBufferChunk { + public: + explicit TraceBufferChunk(uint32_t seq); + + void Reset(uint32_t new_seq); + bool IsFull() const { return next_free_ == kChunkSize; } + TraceObject* AddTraceEvent(size_t* event_index); + TraceObject* GetEventAt(size_t index) { return &chunk_[index]; } + + uint32_t seq() const { return seq_; } + size_t size() const { return next_free_; } + + static const size_t kChunkSize = 64; + + private: + size_t next_free_ = 0; + TraceObject chunk_[kChunkSize]; + uint32_t seq_; + + // Disallow copy and assign + TraceBufferChunk(const TraceBufferChunk&) = delete; + void operator=(const TraceBufferChunk&) = delete; +}; + +class V8_PLATFORM_EXPORT TraceBuffer { + public: + TraceBuffer() = default; + virtual ~TraceBuffer() = default; + + virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0; + virtual TraceObject* GetEventByHandle(uint64_t handle) = 0; + virtual bool Flush() = 0; + + static const size_t kRingBufferChunks = 1024; + + static TraceBuffer* CreateTraceBufferRingBuffer(size_t max_chunks, + TraceWriter* trace_writer); + + private: + // Disallow copy and assign + TraceBuffer(const TraceBuffer&) = delete; + void operator=(const TraceBuffer&) = delete; +}; + +// Options determines how the trace buffer stores data. +enum TraceRecordMode { + // Record until the trace buffer is full. + RECORD_UNTIL_FULL, + + // Record until the user ends the trace. The trace buffer is a fixed size + // and we use it as a ring buffer during recording. + RECORD_CONTINUOUSLY, + + // Record until the trace buffer is full, but with a huge buffer size. + RECORD_AS_MUCH_AS_POSSIBLE, + + // Echo to console. Events are discarded. + ECHO_TO_CONSOLE, +}; + +class V8_PLATFORM_EXPORT TraceConfig { + public: + typedef std::vector<std::string> StringList; + + static TraceConfig* CreateDefaultTraceConfig(); + + TraceConfig() : enable_systrace_(false), enable_argument_filter_(false) {} + TraceRecordMode GetTraceRecordMode() const { return record_mode_; } + bool IsSystraceEnabled() const { return enable_systrace_; } + bool IsArgumentFilterEnabled() const { return enable_argument_filter_; } + + void SetTraceRecordMode(TraceRecordMode mode) { record_mode_ = mode; } + void EnableSystrace() { enable_systrace_ = true; } + void EnableArgumentFilter() { enable_argument_filter_ = true; } + + void AddIncludedCategory(const char* included_category); + + bool IsCategoryGroupEnabled(const char* category_group) const; + + private: + TraceRecordMode record_mode_; + bool enable_systrace_ : 1; + bool enable_argument_filter_ : 1; + StringList included_categories_; + + // Disallow copy and assign + TraceConfig(const TraceConfig&) = delete; + void operator=(const TraceConfig&) = delete; +}; + +#if defined(_MSC_VER) +#define V8_PLATFORM_NON_EXPORTED_BASE(code) \ + __pragma(warning(suppress : 4275)) code +#else +#define V8_PLATFORM_NON_EXPORTED_BASE(code) code +#endif // defined(_MSC_VER) + +class V8_PLATFORM_EXPORT TracingController + : public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) { + public: + // The pointer returned from GetCategoryGroupEnabled() points to a value with + // zero or more of the following bits. Used in this class only. The + // TRACE_EVENT macros should only use the value as a bool. These values must + // be in sync with macro values in TraceEvent.h in Blink. + enum CategoryGroupEnabledFlags { + // Category group enabled for the recording mode. + ENABLED_FOR_RECORDING = 1 << 0, + // Category group enabled by SetEventCallbackEnabled(). + ENABLED_FOR_EVENT_CALLBACK = 1 << 2, + // Category group enabled to export events to ETW. + ENABLED_FOR_ETW_EXPORT = 1 << 3 + }; + + TracingController(); + ~TracingController() override; + void Initialize(TraceBuffer* trace_buffer); + + // v8::TracingController implementation. + const uint8_t* GetCategoryGroupEnabled(const char* category_group) override; + uint64_t AddTraceEvent( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, + unsigned int flags) override; + uint64_t AddTraceEventWithTimestamp( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, + unsigned int flags, int64_t timestamp) override; + void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, + const char* name, uint64_t handle) override; + void AddTraceStateObserver( + v8::TracingController::TraceStateObserver* observer) override; + void RemoveTraceStateObserver( + v8::TracingController::TraceStateObserver* observer) override; + + void StartTracing(TraceConfig* trace_config); + void StopTracing(); + + static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag); + + protected: + virtual int64_t CurrentTimestampMicroseconds(); + virtual int64_t CurrentCpuTimestampMicroseconds(); + + private: + void UpdateCategoryGroupEnabledFlag(size_t category_index); + void UpdateCategoryGroupEnabledFlags(); + + std::unique_ptr<TraceBuffer> trace_buffer_; + std::unique_ptr<TraceConfig> trace_config_; + std::unique_ptr<base::Mutex> mutex_; + std::unordered_set<v8::TracingController::TraceStateObserver*> observers_; + std::atomic_bool recording_{false}; + + // Disallow copy and assign + TracingController(const TracingController&) = delete; + void operator=(const TracingController&) = delete; +}; + +#undef V8_PLATFORM_NON_EXPORTED_BASE + +} // namespace tracing +} // namespace platform +} // namespace v8 + +#endif // V8_LIBPLATFORM_V8_TRACING_H_ diff --git a/android/x86/include/v8/v8-inspector-protocol.h b/android/x86/include/v8/v8-inspector-protocol.h new file mode 100755 index 00000000..612a2ebc --- /dev/null +++ b/android/x86/include/v8/v8-inspector-protocol.h @@ -0,0 +1,13 @@ +// Copyright 2016 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_V8_INSPECTOR_PROTOCOL_H_ +#define V8_V8_INSPECTOR_PROTOCOL_H_ + +#include "inspector/Debugger.h" // NOLINT(build/include) +#include "inspector/Runtime.h" // NOLINT(build/include) +#include "inspector/Schema.h" // NOLINT(build/include) +#include "v8-inspector.h" // NOLINT(build/include) + +#endif // V8_V8_INSPECTOR_PROTOCOL_H_ diff --git a/android/x86/include/v8/v8-inspector.h b/android/x86/include/v8/v8-inspector.h new file mode 100755 index 00000000..70201358 --- /dev/null +++ b/android/x86/include/v8/v8-inspector.h @@ -0,0 +1,296 @@ +// Copyright 2016 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_V8_INSPECTOR_H_ +#define V8_V8_INSPECTOR_H_ + +#include <stdint.h> +#include <cctype> + +#include <memory> + +#include "v8.h" // NOLINT(build/include) + +namespace v8_inspector { + +namespace protocol { +namespace Debugger { +namespace API { +class SearchMatch; +} +} +namespace Runtime { +namespace API { +class RemoteObject; +class StackTrace; +} +} +namespace Schema { +namespace API { +class Domain; +} +} +} // namespace protocol + +class V8_EXPORT StringView { + public: + StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {} + + StringView(const uint8_t* characters, size_t length) + : m_is8Bit(true), m_length(length), m_characters8(characters) {} + + StringView(const uint16_t* characters, size_t length) + : m_is8Bit(false), m_length(length), m_characters16(characters) {} + + bool is8Bit() const { return m_is8Bit; } + size_t length() const { return m_length; } + + // TODO(dgozman): add DCHECK(m_is8Bit) to accessors once platform can be used + // here. + const uint8_t* characters8() const { return m_characters8; } + const uint16_t* characters16() const { return m_characters16; } + + private: + bool m_is8Bit; + size_t m_length; + union { + const uint8_t* m_characters8; + const uint16_t* m_characters16; + }; +}; + +class V8_EXPORT StringBuffer { + public: + virtual ~StringBuffer() = default; + virtual const StringView& string() = 0; + // This method copies contents. + static std::unique_ptr<StringBuffer> create(const StringView&); +}; + +class V8_EXPORT V8ContextInfo { + public: + V8ContextInfo(v8::Local<v8::Context> context, int contextGroupId, + const StringView& humanReadableName) + : context(context), + contextGroupId(contextGroupId), + humanReadableName(humanReadableName), + hasMemoryOnConsole(false) {} + + v8::Local<v8::Context> context; + // Each v8::Context is a part of a group. The group id must be non-zero. + int contextGroupId; + StringView humanReadableName; + StringView origin; + StringView auxData; + bool hasMemoryOnConsole; + + static int executionContextId(v8::Local<v8::Context> context); + + private: + // Disallow copying and allocating this one. + enum NotNullTagEnum { NotNullLiteral }; + void* operator new(size_t) = delete; + void* operator new(size_t, NotNullTagEnum, void*) = delete; + void* operator new(size_t, void*) = delete; + V8ContextInfo(const V8ContextInfo&) = delete; + V8ContextInfo& operator=(const V8ContextInfo&) = delete; +}; + +class V8_EXPORT V8StackTrace { + public: + virtual StringView firstNonEmptySourceURL() const = 0; + virtual bool isEmpty() const = 0; + virtual StringView topSourceURL() const = 0; + virtual int topLineNumber() const = 0; + virtual int topColumnNumber() const = 0; + virtual StringView topScriptId() const = 0; + virtual StringView topFunctionName() const = 0; + + virtual ~V8StackTrace() = default; + virtual std::unique_ptr<protocol::Runtime::API::StackTrace> + buildInspectorObject() const = 0; + virtual std::unique_ptr<StringBuffer> toString() const = 0; + + // Safe to pass between threads, drops async chain. + virtual std::unique_ptr<V8StackTrace> clone() = 0; +}; + +class V8_EXPORT V8InspectorSession { + public: + virtual ~V8InspectorSession() = default; + + // Cross-context inspectable values (DOM nodes in different worlds, etc.). + class V8_EXPORT Inspectable { + public: + virtual v8::Local<v8::Value> get(v8::Local<v8::Context>) = 0; + virtual ~Inspectable() = default; + }; + virtual void addInspectedObject(std::unique_ptr<Inspectable>) = 0; + + // Dispatching protocol messages. + static bool canDispatchMethod(const StringView& method); + virtual void dispatchProtocolMessage(const StringView& message) = 0; + virtual std::unique_ptr<StringBuffer> stateJSON() = 0; + virtual std::vector<std::unique_ptr<protocol::Schema::API::Domain>> + supportedDomains() = 0; + + // Debugger actions. + virtual void schedulePauseOnNextStatement(const StringView& breakReason, + const StringView& breakDetails) = 0; + virtual void cancelPauseOnNextStatement() = 0; + virtual void breakProgram(const StringView& breakReason, + const StringView& breakDetails) = 0; + virtual void setSkipAllPauses(bool) = 0; + virtual void resume() = 0; + virtual void stepOver() = 0; + virtual std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> + searchInTextByLines(const StringView& text, const StringView& query, + bool caseSensitive, bool isRegex) = 0; + + // Remote objects. + virtual std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject( + v8::Local<v8::Context>, v8::Local<v8::Value>, const StringView& groupName, + bool generatePreview) = 0; + + virtual bool unwrapObject(std::unique_ptr<StringBuffer>* error, + const StringView& objectId, v8::Local<v8::Value>*, + v8::Local<v8::Context>*, + std::unique_ptr<StringBuffer>* objectGroup) = 0; + virtual void releaseObjectGroup(const StringView&) = 0; +}; + +class V8_EXPORT V8InspectorClient { + public: + virtual ~V8InspectorClient() = default; + + virtual void runMessageLoopOnPause(int contextGroupId) {} + virtual void quitMessageLoopOnPause() {} + virtual void runIfWaitingForDebugger(int contextGroupId) {} + + virtual void muteMetrics(int contextGroupId) {} + virtual void unmuteMetrics(int contextGroupId) {} + + virtual void beginUserGesture() {} + virtual void endUserGesture() {} + + virtual std::unique_ptr<StringBuffer> valueSubtype(v8::Local<v8::Value>) { + return nullptr; + } + virtual bool formatAccessorsAsProperties(v8::Local<v8::Value>) { + return false; + } + virtual bool isInspectableHeapObject(v8::Local<v8::Object>) { return true; } + + virtual v8::Local<v8::Context> ensureDefaultContextInGroup( + int contextGroupId) { + return v8::Local<v8::Context>(); + } + virtual void beginEnsureAllContextsInGroup(int contextGroupId) {} + virtual void endEnsureAllContextsInGroup(int contextGroupId) {} + + virtual void installAdditionalCommandLineAPI(v8::Local<v8::Context>, + v8::Local<v8::Object>) {} + virtual void consoleAPIMessage(int contextGroupId, + v8::Isolate::MessageErrorLevel level, + const StringView& message, + const StringView& url, unsigned lineNumber, + unsigned columnNumber, V8StackTrace*) {} + virtual v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate*, + v8::Local<v8::Context>) { + return v8::MaybeLocal<v8::Value>(); + } + + virtual void consoleTime(const StringView& title) {} + virtual void consoleTimeEnd(const StringView& title) {} + virtual void consoleTimeStamp(const StringView& title) {} + virtual void consoleClear(int contextGroupId) {} + virtual double currentTimeMS() { return 0; } + typedef void (*TimerCallback)(void*); + virtual void startRepeatingTimer(double, TimerCallback, void* data) {} + virtual void cancelTimer(void* data) {} + + // TODO(dgozman): this was added to support service worker shadow page. We + // should not connect at all. + virtual bool canExecuteScripts(int contextGroupId) { return true; } + + virtual void maxAsyncCallStackDepthChanged(int depth) {} + + virtual std::unique_ptr<StringBuffer> resourceNameToUrl( + const StringView& resourceName) { + return nullptr; + } +}; + +// These stack trace ids are intended to be passed between debuggers and be +// resolved later. This allows to track cross-debugger calls and step between +// them if a single client connects to multiple debuggers. +struct V8_EXPORT V8StackTraceId { + uintptr_t id; + std::pair<int64_t, int64_t> debugger_id; + + V8StackTraceId(); + V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id); + ~V8StackTraceId() = default; + + bool IsInvalid() const; +}; + +class V8_EXPORT V8Inspector { + public: + static std::unique_ptr<V8Inspector> create(v8::Isolate*, V8InspectorClient*); + virtual ~V8Inspector() = default; + + // Contexts instrumentation. + virtual void contextCreated(const V8ContextInfo&) = 0; + virtual void contextDestroyed(v8::Local<v8::Context>) = 0; + virtual void resetContextGroup(int contextGroupId) = 0; + virtual v8::MaybeLocal<v8::Context> contextById(int contextId) = 0; + + // Various instrumentation. + virtual void idleStarted() = 0; + virtual void idleFinished() = 0; + + // Async stack traces instrumentation. + virtual void asyncTaskScheduled(const StringView& taskName, void* task, + bool recurring) = 0; + virtual void asyncTaskCanceled(void* task) = 0; + virtual void asyncTaskStarted(void* task) = 0; + virtual void asyncTaskFinished(void* task) = 0; + virtual void allAsyncTasksCanceled() = 0; + + virtual V8StackTraceId storeCurrentStackTrace( + const StringView& description) = 0; + virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0; + virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0; + + // Exceptions instrumentation. + virtual unsigned exceptionThrown( + v8::Local<v8::Context>, const StringView& message, + v8::Local<v8::Value> exception, const StringView& detailedMessage, + const StringView& url, unsigned lineNumber, unsigned columnNumber, + std::unique_ptr<V8StackTrace>, int scriptId) = 0; + virtual void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId, + const StringView& message) = 0; + + // Connection. + class V8_EXPORT Channel { + public: + virtual ~Channel() = default; + virtual void sendResponse(int callId, + std::unique_ptr<StringBuffer> message) = 0; + virtual void sendNotification(std::unique_ptr<StringBuffer> message) = 0; + virtual void flushProtocolNotifications() = 0; + }; + virtual std::unique_ptr<V8InspectorSession> connect( + int contextGroupId, Channel*, const StringView& state) = 0; + + // API methods. + virtual std::unique_ptr<V8StackTrace> createStackTrace( + v8::Local<v8::StackTrace>) = 0; + virtual std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) = 0; +}; + +} // namespace v8_inspector + +#endif // V8_V8_INSPECTOR_H_ diff --git a/android/x86/include/v8/v8-internal.h b/android/x86/include/v8/v8-internal.h new file mode 100755 index 00000000..8e700a4d --- /dev/null +++ b/android/x86/include/v8/v8-internal.h @@ -0,0 +1,373 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef INCLUDE_V8_INTERNAL_H_ +#define INCLUDE_V8_INTERNAL_H_ + +#include <stddef.h> +#include <stdint.h> +#include <string.h> +#include <type_traits> + +#include "v8-version.h" // NOLINT(build/include) +#include "v8config.h" // NOLINT(build/include) + +namespace v8 { + +class Context; +class Data; +class Isolate; + +namespace internal { + +class Isolate; + +typedef uintptr_t Address; +static const Address kNullAddress = 0; + +/** + * Configuration of tagging scheme. + */ +const int kApiSystemPointerSize = sizeof(void*); +const int kApiDoubleSize = sizeof(double); +const int kApiInt32Size = sizeof(int32_t); +const int kApiInt64Size = sizeof(int64_t); + +// Tag information for HeapObject. +const int kHeapObjectTag = 1; +const int kWeakHeapObjectTag = 3; +const int kHeapObjectTagSize = 2; +const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; + +// Tag information for Smi. +const int kSmiTag = 0; +const int kSmiTagSize = 1; +const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; + +template <size_t tagged_ptr_size> +struct SmiTagging; + +// Smi constants for systems where tagged pointer is a 32-bit value. +template <> +struct SmiTagging<4> { + enum { kSmiShiftSize = 0, kSmiValueSize = 31 }; + V8_INLINE static int SmiToInt(const internal::Address value) { + int shift_bits = kSmiTagSize + kSmiShiftSize; + // Shift down (requires >> to be sign extending). + return static_cast<int>(static_cast<intptr_t>(value)) >> shift_bits; + } + V8_INLINE static constexpr bool IsValidSmi(intptr_t value) { + // To be representable as an tagged small integer, the two + // most-significant bits of 'value' must be either 00 or 11 due to + // sign-extension. To check this we add 01 to the two + // most-significant bits, and check if the most-significant bit is 0. + // + // CAUTION: The original code below: + // bool result = ((value + 0x40000000) & 0x80000000) == 0; + // may lead to incorrect results according to the C language spec, and + // in fact doesn't work correctly with gcc4.1.1 in some cases: The + // compiler may produce undefined results in case of signed integer + // overflow. The computation must be done w/ unsigned ints. + return static_cast<uintptr_t>(value) + 0x40000000U < 0x80000000U; + } +}; + +// Smi constants for systems where tagged pointer is a 64-bit value. +template <> +struct SmiTagging<8> { + enum { kSmiShiftSize = 31, kSmiValueSize = 32 }; + V8_INLINE static int SmiToInt(const internal::Address value) { + int shift_bits = kSmiTagSize + kSmiShiftSize; + // Shift down and throw away top 32 bits. + return static_cast<int>(static_cast<intptr_t>(value) >> shift_bits); + } + V8_INLINE static constexpr bool IsValidSmi(intptr_t value) { + // To be representable as a long smi, the value must be a 32-bit integer. + return (value == static_cast<int32_t>(value)); + } +}; + +#ifdef V8_COMPRESS_POINTERS +static_assert( + kApiSystemPointerSize == kApiInt64Size, + "Pointer compression can be enabled only for 64-bit architectures"); +const int kApiTaggedSize = kApiInt32Size; +#else +const int kApiTaggedSize = kApiSystemPointerSize; +#endif + +#ifdef V8_31BIT_SMIS_ON_64BIT_ARCH +typedef SmiTagging<kApiInt32Size> PlatformSmiTagging; +#else +typedef SmiTagging<kApiTaggedSize> PlatformSmiTagging; +#endif + +const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; +const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; +const int kSmiMinValue = (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1); +const int kSmiMaxValue = -(kSmiMinValue + 1); +constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; } +constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; } + +V8_INLINE static constexpr internal::Address IntToSmi(int value) { + return (static_cast<Address>(value) << (kSmiTagSize + kSmiShiftSize)) | + kSmiTag; +} + +/** + * This class exports constants and functionality from within v8 that + * is necessary to implement inline functions in the v8 api. Don't + * depend on functions and constants defined here. + */ +class Internals { + public: + // These values match non-compiler-dependent values defined within + // the implementation of v8. + static const int kHeapObjectMapOffset = 0; + static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiInt32Size; + static const int kStringResourceOffset = + 1 * kApiTaggedSize + 2 * kApiInt32Size; + + static const int kOddballKindOffset = 4 * kApiTaggedSize + kApiDoubleSize; + static const int kForeignAddressOffset = kApiTaggedSize; + static const int kJSObjectHeaderSize = 3 * kApiTaggedSize; + static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize; + static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize; + static const int kEmbedderDataSlotSize = kApiSystemPointerSize; + static const int kNativeContextEmbedderDataOffset = 7 * kApiTaggedSize; + static const int kFullStringRepresentationMask = 0x0f; + static const int kStringEncodingMask = 0x8; + static const int kExternalTwoByteRepresentationTag = 0x02; + static const int kExternalOneByteRepresentationTag = 0x0a; + + static const uint32_t kNumIsolateDataSlots = 4; + + static const int kIsolateEmbedderDataOffset = 0; + static const int kExternalMemoryOffset = + kNumIsolateDataSlots * kApiSystemPointerSize; + static const int kExternalMemoryLimitOffset = + kExternalMemoryOffset + kApiInt64Size; + static const int kExternalMemoryAtLastMarkCompactOffset = + kExternalMemoryLimitOffset + kApiInt64Size; + static const int kIsolateRootsOffset = + kExternalMemoryAtLastMarkCompactOffset + kApiInt64Size; + + static const int kUndefinedValueRootIndex = 4; + static const int kTheHoleValueRootIndex = 5; + static const int kNullValueRootIndex = 6; + static const int kTrueValueRootIndex = 7; + static const int kFalseValueRootIndex = 8; + static const int kEmptyStringRootIndex = 9; + + static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize; + static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3; + static const int kNodeStateMask = 0x7; + static const int kNodeStateIsWeakValue = 2; + static const int kNodeStateIsPendingValue = 3; + static const int kNodeIsIndependentShift = 3; + static const int kNodeIsActiveShift = 4; + + static const int kFirstNonstringType = 0x40; + static const int kOddballType = 0x43; + static const int kForeignType = 0x47; + static const int kJSSpecialApiObjectType = 0x410; + static const int kJSApiObjectType = 0x420; + static const int kJSObjectType = 0x421; + + static const int kUndefinedOddballKind = 5; + static const int kNullOddballKind = 3; + + // Constants used by PropertyCallbackInfo to check if we should throw when an + // error occurs. + static const int kThrowOnError = 0; + static const int kDontThrow = 1; + static const int kInferShouldThrowMode = 2; + + // Soft limit for AdjustAmountofExternalAllocatedMemory. Trigger an + // incremental GC once the external memory reaches this limit. + static constexpr int kExternalAllocationSoftLimit = 64 * 1024 * 1024; + + V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); + V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { +#ifdef V8_ENABLE_CHECKS + CheckInitializedImpl(isolate); +#endif + } + + V8_INLINE static bool HasHeapObjectTag(const internal::Address value) { + return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag); + } + + V8_INLINE static int SmiValue(const internal::Address value) { + return PlatformSmiTagging::SmiToInt(value); + } + + V8_INLINE static constexpr internal::Address IntToSmi(int value) { + return internal::IntToSmi(value); + } + + V8_INLINE static constexpr bool IsValidSmi(intptr_t value) { + return PlatformSmiTagging::IsValidSmi(value); + } + + V8_INLINE static int GetInstanceType(const internal::Address obj) { + typedef internal::Address A; + A map = ReadTaggedPointerField(obj, kHeapObjectMapOffset); + return ReadRawField<uint16_t>(map, kMapInstanceTypeOffset); + } + + V8_INLINE static int GetOddballKind(const internal::Address obj) { + return SmiValue(ReadTaggedSignedField(obj, kOddballKindOffset)); + } + + V8_INLINE static bool IsExternalTwoByteString(int instance_type) { + int representation = (instance_type & kFullStringRepresentationMask); + return representation == kExternalTwoByteRepresentationTag; + } + + V8_INLINE static uint8_t GetNodeFlag(internal::Address* obj, int shift) { + uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; + return *addr & static_cast<uint8_t>(1U << shift); + } + + V8_INLINE static void UpdateNodeFlag(internal::Address* obj, bool value, + int shift) { + uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; + uint8_t mask = static_cast<uint8_t>(1U << shift); + *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift)); + } + + V8_INLINE static uint8_t GetNodeState(internal::Address* obj) { + uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; + return *addr & kNodeStateMask; + } + + V8_INLINE static void UpdateNodeState(internal::Address* obj, uint8_t value) { + uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; + *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); + } + + V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot, + void* data) { + internal::Address addr = reinterpret_cast<internal::Address>(isolate) + + kIsolateEmbedderDataOffset + + slot * kApiSystemPointerSize; + *reinterpret_cast<void**>(addr) = data; + } + + V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate, + uint32_t slot) { + internal::Address addr = reinterpret_cast<internal::Address>(isolate) + + kIsolateEmbedderDataOffset + + slot * kApiSystemPointerSize; + return *reinterpret_cast<void* const*>(addr); + } + + V8_INLINE static internal::Address* GetRoot(v8::Isolate* isolate, int index) { + internal::Address addr = reinterpret_cast<internal::Address>(isolate) + + kIsolateRootsOffset + + index * kApiSystemPointerSize; + return reinterpret_cast<internal::Address*>(addr); + } + + template <typename T> + V8_INLINE static T ReadRawField(internal::Address heap_object_ptr, + int offset) { + internal::Address addr = heap_object_ptr + offset - kHeapObjectTag; +#ifdef V8_COMPRESS_POINTERS + if (sizeof(T) > kApiTaggedSize) { + // TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size + // fields (external pointers, doubles and BigInt data) are only + // kTaggedSize aligned so we have to use unaligned pointer friendly way of + // accessing them in order to avoid undefined behavior in C++ code. + T r; + memcpy(&r, reinterpret_cast<void*>(addr), sizeof(T)); + return r; + } +#endif + return *reinterpret_cast<const T*>(addr); + } + + V8_INLINE static internal::Address ReadTaggedPointerField( + internal::Address heap_object_ptr, int offset) { +#ifdef V8_COMPRESS_POINTERS + int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset); + internal::Address root = GetRootFromOnHeapAddress(heap_object_ptr); + return root + static_cast<internal::Address>(static_cast<intptr_t>(value)); +#else + return ReadRawField<internal::Address>(heap_object_ptr, offset); +#endif + } + + V8_INLINE static internal::Address ReadTaggedSignedField( + internal::Address heap_object_ptr, int offset) { +#ifdef V8_COMPRESS_POINTERS + int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset); + return static_cast<internal::Address>(static_cast<intptr_t>(value)); +#else + return ReadRawField<internal::Address>(heap_object_ptr, offset); +#endif + } + +#ifdef V8_COMPRESS_POINTERS + // See v8:7703 or src/ptr-compr.* for details about pointer compression. + static constexpr size_t kPtrComprHeapReservationSize = size_t{1} << 32; + static constexpr size_t kPtrComprIsolateRootBias = + kPtrComprHeapReservationSize / 2; + static constexpr size_t kPtrComprIsolateRootAlignment = size_t{1} << 32; + + V8_INLINE static internal::Address GetRootFromOnHeapAddress( + internal::Address addr) { + return (addr + kPtrComprIsolateRootBias) & + -static_cast<intptr_t>(kPtrComprIsolateRootAlignment); + } + + V8_INLINE static internal::Address DecompressTaggedAnyField( + internal::Address heap_object_ptr, int32_t value) { + internal::Address root_mask = static_cast<internal::Address>( + -static_cast<intptr_t>(value & kSmiTagMask)); + internal::Address root_or_zero = + root_mask & GetRootFromOnHeapAddress(heap_object_ptr); + return root_or_zero + + static_cast<internal::Address>(static_cast<intptr_t>(value)); + } +#endif // V8_COMPRESS_POINTERS +}; + +// Only perform cast check for types derived from v8::Data since +// other types do not implement the Cast method. +template <bool PerformCheck> +struct CastCheck { + template <class T> + static void Perform(T* data); +}; + +template <> +template <class T> +void CastCheck<true>::Perform(T* data) { + T::Cast(data); +} + +template <> +template <class T> +void CastCheck<false>::Perform(T* data) {} + +template <class T> +V8_INLINE void PerformCastCheck(T* data) { + CastCheck<std::is_base_of<Data, T>::value>::Perform(data); +} + +// {obj} must be the raw tagged pointer representation of a HeapObject +// that's guaranteed to never be in ReadOnlySpace. +V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj); + +// Returns if we need to throw when an error occurs. This infers the language +// mode based on the current context and the closure. This returns true if the +// language mode is strict. +V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate* isolate); + +} // namespace internal +} // namespace v8 + +#endif // INCLUDE_V8_INTERNAL_H_ diff --git a/android/x86/include/v8/v8-platform.h b/android/x86/include/v8/v8-platform.h new file mode 100755 index 00000000..556407d8 --- /dev/null +++ b/android/x86/include/v8/v8-platform.h @@ -0,0 +1,454 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_V8_PLATFORM_H_ +#define V8_V8_PLATFORM_H_ + +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> // For abort. +#include <memory> +#include <string> + +#include "v8config.h" // NOLINT(build/include) + +namespace v8 { + +class Isolate; + +/** + * A Task represents a unit of work. + */ +class Task { + public: + virtual ~Task() = default; + + virtual void Run() = 0; +}; + +/** + * An IdleTask represents a unit of work to be performed in idle time. + * The Run method is invoked with an argument that specifies the deadline in + * seconds returned by MonotonicallyIncreasingTime(). + * The idle task is expected to complete by this deadline. + */ +class IdleTask { + public: + virtual ~IdleTask() = default; + virtual void Run(double deadline_in_seconds) = 0; +}; + +/** + * A TaskRunner allows scheduling of tasks. The TaskRunner may still be used to + * post tasks after the isolate gets destructed, but these tasks may not get + * executed anymore. All tasks posted to a given TaskRunner will be invoked in + * sequence. Tasks can be posted from any thread. + */ +class TaskRunner { + public: + /** + * Schedules a task to be invoked by this TaskRunner. The TaskRunner + * implementation takes ownership of |task|. + */ + virtual void PostTask(std::unique_ptr<Task> task) = 0; + + /** + * Schedules a task to be invoked by this TaskRunner. The TaskRunner + * implementation takes ownership of |task|. The |task| cannot be nested + * within other task executions. + * + * Requires that |TaskRunner::NonNestableTasksEnabled()| is true. + */ + virtual void PostNonNestableTask(std::unique_ptr<Task> task) {} + + /** + * Schedules a task to be invoked by this TaskRunner. The task is scheduled + * after the given number of seconds |delay_in_seconds|. The TaskRunner + * implementation takes ownership of |task|. + */ + virtual void PostDelayedTask(std::unique_ptr<Task> task, + double delay_in_seconds) = 0; + + /** + * Schedules a task to be invoked by this TaskRunner. The task is scheduled + * after the given number of seconds |delay_in_seconds|. The TaskRunner + * implementation takes ownership of |task|. The |task| cannot be nested + * within other task executions. + * + * Requires that |TaskRunner::NonNestableDelayedTasksEnabled()| is true. + */ + virtual void PostNonNestableDelayedTask(std::unique_ptr<Task> task, + double delay_in_seconds) {} + + /** + * Schedules an idle task to be invoked by this TaskRunner. The task is + * scheduled when the embedder is idle. Requires that + * |TaskRunner::IdleTasksEnabled()| is true. Idle tasks may be reordered + * relative to other task types and may be starved for an arbitrarily long + * time if no idle time is available. The TaskRunner implementation takes + * ownership of |task|. + */ + virtual void PostIdleTask(std::unique_ptr<IdleTask> task) = 0; + + /** + * Returns true if idle tasks are enabled for this TaskRunner. + */ + virtual bool IdleTasksEnabled() = 0; + + /** + * Returns true if non-nestable tasks are enabled for this TaskRunner. + */ + virtual bool NonNestableTasksEnabled() const { return false; } + + /** + * Returns true if non-nestable delayed tasks are enabled for this TaskRunner. + */ + virtual bool NonNestableDelayedTasksEnabled() const { return false; } + + TaskRunner() = default; + virtual ~TaskRunner() = default; + + private: + TaskRunner(const TaskRunner&) = delete; + TaskRunner& operator=(const TaskRunner&) = delete; +}; + +/** + * The interface represents complex arguments to trace events. + */ +class ConvertableToTraceFormat { + public: + virtual ~ConvertableToTraceFormat() = default; + + /** + * Append the class info to the provided |out| string. The appended + * data must be a valid JSON object. Strings must be properly quoted, and + * escaped. There is no processing applied to the content after it is + * appended. + */ + virtual void AppendAsTraceFormat(std::string* out) const = 0; +}; + +/** + * V8 Tracing controller. + * + * Can be implemented by an embedder to record trace events from V8. + */ +class TracingController { + public: + virtual ~TracingController() = default; + + /** + * Called by TRACE_EVENT* macros, don't call this directly. + * The name parameter is a category group for example: + * TRACE_EVENT0("v8,parse", "V8.Parse") + * The pointer returned points to a value with zero or more of the bits + * defined in CategoryGroupEnabledFlags. + **/ + virtual const uint8_t* GetCategoryGroupEnabled(const char* name) { + static uint8_t no = 0; + return &no; + } + + /** + * Adds a trace event to the platform tracing system. These function calls are + * usually the result of a TRACE_* macro from trace_event_common.h when + * tracing and the category of the particular trace are enabled. It is not + * advisable to call these functions on their own; they are really only meant + * to be used by the trace macros. The returned handle can be used by + * UpdateTraceEventDuration to update the duration of COMPLETE events. + */ + virtual uint64_t AddTraceEvent( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr<ConvertableToTraceFormat>* arg_convertables, + unsigned int flags) { + return 0; + } + virtual uint64_t AddTraceEventWithTimestamp( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr<ConvertableToTraceFormat>* arg_convertables, + unsigned int flags, int64_t timestamp) { + return 0; + } + + /** + * Sets the duration field of a COMPLETE trace event. It must be called with + * the handle returned from AddTraceEvent(). + **/ + virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, + const char* name, uint64_t handle) {} + + class TraceStateObserver { + public: + virtual ~TraceStateObserver() = default; + virtual void OnTraceEnabled() = 0; + virtual void OnTraceDisabled() = 0; + }; + + /** Adds tracing state change observer. */ + virtual void AddTraceStateObserver(TraceStateObserver*) {} + + /** Removes tracing state change observer. */ + virtual void RemoveTraceStateObserver(TraceStateObserver*) {} +}; + +/** + * A V8 memory page allocator. + * + * Can be implemented by an embedder to manage large host OS allocations. + */ +class PageAllocator { + public: + virtual ~PageAllocator() = default; + + /** + * Gets the page granularity for AllocatePages and FreePages. Addresses and + * lengths for those calls should be multiples of AllocatePageSize(). + */ + virtual size_t AllocatePageSize() = 0; + + /** + * Gets the page granularity for SetPermissions and ReleasePages. Addresses + * and lengths for those calls should be multiples of CommitPageSize(). + */ + virtual size_t CommitPageSize() = 0; + + /** + * Sets the random seed so that GetRandomMmapAddr() will generate repeatable + * sequences of random mmap addresses. + */ + virtual void SetRandomMmapSeed(int64_t seed) = 0; + + /** + * Returns a randomized address, suitable for memory allocation under ASLR. + * The address will be aligned to AllocatePageSize. + */ + virtual void* GetRandomMmapAddr() = 0; + + /** + * Memory permissions. + */ + enum Permission { + kNoAccess, + kRead, + kReadWrite, + // TODO(hpayer): Remove this flag. Memory should never be rwx. + kReadWriteExecute, + kReadExecute + }; + + /** + * Allocates memory in range with the given alignment and permission. + */ + virtual void* AllocatePages(void* address, size_t length, size_t alignment, + Permission permissions) = 0; + + /** + * Frees memory in a range that was allocated by a call to AllocatePages. + */ + virtual bool FreePages(void* address, size_t length) = 0; + + /** + * Releases memory in a range that was allocated by a call to AllocatePages. + */ + virtual bool ReleasePages(void* address, size_t length, + size_t new_length) = 0; + + /** + * Sets permissions on pages in an allocated range. + */ + virtual bool SetPermissions(void* address, size_t length, + Permission permissions) = 0; + + /** + * Frees memory in the given [address, address + size) range. address and size + * should be operating system page-aligned. The next write to this + * memory area brings the memory transparently back. + */ + virtual bool DiscardSystemPages(void* address, size_t size) { return true; } +}; + +/** + * V8 Platform abstraction layer. + * + * The embedder has to provide an implementation of this interface before + * initializing the rest of V8. + */ +class Platform { + public: + virtual ~Platform() = default; + + /** + * Allows the embedder to manage memory page allocations. + */ + virtual PageAllocator* GetPageAllocator() { + // TODO(bbudge) Make this abstract after all embedders implement this. + return nullptr; + } + + /** + * Enables the embedder to respond in cases where V8 can't allocate large + * blocks of memory. V8 retries the failed allocation once after calling this + * method. On success, execution continues; otherwise V8 exits with a fatal + * error. + * Embedder overrides of this function must NOT call back into V8. + */ + virtual void OnCriticalMemoryPressure() { + // TODO(bbudge) Remove this when embedders override the following method. + // See crbug.com/634547. + } + + /** + * Enables the embedder to respond in cases where V8 can't allocate large + * memory regions. The |length| parameter is the amount of memory needed. + * Returns true if memory is now available. Returns false if no memory could + * be made available. V8 will retry allocations until this method returns + * false. + * + * Embedder overrides of this function must NOT call back into V8. + */ + virtual bool OnCriticalMemoryPressure(size_t length) { return false; } + + /** + * Gets the number of worker threads used by + * Call(BlockingTask)OnWorkerThread(). This can be used to estimate the number + * of tasks a work package should be split into. A return value of 0 means + * that there are no worker threads available. Note that a value of 0 won't + * prohibit V8 from posting tasks using |CallOnWorkerThread|. + */ + virtual int NumberOfWorkerThreads() = 0; + + /** + * Returns a TaskRunner which can be used to post a task on the foreground. + * This function should only be called from a foreground thread. + */ + virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner( + Isolate* isolate) = 0; + + /** + * Schedules a task to be invoked on a worker thread. + */ + virtual void CallOnWorkerThread(std::unique_ptr<Task> task) = 0; + + /** + * Schedules a task that blocks the main thread to be invoked with + * high-priority on a worker thread. + */ + virtual void CallBlockingTaskOnWorkerThread(std::unique_ptr<Task> task) { + // Embedders may optionally override this to process these tasks in a high + // priority pool. + CallOnWorkerThread(std::move(task)); + } + + /** + * Schedules a task to be invoked with low-priority on a worker thread. + */ + virtual void CallLowPriorityTaskOnWorkerThread(std::unique_ptr<Task> task) { + // Embedders may optionally override this to process these tasks in a low + // priority pool. + CallOnWorkerThread(std::move(task)); + } + + /** + * Schedules a task to be invoked on a worker thread after |delay_in_seconds| + * expires. + */ + virtual void CallDelayedOnWorkerThread(std::unique_ptr<Task> task, + double delay_in_seconds) = 0; + + /** + * Schedules a task to be invoked on a foreground thread wrt a specific + * |isolate|. Tasks posted for the same isolate should be execute in order of + * scheduling. The definition of "foreground" is opaque to V8. + */ + V8_DEPRECATE_SOON( + "Use a taskrunner acquired by GetForegroundTaskRunner instead.", + virtual void CallOnForegroundThread(Isolate* isolate, Task* task)) = 0; + + /** + * Schedules a task to be invoked on a foreground thread wrt a specific + * |isolate| after the given number of seconds |delay_in_seconds|. + * Tasks posted for the same isolate should be execute in order of + * scheduling. The definition of "foreground" is opaque to V8. + */ + V8_DEPRECATE_SOON( + "Use a taskrunner acquired by GetForegroundTaskRunner instead.", + virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task, + double delay_in_seconds)) = 0; + + /** + * Schedules a task to be invoked on a foreground thread wrt a specific + * |isolate| when the embedder is idle. + * Requires that SupportsIdleTasks(isolate) is true. + * Idle tasks may be reordered relative to other task types and may be + * starved for an arbitrarily long time if no idle time is available. + * The definition of "foreground" is opaque to V8. + */ + V8_DEPRECATE_SOON( + "Use a taskrunner acquired by GetForegroundTaskRunner instead.", + virtual void CallIdleOnForegroundThread(Isolate* isolate, + IdleTask* task)) { + // This must be overriden if |IdleTasksEnabled()|. + abort(); + } + + /** + * Returns true if idle tasks are enabled for the given |isolate|. + */ + virtual bool IdleTasksEnabled(Isolate* isolate) { + return false; + } + + /** + * Monotonically increasing time in seconds from an arbitrary fixed point in + * the past. This function is expected to return at least + * millisecond-precision values. For this reason, + * it is recommended that the fixed point be no further in the past than + * the epoch. + **/ + virtual double MonotonicallyIncreasingTime() = 0; + + /** + * Current wall-clock time in milliseconds since epoch. + * This function is expected to return at least millisecond-precision values. + */ + virtual double CurrentClockTimeMillis() = 0; + + typedef void (*StackTracePrinter)(); + + /** + * Returns a function pointer that print a stack trace of the current stack + * on invocation. Disables printing of the stack trace if nullptr. + */ + virtual StackTracePrinter GetStackTracePrinter() { return nullptr; } + + /** + * Returns an instance of a v8::TracingController. This must be non-nullptr. + */ + virtual TracingController* GetTracingController() = 0; + + /** + * Tells the embedder to generate and upload a crashdump during an unexpected + * but non-critical scenario. + */ + virtual void DumpWithoutCrashing() {} + + protected: + /** + * Default implementation of current wall-clock time in milliseconds + * since epoch. Useful for implementing |CurrentClockTimeMillis| if + * nothing special needed. + */ + V8_EXPORT static double SystemClockTimeMillis(); +}; + +} // namespace v8 + +#endif // V8_V8_PLATFORM_H_ diff --git a/android/x86/include/v8/v8-profiler.h b/android/x86/include/v8/v8-profiler.h new file mode 100755 index 00000000..672a694e --- /dev/null +++ b/android/x86/include/v8/v8-profiler.h @@ -0,0 +1,1039 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_V8_PROFILER_H_ +#define V8_V8_PROFILER_H_ + +#include <unordered_set> +#include <vector> +#include "v8.h" // NOLINT(build/include) + +/** + * Profiler support for the V8 JavaScript engine. + */ +namespace v8 { + +class HeapGraphNode; +struct HeapStatsUpdate; + +typedef uint32_t SnapshotObjectId; + + +struct CpuProfileDeoptFrame { + int script_id; + size_t position; +}; + +} // namespace v8 + +#ifdef V8_OS_WIN +template class V8_EXPORT std::vector<v8::CpuProfileDeoptFrame>; +#endif + +namespace v8 { + +struct V8_EXPORT CpuProfileDeoptInfo { + /** A pointer to a static string owned by v8. */ + const char* deopt_reason; + std::vector<CpuProfileDeoptFrame> stack; +}; + +} // namespace v8 + +#ifdef V8_OS_WIN +template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>; +#endif + +namespace v8 { + +// TickSample captures the information collected for each sample. +struct V8_EXPORT TickSample { + // Internal profiling (with --prof + tools/$OS-tick-processor) wants to + // include the runtime function we're calling. Externally exposed tick + // samples don't care. + enum RecordCEntryFrame { kIncludeCEntryFrame, kSkipCEntryFrame }; + + TickSample() + : state(OTHER), + pc(nullptr), + external_callback_entry(nullptr), + frames_count(0), + has_external_callback(false), + update_stats(true) {} + + /** + * Initialize a tick sample from the isolate. + * \param isolate The isolate. + * \param state Execution state. + * \param record_c_entry_frame Include or skip the runtime function. + * \param update_stats Whether update the sample to the aggregated stats. + * \param use_simulator_reg_state When set to true and V8 is running under a + * simulator, the method will use the simulator + * register state rather than the one provided + * with |state| argument. Otherwise the method + * will use provided register |state| as is. + */ + void Init(Isolate* isolate, const v8::RegisterState& state, + RecordCEntryFrame record_c_entry_frame, bool update_stats, + bool use_simulator_reg_state = true); + /** + * Get a call stack sample from the isolate. + * \param isolate The isolate. + * \param state Register state. + * \param record_c_entry_frame Include or skip the runtime function. + * \param frames Caller allocated buffer to store stack frames. + * \param frames_limit Maximum number of frames to capture. The buffer must + * be large enough to hold the number of frames. + * \param sample_info The sample info is filled up by the function + * provides number of actual captured stack frames and + * the current VM state. + * \param use_simulator_reg_state When set to true and V8 is running under a + * simulator, the method will use the simulator + * register state rather than the one provided + * with |state| argument. Otherwise the method + * will use provided register |state| as is. + * \note GetStackSample is thread and signal safe and should only be called + * when the JS thread is paused or interrupted. + * Otherwise the behavior is undefined. + */ + static bool GetStackSample(Isolate* isolate, v8::RegisterState* state, + RecordCEntryFrame record_c_entry_frame, + void** frames, size_t frames_limit, + v8::SampleInfo* sample_info, + bool use_simulator_reg_state = true); + StateTag state; // The state of the VM. + void* pc; // Instruction pointer. + union { + void* tos; // Top stack value (*sp). + void* external_callback_entry; + }; + static const unsigned kMaxFramesCountLog2 = 8; + static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; + void* stack[kMaxFramesCount]; // Call stack. + unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. + bool has_external_callback : 1; + bool update_stats : 1; // Whether the sample should update aggregated stats. +}; + +/** + * CpuProfileNode represents a node in a call graph. + */ +class V8_EXPORT CpuProfileNode { + public: + struct LineTick { + /** The 1-based number of the source line where the function originates. */ + int line; + + /** The count of samples associated with the source line. */ + unsigned int hit_count; + }; + + // An annotation hinting at the source of a CpuProfileNode. + enum SourceType { + // User-supplied script with associated resource information. + kScript = 0, + // Native scripts and provided builtins. + kBuiltin = 1, + // Callbacks into native code. + kCallback = 2, + // VM-internal functions or state. + kInternal = 3, + // A node that failed to symbolize. + kUnresolved = 4, + }; + + /** Returns function name (empty string for anonymous functions.) */ + Local<String> GetFunctionName() const; + + /** + * Returns function name (empty string for anonymous functions.) + * The string ownership is *not* passed to the caller. It stays valid until + * profile is deleted. The function is thread safe. + */ + const char* GetFunctionNameStr() const; + + /** Returns id of the script where function is located. */ + int GetScriptId() const; + + /** Returns resource name for script from where the function originates. */ + Local<String> GetScriptResourceName() const; + + /** + * Returns resource name for script from where the function originates. + * The string ownership is *not* passed to the caller. It stays valid until + * profile is deleted. The function is thread safe. + */ + const char* GetScriptResourceNameStr() const; + + /** + * Return true if the script from where the function originates is flagged as + * being shared cross-origin. + */ + bool IsScriptSharedCrossOrigin() const; + + /** + * Returns the number, 1-based, of the line where the function originates. + * kNoLineNumberInfo if no line number information is available. + */ + int GetLineNumber() const; + + /** + * Returns 1-based number of the column where the function originates. + * kNoColumnNumberInfo if no column number information is available. + */ + int GetColumnNumber() const; + + /** + * Returns the number of the function's source lines that collect the samples. + */ + unsigned int GetHitLineCount() const; + + /** Returns the set of source lines that collect the samples. + * The caller allocates buffer and responsible for releasing it. + * True if all available entries are copied, otherwise false. + * The function copies nothing if buffer is not large enough. + */ + bool GetLineTicks(LineTick* entries, unsigned int length) const; + + /** Returns bailout reason for the function + * if the optimization was disabled for it. + */ + const char* GetBailoutReason() const; + + /** + * Returns the count of samples where the function was currently executing. + */ + unsigned GetHitCount() const; + + /** Returns function entry UID. */ + V8_DEPRECATE_SOON( + "Use GetScriptId, GetLineNumber, and GetColumnNumber instead.", + unsigned GetCallUid() const); + + /** Returns id of the node. The id is unique within the tree */ + unsigned GetNodeId() const; + + /** + * Gets the type of the source which the node was captured from. + */ + SourceType GetSourceType() const; + + /** Returns child nodes count of the node. */ + int GetChildrenCount() const; + + /** Retrieves a child node by index. */ + const CpuProfileNode* GetChild(int index) const; + + /** Retrieves the ancestor node, or null if the root. */ + const CpuProfileNode* GetParent() const; + + /** Retrieves deopt infos for the node. */ + const std::vector<CpuProfileDeoptInfo>& GetDeoptInfos() const; + + static const int kNoLineNumberInfo = Message::kNoLineNumberInfo; + static const int kNoColumnNumberInfo = Message::kNoColumnInfo; +}; + + +/** + * CpuProfile contains a CPU profile in a form of top-down call tree + * (from main() down to functions that do all the work). + */ +class V8_EXPORT CpuProfile { + public: + /** Returns CPU profile title. */ + Local<String> GetTitle() const; + + /** Returns the root node of the top down call tree. */ + const CpuProfileNode* GetTopDownRoot() const; + + /** + * Returns number of samples recorded. The samples are not recorded unless + * |record_samples| parameter of CpuProfiler::StartCpuProfiling is true. + */ + int GetSamplesCount() const; + + /** + * Returns profile node corresponding to the top frame the sample at + * the given index. + */ + const CpuProfileNode* GetSample(int index) const; + + /** + * Returns the timestamp of the sample. The timestamp is the number of + * microseconds since some unspecified starting point. + * The point is equal to the starting point used by GetStartTime. + */ + int64_t GetSampleTimestamp(int index) const; + + /** + * Returns time when the profile recording was started (in microseconds) + * since some unspecified starting point. + */ + int64_t GetStartTime() const; + + /** + * Returns time when the profile recording was stopped (in microseconds) + * since some unspecified starting point. + * The point is equal to the starting point used by GetStartTime. + */ + int64_t GetEndTime() const; + + /** + * Deletes the profile and removes it from CpuProfiler's list. + * All pointers to nodes previously returned become invalid. + */ + void Delete(); +}; + +enum CpuProfilingMode { + // In the resulting CpuProfile tree, intermediate nodes in a stack trace + // (from the root to a leaf) will have line numbers that point to the start + // line of the function, rather than the line of the callsite of the child. + kLeafNodeLineNumbers, + // In the resulting CpuProfile tree, nodes are separated based on the line + // number of their callsite in their parent. + kCallerLineNumbers, +}; + +/** + * Interface for controlling CPU profiling. Instance of the + * profiler can be created using v8::CpuProfiler::New method. + */ +class V8_EXPORT CpuProfiler { + public: + /** + * Creates a new CPU profiler for the |isolate|. The isolate must be + * initialized. The profiler object must be disposed after use by calling + * |Dispose| method. + */ + static CpuProfiler* New(Isolate* isolate); + + /** + * Synchronously collect current stack sample in all profilers attached to + * the |isolate|. The call does not affect number of ticks recorded for + * the current top node. + */ + static void CollectSample(Isolate* isolate); + + /** + * Disposes the CPU profiler object. + */ + void Dispose(); + + /** + * Changes default CPU profiler sampling interval to the specified number + * of microseconds. Default interval is 1000us. This method must be called + * when there are no profiles being recorded. + */ + void SetSamplingInterval(int us); + + /** + * Sets whether or not the profiler should prioritize consistency of sample + * periodicity on Windows. Disabling this can greatly reduce CPU usage, but + * may result in greater variance in sample timings from the platform's + * scheduler. Defaults to enabled. This method must be called when there are + * no profiles being recorded. + */ + void SetUsePreciseSampling(bool); + + /** + * Starts collecting CPU profile. Title may be an empty string. It + * is allowed to have several profiles being collected at + * once. Attempts to start collecting several profiles with the same + * title are silently ignored. While collecting a profile, functions + * from all security contexts are included in it. The token-based + * filtering is only performed when querying for a profile. + * + * |record_samples| parameter controls whether individual samples should + * be recorded in addition to the aggregated tree. + */ + void StartProfiling(Local<String> title, CpuProfilingMode mode, + bool record_samples = false); + /** + * The same as StartProfiling above, but the CpuProfilingMode defaults to + * kLeafNodeLineNumbers mode, which was the previous default behavior of the + * profiler. + */ + void StartProfiling(Local<String> title, bool record_samples = false); + + /** + * Stops collecting CPU profile with a given title and returns it. + * If the title given is empty, finishes the last profile started. + */ + CpuProfile* StopProfiling(Local<String> title); + + /** + * Force collection of a sample. Must be called on the VM thread. + * Recording the forced sample does not contribute to the aggregated + * profile statistics. + */ + V8_DEPRECATED("Use static CollectSample(Isolate*) instead.", + void CollectSample()); + + /** + * Tells the profiler whether the embedder is idle. + */ + V8_DEPRECATED("Use Isolate::SetIdle(bool) instead.", + void SetIdle(bool is_idle)); + + /** + * Generate more detailed source positions to code objects. This results in + * better results when mapping profiling samples to script source. + */ + static void UseDetailedSourcePositionsForProfiling(Isolate* isolate); + + private: + CpuProfiler(); + ~CpuProfiler(); + CpuProfiler(const CpuProfiler&); + CpuProfiler& operator=(const CpuProfiler&); +}; + + +/** + * HeapSnapshotEdge represents a directed connection between heap + * graph nodes: from retainers to retained nodes. + */ +class V8_EXPORT HeapGraphEdge { + public: + enum Type { + kContextVariable = 0, // A variable from a function context. + kElement = 1, // An element of an array. + kProperty = 2, // A named object property. + kInternal = 3, // A link that can't be accessed from JS, + // thus, its name isn't a real property name + // (e.g. parts of a ConsString). + kHidden = 4, // A link that is needed for proper sizes + // calculation, but may be hidden from user. + kShortcut = 5, // A link that must not be followed during + // sizes calculation. + kWeak = 6 // A weak reference (ignored by the GC). + }; + + /** Returns edge type (see HeapGraphEdge::Type). */ + Type GetType() const; + + /** + * Returns edge name. This can be a variable name, an element index, or + * a property name. + */ + Local<Value> GetName() const; + + /** Returns origin node. */ + const HeapGraphNode* GetFromNode() const; + + /** Returns destination node. */ + const HeapGraphNode* GetToNode() const; +}; + + +/** + * HeapGraphNode represents a node in a heap graph. + */ +class V8_EXPORT HeapGraphNode { + public: + enum Type { + kHidden = 0, // Hidden node, may be filtered when shown to user. + kArray = 1, // An array of elements. + kString = 2, // A string. + kObject = 3, // A JS object (except for arrays and strings). + kCode = 4, // Compiled code. + kClosure = 5, // Function closure. + kRegExp = 6, // RegExp. + kHeapNumber = 7, // Number stored in the heap. + kNative = 8, // Native object (not from V8 heap). + kSynthetic = 9, // Synthetic object, usually used for grouping + // snapshot items together. + kConsString = 10, // Concatenated string. A pair of pointers to strings. + kSlicedString = 11, // Sliced string. A fragment of another string. + kSymbol = 12, // A Symbol (ES6). + kBigInt = 13 // BigInt. + }; + + /** Returns node type (see HeapGraphNode::Type). */ + Type GetType() const; + + /** + * Returns node name. Depending on node's type this can be the name + * of the constructor (for objects), the name of the function (for + * closures), string value, or an empty string (for compiled code). + */ + Local<String> GetName() const; + + /** + * Returns node id. For the same heap object, the id remains the same + * across all snapshots. + */ + SnapshotObjectId GetId() const; + + /** Returns node's own size, in bytes. */ + size_t GetShallowSize() const; + + /** Returns child nodes count of the node. */ + int GetChildrenCount() const; + + /** Retrieves a child by index. */ + const HeapGraphEdge* GetChild(int index) const; +}; + + +/** + * An interface for exporting data from V8, using "push" model. + */ +class V8_EXPORT OutputStream { // NOLINT + public: + enum WriteResult { + kContinue = 0, + kAbort = 1 + }; + virtual ~OutputStream() = default; + /** Notify about the end of stream. */ + virtual void EndOfStream() = 0; + /** Get preferred output chunk size. Called only once. */ + virtual int GetChunkSize() { return 1024; } + /** + * Writes the next chunk of snapshot data into the stream. Writing + * can be stopped by returning kAbort as function result. EndOfStream + * will not be called in case writing was aborted. + */ + virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; + /** + * Writes the next chunk of heap stats data into the stream. Writing + * can be stopped by returning kAbort as function result. EndOfStream + * will not be called in case writing was aborted. + */ + virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) { + return kAbort; + } +}; + + +/** + * HeapSnapshots record the state of the JS heap at some moment. + */ +class V8_EXPORT HeapSnapshot { + public: + enum SerializationFormat { + kJSON = 0 // See format description near 'Serialize' method. + }; + + /** Returns the root node of the heap graph. */ + const HeapGraphNode* GetRoot() const; + + /** Returns a node by its id. */ + const HeapGraphNode* GetNodeById(SnapshotObjectId id) const; + + /** Returns total nodes count in the snapshot. */ + int GetNodesCount() const; + + /** Returns a node by index. */ + const HeapGraphNode* GetNode(int index) const; + + /** Returns a max seen JS object Id. */ + SnapshotObjectId GetMaxSnapshotJSObjectId() const; + + /** + * Deletes the snapshot and removes it from HeapProfiler's list. + * All pointers to nodes, edges and paths previously returned become + * invalid. + */ + void Delete(); + + /** + * Prepare a serialized representation of the snapshot. The result + * is written into the stream provided in chunks of specified size. + * The total length of the serialized snapshot is unknown in + * advance, it can be roughly equal to JS heap size (that means, + * it can be really big - tens of megabytes). + * + * For the JSON format, heap contents are represented as an object + * with the following structure: + * + * { + * snapshot: { + * title: "...", + * uid: nnn, + * meta: { meta-info }, + * node_count: nnn, + * edge_count: nnn + * }, + * nodes: [nodes array], + * edges: [edges array], + * strings: [strings array] + * } + * + * Nodes reference strings, other nodes, and edges by their indexes + * in corresponding arrays. + */ + void Serialize(OutputStream* stream, + SerializationFormat format = kJSON) const; +}; + + +/** + * An interface for reporting progress and controlling long-running + * activities. + */ +class V8_EXPORT ActivityControl { // NOLINT + public: + enum ControlOption { + kContinue = 0, + kAbort = 1 + }; + virtual ~ActivityControl() = default; + /** + * Notify about current progress. The activity can be stopped by + * returning kAbort as the callback result. + */ + virtual ControlOption ReportProgressValue(int done, int total) = 0; +}; + + +/** + * AllocationProfile is a sampled profile of allocations done by the program. + * This is structured as a call-graph. + */ +class V8_EXPORT AllocationProfile { + public: + struct Allocation { + /** + * Size of the sampled allocation object. + */ + size_t size; + + /** + * The number of objects of such size that were sampled. + */ + unsigned int count; + }; + + /** + * Represents a node in the call-graph. + */ + struct Node { + /** + * Name of the function. May be empty for anonymous functions or if the + * script corresponding to this function has been unloaded. + */ + Local<String> name; + + /** + * Name of the script containing the function. May be empty if the script + * name is not available, or if the script has been unloaded. + */ + Local<String> script_name; + + /** + * id of the script where the function is located. May be equal to + * v8::UnboundScript::kNoScriptId in cases where the script doesn't exist. + */ + int script_id; + + /** + * Start position of the function in the script. + */ + int start_position; + + /** + * 1-indexed line number where the function starts. May be + * kNoLineNumberInfo if no line number information is available. + */ + int line_number; + + /** + * 1-indexed column number where the function starts. May be + * kNoColumnNumberInfo if no line number information is available. + */ + int column_number; + + /** + * Unique id of the node. + */ + uint32_t node_id; + + /** + * List of callees called from this node for which we have sampled + * allocations. The lifetime of the children is scoped to the containing + * AllocationProfile. + */ + std::vector<Node*> children; + + /** + * List of self allocations done by this node in the call-graph. + */ + std::vector<Allocation> allocations; + }; + + /** + * Represent a single sample recorded for an allocation. + */ + struct Sample { + /** + * id of the node in the profile tree. + */ + uint32_t node_id; + + /** + * Size of the sampled allocation object. + */ + size_t size; + + /** + * The number of objects of such size that were sampled. + */ + unsigned int count; + + /** + * Unique time-ordered id of the allocation sample. Can be used to track + * what samples were added or removed between two snapshots. + */ + uint64_t sample_id; + }; + + /** + * Returns the root node of the call-graph. The root node corresponds to an + * empty JS call-stack. The lifetime of the returned Node* is scoped to the + * containing AllocationProfile. + */ + virtual Node* GetRootNode() = 0; + virtual const std::vector<Sample>& GetSamples() = 0; + + virtual ~AllocationProfile() = default; + + static const int kNoLineNumberInfo = Message::kNoLineNumberInfo; + static const int kNoColumnNumberInfo = Message::kNoColumnInfo; +}; + +/** + * An object graph consisting of embedder objects and V8 objects. + * Edges of the graph are strong references between the objects. + * The embedder can build this graph during heap snapshot generation + * to include the embedder objects in the heap snapshot. + * Usage: + * 1) Define derived class of EmbedderGraph::Node for embedder objects. + * 2) Set the build embedder graph callback on the heap profiler using + * HeapProfiler::AddBuildEmbedderGraphCallback. + * 3) In the callback use graph->AddEdge(node1, node2) to add an edge from + * node1 to node2. + * 4) To represent references from/to V8 object, construct V8 nodes using + * graph->V8Node(value). + */ +class V8_EXPORT EmbedderGraph { + public: + class Node { + public: + Node() = default; + virtual ~Node() = default; + virtual const char* Name() = 0; + virtual size_t SizeInBytes() = 0; + /** + * The corresponding V8 wrapper node if not null. + * During heap snapshot generation the embedder node and the V8 wrapper + * node will be merged into one node to simplify retaining paths. + */ + virtual Node* WrapperNode() { return nullptr; } + virtual bool IsRootNode() { return false; } + /** Must return true for non-V8 nodes. */ + virtual bool IsEmbedderNode() { return true; } + /** + * Optional name prefix. It is used in Chrome for tagging detached nodes. + */ + virtual const char* NamePrefix() { return nullptr; } + + private: + Node(const Node&) = delete; + Node& operator=(const Node&) = delete; + }; + + /** + * Returns a node corresponding to the given V8 value. Ownership is not + * transferred. The result pointer is valid while the graph is alive. + */ + virtual Node* V8Node(const v8::Local<v8::Value>& value) = 0; + + /** + * Adds the given node to the graph and takes ownership of the node. + * Returns a raw pointer to the node that is valid while the graph is alive. + */ + virtual Node* AddNode(std::unique_ptr<Node> node) = 0; + + /** + * Adds an edge that represents a strong reference from the given + * node |from| to the given node |to|. The nodes must be added to the graph + * before calling this function. + * + * If name is nullptr, the edge will have auto-increment indexes, otherwise + * it will be named accordingly. + */ + virtual void AddEdge(Node* from, Node* to, const char* name = nullptr) = 0; + + virtual ~EmbedderGraph() = default; +}; + +/** + * Interface for controlling heap profiling. Instance of the + * profiler can be retrieved using v8::Isolate::GetHeapProfiler. + */ +class V8_EXPORT HeapProfiler { + public: + enum SamplingFlags { + kSamplingNoFlags = 0, + kSamplingForceGC = 1 << 0, + }; + + /** + * Callback function invoked during heap snapshot generation to retrieve + * the embedder object graph. The callback should use graph->AddEdge(..) to + * add references between the objects. + * The callback must not trigger garbage collection in V8. + */ + typedef void (*BuildEmbedderGraphCallback)(v8::Isolate* isolate, + v8::EmbedderGraph* graph, + void* data); + + /** Returns the number of snapshots taken. */ + int GetSnapshotCount(); + + /** Returns a snapshot by index. */ + const HeapSnapshot* GetHeapSnapshot(int index); + + /** + * Returns SnapshotObjectId for a heap object referenced by |value| if + * it has been seen by the heap profiler, kUnknownObjectId otherwise. + */ + SnapshotObjectId GetObjectId(Local<Value> value); + + /** + * Returns heap object with given SnapshotObjectId if the object is alive, + * otherwise empty handle is returned. + */ + Local<Value> FindObjectById(SnapshotObjectId id); + + /** + * Clears internal map from SnapshotObjectId to heap object. The new objects + * will not be added into it unless a heap snapshot is taken or heap object + * tracking is kicked off. + */ + void ClearObjectIds(); + + /** + * A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return + * it in case heap profiler cannot find id for the object passed as + * parameter. HeapSnapshot::GetNodeById will always return NULL for such id. + */ + static const SnapshotObjectId kUnknownObjectId = 0; + + /** + * Callback interface for retrieving user friendly names of global objects. + */ + class ObjectNameResolver { + public: + /** + * Returns name to be used in the heap snapshot for given node. Returned + * string must stay alive until snapshot collection is completed. + */ + virtual const char* GetName(Local<Object> object) = 0; + + protected: + virtual ~ObjectNameResolver() = default; + }; + + /** + * Takes a heap snapshot and returns it. + */ + const HeapSnapshot* TakeHeapSnapshot( + ActivityControl* control = nullptr, + ObjectNameResolver* global_object_name_resolver = nullptr); + + /** + * Starts tracking of heap objects population statistics. After calling + * this method, all heap objects relocations done by the garbage collector + * are being registered. + * + * |track_allocations| parameter controls whether stack trace of each + * allocation in the heap will be recorded and reported as part of + * HeapSnapshot. + */ + void StartTrackingHeapObjects(bool track_allocations = false); + + /** + * Adds a new time interval entry to the aggregated statistics array. The + * time interval entry contains information on the current heap objects + * population size. The method also updates aggregated statistics and + * reports updates for all previous time intervals via the OutputStream + * object. Updates on each time interval are provided as a stream of the + * HeapStatsUpdate structure instances. + * If |timestamp_us| is supplied, timestamp of the new entry will be written + * into it. The return value of the function is the last seen heap object Id. + * + * StartTrackingHeapObjects must be called before the first call to this + * method. + */ + SnapshotObjectId GetHeapStats(OutputStream* stream, + int64_t* timestamp_us = nullptr); + + /** + * Stops tracking of heap objects population statistics, cleans up all + * collected data. StartHeapObjectsTracking must be called again prior to + * calling GetHeapStats next time. + */ + void StopTrackingHeapObjects(); + + /** + * Starts gathering a sampling heap profile. A sampling heap profile is + * similar to tcmalloc's heap profiler and Go's mprof. It samples object + * allocations and builds an online 'sampling' heap profile. At any point in + * time, this profile is expected to be a representative sample of objects + * currently live in the system. Each sampled allocation includes the stack + * trace at the time of allocation, which makes this really useful for memory + * leak detection. + * + * This mechanism is intended to be cheap enough that it can be used in + * production with minimal performance overhead. + * + * Allocations are sampled using a randomized Poisson process. On average, one + * allocation will be sampled every |sample_interval| bytes allocated. The + * |stack_depth| parameter controls the maximum number of stack frames to be + * captured on each allocation. + * + * NOTE: This is a proof-of-concept at this point. Right now we only sample + * newspace allocations. Support for paged space allocation (e.g. pre-tenured + * objects, large objects, code objects, etc.) and native allocations + * doesn't exist yet, but is anticipated in the future. + * + * Objects allocated before the sampling is started will not be included in + * the profile. + * + * Returns false if a sampling heap profiler is already running. + */ + bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024, + int stack_depth = 16, + SamplingFlags flags = kSamplingNoFlags); + + /** + * Stops the sampling heap profile and discards the current profile. + */ + void StopSamplingHeapProfiler(); + + /** + * Returns the sampled profile of allocations allocated (and still live) since + * StartSamplingHeapProfiler was called. The ownership of the pointer is + * transferred to the caller. Returns nullptr if sampling heap profiler is not + * active. + */ + AllocationProfile* GetAllocationProfile(); + + /** + * Deletes all snapshots taken. All previously returned pointers to + * snapshots and their contents become invalid after this call. + */ + void DeleteAllHeapSnapshots(); + + void AddBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback, + void* data); + void RemoveBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback, + void* data); + + /** + * Default value of persistent handle class ID. Must not be used to + * define a class. Can be used to reset a class of a persistent + * handle. + */ + static const uint16_t kPersistentHandleNoClassId = 0; + + private: + HeapProfiler(); + ~HeapProfiler(); + HeapProfiler(const HeapProfiler&); + HeapProfiler& operator=(const HeapProfiler&); +}; + +/** + * A struct for exporting HeapStats data from V8, using "push" model. + * See HeapProfiler::GetHeapStats. + */ +struct HeapStatsUpdate { + HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size) + : index(index), count(count), size(size) { } + uint32_t index; // Index of the time interval that was changed. + uint32_t count; // New value of count field for the interval with this index. + uint32_t size; // New value of size field for the interval with this index. +}; + +#define CODE_EVENTS_LIST(V) \ + V(Builtin) \ + V(Callback) \ + V(Eval) \ + V(Function) \ + V(InterpretedFunction) \ + V(Handler) \ + V(BytecodeHandler) \ + V(LazyCompile) \ + V(RegExp) \ + V(Script) \ + V(Stub) + +/** + * Note that this enum may be extended in the future. Please include a default + * case if this enum is used in a switch statement. + */ +enum CodeEventType { + kUnknownType = 0 +#define V(Name) , k##Name##Type + CODE_EVENTS_LIST(V) +#undef V +}; + +/** + * Representation of a code creation event + */ +class V8_EXPORT CodeEvent { + public: + uintptr_t GetCodeStartAddress(); + size_t GetCodeSize(); + Local<String> GetFunctionName(); + Local<String> GetScriptName(); + int GetScriptLine(); + int GetScriptColumn(); + /** + * NOTE (mmarchini): We can't allocate objects in the heap when we collect + * existing code, and both the code type and the comment are not stored in the + * heap, so we return those as const char*. + */ + CodeEventType GetCodeType(); + const char* GetComment(); + + static const char* GetCodeEventTypeName(CodeEventType code_event_type); +}; + +/** + * Interface to listen to code creation events. + */ +class V8_EXPORT CodeEventHandler { + public: + /** + * Creates a new listener for the |isolate|. The isolate must be initialized. + * The listener object must be disposed after use by calling |Dispose| method. + * Multiple listeners can be created for the same isolate. + */ + explicit CodeEventHandler(Isolate* isolate); + virtual ~CodeEventHandler(); + + virtual void Handle(CodeEvent* code_event) = 0; + + void Enable(); + void Disable(); + + private: + CodeEventHandler(); + CodeEventHandler(const CodeEventHandler&); + CodeEventHandler& operator=(const CodeEventHandler&); + void* internal_listener_; +}; + +} // namespace v8 + + +#endif // V8_V8_PROFILER_H_ diff --git a/android/x86/include/v8/v8-testing.h b/android/x86/include/v8/v8-testing.h new file mode 100755 index 00000000..f67bf253 --- /dev/null +++ b/android/x86/include/v8/v8-testing.h @@ -0,0 +1,48 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_V8_TEST_H_ +#define V8_V8_TEST_H_ + +#include "v8.h" // NOLINT(build/include) + +/** + * Testing support for the V8 JavaScript engine. + */ +namespace v8 { + +class V8_EXPORT Testing { + public: + enum StressType { + kStressTypeOpt, + kStressTypeDeopt + }; + + /** + * Set the type of stressing to do. The default if not set is kStressTypeOpt. + */ + static void SetStressRunType(StressType type); + + /** + * Get the number of runs of a given test that is required to get the full + * stress coverage. + */ + static int GetStressRuns(); + + /** + * Indicate the number of the run which is about to start. The value of run + * should be between 0 and one less than the result from GetStressRuns() + */ + static void PrepareStressRun(int run); + + /** + * Force deoptimization of all functions. + */ + static void DeoptimizeAll(Isolate* isolate); +}; + + +} // namespace v8 + +#endif // V8_V8_TEST_H_ diff --git a/android/x86/include/v8/v8-util.h b/android/x86/include/v8/v8-util.h new file mode 100755 index 00000000..24962607 --- /dev/null +++ b/android/x86/include/v8/v8-util.h @@ -0,0 +1,670 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_UTIL_H_ +#define V8_UTIL_H_ + +#include "v8.h" // NOLINT(build/include) +#include <assert.h> +#include <map> +#include <vector> + +/** + * Support for Persistent containers. + * + * C++11 embedders can use STL containers with Global values, + * but pre-C++11 does not support the required move semantic and hence + * may want these container classes. + */ +namespace v8 { + +typedef uintptr_t PersistentContainerValue; +static const uintptr_t kPersistentContainerNotFound = 0; +enum PersistentContainerCallbackType { + kNotWeak, + // These correspond to v8::WeakCallbackType + kWeakWithParameter, + kWeakWithInternalFields +}; + +/** + * A default trait implementation for PersistentValueMap which uses std::map + * as a backing map. + * + * Users will have to implement their own weak callbacks & dispose traits. + */ +template<typename K, typename V> +class StdMapTraits { + public: + // STL map & related: + typedef std::map<K, PersistentContainerValue> Impl; + typedef typename Impl::iterator Iterator; + + static bool Empty(Impl* impl) { return impl->empty(); } + static size_t Size(Impl* impl) { return impl->size(); } + static void Swap(Impl& a, Impl& b) { std::swap(a, b); } // NOLINT + static Iterator Begin(Impl* impl) { return impl->begin(); } + static Iterator End(Impl* impl) { return impl->end(); } + static K Key(Iterator it) { return it->first; } + static PersistentContainerValue Value(Iterator it) { return it->second; } + static PersistentContainerValue Set(Impl* impl, K key, + PersistentContainerValue value) { + std::pair<Iterator, bool> res = impl->insert(std::make_pair(key, value)); + PersistentContainerValue old_value = kPersistentContainerNotFound; + if (!res.second) { + old_value = res.first->second; + res.first->second = value; + } + return old_value; + } + static PersistentContainerValue Get(Impl* impl, K key) { + Iterator it = impl->find(key); + if (it == impl->end()) return kPersistentContainerNotFound; + return it->second; + } + static PersistentContainerValue Remove(Impl* impl, K key) { + Iterator it = impl->find(key); + if (it == impl->end()) return kPersistentContainerNotFound; + PersistentContainerValue value = it->second; + impl->erase(it); + return value; + } +}; + + +/** + * A default trait implementation for PersistentValueMap, which inherits + * a std:map backing map from StdMapTraits and holds non-weak persistent + * objects and has no special Dispose handling. + * + * You should not derive from this class, since MapType depends on the + * surrounding class, and hence a subclass cannot simply inherit the methods. + */ +template<typename K, typename V> +class DefaultPersistentValueMapTraits : public StdMapTraits<K, V> { + public: + // Weak callback & friends: + static const PersistentContainerCallbackType kCallbackType = kNotWeak; + typedef PersistentValueMap<K, V, DefaultPersistentValueMapTraits<K, V> > + MapType; + typedef void WeakCallbackDataType; + + static WeakCallbackDataType* WeakCallbackParameter( + MapType* map, const K& key, Local<V> value) { + return nullptr; + } + static MapType* MapFromWeakCallbackInfo( + const WeakCallbackInfo<WeakCallbackDataType>& data) { + return nullptr; + } + static K KeyFromWeakCallbackInfo( + const WeakCallbackInfo<WeakCallbackDataType>& data) { + return K(); + } + static void DisposeCallbackData(WeakCallbackDataType* data) { } + static void Dispose(Isolate* isolate, Global<V> value, K key) {} +}; + + +template <typename K, typename V> +class DefaultGlobalMapTraits : public StdMapTraits<K, V> { + private: + template <typename T> + struct RemovePointer; + + public: + // Weak callback & friends: + static const PersistentContainerCallbackType kCallbackType = kNotWeak; + typedef GlobalValueMap<K, V, DefaultGlobalMapTraits<K, V> > MapType; + typedef void WeakCallbackDataType; + + static WeakCallbackDataType* WeakCallbackParameter(MapType* map, const K& key, + Local<V> value) { + return nullptr; + } + static MapType* MapFromWeakCallbackInfo( + const WeakCallbackInfo<WeakCallbackDataType>& data) { + return nullptr; + } + static K KeyFromWeakCallbackInfo( + const WeakCallbackInfo<WeakCallbackDataType>& data) { + return K(); + } + static void DisposeCallbackData(WeakCallbackDataType* data) {} + static void OnWeakCallback( + const WeakCallbackInfo<WeakCallbackDataType>& data) {} + static void Dispose(Isolate* isolate, Global<V> value, K key) {} + // This is a second pass callback, so SetSecondPassCallback cannot be called. + static void DisposeWeak(const WeakCallbackInfo<WeakCallbackDataType>& data) {} + + private: + template <typename T> + struct RemovePointer<T*> { + typedef T Type; + }; +}; + + +/** + * A map wrapper that allows using Global as a mapped value. + * C++11 embedders don't need this class, as they can use Global + * directly in std containers. + * + * The map relies on a backing map, whose type and accessors are described + * by the Traits class. The backing map will handle values of type + * PersistentContainerValue, with all conversion into and out of V8 + * handles being transparently handled by this class. + */ +template <typename K, typename V, typename Traits> +class PersistentValueMapBase { + public: + Isolate* GetIsolate() { return isolate_; } + + /** + * Return size of the map. + */ + size_t Size() { return Traits::Size(&impl_); } + + /** + * Return whether the map holds weak persistents. + */ + bool IsWeak() { return Traits::kCallbackType != kNotWeak; } + + /** + * Get value stored in map. + */ + Local<V> Get(const K& key) { + return Local<V>::New(isolate_, FromVal(Traits::Get(&impl_, key))); + } + + /** + * Check whether a value is contained in the map. + */ + bool Contains(const K& key) { + return Traits::Get(&impl_, key) != kPersistentContainerNotFound; + } + + /** + * Get value stored in map and set it in returnValue. + * Return true if a value was found. + */ + bool SetReturnValue(const K& key, + ReturnValue<Value> returnValue) { + return SetReturnValueFromVal(&returnValue, Traits::Get(&impl_, key)); + } + + /** + * Call V8::RegisterExternallyReferencedObject with the map value for given + * key. + */ + V8_DEPRECATED( + "Used TracedGlobal and EmbedderHeapTracer::RegisterEmbedderReference", + inline void RegisterExternallyReferencedObject(K& key)); + + /** + * Return value for key and remove it from the map. + */ + Global<V> Remove(const K& key) { + return Release(Traits::Remove(&impl_, key)).Pass(); + } + + /** + * Traverses the map repeatedly, + * in case side effects of disposal cause insertions. + **/ + void Clear() { + typedef typename Traits::Iterator It; + HandleScope handle_scope(isolate_); + // TODO(dcarney): figure out if this swap and loop is necessary. + while (!Traits::Empty(&impl_)) { + typename Traits::Impl impl; + Traits::Swap(impl_, impl); + for (It i = Traits::Begin(&impl); i != Traits::End(&impl); ++i) { + Traits::Dispose(isolate_, Release(Traits::Value(i)).Pass(), + Traits::Key(i)); + } + } + } + + /** + * Helper class for GetReference/SetWithReference. Do not use outside + * that context. + */ + class PersistentValueReference { + public: + PersistentValueReference() : value_(kPersistentContainerNotFound) { } + PersistentValueReference(const PersistentValueReference& other) + : value_(other.value_) { } + + Local<V> NewLocal(Isolate* isolate) const { + return Local<V>::New(isolate, FromVal(value_)); + } + bool IsEmpty() const { + return value_ == kPersistentContainerNotFound; + } + template<typename T> + bool SetReturnValue(ReturnValue<T> returnValue) { + return SetReturnValueFromVal(&returnValue, value_); + } + void Reset() { + value_ = kPersistentContainerNotFound; + } + void operator=(const PersistentValueReference& other) { + value_ = other.value_; + } + + private: + friend class PersistentValueMapBase; + friend class PersistentValueMap<K, V, Traits>; + friend class GlobalValueMap<K, V, Traits>; + + explicit PersistentValueReference(PersistentContainerValue value) + : value_(value) { } + + void operator=(PersistentContainerValue value) { + value_ = value; + } + + PersistentContainerValue value_; + }; + + /** + * Get a reference to a map value. This enables fast, repeated access + * to a value stored in the map while the map remains unchanged. + * + * Careful: This is potentially unsafe, so please use with care. + * The value will become invalid if the value for this key changes + * in the underlying map, as a result of Set or Remove for the same + * key; as a result of the weak callback for the same key; or as a + * result of calling Clear() or destruction of the map. + */ + PersistentValueReference GetReference(const K& key) { + return PersistentValueReference(Traits::Get(&impl_, key)); + } + + protected: + explicit PersistentValueMapBase(Isolate* isolate) + : isolate_(isolate), label_(nullptr) {} + PersistentValueMapBase(Isolate* isolate, const char* label) + : isolate_(isolate), label_(label) {} + + ~PersistentValueMapBase() { Clear(); } + + Isolate* isolate() { return isolate_; } + typename Traits::Impl* impl() { return &impl_; } + + static V* FromVal(PersistentContainerValue v) { + return reinterpret_cast<V*>(v); + } + + static PersistentContainerValue ClearAndLeak(Global<V>* persistent) { + V* v = persistent->val_; + persistent->val_ = nullptr; + return reinterpret_cast<PersistentContainerValue>(v); + } + + static PersistentContainerValue Leak(Global<V>* persistent) { + return reinterpret_cast<PersistentContainerValue>(persistent->val_); + } + + /** + * Return a container value as Global and make sure the weak + * callback is properly disposed of. All remove functionality should go + * through this. + */ + static Global<V> Release(PersistentContainerValue v) { + Global<V> p; + p.val_ = FromVal(v); + if (Traits::kCallbackType != kNotWeak && p.IsWeak()) { + Traits::DisposeCallbackData( + p.template ClearWeak<typename Traits::WeakCallbackDataType>()); + } + return p.Pass(); + } + + void RemoveWeak(const K& key) { + Global<V> p; + p.val_ = FromVal(Traits::Remove(&impl_, key)); + p.Reset(); + } + + void AnnotateStrongRetainer(Global<V>* persistent) { + persistent->AnnotateStrongRetainer(label_); + } + + private: + PersistentValueMapBase(PersistentValueMapBase&); + void operator=(PersistentValueMapBase&); + + static bool SetReturnValueFromVal(ReturnValue<Value>* returnValue, + PersistentContainerValue value) { + bool hasValue = value != kPersistentContainerNotFound; + if (hasValue) { + returnValue->SetInternal( + *reinterpret_cast<internal::Address*>(FromVal(value))); + } + return hasValue; + } + + Isolate* isolate_; + typename Traits::Impl impl_; + const char* label_; +}; + +template <typename K, typename V, typename Traits> +inline void +PersistentValueMapBase<K, V, Traits>::RegisterExternallyReferencedObject( + K& key) { + assert(Contains(key)); + V8::RegisterExternallyReferencedObject( + reinterpret_cast<internal::Address*>(FromVal(Traits::Get(&impl_, key))), + reinterpret_cast<internal::Isolate*>(GetIsolate())); +} + +template <typename K, typename V, typename Traits> +class PersistentValueMap : public PersistentValueMapBase<K, V, Traits> { + public: + explicit PersistentValueMap(Isolate* isolate) + : PersistentValueMapBase<K, V, Traits>(isolate) {} + PersistentValueMap(Isolate* isolate, const char* label) + : PersistentValueMapBase<K, V, Traits>(isolate, label) {} + + typedef + typename PersistentValueMapBase<K, V, Traits>::PersistentValueReference + PersistentValueReference; + + /** + * Put value into map. Depending on Traits::kIsWeak, the value will be held + * by the map strongly or weakly. + * Returns old value as Global. + */ + Global<V> Set(const K& key, Local<V> value) { + Global<V> persistent(this->isolate(), value); + return SetUnique(key, &persistent); + } + + /** + * Put value into map, like Set(const K&, Local<V>). + */ + Global<V> Set(const K& key, Global<V> value) { + return SetUnique(key, &value); + } + + /** + * Put the value into the map, and set the 'weak' callback when demanded + * by the Traits class. + */ + Global<V> SetUnique(const K& key, Global<V>* persistent) { + if (Traits::kCallbackType == kNotWeak) { + this->AnnotateStrongRetainer(persistent); + } else { + WeakCallbackType callback_type = + Traits::kCallbackType == kWeakWithInternalFields + ? WeakCallbackType::kInternalFields + : WeakCallbackType::kParameter; + Local<V> value(Local<V>::New(this->isolate(), *persistent)); + persistent->template SetWeak<typename Traits::WeakCallbackDataType>( + Traits::WeakCallbackParameter(this, key, value), WeakCallback, + callback_type); + } + PersistentContainerValue old_value = + Traits::Set(this->impl(), key, this->ClearAndLeak(persistent)); + return this->Release(old_value).Pass(); + } + + /** + * Put a value into the map and update the reference. + * Restrictions of GetReference apply here as well. + */ + Global<V> Set(const K& key, Global<V> value, + PersistentValueReference* reference) { + *reference = this->Leak(&value); + return SetUnique(key, &value); + } + + private: + static void WeakCallback( + const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) { + if (Traits::kCallbackType != kNotWeak) { + PersistentValueMap<K, V, Traits>* persistentValueMap = + Traits::MapFromWeakCallbackInfo(data); + K key = Traits::KeyFromWeakCallbackInfo(data); + Traits::Dispose(data.GetIsolate(), + persistentValueMap->Remove(key).Pass(), key); + Traits::DisposeCallbackData(data.GetParameter()); + } + } +}; + + +template <typename K, typename V, typename Traits> +class GlobalValueMap : public PersistentValueMapBase<K, V, Traits> { + public: + explicit GlobalValueMap(Isolate* isolate) + : PersistentValueMapBase<K, V, Traits>(isolate) {} + GlobalValueMap(Isolate* isolate, const char* label) + : PersistentValueMapBase<K, V, Traits>(isolate, label) {} + + typedef + typename PersistentValueMapBase<K, V, Traits>::PersistentValueReference + PersistentValueReference; + + /** + * Put value into map. Depending on Traits::kIsWeak, the value will be held + * by the map strongly or weakly. + * Returns old value as Global. + */ + Global<V> Set(const K& key, Local<V> value) { + Global<V> persistent(this->isolate(), value); + return SetUnique(key, &persistent); + } + + /** + * Put value into map, like Set(const K&, Local<V>). + */ + Global<V> Set(const K& key, Global<V> value) { + return SetUnique(key, &value); + } + + /** + * Put the value into the map, and set the 'weak' callback when demanded + * by the Traits class. + */ + Global<V> SetUnique(const K& key, Global<V>* persistent) { + if (Traits::kCallbackType == kNotWeak) { + this->AnnotateStrongRetainer(persistent); + } else { + WeakCallbackType callback_type = + Traits::kCallbackType == kWeakWithInternalFields + ? WeakCallbackType::kInternalFields + : WeakCallbackType::kParameter; + Local<V> value(Local<V>::New(this->isolate(), *persistent)); + persistent->template SetWeak<typename Traits::WeakCallbackDataType>( + Traits::WeakCallbackParameter(this, key, value), OnWeakCallback, + callback_type); + } + PersistentContainerValue old_value = + Traits::Set(this->impl(), key, this->ClearAndLeak(persistent)); + return this->Release(old_value).Pass(); + } + + /** + * Put a value into the map and update the reference. + * Restrictions of GetReference apply here as well. + */ + Global<V> Set(const K& key, Global<V> value, + PersistentValueReference* reference) { + *reference = this->Leak(&value); + return SetUnique(key, &value); + } + + private: + static void OnWeakCallback( + const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) { + if (Traits::kCallbackType != kNotWeak) { + auto map = Traits::MapFromWeakCallbackInfo(data); + K key = Traits::KeyFromWeakCallbackInfo(data); + map->RemoveWeak(key); + Traits::OnWeakCallback(data); + data.SetSecondPassCallback(SecondWeakCallback); + } + } + + static void SecondWeakCallback( + const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) { + Traits::DisposeWeak(data); + } +}; + + +/** + * A map that uses Global as value and std::map as the backing + * implementation. Persistents are held non-weak. + * + * C++11 embedders don't need this class, as they can use + * Global directly in std containers. + */ +template<typename K, typename V, + typename Traits = DefaultPersistentValueMapTraits<K, V> > +class StdPersistentValueMap : public PersistentValueMap<K, V, Traits> { + public: + explicit StdPersistentValueMap(Isolate* isolate) + : PersistentValueMap<K, V, Traits>(isolate) {} +}; + + +/** + * A map that uses Global as value and std::map as the backing + * implementation. Globals are held non-weak. + * + * C++11 embedders don't need this class, as they can use + * Global directly in std containers. + */ +template <typename K, typename V, + typename Traits = DefaultGlobalMapTraits<K, V> > +class StdGlobalValueMap : public GlobalValueMap<K, V, Traits> { + public: + explicit StdGlobalValueMap(Isolate* isolate) + : GlobalValueMap<K, V, Traits>(isolate) {} +}; + + +class DefaultPersistentValueVectorTraits { + public: + typedef std::vector<PersistentContainerValue> Impl; + + static void Append(Impl* impl, PersistentContainerValue value) { + impl->push_back(value); + } + static bool IsEmpty(const Impl* impl) { + return impl->empty(); + } + static size_t Size(const Impl* impl) { + return impl->size(); + } + static PersistentContainerValue Get(const Impl* impl, size_t i) { + return (i < impl->size()) ? impl->at(i) : kPersistentContainerNotFound; + } + static void ReserveCapacity(Impl* impl, size_t capacity) { + impl->reserve(capacity); + } + static void Clear(Impl* impl) { + impl->clear(); + } +}; + + +/** + * A vector wrapper that safely stores Global values. + * C++11 embedders don't need this class, as they can use Global + * directly in std containers. + * + * This class relies on a backing vector implementation, whose type and methods + * are described by the Traits class. The backing map will handle values of type + * PersistentContainerValue, with all conversion into and out of V8 + * handles being transparently handled by this class. + */ +template<typename V, typename Traits = DefaultPersistentValueVectorTraits> +class PersistentValueVector { + public: + explicit PersistentValueVector(Isolate* isolate) : isolate_(isolate) { } + + ~PersistentValueVector() { + Clear(); + } + + /** + * Append a value to the vector. + */ + void Append(Local<V> value) { + Global<V> persistent(isolate_, value); + Traits::Append(&impl_, ClearAndLeak(&persistent)); + } + + /** + * Append a persistent's value to the vector. + */ + void Append(Global<V> persistent) { + Traits::Append(&impl_, ClearAndLeak(&persistent)); + } + + /** + * Are there any values in the vector? + */ + bool IsEmpty() const { + return Traits::IsEmpty(&impl_); + } + + /** + * How many elements are in the vector? + */ + size_t Size() const { + return Traits::Size(&impl_); + } + + /** + * Retrieve the i-th value in the vector. + */ + Local<V> Get(size_t index) const { + return Local<V>::New(isolate_, FromVal(Traits::Get(&impl_, index))); + } + + /** + * Remove all elements from the vector. + */ + void Clear() { + size_t length = Traits::Size(&impl_); + for (size_t i = 0; i < length; i++) { + Global<V> p; + p.val_ = FromVal(Traits::Get(&impl_, i)); + } + Traits::Clear(&impl_); + } + + /** + * Reserve capacity in the vector. + * (Efficiency gains depend on the backing implementation.) + */ + void ReserveCapacity(size_t capacity) { + Traits::ReserveCapacity(&impl_, capacity); + } + + private: + static PersistentContainerValue ClearAndLeak(Global<V>* persistent) { + V* v = persistent->val_; + persistent->val_ = nullptr; + return reinterpret_cast<PersistentContainerValue>(v); + } + + static V* FromVal(PersistentContainerValue v) { + return reinterpret_cast<V*>(v); + } + + Isolate* isolate_; + typename Traits::Impl impl_; +}; + +} // namespace v8 + +#endif // V8_UTIL_H diff --git a/android/x86/include/v8/v8-value-serializer-version.h b/android/x86/include/v8/v8-value-serializer-version.h new file mode 100755 index 00000000..c72911c6 --- /dev/null +++ b/android/x86/include/v8/v8-value-serializer-version.h @@ -0,0 +1,24 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Compile-time constants. + * + * This header provides access to information about the value serializer at + * compile time, without declaring or defining any symbols that require linking + * to V8. + */ + +#ifndef INCLUDE_V8_VALUE_SERIALIZER_VERSION_H_ +#define INCLUDE_V8_VALUE_SERIALIZER_VERSION_H_ + +#include <stdint.h> + +namespace v8 { + +constexpr uint32_t CurrentValueSerializerFormatVersion() { return 13; } + +} // namespace v8 + +#endif // INCLUDE_V8_VALUE_SERIALIZER_VERSION_H_ diff --git a/android/x86/include/v8/v8-version-string.h b/android/x86/include/v8/v8-version-string.h new file mode 100755 index 00000000..fb84144d --- /dev/null +++ b/android/x86/include/v8/v8-version-string.h @@ -0,0 +1,38 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_VERSION_STRING_H_ +#define V8_VERSION_STRING_H_ + +#include "v8-version.h" // NOLINT(build/include) + +// This is here rather than v8-version.h to keep that file simple and +// machine-processable. + +#if V8_IS_CANDIDATE_VERSION +#define V8_CANDIDATE_STRING " (candidate)" +#else +#define V8_CANDIDATE_STRING "" +#endif + +#ifndef V8_EMBEDDER_STRING +#define V8_EMBEDDER_STRING "" +#endif + +#define V8_SX(x) #x +#define V8_S(x) V8_SX(x) + +#if V8_PATCH_LEVEL > 0 +#define V8_VERSION_STRING \ + V8_S(V8_MAJOR_VERSION) \ + "." V8_S(V8_MINOR_VERSION) "." V8_S(V8_BUILD_NUMBER) "." V8_S( \ + V8_PATCH_LEVEL) V8_EMBEDDER_STRING V8_CANDIDATE_STRING +#else +#define V8_VERSION_STRING \ + V8_S(V8_MAJOR_VERSION) \ + "." V8_S(V8_MINOR_VERSION) "." V8_S(V8_BUILD_NUMBER) \ + V8_EMBEDDER_STRING V8_CANDIDATE_STRING +#endif + +#endif // V8_VERSION_STRING_H_ diff --git a/android/x86/include/v8/v8-version.h b/android/x86/include/v8/v8-version.h new file mode 100755 index 00000000..dfcd5b46 --- /dev/null +++ b/android/x86/include/v8/v8-version.h @@ -0,0 +1,20 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_INCLUDE_VERSION_H_ // V8_VERSION_H_ conflicts with src/version.h +#define V8_INCLUDE_VERSION_H_ + +// These macros define the version number for the current version. +// NOTE these macros are used by some of the tool scripts and the build +// system so their names cannot be changed without changing the scripts. +#define V8_MAJOR_VERSION 7 +#define V8_MINOR_VERSION 5 +#define V8_BUILD_NUMBER 288 +#define V8_PATCH_LEVEL 22 + +// Use 1 for candidates and 0 otherwise. +// (Boolean macro values are not supported by all preprocessors.) +#define V8_IS_CANDIDATE_VERSION 0 + +#endif // V8_INCLUDE_VERSION_H_ diff --git a/android/x86/include/v8/v8-wasm-trap-handler-posix.h b/android/x86/include/v8/v8-wasm-trap-handler-posix.h new file mode 100755 index 00000000..998d0a41 --- /dev/null +++ b/android/x86/include/v8/v8-wasm-trap-handler-posix.h @@ -0,0 +1,31 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_WASM_TRAP_HANDLER_POSIX_H_ +#define V8_WASM_TRAP_HANDLER_POSIX_H_ + +#include <signal.h> + +#include "v8config.h" // NOLINT(build/include) + +namespace v8 { +/** + * This function determines whether a memory access violation has been an + * out-of-bounds memory access in WebAssembly. If so, it will modify the context + * parameter and add a return address where the execution can continue after the + * signal handling, and return true. Otherwise, false will be returned. + * + * The parameters to this function correspond to those passed to a Posix signal + * handler. Use this function only on Linux and Mac. + * + * \param sig_code The signal code, e.g. SIGSEGV. + * \param info A pointer to the siginfo_t struct provided to the signal handler. + * \param context A pointer to a ucontext_t struct provided to the signal + * handler. + */ +V8_EXPORT bool TryHandleWebAssemblyTrapPosix(int sig_code, siginfo_t* info, + void* context); + +} // namespace v8 +#endif // V8_WASM_TRAP_HANDLER_POSIX_H_ diff --git a/android/x86/include/v8/v8-wasm-trap-handler-win.h b/android/x86/include/v8/v8-wasm-trap-handler-win.h new file mode 100755 index 00000000..0185df64 --- /dev/null +++ b/android/x86/include/v8/v8-wasm-trap-handler-win.h @@ -0,0 +1,28 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_WASM_TRAP_HANDLER_WIN_H_ +#define V8_WASM_TRAP_HANDLER_WIN_H_ + +#include <windows.h> + +#include "v8config.h" // NOLINT(build/include) + +namespace v8 { +/** + * This function determines whether a memory access violation has been an + * out-of-bounds memory access in WebAssembly. If so, it will modify the + * exception parameter and add a return address where the execution can continue + * after the exception handling, and return true. Otherwise the return value + * will be false. + * + * The parameter to this function corresponds to the one passed to a Windows + * vectored exception handler. Use this function only on Windows. + * + * \param exception An EXCEPTION_POINTERS* as provided to the exception handler. + */ +V8_EXPORT bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS* exception); + +} // namespace v8 +#endif // V8_WASM_TRAP_HANDLER_WIN_H_ diff --git a/android/x86/include/v8/v8.h b/android/x86/include/v8/v8.h new file mode 100755 index 00000000..b4b92055 --- /dev/null +++ b/android/x86/include/v8/v8.h @@ -0,0 +1,11042 @@ +// Copyright 2012 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** \mainpage V8 API Reference Guide + * + * V8 is Google's open source JavaScript engine. + * + * This set of documents provides reference material generated from the + * V8 header file, include/v8.h. + * + * For other documentation see http://code.google.com/apis/v8/ + */ + +#ifndef INCLUDE_V8_H_ +#define INCLUDE_V8_H_ + +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <memory> +#include <utility> +#include <vector> + +#include "v8-internal.h" // NOLINT(build/include) +#include "v8-version.h" // NOLINT(build/include) +#include "v8config.h" // NOLINT(build/include) + +// We reserve the V8_* prefix for macros defined in V8 public API and +// assume there are no name conflicts with the embedder's code. + +/** + * The v8 JavaScript engine. + */ +namespace v8 { + +class AccessorSignature; +class Array; +class ArrayBuffer; +class BigInt; +class BigIntObject; +class Boolean; +class BooleanObject; +class Context; +class Data; +class Date; +class External; +class Function; +class FunctionTemplate; +class HeapProfiler; +class ImplementationUtilities; +class Int32; +class Integer; +class Isolate; +template <class T> +class Maybe; +class MicrotaskQueue; +class Name; +class Number; +class NumberObject; +class Object; +class ObjectOperationDescriptor; +class ObjectTemplate; +class Platform; +class Primitive; +class Promise; +class PropertyDescriptor; +class Proxy; +class RawOperationDescriptor; +class Script; +class SharedArrayBuffer; +class Signature; +class StartupData; +class StackFrame; +class StackTrace; +class String; +class StringObject; +class Symbol; +class SymbolObject; +class PrimitiveArray; +class Private; +class Uint32; +class Utils; +class Value; +class WasmModuleObject; +template <class T> class Local; +template <class T> +class MaybeLocal; +template <class T> class Eternal; +template<class T> class NonCopyablePersistentTraits; +template<class T> class PersistentBase; +template <class T, class M = NonCopyablePersistentTraits<T> > +class Persistent; +template <class T> +class Global; +template <class T> +class TracedGlobal; +template<class K, class V, class T> class PersistentValueMap; +template <class K, class V, class T> +class PersistentValueMapBase; +template <class K, class V, class T> +class GlobalValueMap; +template<class V, class T> class PersistentValueVector; +template<class T, class P> class WeakCallbackObject; +class FunctionTemplate; +class ObjectTemplate; +template<typename T> class FunctionCallbackInfo; +template<typename T> class PropertyCallbackInfo; +class StackTrace; +class StackFrame; +class Isolate; +class CallHandlerHelper; +class EscapableHandleScope; +template<typename T> class ReturnValue; + +namespace internal { +class Arguments; +class DeferredHandles; +class Heap; +class HeapObject; +class ExternalString; +class Isolate; +class LocalEmbedderHeapTracer; +class MicrotaskQueue; +class NeverReadOnlySpaceObject; +struct ScriptStreamingData; +template<typename T> class CustomArguments; +class PropertyCallbackArguments; +class FunctionCallbackArguments; +class GlobalHandles; +class ScopedExternalStringLock; + +namespace wasm { +class NativeModule; +class StreamingDecoder; +} // namespace wasm + +} // namespace internal + +namespace debug { +class ConsoleCallArguments; +} // namespace debug + +// --- Handles --- + +#define TYPE_CHECK(T, S) \ + while (false) { \ + *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ + } + +/** + * An object reference managed by the v8 garbage collector. + * + * All objects returned from v8 have to be tracked by the garbage + * collector so that it knows that the objects are still alive. Also, + * because the garbage collector may move objects, it is unsafe to + * point directly to an object. Instead, all objects are stored in + * handles which are known by the garbage collector and updated + * whenever an object moves. Handles should always be passed by value + * (except in cases like out-parameters) and they should never be + * allocated on the heap. + * + * There are two types of handles: local and persistent handles. + * + * Local handles are light-weight and transient and typically used in + * local operations. They are managed by HandleScopes. That means that a + * HandleScope must exist on the stack when they are created and that they are + * only valid inside of the HandleScope active during their creation. + * For passing a local handle to an outer HandleScope, an EscapableHandleScope + * and its Escape() method must be used. + * + * Persistent handles can be used when storing objects across several + * independent operations and have to be explicitly deallocated when they're no + * longer used. + * + * It is safe to extract the object stored in the handle by + * dereferencing the handle (for instance, to extract the Object* from + * a Local<Object>); the value will still be governed by a handle + * behind the scenes and the same rules apply to these values as to + * their handles. + */ +template <class T> +class Local { + public: + V8_INLINE Local() : val_(nullptr) {} + template <class S> + V8_INLINE Local(Local<S> that) + : val_(reinterpret_cast<T*>(*that)) { + /** + * This check fails when trying to convert between incompatible + * handles. For example, converting from a Local<String> to a + * Local<Number>. + */ + TYPE_CHECK(T, S); + } + + /** + * Returns true if the handle is empty. + */ + V8_INLINE bool IsEmpty() const { return val_ == nullptr; } + + /** + * Sets the handle to be empty. IsEmpty() will then return true. + */ + V8_INLINE void Clear() { val_ = nullptr; } + + V8_INLINE T* operator->() const { return val_; } + + V8_INLINE T* operator*() const { return val_; } + + /** + * Checks whether two handles are the same. + * Returns true if both are empty, or if the objects + * to which they refer are identical. + * The handles' references are not checked. + */ + template <class S> + V8_INLINE bool operator==(const Local<S>& that) const { + internal::Address* a = reinterpret_cast<internal::Address*>(this->val_); + internal::Address* b = reinterpret_cast<internal::Address*>(that.val_); + if (a == nullptr) return b == nullptr; + if (b == nullptr) return false; + return *a == *b; + } + + template <class S> V8_INLINE bool operator==( + const PersistentBase<S>& that) const { + internal::Address* a = reinterpret_cast<internal::Address*>(this->val_); + internal::Address* b = reinterpret_cast<internal::Address*>(that.val_); + if (a == nullptr) return b == nullptr; + if (b == nullptr) return false; + return *a == *b; + } + + /** + * Checks whether two handles are different. + * Returns true if only one of the handles is empty, or if + * the objects to which they refer are different. + * The handles' references are not checked. + */ + template <class S> + V8_INLINE bool operator!=(const Local<S>& that) const { + return !operator==(that); + } + + template <class S> V8_INLINE bool operator!=( + const Persistent<S>& that) const { + return !operator==(that); + } + + /** + * Cast a handle to a subclass, e.g. Local<Value> to Local<Object>. + * This is only valid if the handle actually refers to a value of the + * target type. + */ + template <class S> V8_INLINE static Local<T> Cast(Local<S> that) { +#ifdef V8_ENABLE_CHECKS + // If we're going to perform the type check then we have to check + // that the handle isn't empty before doing the checked cast. + if (that.IsEmpty()) return Local<T>(); +#endif + return Local<T>(T::Cast(*that)); + } + + /** + * Calling this is equivalent to Local<S>::Cast(). + * In particular, this is only valid if the handle actually refers to a value + * of the target type. + */ + template <class S> + V8_INLINE Local<S> As() const { + return Local<S>::Cast(*this); + } + + /** + * Create a local handle for the content of another handle. + * The referee is kept alive by the local handle even when + * the original handle is destroyed/disposed. + */ + V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that); + V8_INLINE static Local<T> New(Isolate* isolate, + const PersistentBase<T>& that); + V8_INLINE static Local<T> New(Isolate* isolate, const TracedGlobal<T>& that); + + private: + friend class Utils; + template<class F> friend class Eternal; + template<class F> friend class PersistentBase; + template<class F, class M> friend class Persistent; + template<class F> friend class Local; + template <class F> + friend class MaybeLocal; + template<class F> friend class FunctionCallbackInfo; + template<class F> friend class PropertyCallbackInfo; + friend class String; + friend class Object; + friend class Context; + friend class Isolate; + friend class Private; + template<class F> friend class internal::CustomArguments; + friend Local<Primitive> Undefined(Isolate* isolate); + friend Local<Primitive> Null(Isolate* isolate); + friend Local<Boolean> True(Isolate* isolate); + friend Local<Boolean> False(Isolate* isolate); + friend class HandleScope; + friend class EscapableHandleScope; + template <class F1, class F2, class F3> + friend class PersistentValueMapBase; + template<class F1, class F2> friend class PersistentValueVector; + template <class F> + friend class ReturnValue; + template <class F> + friend class TracedGlobal; + + explicit V8_INLINE Local(T* that) : val_(that) {} + V8_INLINE static Local<T> New(Isolate* isolate, T* that); + T* val_; +}; + + +#if !defined(V8_IMMINENT_DEPRECATION_WARNINGS) +// Handle is an alias for Local for historical reasons. +template <class T> +using Handle = Local<T>; +#endif + + +/** + * A MaybeLocal<> is a wrapper around Local<> that enforces a check whether + * the Local<> is empty before it can be used. + * + * If an API method returns a MaybeLocal<>, the API method can potentially fail + * either because an exception is thrown, or because an exception is pending, + * e.g. because a previous API call threw an exception that hasn't been caught + * yet, or because a TerminateExecution exception was thrown. In that case, an + * empty MaybeLocal is returned. + */ +template <class T> +class MaybeLocal { + public: + V8_INLINE MaybeLocal() : val_(nullptr) {} + template <class S> + V8_INLINE MaybeLocal(Local<S> that) + : val_(reinterpret_cast<T*>(*that)) { + TYPE_CHECK(T, S); + } + + V8_INLINE bool IsEmpty() const { return val_ == nullptr; } + + /** + * Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty, + * |false| is returned and |out| is left untouched. + */ + template <class S> + V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const { + out->val_ = IsEmpty() ? nullptr : this->val_; + return !IsEmpty(); + } + + /** + * Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty, + * V8 will crash the process. + */ + V8_INLINE Local<T> ToLocalChecked(); + + /** + * Converts this MaybeLocal<> to a Local<>, using a default value if this + * MaybeLocal<> is empty. + */ + template <class S> + V8_INLINE Local<S> FromMaybe(Local<S> default_value) const { + return IsEmpty() ? default_value : Local<S>(val_); + } + + private: + T* val_; +}; + +/** + * Eternal handles are set-once handles that live for the lifetime of the + * isolate. + */ +template <class T> class Eternal { + public: + V8_INLINE Eternal() : val_(nullptr) {} + template <class S> + V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) { + Set(isolate, handle); + } + // Can only be safely called if already set. + V8_INLINE Local<T> Get(Isolate* isolate) const; + V8_INLINE bool IsEmpty() const { return val_ == nullptr; } + template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle); + + private: + T* val_; +}; + + +static const int kInternalFieldsInWeakCallback = 2; +static const int kEmbedderFieldsInWeakCallback = 2; + +template <typename T> +class WeakCallbackInfo { + public: + typedef void (*Callback)(const WeakCallbackInfo<T>& data); + + WeakCallbackInfo(Isolate* isolate, T* parameter, + void* embedder_fields[kEmbedderFieldsInWeakCallback], + Callback* callback) + : isolate_(isolate), parameter_(parameter), callback_(callback) { + for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) { + embedder_fields_[i] = embedder_fields[i]; + } + } + + V8_INLINE Isolate* GetIsolate() const { return isolate_; } + V8_INLINE T* GetParameter() const { return parameter_; } + V8_INLINE void* GetInternalField(int index) const; + + // When first called, the embedder MUST Reset() the Global which triggered the + // callback. The Global itself is unusable for anything else. No v8 other api + // calls may be called in the first callback. Should additional work be + // required, the embedder must set a second pass callback, which will be + // called after all the initial callbacks are processed. + // Calling SetSecondPassCallback on the second pass will immediately crash. + void SetSecondPassCallback(Callback callback) const { *callback_ = callback; } + + private: + Isolate* isolate_; + T* parameter_; + Callback* callback_; + void* embedder_fields_[kEmbedderFieldsInWeakCallback]; +}; + + +// kParameter will pass a void* parameter back to the callback, kInternalFields +// will pass the first two internal fields back to the callback, kFinalizer +// will pass a void* parameter back, but is invoked before the object is +// actually collected, so it can be resurrected. In the last case, it is not +// possible to request a second pass callback. +enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer }; + +/** + * An object reference that is independent of any handle scope. Where + * a Local handle only lives as long as the HandleScope in which it was + * allocated, a PersistentBase handle remains valid until it is explicitly + * disposed using Reset(). + * + * A persistent handle contains a reference to a storage cell within + * the V8 engine which holds an object value and which is updated by + * the garbage collector whenever the object is moved. A new storage + * cell can be created using the constructor or PersistentBase::Reset and + * existing handles can be disposed using PersistentBase::Reset. + * + */ +template <class T> class PersistentBase { + public: + /** + * If non-empty, destroy the underlying storage cell + * IsEmpty() will return true after this call. + */ + V8_INLINE void Reset(); + /** + * If non-empty, destroy the underlying storage cell + * and create a new one with the contents of other if other is non empty + */ + template <class S> + V8_INLINE void Reset(Isolate* isolate, const Local<S>& other); + + /** + * If non-empty, destroy the underlying storage cell + * and create a new one with the contents of other if other is non empty + */ + template <class S> + V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other); + + V8_INLINE bool IsEmpty() const { return val_ == nullptr; } + V8_INLINE void Empty() { val_ = 0; } + + V8_INLINE Local<T> Get(Isolate* isolate) const { + return Local<T>::New(isolate, *this); + } + + template <class S> + V8_INLINE bool operator==(const PersistentBase<S>& that) const { + internal::Address* a = reinterpret_cast<internal::Address*>(this->val_); + internal::Address* b = reinterpret_cast<internal::Address*>(that.val_); + if (a == nullptr) return b == nullptr; + if (b == nullptr) return false; + return *a == *b; + } + + template <class S> + V8_INLINE bool operator==(const Local<S>& that) const { + internal::Address* a = reinterpret_cast<internal::Address*>(this->val_); + internal::Address* b = reinterpret_cast<internal::Address*>(that.val_); + if (a == nullptr) return b == nullptr; + if (b == nullptr) return false; + return *a == *b; + } + + template <class S> + V8_INLINE bool operator!=(const PersistentBase<S>& that) const { + return !operator==(that); + } + + template <class S> + V8_INLINE bool operator!=(const Local<S>& that) const { + return !operator==(that); + } + + /** + * Install a finalization callback on this object. + * NOTE: There is no guarantee as to *when* or even *if* the callback is + * invoked. The invocation is performed solely on a best effort basis. + * As always, GC-based finalization should *not* be relied upon for any + * critical form of resource management! + */ + template <typename P> + V8_INLINE void SetWeak(P* parameter, + typename WeakCallbackInfo<P>::Callback callback, + WeakCallbackType type); + + /** + * Turns this handle into a weak phantom handle without finalization callback. + * The handle will be reset automatically when the garbage collector detects + * that the object is no longer reachable. + * A related function Isolate::NumberOfPhantomHandleResetsSinceLastCall + * returns how many phantom handles were reset by the garbage collector. + */ + V8_INLINE void SetWeak(); + + template<typename P> + V8_INLINE P* ClearWeak(); + + // TODO(dcarney): remove this. + V8_INLINE void ClearWeak() { ClearWeak<void>(); } + + /** + * Annotates the strong handle with the given label, which is then used by the + * heap snapshot generator as a name of the edge from the root to the handle. + * The function does not take ownership of the label and assumes that the + * label is valid as long as the handle is valid. + */ + V8_INLINE void AnnotateStrongRetainer(const char* label); + + /** + * Allows the embedder to tell the v8 garbage collector that a certain object + * is alive. Only allowed when the embedder is asked to trace its heap by + * EmbedderHeapTracer. + */ + V8_DEPRECATED( + "Used TracedGlobal and EmbedderHeapTracer::RegisterEmbedderReference", + V8_INLINE void RegisterExternalReference(Isolate* isolate) const); + + /** + * Marks the reference to this object independent. Garbage collector is free + * to ignore any object groups containing this object. Weak callback for an + * independent handle should not assume that it will be preceded by a global + * GC prologue callback or followed by a global GC epilogue callback. + */ + V8_DEPRECATED( + "Weak objects are always considered independent. " + "Use TracedGlobal when trying to use EmbedderHeapTracer. " + "Use a strong handle when trying to keep an object alive.", + V8_INLINE void MarkIndependent()); + + /** + * Marks the reference to this object as active. The scavenge garbage + * collection should not reclaim the objects marked as active, even if the + * object held by the handle is otherwise unreachable. + * + * This bit is cleared after the each garbage collection pass. + */ + V8_DEPRECATED("Use TracedGlobal.", V8_INLINE void MarkActive()); + + V8_DEPRECATED("See MarkIndependent.", V8_INLINE bool IsIndependent() const); + + /** Returns true if the handle's reference is weak. */ + V8_INLINE bool IsWeak() const; + + /** + * Assigns a wrapper class ID to the handle. + */ + V8_INLINE void SetWrapperClassId(uint16_t class_id); + + /** + * Returns the class ID previously assigned to this handle or 0 if no class ID + * was previously assigned. + */ + V8_INLINE uint16_t WrapperClassId() const; + + PersistentBase(const PersistentBase& other) = delete; // NOLINT + void operator=(const PersistentBase&) = delete; + + private: + friend class Isolate; + friend class Utils; + template<class F> friend class Local; + template<class F1, class F2> friend class Persistent; + template <class F> + friend class Global; + template<class F> friend class PersistentBase; + template<class F> friend class ReturnValue; + template <class F1, class F2, class F3> + friend class PersistentValueMapBase; + template<class F1, class F2> friend class PersistentValueVector; + friend class Object; + + explicit V8_INLINE PersistentBase(T* val) : val_(val) {} + V8_INLINE static T* New(Isolate* isolate, T* that); + + T* val_; +}; + + +/** + * Default traits for Persistent. This class does not allow + * use of the copy constructor or assignment operator. + * At present kResetInDestructor is not set, but that will change in a future + * version. + */ +template<class T> +class NonCopyablePersistentTraits { + public: + typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent; + static const bool kResetInDestructor = false; + template<class S, class M> + V8_INLINE static void Copy(const Persistent<S, M>& source, + NonCopyablePersistent* dest) { + Uncompilable<Object>(); + } + // TODO(dcarney): come up with a good compile error here. + template<class O> V8_INLINE static void Uncompilable() { + TYPE_CHECK(O, Primitive); + } +}; + + +/** + * Helper class traits to allow copying and assignment of Persistent. + * This will clone the contents of storage cell, but not any of the flags, etc. + */ +template<class T> +struct CopyablePersistentTraits { + typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent; + static const bool kResetInDestructor = true; + template<class S, class M> + static V8_INLINE void Copy(const Persistent<S, M>& source, + CopyablePersistent* dest) { + // do nothing, just allow copy + } +}; + + +/** + * A PersistentBase which allows copy and assignment. + * + * Copy, assignment and destructor behavior is controlled by the traits + * class M. + * + * Note: Persistent class hierarchy is subject to future changes. + */ +template <class T, class M> class Persistent : public PersistentBase<T> { + public: + /** + * A Persistent with no storage cell. + */ + V8_INLINE Persistent() : PersistentBase<T>(nullptr) {} + /** + * Construct a Persistent from a Local. + * When the Local is non-empty, a new storage cell is created + * pointing to the same object, and no flags are set. + */ + template <class S> + V8_INLINE Persistent(Isolate* isolate, Local<S> that) + : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { + TYPE_CHECK(T, S); + } + /** + * Construct a Persistent from a Persistent. + * When the Persistent is non-empty, a new storage cell is created + * pointing to the same object, and no flags are set. + */ + template <class S, class M2> + V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that) + : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { + TYPE_CHECK(T, S); + } + /** + * The copy constructors and assignment operator create a Persistent + * exactly as the Persistent constructor, but the Copy function from the + * traits class is called, allowing the setting of flags based on the + * copied Persistent. + */ + V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(nullptr) { + Copy(that); + } + template <class S, class M2> + V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) { + Copy(that); + } + V8_INLINE Persistent& operator=(const Persistent& that) { + Copy(that); + return *this; + } + template <class S, class M2> + V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT + Copy(that); + return *this; + } + /** + * The destructor will dispose the Persistent based on the + * kResetInDestructor flags in the traits class. Since not calling dispose + * can result in a memory leak, it is recommended to always set this flag. + */ + V8_INLINE ~Persistent() { + if (M::kResetInDestructor) this->Reset(); + } + + // TODO(dcarney): this is pretty useless, fix or remove + template <class S> + V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT +#ifdef V8_ENABLE_CHECKS + // If we're going to perform the type check then we have to check + // that the handle isn't empty before doing the checked cast. + if (!that.IsEmpty()) T::Cast(*that); +#endif + return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that)); + } + + // TODO(dcarney): this is pretty useless, fix or remove + template <class S> + V8_INLINE Persistent<S>& As() const { // NOLINT + return Persistent<S>::Cast(*this); + } + + private: + friend class Isolate; + friend class Utils; + template<class F> friend class Local; + template<class F1, class F2> friend class Persistent; + template<class F> friend class ReturnValue; + + explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {} + V8_INLINE T* operator*() const { return this->val_; } + template<class S, class M2> + V8_INLINE void Copy(const Persistent<S, M2>& that); +}; + + +/** + * A PersistentBase which has move semantics. + * + * Note: Persistent class hierarchy is subject to future changes. + */ +template <class T> +class Global : public PersistentBase<T> { + public: + /** + * A Global with no storage cell. + */ + V8_INLINE Global() : PersistentBase<T>(nullptr) {} + + /** + * Construct a Global from a Local. + * When the Local is non-empty, a new storage cell is created + * pointing to the same object, and no flags are set. + */ + template <class S> + V8_INLINE Global(Isolate* isolate, Local<S> that) + : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { + TYPE_CHECK(T, S); + } + + /** + * Construct a Global from a PersistentBase. + * When the Persistent is non-empty, a new storage cell is created + * pointing to the same object, and no flags are set. + */ + template <class S> + V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that) + : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) { + TYPE_CHECK(T, S); + } + + /** + * Move constructor. + */ + V8_INLINE Global(Global&& other); + + V8_INLINE ~Global() { this->Reset(); } + + /** + * Move via assignment. + */ + template <class S> + V8_INLINE Global& operator=(Global<S>&& rhs); + + /** + * Pass allows returning uniques from functions, etc. + */ + Global Pass() { return static_cast<Global&&>(*this); } // NOLINT + + /* + * For compatibility with Chromium's base::Bind (base::Passed). + */ + typedef void MoveOnlyTypeForCPP03; + + Global(const Global&) = delete; + void operator=(const Global&) = delete; + + private: + template <class F> + friend class ReturnValue; + V8_INLINE T* operator*() const { return this->val_; } +}; + + +// UniquePersistent is an alias for Global for historical reason. +template <class T> +using UniquePersistent = Global<T>; + +/** + * A traced handle with move semantics, similar to std::unique_ptr. The handle + * is to be used together with |v8::EmbedderHeapTracer| and specifies edges from + * the embedder into V8's heap. + * + * The exact semantics are: + * - Tracing garbage collections use |v8::EmbedderHeapTracer|. + * - Non-tracing garbage collections refer to + * |v8::EmbedderHeapTracer::IsRootForNonTracingGC()| whether the handle should + * be treated as root or not. + */ +template <typename T> +class V8_EXPORT TracedGlobal { + public: + /** + * An empty TracedGlobal without storage cell. + */ + TracedGlobal() = default; + ~TracedGlobal() { Reset(); } + + /** + * Construct a TracedGlobal from a Local. + * + * When the Local is non-empty, a new storage cell is created + * pointing to the same object. + */ + template <class S> + TracedGlobal(Isolate* isolate, Local<S> that) + : val_(New(isolate, *that, &val_)) { + TYPE_CHECK(T, S); + } + + /** + * Move constructor initializing TracedGlobal from an existing one. + */ + V8_INLINE TracedGlobal(TracedGlobal&& other); + + /** + * Move assignment operator initializing TracedGlobal from an existing one. + */ + template <class S> + V8_INLINE TracedGlobal& operator=(TracedGlobal<S>&& rhs); + + /** + * TracedGlobal only supports move semantics and forbids copying. + */ + TracedGlobal(const TracedGlobal&) = delete; + void operator=(const TracedGlobal&) = delete; + + /** + * Returns true if this TracedGlobal is empty, i.e., has not been assigned an + * object. + */ + bool IsEmpty() const { return val_ == nullptr; } + + /** + * If non-empty, destroy the underlying storage cell. |IsEmpty| will return + * true after this call. + */ + V8_INLINE void Reset(); + + /** + * If non-empty, destroy the underlying storage cell and create a new one with + * the contents of other if other is non empty + */ + template <class S> + V8_INLINE void Reset(Isolate* isolate, const Local<S>& other); + + /** + * Construct a Local<T> from this handle. + */ + Local<T> Get(Isolate* isolate) const { return Local<T>::New(isolate, *this); } + + template <class S> + V8_INLINE TracedGlobal<S>& As() const { + return reinterpret_cast<TracedGlobal<S>&>( + const_cast<TracedGlobal<T>&>(*this)); + } + + template <class S> + V8_INLINE bool operator==(const TracedGlobal<S>& that) const { + internal::Address* a = reinterpret_cast<internal::Address*>(this->val_); + internal::Address* b = reinterpret_cast<internal::Address*>(that.val_); + if (a == nullptr) return b == nullptr; + if (b == nullptr) return false; + return *a == *b; + } + + template <class S> + V8_INLINE bool operator==(const Local<S>& that) const { + internal::Address* a = reinterpret_cast<internal::Address*>(this->val_); + internal::Address* b = reinterpret_cast<internal::Address*>(that.val_); + if (a == nullptr) return b == nullptr; + if (b == nullptr) return false; + return *a == *b; + } + + template <class S> + V8_INLINE bool operator!=(const TracedGlobal<S>& that) const { + return !operator==(that); + } + + template <class S> + V8_INLINE bool operator!=(const Local<S>& that) const { + return !operator==(that); + } + + /** + * Assigns a wrapper class ID to the handle. + */ + V8_INLINE void SetWrapperClassId(uint16_t class_id); + + /** + * Returns the class ID previously assigned to this handle or 0 if no class ID + * was previously assigned. + */ + V8_INLINE uint16_t WrapperClassId() const; + + /** + * Adds a finalization callback to the handle. The type of this callback is + * similar to WeakCallbackType::kInternalFields, i.e., it will pass the + * parameter and the first two internal fields of the object. + * + * The callback is then supposed to reset the handle in the callback. No + * further V8 API may be called in this callback. In case additional work + * involving V8 needs to be done, a second callback can be scheduled using + * WeakCallbackInfo<void>::SetSecondPassCallback. + */ + V8_INLINE void SetFinalizationCallback( + void* parameter, WeakCallbackInfo<void>::Callback callback); + + private: + V8_INLINE static T* New(Isolate* isolate, T* that, T** slot); + + T* operator*() const { return this->val_; } + + T* val_ = nullptr; + + friend class EmbedderHeapTracer; + template <typename F> + friend class Local; + friend class Object; + template <typename F> + friend class ReturnValue; +}; + + /** + * A stack-allocated class that governs a number of local handles. + * After a handle scope has been created, all local handles will be + * allocated within that handle scope until either the handle scope is + * deleted or another handle scope is created. If there is already a + * handle scope and a new one is created, all allocations will take + * place in the new handle scope until it is deleted. After that, + * new handles will again be allocated in the original handle scope. + * + * After the handle scope of a local handle has been deleted the + * garbage collector will no longer track the object stored in the + * handle and may deallocate it. The behavior of accessing a handle + * for which the handle scope has been deleted is undefined. + */ +class V8_EXPORT HandleScope { + public: + explicit HandleScope(Isolate* isolate); + + ~HandleScope(); + + /** + * Counts the number of allocated handles. + */ + static int NumberOfHandles(Isolate* isolate); + + V8_INLINE Isolate* GetIsolate() const { + return reinterpret_cast<Isolate*>(isolate_); + } + + HandleScope(const HandleScope&) = delete; + void operator=(const HandleScope&) = delete; + + protected: + V8_INLINE HandleScope() = default; + + void Initialize(Isolate* isolate); + + static internal::Address* CreateHandle(internal::Isolate* isolate, + internal::Address value); + + private: + // Declaring operator new and delete as deleted is not spec compliant. + // Therefore declare them private instead to disable dynamic alloc + void* operator new(size_t size); + void* operator new[](size_t size); + void operator delete(void*, size_t); + void operator delete[](void*, size_t); + + internal::Isolate* isolate_; + internal::Address* prev_next_; + internal::Address* prev_limit_; + + // Local::New uses CreateHandle with an Isolate* parameter. + template<class F> friend class Local; + + // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with + // a HeapObject in their shortcuts. + friend class Object; + friend class Context; +}; + + +/** + * A HandleScope which first allocates a handle in the current scope + * which will be later filled with the escape value. + */ +class V8_EXPORT EscapableHandleScope : public HandleScope { + public: + explicit EscapableHandleScope(Isolate* isolate); + V8_INLINE ~EscapableHandleScope() = default; + + /** + * Pushes the value into the previous scope and returns a handle to it. + * Cannot be called twice. + */ + template <class T> + V8_INLINE Local<T> Escape(Local<T> value) { + internal::Address* slot = + Escape(reinterpret_cast<internal::Address*>(*value)); + return Local<T>(reinterpret_cast<T*>(slot)); + } + + template <class T> + V8_INLINE MaybeLocal<T> EscapeMaybe(MaybeLocal<T> value) { + return Escape(value.FromMaybe(Local<T>())); + } + + EscapableHandleScope(const EscapableHandleScope&) = delete; + void operator=(const EscapableHandleScope&) = delete; + + private: + // Declaring operator new and delete as deleted is not spec compliant. + // Therefore declare them private instead to disable dynamic alloc + void* operator new(size_t size); + void* operator new[](size_t size); + void operator delete(void*, size_t); + void operator delete[](void*, size_t); + + internal::Address* Escape(internal::Address* escape_value); + internal::Address* escape_slot_; +}; + +/** + * A SealHandleScope acts like a handle scope in which no handle allocations + * are allowed. It can be useful for debugging handle leaks. + * Handles can be allocated within inner normal HandleScopes. + */ +class V8_EXPORT SealHandleScope { + public: + explicit SealHandleScope(Isolate* isolate); + ~SealHandleScope(); + + SealHandleScope(const SealHandleScope&) = delete; + void operator=(const SealHandleScope&) = delete; + + private: + // Declaring operator new and delete as deleted is not spec compliant. + // Therefore declare them private instead to disable dynamic alloc + void* operator new(size_t size); + void* operator new[](size_t size); + void operator delete(void*, size_t); + void operator delete[](void*, size_t); + + internal::Isolate* const isolate_; + internal::Address* prev_limit_; + int prev_sealed_level_; +}; + + +// --- Special objects --- + + +/** + * The superclass of values and API object templates. + */ +class V8_EXPORT Data { + private: + Data(); +}; + +/** + * A container type that holds relevant metadata for module loading. + * + * This is passed back to the embedder as part of + * HostImportModuleDynamicallyCallback for module loading. + */ +class V8_EXPORT ScriptOrModule { + public: + /** + * The name that was passed by the embedder as ResourceName to the + * ScriptOrigin. This can be either a v8::String or v8::Undefined. + */ + Local<Value> GetResourceName(); + + /** + * The options that were passed by the embedder as HostDefinedOptions to + * the ScriptOrigin. + */ + Local<PrimitiveArray> GetHostDefinedOptions(); +}; + +/** + * An array to hold Primitive values. This is used by the embedder to + * pass host defined options to the ScriptOptions during compilation. + * + * This is passed back to the embedder as part of + * HostImportModuleDynamicallyCallback for module loading. + * + */ +class V8_EXPORT PrimitiveArray { + public: + static Local<PrimitiveArray> New(Isolate* isolate, int length); + int Length() const; + void Set(Isolate* isolate, int index, Local<Primitive> item); + Local<Primitive> Get(Isolate* isolate, int index); +}; + +/** + * The optional attributes of ScriptOrigin. + */ +class ScriptOriginOptions { + public: + V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false, + bool is_opaque = false, bool is_wasm = false, + bool is_module = false) + : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) | + (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) | + (is_module ? kIsModule : 0)) {} + V8_INLINE ScriptOriginOptions(int flags) + : flags_(flags & + (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {} + + bool IsSharedCrossOrigin() const { + return (flags_ & kIsSharedCrossOrigin) != 0; + } + bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; } + bool IsWasm() const { return (flags_ & kIsWasm) != 0; } + bool IsModule() const { return (flags_ & kIsModule) != 0; } + + int Flags() const { return flags_; } + + private: + enum { + kIsSharedCrossOrigin = 1, + kIsOpaque = 1 << 1, + kIsWasm = 1 << 2, + kIsModule = 1 << 3 + }; + const int flags_; +}; + +/** + * The origin, within a file, of a script. + */ +class ScriptOrigin { + public: + V8_INLINE ScriptOrigin( + Local<Value> resource_name, + Local<Integer> resource_line_offset = Local<Integer>(), + Local<Integer> resource_column_offset = Local<Integer>(), + Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(), + Local<Integer> script_id = Local<Integer>(), + Local<Value> source_map_url = Local<Value>(), + Local<Boolean> resource_is_opaque = Local<Boolean>(), + Local<Boolean> is_wasm = Local<Boolean>(), + Local<Boolean> is_module = Local<Boolean>(), + Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>()); + + V8_INLINE Local<Value> ResourceName() const; + V8_INLINE Local<Integer> ResourceLineOffset() const; + V8_INLINE Local<Integer> ResourceColumnOffset() const; + V8_INLINE Local<Integer> ScriptID() const; + V8_INLINE Local<Value> SourceMapUrl() const; + V8_INLINE Local<PrimitiveArray> HostDefinedOptions() const; + V8_INLINE ScriptOriginOptions Options() const { return options_; } + + private: + Local<Value> resource_name_; + Local<Integer> resource_line_offset_; + Local<Integer> resource_column_offset_; + ScriptOriginOptions options_; + Local<Integer> script_id_; + Local<Value> source_map_url_; + Local<PrimitiveArray> host_defined_options_; +}; + +/** + * A compiled JavaScript script, not yet tied to a Context. + */ +class V8_EXPORT UnboundScript { + public: + /** + * Binds the script to the currently entered context. + */ + Local<Script> BindToCurrentContext(); + + int GetId(); + Local<Value> GetScriptName(); + + /** + * Data read from magic sourceURL comments. + */ + Local<Value> GetSourceURL(); + /** + * Data read from magic sourceMappingURL comments. + */ + Local<Value> GetSourceMappingURL(); + + /** + * Returns zero based line number of the code_pos location in the script. + * -1 will be returned if no information available. + */ + int GetLineNumber(int code_pos); + + static const int kNoScriptId = 0; +}; + +/** + * A compiled JavaScript module, not yet tied to a Context. + */ +class V8_EXPORT UnboundModuleScript { + // Only used as a container for code caching. +}; + +/** + * A location in JavaScript source. + */ +class V8_EXPORT Location { + public: + int GetLineNumber() { return line_number_; } + int GetColumnNumber() { return column_number_; } + + Location(int line_number, int column_number) + : line_number_(line_number), column_number_(column_number) {} + + private: + int line_number_; + int column_number_; +}; + +/** + * A compiled JavaScript module. + */ +class V8_EXPORT Module { + public: + /** + * The different states a module can be in. + * + * This corresponds to the states used in ECMAScript except that "evaluated" + * is split into kEvaluated and kErrored, indicating success and failure, + * respectively. + */ + enum Status { + kUninstantiated, + kInstantiating, + kInstantiated, + kEvaluating, + kEvaluated, + kErrored + }; + + /** + * Returns the module's current status. + */ + Status GetStatus() const; + + /** + * For a module in kErrored status, this returns the corresponding exception. + */ + Local<Value> GetException() const; + + /** + * Returns the number of modules requested by this module. + */ + int GetModuleRequestsLength() const; + + /** + * Returns the ith module specifier in this module. + * i must be < GetModuleRequestsLength() and >= 0. + */ + Local<String> GetModuleRequest(int i) const; + + /** + * Returns the source location (line number and column number) of the ith + * module specifier's first occurrence in this module. + */ + Location GetModuleRequestLocation(int i) const; + + /** + * Returns the identity hash for this object. + */ + int GetIdentityHash() const; + + typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context, + Local<String> specifier, + Local<Module> referrer); + + /** + * Instantiates the module and its dependencies. + * + * Returns an empty Maybe<bool> if an exception occurred during + * instantiation. (In the case where the callback throws an exception, that + * exception is propagated.) + */ + V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(Local<Context> context, + ResolveCallback callback); + + /** + * Evaluates the module and its dependencies. + * + * If status is kInstantiated, run the module's code. On success, set status + * to kEvaluated and return the completion value; on failure, set status to + * kErrored and propagate the thrown exception (which is then also available + * via |GetException|). + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context); + + /** + * Returns the namespace object of this module. + * + * The module's status must be at least kInstantiated. + */ + Local<Value> GetModuleNamespace(); + + /** + * Returns the corresponding context-unbound module script. + * + * The module must be unevaluated, i.e. its status must not be kEvaluating, + * kEvaluated or kErrored. + */ + Local<UnboundModuleScript> GetUnboundModuleScript(); +}; + +/** + * A compiled JavaScript script, tied to a Context which was active when the + * script was compiled. + */ +class V8_EXPORT Script { + public: + /** + * A shorthand for ScriptCompiler::Compile(). + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile( + Local<Context> context, Local<String> source, + ScriptOrigin* origin = nullptr); + + /** + * Runs the script returning the resulting value. It will be run in the + * context in which it was created (ScriptCompiler::CompileBound or + * UnboundScript::BindToCurrentContext()). + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context); + + /** + * Returns the corresponding context-unbound script. + */ + Local<UnboundScript> GetUnboundScript(); +}; + + +/** + * For compiling scripts. + */ +class V8_EXPORT ScriptCompiler { + public: + /** + * Compilation data that the embedder can cache and pass back to speed up + * future compilations. The data is produced if the CompilerOptions passed to + * the compilation functions in ScriptCompiler contains produce_data_to_cache + * = true. The data to cache can then can be retrieved from + * UnboundScript. + */ + struct V8_EXPORT CachedData { + enum BufferPolicy { + BufferNotOwned, + BufferOwned + }; + + CachedData() + : data(nullptr), + length(0), + rejected(false), + buffer_policy(BufferNotOwned) {} + + // If buffer_policy is BufferNotOwned, the caller keeps the ownership of + // data and guarantees that it stays alive until the CachedData object is + // destroyed. If the policy is BufferOwned, the given data will be deleted + // (with delete[]) when the CachedData object is destroyed. + CachedData(const uint8_t* data, int length, + BufferPolicy buffer_policy = BufferNotOwned); + ~CachedData(); + // TODO(marja): Async compilation; add constructors which take a callback + // which will be called when V8 no longer needs the data. + const uint8_t* data; + int length; + bool rejected; + BufferPolicy buffer_policy; + + // Prevent copying. + CachedData(const CachedData&) = delete; + CachedData& operator=(const CachedData&) = delete; + }; + + /** + * Source code which can be then compiled to a UnboundScript or Script. + */ + class Source { + public: + // Source takes ownership of CachedData. + V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin, + CachedData* cached_data = nullptr); + V8_INLINE Source(Local<String> source_string, + CachedData* cached_data = nullptr); + V8_INLINE ~Source(); + + // Ownership of the CachedData or its buffers is *not* transferred to the + // caller. The CachedData object is alive as long as the Source object is + // alive. + V8_INLINE const CachedData* GetCachedData() const; + + V8_INLINE const ScriptOriginOptions& GetResourceOptions() const; + + // Prevent copying. + Source(const Source&) = delete; + Source& operator=(const Source&) = delete; + + private: + friend class ScriptCompiler; + + Local<String> source_string; + + // Origin information + Local<Value> resource_name; + Local<Integer> resource_line_offset; + Local<Integer> resource_column_offset; + ScriptOriginOptions resource_options; + Local<Value> source_map_url; + Local<PrimitiveArray> host_defined_options; + + // Cached data from previous compilation (if a kConsume*Cache flag is + // set), or hold newly generated cache data (kProduce*Cache flags) are + // set when calling a compile method. + CachedData* cached_data; + }; + + /** + * For streaming incomplete script data to V8. The embedder should implement a + * subclass of this class. + */ + class V8_EXPORT ExternalSourceStream { + public: + virtual ~ExternalSourceStream() = default; + + /** + * V8 calls this to request the next chunk of data from the embedder. This + * function will be called on a background thread, so it's OK to block and + * wait for the data, if the embedder doesn't have data yet. Returns the + * length of the data returned. When the data ends, GetMoreData should + * return 0. Caller takes ownership of the data. + * + * When streaming UTF-8 data, V8 handles multi-byte characters split between + * two data chunks, but doesn't handle multi-byte characters split between + * more than two data chunks. The embedder can avoid this problem by always + * returning at least 2 bytes of data. + * + * When streaming UTF-16 data, V8 does not handle characters split between + * two data chunks. The embedder has to make sure that chunks have an even + * length. + * + * If the embedder wants to cancel the streaming, they should make the next + * GetMoreData call return 0. V8 will interpret it as end of data (and most + * probably, parsing will fail). The streaming task will return as soon as + * V8 has parsed the data it received so far. + */ + virtual size_t GetMoreData(const uint8_t** src) = 0; + + /** + * V8 calls this method to set a 'bookmark' at the current position in + * the source stream, for the purpose of (maybe) later calling + * ResetToBookmark. If ResetToBookmark is called later, then subsequent + * calls to GetMoreData should return the same data as they did when + * SetBookmark was called earlier. + * + * The embedder may return 'false' to indicate it cannot provide this + * functionality. + */ + virtual bool SetBookmark(); + + /** + * V8 calls this to return to a previously set bookmark. + */ + virtual void ResetToBookmark(); + }; + + /** + * Source code which can be streamed into V8 in pieces. It will be parsed + * while streaming and compiled after parsing has completed. StreamedSource + * must be kept alive while the streaming task is run (see ScriptStreamingTask + * below). + */ + class V8_EXPORT StreamedSource { + public: + enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 }; + + V8_DEPRECATE_SOON( + "This class takes ownership of source_stream, so use the constructor " + "taking a unique_ptr to make these semantics clearer", + StreamedSource(ExternalSourceStream* source_stream, Encoding encoding)); + StreamedSource(std::unique_ptr<ExternalSourceStream> source_stream, + Encoding encoding); + ~StreamedSource(); + + internal::ScriptStreamingData* impl() const { return impl_.get(); } + + // Prevent copying. + StreamedSource(const StreamedSource&) = delete; + StreamedSource& operator=(const StreamedSource&) = delete; + + private: + std::unique_ptr<internal::ScriptStreamingData> impl_; + }; + + /** + * A streaming task which the embedder must run on a background thread to + * stream scripts into V8. Returned by ScriptCompiler::StartStreamingScript. + */ + class V8_EXPORT ScriptStreamingTask final { + public: + void Run(); + + private: + friend class ScriptCompiler; + + explicit ScriptStreamingTask(internal::ScriptStreamingData* data) + : data_(data) {} + + internal::ScriptStreamingData* data_; + }; + + enum CompileOptions { + kNoCompileOptions = 0, + kConsumeCodeCache, + kEagerCompile + }; + + /** + * The reason for which we are not requesting or providing a code cache. + */ + enum NoCacheReason { + kNoCacheNoReason = 0, + kNoCacheBecauseCachingDisabled, + kNoCacheBecauseNoResource, + kNoCacheBecauseInlineScript, + kNoCacheBecauseModule, + kNoCacheBecauseStreamingSource, + kNoCacheBecauseInspector, + kNoCacheBecauseScriptTooSmall, + kNoCacheBecauseCacheTooCold, + kNoCacheBecauseV8Extension, + kNoCacheBecauseExtensionModule, + kNoCacheBecausePacScript, + kNoCacheBecauseInDocumentWrite, + kNoCacheBecauseResourceWithNoCacheHandler, + kNoCacheBecauseDeferredProduceCodeCache + }; + + /** + * Compiles the specified script (context-independent). + * Cached data as part of the source object can be optionally produced to be + * consumed later to speed up compilation of identical source scripts. + * + * Note that when producing cached data, the source must point to NULL for + * cached data. When consuming cached data, the cached data must have been + * produced by the same version of V8. + * + * \param source Script source code. + * \return Compiled script object (context independent; for running it must be + * bound to a context). + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript( + Isolate* isolate, Source* source, + CompileOptions options = kNoCompileOptions, + NoCacheReason no_cache_reason = kNoCacheNoReason); + + /** + * Compiles the specified script (bound to current context). + * + * \param source Script source code. + * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() + * using pre_data speeds compilation if it's done multiple times. + * Owned by caller, no references are kept when this function returns. + * \return Compiled script object, bound to the context that was active + * when this function was called. When run it will always use this + * context. + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile( + Local<Context> context, Source* source, + CompileOptions options = kNoCompileOptions, + NoCacheReason no_cache_reason = kNoCacheNoReason); + + /** + * Returns a task which streams script data into V8, or NULL if the script + * cannot be streamed. The user is responsible for running the task on a + * background thread and deleting it. When ran, the task starts parsing the + * script, and it will request data from the StreamedSource as needed. When + * ScriptStreamingTask::Run exits, all data has been streamed and the script + * can be compiled (see Compile below). + * + * This API allows to start the streaming with as little data as possible, and + * the remaining data (for example, the ScriptOrigin) is passed to Compile. + */ + static ScriptStreamingTask* StartStreamingScript( + Isolate* isolate, StreamedSource* source, + CompileOptions options = kNoCompileOptions); + + /** + * Compiles a streamed script (bound to current context). + * + * This can only be called after the streaming has finished + * (ScriptStreamingTask has been run). V8 doesn't construct the source string + * during streaming, so the embedder needs to pass the full source here. + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile( + Local<Context> context, StreamedSource* source, + Local<String> full_source_string, const ScriptOrigin& origin); + + /** + * Return a version tag for CachedData for the current V8 version & flags. + * + * This value is meant only for determining whether a previously generated + * CachedData instance is still valid; the tag has no other meaing. + * + * Background: The data carried by CachedData may depend on the exact + * V8 version number or current compiler flags. This means that when + * persisting CachedData, the embedder must take care to not pass in + * data from another V8 version, or the same version with different + * features enabled. + * + * The easiest way to do so is to clear the embedder's cache on any + * such change. + * + * Alternatively, this tag can be stored alongside the cached data and + * compared when it is being used. + */ + static uint32_t CachedDataVersionTag(); + + /** + * Compile an ES module, returning a Module that encapsulates + * the compiled code. + * + * Corresponds to the ParseModule abstract operation in the + * ECMAScript specification. + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule( + Isolate* isolate, Source* source, + CompileOptions options = kNoCompileOptions, + NoCacheReason no_cache_reason = kNoCacheNoReason); + + /** + * Compile a function for a given context. This is equivalent to running + * + * with (obj) { + * return function(args) { ... } + * } + * + * It is possible to specify multiple context extensions (obj in the above + * example). + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext( + Local<Context> context, Source* source, size_t arguments_count, + Local<String> arguments[], size_t context_extension_count, + Local<Object> context_extensions[], + CompileOptions options = kNoCompileOptions, + NoCacheReason no_cache_reason = kNoCacheNoReason); + + /** + * Creates and returns code cache for the specified unbound_script. + * This will return nullptr if the script cannot be serialized. The + * CachedData returned by this function should be owned by the caller. + */ + static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script); + + /** + * Creates and returns code cache for the specified unbound_module_script. + * This will return nullptr if the script cannot be serialized. The + * CachedData returned by this function should be owned by the caller. + */ + static CachedData* CreateCodeCache( + Local<UnboundModuleScript> unbound_module_script); + + /** + * Creates and returns code cache for the specified function that was + * previously produced by CompileFunctionInContext. + * This will return nullptr if the script cannot be serialized. The + * CachedData returned by this function should be owned by the caller. + */ + static CachedData* CreateCodeCacheForFunction(Local<Function> function); + + private: + static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal( + Isolate* isolate, Source* source, CompileOptions options, + NoCacheReason no_cache_reason); +}; + + +/** + * An error message. + */ +class V8_EXPORT Message { + public: + Local<String> Get() const; + + /** + * Return the isolate to which the Message belongs. + */ + Isolate* GetIsolate() const; + + V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine( + Local<Context> context) const; + + /** + * Returns the origin for the script from where the function causing the + * error originates. + */ + ScriptOrigin GetScriptOrigin() const; + + /** + * Returns the resource name for the script from where the function causing + * the error originates. + */ + Local<Value> GetScriptResourceName() const; + + /** + * Exception stack trace. By default stack traces are not captured for + * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows + * to change this option. + */ + Local<StackTrace> GetStackTrace() const; + + /** + * Returns the number, 1-based, of the line where the error occurred. + */ + V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const; + + /** + * Returns the index within the script of the first character where + * the error occurred. + */ + int GetStartPosition() const; + + /** + * Returns the index within the script of the last character where + * the error occurred. + */ + int GetEndPosition() const; + + /** + * Returns the error level of the message. + */ + int ErrorLevel() const; + + /** + * Returns the index within the line of the first character where + * the error occurred. + */ + int GetStartColumn() const; + V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const; + + /** + * Returns the index within the line of the last character where + * the error occurred. + */ + int GetEndColumn() const; + V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const; + + /** + * Passes on the value set by the embedder when it fed the script from which + * this Message was generated to V8. + */ + bool IsSharedCrossOrigin() const; + bool IsOpaque() const; + + // TODO(1245381): Print to a string instead of on a FILE. + static void PrintCurrentStackTrace(Isolate* isolate, FILE* out); + + static const int kNoLineNumberInfo = 0; + static const int kNoColumnInfo = 0; + static const int kNoScriptIdInfo = 0; +}; + + +/** + * Representation of a JavaScript stack trace. The information collected is a + * snapshot of the execution stack and the information remains valid after + * execution continues. + */ +class V8_EXPORT StackTrace { + public: + /** + * Flags that determine what information is placed captured for each + * StackFrame when grabbing the current stack trace. + * Note: these options are deprecated and we always collect all available + * information (kDetailed). + */ + enum StackTraceOptions { + kLineNumber = 1, + kColumnOffset = 1 << 1 | kLineNumber, + kScriptName = 1 << 2, + kFunctionName = 1 << 3, + kIsEval = 1 << 4, + kIsConstructor = 1 << 5, + kScriptNameOrSourceURL = 1 << 6, + kScriptId = 1 << 7, + kExposeFramesAcrossSecurityOrigins = 1 << 8, + kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, + kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL + }; + + /** + * Returns a StackFrame at a particular index. + */ + Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const; + + /** + * Returns the number of StackFrames. + */ + int GetFrameCount() const; + + /** + * Grab a snapshot of the current JavaScript execution stack. + * + * \param frame_limit The maximum number of stack frames we want to capture. + * \param options Enumerates the set of things we will capture for each + * StackFrame. + */ + static Local<StackTrace> CurrentStackTrace( + Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed); +}; + + +/** + * A single JavaScript stack frame. + */ +class V8_EXPORT StackFrame { + public: + /** + * Returns the number, 1-based, of the line for the associate function call. + * This method will return Message::kNoLineNumberInfo if it is unable to + * retrieve the line number, or if kLineNumber was not passed as an option + * when capturing the StackTrace. + */ + int GetLineNumber() const; + + /** + * Returns the 1-based column offset on the line for the associated function + * call. + * This method will return Message::kNoColumnInfo if it is unable to retrieve + * the column number, or if kColumnOffset was not passed as an option when + * capturing the StackTrace. + */ + int GetColumn() const; + + /** + * Returns the id of the script for the function for this StackFrame. + * This method will return Message::kNoScriptIdInfo if it is unable to + * retrieve the script id, or if kScriptId was not passed as an option when + * capturing the StackTrace. + */ + int GetScriptId() const; + + /** + * Returns the name of the resource that contains the script for the + * function for this StackFrame. + */ + Local<String> GetScriptName() const; + + /** + * Returns the name of the resource that contains the script for the + * function for this StackFrame or sourceURL value if the script name + * is undefined and its source ends with //# sourceURL=... string or + * deprecated //@ sourceURL=... string. + */ + Local<String> GetScriptNameOrSourceURL() const; + + /** + * Returns the name of the function associated with this stack frame. + */ + Local<String> GetFunctionName() const; + + /** + * Returns whether or not the associated function is compiled via a call to + * eval(). + */ + bool IsEval() const; + + /** + * Returns whether or not the associated function is called as a + * constructor via "new". + */ + bool IsConstructor() const; + + /** + * Returns whether or not the associated functions is defined in wasm. + */ + bool IsWasm() const; +}; + + +// A StateTag represents a possible state of the VM. +enum StateTag { + JS, + GC, + PARSER, + BYTECODE_COMPILER, + COMPILER, + OTHER, + EXTERNAL, + IDLE +}; + +// A RegisterState represents the current state of registers used +// by the sampling profiler API. +struct RegisterState { + RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {} + void* pc; // Instruction pointer. + void* sp; // Stack pointer. + void* fp; // Frame pointer. +}; + +// The output structure filled up by GetStackSample API function. +struct SampleInfo { + size_t frames_count; // Number of frames collected. + StateTag vm_state; // Current VM state. + void* external_callback_entry; // External callback address if VM is + // executing an external callback. +}; + +struct MemoryRange { + const void* start = nullptr; + size_t length_in_bytes = 0; +}; + +struct JSEntryStub { + MemoryRange code; +}; + +struct UnwindState { + MemoryRange code_range; + MemoryRange embedded_code_range; + JSEntryStub js_entry_stub; +}; + +/** + * A JSON Parser and Stringifier. + */ +class V8_EXPORT JSON { + public: + /** + * Tries to parse the string |json_string| and returns it as value if + * successful. + * + * \param the context in which to parse and create the value. + * \param json_string The string to parse. + * \return The corresponding value if successfully parsed. + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse( + Local<Context> context, Local<String> json_string); + + /** + * Tries to stringify the JSON-serializable object |json_object| and returns + * it as string if successful. + * + * \param json_object The JSON-serializable object to stringify. + * \return The corresponding string if successfully stringified. + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify( + Local<Context> context, Local<Value> json_object, + Local<String> gap = Local<String>()); +}; + +/** + * Value serialization compatible with the HTML structured clone algorithm. + * The format is backward-compatible (i.e. safe to store to disk). + */ +class V8_EXPORT ValueSerializer { + public: + class V8_EXPORT Delegate { + public: + virtual ~Delegate() = default; + + /** + * Handles the case where a DataCloneError would be thrown in the structured + * clone spec. Other V8 embedders may throw some other appropriate exception + * type. + */ + virtual void ThrowDataCloneError(Local<String> message) = 0; + + /** + * The embedder overrides this method to write some kind of host object, if + * possible. If not, a suitable exception should be thrown and + * Nothing<bool>() returned. + */ + virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object); + + /** + * Called when the ValueSerializer is going to serialize a + * SharedArrayBuffer object. The embedder must return an ID for the + * object, using the same ID if this SharedArrayBuffer has already been + * serialized in this buffer. When deserializing, this ID will be passed to + * ValueDeserializer::GetSharedArrayBufferFromId as |clone_id|. + * + * If the object cannot be serialized, an + * exception should be thrown and Nothing<uint32_t>() returned. + */ + virtual Maybe<uint32_t> GetSharedArrayBufferId( + Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer); + + virtual Maybe<uint32_t> GetWasmModuleTransferId( + Isolate* isolate, Local<WasmModuleObject> module); + /** + * Allocates memory for the buffer of at least the size provided. The actual + * size (which may be greater or equal) is written to |actual_size|. If no + * buffer has been allocated yet, nullptr will be provided. + * + * If the memory cannot be allocated, nullptr should be returned. + * |actual_size| will be ignored. It is assumed that |old_buffer| is still + * valid in this case and has not been modified. + * + * The default implementation uses the stdlib's `realloc()` function. + */ + virtual void* ReallocateBufferMemory(void* old_buffer, size_t size, + size_t* actual_size); + + /** + * Frees a buffer allocated with |ReallocateBufferMemory|. + * + * The default implementation uses the stdlib's `free()` function. + */ + virtual void FreeBufferMemory(void* buffer); + }; + + explicit ValueSerializer(Isolate* isolate); + ValueSerializer(Isolate* isolate, Delegate* delegate); + ~ValueSerializer(); + + /** + * Writes out a header, which includes the format version. + */ + void WriteHeader(); + + /** + * Serializes a JavaScript value into the buffer. + */ + V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context, + Local<Value> value); + + /** + * Returns the stored data (allocated using the delegate's + * ReallocateBufferMemory) and its size. This serializer should not be used + * once the buffer is released. The contents are undefined if a previous write + * has failed. Ownership of the buffer is transferred to the caller. + */ + V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release(); + + /** + * Marks an ArrayBuffer as havings its contents transferred out of band. + * Pass the corresponding ArrayBuffer in the deserializing context to + * ValueDeserializer::TransferArrayBuffer. + */ + void TransferArrayBuffer(uint32_t transfer_id, + Local<ArrayBuffer> array_buffer); + + + /** + * Indicate whether to treat ArrayBufferView objects as host objects, + * i.e. pass them to Delegate::WriteHostObject. This should not be + * called when no Delegate was passed. + * + * The default is not to treat ArrayBufferViews as host objects. + */ + void SetTreatArrayBufferViewsAsHostObjects(bool mode); + + /** + * Write raw data in various common formats to the buffer. + * Note that integer types are written in base-128 varint format, not with a + * binary copy. For use during an override of Delegate::WriteHostObject. + */ + void WriteUint32(uint32_t value); + void WriteUint64(uint64_t value); + void WriteDouble(double value); + void WriteRawBytes(const void* source, size_t length); + + private: + ValueSerializer(const ValueSerializer&) = delete; + void operator=(const ValueSerializer&) = delete; + + struct PrivateData; + PrivateData* private_; +}; + +/** + * Deserializes values from data written with ValueSerializer, or a compatible + * implementation. + */ +class V8_EXPORT ValueDeserializer { + public: + class V8_EXPORT Delegate { + public: + virtual ~Delegate() = default; + + /** + * The embedder overrides this method to read some kind of host object, if + * possible. If not, a suitable exception should be thrown and + * MaybeLocal<Object>() returned. + */ + virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate); + + /** + * Get a WasmModuleObject given a transfer_id previously provided + * by ValueSerializer::GetWasmModuleTransferId + */ + virtual MaybeLocal<WasmModuleObject> GetWasmModuleFromId( + Isolate* isolate, uint32_t transfer_id); + + /** + * Get a SharedArrayBuffer given a clone_id previously provided + * by ValueSerializer::GetSharedArrayBufferId + */ + virtual MaybeLocal<SharedArrayBuffer> GetSharedArrayBufferFromId( + Isolate* isolate, uint32_t clone_id); + }; + + ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size); + ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size, + Delegate* delegate); + ~ValueDeserializer(); + + /** + * Reads and validates a header (including the format version). + * May, for example, reject an invalid or unsupported wire format. + */ + V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context); + + /** + * Deserializes a JavaScript value from the buffer. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context); + + /** + * Accepts the array buffer corresponding to the one passed previously to + * ValueSerializer::TransferArrayBuffer. + */ + void TransferArrayBuffer(uint32_t transfer_id, + Local<ArrayBuffer> array_buffer); + + /** + * Similar to TransferArrayBuffer, but for SharedArrayBuffer. + * The id is not necessarily in the same namespace as unshared ArrayBuffer + * objects. + */ + void TransferSharedArrayBuffer(uint32_t id, + Local<SharedArrayBuffer> shared_array_buffer); + + /** + * Must be called before ReadHeader to enable support for reading the legacy + * wire format (i.e., which predates this being shipped). + * + * Don't use this unless you need to read data written by previous versions of + * blink::ScriptValueSerializer. + */ + void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format); + + /** + * Expect inline wasm in the data stream (rather than in-memory transfer) + */ + void SetExpectInlineWasm(bool allow_inline_wasm); + + /** + * Reads the underlying wire format version. Likely mostly to be useful to + * legacy code reading old wire format versions. Must be called after + * ReadHeader. + */ + uint32_t GetWireFormatVersion() const; + + /** + * Reads raw data in various common formats to the buffer. + * Note that integer types are read in base-128 varint format, not with a + * binary copy. For use during an override of Delegate::ReadHostObject. + */ + V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value); + V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value); + V8_WARN_UNUSED_RESULT bool ReadDouble(double* value); + V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data); + + private: + ValueDeserializer(const ValueDeserializer&) = delete; + void operator=(const ValueDeserializer&) = delete; + + struct PrivateData; + PrivateData* private_; +}; + + +// --- Value --- + + +/** + * The superclass of all JavaScript values and objects. + */ +class V8_EXPORT Value : public Data { + public: + /** + * Returns true if this value is the undefined value. See ECMA-262 + * 4.3.10. + */ + V8_INLINE bool IsUndefined() const; + + /** + * Returns true if this value is the null value. See ECMA-262 + * 4.3.11. + */ + V8_INLINE bool IsNull() const; + + /** + * Returns true if this value is either the null or the undefined value. + * See ECMA-262 + * 4.3.11. and 4.3.12 + */ + V8_INLINE bool IsNullOrUndefined() const; + + /** + * Returns true if this value is true. + */ + bool IsTrue() const; + + /** + * Returns true if this value is false. + */ + bool IsFalse() const; + + /** + * Returns true if this value is a symbol or a string. + */ + bool IsName() const; + + /** + * Returns true if this value is an instance of the String type. + * See ECMA-262 8.4. + */ + V8_INLINE bool IsString() const; + + /** + * Returns true if this value is a symbol. + */ + bool IsSymbol() const; + + /** + * Returns true if this value is a function. + */ + bool IsFunction() const; + + /** + * Returns true if this value is an array. Note that it will return false for + * an Proxy for an array. + */ + bool IsArray() const; + + /** + * Returns true if this value is an object. + */ + bool IsObject() const; + + /** + * Returns true if this value is a bigint. + */ + bool IsBigInt() const; + + /** + * Returns true if this value is boolean. + */ + bool IsBoolean() const; + + /** + * Returns true if this value is a number. + */ + bool IsNumber() const; + + /** + * Returns true if this value is external. + */ + bool IsExternal() const; + + /** + * Returns true if this value is a 32-bit signed integer. + */ + bool IsInt32() const; + + /** + * Returns true if this value is a 32-bit unsigned integer. + */ + bool IsUint32() const; + + /** + * Returns true if this value is a Date. + */ + bool IsDate() const; + + /** + * Returns true if this value is an Arguments object. + */ + bool IsArgumentsObject() const; + + /** + * Returns true if this value is a BigInt object. + */ + bool IsBigIntObject() const; + + /** + * Returns true if this value is a Boolean object. + */ + bool IsBooleanObject() const; + + /** + * Returns true if this value is a Number object. + */ + bool IsNumberObject() const; + + /** + * Returns true if this value is a String object. + */ + bool IsStringObject() const; + + /** + * Returns true if this value is a Symbol object. + */ + bool IsSymbolObject() const; + + /** + * Returns true if this value is a NativeError. + */ + bool IsNativeError() const; + + /** + * Returns true if this value is a RegExp. + */ + bool IsRegExp() const; + + /** + * Returns true if this value is an async function. + */ + bool IsAsyncFunction() const; + + /** + * Returns true if this value is a Generator function. + */ + bool IsGeneratorFunction() const; + + /** + * Returns true if this value is a Generator object (iterator). + */ + bool IsGeneratorObject() const; + + /** + * Returns true if this value is a Promise. + */ + bool IsPromise() const; + + /** + * Returns true if this value is a Map. + */ + bool IsMap() const; + + /** + * Returns true if this value is a Set. + */ + bool IsSet() const; + + /** + * Returns true if this value is a Map Iterator. + */ + bool IsMapIterator() const; + + /** + * Returns true if this value is a Set Iterator. + */ + bool IsSetIterator() const; + + /** + * Returns true if this value is a WeakMap. + */ + bool IsWeakMap() const; + + /** + * Returns true if this value is a WeakSet. + */ + bool IsWeakSet() const; + + /** + * Returns true if this value is an ArrayBuffer. + */ + bool IsArrayBuffer() const; + + /** + * Returns true if this value is an ArrayBufferView. + */ + bool IsArrayBufferView() const; + + /** + * Returns true if this value is one of TypedArrays. + */ + bool IsTypedArray() const; + + /** + * Returns true if this value is an Uint8Array. + */ + bool IsUint8Array() const; + + /** + * Returns true if this value is an Uint8ClampedArray. + */ + bool IsUint8ClampedArray() const; + + /** + * Returns true if this value is an Int8Array. + */ + bool IsInt8Array() const; + + /** + * Returns true if this value is an Uint16Array. + */ + bool IsUint16Array() const; + + /** + * Returns true if this value is an Int16Array. + */ + bool IsInt16Array() const; + + /** + * Returns true if this value is an Uint32Array. + */ + bool IsUint32Array() const; + + /** + * Returns true if this value is an Int32Array. + */ + bool IsInt32Array() const; + + /** + * Returns true if this value is a Float32Array. + */ + bool IsFloat32Array() const; + + /** + * Returns true if this value is a Float64Array. + */ + bool IsFloat64Array() const; + + /** + * Returns true if this value is a BigInt64Array. + */ + bool IsBigInt64Array() const; + + /** + * Returns true if this value is a BigUint64Array. + */ + bool IsBigUint64Array() const; + + /** + * Returns true if this value is a DataView. + */ + bool IsDataView() const; + + /** + * Returns true if this value is a SharedArrayBuffer. + * This is an experimental feature. + */ + bool IsSharedArrayBuffer() const; + + /** + * Returns true if this value is a JavaScript Proxy. + */ + bool IsProxy() const; + + bool IsWebAssemblyCompiledModule() const; + + /** + * Returns true if the value is a Module Namespace Object. + */ + bool IsModuleNamespaceObject() const; + + V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt( + Local<Context> context) const; + V8_DEPRECATED("ToBoolean can never throw. Use Local version.", + V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean( + Local<Context> context) const); + V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber( + Local<Context> context) const; + V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString( + Local<Context> context) const; + V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString( + Local<Context> context) const; + V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject( + Local<Context> context) const; + V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger( + Local<Context> context) const; + V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32( + Local<Context> context) const; + V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const; + + Local<Boolean> ToBoolean(Isolate* isolate) const; + V8_DEPRECATED("Use maybe version", + Local<Number> ToNumber(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local<String> ToString(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local<Object> ToObject(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local<Integer> ToInteger(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local<Int32> ToInt32(Isolate* isolate) const); + + /** + * Attempts to convert a string to an array index. + * Returns an empty handle if the conversion fails. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex( + Local<Context> context) const; + + bool BooleanValue(Isolate* isolate) const; + + V8_DEPRECATED("BooleanValue can never throw. Use Isolate version.", + V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue( + Local<Context> context) const); + V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const; + V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue( + Local<Context> context) const; + V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value( + Local<Context> context) const; + V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const; + + /** JS == */ + V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context, + Local<Value> that) const; + bool StrictEquals(Local<Value> that) const; + bool SameValue(Local<Value> that) const; + + template <class T> V8_INLINE static Value* Cast(T* value); + + Local<String> TypeOf(Isolate*); + + Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object); + + private: + V8_INLINE bool QuickIsUndefined() const; + V8_INLINE bool QuickIsNull() const; + V8_INLINE bool QuickIsNullOrUndefined() const; + V8_INLINE bool QuickIsString() const; + bool FullIsUndefined() const; + bool FullIsNull() const; + bool FullIsString() const; +}; + + +/** + * The superclass of primitive values. See ECMA-262 4.3.2. + */ +class V8_EXPORT Primitive : public Value { }; + + +/** + * A primitive boolean value (ECMA-262, 4.3.14). Either the true + * or false value. + */ +class V8_EXPORT Boolean : public Primitive { + public: + bool Value() const; + V8_INLINE static Boolean* Cast(v8::Value* obj); + V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value); + + private: + static void CheckCast(v8::Value* obj); +}; + + +/** + * A superclass for symbols and strings. + */ +class V8_EXPORT Name : public Primitive { + public: + /** + * Returns the identity hash for this object. The current implementation + * uses an inline property on the object to store the identity hash. + * + * The return value will never be 0. Also, it is not guaranteed to be + * unique. + */ + int GetIdentityHash(); + + V8_INLINE static Name* Cast(Value* obj); + + private: + static void CheckCast(Value* obj); +}; + +/** + * A flag describing different modes of string creation. + * + * Aside from performance implications there are no differences between the two + * creation modes. + */ +enum class NewStringType { + /** + * Create a new string, always allocating new storage memory. + */ + kNormal, + + /** + * Acts as a hint that the string should be created in the + * old generation heap space and be deduplicated if an identical string + * already exists. + */ + kInternalized +}; + +/** + * A JavaScript string value (ECMA-262, 4.3.17). + */ +class V8_EXPORT String : public Name { + public: + static constexpr int kMaxLength = internal::kApiTaggedSize == 4 + ? (1 << 28) - 16 + : internal::kSmiMaxValue / 2 - 24; + + enum Encoding { + UNKNOWN_ENCODING = 0x1, + TWO_BYTE_ENCODING = 0x0, + ONE_BYTE_ENCODING = 0x8 + }; + /** + * Returns the number of characters (UTF-16 code units) in this string. + */ + int Length() const; + + /** + * Returns the number of bytes in the UTF-8 encoded + * representation of this string. + */ + int Utf8Length(Isolate* isolate) const; + + /** + * Returns whether this string is known to contain only one byte data, + * i.e. ISO-8859-1 code points. + * Does not read the string. + * False negatives are possible. + */ + bool IsOneByte() const; + + /** + * Returns whether this string contain only one byte data, + * i.e. ISO-8859-1 code points. + * Will read the entire string in some cases. + */ + bool ContainsOnlyOneByte() const; + + /** + * Write the contents of the string to an external buffer. + * If no arguments are given, expects the buffer to be large + * enough to hold the entire string and NULL terminator. Copies + * the contents of the string and the NULL terminator into the + * buffer. + * + * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop + * before the end of the buffer. + * + * Copies up to length characters into the output buffer. + * Only null-terminates if there is enough space in the buffer. + * + * \param buffer The buffer into which the string will be copied. + * \param start The starting position within the string at which + * copying begins. + * \param length The number of characters to copy from the string. For + * WriteUtf8 the number of bytes in the buffer. + * \param nchars_ref The number of characters written, can be NULL. + * \param options Various options that might affect performance of this or + * subsequent operations. + * \return The number of characters copied to the buffer excluding the null + * terminator. For WriteUtf8: The number of bytes copied to the buffer + * including the null terminator (if written). + */ + enum WriteOptions { + NO_OPTIONS = 0, + HINT_MANY_WRITES_EXPECTED = 1, + NO_NULL_TERMINATION = 2, + PRESERVE_ONE_BYTE_NULL = 4, + // Used by WriteUtf8 to replace orphan surrogate code units with the + // unicode replacement character. Needs to be set to guarantee valid UTF-8 + // output. + REPLACE_INVALID_UTF8 = 8 + }; + + // 16-bit character codes. + int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1, + int options = NO_OPTIONS) const; + // One byte characters. + int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0, + int length = -1, int options = NO_OPTIONS) const; + // UTF-8 encoded characters. + int WriteUtf8(Isolate* isolate, char* buffer, int length = -1, + int* nchars_ref = nullptr, int options = NO_OPTIONS) const; + + /** + * A zero length string. + */ + V8_INLINE static Local<String> Empty(Isolate* isolate); + + /** + * Returns true if the string is external + */ + bool IsExternal() const; + + /** + * Returns true if the string is both external and one-byte. + */ + bool IsExternalOneByte() const; + + class V8_EXPORT ExternalStringResourceBase { // NOLINT + public: + virtual ~ExternalStringResourceBase() = default; + + /** + * If a string is cacheable, the value returned by + * ExternalStringResource::data() may be cached, otherwise it is not + * expected to be stable beyond the current top-level task. + */ + virtual bool IsCacheable() const { return true; } + + protected: + ExternalStringResourceBase() = default; + + /** + * Internally V8 will call this Dispose method when the external string + * resource is no longer needed. The default implementation will use the + * delete operator. This method can be overridden in subclasses to + * control how allocated external string resources are disposed. + */ + virtual void Dispose() { delete this; } + + /** + * For a non-cacheable string, the value returned by + * |ExternalStringResource::data()| has to be stable between |Lock()| and + * |Unlock()|, that is the string must behave as is |IsCacheable()| returned + * true. + * + * These two functions must be thread-safe, and can be called from anywhere. + * They also must handle lock depth, in the sense that each can be called + * several times, from different threads, and unlocking should only happen + * when the balance of Lock() and Unlock() calls is 0. + */ + virtual void Lock() const {} + + /** + * Unlocks the string. + */ + virtual void Unlock() const {} + + // Disallow copying and assigning. + ExternalStringResourceBase(const ExternalStringResourceBase&) = delete; + void operator=(const ExternalStringResourceBase&) = delete; + + private: + friend class internal::ExternalString; + friend class v8::String; + friend class internal::ScopedExternalStringLock; + }; + + /** + * An ExternalStringResource is a wrapper around a two-byte string + * buffer that resides outside V8's heap. Implement an + * ExternalStringResource to manage the life cycle of the underlying + * buffer. Note that the string data must be immutable. + */ + class V8_EXPORT ExternalStringResource + : public ExternalStringResourceBase { + public: + /** + * Override the destructor to manage the life cycle of the underlying + * buffer. + */ + ~ExternalStringResource() override = default; + + /** + * The string data from the underlying buffer. + */ + virtual const uint16_t* data() const = 0; + + /** + * The length of the string. That is, the number of two-byte characters. + */ + virtual size_t length() const = 0; + + protected: + ExternalStringResource() = default; + }; + + /** + * An ExternalOneByteStringResource is a wrapper around an one-byte + * string buffer that resides outside V8's heap. Implement an + * ExternalOneByteStringResource to manage the life cycle of the + * underlying buffer. Note that the string data must be immutable + * and that the data must be Latin-1 and not UTF-8, which would require + * special treatment internally in the engine and do not allow efficient + * indexing. Use String::New or convert to 16 bit data for non-Latin1. + */ + + class V8_EXPORT ExternalOneByteStringResource + : public ExternalStringResourceBase { + public: + /** + * Override the destructor to manage the life cycle of the underlying + * buffer. + */ + ~ExternalOneByteStringResource() override = default; + /** The string data from the underlying buffer.*/ + virtual const char* data() const = 0; + /** The number of Latin-1 characters in the string.*/ + virtual size_t length() const = 0; + protected: + ExternalOneByteStringResource() = default; + }; + + /** + * If the string is an external string, return the ExternalStringResourceBase + * regardless of the encoding, otherwise return NULL. The encoding of the + * string is returned in encoding_out. + */ + V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase( + Encoding* encoding_out) const; + + /** + * Get the ExternalStringResource for an external string. Returns + * NULL if IsExternal() doesn't return true. + */ + V8_INLINE ExternalStringResource* GetExternalStringResource() const; + + /** + * Get the ExternalOneByteStringResource for an external one-byte string. + * Returns NULL if IsExternalOneByte() doesn't return true. + */ + const ExternalOneByteStringResource* GetExternalOneByteStringResource() const; + + V8_INLINE static String* Cast(v8::Value* obj); + + // TODO(dcarney): remove with deprecation of New functions. + enum NewStringType { + kNormalString = static_cast<int>(v8::NewStringType::kNormal), + kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized) + }; + + /** Allocates a new string from UTF-8 data.*/ + static V8_DEPRECATED( + "Use maybe version", + Local<String> NewFromUtf8(Isolate* isolate, const char* data, + NewStringType type = kNormalString, + int length = -1)); + + /** Allocates a new string from UTF-8 data. Only returns an empty value when + * length > kMaxLength. **/ + static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8( + Isolate* isolate, const char* data, v8::NewStringType type, + int length = -1); + + /** Allocates a new string from Latin-1 data. Only returns an empty value + * when length > kMaxLength. **/ + static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte( + Isolate* isolate, const uint8_t* data, v8::NewStringType type, + int length = -1); + + /** Allocates a new string from UTF-16 data.*/ + static V8_DEPRECATED( + "Use maybe version", + Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data, + NewStringType type = kNormalString, + int length = -1)); + + /** Allocates a new string from UTF-16 data. Only returns an empty value when + * length > kMaxLength. **/ + static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte( + Isolate* isolate, const uint16_t* data, v8::NewStringType type, + int length = -1); + + /** + * Creates a new string by concatenating the left and the right strings + * passed in as parameters. + */ + static Local<String> Concat(Isolate* isolate, Local<String> left, + Local<String> right); + + /** + * Creates a new external string using the data defined in the given + * resource. When the external string is no longer live on V8's heap the + * resource will be disposed by calling its Dispose method. The caller of + * this function should not otherwise delete or modify the resource. Neither + * should the underlying buffer be deallocated or modified except through the + * destructor of the external string resource. + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte( + Isolate* isolate, ExternalStringResource* resource); + + /** + * Associate an external string resource with this string by transforming it + * in place so that existing references to this string in the JavaScript heap + * will use the external string resource. The external string resource's + * character contents need to be equivalent to this string. + * Returns true if the string has been changed to be an external string. + * The string is not modified if the operation fails. See NewExternal for + * information on the lifetime of the resource. + */ + bool MakeExternal(ExternalStringResource* resource); + + /** + * Creates a new external string using the one-byte data defined in the given + * resource. When the external string is no longer live on V8's heap the + * resource will be disposed by calling its Dispose method. The caller of + * this function should not otherwise delete or modify the resource. Neither + * should the underlying buffer be deallocated or modified except through the + * destructor of the external string resource. + */ + static V8_DEPRECATED( + "Use maybe version", + Local<String> NewExternal(Isolate* isolate, + ExternalOneByteStringResource* resource)); + static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte( + Isolate* isolate, ExternalOneByteStringResource* resource); + + /** + * Associate an external string resource with this string by transforming it + * in place so that existing references to this string in the JavaScript heap + * will use the external string resource. The external string resource's + * character contents need to be equivalent to this string. + * Returns true if the string has been changed to be an external string. + * The string is not modified if the operation fails. See NewExternal for + * information on the lifetime of the resource. + */ + bool MakeExternal(ExternalOneByteStringResource* resource); + + /** + * Returns true if this string can be made external. + */ + bool CanMakeExternal(); + + /** + * Returns true if the strings values are equal. Same as JS ==/===. + */ + bool StringEquals(Local<String> str); + + /** + * Converts an object to a UTF-8-encoded character array. Useful if + * you want to print the object. If conversion to a string fails + * (e.g. due to an exception in the toString() method of the object) + * then the length() method returns 0 and the * operator returns + * NULL. + */ + class V8_EXPORT Utf8Value { + public: + Utf8Value(Isolate* isolate, Local<v8::Value> obj); + ~Utf8Value(); + char* operator*() { return str_; } + const char* operator*() const { return str_; } + int length() const { return length_; } + + // Disallow copying and assigning. + Utf8Value(const Utf8Value&) = delete; + void operator=(const Utf8Value&) = delete; + + private: + char* str_; + int length_; + }; + + /** + * Converts an object to a two-byte (UTF-16-encoded) string. + * If conversion to a string fails (eg. due to an exception in the toString() + * method of the object) then the length() method returns 0 and the * operator + * returns NULL. + */ + class V8_EXPORT Value { + public: + Value(Isolate* isolate, Local<v8::Value> obj); + ~Value(); + uint16_t* operator*() { return str_; } + const uint16_t* operator*() const { return str_; } + int length() const { return length_; } + + // Disallow copying and assigning. + Value(const Value&) = delete; + void operator=(const Value&) = delete; + + private: + uint16_t* str_; + int length_; + }; + + private: + void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, + Encoding encoding) const; + void VerifyExternalStringResource(ExternalStringResource* val) const; + ExternalStringResource* GetExternalStringResourceSlow() const; + ExternalStringResourceBase* GetExternalStringResourceBaseSlow( + String::Encoding* encoding_out) const; + + static void CheckCast(v8::Value* obj); +}; + + +/** + * A JavaScript symbol (ECMA-262 edition 6) + */ +class V8_EXPORT Symbol : public Name { + public: + /** + * Returns the print name string of the symbol, or undefined if none. + */ + Local<Value> Name() const; + + /** + * Create a symbol. If name is not empty, it will be used as the description. + */ + static Local<Symbol> New(Isolate* isolate, + Local<String> name = Local<String>()); + + /** + * Access global symbol registry. + * Note that symbols created this way are never collected, so + * they should only be used for statically fixed properties. + * Also, there is only one global name space for the names used as keys. + * To minimize the potential for clashes, use qualified names as keys. + */ + static Local<Symbol> For(Isolate *isolate, Local<String> name); + + /** + * Retrieve a global symbol. Similar to |For|, but using a separate + * registry that is not accessible by (and cannot clash with) JavaScript code. + */ + static Local<Symbol> ForApi(Isolate *isolate, Local<String> name); + + // Well-known symbols + static Local<Symbol> GetAsyncIterator(Isolate* isolate); + static Local<Symbol> GetHasInstance(Isolate* isolate); + static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate); + static Local<Symbol> GetIterator(Isolate* isolate); + static Local<Symbol> GetMatch(Isolate* isolate); + static Local<Symbol> GetReplace(Isolate* isolate); + static Local<Symbol> GetSearch(Isolate* isolate); + static Local<Symbol> GetSplit(Isolate* isolate); + static Local<Symbol> GetToPrimitive(Isolate* isolate); + static Local<Symbol> GetToStringTag(Isolate* isolate); + static Local<Symbol> GetUnscopables(Isolate* isolate); + + V8_INLINE static Symbol* Cast(Value* obj); + + private: + Symbol(); + static void CheckCast(Value* obj); +}; + + +/** + * A private symbol + * + * This is an experimental feature. Use at your own risk. + */ +class V8_EXPORT Private : public Data { + public: + /** + * Returns the print name string of the private symbol, or undefined if none. + */ + Local<Value> Name() const; + + /** + * Create a private symbol. If name is not empty, it will be the description. + */ + static Local<Private> New(Isolate* isolate, + Local<String> name = Local<String>()); + + /** + * Retrieve a global private symbol. If a symbol with this name has not + * been retrieved in the same isolate before, it is created. + * Note that private symbols created this way are never collected, so + * they should only be used for statically fixed properties. + * Also, there is only one global name space for the names used as keys. + * To minimize the potential for clashes, use qualified names as keys, + * e.g., "Class#property". + */ + static Local<Private> ForApi(Isolate* isolate, Local<String> name); + + V8_INLINE static Private* Cast(Data* data); + + private: + Private(); + + static void CheckCast(Data* that); +}; + + +/** + * A JavaScript number value (ECMA-262, 4.3.20) + */ +class V8_EXPORT Number : public Primitive { + public: + double Value() const; + static Local<Number> New(Isolate* isolate, double value); + V8_INLINE static Number* Cast(v8::Value* obj); + private: + Number(); + static void CheckCast(v8::Value* obj); +}; + + +/** + * A JavaScript value representing a signed integer. + */ +class V8_EXPORT Integer : public Number { + public: + static Local<Integer> New(Isolate* isolate, int32_t value); + static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value); + int64_t Value() const; + V8_INLINE static Integer* Cast(v8::Value* obj); + private: + Integer(); + static void CheckCast(v8::Value* obj); +}; + + +/** + * A JavaScript value representing a 32-bit signed integer. + */ +class V8_EXPORT Int32 : public Integer { + public: + int32_t Value() const; + V8_INLINE static Int32* Cast(v8::Value* obj); + + private: + Int32(); + static void CheckCast(v8::Value* obj); +}; + + +/** + * A JavaScript value representing a 32-bit unsigned integer. + */ +class V8_EXPORT Uint32 : public Integer { + public: + uint32_t Value() const; + V8_INLINE static Uint32* Cast(v8::Value* obj); + + private: + Uint32(); + static void CheckCast(v8::Value* obj); +}; + +/** + * A JavaScript BigInt value (https://tc39.github.io/proposal-bigint) + */ +class V8_EXPORT BigInt : public Primitive { + public: + static Local<BigInt> New(Isolate* isolate, int64_t value); + static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value); + /** + * Creates a new BigInt object using a specified sign bit and a + * specified list of digits/words. + * The resulting number is calculated as: + * + * (-1)^sign_bit * (words[0] * (2^64)^0 + words[1] * (2^64)^1 + ...) + */ + static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit, + int word_count, const uint64_t* words); + + /** + * Returns the value of this BigInt as an unsigned 64-bit integer. + * If `lossless` is provided, it will reflect whether the return value was + * truncated or wrapped around. In particular, it is set to `false` if this + * BigInt is negative. + */ + uint64_t Uint64Value(bool* lossless = nullptr) const; + + /** + * Returns the value of this BigInt as a signed 64-bit integer. + * If `lossless` is provided, it will reflect whether this BigInt was + * truncated or not. + */ + int64_t Int64Value(bool* lossless = nullptr) const; + + /** + * Returns the number of 64-bit words needed to store the result of + * ToWordsArray(). + */ + int WordCount() const; + + /** + * Writes the contents of this BigInt to a specified memory location. + * `sign_bit` must be provided and will be set to 1 if this BigInt is + * negative. + * `*word_count` has to be initialized to the length of the `words` array. + * Upon return, it will be set to the actual number of words that would + * be needed to store this BigInt (i.e. the return value of `WordCount()`). + */ + void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const; + + V8_INLINE static BigInt* Cast(v8::Value* obj); + + private: + BigInt(); + static void CheckCast(v8::Value* obj); +}; + +/** + * PropertyAttribute. + */ +enum PropertyAttribute { + /** None. **/ + None = 0, + /** ReadOnly, i.e., not writable. **/ + ReadOnly = 1 << 0, + /** DontEnum, i.e., not enumerable. **/ + DontEnum = 1 << 1, + /** DontDelete, i.e., not configurable. **/ + DontDelete = 1 << 2 +}; + +/** + * Accessor[Getter|Setter] are used as callback functions when + * setting|getting a particular property. See Object and ObjectTemplate's + * method SetAccessor. + */ +typedef void (*AccessorGetterCallback)( + Local<String> property, + const PropertyCallbackInfo<Value>& info); +typedef void (*AccessorNameGetterCallback)( + Local<Name> property, + const PropertyCallbackInfo<Value>& info); + + +typedef void (*AccessorSetterCallback)( + Local<String> property, + Local<Value> value, + const PropertyCallbackInfo<void>& info); +typedef void (*AccessorNameSetterCallback)( + Local<Name> property, + Local<Value> value, + const PropertyCallbackInfo<void>& info); + + +/** + * Access control specifications. + * + * Some accessors should be accessible across contexts. These + * accessors have an explicit access control parameter which specifies + * the kind of cross-context access that should be allowed. + * + * TODO(dcarney): Remove PROHIBITS_OVERWRITING as it is now unused. + */ +enum AccessControl { + DEFAULT = 0, + ALL_CAN_READ = 1, + ALL_CAN_WRITE = 1 << 1, + PROHIBITS_OVERWRITING = 1 << 2 +}; + +/** + * Property filter bits. They can be or'ed to build a composite filter. + */ +enum PropertyFilter { + ALL_PROPERTIES = 0, + ONLY_WRITABLE = 1, + ONLY_ENUMERABLE = 2, + ONLY_CONFIGURABLE = 4, + SKIP_STRINGS = 8, + SKIP_SYMBOLS = 16 +}; + +/** + * Options for marking whether callbacks may trigger JS-observable side effects. + * Side-effect-free callbacks are whitelisted during debug evaluation with + * throwOnSideEffect. It applies when calling a Function, FunctionTemplate, + * or an Accessor callback. For Interceptors, please see + * PropertyHandlerFlags's kHasNoSideEffect. + * Callbacks that only cause side effects to the receiver are whitelisted if + * invoked on receiver objects that are created within the same debug-evaluate + * call, as these objects are temporary and the side effect does not escape. + */ +enum class SideEffectType { + kHasSideEffect, + kHasNoSideEffect, + kHasSideEffectToReceiver +}; + +/** + * Keys/Properties filter enums: + * + * KeyCollectionMode limits the range of collected properties. kOwnOnly limits + * the collected properties to the given Object only. kIncludesPrototypes will + * include all keys of the objects's prototype chain as well. + */ +enum class KeyCollectionMode { kOwnOnly, kIncludePrototypes }; + +/** + * kIncludesIndices allows for integer indices to be collected, while + * kSkipIndices will exclude integer indices from being collected. + */ +enum class IndexFilter { kIncludeIndices, kSkipIndices }; + +/** + * kConvertToString will convert integer indices to strings. + * kKeepNumbers will return numbers for integer indices. + */ +enum class KeyConversionMode { kConvertToString, kKeepNumbers }; + +/** + * Integrity level for objects. + */ +enum class IntegrityLevel { kFrozen, kSealed }; + +/** + * A JavaScript object (ECMA-262, 4.3.3) + */ +class V8_EXPORT Object : public Value { + public: + V8_DEPRECATE_SOON("Use maybe version", + bool Set(Local<Value> key, Local<Value> value)); + /** + * Set only return Just(true) or Empty(), so if it should never fail, use + * result.Check(). + */ + V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, + Local<Value> key, Local<Value> value); + + V8_DEPRECATE_SOON("Use maybe version", + bool Set(uint32_t index, Local<Value> value)); + V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index, + Local<Value> value); + + // Implements CreateDataProperty (ECMA-262, 7.3.4). + // + // Defines a configurable, writable, enumerable property with the given value + // on the object unless the property already exists and is not configurable + // or the object is not extensible. + // + // Returns true on success. + V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context, + Local<Name> key, + Local<Value> value); + V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context, + uint32_t index, + Local<Value> value); + + // Implements DefineOwnProperty. + // + // In general, CreateDataProperty will be faster, however, does not allow + // for specifying attributes. + // + // Returns true on success. + V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty( + Local<Context> context, Local<Name> key, Local<Value> value, + PropertyAttribute attributes = None); + + // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4. + // + // The defineProperty function is used to add an own property or + // update the attributes of an existing own property of an object. + // + // Both data and accessor descriptors can be used. + // + // In general, CreateDataProperty is faster, however, does not allow + // for specifying attributes or an accessor descriptor. + // + // The PropertyDescriptor can change when redefining a property. + // + // Returns true on success. + V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty( + Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor); + + V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key)); + V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context, + Local<Value> key); + + V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index)); + V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context, + uint32_t index); + + /** + * Gets the property attributes of a property which can be None or + * any combination of ReadOnly, DontEnum and DontDelete. Returns + * None when the property doesn't exist. + */ + V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes( + Local<Context> context, Local<Value> key); + + /** + * Returns Object.getOwnPropertyDescriptor as per ES2016 section 19.1.2.6. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor( + Local<Context> context, Local<Name> key); + + /** + * Object::Has() calls the abstract operation HasProperty(O, P) described + * in ECMA-262, 7.3.10. Has() returns + * true, if the object has the property, either own or on the prototype chain. + * Interceptors, i.e., PropertyQueryCallbacks, are called if present. + * + * Has() has the same side effects as JavaScript's `variable in object`. + * For example, calling Has() on a revoked proxy will throw an exception. + * + * \note Has() converts the key to a name, which possibly calls back into + * JavaScript. + * + * See also v8::Object::HasOwnProperty() and + * v8::Object::HasRealNamedProperty(). + */ + V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, + Local<Value> key); + + V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context, + Local<Value> key); + + V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index); + + V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context, + uint32_t index); + + /** + * Note: SideEffectType affects the getter only, not the setter. + */ + V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor( + Local<Context> context, Local<Name> name, + AccessorNameGetterCallback getter, + AccessorNameSetterCallback setter = nullptr, + MaybeLocal<Value> data = MaybeLocal<Value>(), + AccessControl settings = DEFAULT, PropertyAttribute attribute = None, + SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, + SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); + + void SetAccessorProperty(Local<Name> name, Local<Function> getter, + Local<Function> setter = Local<Function>(), + PropertyAttribute attribute = None, + AccessControl settings = DEFAULT); + + /** + * Sets a native data property like Template::SetNativeDataProperty, but + * this method sets on this object directly. + */ + V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty( + Local<Context> context, Local<Name> name, + AccessorNameGetterCallback getter, + AccessorNameSetterCallback setter = nullptr, + Local<Value> data = Local<Value>(), PropertyAttribute attributes = None, + SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, + SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); + + /** + * Attempts to create a property with the given name which behaves like a data + * property, except that the provided getter is invoked (and provided with the + * data value) to supply its value the first time it is read. After the + * property is accessed once, it is replaced with an ordinary data property. + * + * Analogous to Template::SetLazyDataProperty. + */ + V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty( + Local<Context> context, Local<Name> name, + AccessorNameGetterCallback getter, Local<Value> data = Local<Value>(), + PropertyAttribute attributes = None, + SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, + SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); + + /** + * Functionality for private properties. + * This is an experimental feature, use at your own risk. + * Note: Private properties are not inherited. Do not rely on this, since it + * may change. + */ + Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key); + Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key, + Local<Value> value); + Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key); + MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key); + + /** + * Returns an array containing the names of the enumerable properties + * of this object, including properties from prototype objects. The + * array returned by this method contains the same values as would + * be enumerated by a for-in statement over this object. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames( + Local<Context> context); + V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames( + Local<Context> context, KeyCollectionMode mode, + PropertyFilter property_filter, IndexFilter index_filter, + KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers); + + /** + * This function has the same functionality as GetPropertyNames but + * the returned array doesn't contain the names of properties from + * prototype objects. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames( + Local<Context> context); + + /** + * Returns an array containing the names of the filtered properties + * of this object, including properties from prototype objects. The + * array returned by this method contains the same values as would + * be enumerated by a for-in statement over this object. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames( + Local<Context> context, PropertyFilter filter, + KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers); + + /** + * Get the prototype object. This does not skip objects marked to + * be skipped by __proto__ and it does not consult the security + * handler. + */ + Local<Value> GetPrototype(); + + /** + * Set the prototype object. This does not skip objects marked to + * be skipped by __proto__ and it does not consult the security + * handler. + */ + V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context, + Local<Value> prototype); + + /** + * Finds an instance of the given function template in the prototype + * chain. + */ + Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl); + + /** + * Call builtin Object.prototype.toString on this object. + * This is different from Value::ToString() that may call + * user-defined toString function. This one does not. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString( + Local<Context> context); + + /** + * Returns the name of the function invoked as a constructor for this object. + */ + Local<String> GetConstructorName(); + + /** + * Sets the integrity level of the object. + */ + Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level); + + /** Gets the number of internal fields for this Object. */ + int InternalFieldCount(); + + /** Same as above, but works for PersistentBase. */ + V8_INLINE static int InternalFieldCount( + const PersistentBase<Object>& object) { + return object.val_->InternalFieldCount(); + } + + /** Same as above, but works for TracedGlobal. */ + V8_INLINE static int InternalFieldCount(const TracedGlobal<Object>& object) { + return object.val_->InternalFieldCount(); + } + + /** Gets the value from an internal field. */ + V8_INLINE Local<Value> GetInternalField(int index); + + /** Sets the value in an internal field. */ + void SetInternalField(int index, Local<Value> value); + + /** + * Gets a 2-byte-aligned native pointer from an internal field. This field + * must have been set by SetAlignedPointerInInternalField, everything else + * leads to undefined behavior. + */ + V8_INLINE void* GetAlignedPointerFromInternalField(int index); + + /** Same as above, but works for PersistentBase. */ + V8_INLINE static void* GetAlignedPointerFromInternalField( + const PersistentBase<Object>& object, int index) { + return object.val_->GetAlignedPointerFromInternalField(index); + } + + /** Same as above, but works for TracedGlobal. */ + V8_INLINE static void* GetAlignedPointerFromInternalField( + const TracedGlobal<Object>& object, int index) { + return object.val_->GetAlignedPointerFromInternalField(index); + } + + /** + * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such + * a field, GetAlignedPointerFromInternalField must be used, everything else + * leads to undefined behavior. + */ + void SetAlignedPointerInInternalField(int index, void* value); + void SetAlignedPointerInInternalFields(int argc, int indices[], + void* values[]); + + /** + * HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty(). + * + * See also v8::Object::Has() and v8::Object::HasRealNamedProperty(). + */ + V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context, + Local<Name> key); + V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context, + uint32_t index); + /** + * Use HasRealNamedProperty() if you want to check if an object has an own + * property without causing side effects, i.e., without calling interceptors. + * + * This function is similar to v8::Object::HasOwnProperty(), but it does not + * call interceptors. + * + * \note Consider using non-masking interceptors, i.e., the interceptors are + * not called if the receiver has the real named property. See + * `v8::PropertyHandlerFlags::kNonMasking`. + * + * See also v8::Object::Has(). + */ + V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context, + Local<Name> key); + V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty( + Local<Context> context, uint32_t index); + V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty( + Local<Context> context, Local<Name> key); + + /** + * If result.IsEmpty() no real property was located in the prototype chain. + * This means interceptors in the prototype chain are not called. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain( + Local<Context> context, Local<Name> key); + + /** + * Gets the property attributes of a real property in the prototype chain, + * which can be None or any combination of ReadOnly, DontEnum and DontDelete. + * Interceptors in the prototype chain are not called. + */ + V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> + GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context, + Local<Name> key); + + /** + * If result.IsEmpty() no real property was located on the object or + * in the prototype chain. + * This means interceptors in the prototype chain are not called. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty( + Local<Context> context, Local<Name> key); + + /** + * Gets the property attributes of a real property which can be + * None or any combination of ReadOnly, DontEnum and DontDelete. + * Interceptors in the prototype chain are not called. + */ + V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes( + Local<Context> context, Local<Name> key); + + /** Tests for a named lookup interceptor.*/ + bool HasNamedLookupInterceptor(); + + /** Tests for an index lookup interceptor.*/ + bool HasIndexedLookupInterceptor(); + + /** + * Returns the identity hash for this object. The current implementation + * uses a hidden property on the object to store the identity hash. + * + * The return value will never be 0. Also, it is not guaranteed to be + * unique. + */ + int GetIdentityHash(); + + /** + * Clone this object with a fast but shallow copy. Values will point + * to the same values as the original object. + */ + // TODO(dcarney): take an isolate and optionally bail out? + Local<Object> Clone(); + + /** + * Returns the context in which the object was created. + */ + Local<Context> CreationContext(); + + /** Same as above, but works for Persistents */ + V8_INLINE static Local<Context> CreationContext( + const PersistentBase<Object>& object) { + return object.val_->CreationContext(); + } + + /** + * Checks whether a callback is set by the + * ObjectTemplate::SetCallAsFunctionHandler method. + * When an Object is callable this method returns true. + */ + bool IsCallable(); + + /** + * True if this object is a constructor. + */ + bool IsConstructor(); + + /** + * Call an Object as a function if a callback is set by the + * ObjectTemplate::SetCallAsFunctionHandler method. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context, + Local<Value> recv, + int argc, + Local<Value> argv[]); + + /** + * Call an Object as a constructor if a callback is set by the + * ObjectTemplate::SetCallAsFunctionHandler method. + * Note: This method behaves like the Function::NewInstance method. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor( + Local<Context> context, int argc, Local<Value> argv[]); + + /** + * Return the isolate to which the Object belongs to. + */ + Isolate* GetIsolate(); + + /** + * If this object is a Set, Map, WeakSet or WeakMap, this returns a + * representation of the elements of this object as an array. + * If this object is a SetIterator or MapIterator, this returns all + * elements of the underlying collection, starting at the iterator's current + * position. + * For other types, this will return an empty MaybeLocal<Array> (without + * scheduling an exception). + */ + MaybeLocal<Array> PreviewEntries(bool* is_key_value); + + static Local<Object> New(Isolate* isolate); + + /** + * Creates a JavaScript object with the given properties, and + * a the given prototype_or_null (which can be any JavaScript + * value, and if it's null, the newly created object won't have + * a prototype at all). This is similar to Object.create(). + * All properties will be created as enumerable, configurable + * and writable properties. + */ + static Local<Object> New(Isolate* isolate, Local<Value> prototype_or_null, + Local<Name>* names, Local<Value>* values, + size_t length); + + V8_INLINE static Object* Cast(Value* obj); + + private: + Object(); + static void CheckCast(Value* obj); + Local<Value> SlowGetInternalField(int index); + void* SlowGetAlignedPointerFromInternalField(int index); +}; + + +/** + * An instance of the built-in array constructor (ECMA-262, 15.4.2). + */ +class V8_EXPORT Array : public Object { + public: + uint32_t Length() const; + + /** + * Creates a JavaScript array with the given length. If the length + * is negative the returned array will have length 0. + */ + static Local<Array> New(Isolate* isolate, int length = 0); + + /** + * Creates a JavaScript array out of a Local<Value> array in C++ + * with a known length. + */ + static Local<Array> New(Isolate* isolate, Local<Value>* elements, + size_t length); + V8_INLINE static Array* Cast(Value* obj); + private: + Array(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1). + */ +class V8_EXPORT Map : public Object { + public: + size_t Size() const; + void Clear(); + V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context, + Local<Value> key); + V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context, + Local<Value> key, + Local<Value> value); + V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, + Local<Value> key); + V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context, + Local<Value> key); + + /** + * Returns an array of length Size() * 2, where index N is the Nth key and + * index N + 1 is the Nth value. + */ + Local<Array> AsArray() const; + + /** + * Creates a new empty Map. + */ + static Local<Map> New(Isolate* isolate); + + V8_INLINE static Map* Cast(Value* obj); + + private: + Map(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1). + */ +class V8_EXPORT Set : public Object { + public: + size_t Size() const; + void Clear(); + V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context, + Local<Value> key); + V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, + Local<Value> key); + V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context, + Local<Value> key); + + /** + * Returns an array of the keys in this Set. + */ + Local<Array> AsArray() const; + + /** + * Creates a new empty Set. + */ + static Local<Set> New(Isolate* isolate); + + V8_INLINE static Set* Cast(Value* obj); + + private: + Set(); + static void CheckCast(Value* obj); +}; + + +template<typename T> +class ReturnValue { + public: + template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that) + : value_(that.value_) { + TYPE_CHECK(T, S); + } + // Local setters + template <typename S> + V8_INLINE V8_DEPRECATED("Use Global<> instead", + void Set(const Persistent<S>& handle)); + template <typename S> + V8_INLINE void Set(const Global<S>& handle); + template <typename S> + V8_INLINE void Set(const TracedGlobal<S>& handle); + template <typename S> + V8_INLINE void Set(const Local<S> handle); + // Fast primitive setters + V8_INLINE void Set(bool value); + V8_INLINE void Set(double i); + V8_INLINE void Set(int32_t i); + V8_INLINE void Set(uint32_t i); + // Fast JS primitive setters + V8_INLINE void SetNull(); + V8_INLINE void SetUndefined(); + V8_INLINE void SetEmptyString(); + // Convenience getter for Isolate + V8_INLINE Isolate* GetIsolate() const; + + // Pointer setter: Uncompilable to prevent inadvertent misuse. + template <typename S> + V8_INLINE void Set(S* whatever); + + // Getter. Creates a new Local<> so it comes with a certain performance + // hit. If the ReturnValue was not yet set, this will return the undefined + // value. + V8_INLINE Local<Value> Get() const; + + private: + template<class F> friend class ReturnValue; + template<class F> friend class FunctionCallbackInfo; + template<class F> friend class PropertyCallbackInfo; + template <class F, class G, class H> + friend class PersistentValueMapBase; + V8_INLINE void SetInternal(internal::Address value) { *value_ = value; } + V8_INLINE internal::Address GetDefaultValue(); + V8_INLINE explicit ReturnValue(internal::Address* slot); + internal::Address* value_; +}; + + +/** + * The argument information given to function call callbacks. This + * class provides access to information about the context of the call, + * including the receiver, the number and values of arguments, and + * the holder of the function. + */ +template<typename T> +class FunctionCallbackInfo { + public: + /** The number of available arguments. */ + V8_INLINE int Length() const; + /** Accessor for the available arguments. */ + V8_INLINE Local<Value> operator[](int i) const; + /** Returns the receiver. This corresponds to the "this" value. */ + V8_INLINE Local<Object> This() const; + /** + * If the callback was created without a Signature, this is the same + * value as This(). If there is a signature, and the signature didn't match + * This() but one of its hidden prototypes, this will be the respective + * hidden prototype. + * + * Note that this is not the prototype of This() on which the accessor + * referencing this callback was found (which in V8 internally is often + * referred to as holder [sic]). + */ + V8_INLINE Local<Object> Holder() const; + /** For construct calls, this returns the "new.target" value. */ + V8_INLINE Local<Value> NewTarget() const; + /** Indicates whether this is a regular call or a construct call. */ + V8_INLINE bool IsConstructCall() const; + /** The data argument specified when creating the callback. */ + V8_INLINE Local<Value> Data() const; + /** The current Isolate. */ + V8_INLINE Isolate* GetIsolate() const; + /** The ReturnValue for the call. */ + V8_INLINE ReturnValue<T> GetReturnValue() const; + // This shouldn't be public, but the arm compiler needs it. + static const int kArgsLength = 6; + + protected: + friend class internal::FunctionCallbackArguments; + friend class internal::CustomArguments<FunctionCallbackInfo>; + friend class debug::ConsoleCallArguments; + static const int kHolderIndex = 0; + static const int kIsolateIndex = 1; + static const int kReturnValueDefaultValueIndex = 2; + static const int kReturnValueIndex = 3; + static const int kDataIndex = 4; + static const int kNewTargetIndex = 5; + + V8_INLINE FunctionCallbackInfo(internal::Address* implicit_args, + internal::Address* values, int length); + internal::Address* implicit_args_; + internal::Address* values_; + int length_; +}; + + +/** + * The information passed to a property callback about the context + * of the property access. + */ +template<typename T> +class PropertyCallbackInfo { + public: + /** + * \return The isolate of the property access. + */ + V8_INLINE Isolate* GetIsolate() const; + + /** + * \return The data set in the configuration, i.e., in + * `NamedPropertyHandlerConfiguration` or + * `IndexedPropertyHandlerConfiguration.` + */ + V8_INLINE Local<Value> Data() const; + + /** + * \return The receiver. In many cases, this is the object on which the + * property access was intercepted. When using + * `Reflect.get`, `Function.prototype.call`, or similar functions, it is the + * object passed in as receiver or thisArg. + * + * \code + * void GetterCallback(Local<Name> name, + * const v8::PropertyCallbackInfo<v8::Value>& info) { + * auto context = info.GetIsolate()->GetCurrentContext(); + * + * v8::Local<v8::Value> a_this = + * info.This() + * ->GetRealNamedProperty(context, v8_str("a")) + * .ToLocalChecked(); + * v8::Local<v8::Value> a_holder = + * info.Holder() + * ->GetRealNamedProperty(context, v8_str("a")) + * .ToLocalChecked(); + * + * CHECK(v8_str("r")->Equals(context, a_this).FromJust()); + * CHECK(v8_str("obj")->Equals(context, a_holder).FromJust()); + * + * info.GetReturnValue().Set(name); + * } + * + * v8::Local<v8::FunctionTemplate> templ = + * v8::FunctionTemplate::New(isolate); + * templ->InstanceTemplate()->SetHandler( + * v8::NamedPropertyHandlerConfiguration(GetterCallback)); + * LocalContext env; + * env->Global() + * ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) + * .ToLocalChecked() + * ->NewInstance(env.local()) + * .ToLocalChecked()) + * .FromJust(); + * + * CompileRun("obj.a = 'obj'; var r = {a: 'r'}; Reflect.get(obj, 'x', r)"); + * \endcode + */ + V8_INLINE Local<Object> This() const; + + /** + * \return The object in the prototype chain of the receiver that has the + * interceptor. Suppose you have `x` and its prototype is `y`, and `y` + * has an interceptor. Then `info.This()` is `x` and `info.Holder()` is `y`. + * The Holder() could be a hidden object (the global object, rather + * than the global proxy). + * + * \note For security reasons, do not pass the object back into the runtime. + */ + V8_INLINE Local<Object> Holder() const; + + /** + * \return The return value of the callback. + * Can be changed by calling Set(). + * \code + * info.GetReturnValue().Set(...) + * \endcode + * + */ + V8_INLINE ReturnValue<T> GetReturnValue() const; + + /** + * \return True if the intercepted function should throw if an error occurs. + * Usually, `true` corresponds to `'use strict'`. + * + * \note Always `false` when intercepting `Reflect.set()` + * independent of the language mode. + */ + V8_INLINE bool ShouldThrowOnError() const; + + // This shouldn't be public, but the arm compiler needs it. + static const int kArgsLength = 7; + + protected: + friend class MacroAssembler; + friend class internal::PropertyCallbackArguments; + friend class internal::CustomArguments<PropertyCallbackInfo>; + static const int kShouldThrowOnErrorIndex = 0; + static const int kHolderIndex = 1; + static const int kIsolateIndex = 2; + static const int kReturnValueDefaultValueIndex = 3; + static const int kReturnValueIndex = 4; + static const int kDataIndex = 5; + static const int kThisIndex = 6; + + V8_INLINE PropertyCallbackInfo(internal::Address* args) : args_(args) {} + internal::Address* args_; +}; + + +typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info); + +enum class ConstructorBehavior { kThrow, kAllow }; + +/** + * A JavaScript function object (ECMA-262, 15.3). + */ +class V8_EXPORT Function : public Object { + public: + /** + * Create a function in the current execution context + * for a given FunctionCallback. + */ + static MaybeLocal<Function> New( + Local<Context> context, FunctionCallback callback, + Local<Value> data = Local<Value>(), int length = 0, + ConstructorBehavior behavior = ConstructorBehavior::kAllow, + SideEffectType side_effect_type = SideEffectType::kHasSideEffect); + + V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance( + Local<Context> context, int argc, Local<Value> argv[]) const; + + V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance( + Local<Context> context) const { + return NewInstance(context, 0, nullptr); + } + + /** + * When side effect checks are enabled, passing kHasNoSideEffect allows the + * constructor to be invoked without throwing. Calls made within the + * constructor are still checked. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType( + Local<Context> context, int argc, Local<Value> argv[], + SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const; + + V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context, + Local<Value> recv, int argc, + Local<Value> argv[]); + + void SetName(Local<String> name); + Local<Value> GetName() const; + + /** + * Name inferred from variable or property assignment of this function. + * Used to facilitate debugging and profiling of JavaScript code written + * in an OO style, where many functions are anonymous but are assigned + * to object properties. + */ + Local<Value> GetInferredName() const; + + /** + * displayName if it is set, otherwise name if it is configured, otherwise + * function name, otherwise inferred name. + */ + Local<Value> GetDebugName() const; + + /** + * User-defined name assigned to the "displayName" property of this function. + * Used to facilitate debugging and profiling of JavaScript code. + */ + Local<Value> GetDisplayName() const; + + /** + * Returns zero based line number of function body and + * kLineOffsetNotFound if no information available. + */ + int GetScriptLineNumber() const; + /** + * Returns zero based column number of function body and + * kLineOffsetNotFound if no information available. + */ + int GetScriptColumnNumber() const; + + /** + * Returns scriptId. + */ + int ScriptId() const; + + /** + * Returns the original function if this function is bound, else returns + * v8::Undefined. + */ + Local<Value> GetBoundFunction() const; + + ScriptOrigin GetScriptOrigin() const; + V8_INLINE static Function* Cast(Value* obj); + static const int kLineOffsetNotFound; + + private: + Function(); + static void CheckCast(Value* obj); +}; + +#ifndef V8_PROMISE_INTERNAL_FIELD_COUNT +// The number of required internal fields can be defined by embedder. +#define V8_PROMISE_INTERNAL_FIELD_COUNT 0 +#endif + +/** + * An instance of the built-in Promise constructor (ES6 draft). + */ +class V8_EXPORT Promise : public Object { + public: + /** + * State of the promise. Each value corresponds to one of the possible values + * of the [[PromiseState]] field. + */ + enum PromiseState { kPending, kFulfilled, kRejected }; + + class V8_EXPORT Resolver : public Object { + public: + /** + * Create a new resolver, along with an associated promise in pending state. + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New( + Local<Context> context); + + /** + * Extract the associated promise. + */ + Local<Promise> GetPromise(); + + /** + * Resolve/reject the associated promise with a given value. + * Ignored if the promise is no longer pending. + */ + V8_WARN_UNUSED_RESULT Maybe<bool> Resolve(Local<Context> context, + Local<Value> value); + + V8_WARN_UNUSED_RESULT Maybe<bool> Reject(Local<Context> context, + Local<Value> value); + + V8_INLINE static Resolver* Cast(Value* obj); + + private: + Resolver(); + static void CheckCast(Value* obj); + }; + + /** + * Register a resolution/rejection handler with a promise. + * The handler is given the respective resolution/rejection value as + * an argument. If the promise is already resolved/rejected, the handler is + * invoked at the end of turn. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context, + Local<Function> handler); + + V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context, + Local<Function> handler); + + V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context, + Local<Function> on_fulfilled, + Local<Function> on_rejected); + + /** + * Returns true if the promise has at least one derived promise, and + * therefore resolve/reject handlers (including default handler). + */ + bool HasHandler(); + + /** + * Returns the content of the [[PromiseResult]] field. The Promise must not + * be pending. + */ + Local<Value> Result(); + + /** + * Returns the value of the [[PromiseState]] field. + */ + PromiseState State(); + + /** + * Marks this promise as handled to avoid reporting unhandled rejections. + */ + void MarkAsHandled(); + + V8_INLINE static Promise* Cast(Value* obj); + + static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT; + + private: + Promise(); + static void CheckCast(Value* obj); +}; + +/** + * An instance of a Property Descriptor, see Ecma-262 6.2.4. + * + * Properties in a descriptor are present or absent. If you do not set + * `enumerable`, `configurable`, and `writable`, they are absent. If `value`, + * `get`, or `set` are absent, but you must specify them in the constructor, use + * empty handles. + * + * Accessors `get` and `set` must be callable or undefined if they are present. + * + * \note Only query properties if they are present, i.e., call `x()` only if + * `has_x()` returns true. + * + * \code + * // var desc = {writable: false} + * v8::PropertyDescriptor d(Local<Value>()), false); + * d.value(); // error, value not set + * if (d.has_writable()) { + * d.writable(); // false + * } + * + * // var desc = {value: undefined} + * v8::PropertyDescriptor d(v8::Undefined(isolate)); + * + * // var desc = {get: undefined} + * v8::PropertyDescriptor d(v8::Undefined(isolate), Local<Value>())); + * \endcode + */ +class V8_EXPORT PropertyDescriptor { + public: + // GenericDescriptor + PropertyDescriptor(); + + // DataDescriptor + explicit PropertyDescriptor(Local<Value> value); + + // DataDescriptor with writable property + PropertyDescriptor(Local<Value> value, bool writable); + + // AccessorDescriptor + PropertyDescriptor(Local<Value> get, Local<Value> set); + + ~PropertyDescriptor(); + + Local<Value> value() const; + bool has_value() const; + + Local<Value> get() const; + bool has_get() const; + Local<Value> set() const; + bool has_set() const; + + void set_enumerable(bool enumerable); + bool enumerable() const; + bool has_enumerable() const; + + void set_configurable(bool configurable); + bool configurable() const; + bool has_configurable() const; + + bool writable() const; + bool has_writable() const; + + struct PrivateData; + PrivateData* get_private() const { return private_; } + + PropertyDescriptor(const PropertyDescriptor&) = delete; + void operator=(const PropertyDescriptor&) = delete; + + private: + PrivateData* private_; +}; + +/** + * An instance of the built-in Proxy constructor (ECMA-262, 6th Edition, + * 26.2.1). + */ +class V8_EXPORT Proxy : public Object { + public: + Local<Value> GetTarget(); + Local<Value> GetHandler(); + bool IsRevoked(); + void Revoke(); + + /** + * Creates a new Proxy for the target object. + */ + static MaybeLocal<Proxy> New(Local<Context> context, + Local<Object> local_target, + Local<Object> local_handler); + + V8_INLINE static Proxy* Cast(Value* obj); + + private: + Proxy(); + static void CheckCast(Value* obj); +}; + +/** + * Points to an unowned continous buffer holding a known number of elements. + * + * This is similar to std::span (under consideration for C++20), but does not + * require advanced C++ support. In the (far) future, this may be replaced with + * or aliased to std::span. + * + * To facilitate future migration, this class exposes a subset of the interface + * implemented by std::span. + */ +template <typename T> +class V8_EXPORT MemorySpan { + public: + /** The default constructor creates an empty span. */ + constexpr MemorySpan() = default; + + constexpr MemorySpan(T* data, size_t size) : data_(data), size_(size) {} + + /** Returns a pointer to the beginning of the buffer. */ + constexpr T* data() const { return data_; } + /** Returns the number of elements that the buffer holds. */ + constexpr size_t size() const { return size_; } + + private: + T* data_ = nullptr; + size_t size_ = 0; +}; + +/** + * An owned byte buffer with associated size. + */ +struct OwnedBuffer { + std::unique_ptr<const uint8_t[]> buffer; + size_t size = 0; + OwnedBuffer(std::unique_ptr<const uint8_t[]> buffer, size_t size) + : buffer(std::move(buffer)), size(size) {} + OwnedBuffer() = default; +}; + +// Wrapper around a compiled WebAssembly module, which is potentially shared by +// different WasmModuleObjects. +class V8_EXPORT CompiledWasmModule { + public: + /** + * Serialize the compiled module. The serialized data does not include the + * wire bytes. + */ + OwnedBuffer Serialize(); + + /** + * Get the (wasm-encoded) wire bytes that were used to compile this module. + */ + MemorySpan<const uint8_t> GetWireBytesRef(); + + private: + explicit CompiledWasmModule(std::shared_ptr<internal::wasm::NativeModule>); + friend class Utils; + + const std::shared_ptr<internal::wasm::NativeModule> native_module_; +}; + +// An instance of WebAssembly.Module. +class V8_EXPORT WasmModuleObject : public Object { + public: + /** + * An opaque, native heap object for transferring wasm modules. It + * supports move semantics, and does not support copy semantics. + * TODO(wasm): Merge this with CompiledWasmModule once code sharing is always + * enabled. + */ + class TransferrableModule final { + public: + TransferrableModule(TransferrableModule&& src) = default; + TransferrableModule(const TransferrableModule& src) = delete; + + TransferrableModule& operator=(TransferrableModule&& src) = default; + TransferrableModule& operator=(const TransferrableModule& src) = delete; + + private: + typedef std::shared_ptr<internal::wasm::NativeModule> SharedModule; + friend class WasmModuleObject; + explicit TransferrableModule(SharedModule shared_module) + : shared_module_(std::move(shared_module)) {} + TransferrableModule(OwnedBuffer serialized, OwnedBuffer bytes) + : serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {} + + SharedModule shared_module_; + OwnedBuffer serialized_ = {nullptr, 0}; + OwnedBuffer wire_bytes_ = {nullptr, 0}; + }; + + /** + * Get an in-memory, non-persistable, and context-independent (meaning, + * suitable for transfer to another Isolate and Context) representation + * of this wasm compiled module. + */ + TransferrableModule GetTransferrableModule(); + + /** + * Efficiently re-create a WasmModuleObject, without recompiling, from + * a TransferrableModule. + */ + static MaybeLocal<WasmModuleObject> FromTransferrableModule( + Isolate* isolate, const TransferrableModule&); + + /** + * Get the compiled module for this module object. The compiled module can be + * shared by several module objects. + */ + CompiledWasmModule GetCompiledModule(); + + /** + * If possible, deserialize the module, otherwise compile it from the provided + * uncompiled bytes. + */ + static MaybeLocal<WasmModuleObject> DeserializeOrCompile( + Isolate* isolate, MemorySpan<const uint8_t> serialized_module, + MemorySpan<const uint8_t> wire_bytes); + V8_INLINE static WasmModuleObject* Cast(Value* obj); + + private: + static MaybeLocal<WasmModuleObject> Deserialize( + Isolate* isolate, MemorySpan<const uint8_t> serialized_module, + MemorySpan<const uint8_t> wire_bytes); + static MaybeLocal<WasmModuleObject> Compile(Isolate* isolate, + const uint8_t* start, + size_t length); + static MemorySpan<const uint8_t> AsReference(const OwnedBuffer& buff) { + return {buff.buffer.get(), buff.size}; + } + + WasmModuleObject(); + static void CheckCast(Value* obj); +}; + +/** + * The V8 interface for WebAssembly streaming compilation. When streaming + * compilation is initiated, V8 passes a {WasmStreaming} object to the embedder + * such that the embedder can pass the input bytes for streaming compilation to + * V8. + */ +class V8_EXPORT WasmStreaming final { + public: + class WasmStreamingImpl; + + /** + * Client to receive streaming event notifications. + */ + class Client { + public: + virtual ~Client() = default; + /** + * Passes the fully compiled module to the client. This can be used to + * implement code caching. + */ + virtual void OnModuleCompiled(CompiledWasmModule compiled_module) = 0; + }; + + explicit WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl); + + ~WasmStreaming(); + + /** + * Pass a new chunk of bytes to WebAssembly streaming compilation. + * The buffer passed into {OnBytesReceived} is owned by the caller. + */ + void OnBytesReceived(const uint8_t* bytes, size_t size); + + /** + * {Finish} should be called after all received bytes where passed to + * {OnBytesReceived} to tell V8 that there will be no more bytes. {Finish} + * does not have to be called after {Abort} has been called already. + */ + void Finish(); + + /** + * Abort streaming compilation. If {exception} has a value, then the promise + * associated with streaming compilation is rejected with that value. If + * {exception} does not have value, the promise does not get rejected. + */ + void Abort(MaybeLocal<Value> exception); + + /** + * Passes previously compiled module bytes. This must be called before + * {OnBytesReceived}, {Finish}, or {Abort}. Returns true if the module bytes + * can be used, false otherwise. The buffer passed via {bytes} and {size} + * is owned by the caller. If {SetCompiledModuleBytes} returns true, the + * buffer must remain valid until either {Finish} or {Abort} completes. + */ + bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size); + + /** + * Sets the client object that will receive streaming event notifications. + * This must be called before {OnBytesReceived}, {Finish}, or {Abort}. + */ + void SetClient(std::shared_ptr<Client> client); + + /** + * Unpacks a {WasmStreaming} object wrapped in a {Managed} for the embedder. + * Since the embedder is on the other side of the API, it cannot unpack the + * {Managed} itself. + */ + static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate, + Local<Value> value); + + private: + std::unique_ptr<WasmStreamingImpl> impl_; +}; + +// TODO(mtrofin): when streaming compilation is done, we can rename this +// to simply WasmModuleObjectBuilder +class V8_EXPORT WasmModuleObjectBuilderStreaming final { + public: + explicit WasmModuleObjectBuilderStreaming(Isolate* isolate); + /** + * The buffer passed into OnBytesReceived is owned by the caller. + */ + void OnBytesReceived(const uint8_t*, size_t size); + void Finish(); + /** + * Abort streaming compilation. If {exception} has a value, then the promise + * associated with streaming compilation is rejected with that value. If + * {exception} does not have value, the promise does not get rejected. + */ + void Abort(MaybeLocal<Value> exception); + Local<Promise> GetPromise(); + + ~WasmModuleObjectBuilderStreaming() = default; + + private: + WasmModuleObjectBuilderStreaming(const WasmModuleObjectBuilderStreaming&) = + delete; + WasmModuleObjectBuilderStreaming(WasmModuleObjectBuilderStreaming&&) = + default; + WasmModuleObjectBuilderStreaming& operator=( + const WasmModuleObjectBuilderStreaming&) = delete; + WasmModuleObjectBuilderStreaming& operator=( + WasmModuleObjectBuilderStreaming&&) = default; + Isolate* isolate_ = nullptr; + +#if V8_CC_MSVC + /** + * We don't need the static Copy API, so the default + * NonCopyablePersistentTraits would be sufficient, however, + * MSVC eagerly instantiates the Copy. + * We ensure we don't use Copy, however, by compiling with the + * defaults everywhere else. + */ + Persistent<Promise, CopyablePersistentTraits<Promise>> promise_; +#else + Persistent<Promise> promise_; +#endif + std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_; +}; + +#ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT +// The number of required internal fields can be defined by embedder. +#define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 +#endif + + +enum class ArrayBufferCreationMode { kInternalized, kExternalized }; + + +/** + * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). + */ +class V8_EXPORT ArrayBuffer : public Object { + public: + /** + * A thread-safe allocator that V8 uses to allocate |ArrayBuffer|'s memory. + * The allocator is a global V8 setting. It has to be set via + * Isolate::CreateParams. + * + * Memory allocated through this allocator by V8 is accounted for as external + * memory by V8. Note that V8 keeps track of the memory for all internalized + * |ArrayBuffer|s. Responsibility for tracking external memory (using + * Isolate::AdjustAmountOfExternalAllocatedMemory) is handed over to the + * embedder upon externalization and taken over upon internalization (creating + * an internalized buffer from an existing buffer). + * + * Note that it is unsafe to call back into V8 from any of the allocator + * functions. + */ + class V8_EXPORT Allocator { // NOLINT + public: + virtual ~Allocator() = default; + + /** + * Allocate |length| bytes. Return NULL if allocation is not successful. + * Memory should be initialized to zeroes. + */ + virtual void* Allocate(size_t length) = 0; + + /** + * Allocate |length| bytes. Return NULL if allocation is not successful. + * Memory does not have to be initialized. + */ + virtual void* AllocateUninitialized(size_t length) = 0; + + /** + * Free the memory block of size |length|, pointed to by |data|. + * That memory is guaranteed to be previously allocated by |Allocate|. + */ + virtual void Free(void* data, size_t length) = 0; + + /** + * ArrayBuffer allocation mode. kNormal is a malloc/free style allocation, + * while kReservation is for larger allocations with the ability to set + * access permissions. + */ + enum class AllocationMode { kNormal, kReservation }; + + /** + * malloc/free based convenience allocator. + * + * Caller takes ownership, i.e. the returned object needs to be freed using + * |delete allocator| once it is no longer in use. + */ + static Allocator* NewDefaultAllocator(); + }; + + /** + * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| + * returns an instance of this class, populated, with a pointer to data + * and byte length. + * + * The Data pointer of ArrayBuffer::Contents must be freed using the provided + * deleter, which will call ArrayBuffer::Allocator::Free if the buffer + * was allocated with ArraryBuffer::Allocator::Allocate. + */ + class V8_EXPORT Contents { // NOLINT + public: + using DeleterCallback = void (*)(void* buffer, size_t length, void* info); + + Contents() + : data_(nullptr), + byte_length_(0), + allocation_base_(nullptr), + allocation_length_(0), + allocation_mode_(Allocator::AllocationMode::kNormal), + deleter_(nullptr), + deleter_data_(nullptr) {} + + void* AllocationBase() const { return allocation_base_; } + size_t AllocationLength() const { return allocation_length_; } + Allocator::AllocationMode AllocationMode() const { + return allocation_mode_; + } + + void* Data() const { return data_; } + size_t ByteLength() const { return byte_length_; } + DeleterCallback Deleter() const { return deleter_; } + void* DeleterData() const { return deleter_data_; } + + private: + Contents(void* data, size_t byte_length, void* allocation_base, + size_t allocation_length, + Allocator::AllocationMode allocation_mode, DeleterCallback deleter, + void* deleter_data); + + void* data_; + size_t byte_length_; + void* allocation_base_; + size_t allocation_length_; + Allocator::AllocationMode allocation_mode_; + DeleterCallback deleter_; + void* deleter_data_; + + friend class ArrayBuffer; + }; + + + /** + * Data length in bytes. + */ + size_t ByteLength() const; + + /** + * Create a new ArrayBuffer. Allocate |byte_length| bytes. + * Allocated memory will be owned by a created ArrayBuffer and + * will be deallocated when it is garbage-collected, + * unless the object is externalized. + */ + static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); + + /** + * Create a new ArrayBuffer over an existing memory block. + * The created array buffer is by default immediately in externalized state. + * In externalized state, the memory block will not be reclaimed when a + * created ArrayBuffer is garbage-collected. + * In internalized state, the memory block will be released using + * |Allocator::Free| once all ArrayBuffers referencing it are collected by + * the garbage collector. + */ + static Local<ArrayBuffer> New( + Isolate* isolate, void* data, size_t byte_length, + ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); + + /** + * Returns true if ArrayBuffer is externalized, that is, does not + * own its memory block. + */ + bool IsExternal() const; + + /** + * Returns true if this ArrayBuffer may be detached. + */ + bool IsDetachable() const; + + // TODO(913887): fix the use of 'neuter' in the API. + V8_DEPRECATE_SOON("Use IsDetachable() instead.", + inline bool IsNeuterable() const) { + return IsDetachable(); + } + + /** + * Detaches this ArrayBuffer and all its views (typed arrays). + * Detaching sets the byte length of the buffer and all typed arrays to zero, + * preventing JavaScript from ever accessing underlying backing store. + * ArrayBuffer should have been externalized and must be detachable. + */ + void Detach(); + + // TODO(913887): fix the use of 'neuter' in the API. + V8_DEPRECATE_SOON("Use Detach() instead.", inline void Neuter()) { Detach(); } + + /** + * Make this ArrayBuffer external. The pointer to underlying memory block + * and byte length are returned as |Contents| structure. After ArrayBuffer + * had been externalized, it does no longer own the memory block. The caller + * should take steps to free memory when it is no longer needed. + * + * The Data pointer of ArrayBuffer::Contents must be freed using the provided + * deleter, which will call ArrayBuffer::Allocator::Free if the buffer + * was allocated with ArraryBuffer::Allocator::Allocate. + */ + Contents Externalize(); + + /** + * Get a pointer to the ArrayBuffer's underlying memory block without + * externalizing it. If the ArrayBuffer is not externalized, this pointer + * will become invalid as soon as the ArrayBuffer gets garbage collected. + * + * The embedder should make sure to hold a strong reference to the + * ArrayBuffer while accessing this pointer. + */ + Contents GetContents(); + + V8_INLINE static ArrayBuffer* Cast(Value* obj); + + static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; + static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; + + private: + ArrayBuffer(); + static void CheckCast(Value* obj); +}; + + +#ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT +// The number of required internal fields can be defined by embedder. +#define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2 +#endif + + +/** + * A base class for an instance of one of "views" over ArrayBuffer, + * including TypedArrays and DataView (ES6 draft 15.13). + */ +class V8_EXPORT ArrayBufferView : public Object { + public: + /** + * Returns underlying ArrayBuffer. + */ + Local<ArrayBuffer> Buffer(); + /** + * Byte offset in |Buffer|. + */ + size_t ByteOffset(); + /** + * Size of a view in bytes. + */ + size_t ByteLength(); + + /** + * Copy the contents of the ArrayBufferView's buffer to an embedder defined + * memory without additional overhead that calling ArrayBufferView::Buffer + * might incur. + * + * Will write at most min(|byte_length|, ByteLength) bytes starting at + * ByteOffset of the underlying buffer to the memory starting at |dest|. + * Returns the number of bytes actually written. + */ + size_t CopyContents(void* dest, size_t byte_length); + + /** + * Returns true if ArrayBufferView's backing ArrayBuffer has already been + * allocated. + */ + bool HasBuffer() const; + + V8_INLINE static ArrayBufferView* Cast(Value* obj); + + static const int kInternalFieldCount = + V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT; + static const int kEmbedderFieldCount = + V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT; + + private: + ArrayBufferView(); + static void CheckCast(Value* obj); +}; + + +/** + * A base class for an instance of TypedArray series of constructors + * (ES6 draft 15.13.6). + */ +class V8_EXPORT TypedArray : public ArrayBufferView { + public: + /* + * The largest typed array size that can be constructed using New. + */ + static constexpr size_t kMaxLength = internal::kSmiMaxValue; + + /** + * Number of elements in this typed array + * (e.g. for Int16Array, |ByteLength|/2). + */ + size_t Length(); + + V8_INLINE static TypedArray* Cast(Value* obj); + + private: + TypedArray(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of Uint8Array constructor (ES6 draft 15.13.6). + */ +class V8_EXPORT Uint8Array : public TypedArray { + public: + static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static Uint8Array* Cast(Value* obj); + + private: + Uint8Array(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6). + */ +class V8_EXPORT Uint8ClampedArray : public TypedArray { + public: + static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Uint8ClampedArray> New( + Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset, + size_t length); + V8_INLINE static Uint8ClampedArray* Cast(Value* obj); + + private: + Uint8ClampedArray(); + static void CheckCast(Value* obj); +}; + +/** + * An instance of Int8Array constructor (ES6 draft 15.13.6). + */ +class V8_EXPORT Int8Array : public TypedArray { + public: + static Local<Int8Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static Int8Array* Cast(Value* obj); + + private: + Int8Array(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of Uint16Array constructor (ES6 draft 15.13.6). + */ +class V8_EXPORT Uint16Array : public TypedArray { + public: + static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static Uint16Array* Cast(Value* obj); + + private: + Uint16Array(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of Int16Array constructor (ES6 draft 15.13.6). + */ +class V8_EXPORT Int16Array : public TypedArray { + public: + static Local<Int16Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static Int16Array* Cast(Value* obj); + + private: + Int16Array(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of Uint32Array constructor (ES6 draft 15.13.6). + */ +class V8_EXPORT Uint32Array : public TypedArray { + public: + static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static Uint32Array* Cast(Value* obj); + + private: + Uint32Array(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of Int32Array constructor (ES6 draft 15.13.6). + */ +class V8_EXPORT Int32Array : public TypedArray { + public: + static Local<Int32Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static Int32Array* Cast(Value* obj); + + private: + Int32Array(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of Float32Array constructor (ES6 draft 15.13.6). + */ +class V8_EXPORT Float32Array : public TypedArray { + public: + static Local<Float32Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static Float32Array* Cast(Value* obj); + + private: + Float32Array(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of Float64Array constructor (ES6 draft 15.13.6). + */ +class V8_EXPORT Float64Array : public TypedArray { + public: + static Local<Float64Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static Float64Array* Cast(Value* obj); + + private: + Float64Array(); + static void CheckCast(Value* obj); +}; + +/** + * An instance of BigInt64Array constructor. + */ +class V8_EXPORT BigInt64Array : public TypedArray { + public: + static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static BigInt64Array* Cast(Value* obj); + + private: + BigInt64Array(); + static void CheckCast(Value* obj); +}; + +/** + * An instance of BigUint64Array constructor. + */ +class V8_EXPORT BigUint64Array : public TypedArray { + public: + static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static BigUint64Array* Cast(Value* obj); + + private: + BigUint64Array(); + static void CheckCast(Value* obj); +}; + +/** + * An instance of DataView constructor (ES6 draft 15.13.7). + */ +class V8_EXPORT DataView : public ArrayBufferView { + public: + static Local<DataView> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); + V8_INLINE static DataView* Cast(Value* obj); + + private: + DataView(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of the built-in SharedArrayBuffer constructor. + * This API is experimental and may change significantly. + */ +class V8_EXPORT SharedArrayBuffer : public Object { + public: + /** + * The contents of an |SharedArrayBuffer|. Externalization of + * |SharedArrayBuffer| returns an instance of this class, populated, with a + * pointer to data and byte length. + * + * The Data pointer of ArrayBuffer::Contents must be freed using the provided + * deleter, which will call ArrayBuffer::Allocator::Free if the buffer + * was allocated with ArraryBuffer::Allocator::Allocate. + * + * This API is experimental and may change significantly. + */ + class V8_EXPORT Contents { // NOLINT + public: + using Allocator = v8::ArrayBuffer::Allocator; + using DeleterCallback = void (*)(void* buffer, size_t length, void* info); + + Contents() + : data_(nullptr), + byte_length_(0), + allocation_base_(nullptr), + allocation_length_(0), + allocation_mode_(Allocator::AllocationMode::kNormal), + deleter_(nullptr), + deleter_data_(nullptr) {} + + void* AllocationBase() const { return allocation_base_; } + size_t AllocationLength() const { return allocation_length_; } + Allocator::AllocationMode AllocationMode() const { + return allocation_mode_; + } + + void* Data() const { return data_; } + size_t ByteLength() const { return byte_length_; } + DeleterCallback Deleter() const { return deleter_; } + void* DeleterData() const { return deleter_data_; } + + private: + Contents(void* data, size_t byte_length, void* allocation_base, + size_t allocation_length, + Allocator::AllocationMode allocation_mode, DeleterCallback deleter, + void* deleter_data); + + void* data_; + size_t byte_length_; + void* allocation_base_; + size_t allocation_length_; + Allocator::AllocationMode allocation_mode_; + DeleterCallback deleter_; + void* deleter_data_; + + friend class SharedArrayBuffer; + }; + + /** + * Data length in bytes. + */ + size_t ByteLength() const; + + /** + * Create a new SharedArrayBuffer. Allocate |byte_length| bytes. + * Allocated memory will be owned by a created SharedArrayBuffer and + * will be deallocated when it is garbage-collected, + * unless the object is externalized. + */ + static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length); + + /** + * Create a new SharedArrayBuffer over an existing memory block. The created + * array buffer is immediately in externalized state unless otherwise + * specified. The memory block will not be reclaimed when a created + * SharedArrayBuffer is garbage-collected. + */ + static Local<SharedArrayBuffer> New( + Isolate* isolate, void* data, size_t byte_length, + ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); + + /** + * Create a new SharedArrayBuffer over an existing memory block. Propagate + * flags to indicate whether the underlying buffer can be grown. + */ + V8_DEPRECATED("Use New method with data, and byte_length instead.", + static Local<SharedArrayBuffer> New( + Isolate* isolate, const SharedArrayBuffer::Contents&, + ArrayBufferCreationMode mode = + ArrayBufferCreationMode::kExternalized)); + + /** + * Returns true if SharedArrayBuffer is externalized, that is, does not + * own its memory block. + */ + bool IsExternal() const; + + /** + * Make this SharedArrayBuffer external. The pointer to underlying memory + * block and byte length are returned as |Contents| structure. After + * SharedArrayBuffer had been externalized, it does no longer own the memory + * block. The caller should take steps to free memory when it is no longer + * needed. + * + * The memory block is guaranteed to be allocated with |Allocator::Allocate| + * by the allocator specified in + * v8::Isolate::CreateParams::array_buffer_allocator. + * + */ + Contents Externalize(); + + /** + * Get a pointer to the ArrayBuffer's underlying memory block without + * externalizing it. If the ArrayBuffer is not externalized, this pointer + * will become invalid as soon as the ArrayBuffer became garbage collected. + * + * The embedder should make sure to hold a strong reference to the + * ArrayBuffer while accessing this pointer. + * + * The memory block is guaranteed to be allocated with |Allocator::Allocate| + * by the allocator specified in + * v8::Isolate::CreateParams::array_buffer_allocator. + */ + Contents GetContents(); + + V8_INLINE static SharedArrayBuffer* Cast(Value* obj); + + static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; + + private: + SharedArrayBuffer(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of the built-in Date constructor (ECMA-262, 15.9). + */ +class V8_EXPORT Date : public Object { + public: + static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context, + double time); + + /** + * A specialization of Value::NumberValue that is more efficient + * because we know the structure of this object. + */ + double ValueOf() const; + + V8_INLINE static Date* Cast(Value* obj); + + /** + * Time zone redetection indicator for + * DateTimeConfigurationChangeNotification. + * + * kSkip indicates V8 that the notification should not trigger redetecting + * host time zone. kRedetect indicates V8 that host time zone should be + * redetected, and used to set the default time zone. + * + * The host time zone detection may require file system access or similar + * operations unlikely to be available inside a sandbox. If v8 is run inside a + * sandbox, the host time zone has to be detected outside the sandbox before + * calling DateTimeConfigurationChangeNotification function. + */ + enum class TimeZoneDetection { kSkip, kRedetect }; + + /** + * Notification that the embedder has changed the time zone, + * daylight savings time, or other date / time configuration + * parameters. V8 keeps a cache of various values used for + * date / time computation. This notification will reset + * those cached values for the current context so that date / + * time configuration changes would be reflected in the Date + * object. + * + * This API should not be called more than needed as it will + * negatively impact the performance of date operations. + */ + V8_DEPRECATED("Use Isolate::DateTimeConfigurationChangeNotification", + static void DateTimeConfigurationChangeNotification( + Isolate* isolate, TimeZoneDetection time_zone_detection = + TimeZoneDetection::kSkip)); + + private: + static void CheckCast(Value* obj); +}; + + +/** + * A Number object (ECMA-262, 4.3.21). + */ +class V8_EXPORT NumberObject : public Object { + public: + static Local<Value> New(Isolate* isolate, double value); + + double ValueOf() const; + + V8_INLINE static NumberObject* Cast(Value* obj); + + private: + static void CheckCast(Value* obj); +}; + +/** + * A BigInt object (https://tc39.github.io/proposal-bigint) + */ +class V8_EXPORT BigIntObject : public Object { + public: + static Local<Value> New(Isolate* isolate, int64_t value); + + Local<BigInt> ValueOf() const; + + V8_INLINE static BigIntObject* Cast(Value* obj); + + private: + static void CheckCast(Value* obj); +}; + +/** + * A Boolean object (ECMA-262, 4.3.15). + */ +class V8_EXPORT BooleanObject : public Object { + public: + static Local<Value> New(Isolate* isolate, bool value); + + bool ValueOf() const; + + V8_INLINE static BooleanObject* Cast(Value* obj); + + private: + static void CheckCast(Value* obj); +}; + + +/** + * A String object (ECMA-262, 4.3.18). + */ +class V8_EXPORT StringObject : public Object { + public: + static Local<Value> New(Isolate* isolate, Local<String> value); + + Local<String> ValueOf() const; + + V8_INLINE static StringObject* Cast(Value* obj); + + private: + static void CheckCast(Value* obj); +}; + + +/** + * A Symbol object (ECMA-262 edition 6). + */ +class V8_EXPORT SymbolObject : public Object { + public: + static Local<Value> New(Isolate* isolate, Local<Symbol> value); + + Local<Symbol> ValueOf() const; + + V8_INLINE static SymbolObject* Cast(Value* obj); + + private: + static void CheckCast(Value* obj); +}; + + +/** + * An instance of the built-in RegExp constructor (ECMA-262, 15.10). + */ +class V8_EXPORT RegExp : public Object { + public: + /** + * Regular expression flag bits. They can be or'ed to enable a set + * of flags. + */ + enum Flags { + kNone = 0, + kGlobal = 1 << 0, + kIgnoreCase = 1 << 1, + kMultiline = 1 << 2, + kSticky = 1 << 3, + kUnicode = 1 << 4, + kDotAll = 1 << 5, + }; + + /** + * Creates a regular expression from the given pattern string and + * the flags bit field. May throw a JavaScript exception as + * described in ECMA-262, 15.10.4.1. + * + * For example, + * RegExp::New(v8::String::New("foo"), + * static_cast<RegExp::Flags>(kGlobal | kMultiline)) + * is equivalent to evaluating "/foo/gm". + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context, + Local<String> pattern, + Flags flags); + + /** + * Returns the value of the source property: a string representing + * the regular expression. + */ + Local<String> GetSource() const; + + /** + * Returns the flags bit field. + */ + Flags GetFlags() const; + + V8_INLINE static RegExp* Cast(Value* obj); + + private: + static void CheckCast(Value* obj); +}; + + +/** + * A JavaScript value that wraps a C++ void*. This type of value is mainly used + * to associate C++ data structures with JavaScript objects. + */ +class V8_EXPORT External : public Value { + public: + static Local<External> New(Isolate* isolate, void* value); + V8_INLINE static External* Cast(Value* obj); + void* Value() const; + private: + static void CheckCast(v8::Value* obj); +}; + +#define V8_INTRINSICS_LIST(F) \ + F(ArrayProto_entries, array_entries_iterator) \ + F(ArrayProto_forEach, array_for_each_iterator) \ + F(ArrayProto_keys, array_keys_iterator) \ + F(ArrayProto_values, array_values_iterator) \ + F(ErrorPrototype, initial_error_prototype) \ + F(IteratorPrototype, initial_iterator_prototype) + +enum Intrinsic { +#define V8_DECL_INTRINSIC(name, iname) k##name, + V8_INTRINSICS_LIST(V8_DECL_INTRINSIC) +#undef V8_DECL_INTRINSIC +}; + + +// --- Templates --- + + +/** + * The superclass of object and function templates. + */ +class V8_EXPORT Template : public Data { + public: + /** + * Adds a property to each instance created by this template. + * + * The property must be defined either as a primitive value, or a template. + */ + void Set(Local<Name> name, Local<Data> value, + PropertyAttribute attributes = None); + void SetPrivate(Local<Private> name, Local<Data> value, + PropertyAttribute attributes = None); + V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value); + + void SetAccessorProperty( + Local<Name> name, + Local<FunctionTemplate> getter = Local<FunctionTemplate>(), + Local<FunctionTemplate> setter = Local<FunctionTemplate>(), + PropertyAttribute attribute = None, + AccessControl settings = DEFAULT); + + /** + * Whenever the property with the given name is accessed on objects + * created from this Template the getter and setter callbacks + * are called instead of getting and setting the property directly + * on the JavaScript object. + * + * \param name The name of the property for which an accessor is added. + * \param getter The callback to invoke when getting the property. + * \param setter The callback to invoke when setting the property. + * \param data A piece of data that will be passed to the getter and setter + * callbacks whenever they are invoked. + * \param settings Access control settings for the accessor. This is a bit + * field consisting of one of more of + * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. + * The default is to not allow cross-context access. + * ALL_CAN_READ means that all cross-context reads are allowed. + * ALL_CAN_WRITE means that all cross-context writes are allowed. + * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all + * cross-context access. + * \param attribute The attributes of the property for which an accessor + * is added. + * \param signature The signature describes valid receivers for the accessor + * and is used to perform implicit instance checks against them. If the + * receiver is incompatible (i.e. is not an instance of the constructor as + * defined by FunctionTemplate::HasInstance()), an implicit TypeError is + * thrown and no callback is invoked. + */ + void SetNativeDataProperty( + Local<String> name, AccessorGetterCallback getter, + AccessorSetterCallback setter = nullptr, + // TODO(dcarney): gcc can't handle Local below + Local<Value> data = Local<Value>(), PropertyAttribute attribute = None, + Local<AccessorSignature> signature = Local<AccessorSignature>(), + AccessControl settings = DEFAULT, + SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, + SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); + void SetNativeDataProperty( + Local<Name> name, AccessorNameGetterCallback getter, + AccessorNameSetterCallback setter = nullptr, + // TODO(dcarney): gcc can't handle Local below + Local<Value> data = Local<Value>(), PropertyAttribute attribute = None, + Local<AccessorSignature> signature = Local<AccessorSignature>(), + AccessControl settings = DEFAULT, + SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, + SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); + + /** + * Like SetNativeDataProperty, but V8 will replace the native data property + * with a real data property on first access. + */ + void SetLazyDataProperty( + Local<Name> name, AccessorNameGetterCallback getter, + Local<Value> data = Local<Value>(), PropertyAttribute attribute = None, + SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, + SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); + + /** + * During template instantiation, sets the value with the intrinsic property + * from the correct context. + */ + void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic, + PropertyAttribute attribute = None); + + private: + Template(); + + friend class ObjectTemplate; + friend class FunctionTemplate; +}; + +// TODO(dcarney): Replace GenericNamedPropertyFooCallback with just +// NamedPropertyFooCallback. + +/** + * Interceptor for get requests on an object. + * + * Use `info.GetReturnValue().Set()` to set the return value of the + * intercepted get request. + * + * \param property The name of the property for which the request was + * intercepted. + * \param info Information about the intercepted request, such as + * isolate, receiver, return value, or whether running in `'use strict`' mode. + * See `PropertyCallbackInfo`. + * + * \code + * void GetterCallback( + * Local<Name> name, + * const v8::PropertyCallbackInfo<v8::Value>& info) { + * info.GetReturnValue().Set(v8_num(42)); + * } + * + * v8::Local<v8::FunctionTemplate> templ = + * v8::FunctionTemplate::New(isolate); + * templ->InstanceTemplate()->SetHandler( + * v8::NamedPropertyHandlerConfiguration(GetterCallback)); + * LocalContext env; + * env->Global() + * ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) + * .ToLocalChecked() + * ->NewInstance(env.local()) + * .ToLocalChecked()) + * .FromJust(); + * v8::Local<v8::Value> result = CompileRun("obj.a = 17; obj.a"); + * CHECK(v8_num(42)->Equals(env.local(), result).FromJust()); + * \endcode + * + * See also `ObjectTemplate::SetHandler`. + */ +typedef void (*GenericNamedPropertyGetterCallback)( + Local<Name> property, const PropertyCallbackInfo<Value>& info); + +/** + * Interceptor for set requests on an object. + * + * Use `info.GetReturnValue()` to indicate whether the request was intercepted + * or not. If the setter successfully intercepts the request, i.e., if the + * request should not be further executed, call + * `info.GetReturnValue().Set(value)`. If the setter + * did not intercept the request, i.e., if the request should be handled as + * if no interceptor is present, do not not call `Set()`. + * + * \param property The name of the property for which the request was + * intercepted. + * \param value The value which the property will have if the request + * is not intercepted. + * \param info Information about the intercepted request, such as + * isolate, receiver, return value, or whether running in `'use strict'` mode. + * See `PropertyCallbackInfo`. + * + * See also + * `ObjectTemplate::SetHandler.` + */ +typedef void (*GenericNamedPropertySetterCallback)( + Local<Name> property, Local<Value> value, + const PropertyCallbackInfo<Value>& info); + +/** + * Intercepts all requests that query the attributes of the + * property, e.g., getOwnPropertyDescriptor(), propertyIsEnumerable(), and + * defineProperty(). + * + * Use `info.GetReturnValue().Set(value)` to set the property attributes. The + * value is an integer encoding a `v8::PropertyAttribute`. + * + * \param property The name of the property for which the request was + * intercepted. + * \param info Information about the intercepted request, such as + * isolate, receiver, return value, or whether running in `'use strict'` mode. + * See `PropertyCallbackInfo`. + * + * \note Some functions query the property attributes internally, even though + * they do not return the attributes. For example, `hasOwnProperty()` can + * trigger this interceptor depending on the state of the object. + * + * See also + * `ObjectTemplate::SetHandler.` + */ +typedef void (*GenericNamedPropertyQueryCallback)( + Local<Name> property, const PropertyCallbackInfo<Integer>& info); + +/** + * Interceptor for delete requests on an object. + * + * Use `info.GetReturnValue()` to indicate whether the request was intercepted + * or not. If the deleter successfully intercepts the request, i.e., if the + * request should not be further executed, call + * `info.GetReturnValue().Set(value)` with a boolean `value`. The `value` is + * used as the return value of `delete`. + * + * \param property The name of the property for which the request was + * intercepted. + * \param info Information about the intercepted request, such as + * isolate, receiver, return value, or whether running in `'use strict'` mode. + * See `PropertyCallbackInfo`. + * + * \note If you need to mimic the behavior of `delete`, i.e., throw in strict + * mode instead of returning false, use `info.ShouldThrowOnError()` to determine + * if you are in strict mode. + * + * See also `ObjectTemplate::SetHandler.` + */ +typedef void (*GenericNamedPropertyDeleterCallback)( + Local<Name> property, const PropertyCallbackInfo<Boolean>& info); + +/** + * Returns an array containing the names of the properties the named + * property getter intercepts. + * + * Note: The values in the array must be of type v8::Name. + */ +typedef void (*GenericNamedPropertyEnumeratorCallback)( + const PropertyCallbackInfo<Array>& info); + +/** + * Interceptor for defineProperty requests on an object. + * + * Use `info.GetReturnValue()` to indicate whether the request was intercepted + * or not. If the definer successfully intercepts the request, i.e., if the + * request should not be further executed, call + * `info.GetReturnValue().Set(value)`. If the definer + * did not intercept the request, i.e., if the request should be handled as + * if no interceptor is present, do not not call `Set()`. + * + * \param property The name of the property for which the request was + * intercepted. + * \param desc The property descriptor which is used to define the + * property if the request is not intercepted. + * \param info Information about the intercepted request, such as + * isolate, receiver, return value, or whether running in `'use strict'` mode. + * See `PropertyCallbackInfo`. + * + * See also `ObjectTemplate::SetHandler`. + */ +typedef void (*GenericNamedPropertyDefinerCallback)( + Local<Name> property, const PropertyDescriptor& desc, + const PropertyCallbackInfo<Value>& info); + +/** + * Interceptor for getOwnPropertyDescriptor requests on an object. + * + * Use `info.GetReturnValue().Set()` to set the return value of the + * intercepted request. The return value must be an object that + * can be converted to a PropertyDescriptor, e.g., a `v8::value` returned from + * `v8::Object::getOwnPropertyDescriptor`. + * + * \param property The name of the property for which the request was + * intercepted. + * \info Information about the intercepted request, such as + * isolate, receiver, return value, or whether running in `'use strict'` mode. + * See `PropertyCallbackInfo`. + * + * \note If GetOwnPropertyDescriptor is intercepted, it will + * always return true, i.e., indicate that the property was found. + * + * See also `ObjectTemplate::SetHandler`. + */ +typedef void (*GenericNamedPropertyDescriptorCallback)( + Local<Name> property, const PropertyCallbackInfo<Value>& info); + +/** + * See `v8::GenericNamedPropertyGetterCallback`. + */ +typedef void (*IndexedPropertyGetterCallback)( + uint32_t index, + const PropertyCallbackInfo<Value>& info); + +/** + * See `v8::GenericNamedPropertySetterCallback`. + */ +typedef void (*IndexedPropertySetterCallback)( + uint32_t index, + Local<Value> value, + const PropertyCallbackInfo<Value>& info); + +/** + * See `v8::GenericNamedPropertyQueryCallback`. + */ +typedef void (*IndexedPropertyQueryCallback)( + uint32_t index, + const PropertyCallbackInfo<Integer>& info); + +/** + * See `v8::GenericNamedPropertyDeleterCallback`. + */ +typedef void (*IndexedPropertyDeleterCallback)( + uint32_t index, + const PropertyCallbackInfo<Boolean>& info); + +/** + * Returns an array containing the indices of the properties the indexed + * property getter intercepts. + * + * Note: The values in the array must be uint32_t. + */ +typedef void (*IndexedPropertyEnumeratorCallback)( + const PropertyCallbackInfo<Array>& info); + +/** + * See `v8::GenericNamedPropertyDefinerCallback`. + */ +typedef void (*IndexedPropertyDefinerCallback)( + uint32_t index, const PropertyDescriptor& desc, + const PropertyCallbackInfo<Value>& info); + +/** + * See `v8::GenericNamedPropertyDescriptorCallback`. + */ +typedef void (*IndexedPropertyDescriptorCallback)( + uint32_t index, const PropertyCallbackInfo<Value>& info); + +/** + * Access type specification. + */ +enum AccessType { + ACCESS_GET, + ACCESS_SET, + ACCESS_HAS, + ACCESS_DELETE, + ACCESS_KEYS +}; + + +/** + * Returns true if the given context should be allowed to access the given + * object. + */ +typedef bool (*AccessCheckCallback)(Local<Context> accessing_context, + Local<Object> accessed_object, + Local<Value> data); + +/** + * A FunctionTemplate is used to create functions at runtime. There + * can only be one function created from a FunctionTemplate in a + * context. The lifetime of the created function is equal to the + * lifetime of the context. So in case the embedder needs to create + * temporary functions that can be collected using Scripts is + * preferred. + * + * Any modification of a FunctionTemplate after first instantiation will trigger + * a crash. + * + * A FunctionTemplate can have properties, these properties are added to the + * function object when it is created. + * + * A FunctionTemplate has a corresponding instance template which is + * used to create object instances when the function is used as a + * constructor. Properties added to the instance template are added to + * each object instance. + * + * A FunctionTemplate can have a prototype template. The prototype template + * is used to create the prototype object of the function. + * + * The following example shows how to use a FunctionTemplate: + * + * \code + * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); + * t->Set(isolate, "func_property", v8::Number::New(isolate, 1)); + * + * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); + * proto_t->Set(isolate, + * "proto_method", + * v8::FunctionTemplate::New(isolate, InvokeCallback)); + * proto_t->Set(isolate, "proto_const", v8::Number::New(isolate, 2)); + * + * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); + * instance_t->SetAccessor(String::NewFromUtf8(isolate, "instance_accessor"), + * InstanceAccessorCallback); + * instance_t->SetHandler( + * NamedPropertyHandlerConfiguration(PropertyHandlerCallback)); + * instance_t->Set(String::NewFromUtf8(isolate, "instance_property"), + * Number::New(isolate, 3)); + * + * v8::Local<v8::Function> function = t->GetFunction(); + * v8::Local<v8::Object> instance = function->NewInstance(); + * \endcode + * + * Let's use "function" as the JS variable name of the function object + * and "instance" for the instance object created above. The function + * and the instance will have the following properties: + * + * \code + * func_property in function == true; + * function.func_property == 1; + * + * function.prototype.proto_method() invokes 'InvokeCallback' + * function.prototype.proto_const == 2; + * + * instance instanceof function == true; + * instance.instance_accessor calls 'InstanceAccessorCallback' + * instance.instance_property == 3; + * \endcode + * + * A FunctionTemplate can inherit from another one by calling the + * FunctionTemplate::Inherit method. The following graph illustrates + * the semantics of inheritance: + * + * \code + * FunctionTemplate Parent -> Parent() . prototype -> { } + * ^ ^ + * | Inherit(Parent) | .__proto__ + * | | + * FunctionTemplate Child -> Child() . prototype -> { } + * \endcode + * + * A FunctionTemplate 'Child' inherits from 'Parent', the prototype + * object of the Child() function has __proto__ pointing to the + * Parent() function's prototype object. An instance of the Child + * function has all properties on Parent's instance templates. + * + * Let Parent be the FunctionTemplate initialized in the previous + * section and create a Child FunctionTemplate by: + * + * \code + * Local<FunctionTemplate> parent = t; + * Local<FunctionTemplate> child = FunctionTemplate::New(); + * child->Inherit(parent); + * + * Local<Function> child_function = child->GetFunction(); + * Local<Object> child_instance = child_function->NewInstance(); + * \endcode + * + * The Child function and Child instance will have the following + * properties: + * + * \code + * child_func.prototype.__proto__ == function.prototype; + * child_instance.instance_accessor calls 'InstanceAccessorCallback' + * child_instance.instance_property == 3; + * \endcode + */ +class V8_EXPORT FunctionTemplate : public Template { + public: + /** Creates a function template.*/ + static Local<FunctionTemplate> New( + Isolate* isolate, FunctionCallback callback = nullptr, + Local<Value> data = Local<Value>(), + Local<Signature> signature = Local<Signature>(), int length = 0, + ConstructorBehavior behavior = ConstructorBehavior::kAllow, + SideEffectType side_effect_type = SideEffectType::kHasSideEffect); + + /** Get a template included in the snapshot by index. */ + static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate, + size_t index); + + /** + * Creates a function template backed/cached by a private property. + */ + static Local<FunctionTemplate> NewWithCache( + Isolate* isolate, FunctionCallback callback, + Local<Private> cache_property, Local<Value> data = Local<Value>(), + Local<Signature> signature = Local<Signature>(), int length = 0, + SideEffectType side_effect_type = SideEffectType::kHasSideEffect); + + /** Returns the unique function instance in the current execution context.*/ + V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction( + Local<Context> context); + + /** + * Similar to Context::NewRemoteContext, this creates an instance that + * isn't backed by an actual object. + * + * The InstanceTemplate of this FunctionTemplate must have access checks with + * handlers installed. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance(); + + /** + * Set the call-handler callback for a FunctionTemplate. This + * callback is called whenever the function created from this + * FunctionTemplate is called. + */ + void SetCallHandler( + FunctionCallback callback, Local<Value> data = Local<Value>(), + SideEffectType side_effect_type = SideEffectType::kHasSideEffect); + + /** Set the predefined length property for the FunctionTemplate. */ + void SetLength(int length); + + /** Get the InstanceTemplate. */ + Local<ObjectTemplate> InstanceTemplate(); + + /** + * Causes the function template to inherit from a parent function template. + * This means the function's prototype.__proto__ is set to the parent + * function's prototype. + **/ + void Inherit(Local<FunctionTemplate> parent); + + /** + * A PrototypeTemplate is the template used to create the prototype object + * of the function created by this template. + */ + Local<ObjectTemplate> PrototypeTemplate(); + + /** + * A PrototypeProviderTemplate is another function template whose prototype + * property is used for this template. This is mutually exclusive with setting + * a prototype template indirectly by calling PrototypeTemplate() or using + * Inherit(). + **/ + void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider); + + /** + * Set the class name of the FunctionTemplate. This is used for + * printing objects created with the function created from the + * FunctionTemplate as its constructor. + */ + void SetClassName(Local<String> name); + + + /** + * When set to true, no access check will be performed on the receiver of a + * function call. Currently defaults to true, but this is subject to change. + */ + void SetAcceptAnyReceiver(bool value); + + /** + * Determines whether the __proto__ accessor ignores instances of + * the function template. If instances of the function template are + * ignored, __proto__ skips all instances and instead returns the + * next object in the prototype chain. + * + * Call with a value of true to make the __proto__ accessor ignore + * instances of the function template. Call with a value of false + * to make the __proto__ accessor not ignore instances of the + * function template. By default, instances of a function template + * are not ignored. + */ + V8_DEPRECATED("This feature is incompatible with ES6+.", + void SetHiddenPrototype(bool value)); + + /** + * Sets the ReadOnly flag in the attributes of the 'prototype' property + * of functions created from this FunctionTemplate to true. + */ + void ReadOnlyPrototype(); + + /** + * Removes the prototype property from functions created from this + * FunctionTemplate. + */ + void RemovePrototype(); + + /** + * Returns true if the given object is an instance of this function + * template. + */ + bool HasInstance(Local<Value> object); + + V8_INLINE static FunctionTemplate* Cast(Data* data); + + private: + FunctionTemplate(); + + static void CheckCast(Data* that); + friend class Context; + friend class ObjectTemplate; +}; + +/** + * Configuration flags for v8::NamedPropertyHandlerConfiguration or + * v8::IndexedPropertyHandlerConfiguration. + */ +enum class PropertyHandlerFlags { + /** + * None. + */ + kNone = 0, + + /** + * See ALL_CAN_READ above. + */ + kAllCanRead = 1, + + /** Will not call into interceptor for properties on the receiver or prototype + * chain, i.e., only call into interceptor for properties that do not exist. + * Currently only valid for named interceptors. + */ + kNonMasking = 1 << 1, + + /** + * Will not call into interceptor for symbol lookup. Only meaningful for + * named interceptors. + */ + kOnlyInterceptStrings = 1 << 2, + + /** + * The getter, query, enumerator callbacks do not produce side effects. + */ + kHasNoSideEffect = 1 << 3, +}; + +struct NamedPropertyHandlerConfiguration { + NamedPropertyHandlerConfiguration( + GenericNamedPropertyGetterCallback getter, + GenericNamedPropertySetterCallback setter, + GenericNamedPropertyQueryCallback query, + GenericNamedPropertyDeleterCallback deleter, + GenericNamedPropertyEnumeratorCallback enumerator, + GenericNamedPropertyDefinerCallback definer, + GenericNamedPropertyDescriptorCallback descriptor, + Local<Value> data = Local<Value>(), + PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) + : getter(getter), + setter(setter), + query(query), + deleter(deleter), + enumerator(enumerator), + definer(definer), + descriptor(descriptor), + data(data), + flags(flags) {} + + NamedPropertyHandlerConfiguration( + /** Note: getter is required */ + GenericNamedPropertyGetterCallback getter = nullptr, + GenericNamedPropertySetterCallback setter = nullptr, + GenericNamedPropertyQueryCallback query = nullptr, + GenericNamedPropertyDeleterCallback deleter = nullptr, + GenericNamedPropertyEnumeratorCallback enumerator = nullptr, + Local<Value> data = Local<Value>(), + PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) + : getter(getter), + setter(setter), + query(query), + deleter(deleter), + enumerator(enumerator), + definer(nullptr), + descriptor(nullptr), + data(data), + flags(flags) {} + + NamedPropertyHandlerConfiguration( + GenericNamedPropertyGetterCallback getter, + GenericNamedPropertySetterCallback setter, + GenericNamedPropertyDescriptorCallback descriptor, + GenericNamedPropertyDeleterCallback deleter, + GenericNamedPropertyEnumeratorCallback enumerator, + GenericNamedPropertyDefinerCallback definer, + Local<Value> data = Local<Value>(), + PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) + : getter(getter), + setter(setter), + query(nullptr), + deleter(deleter), + enumerator(enumerator), + definer(definer), + descriptor(descriptor), + data(data), + flags(flags) {} + + GenericNamedPropertyGetterCallback getter; + GenericNamedPropertySetterCallback setter; + GenericNamedPropertyQueryCallback query; + GenericNamedPropertyDeleterCallback deleter; + GenericNamedPropertyEnumeratorCallback enumerator; + GenericNamedPropertyDefinerCallback definer; + GenericNamedPropertyDescriptorCallback descriptor; + Local<Value> data; + PropertyHandlerFlags flags; +}; + + +struct IndexedPropertyHandlerConfiguration { + IndexedPropertyHandlerConfiguration( + IndexedPropertyGetterCallback getter, + IndexedPropertySetterCallback setter, IndexedPropertyQueryCallback query, + IndexedPropertyDeleterCallback deleter, + IndexedPropertyEnumeratorCallback enumerator, + IndexedPropertyDefinerCallback definer, + IndexedPropertyDescriptorCallback descriptor, + Local<Value> data = Local<Value>(), + PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) + : getter(getter), + setter(setter), + query(query), + deleter(deleter), + enumerator(enumerator), + definer(definer), + descriptor(descriptor), + data(data), + flags(flags) {} + + IndexedPropertyHandlerConfiguration( + /** Note: getter is required */ + IndexedPropertyGetterCallback getter = nullptr, + IndexedPropertySetterCallback setter = nullptr, + IndexedPropertyQueryCallback query = nullptr, + IndexedPropertyDeleterCallback deleter = nullptr, + IndexedPropertyEnumeratorCallback enumerator = nullptr, + Local<Value> data = Local<Value>(), + PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) + : getter(getter), + setter(setter), + query(query), + deleter(deleter), + enumerator(enumerator), + definer(nullptr), + descriptor(nullptr), + data(data), + flags(flags) {} + + IndexedPropertyHandlerConfiguration( + IndexedPropertyGetterCallback getter, + IndexedPropertySetterCallback setter, + IndexedPropertyDescriptorCallback descriptor, + IndexedPropertyDeleterCallback deleter, + IndexedPropertyEnumeratorCallback enumerator, + IndexedPropertyDefinerCallback definer, + Local<Value> data = Local<Value>(), + PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) + : getter(getter), + setter(setter), + query(nullptr), + deleter(deleter), + enumerator(enumerator), + definer(definer), + descriptor(descriptor), + data(data), + flags(flags) {} + + IndexedPropertyGetterCallback getter; + IndexedPropertySetterCallback setter; + IndexedPropertyQueryCallback query; + IndexedPropertyDeleterCallback deleter; + IndexedPropertyEnumeratorCallback enumerator; + IndexedPropertyDefinerCallback definer; + IndexedPropertyDescriptorCallback descriptor; + Local<Value> data; + PropertyHandlerFlags flags; +}; + + +/** + * An ObjectTemplate is used to create objects at runtime. + * + * Properties added to an ObjectTemplate are added to each object + * created from the ObjectTemplate. + */ +class V8_EXPORT ObjectTemplate : public Template { + public: + /** Creates an ObjectTemplate. */ + static Local<ObjectTemplate> New( + Isolate* isolate, + Local<FunctionTemplate> constructor = Local<FunctionTemplate>()); + + /** Get a template included in the snapshot by index. */ + static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate, + size_t index); + + /** Creates a new instance of this template.*/ + V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context); + + /** + * Sets an accessor on the object template. + * + * Whenever the property with the given name is accessed on objects + * created from this ObjectTemplate the getter and setter callbacks + * are called instead of getting and setting the property directly + * on the JavaScript object. + * + * \param name The name of the property for which an accessor is added. + * \param getter The callback to invoke when getting the property. + * \param setter The callback to invoke when setting the property. + * \param data A piece of data that will be passed to the getter and setter + * callbacks whenever they are invoked. + * \param settings Access control settings for the accessor. This is a bit + * field consisting of one of more of + * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. + * The default is to not allow cross-context access. + * ALL_CAN_READ means that all cross-context reads are allowed. + * ALL_CAN_WRITE means that all cross-context writes are allowed. + * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all + * cross-context access. + * \param attribute The attributes of the property for which an accessor + * is added. + * \param signature The signature describes valid receivers for the accessor + * and is used to perform implicit instance checks against them. If the + * receiver is incompatible (i.e. is not an instance of the constructor as + * defined by FunctionTemplate::HasInstance()), an implicit TypeError is + * thrown and no callback is invoked. + */ + void SetAccessor( + Local<String> name, AccessorGetterCallback getter, + AccessorSetterCallback setter = nullptr, + Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT, + PropertyAttribute attribute = None, + Local<AccessorSignature> signature = Local<AccessorSignature>(), + SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, + SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); + void SetAccessor( + Local<Name> name, AccessorNameGetterCallback getter, + AccessorNameSetterCallback setter = nullptr, + Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT, + PropertyAttribute attribute = None, + Local<AccessorSignature> signature = Local<AccessorSignature>(), + SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, + SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); + + /** + * Sets a named property handler on the object template. + * + * Whenever a property whose name is a string or a symbol is accessed on + * objects created from this object template, the provided callback is + * invoked instead of accessing the property directly on the JavaScript + * object. + * + * @param configuration The NamedPropertyHandlerConfiguration that defines the + * callbacks to invoke when accessing a property. + */ + void SetHandler(const NamedPropertyHandlerConfiguration& configuration); + + /** + * Sets an indexed property handler on the object template. + * + * Whenever an indexed property is accessed on objects created from + * this object template, the provided callback is invoked instead of + * accessing the property directly on the JavaScript object. + * + * \param getter The callback to invoke when getting a property. + * \param setter The callback to invoke when setting a property. + * \param query The callback to invoke to check if an object has a property. + * \param deleter The callback to invoke when deleting a property. + * \param enumerator The callback to invoke to enumerate all the indexed + * properties of an object. + * \param data A piece of data that will be passed to the callbacks + * whenever they are invoked. + */ + // TODO(dcarney): deprecate + void SetIndexedPropertyHandler( + IndexedPropertyGetterCallback getter, + IndexedPropertySetterCallback setter = nullptr, + IndexedPropertyQueryCallback query = nullptr, + IndexedPropertyDeleterCallback deleter = nullptr, + IndexedPropertyEnumeratorCallback enumerator = nullptr, + Local<Value> data = Local<Value>()) { + SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query, + deleter, enumerator, data)); + } + + /** + * Sets an indexed property handler on the object template. + * + * Whenever an indexed property is accessed on objects created from + * this object template, the provided callback is invoked instead of + * accessing the property directly on the JavaScript object. + * + * @param configuration The IndexedPropertyHandlerConfiguration that defines + * the callbacks to invoke when accessing a property. + */ + void SetHandler(const IndexedPropertyHandlerConfiguration& configuration); + + /** + * Sets the callback to be used when calling instances created from + * this template as a function. If no callback is set, instances + * behave like normal JavaScript objects that cannot be called as a + * function. + */ + void SetCallAsFunctionHandler(FunctionCallback callback, + Local<Value> data = Local<Value>()); + + /** + * Mark object instances of the template as undetectable. + * + * In many ways, undetectable objects behave as though they are not + * there. They behave like 'undefined' in conditionals and when + * printed. However, properties can be accessed and called as on + * normal objects. + */ + void MarkAsUndetectable(); + + /** + * Sets access check callback on the object template and enables access + * checks. + * + * When accessing properties on instances of this object template, + * the access check callback will be called to determine whether or + * not to allow cross-context access to the properties. + */ + void SetAccessCheckCallback(AccessCheckCallback callback, + Local<Value> data = Local<Value>()); + + /** + * Like SetAccessCheckCallback but invokes an interceptor on failed access + * checks instead of looking up all-can-read properties. You can only use + * either this method or SetAccessCheckCallback, but not both at the same + * time. + */ + void SetAccessCheckCallbackAndHandler( + AccessCheckCallback callback, + const NamedPropertyHandlerConfiguration& named_handler, + const IndexedPropertyHandlerConfiguration& indexed_handler, + Local<Value> data = Local<Value>()); + + /** + * Gets the number of internal fields for objects generated from + * this template. + */ + int InternalFieldCount(); + + /** + * Sets the number of internal fields for objects generated from + * this template. + */ + void SetInternalFieldCount(int value); + + /** + * Returns true if the object will be an immutable prototype exotic object. + */ + bool IsImmutableProto(); + + /** + * Makes the ObjectTemplate for an immutable prototype exotic object, with an + * immutable __proto__. + */ + void SetImmutableProto(); + + V8_INLINE static ObjectTemplate* Cast(Data* data); + + private: + ObjectTemplate(); + static Local<ObjectTemplate> New(internal::Isolate* isolate, + Local<FunctionTemplate> constructor); + static void CheckCast(Data* that); + friend class FunctionTemplate; +}; + +/** + * A Signature specifies which receiver is valid for a function. + * + * A receiver matches a given signature if the receiver (or any of its + * hidden prototypes) was created from the signature's FunctionTemplate, or + * from a FunctionTemplate that inherits directly or indirectly from the + * signature's FunctionTemplate. + */ +class V8_EXPORT Signature : public Data { + public: + static Local<Signature> New( + Isolate* isolate, + Local<FunctionTemplate> receiver = Local<FunctionTemplate>()); + + V8_INLINE static Signature* Cast(Data* data); + + private: + Signature(); + + static void CheckCast(Data* that); +}; + + +/** + * An AccessorSignature specifies which receivers are valid parameters + * to an accessor callback. + */ +class V8_EXPORT AccessorSignature : public Data { + public: + static Local<AccessorSignature> New( + Isolate* isolate, + Local<FunctionTemplate> receiver = Local<FunctionTemplate>()); + + V8_INLINE static AccessorSignature* Cast(Data* data); + + private: + AccessorSignature(); + + static void CheckCast(Data* that); +}; + + +// --- Extensions --- + +/** + * Ignore + */ +class V8_EXPORT Extension { // NOLINT + public: + // Note that the strings passed into this constructor must live as long + // as the Extension itself. + Extension(const char* name, const char* source = nullptr, int dep_count = 0, + const char** deps = nullptr, int source_length = -1); + virtual ~Extension() { delete source_; } + virtual Local<FunctionTemplate> GetNativeFunctionTemplate( + Isolate* isolate, Local<String> name) { + return Local<FunctionTemplate>(); + } + + const char* name() const { return name_; } + size_t source_length() const { return source_length_; } + const String::ExternalOneByteStringResource* source() const { + return source_; + } + int dependency_count() const { return dep_count_; } + const char** dependencies() const { return deps_; } + void set_auto_enable(bool value) { auto_enable_ = value; } + bool auto_enable() { return auto_enable_; } + + // Disallow copying and assigning. + Extension(const Extension&) = delete; + void operator=(const Extension&) = delete; + + private: + const char* name_; + size_t source_length_; // expected to initialize before source_ + String::ExternalOneByteStringResource* source_; + int dep_count_; + const char** deps_; + bool auto_enable_; +}; + +void V8_EXPORT RegisterExtension(std::unique_ptr<Extension>); + +// --- Statics --- + +V8_INLINE Local<Primitive> Undefined(Isolate* isolate); +V8_INLINE Local<Primitive> Null(Isolate* isolate); +V8_INLINE Local<Boolean> True(Isolate* isolate); +V8_INLINE Local<Boolean> False(Isolate* isolate); + +/** + * A set of constraints that specifies the limits of the runtime's memory use. + * You must set the heap size before initializing the VM - the size cannot be + * adjusted after the VM is initialized. + * + * If you are using threads then you should hold the V8::Locker lock while + * setting the stack limit and you must set a non-default stack limit separately + * for each thread. + * + * The arguments for set_max_semi_space_size, set_max_old_space_size, + * set_max_executable_size, set_code_range_size specify limits in MB. + * + * The argument for set_max_semi_space_size_in_kb is in KB. + */ +class V8_EXPORT ResourceConstraints { + public: + ResourceConstraints(); + + /** + * Configures the constraints with reasonable default values based on the + * capabilities of the current device the VM is running on. + * + * \param physical_memory The total amount of physical memory on the current + * device, in bytes. + * \param virtual_memory_limit The amount of virtual memory on the current + * device, in bytes, or zero, if there is no limit. + */ + void ConfigureDefaults(uint64_t physical_memory, + uint64_t virtual_memory_limit); + + // Returns the max semi-space size in KB. + size_t max_semi_space_size_in_kb() const { + return max_semi_space_size_in_kb_; + } + + // Sets the max semi-space size in KB. + void set_max_semi_space_size_in_kb(size_t limit_in_kb) { + max_semi_space_size_in_kb_ = limit_in_kb; + } + + size_t max_old_space_size() const { return max_old_space_size_; } + void set_max_old_space_size(size_t limit_in_mb) { + max_old_space_size_ = limit_in_mb; + } + uint32_t* stack_limit() const { return stack_limit_; } + // Sets an address beyond which the VM's stack may not grow. + void set_stack_limit(uint32_t* value) { stack_limit_ = value; } + size_t code_range_size() const { return code_range_size_; } + void set_code_range_size(size_t limit_in_mb) { + code_range_size_ = limit_in_mb; + } + V8_DEPRECATE_SOON("Zone does not pool memory any more.", + size_t max_zone_pool_size() const) { + return max_zone_pool_size_; + } + V8_DEPRECATE_SOON("Zone does not pool memory any more.", + void set_max_zone_pool_size(size_t bytes)) { + max_zone_pool_size_ = bytes; + } + + private: + // max_semi_space_size_ is in KB + size_t max_semi_space_size_in_kb_; + + // The remaining limits are in MB + size_t max_old_space_size_; + uint32_t* stack_limit_; + size_t code_range_size_; + size_t max_zone_pool_size_; +}; + + +// --- Exceptions --- + + +typedef void (*FatalErrorCallback)(const char* location, const char* message); + +typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom); + +typedef void (*DcheckErrorCallback)(const char* file, int line, + const char* message); + +typedef void (*MessageCallback)(Local<Message> message, Local<Value> data); + +// --- Tracing --- + +typedef void (*LogEventCallback)(const char* name, int event); + +/** + * Create new error objects by calling the corresponding error object + * constructor with the message. + */ +class V8_EXPORT Exception { + public: + static Local<Value> RangeError(Local<String> message); + static Local<Value> ReferenceError(Local<String> message); + static Local<Value> SyntaxError(Local<String> message); + static Local<Value> TypeError(Local<String> message); + static Local<Value> Error(Local<String> message); + + /** + * Creates an error message for the given exception. + * Will try to reconstruct the original stack trace from the exception value, + * or capture the current stack trace if not available. + */ + static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception); + + /** + * Returns the original stack trace that was captured at the creation time + * of a given exception, or an empty handle if not available. + */ + static Local<StackTrace> GetStackTrace(Local<Value> exception); +}; + + +// --- Counters Callbacks --- + +typedef int* (*CounterLookupCallback)(const char* name); + +typedef void* (*CreateHistogramCallback)(const char* name, + int min, + int max, + size_t buckets); + +typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); + +// --- Enter/Leave Script Callback --- +typedef void (*BeforeCallEnteredCallback)(Isolate*); +typedef void (*CallCompletedCallback)(Isolate*); + +/** + * HostImportModuleDynamicallyCallback is called when we require the + * embedder to load a module. This is used as part of the dynamic + * import syntax. + * + * The referrer contains metadata about the script/module that calls + * import. + * + * The specifier is the name of the module that should be imported. + * + * The embedder must compile, instantiate, evaluate the Module, and + * obtain it's namespace object. + * + * The Promise returned from this function is forwarded to userland + * JavaScript. The embedder must resolve this promise with the module + * namespace object. In case of an exception, the embedder must reject + * this promise with the exception. If the promise creation itself + * fails (e.g. due to stack overflow), the embedder must propagate + * that exception by returning an empty MaybeLocal. + */ +typedef MaybeLocal<Promise> (*HostImportModuleDynamicallyCallback)( + Local<Context> context, Local<ScriptOrModule> referrer, + Local<String> specifier); + +/** + * HostInitializeImportMetaObjectCallback is called the first time import.meta + * is accessed for a module. Subsequent access will reuse the same value. + * + * The method combines two implementation-defined abstract operations into one: + * HostGetImportMetaProperties and HostFinalizeImportMeta. + * + * The embedder should use v8::Object::CreateDataProperty to add properties on + * the meta object. + */ +typedef void (*HostInitializeImportMetaObjectCallback)(Local<Context> context, + Local<Module> module, + Local<Object> meta); + +/** + * PrepareStackTraceCallback is called when the stack property of an error is + * first accessed. The return value will be used as the stack value. If this + * callback is registed, the |Error.prepareStackTrace| API will be disabled. + * |sites| is an array of call sites, specified in + * https://v8.dev/docs/stack-trace-api + */ +typedef MaybeLocal<Value> (*PrepareStackTraceCallback)(Local<Context> context, + Local<Value> error, + Local<Array> sites); + +/** + * PromiseHook with type kInit is called when a new promise is + * created. When a new promise is created as part of the chain in the + * case of Promise.then or in the intermediate promises created by + * Promise.{race, all}/AsyncFunctionAwait, we pass the parent promise + * otherwise we pass undefined. + * + * PromiseHook with type kResolve is called at the beginning of + * resolve or reject function defined by CreateResolvingFunctions. + * + * PromiseHook with type kBefore is called at the beginning of the + * PromiseReactionJob. + * + * PromiseHook with type kAfter is called right at the end of the + * PromiseReactionJob. + */ +enum class PromiseHookType { kInit, kResolve, kBefore, kAfter }; + +typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise, + Local<Value> parent); + +// --- Promise Reject Callback --- +enum PromiseRejectEvent { + kPromiseRejectWithNoHandler = 0, + kPromiseHandlerAddedAfterReject = 1, + kPromiseRejectAfterResolved = 2, + kPromiseResolveAfterResolved = 3, +}; + +class PromiseRejectMessage { + public: + PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event, + Local<Value> value) + : promise_(promise), event_(event), value_(value) {} + + V8_INLINE Local<Promise> GetPromise() const { return promise_; } + V8_INLINE PromiseRejectEvent GetEvent() const { return event_; } + V8_INLINE Local<Value> GetValue() const { return value_; } + + private: + Local<Promise> promise_; + PromiseRejectEvent event_; + Local<Value> value_; +}; + +typedef void (*PromiseRejectCallback)(PromiseRejectMessage message); + +// --- Microtasks Callbacks --- +V8_DEPRECATE_SOON("Use *WithData version.", + typedef void (*MicrotasksCompletedCallback)(Isolate*)); +typedef void (*MicrotasksCompletedCallbackWithData)(Isolate*, void*); +typedef void (*MicrotaskCallback)(void* data); + + +/** + * Policy for running microtasks: + * - explicit: microtasks are invoked with Isolate::RunMicrotasks() method; + * - scoped: microtasks invocation is controlled by MicrotasksScope objects; + * - auto: microtasks are invoked when the script call depth decrements + * to zero. + */ +enum class MicrotasksPolicy { kExplicit, kScoped, kAuto }; + +/** + * Represents the microtask queue, where microtasks are stored and processed. + * https://html.spec.whatwg.org/multipage/webappapis.html#microtask-queue + * https://html.spec.whatwg.org/multipage/webappapis.html#enqueuejob(queuename,-job,-arguments) + * https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint + * + * A MicrotaskQueue instance may be associated to multiple Contexts by passing + * it to Context::New(), and they can be detached by Context::DetachGlobal(). + * The embedder must keep the MicrotaskQueue instance alive until all associated + * Contexts are gone or detached. + * + * Use the same instance of MicrotaskQueue for all Contexts that may access each + * other synchronously. E.g. for Web embedding, use the same instance for all + * origins that share the same URL scheme and eTLD+1. + */ +class V8_EXPORT MicrotaskQueue { + public: + /** + * Creates an empty MicrotaskQueue instance. + */ + static std::unique_ptr<MicrotaskQueue> New( + Isolate* isolate, MicrotasksPolicy policy = MicrotasksPolicy::kAuto); + + virtual ~MicrotaskQueue() = default; + + /** + * Enqueues the callback to the queue. + */ + virtual void EnqueueMicrotask(Isolate* isolate, + Local<Function> microtask) = 0; + + /** + * Enqueues the callback to the queue. + */ + virtual void EnqueueMicrotask(v8::Isolate* isolate, + MicrotaskCallback callback, + void* data = nullptr) = 0; + + /** + * Adds a callback to notify the embedder after microtasks were run. The + * callback is triggered by explicit RunMicrotasks call or automatic + * microtasks execution (see Isolate::SetMicrotasksPolicy). + * + * Callback will trigger even if microtasks were attempted to run, + * but the microtasks queue was empty and no single microtask was actually + * executed. + * + * Executing scripts inside the callback will not re-trigger microtasks and + * the callback. + */ + virtual void AddMicrotasksCompletedCallback( + MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0; + + /** + * Removes callback that was installed by AddMicrotasksCompletedCallback. + */ + virtual void RemoveMicrotasksCompletedCallback( + MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0; + + /** + * Runs microtasks if no microtask is running on this MicrotaskQueue instance. + */ + virtual void PerformCheckpoint(Isolate* isolate) = 0; + + /** + * Returns true if a microtask is running on this MicrotaskQueue instance. + */ + virtual bool IsRunningMicrotasks() const = 0; + + /** + * Returns the current depth of nested MicrotasksScope that has + * kRunMicrotasks. + */ + virtual int GetMicrotasksScopeDepth() const = 0; + + private: + friend class internal::MicrotaskQueue; + MicrotaskQueue() = default; + MicrotaskQueue(const MicrotaskQueue&) = delete; + MicrotaskQueue& operator=(const MicrotaskQueue&) = delete; +}; + +/** + * This scope is used to control microtasks when kScopeMicrotasksInvocation + * is used on Isolate. In this mode every non-primitive call to V8 should be + * done inside some MicrotasksScope. + * Microtasks are executed when topmost MicrotasksScope marked as kRunMicrotasks + * exits. + * kDoNotRunMicrotasks should be used to annotate calls not intended to trigger + * microtasks. + */ +class V8_EXPORT MicrotasksScope { + public: + enum Type { kRunMicrotasks, kDoNotRunMicrotasks }; + + MicrotasksScope(Isolate* isolate, Type type); + MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type); + ~MicrotasksScope(); + + /** + * Runs microtasks if no kRunMicrotasks scope is currently active. + */ + static void PerformCheckpoint(Isolate* isolate); + + /** + * Returns current depth of nested kRunMicrotasks scopes. + */ + static int GetCurrentDepth(Isolate* isolate); + + /** + * Returns true while microtasks are being executed. + */ + static bool IsRunningMicrotasks(Isolate* isolate); + + // Prevent copying. + MicrotasksScope(const MicrotasksScope&) = delete; + MicrotasksScope& operator=(const MicrotasksScope&) = delete; + + private: + internal::Isolate* const isolate_; + internal::MicrotaskQueue* const microtask_queue_; + bool run_; +}; + + +// --- Failed Access Check Callback --- +typedef void (*FailedAccessCheckCallback)(Local<Object> target, + AccessType type, + Local<Value> data); + +// --- AllowCodeGenerationFromStrings callbacks --- + +/** + * Callback to check if code generation from strings is allowed. See + * Context::AllowCodeGenerationFromStrings. + */ +typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context, + Local<String> source); + +// --- WebAssembly compilation callbacks --- +typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&); + +typedef bool (*AllowWasmCodeGenerationCallback)(Local<Context> context, + Local<String> source); + +// --- Callback for APIs defined on v8-supported objects, but implemented +// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming --- +typedef void (*ApiImplementationCallback)(const FunctionCallbackInfo<Value>&); + +// --- Callback for WebAssembly.compileStreaming --- +typedef void (*WasmStreamingCallback)(const FunctionCallbackInfo<Value>&); + +// --- Callback for checking if WebAssembly threads are enabled --- +typedef bool (*WasmThreadsEnabledCallback)(Local<Context> context); + +// --- Garbage Collection Callbacks --- + +/** + * Applications can register callback functions which will be called before and + * after certain garbage collection operations. Allocations are not allowed in + * the callback functions, you therefore cannot manipulate objects (set or + * delete properties for example) since it is possible such operations will + * result in the allocation of objects. + */ +enum GCType { + kGCTypeScavenge = 1 << 0, + kGCTypeMarkSweepCompact = 1 << 1, + kGCTypeIncrementalMarking = 1 << 2, + kGCTypeProcessWeakCallbacks = 1 << 3, + kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact | + kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks +}; + +/** + * GCCallbackFlags is used to notify additional information about the GC + * callback. + * - kGCCallbackFlagConstructRetainedObjectInfos: The GC callback is for + * constructing retained object infos. + * - kGCCallbackFlagForced: The GC callback is for a forced GC for testing. + * - kGCCallbackFlagSynchronousPhantomCallbackProcessing: The GC callback + * is called synchronously without getting posted to an idle task. + * - kGCCallbackFlagCollectAllAvailableGarbage: The GC callback is called + * in a phase where V8 is trying to collect all available garbage + * (e.g., handling a low memory notification). + * - kGCCallbackScheduleIdleGarbageCollection: The GC callback is called to + * trigger an idle garbage collection. + */ +enum GCCallbackFlags { + kNoGCCallbackFlags = 0, + kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1, + kGCCallbackFlagForced = 1 << 2, + kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3, + kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4, + kGCCallbackFlagCollectAllExternalMemory = 1 << 5, + kGCCallbackScheduleIdleGarbageCollection = 1 << 6, +}; + +typedef void (*GCCallback)(GCType type, GCCallbackFlags flags); + +typedef void (*InterruptCallback)(Isolate* isolate, void* data); + +/** + * This callback is invoked when the heap size is close to the heap limit and + * V8 is likely to abort with out-of-memory error. + * The callback can extend the heap limit by returning a value that is greater + * than the current_heap_limit. The initial heap limit is the limit that was + * set after heap setup. + */ +typedef size_t (*NearHeapLimitCallback)(void* data, size_t current_heap_limit, + size_t initial_heap_limit); + +/** + * Collection of V8 heap information. + * + * Instances of this class can be passed to v8::V8::HeapStatistics to + * get heap statistics from V8. + */ +class V8_EXPORT HeapStatistics { + public: + HeapStatistics(); + size_t total_heap_size() { return total_heap_size_; } + size_t total_heap_size_executable() { return total_heap_size_executable_; } + size_t total_physical_size() { return total_physical_size_; } + size_t total_available_size() { return total_available_size_; } + size_t used_heap_size() { return used_heap_size_; } + size_t heap_size_limit() { return heap_size_limit_; } + size_t malloced_memory() { return malloced_memory_; } + size_t external_memory() { return external_memory_; } + size_t peak_malloced_memory() { return peak_malloced_memory_; } + size_t number_of_native_contexts() { return number_of_native_contexts_; } + size_t number_of_detached_contexts() { return number_of_detached_contexts_; } + + /** + * Returns a 0/1 boolean, which signifies whether the V8 overwrite heap + * garbage with a bit pattern. + */ + size_t does_zap_garbage() { return does_zap_garbage_; } + + private: + size_t total_heap_size_; + size_t total_heap_size_executable_; + size_t total_physical_size_; + size_t total_available_size_; + size_t used_heap_size_; + size_t heap_size_limit_; + size_t malloced_memory_; + size_t external_memory_; + size_t peak_malloced_memory_; + bool does_zap_garbage_; + size_t number_of_native_contexts_; + size_t number_of_detached_contexts_; + + friend class V8; + friend class Isolate; +}; + + +class V8_EXPORT HeapSpaceStatistics { + public: + HeapSpaceStatistics(); + const char* space_name() { return space_name_; } + size_t space_size() { return space_size_; } + size_t space_used_size() { return space_used_size_; } + size_t space_available_size() { return space_available_size_; } + size_t physical_space_size() { return physical_space_size_; } + + private: + const char* space_name_; + size_t space_size_; + size_t space_used_size_; + size_t space_available_size_; + size_t physical_space_size_; + + friend class Isolate; +}; + + +class V8_EXPORT HeapObjectStatistics { + public: + HeapObjectStatistics(); + const char* object_type() { return object_type_; } + const char* object_sub_type() { return object_sub_type_; } + size_t object_count() { return object_count_; } + size_t object_size() { return object_size_; } + + private: + const char* object_type_; + const char* object_sub_type_; + size_t object_count_; + size_t object_size_; + + friend class Isolate; +}; + +class V8_EXPORT HeapCodeStatistics { + public: + HeapCodeStatistics(); + size_t code_and_metadata_size() { return code_and_metadata_size_; } + size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; } + size_t external_script_source_size() { return external_script_source_size_; } + + private: + size_t code_and_metadata_size_; + size_t bytecode_and_metadata_size_; + size_t external_script_source_size_; + + friend class Isolate; +}; + +/** + * A JIT code event is issued each time code is added, moved or removed. + * + * \note removal events are not currently issued. + */ +struct JitCodeEvent { + enum EventType { + CODE_ADDED, + CODE_MOVED, + CODE_REMOVED, + CODE_ADD_LINE_POS_INFO, + CODE_START_LINE_INFO_RECORDING, + CODE_END_LINE_INFO_RECORDING + }; + // Definition of the code position type. The "POSITION" type means the place + // in the source code which are of interest when making stack traces to + // pin-point the source location of a stack frame as close as possible. + // The "STATEMENT_POSITION" means the place at the beginning of each + // statement, and is used to indicate possible break locations. + enum PositionType { POSITION, STATEMENT_POSITION }; + + // There are two different kinds of JitCodeEvents, one for JIT code generated + // by the optimizing compiler, and one for byte code generated for the + // interpreter. For JIT_CODE events, the |code_start| member of the event + // points to the beginning of jitted assembly code, while for BYTE_CODE + // events, |code_start| points to the first bytecode of the interpreted + // function. + enum CodeType { BYTE_CODE, JIT_CODE }; + + // Type of event. + EventType type; + CodeType code_type; + // Start of the instructions. + void* code_start; + // Size of the instructions. + size_t code_len; + // Script info for CODE_ADDED event. + Local<UnboundScript> script; + // User-defined data for *_LINE_INFO_* event. It's used to hold the source + // code line information which is returned from the + // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent + // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events. + void* user_data; + + struct name_t { + // Name of the object associated with the code, note that the string is not + // zero-terminated. + const char* str; + // Number of chars in str. + size_t len; + }; + + struct line_info_t { + // PC offset + size_t offset; + // Code position + size_t pos; + // The position type. + PositionType position_type; + }; + + union { + // Only valid for CODE_ADDED. + struct name_t name; + + // Only valid for CODE_ADD_LINE_POS_INFO + struct line_info_t line_info; + + // New location of instructions. Only valid for CODE_MOVED. + void* new_code_start; + }; + + Isolate* isolate; +}; + +/** + * Option flags passed to the SetRAILMode function. + * See documentation https://developers.google.com/web/tools/chrome-devtools/ + * profile/evaluate-performance/rail + */ +enum RAILMode : unsigned { + // Response performance mode: In this mode very low virtual machine latency + // is provided. V8 will try to avoid JavaScript execution interruptions. + // Throughput may be throttled. + PERFORMANCE_RESPONSE, + // Animation performance mode: In this mode low virtual machine latency is + // provided. V8 will try to avoid as many JavaScript execution interruptions + // as possible. Throughput may be throttled. This is the default mode. + PERFORMANCE_ANIMATION, + // Idle performance mode: The embedder is idle. V8 can complete deferred work + // in this mode. + PERFORMANCE_IDLE, + // Load performance mode: In this mode high throughput is provided. V8 may + // turn off latency optimizations. + PERFORMANCE_LOAD +}; + +/** + * Option flags passed to the SetJitCodeEventHandler function. + */ +enum JitCodeEventOptions { + kJitCodeEventDefault = 0, + // Generate callbacks for already existent code. + kJitCodeEventEnumExisting = 1 +}; + + +/** + * Callback function passed to SetJitCodeEventHandler. + * + * \param event code add, move or removal event. + */ +typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); + +/** + * Callback function passed to SetUnhandledExceptionCallback. + */ +#if defined(V8_OS_WIN) +typedef int (*UnhandledExceptionCallback)( + _EXCEPTION_POINTERS* exception_pointers); +#endif + +/** + * Interface for iterating through all external resources in the heap. + */ +class V8_EXPORT ExternalResourceVisitor { // NOLINT + public: + virtual ~ExternalResourceVisitor() = default; + virtual void VisitExternalString(Local<String> string) {} +}; + + +/** + * Interface for iterating through all the persistent handles in the heap. + */ +class V8_EXPORT PersistentHandleVisitor { // NOLINT + public: + virtual ~PersistentHandleVisitor() = default; + virtual void VisitPersistentHandle(Persistent<Value>* value, + uint16_t class_id) {} +}; + +/** + * Memory pressure level for the MemoryPressureNotification. + * kNone hints V8 that there is no memory pressure. + * kModerate hints V8 to speed up incremental garbage collection at the cost of + * of higher latency due to garbage collection pauses. + * kCritical hints V8 to free memory as soon as possible. Garbage collection + * pauses at this level will be large. + */ +enum class MemoryPressureLevel { kNone, kModerate, kCritical }; + +/** + * Interface for tracing through the embedder heap. During a V8 garbage + * collection, V8 collects hidden fields of all potential wrappers, and at the + * end of its marking phase iterates the collection and asks the embedder to + * trace through its heap and use reporter to report each JavaScript object + * reachable from any of the given wrappers. + */ +class V8_EXPORT EmbedderHeapTracer { + public: + // Indicator for the stack state of the embedder. + enum EmbedderStackState { + kUnknown, + kNonEmpty, + kEmpty, + }; + + /** + * Interface for iterating through TracedGlobal handles. + */ + class V8_EXPORT TracedGlobalHandleVisitor { + public: + virtual ~TracedGlobalHandleVisitor() = default; + virtual void VisitTracedGlobalHandle(const TracedGlobal<Value>& value) = 0; + }; + + virtual ~EmbedderHeapTracer() = default; + + /** + * Iterates all TracedGlobal handles created for the v8::Isolate the tracer is + * attached to. + */ + void IterateTracedGlobalHandles(TracedGlobalHandleVisitor* visitor); + + /** + * Called by v8 to register internal fields of found wrappers. + * + * The embedder is expected to store them somewhere and trace reachable + * wrappers from them when called through |AdvanceTracing|. + */ + virtual void RegisterV8References( + const std::vector<std::pair<void*, void*> >& embedder_fields) = 0; + + void RegisterEmbedderReference(const TracedGlobal<v8::Value>& ref); + + /** + * Called at the beginning of a GC cycle. + */ + virtual void TracePrologue() = 0; + + /** + * Called to advance tracing in the embedder. + * + * The embedder is expected to trace its heap starting from wrappers reported + * by RegisterV8References method, and report back all reachable wrappers. + * Furthermore, the embedder is expected to stop tracing by the given + * deadline. A deadline of infinity means that tracing should be finished. + * + * Returns |true| if tracing is done, and false otherwise. + */ + virtual bool AdvanceTracing(double deadline_in_ms) = 0; + + /* + * Returns true if there no more tracing work to be done (see AdvanceTracing) + * and false otherwise. + */ + virtual bool IsTracingDone() = 0; + + /** + * Called at the end of a GC cycle. + * + * Note that allocation is *not* allowed within |TraceEpilogue|. + */ + virtual void TraceEpilogue() = 0; + + /** + * Called upon entering the final marking pause. No more incremental marking + * steps will follow this call. + */ + virtual void EnterFinalPause(EmbedderStackState stack_state) = 0; + + /* + * Called by the embedder to request immediate finalization of the currently + * running tracing phase that has been started with TracePrologue and not + * yet finished with TraceEpilogue. + * + * Will be a noop when currently not in tracing. + * + * This is an experimental feature. + */ + void FinalizeTracing(); + + /** + * Returns true if the TracedGlobal handle should be considered as root for + * the currently running non-tracing garbage collection and false otherwise. + * + * Default implementation will keep all TracedGlobal references as roots. + */ + virtual bool IsRootForNonTracingGC( + const v8::TracedGlobal<v8::Value>& handle) { + return true; + } + + /* + * Called by the embedder to immediately perform a full garbage collection. + * + * Should only be used in testing code. + */ + void GarbageCollectionForTesting(EmbedderStackState stack_state); + + /* + * Returns the v8::Isolate this tracer is attached too and |nullptr| if it + * is not attached to any v8::Isolate. + */ + v8::Isolate* isolate() const { return isolate_; } + + protected: + v8::Isolate* isolate_ = nullptr; + + friend class internal::LocalEmbedderHeapTracer; +}; + +/** + * Callback and supporting data used in SnapshotCreator to implement embedder + * logic to serialize internal fields. + * Internal fields that directly reference V8 objects are serialized without + * calling this callback. Internal fields that contain aligned pointers are + * serialized by this callback if it returns non-zero result. Otherwise it is + * serialized verbatim. + */ +struct SerializeInternalFieldsCallback { + typedef StartupData (*CallbackFunction)(Local<Object> holder, int index, + void* data); + SerializeInternalFieldsCallback(CallbackFunction function = nullptr, + void* data_arg = nullptr) + : callback(function), data(data_arg) {} + CallbackFunction callback; + void* data; +}; +// Note that these fields are called "internal fields" in the API and called +// "embedder fields" within V8. +typedef SerializeInternalFieldsCallback SerializeEmbedderFieldsCallback; + +/** + * Callback and supporting data used to implement embedder logic to deserialize + * internal fields. + */ +struct DeserializeInternalFieldsCallback { + typedef void (*CallbackFunction)(Local<Object> holder, int index, + StartupData payload, void* data); + DeserializeInternalFieldsCallback(CallbackFunction function = nullptr, + void* data_arg = nullptr) + : callback(function), data(data_arg) {} + void (*callback)(Local<Object> holder, int index, StartupData payload, + void* data); + void* data; +}; +typedef DeserializeInternalFieldsCallback DeserializeEmbedderFieldsCallback; + +/** + * Isolate represents an isolated instance of the V8 engine. V8 isolates have + * completely separate states. Objects from one isolate must not be used in + * other isolates. The embedder can create multiple isolates and use them in + * parallel in multiple threads. An isolate can be entered by at most one + * thread at any given time. The Locker/Unlocker API must be used to + * synchronize. + */ +class V8_EXPORT Isolate { + public: + /** + * Initial configuration parameters for a new Isolate. + */ + struct CreateParams { + CreateParams() + : code_event_handler(nullptr), + snapshot_blob(nullptr), + counter_lookup_callback(nullptr), + create_histogram_callback(nullptr), + add_histogram_sample_callback(nullptr), + array_buffer_allocator(nullptr), + external_references(nullptr), + allow_atomics_wait(true), + only_terminate_in_safe_scope(false) {} + + /** + * Allows the host application to provide the address of a function that is + * notified each time code is added, moved or removed. + */ + JitCodeEventHandler code_event_handler; + + /** + * ResourceConstraints to use for the new Isolate. + */ + ResourceConstraints constraints; + + /** + * Explicitly specify a startup snapshot blob. The embedder owns the blob. + */ + StartupData* snapshot_blob; + + + /** + * Enables the host application to provide a mechanism for recording + * statistics counters. + */ + CounterLookupCallback counter_lookup_callback; + + /** + * Enables the host application to provide a mechanism for recording + * histograms. The CreateHistogram function returns a + * histogram which will later be passed to the AddHistogramSample + * function. + */ + CreateHistogramCallback create_histogram_callback; + AddHistogramSampleCallback add_histogram_sample_callback; + + /** + * The ArrayBuffer::Allocator to use for allocating and freeing the backing + * store of ArrayBuffers. + */ + ArrayBuffer::Allocator* array_buffer_allocator; + + /** + * Specifies an optional nullptr-terminated array of raw addresses in the + * embedder that V8 can match against during serialization and use for + * deserialization. This array and its content must stay valid for the + * entire lifetime of the isolate. + */ + const intptr_t* external_references; + + /** + * Whether calling Atomics.wait (a function that may block) is allowed in + * this isolate. This can also be configured via SetAllowAtomicsWait. + */ + bool allow_atomics_wait; + + /** + * Termination is postponed when there is no active SafeForTerminationScope. + */ + bool only_terminate_in_safe_scope; + }; + + + /** + * Stack-allocated class which sets the isolate for all operations + * executed within a local scope. + */ + class V8_EXPORT Scope { + public: + explicit Scope(Isolate* isolate) : isolate_(isolate) { + isolate->Enter(); + } + + ~Scope() { isolate_->Exit(); } + + // Prevent copying of Scope objects. + Scope(const Scope&) = delete; + Scope& operator=(const Scope&) = delete; + + private: + Isolate* const isolate_; + }; + + + /** + * Assert that no Javascript code is invoked. + */ + class V8_EXPORT DisallowJavascriptExecutionScope { + public: + enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE }; + + DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure); + ~DisallowJavascriptExecutionScope(); + + // Prevent copying of Scope objects. + DisallowJavascriptExecutionScope(const DisallowJavascriptExecutionScope&) = + delete; + DisallowJavascriptExecutionScope& operator=( + const DisallowJavascriptExecutionScope&) = delete; + + private: + OnFailure on_failure_; + void* internal_; + }; + + + /** + * Introduce exception to DisallowJavascriptExecutionScope. + */ + class V8_EXPORT AllowJavascriptExecutionScope { + public: + explicit AllowJavascriptExecutionScope(Isolate* isolate); + ~AllowJavascriptExecutionScope(); + + // Prevent copying of Scope objects. + AllowJavascriptExecutionScope(const AllowJavascriptExecutionScope&) = + delete; + AllowJavascriptExecutionScope& operator=( + const AllowJavascriptExecutionScope&) = delete; + + private: + void* internal_throws_; + void* internal_assert_; + void* internal_dump_; + }; + + /** + * Do not run microtasks while this scope is active, even if microtasks are + * automatically executed otherwise. + */ + class V8_EXPORT SuppressMicrotaskExecutionScope { + public: + explicit SuppressMicrotaskExecutionScope(Isolate* isolate); + explicit SuppressMicrotaskExecutionScope(MicrotaskQueue* microtask_queue); + ~SuppressMicrotaskExecutionScope(); + + // Prevent copying of Scope objects. + SuppressMicrotaskExecutionScope(const SuppressMicrotaskExecutionScope&) = + delete; + SuppressMicrotaskExecutionScope& operator=( + const SuppressMicrotaskExecutionScope&) = delete; + + private: + internal::Isolate* const isolate_; + internal::MicrotaskQueue* const microtask_queue_; + }; + + /** + * This scope allows terminations inside direct V8 API calls and forbid them + * inside any recursice API calls without explicit SafeForTerminationScope. + */ + class V8_EXPORT SafeForTerminationScope { + public: + explicit SafeForTerminationScope(v8::Isolate* isolate); + ~SafeForTerminationScope(); + + // Prevent copying of Scope objects. + SafeForTerminationScope(const SafeForTerminationScope&) = delete; + SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete; + + private: + internal::Isolate* isolate_; + bool prev_value_; + }; + + /** + * Types of garbage collections that can be requested via + * RequestGarbageCollectionForTesting. + */ + enum GarbageCollectionType { + kFullGarbageCollection, + kMinorGarbageCollection + }; + + /** + * Features reported via the SetUseCounterCallback callback. Do not change + * assigned numbers of existing items; add new features to the end of this + * list. + */ + enum UseCounterFeature { + kUseAsm = 0, + kBreakIterator = 1, + kLegacyConst = 2, + kMarkDequeOverflow = 3, + kStoreBufferOverflow = 4, + kSlotsBufferOverflow = 5, + kObjectObserve = 6, + kForcedGC = 7, + kSloppyMode = 8, + kStrictMode = 9, + kStrongMode = 10, + kRegExpPrototypeStickyGetter = 11, + kRegExpPrototypeToString = 12, + kRegExpPrototypeUnicodeGetter = 13, + kIntlV8Parse = 14, + kIntlPattern = 15, + kIntlResolved = 16, + kPromiseChain = 17, + kPromiseAccept = 18, + kPromiseDefer = 19, + kHtmlCommentInExternalScript = 20, + kHtmlComment = 21, + kSloppyModeBlockScopedFunctionRedefinition = 22, + kForInInitializer = 23, + kArrayProtectorDirtied = 24, + kArraySpeciesModified = 25, + kArrayPrototypeConstructorModified = 26, + kArrayInstanceProtoModified = 27, + kArrayInstanceConstructorModified = 28, + kLegacyFunctionDeclaration = 29, + kRegExpPrototypeSourceGetter = 30, + kRegExpPrototypeOldFlagGetter = 31, + kDecimalWithLeadingZeroInStrictMode = 32, + kLegacyDateParser = 33, + kDefineGetterOrSetterWouldThrow = 34, + kFunctionConstructorReturnedUndefined = 35, + kAssigmentExpressionLHSIsCallInSloppy = 36, + kAssigmentExpressionLHSIsCallInStrict = 37, + kPromiseConstructorReturnedUndefined = 38, + kConstructorNonUndefinedPrimitiveReturn = 39, + kLabeledExpressionStatement = 40, + kLineOrParagraphSeparatorAsLineTerminator = 41, + kIndexAccessor = 42, + kErrorCaptureStackTrace = 43, + kErrorPrepareStackTrace = 44, + kErrorStackTraceLimit = 45, + kWebAssemblyInstantiation = 46, + kDeoptimizerDisableSpeculation = 47, + kArrayPrototypeSortJSArrayModifiedPrototype = 48, + kFunctionTokenOffsetTooLongForToString = 49, + kWasmSharedMemory = 50, + kWasmThreadOpcodes = 51, + kAtomicsNotify = 52, + kAtomicsWake = 53, + kCollator = 54, + kNumberFormat = 55, + kDateTimeFormat = 56, + kPluralRules = 57, + kRelativeTimeFormat = 58, + kLocale = 59, + kListFormat = 60, + kSegmenter = 61, + kStringLocaleCompare = 62, + kStringToLocaleUpperCase = 63, + kStringToLocaleLowerCase = 64, + kNumberToLocaleString = 65, + kDateToLocaleString = 66, + kDateToLocaleDateString = 67, + kDateToLocaleTimeString = 68, + kAttemptOverrideReadOnlyOnPrototypeSloppy = 69, + kAttemptOverrideReadOnlyOnPrototypeStrict = 70, + kOptimizedFunctionWithOneShotBytecode = 71, + kRegExpMatchIsTrueishOnNonJSRegExp = 72, + kRegExpMatchIsFalseishOnJSRegExp = 73, + kDateGetTimezoneOffset = 74, + kStringNormalize = 75, + + // If you add new values here, you'll also need to update Chromium's: + // web_feature.mojom, UseCounterCallback.cpp, and enums.xml. V8 changes to + // this list need to be landed first, then changes on the Chromium side. + kUseCounterFeatureCount // This enum value must be last. + }; + + enum MessageErrorLevel { + kMessageLog = (1 << 0), + kMessageDebug = (1 << 1), + kMessageInfo = (1 << 2), + kMessageError = (1 << 3), + kMessageWarning = (1 << 4), + kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError | + kMessageWarning, + }; + + typedef void (*UseCounterCallback)(Isolate* isolate, + UseCounterFeature feature); + + /** + * Allocates a new isolate but does not initialize it. Does not change the + * currently entered isolate. + * + * Only Isolate::GetData() and Isolate::SetData(), which access the + * embedder-controlled parts of the isolate, are allowed to be called on the + * uninitialized isolate. To initialize the isolate, call + * Isolate::Initialize(). + * + * When an isolate is no longer used its resources should be freed + * by calling Dispose(). Using the delete operator is not allowed. + * + * V8::Initialize() must have run prior to this. + */ + static Isolate* Allocate(); + + /** + * Initialize an Isolate previously allocated by Isolate::Allocate(). + */ + static void Initialize(Isolate* isolate, const CreateParams& params); + + /** + * Creates a new isolate. Does not change the currently entered + * isolate. + * + * When an isolate is no longer used its resources should be freed + * by calling Dispose(). Using the delete operator is not allowed. + * + * V8::Initialize() must have run prior to this. + */ + static Isolate* New(const CreateParams& params); + + /** + * Returns the entered isolate for the current thread or NULL in + * case there is no current isolate. + * + * This method must not be invoked before V8::Initialize() was invoked. + */ + static Isolate* GetCurrent(); + + /** + * Custom callback used by embedders to help V8 determine if it should abort + * when it throws and no internal handler is predicted to catch the + * exception. If --abort-on-uncaught-exception is used on the command line, + * then V8 will abort if either: + * - no custom callback is set. + * - the custom callback set returns true. + * Otherwise, the custom callback will not be called and V8 will not abort. + */ + typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*); + void SetAbortOnUncaughtExceptionCallback( + AbortOnUncaughtExceptionCallback callback); + + /** + * This specifies the callback called by the upcoming dynamic + * import() language feature to load modules. + */ + void SetHostImportModuleDynamicallyCallback( + HostImportModuleDynamicallyCallback callback); + + /** + * This specifies the callback called by the upcoming importa.meta + * language feature to retrieve host-defined meta data for a module. + */ + void SetHostInitializeImportMetaObjectCallback( + HostInitializeImportMetaObjectCallback callback); + + /** + * This specifies the callback called when the stack property of Error + * is accessed. + */ + void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback); + + /** + * Optional notification that the system is running low on memory. + * V8 uses these notifications to guide heuristics. + * It is allowed to call this function from another thread while + * the isolate is executing long running JavaScript code. + */ + void MemoryPressureNotification(MemoryPressureLevel level); + + /** + * Methods below this point require holding a lock (using Locker) in + * a multi-threaded environment. + */ + + /** + * Sets this isolate as the entered one for the current thread. + * Saves the previously entered one (if any), so that it can be + * restored when exiting. Re-entering an isolate is allowed. + */ + void Enter(); + + /** + * Exits this isolate by restoring the previously entered one in the + * current thread. The isolate may still stay the same, if it was + * entered more than once. + * + * Requires: this == Isolate::GetCurrent(). + */ + void Exit(); + + /** + * Disposes the isolate. The isolate must not be entered by any + * thread to be disposable. + */ + void Dispose(); + + /** + * Dumps activated low-level V8 internal stats. This can be used instead + * of performing a full isolate disposal. + */ + void DumpAndResetStats(); + + /** + * Discards all V8 thread-specific data for the Isolate. Should be used + * if a thread is terminating and it has used an Isolate that will outlive + * the thread -- all thread-specific data for an Isolate is discarded when + * an Isolate is disposed so this call is pointless if an Isolate is about + * to be Disposed. + */ + void DiscardThreadSpecificMetadata(); + + /** + * Associate embedder-specific data with the isolate. |slot| has to be + * between 0 and GetNumberOfDataSlots() - 1. + */ + V8_INLINE void SetData(uint32_t slot, void* data); + + /** + * Retrieve embedder-specific data from the isolate. + * Returns NULL if SetData has never been called for the given |slot|. + */ + V8_INLINE void* GetData(uint32_t slot); + + /** + * Returns the maximum number of available embedder data slots. Valid slots + * are in the range of 0 - GetNumberOfDataSlots() - 1. + */ + V8_INLINE static uint32_t GetNumberOfDataSlots(); + + /** + * Return data that was previously attached to the isolate snapshot via + * SnapshotCreator, and removes the reference to it. + * Repeated call with the same index returns an empty MaybeLocal. + */ + template <class T> + V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index); + + /** + * Get statistics about the heap memory usage. + */ + void GetHeapStatistics(HeapStatistics* heap_statistics); + + /** + * Returns the number of spaces in the heap. + */ + size_t NumberOfHeapSpaces(); + + /** + * Get the memory usage of a space in the heap. + * + * \param space_statistics The HeapSpaceStatistics object to fill in + * statistics. + * \param index The index of the space to get statistics from, which ranges + * from 0 to NumberOfHeapSpaces() - 1. + * \returns true on success. + */ + bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics, + size_t index); + + /** + * Returns the number of types of objects tracked in the heap at GC. + */ + size_t NumberOfTrackedHeapObjectTypes(); + + /** + * Get statistics about objects in the heap. + * + * \param object_statistics The HeapObjectStatistics object to fill in + * statistics of objects of given type, which were live in the previous GC. + * \param type_index The index of the type of object to fill details about, + * which ranges from 0 to NumberOfTrackedHeapObjectTypes() - 1. + * \returns true on success. + */ + bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics, + size_t type_index); + + /** + * Get statistics about code and its metadata in the heap. + * + * \param object_statistics The HeapCodeStatistics object to fill in + * statistics of code, bytecode and their metadata. + * \returns true on success. + */ + bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics); + + /** + * Get a call stack sample from the isolate. + * \param state Execution state. + * \param frames Caller allocated buffer to store stack frames. + * \param frames_limit Maximum number of frames to capture. The buffer must + * be large enough to hold the number of frames. + * \param sample_info The sample info is filled up by the function + * provides number of actual captured stack frames and + * the current VM state. + * \note GetStackSample should only be called when the JS thread is paused or + * interrupted. Otherwise the behavior is undefined. + */ + void GetStackSample(const RegisterState& state, void** frames, + size_t frames_limit, SampleInfo* sample_info); + + /** + * Adjusts the amount of registered external memory. Used to give V8 an + * indication of the amount of externally allocated memory that is kept alive + * by JavaScript objects. V8 uses this to decide when to perform global + * garbage collections. Registering externally allocated memory will trigger + * global garbage collections more often than it would otherwise in an attempt + * to garbage collect the JavaScript objects that keep the externally + * allocated memory alive. + * + * \param change_in_bytes the change in externally allocated memory that is + * kept alive by JavaScript objects. + * \returns the adjusted value. + */ + V8_INLINE int64_t + AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes); + + /** + * Returns the number of phantom handles without callbacks that were reset + * by the garbage collector since the last call to this function. + */ + size_t NumberOfPhantomHandleResetsSinceLastCall(); + + /** + * Returns heap profiler for this isolate. Will return NULL until the isolate + * is initialized. + */ + HeapProfiler* GetHeapProfiler(); + + /** + * Tells the VM whether the embedder is idle or not. + */ + void SetIdle(bool is_idle); + + /** Returns the ArrayBuffer::Allocator used in this isolate. */ + ArrayBuffer::Allocator* GetArrayBufferAllocator(); + + /** Returns true if this isolate has a current context. */ + bool InContext(); + + /** + * Returns the context of the currently running JavaScript, or the context + * on the top of the stack if no JavaScript is running. + */ + Local<Context> GetCurrentContext(); + + /** Returns the last context entered through V8's C++ API. */ + V8_DEPRECATED("Use GetEnteredOrMicrotaskContext().", + Local<Context> GetEnteredContext()); + + /** + * Returns either the last context entered through V8's C++ API, or the + * context of the currently running microtask while processing microtasks. + * If a context is entered while executing a microtask, that context is + * returned. + */ + Local<Context> GetEnteredOrMicrotaskContext(); + + /** + * Returns the Context that corresponds to the Incumbent realm in HTML spec. + * https://html.spec.whatwg.org/multipage/webappapis.html#incumbent + */ + Local<Context> GetIncumbentContext(); + + /** + * Schedules an exception to be thrown when returning to JavaScript. When an + * exception has been scheduled it is illegal to invoke any JavaScript + * operation; the caller must return immediately and only after the exception + * has been handled does it become legal to invoke JavaScript operations. + */ + Local<Value> ThrowException(Local<Value> exception); + + typedef void (*GCCallback)(Isolate* isolate, GCType type, + GCCallbackFlags flags); + typedef void (*GCCallbackWithData)(Isolate* isolate, GCType type, + GCCallbackFlags flags, void* data); + + /** + * Enables the host application to receive a notification before a + * garbage collection. Allocations are allowed in the callback function, + * but the callback is not re-entrant: if the allocation inside it will + * trigger the garbage collection, the callback won't be called again. + * It is possible to specify the GCType filter for your callback. But it is + * not possible to register the same callback function two times with + * different GCType filters. + */ + void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr, + GCType gc_type_filter = kGCTypeAll); + void AddGCPrologueCallback(GCCallback callback, + GCType gc_type_filter = kGCTypeAll); + + /** + * This function removes callback which was installed by + * AddGCPrologueCallback function. + */ + void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr); + void RemoveGCPrologueCallback(GCCallback callback); + + /** + * Sets the embedder heap tracer for the isolate. + */ + void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer); + + /* + * Gets the currently active heap tracer for the isolate. + */ + EmbedderHeapTracer* GetEmbedderHeapTracer(); + + /** + * Use for |AtomicsWaitCallback| to indicate the type of event it receives. + */ + enum class AtomicsWaitEvent { + /** Indicates that this call is happening before waiting. */ + kStartWait, + /** `Atomics.wait()` finished because of an `Atomics.wake()` call. */ + kWokenUp, + /** `Atomics.wait()` finished because it timed out. */ + kTimedOut, + /** `Atomics.wait()` was interrupted through |TerminateExecution()|. */ + kTerminatedExecution, + /** `Atomics.wait()` was stopped through |AtomicsWaitWakeHandle|. */ + kAPIStopped, + /** `Atomics.wait()` did not wait, as the initial condition was not met. */ + kNotEqual + }; + + /** + * Passed to |AtomicsWaitCallback| as a means of stopping an ongoing + * `Atomics.wait` call. + */ + class V8_EXPORT AtomicsWaitWakeHandle { + public: + /** + * Stop this `Atomics.wait()` call and call the |AtomicsWaitCallback| + * with |kAPIStopped|. + * + * This function may be called from another thread. The caller has to ensure + * through proper synchronization that it is not called after + * the finishing |AtomicsWaitCallback|. + * + * Note that the ECMAScript specification does not plan for the possibility + * of wakeups that are neither coming from a timeout or an `Atomics.wake()` + * call, so this may invalidate assumptions made by existing code. + * The embedder may accordingly wish to schedule an exception in the + * finishing |AtomicsWaitCallback|. + */ + void Wake(); + }; + + /** + * Embedder callback for `Atomics.wait()` that can be added through + * |SetAtomicsWaitCallback|. + * + * This will be called just before starting to wait with the |event| value + * |kStartWait| and after finishing waiting with one of the other + * values of |AtomicsWaitEvent| inside of an `Atomics.wait()` call. + * + * |array_buffer| will refer to the underlying SharedArrayBuffer, + * |offset_in_bytes| to the location of the waited-on memory address inside + * the SharedArrayBuffer. + * + * |value| and |timeout_in_ms| will be the values passed to + * the `Atomics.wait()` call. If no timeout was used, |timeout_in_ms| + * will be `INFINITY`. + * + * In the |kStartWait| callback, |stop_handle| will be an object that + * is only valid until the corresponding finishing callback and that + * can be used to stop the wait process while it is happening. + * + * This callback may schedule exceptions, *unless* |event| is equal to + * |kTerminatedExecution|. + */ + typedef void (*AtomicsWaitCallback)(AtomicsWaitEvent event, + Local<SharedArrayBuffer> array_buffer, + size_t offset_in_bytes, int64_t value, + double timeout_in_ms, + AtomicsWaitWakeHandle* stop_handle, + void* data); + + /** + * Set a new |AtomicsWaitCallback|. This overrides an earlier + * |AtomicsWaitCallback|, if there was any. If |callback| is nullptr, + * this unsets the callback. |data| will be passed to the callback + * as its last parameter. + */ + void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data); + + /** + * Enables the host application to receive a notification after a + * garbage collection. Allocations are allowed in the callback function, + * but the callback is not re-entrant: if the allocation inside it will + * trigger the garbage collection, the callback won't be called again. + * It is possible to specify the GCType filter for your callback. But it is + * not possible to register the same callback function two times with + * different GCType filters. + */ + void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr, + GCType gc_type_filter = kGCTypeAll); + void AddGCEpilogueCallback(GCCallback callback, + GCType gc_type_filter = kGCTypeAll); + + /** + * This function removes callback which was installed by + * AddGCEpilogueCallback function. + */ + void RemoveGCEpilogueCallback(GCCallbackWithData callback, + void* data = nullptr); + void RemoveGCEpilogueCallback(GCCallback callback); + + typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)(); + + /** + * Set the callback that tells V8 how much memory is currently allocated + * externally of the V8 heap. Ideally this memory is somehow connected to V8 + * objects and may get freed-up when the corresponding V8 objects get + * collected by a V8 garbage collection. + */ + void SetGetExternallyAllocatedMemoryInBytesCallback( + GetExternallyAllocatedMemoryInBytesCallback callback); + + /** + * Forcefully terminate the current thread of JavaScript execution + * in the given isolate. + * + * This method can be used by any thread even if that thread has not + * acquired the V8 lock with a Locker object. + */ + void TerminateExecution(); + + /** + * Is V8 terminating JavaScript execution. + * + * Returns true if JavaScript execution is currently terminating + * because of a call to TerminateExecution. In that case there are + * still JavaScript frames on the stack and the termination + * exception is still active. + */ + bool IsExecutionTerminating(); + + /** + * Resume execution capability in the given isolate, whose execution + * was previously forcefully terminated using TerminateExecution(). + * + * When execution is forcefully terminated using TerminateExecution(), + * the isolate can not resume execution until all JavaScript frames + * have propagated the uncatchable exception which is generated. This + * method allows the program embedding the engine to handle the + * termination event and resume execution capability, even if + * JavaScript frames remain on the stack. + * + * This method can be used by any thread even if that thread has not + * acquired the V8 lock with a Locker object. + */ + void CancelTerminateExecution(); + + /** + * Request V8 to interrupt long running JavaScript code and invoke + * the given |callback| passing the given |data| to it. After |callback| + * returns control will be returned to the JavaScript code. + * There may be a number of interrupt requests in flight. + * Can be called from another thread without acquiring a |Locker|. + * Registered |callback| must not reenter interrupted Isolate. + */ + void RequestInterrupt(InterruptCallback callback, void* data); + + /** + * Request garbage collection in this Isolate. It is only valid to call this + * function if --expose_gc was specified. + * + * This should only be used for testing purposes and not to enforce a garbage + * collection schedule. It has strong negative impact on the garbage + * collection performance. Use IdleNotificationDeadline() or + * LowMemoryNotification() instead to influence the garbage collection + * schedule. + */ + void RequestGarbageCollectionForTesting(GarbageCollectionType type); + + /** + * Set the callback to invoke for logging event. + */ + void SetEventLogger(LogEventCallback that); + + /** + * Adds a callback to notify the host application right before a script + * is about to run. If a script re-enters the runtime during executing, the + * BeforeCallEnteredCallback is invoked for each re-entrance. + * Executing scripts inside the callback will re-trigger the callback. + */ + void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback); + + /** + * Removes callback that was installed by AddBeforeCallEnteredCallback. + */ + void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback); + + /** + * Adds a callback to notify the host application when a script finished + * running. If a script re-enters the runtime during executing, the + * CallCompletedCallback is only invoked when the outer-most script + * execution ends. Executing scripts inside the callback do not trigger + * further callbacks. + */ + void AddCallCompletedCallback(CallCompletedCallback callback); + + /** + * Removes callback that was installed by AddCallCompletedCallback. + */ + void RemoveCallCompletedCallback(CallCompletedCallback callback); + + /** + * Set the PromiseHook callback for various promise lifecycle + * events. + */ + void SetPromiseHook(PromiseHook hook); + + /** + * Set callback to notify about promise reject with no handler, or + * revocation of such a previous notification once the handler is added. + */ + void SetPromiseRejectCallback(PromiseRejectCallback callback); + + /** + * Runs the default MicrotaskQueue until it gets empty. + * Any exceptions thrown by microtask callbacks are swallowed. + */ + void RunMicrotasks(); + + /** + * Enqueues the callback to the default MicrotaskQueue + */ + void EnqueueMicrotask(Local<Function> microtask); + + /** + * Enqueues the callback to the default MicrotaskQueue + */ + void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr); + + /** + * Controls how Microtasks are invoked. See MicrotasksPolicy for details. + */ + void SetMicrotasksPolicy(MicrotasksPolicy policy); + + /** + * Returns the policy controlling how Microtasks are invoked. + */ + MicrotasksPolicy GetMicrotasksPolicy() const; + + /** + * Adds a callback to notify the host application after + * microtasks were run on the default MicrotaskQueue. The callback is + * triggered by explicit RunMicrotasks call or automatic microtasks execution + * (see SetMicrotaskPolicy). + * + * Callback will trigger even if microtasks were attempted to run, + * but the microtasks queue was empty and no single microtask was actually + * executed. + * + * Executing scripts inside the callback will not re-trigger microtasks and + * the callback. + */ + V8_DEPRECATE_SOON("Use *WithData version.", + void AddMicrotasksCompletedCallback( + MicrotasksCompletedCallback callback)); + void AddMicrotasksCompletedCallback( + MicrotasksCompletedCallbackWithData callback, void* data = nullptr); + + /** + * Removes callback that was installed by AddMicrotasksCompletedCallback. + */ + V8_DEPRECATE_SOON("Use *WithData version.", + void RemoveMicrotasksCompletedCallback( + MicrotasksCompletedCallback callback)); + void RemoveMicrotasksCompletedCallback( + MicrotasksCompletedCallbackWithData callback, void* data = nullptr); + + /** + * Sets a callback for counting the number of times a feature of V8 is used. + */ + void SetUseCounterCallback(UseCounterCallback callback); + + /** + * Enables the host application to provide a mechanism for recording + * statistics counters. + */ + void SetCounterFunction(CounterLookupCallback); + + /** + * Enables the host application to provide a mechanism for recording + * histograms. The CreateHistogram function returns a + * histogram which will later be passed to the AddHistogramSample + * function. + */ + void SetCreateHistogramFunction(CreateHistogramCallback); + void SetAddHistogramSampleFunction(AddHistogramSampleCallback); + + /** + * Optional notification that the embedder is idle. + * V8 uses the notification to perform garbage collection. + * This call can be used repeatedly if the embedder remains idle. + * Returns true if the embedder should stop calling IdleNotificationDeadline + * until real work has been done. This indicates that V8 has done + * as much cleanup as it will be able to do. + * + * The deadline_in_seconds argument specifies the deadline V8 has to finish + * garbage collection work. deadline_in_seconds is compared with + * MonotonicallyIncreasingTime() and should be based on the same timebase as + * that function. There is no guarantee that the actual work will be done + * within the time limit. + */ + bool IdleNotificationDeadline(double deadline_in_seconds); + + /** + * Optional notification that the system is running low on memory. + * V8 uses these notifications to attempt to free memory. + */ + void LowMemoryNotification(); + + /** + * Optional notification that a context has been disposed. V8 uses + * these notifications to guide the GC heuristic. Returns the number + * of context disposals - including this one - since the last time + * V8 had a chance to clean up. + * + * The optional parameter |dependant_context| specifies whether the disposed + * context was depending on state from other contexts or not. + */ + int ContextDisposedNotification(bool dependant_context = true); + + /** + * Optional notification that the isolate switched to the foreground. + * V8 uses these notifications to guide heuristics. + */ + void IsolateInForegroundNotification(); + + /** + * Optional notification that the isolate switched to the background. + * V8 uses these notifications to guide heuristics. + */ + void IsolateInBackgroundNotification(); + + /** + * Optional notification which will enable the memory savings mode. + * V8 uses this notification to guide heuristics which may result in a + * smaller memory footprint at the cost of reduced runtime performance. + */ + void EnableMemorySavingsMode(); + + /** + * Optional notification which will disable the memory savings mode. + */ + void DisableMemorySavingsMode(); + + /** + * Optional notification to tell V8 the current performance requirements + * of the embedder based on RAIL. + * V8 uses these notifications to guide heuristics. + * This is an unfinished experimental feature. Semantics and implementation + * may change frequently. + */ + void SetRAILMode(RAILMode rail_mode); + + /** + * Optional notification to tell V8 the current isolate is used for debugging + * and requires higher heap limit. + */ + void IncreaseHeapLimitForDebugging(); + + /** + * Restores the original heap limit after IncreaseHeapLimitForDebugging(). + */ + void RestoreOriginalHeapLimit(); + + /** + * Returns true if the heap limit was increased for debugging and the + * original heap limit was not restored yet. + */ + bool IsHeapLimitIncreasedForDebugging(); + + /** + * Allows the host application to provide the address of a function that is + * notified each time code is added, moved or removed. + * + * \param options options for the JIT code event handler. + * \param event_handler the JIT code event handler, which will be invoked + * each time code is added, moved or removed. + * \note \p event_handler won't get notified of existent code. + * \note since code removal notifications are not currently issued, the + * \p event_handler may get notifications of code that overlaps earlier + * code notifications. This happens when code areas are reused, and the + * earlier overlapping code areas should therefore be discarded. + * \note the events passed to \p event_handler and the strings they point to + * are not guaranteed to live past each call. The \p event_handler must + * copy strings and other parameters it needs to keep around. + * \note the set of events declared in JitCodeEvent::EventType is expected to + * grow over time, and the JitCodeEvent structure is expected to accrue + * new members. The \p event_handler function must ignore event codes + * it does not recognize to maintain future compatibility. + * \note Use Isolate::CreateParams to get events for code executed during + * Isolate setup. + */ + void SetJitCodeEventHandler(JitCodeEventOptions options, + JitCodeEventHandler event_handler); + + /** + * Modifies the stack limit for this Isolate. + * + * \param stack_limit An address beyond which the Vm's stack may not grow. + * + * \note If you are using threads then you should hold the V8::Locker lock + * while setting the stack limit and you must set a non-default stack + * limit separately for each thread. + */ + void SetStackLimit(uintptr_t stack_limit); + + /** + * Returns a memory range that can potentially contain jitted code. Code for + * V8's 'builtins' will not be in this range if embedded builtins is enabled. + * + * On Win64, embedders are advised to install function table callbacks for + * these ranges, as default SEH won't be able to unwind through jitted code. + * The first page of the code range is reserved for the embedder and is + * committed, writable, and executable, to be used to store unwind data, as + * documented in + * https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64. + * + * Might be empty on other platforms. + * + * https://code.google.com/p/v8/issues/detail?id=3598 + */ + void GetCodeRange(void** start, size_t* length_in_bytes); + + /** + * Returns the UnwindState necessary for use with the Unwinder API. + */ + UnwindState GetUnwindState(); + + /** Set the callback to invoke in case of fatal errors. */ + void SetFatalErrorHandler(FatalErrorCallback that); + + /** Set the callback to invoke in case of OOM errors. */ + void SetOOMErrorHandler(OOMErrorCallback that); + + /** + * Add a callback to invoke in case the heap size is close to the heap limit. + * If multiple callbacks are added, only the most recently added callback is + * invoked. + */ + void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data); + + /** + * Remove the given callback and restore the heap limit to the + * given limit. If the given limit is zero, then it is ignored. + * If the current heap size is greater than the given limit, + * then the heap limit is restored to the minimal limit that + * is possible for the current heap size. + */ + void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback, + size_t heap_limit); + + /** + * If the heap limit was changed by the NearHeapLimitCallback, then the + * initial heap limit will be restored once the heap size falls below the + * given threshold percentage of the initial heap limit. + * The threshold percentage is a number in (0.0, 1.0) range. + */ + void AutomaticallyRestoreInitialHeapLimit(double threshold_percent = 0.5); + + /** + * Set the callback to invoke to check if code generation from + * strings should be allowed. + */ + void SetAllowCodeGenerationFromStringsCallback( + AllowCodeGenerationFromStringsCallback callback); + + /** + * Set the callback to invoke to check if wasm code generation should + * be allowed. + */ + void SetAllowWasmCodeGenerationCallback( + AllowWasmCodeGenerationCallback callback); + + /** + * Embedder over{ride|load} injection points for wasm APIs. The expectation + * is that the embedder sets them at most once. + */ + void SetWasmModuleCallback(ExtensionCallback callback); + void SetWasmInstanceCallback(ExtensionCallback callback); + + void SetWasmStreamingCallback(WasmStreamingCallback callback); + + void SetWasmThreadsEnabledCallback(WasmThreadsEnabledCallback callback); + + /** + * Check if V8 is dead and therefore unusable. This is the case after + * fatal errors such as out-of-memory situations. + */ + bool IsDead(); + + /** + * Adds a message listener (errors only). + * + * The same message listener can be added more than once and in that + * case it will be called more than once for each message. + * + * If data is specified, it will be passed to the callback when it is called. + * Otherwise, the exception object will be passed to the callback instead. + */ + bool AddMessageListener(MessageCallback that, + Local<Value> data = Local<Value>()); + + /** + * Adds a message listener. + * + * The same message listener can be added more than once and in that + * case it will be called more than once for each message. + * + * If data is specified, it will be passed to the callback when it is called. + * Otherwise, the exception object will be passed to the callback instead. + * + * A listener can listen for particular error levels by providing a mask. + */ + bool AddMessageListenerWithErrorLevel(MessageCallback that, + int message_levels, + Local<Value> data = Local<Value>()); + + /** + * Remove all message listeners from the specified callback function. + */ + void RemoveMessageListeners(MessageCallback that); + + /** Callback function for reporting failed access checks.*/ + void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); + + /** + * Tells V8 to capture current stack trace when uncaught exception occurs + * and report it to the message listeners. The option is off by default. + */ + void SetCaptureStackTraceForUncaughtExceptions( + bool capture, int frame_limit = 10, + StackTrace::StackTraceOptions options = StackTrace::kOverview); + + /** + * Iterates through all external resources referenced from current isolate + * heap. GC is not invoked prior to iterating, therefore there is no + * guarantee that visited objects are still alive. + */ + void VisitExternalResources(ExternalResourceVisitor* visitor); + + /** + * Iterates through all the persistent handles in the current isolate's heap + * that have class_ids. + */ + void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); + + /** + * Iterates through all the persistent handles in the current isolate's heap + * that have class_ids and are weak to be marked as inactive if there is no + * pending activity for the handle. + */ + void VisitWeakHandles(PersistentHandleVisitor* visitor); + + /** + * Check if this isolate is in use. + * True if at least one thread Enter'ed this isolate. + */ + bool IsInUse(); + + /** + * Set whether calling Atomics.wait (a function that may block) is allowed in + * this isolate. This can also be configured via + * CreateParams::allow_atomics_wait. + */ + void SetAllowAtomicsWait(bool allow); + + /** + * Time zone redetection indicator for + * DateTimeConfigurationChangeNotification. + * + * kSkip indicates V8 that the notification should not trigger redetecting + * host time zone. kRedetect indicates V8 that host time zone should be + * redetected, and used to set the default time zone. + * + * The host time zone detection may require file system access or similar + * operations unlikely to be available inside a sandbox. If v8 is run inside a + * sandbox, the host time zone has to be detected outside the sandbox before + * calling DateTimeConfigurationChangeNotification function. + */ + enum class TimeZoneDetection { kSkip, kRedetect }; + + /** + * Notification that the embedder has changed the time zone, daylight savings + * time or other date / time configuration parameters. V8 keeps a cache of + * various values used for date / time computation. This notification will + * reset those cached values for the current context so that date / time + * configuration changes would be reflected. + * + * This API should not be called more than needed as it will negatively impact + * the performance of date operations. + */ + void DateTimeConfigurationChangeNotification( + TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip); + + /** + * Notification that the embedder has changed the locale. V8 keeps a cache of + * various values used for locale computation. This notification will reset + * those cached values for the current context so that locale configuration + * changes would be reflected. + * + * This API should not be called more than needed as it will negatively impact + * the performance of locale operations. + */ + void LocaleConfigurationChangeNotification(); + + Isolate() = delete; + ~Isolate() = delete; + Isolate(const Isolate&) = delete; + Isolate& operator=(const Isolate&) = delete; + // Deleting operator new and delete here is allowed as ctor and dtor is also + // deleted. + void* operator new(size_t size) = delete; + void* operator new[](size_t size) = delete; + void operator delete(void*, size_t) = delete; + void operator delete[](void*, size_t) = delete; + + private: + template <class K, class V, class Traits> + friend class PersistentValueMapBase; + + internal::Address* GetDataFromSnapshotOnce(size_t index); + void ReportExternalAllocationLimitReached(); + void CheckMemoryPressure(); +}; + +class V8_EXPORT StartupData { + public: + const char* data; + int raw_size; +}; + + +/** + * EntropySource is used as a callback function when v8 needs a source + * of entropy. + */ +typedef bool (*EntropySource)(unsigned char* buffer, size_t length); + +/** + * ReturnAddressLocationResolver is used as a callback function when v8 is + * resolving the location of a return address on the stack. Profilers that + * change the return address on the stack can use this to resolve the stack + * location to wherever the profiler stashed the original return address. + * + * \param return_addr_location A location on stack where a machine + * return address resides. + * \returns Either return_addr_location, or else a pointer to the profiler's + * copy of the original return address. + * + * \note The resolver function must not cause garbage collection. + */ +typedef uintptr_t (*ReturnAddressLocationResolver)( + uintptr_t return_addr_location); + + +/** + * Container class for static utility functions. + */ +class V8_EXPORT V8 { + public: + /** + * Hand startup data to V8, in case the embedder has chosen to build + * V8 with external startup data. + * + * Note: + * - By default the startup data is linked into the V8 library, in which + * case this function is not meaningful. + * - If this needs to be called, it needs to be called before V8 + * tries to make use of its built-ins. + * - To avoid unnecessary copies of data, V8 will point directly into the + * given data blob, so pretty please keep it around until V8 exit. + * - Compression of the startup blob might be useful, but needs to + * handled entirely on the embedders' side. + * - The call will abort if the data is invalid. + */ + static void SetNativesDataBlob(StartupData* startup_blob); + static void SetSnapshotDataBlob(StartupData* startup_blob); + + /** Set the callback to invoke in case of Dcheck failures. */ + static void SetDcheckErrorHandler(DcheckErrorCallback that); + + + /** + * Sets V8 flags from a string. + */ + static void SetFlagsFromString(const char* str, int length); + + /** + * Sets V8 flags from the command line. + */ + static void SetFlagsFromCommandLine(int* argc, + char** argv, + bool remove_flags); + + /** Get the version string. */ + static const char* GetVersion(); + + /** + * Initializes V8. This function needs to be called before the first Isolate + * is created. It always returns true. + */ + static bool Initialize(); + + /** + * Allows the host application to provide a callback which can be used + * as a source of entropy for random number generators. + */ + static void SetEntropySource(EntropySource source); + + /** + * Allows the host application to provide a callback that allows v8 to + * cooperate with a profiler that rewrites return addresses on stack. + */ + static void SetReturnAddressLocationResolver( + ReturnAddressLocationResolver return_address_resolver); + + /** + * Releases any resources used by v8 and stops any utility threads + * that may be running. Note that disposing v8 is permanent, it + * cannot be reinitialized. + * + * It should generally not be necessary to dispose v8 before exiting + * a process, this should happen automatically. It is only necessary + * to use if the process needs the resources taken up by v8. + */ + static bool Dispose(); + + /** + * Initialize the ICU library bundled with V8. The embedder should only + * invoke this method when using the bundled ICU. Returns true on success. + * + * If V8 was compiled with the ICU data in an external file, the location + * of the data file has to be provided. + */ + static bool InitializeICU(const char* icu_data_file = nullptr); + + /** + * Initialize the ICU library bundled with V8. The embedder should only + * invoke this method when using the bundled ICU. If V8 was compiled with + * the ICU data in an external file and when the default location of that + * file should be used, a path to the executable must be provided. + * Returns true on success. + * + * The default is a file called icudtl.dat side-by-side with the executable. + * + * Optionally, the location of the data file can be provided to override the + * default. + */ + static bool InitializeICUDefaultLocation(const char* exec_path, + const char* icu_data_file = nullptr); + + /** + * Initialize the external startup data. The embedder only needs to + * invoke this method when external startup data was enabled in a build. + * + * If V8 was compiled with the startup data in an external file, then + * V8 needs to be given those external files during startup. There are + * three ways to do this: + * - InitializeExternalStartupData(const char*) + * This will look in the given directory for files "natives_blob.bin" + * and "snapshot_blob.bin" - which is what the default build calls them. + * - InitializeExternalStartupData(const char*, const char*) + * As above, but will directly use the two given file names. + * - Call SetNativesDataBlob, SetNativesDataBlob. + * This will read the blobs from the given data structures and will + * not perform any file IO. + */ + static void InitializeExternalStartupData(const char* directory_path); + static void InitializeExternalStartupData(const char* natives_blob, + const char* snapshot_blob); + /** + * Sets the v8::Platform to use. This should be invoked before V8 is + * initialized. + */ + static void InitializePlatform(Platform* platform); + + /** + * Clears all references to the v8::Platform. This should be invoked after + * V8 was disposed. + */ + static void ShutdownPlatform(); + +#if V8_OS_POSIX + /** + * Give the V8 signal handler a chance to handle a fault. + * + * This function determines whether a memory access violation can be recovered + * by V8. If so, it will return true and modify context to return to a code + * fragment that can recover from the fault. Otherwise, TryHandleSignal will + * return false. + * + * The parameters to this function correspond to those passed to a Linux + * signal handler. + * + * \param signal_number The signal number. + * + * \param info A pointer to the siginfo_t structure provided to the signal + * handler. + * + * \param context The third argument passed to the Linux signal handler, which + * points to a ucontext_t structure. + */ + V8_DEPRECATE_SOON("Use TryHandleWebAssemblyTrapPosix", + static bool TryHandleSignal(int signal_number, void* info, + void* context)); +#endif // V8_OS_POSIX + + /** + * Activate trap-based bounds checking for WebAssembly. + * + * \param use_v8_signal_handler Whether V8 should install its own signal + * handler or rely on the embedder's. + */ + static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler); + +#if defined(V8_OS_WIN) + /** + * On Win64, by default V8 does not emit unwinding data for jitted code, + * which means the OS cannot walk the stack frames and the system Structured + * Exception Handling (SEH) cannot unwind through V8-generated code: + * https://code.google.com/p/v8/issues/detail?id=3598. + * + * This function allows embedders to register a custom exception handler for + * exceptions in V8-generated code. + */ + static void SetUnhandledExceptionCallback( + UnhandledExceptionCallback unhandled_exception_callback); +#endif + + private: + V8(); + + static internal::Address* GlobalizeReference(internal::Isolate* isolate, + internal::Address* handle); + static internal::Address* GlobalizeTracedReference(internal::Isolate* isolate, + internal::Address* handle, + internal::Address* slot); + static void MoveGlobalReference(internal::Address** from, + internal::Address** to); + static void MoveTracedGlobalReference(internal::Address** from, + internal::Address** to); + static internal::Address* CopyGlobalReference(internal::Address* from); + static void DisposeGlobal(internal::Address* global_handle); + static void DisposeTracedGlobal(internal::Address* global_handle); + static void MakeWeak(internal::Address* location, void* data, + WeakCallbackInfo<void>::Callback weak_callback, + WeakCallbackType type); + static void MakeWeak(internal::Address** location_addr); + static void* ClearWeak(internal::Address* location); + static void SetFinalizationCallbackTraced( + internal::Address* location, void* parameter, + WeakCallbackInfo<void>::Callback callback); + static void AnnotateStrongRetainer(internal::Address* location, + const char* label); + static Value* Eternalize(Isolate* isolate, Value* handle); + + static void RegisterExternallyReferencedObject(internal::Address* location, + internal::Isolate* isolate); + + template <class K, class V, class T> + friend class PersistentValueMapBase; + + static void FromJustIsNothing(); + static void ToLocalEmpty(); + static void InternalFieldOutOfBounds(int index); + template <class T> + friend class Global; + template <class T> friend class Local; + template <class T> + friend class MaybeLocal; + template <class T> + friend class Maybe; + template <class T> + friend class TracedGlobal; + template <class T> + friend class WeakCallbackInfo; + template <class T> friend class Eternal; + template <class T> friend class PersistentBase; + template <class T, class M> friend class Persistent; + friend class Context; +}; + +/** + * Helper class to create a snapshot data blob. + */ +class V8_EXPORT SnapshotCreator { + public: + enum class FunctionCodeHandling { kClear, kKeep }; + + /** + * Initialize and enter an isolate, and set it up for serialization. + * The isolate is either created from scratch or from an existing snapshot. + * The caller keeps ownership of the argument snapshot. + * \param existing_blob existing snapshot from which to create this one. + * \param external_references a null-terminated array of external references + * that must be equivalent to CreateParams::external_references. + */ + SnapshotCreator(Isolate* isolate, + const intptr_t* external_references = nullptr, + StartupData* existing_blob = nullptr); + + /** + * Create and enter an isolate, and set it up for serialization. + * The isolate is either created from scratch or from an existing snapshot. + * The caller keeps ownership of the argument snapshot. + * \param existing_blob existing snapshot from which to create this one. + * \param external_references a null-terminated array of external references + * that must be equivalent to CreateParams::external_references. + */ + SnapshotCreator(const intptr_t* external_references = nullptr, + StartupData* existing_blob = nullptr); + + ~SnapshotCreator(); + + /** + * \returns the isolate prepared by the snapshot creator. + */ + Isolate* GetIsolate(); + + /** + * Set the default context to be included in the snapshot blob. + * The snapshot will not contain the global proxy, and we expect one or a + * global object template to create one, to be provided upon deserialization. + * + * \param callback optional callback to serialize internal fields. + */ + void SetDefaultContext(Local<Context> context, + SerializeInternalFieldsCallback callback = + SerializeInternalFieldsCallback()); + + /** + * Add additional context to be included in the snapshot blob. + * The snapshot will include the global proxy. + * + * \param callback optional callback to serialize internal fields. + * + * \returns the index of the context in the snapshot blob. + */ + size_t AddContext(Local<Context> context, + SerializeInternalFieldsCallback callback = + SerializeInternalFieldsCallback()); + + /** + * Add a template to be included in the snapshot blob. + * \returns the index of the template in the snapshot blob. + */ + size_t AddTemplate(Local<Template> template_obj); + + /** + * Attach arbitrary V8::Data to the context snapshot, which can be retrieved + * via Context::GetDataFromSnapshot after deserialization. This data does not + * survive when a new snapshot is created from an existing snapshot. + * \returns the index for retrieval. + */ + template <class T> + V8_INLINE size_t AddData(Local<Context> context, Local<T> object); + + /** + * Attach arbitrary V8::Data to the isolate snapshot, which can be retrieved + * via Isolate::GetDataFromSnapshot after deserialization. This data does not + * survive when a new snapshot is created from an existing snapshot. + * \returns the index for retrieval. + */ + template <class T> + V8_INLINE size_t AddData(Local<T> object); + + /** + * Created a snapshot data blob. + * This must not be called from within a handle scope. + * \param function_code_handling whether to include compiled function code + * in the snapshot. + * \returns { nullptr, 0 } on failure, and a startup snapshot on success. The + * caller acquires ownership of the data array in the return value. + */ + StartupData CreateBlob(FunctionCodeHandling function_code_handling); + + // Disallow copying and assigning. + SnapshotCreator(const SnapshotCreator&) = delete; + void operator=(const SnapshotCreator&) = delete; + + private: + size_t AddData(Local<Context> context, internal::Address object); + size_t AddData(internal::Address object); + + void* data_; +}; + +/** + * A simple Maybe type, representing an object which may or may not have a + * value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html. + * + * If an API method returns a Maybe<>, the API method can potentially fail + * either because an exception is thrown, or because an exception is pending, + * e.g. because a previous API call threw an exception that hasn't been caught + * yet, or because a TerminateExecution exception was thrown. In that case, a + * "Nothing" value is returned. + */ +template <class T> +class Maybe { + public: + V8_INLINE bool IsNothing() const { return !has_value_; } + V8_INLINE bool IsJust() const { return has_value_; } + + /** + * An alias for |FromJust|. Will crash if the Maybe<> is nothing. + */ + V8_INLINE T ToChecked() const { return FromJust(); } + + /** + * Short-hand for ToChecked(), which doesn't return a value. To be used, where + * the actual value of the Maybe is not needed like Object::Set. + */ + V8_INLINE void Check() const { + if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing(); + } + + /** + * Converts this Maybe<> to a value of type T. If this Maybe<> is + * nothing (empty), |false| is returned and |out| is left untouched. + */ + V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const { + if (V8_LIKELY(IsJust())) *out = value_; + return IsJust(); + } + + /** + * Converts this Maybe<> to a value of type T. If this Maybe<> is + * nothing (empty), V8 will crash the process. + */ + V8_INLINE T FromJust() const { + if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing(); + return value_; + } + + /** + * Converts this Maybe<> to a value of type T, using a default value if this + * Maybe<> is nothing (empty). + */ + V8_INLINE T FromMaybe(const T& default_value) const { + return has_value_ ? value_ : default_value; + } + + V8_INLINE bool operator==(const Maybe& other) const { + return (IsJust() == other.IsJust()) && + (!IsJust() || FromJust() == other.FromJust()); + } + + V8_INLINE bool operator!=(const Maybe& other) const { + return !operator==(other); + } + + private: + Maybe() : has_value_(false) {} + explicit Maybe(const T& t) : has_value_(true), value_(t) {} + + bool has_value_; + T value_; + + template <class U> + friend Maybe<U> Nothing(); + template <class U> + friend Maybe<U> Just(const U& u); +}; + +template <class T> +inline Maybe<T> Nothing() { + return Maybe<T>(); +} + +template <class T> +inline Maybe<T> Just(const T& t) { + return Maybe<T>(t); +} + +// A template specialization of Maybe<T> for the case of T = void. +template <> +class Maybe<void> { + public: + V8_INLINE bool IsNothing() const { return !is_valid_; } + V8_INLINE bool IsJust() const { return is_valid_; } + + V8_INLINE bool operator==(const Maybe& other) const { + return IsJust() == other.IsJust(); + } + + V8_INLINE bool operator!=(const Maybe& other) const { + return !operator==(other); + } + + private: + struct JustTag {}; + + Maybe() : is_valid_(false) {} + explicit Maybe(JustTag) : is_valid_(true) {} + + bool is_valid_; + + template <class U> + friend Maybe<U> Nothing(); + friend Maybe<void> JustVoid(); +}; + +inline Maybe<void> JustVoid() { return Maybe<void>(Maybe<void>::JustTag()); } + +/** + * An external exception handler. + */ +class V8_EXPORT TryCatch { + public: + /** + * Creates a new try/catch block and registers it with v8. Note that + * all TryCatch blocks should be stack allocated because the memory + * location itself is compared against JavaScript try/catch blocks. + */ + explicit TryCatch(Isolate* isolate); + + /** + * Unregisters and deletes this try/catch block. + */ + ~TryCatch(); + + /** + * Returns true if an exception has been caught by this try/catch block. + */ + bool HasCaught() const; + + /** + * For certain types of exceptions, it makes no sense to continue execution. + * + * If CanContinue returns false, the correct action is to perform any C++ + * cleanup needed and then return. If CanContinue returns false and + * HasTerminated returns true, it is possible to call + * CancelTerminateExecution in order to continue calling into the engine. + */ + bool CanContinue() const; + + /** + * Returns true if an exception has been caught due to script execution + * being terminated. + * + * There is no JavaScript representation of an execution termination + * exception. Such exceptions are thrown when the TerminateExecution + * methods are called to terminate a long-running script. + * + * If such an exception has been thrown, HasTerminated will return true, + * indicating that it is possible to call CancelTerminateExecution in order + * to continue calling into the engine. + */ + bool HasTerminated() const; + + /** + * Throws the exception caught by this TryCatch in a way that avoids + * it being caught again by this same TryCatch. As with ThrowException + * it is illegal to execute any JavaScript operations after calling + * ReThrow; the caller must return immediately to where the exception + * is caught. + */ + Local<Value> ReThrow(); + + /** + * Returns the exception caught by this try/catch block. If no exception has + * been caught an empty handle is returned. + * + * The returned handle is valid until this TryCatch block has been destroyed. + */ + Local<Value> Exception() const; + + /** + * Returns the .stack property of the thrown object. If no .stack + * property is present an empty handle is returned. + */ + V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace( + Local<Context> context) const; + + /** + * Returns the message associated with this exception. If there is + * no message associated an empty handle is returned. + * + * The returned handle is valid until this TryCatch block has been + * destroyed. + */ + Local<v8::Message> Message() const; + + /** + * Clears any exceptions that may have been caught by this try/catch block. + * After this method has been called, HasCaught() will return false. Cancels + * the scheduled exception if it is caught and ReThrow() is not called before. + * + * It is not necessary to clear a try/catch block before using it again; if + * another exception is thrown the previously caught exception will just be + * overwritten. However, it is often a good idea since it makes it easier + * to determine which operation threw a given exception. + */ + void Reset(); + + /** + * Set verbosity of the external exception handler. + * + * By default, exceptions that are caught by an external exception + * handler are not reported. Call SetVerbose with true on an + * external exception handler to have exceptions caught by the + * handler reported as if they were not caught. + */ + void SetVerbose(bool value); + + /** + * Returns true if verbosity is enabled. + */ + bool IsVerbose() const; + + /** + * Set whether or not this TryCatch should capture a Message object + * which holds source information about where the exception + * occurred. True by default. + */ + void SetCaptureMessage(bool value); + + /** + * There are cases when the raw address of C++ TryCatch object cannot be + * used for comparisons with addresses into the JS stack. The cases are: + * 1) ARM, ARM64 and MIPS simulators which have separate JS stack. + * 2) Address sanitizer allocates local C++ object in the heap when + * UseAfterReturn mode is enabled. + * This method returns address that can be used for comparisons with + * addresses into the JS stack. When neither simulator nor ASAN's + * UseAfterReturn is enabled, then the address returned will be the address + * of the C++ try catch handler itself. + */ + static void* JSStackComparableAddress(TryCatch* handler) { + if (handler == nullptr) return nullptr; + return handler->js_stack_comparable_address_; + } + + TryCatch(const TryCatch&) = delete; + void operator=(const TryCatch&) = delete; + + private: + // Declaring operator new and delete as deleted is not spec compliant. + // Therefore declare them private instead to disable dynamic alloc + void* operator new(size_t size); + void* operator new[](size_t size); + void operator delete(void*, size_t); + void operator delete[](void*, size_t); + + void ResetInternal(); + + internal::Isolate* isolate_; + TryCatch* next_; + void* exception_; + void* message_obj_; + void* js_stack_comparable_address_; + bool is_verbose_ : 1; + bool can_continue_ : 1; + bool capture_message_ : 1; + bool rethrow_ : 1; + bool has_terminated_ : 1; + + friend class internal::Isolate; +}; + + +// --- Context --- + + +/** + * A container for extension names. + */ +class V8_EXPORT ExtensionConfiguration { + public: + ExtensionConfiguration() : name_count_(0), names_(nullptr) {} + ExtensionConfiguration(int name_count, const char* names[]) + : name_count_(name_count), names_(names) { } + + const char** begin() const { return &names_[0]; } + const char** end() const { return &names_[name_count_]; } + + private: + const int name_count_; + const char** names_; +}; + +/** + * A sandboxed execution context with its own set of built-in objects + * and functions. + */ +class V8_EXPORT Context { + public: + /** + * Returns the global proxy object. + * + * Global proxy object is a thin wrapper whose prototype points to actual + * context's global object with the properties like Object, etc. This is done + * that way for security reasons (for more details see + * https://wiki.mozilla.org/Gecko:SplitWindow). + * + * Please note that changes to global proxy object prototype most probably + * would break VM---v8 expects only global object as a prototype of global + * proxy object. + */ + Local<Object> Global(); + + /** + * Detaches the global object from its context before + * the global object can be reused to create a new context. + */ + void DetachGlobal(); + + /** + * Creates a new context and returns a handle to the newly allocated + * context. + * + * \param isolate The isolate in which to create the context. + * + * \param extensions An optional extension configuration containing + * the extensions to be installed in the newly created context. + * + * \param global_template An optional object template from which the + * global object for the newly created context will be created. + * + * \param global_object An optional global object to be reused for + * the newly created context. This global object must have been + * created by a previous call to Context::New with the same global + * template. The state of the global object will be completely reset + * and only object identify will remain. + */ + static Local<Context> New( + Isolate* isolate, ExtensionConfiguration* extensions = nullptr, + MaybeLocal<ObjectTemplate> global_template = MaybeLocal<ObjectTemplate>(), + MaybeLocal<Value> global_object = MaybeLocal<Value>(), + DeserializeInternalFieldsCallback internal_fields_deserializer = + DeserializeInternalFieldsCallback(), + MicrotaskQueue* microtask_queue = nullptr); + + /** + * Create a new context from a (non-default) context snapshot. There + * is no way to provide a global object template since we do not create + * a new global object from template, but we can reuse a global object. + * + * \param isolate See v8::Context::New. + * + * \param context_snapshot_index The index of the context snapshot to + * deserialize from. Use v8::Context::New for the default snapshot. + * + * \param embedder_fields_deserializer Optional callback to deserialize + * internal fields. It should match the SerializeInternalFieldCallback used + * to serialize. + * + * \param extensions See v8::Context::New. + * + * \param global_object See v8::Context::New. + */ + static MaybeLocal<Context> FromSnapshot( + Isolate* isolate, size_t context_snapshot_index, + DeserializeInternalFieldsCallback embedder_fields_deserializer = + DeserializeInternalFieldsCallback(), + ExtensionConfiguration* extensions = nullptr, + MaybeLocal<Value> global_object = MaybeLocal<Value>(), + MicrotaskQueue* microtask_queue = nullptr); + + /** + * Returns an global object that isn't backed by an actual context. + * + * The global template needs to have access checks with handlers installed. + * If an existing global object is passed in, the global object is detached + * from its context. + * + * Note that this is different from a detached context where all accesses to + * the global proxy will fail. Instead, the access check handlers are invoked. + * + * It is also not possible to detach an object returned by this method. + * Instead, the access check handlers need to return nothing to achieve the + * same effect. + * + * It is possible, however, to create a new context from the global object + * returned by this method. + */ + static MaybeLocal<Object> NewRemoteContext( + Isolate* isolate, Local<ObjectTemplate> global_template, + MaybeLocal<Value> global_object = MaybeLocal<Value>()); + + /** + * Sets the security token for the context. To access an object in + * another context, the security tokens must match. + */ + void SetSecurityToken(Local<Value> token); + + /** Restores the security token to the default value. */ + void UseDefaultSecurityToken(); + + /** Returns the security token of this context.*/ + Local<Value> GetSecurityToken(); + + /** + * Enter this context. After entering a context, all code compiled + * and run is compiled and run in this context. If another context + * is already entered, this old context is saved so it can be + * restored when the new context is exited. + */ + void Enter(); + + /** + * Exit this context. Exiting the current context restores the + * context that was in place when entering the current context. + */ + void Exit(); + + /** Returns an isolate associated with a current context. */ + Isolate* GetIsolate(); + + /** + * The field at kDebugIdIndex used to be reserved for the inspector. + * It now serves no purpose. + */ + enum EmbedderDataFields { kDebugIdIndex = 0 }; + + /** + * Return the number of fields allocated for embedder data. + */ + uint32_t GetNumberOfEmbedderDataFields(); + + /** + * Gets the embedder data with the given index, which must have been set by a + * previous call to SetEmbedderData with the same index. + */ + V8_INLINE Local<Value> GetEmbedderData(int index); + + /** + * Gets the binding object used by V8 extras. Extra natives get a reference + * to this object and can use it to "export" functionality by adding + * properties. Extra natives can also "import" functionality by accessing + * properties added by the embedder using the V8 API. + */ + Local<Object> GetExtrasBindingObject(); + + /** + * Sets the embedder data with the given index, growing the data as + * needed. Note that index 0 currently has a special meaning for Chrome's + * debugger. + */ + void SetEmbedderData(int index, Local<Value> value); + + /** + * Gets a 2-byte-aligned native pointer from the embedder data with the given + * index, which must have been set by a previous call to + * SetAlignedPointerInEmbedderData with the same index. Note that index 0 + * currently has a special meaning for Chrome's debugger. + */ + V8_INLINE void* GetAlignedPointerFromEmbedderData(int index); + + /** + * Sets a 2-byte-aligned native pointer in the embedder data with the given + * index, growing the data as needed. Note that index 0 currently has a + * special meaning for Chrome's debugger. + */ + void SetAlignedPointerInEmbedderData(int index, void* value); + + /** + * Control whether code generation from strings is allowed. Calling + * this method with false will disable 'eval' and the 'Function' + * constructor for code running in this context. If 'eval' or the + * 'Function' constructor are used an exception will be thrown. + * + * If code generation from strings is not allowed the + * V8::AllowCodeGenerationFromStrings callback will be invoked if + * set before blocking the call to 'eval' or the 'Function' + * constructor. If that callback returns true, the call will be + * allowed, otherwise an exception will be thrown. If no callback is + * set an exception will be thrown. + */ + void AllowCodeGenerationFromStrings(bool allow); + + /** + * Returns true if code generation from strings is allowed for the context. + * For more details see AllowCodeGenerationFromStrings(bool) documentation. + */ + bool IsCodeGenerationFromStringsAllowed(); + + /** + * Sets the error description for the exception that is thrown when + * code generation from strings is not allowed and 'eval' or the 'Function' + * constructor are called. + */ + void SetErrorMessageForCodeGenerationFromStrings(Local<String> message); + + /** + * Return data that was previously attached to the context snapshot via + * SnapshotCreator, and removes the reference to it. + * Repeated call with the same index returns an empty MaybeLocal. + */ + template <class T> + V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index); + + /** + * Stack-allocated class which sets the execution context for all + * operations executed within a local scope. + */ + class Scope { + public: + explicit V8_INLINE Scope(Local<Context> context) : context_(context) { + context_->Enter(); + } + V8_INLINE ~Scope() { context_->Exit(); } + + private: + Local<Context> context_; + }; + + /** + * Stack-allocated class to support the backup incumbent settings object + * stack. + * https://html.spec.whatwg.org/multipage/webappapis.html#backup-incumbent-settings-object-stack + */ + class V8_EXPORT BackupIncumbentScope final { + public: + /** + * |backup_incumbent_context| is pushed onto the backup incumbent settings + * object stack. + */ + explicit BackupIncumbentScope(Local<Context> backup_incumbent_context); + ~BackupIncumbentScope(); + + /** + * Returns address that is comparable with JS stack address. Note that JS + * stack may be allocated separately from the native stack. See also + * |TryCatch::JSStackComparableAddress| for details. + */ + uintptr_t JSStackComparableAddress() const { + return js_stack_comparable_address_; + } + + private: + friend class internal::Isolate; + + Local<Context> backup_incumbent_context_; + uintptr_t js_stack_comparable_address_ = 0; + const BackupIncumbentScope* prev_ = nullptr; + }; + + private: + friend class Value; + friend class Script; + friend class Object; + friend class Function; + + internal::Address* GetDataFromSnapshotOnce(size_t index); + Local<Value> SlowGetEmbedderData(int index); + void* SlowGetAlignedPointerFromEmbedderData(int index); +}; + + +/** + * Multiple threads in V8 are allowed, but only one thread at a time is allowed + * to use any given V8 isolate, see the comments in the Isolate class. The + * definition of 'using a V8 isolate' includes accessing handles or holding onto + * object pointers obtained from V8 handles while in the particular V8 isolate. + * It is up to the user of V8 to ensure, perhaps with locking, that this + * constraint is not violated. In addition to any other synchronization + * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be + * used to signal thread switches to V8. + * + * v8::Locker is a scoped lock object. While it's active, i.e. between its + * construction and destruction, the current thread is allowed to use the locked + * isolate. V8 guarantees that an isolate can be locked by at most one thread at + * any time. In other words, the scope of a v8::Locker is a critical section. + * + * Sample usage: +* \code + * ... + * { + * v8::Locker locker(isolate); + * v8::Isolate::Scope isolate_scope(isolate); + * ... + * // Code using V8 and isolate goes here. + * ... + * } // Destructor called here + * \endcode + * + * If you wish to stop using V8 in a thread A you can do this either by + * destroying the v8::Locker object as above or by constructing a v8::Unlocker + * object: + * + * \code + * { + * isolate->Exit(); + * v8::Unlocker unlocker(isolate); + * ... + * // Code not using V8 goes here while V8 can run in another thread. + * ... + * } // Destructor called here. + * isolate->Enter(); + * \endcode + * + * The Unlocker object is intended for use in a long-running callback from V8, + * where you want to release the V8 lock for other threads to use. + * + * The v8::Locker is a recursive lock, i.e. you can lock more than once in a + * given thread. This can be useful if you have code that can be called either + * from code that holds the lock or from code that does not. The Unlocker is + * not recursive so you can not have several Unlockers on the stack at once, and + * you can not use an Unlocker in a thread that is not inside a Locker's scope. + * + * An unlocker will unlock several lockers if it has to and reinstate the + * correct depth of locking on its destruction, e.g.: + * + * \code + * // V8 not locked. + * { + * v8::Locker locker(isolate); + * Isolate::Scope isolate_scope(isolate); + * // V8 locked. + * { + * v8::Locker another_locker(isolate); + * // V8 still locked (2 levels). + * { + * isolate->Exit(); + * v8::Unlocker unlocker(isolate); + * // V8 not locked. + * } + * isolate->Enter(); + * // V8 locked again (2 levels). + * } + * // V8 still locked (1 level). + * } + * // V8 Now no longer locked. + * \endcode + */ +class V8_EXPORT Unlocker { + public: + /** + * Initialize Unlocker for a given Isolate. + */ + V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); } + + ~Unlocker(); + private: + void Initialize(Isolate* isolate); + + internal::Isolate* isolate_; +}; + + +class V8_EXPORT Locker { + public: + /** + * Initialize Locker for a given Isolate. + */ + V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); } + + ~Locker(); + + /** + * Returns whether or not the locker for a given isolate, is locked by the + * current thread. + */ + static bool IsLocked(Isolate* isolate); + + /** + * Returns whether v8::Locker is being used by this V8 instance. + */ + static bool IsActive(); + + // Disallow copying and assigning. + Locker(const Locker&) = delete; + void operator=(const Locker&) = delete; + + private: + void Initialize(Isolate* isolate); + + bool has_lock_; + bool top_level_; + internal::Isolate* isolate_; +}; + +/** + * Various helpers for skipping over V8 frames in a given stack. + * + * The unwinder API is only supported on the x64 architecture. + */ +class V8_EXPORT Unwinder { + public: + /** + * Attempt to unwind the stack to the most recent C++ frame. This function is + * signal-safe and does not access any V8 state and thus doesn't require an + * Isolate. + * + * The unwinder needs to know the location of the JS Entry Stub (a piece of + * code that is run when C++ code calls into generated JS code). This is used + * for edge cases where the current frame is being constructed or torn down + * when the stack sample occurs. + * + * The unwinder also needs the virtual memory range of all possible V8 code + * objects. There are two ranges required - the heap code range and the range + * for code embedded in the binary. The V8 API provides all required inputs + * via an UnwindState object through the Isolate::GetUnwindState() API. These + * values will not change after Isolate initialization, so the same + * |unwind_state| can be used for multiple calls. + * + * \param unwind_state Input state for the Isolate that the stack comes from. + * \param register_state The current registers. This is an in-out param that + * will be overwritten with the register values after unwinding, on success. + * \param stack_base The resulting stack pointer and frame pointer values are + * bounds-checked against the stack_base and the original stack pointer value + * to ensure that they are valid locations in the given stack. If these values + * or any intermediate frame pointer values used during unwinding are ever out + * of these bounds, unwinding will fail. + * + * \return True on success. + */ + static bool TryUnwindV8Frames(const UnwindState& unwind_state, + RegisterState* register_state, + const void* stack_base); + + /** + * Whether the PC is within the V8 code range represented by code_range or + * embedded_code_range in |unwind_state|. + * + * If this returns false, then calling UnwindV8Frames() with the same PC + * and unwind_state will always fail. If it returns true, then unwinding may + * (but not necessarily) be successful. + */ + static bool PCIsInV8(const UnwindState& unwind_state, void* pc); +}; + +// --- Implementation --- + +template <class T> +Local<T> Local<T>::New(Isolate* isolate, Local<T> that) { + return New(isolate, that.val_); +} + +template <class T> +Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) { + return New(isolate, that.val_); +} + +template <class T> +Local<T> Local<T>::New(Isolate* isolate, const TracedGlobal<T>& that) { + return New(isolate, that.val_); +} + +template <class T> +Local<T> Local<T>::New(Isolate* isolate, T* that) { + if (that == nullptr) return Local<T>(); + T* that_ptr = that; + internal::Address* p = reinterpret_cast<internal::Address*>(that_ptr); + return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( + reinterpret_cast<internal::Isolate*>(isolate), *p))); +} + + +template<class T> +template<class S> +void Eternal<T>::Set(Isolate* isolate, Local<S> handle) { + TYPE_CHECK(T, S); + val_ = reinterpret_cast<T*>( + V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle))); +} + +template <class T> +Local<T> Eternal<T>::Get(Isolate* isolate) const { + // The eternal handle will never go away, so as with the roots, we don't even + // need to open a handle. + return Local<T>(val_); +} + + +template <class T> +Local<T> MaybeLocal<T>::ToLocalChecked() { + if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty(); + return Local<T>(val_); +} + + +template <class T> +void* WeakCallbackInfo<T>::GetInternalField(int index) const { +#ifdef V8_ENABLE_CHECKS + if (index < 0 || index >= kEmbedderFieldsInWeakCallback) { + V8::InternalFieldOutOfBounds(index); + } +#endif + return embedder_fields_[index]; +} + + +template <class T> +T* PersistentBase<T>::New(Isolate* isolate, T* that) { + if (that == nullptr) return nullptr; + internal::Address* p = reinterpret_cast<internal::Address*>(that); + return reinterpret_cast<T*>( + V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), + p)); +} + + +template <class T, class M> +template <class S, class M2> +void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { + TYPE_CHECK(T, S); + this->Reset(); + if (that.IsEmpty()) return; + internal::Address* p = reinterpret_cast<internal::Address*>(that.val_); + this->val_ = reinterpret_cast<T*>(V8::CopyGlobalReference(p)); + M::Copy(that, this); +} + +template <class T> +bool PersistentBase<T>::IsIndependent() const { + typedef internal::Internals I; + if (this->IsEmpty()) return false; + return I::GetNodeFlag(reinterpret_cast<internal::Address*>(this->val_), + I::kNodeIsIndependentShift); +} + +template <class T> +bool PersistentBase<T>::IsWeak() const { + typedef internal::Internals I; + if (this->IsEmpty()) return false; + return I::GetNodeState(reinterpret_cast<internal::Address*>(this->val_)) == + I::kNodeStateIsWeakValue; +} + + +template <class T> +void PersistentBase<T>::Reset() { + if (this->IsEmpty()) return; + V8::DisposeGlobal(reinterpret_cast<internal::Address*>(this->val_)); + val_ = nullptr; +} + + +template <class T> +template <class S> +void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) { + TYPE_CHECK(T, S); + Reset(); + if (other.IsEmpty()) return; + this->val_ = New(isolate, other.val_); +} + + +template <class T> +template <class S> +void PersistentBase<T>::Reset(Isolate* isolate, + const PersistentBase<S>& other) { + TYPE_CHECK(T, S); + Reset(); + if (other.IsEmpty()) return; + this->val_ = New(isolate, other.val_); +} + + +template <class T> +template <typename P> +V8_INLINE void PersistentBase<T>::SetWeak( + P* parameter, typename WeakCallbackInfo<P>::Callback callback, + WeakCallbackType type) { + typedef typename WeakCallbackInfo<void>::Callback Callback; + V8::MakeWeak(reinterpret_cast<internal::Address*>(this->val_), parameter, + reinterpret_cast<Callback>(callback), type); +} + +template <class T> +void PersistentBase<T>::SetWeak() { + V8::MakeWeak(reinterpret_cast<internal::Address**>(&this->val_)); +} + +template <class T> +template <typename P> +P* PersistentBase<T>::ClearWeak() { + return reinterpret_cast<P*>( + V8::ClearWeak(reinterpret_cast<internal::Address*>(this->val_))); +} + +template <class T> +void PersistentBase<T>::AnnotateStrongRetainer(const char* label) { + V8::AnnotateStrongRetainer(reinterpret_cast<internal::Address*>(this->val_), + label); +} + +template <class T> +void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const { + if (IsEmpty()) return; + V8::RegisterExternallyReferencedObject( + reinterpret_cast<internal::Address*>(this->val_), + reinterpret_cast<internal::Isolate*>(isolate)); +} + +template <class T> +void PersistentBase<T>::MarkIndependent() { + typedef internal::Internals I; + if (this->IsEmpty()) return; + I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true, + I::kNodeIsIndependentShift); +} + +template <class T> +void PersistentBase<T>::MarkActive() { + typedef internal::Internals I; + if (this->IsEmpty()) return; + I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true, + I::kNodeIsActiveShift); +} + + +template <class T> +void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) { + typedef internal::Internals I; + if (this->IsEmpty()) return; + internal::Address* obj = reinterpret_cast<internal::Address*>(this->val_); + uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; + *reinterpret_cast<uint16_t*>(addr) = class_id; +} + + +template <class T> +uint16_t PersistentBase<T>::WrapperClassId() const { + typedef internal::Internals I; + if (this->IsEmpty()) return 0; + internal::Address* obj = reinterpret_cast<internal::Address*>(this->val_); + uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; + return *reinterpret_cast<uint16_t*>(addr); +} + +template <class T> +Global<T>::Global(Global&& other) : PersistentBase<T>(other.val_) { + if (other.val_ != nullptr) { + V8::MoveGlobalReference(reinterpret_cast<internal::Address**>(&other.val_), + reinterpret_cast<internal::Address**>(&this->val_)); + other.val_ = nullptr; + } +} + +template <class T> +template <class S> +Global<T>& Global<T>::operator=(Global<S>&& rhs) { + TYPE_CHECK(T, S); + if (this != &rhs) { + this->Reset(); + if (rhs.val_ != nullptr) { + this->val_ = rhs.val_; + V8::MoveGlobalReference( + reinterpret_cast<internal::Address**>(&rhs.val_), + reinterpret_cast<internal::Address**>(&this->val_)); + rhs.val_ = nullptr; + } + } + return *this; +} + +template <class T> +T* TracedGlobal<T>::New(Isolate* isolate, T* that, T** slot) { + if (that == nullptr) return nullptr; + internal::Address* p = reinterpret_cast<internal::Address*>(that); + return reinterpret_cast<T*>(V8::GlobalizeTracedReference( + reinterpret_cast<internal::Isolate*>(isolate), p, + reinterpret_cast<internal::Address*>(slot))); +} + +template <class T> +void TracedGlobal<T>::Reset() { + if (IsEmpty()) return; + V8::DisposeTracedGlobal(reinterpret_cast<internal::Address*>(val_)); + val_ = nullptr; +} + +template <class T> +template <class S> +void TracedGlobal<T>::Reset(Isolate* isolate, const Local<S>& other) { + TYPE_CHECK(T, S); + Reset(); + if (other.IsEmpty()) return; + this->val_ = New(isolate, other.val_, &val_); +} + +template <class T> +TracedGlobal<T>::TracedGlobal(TracedGlobal&& other) : val_(other.val_) { + if (other.val_ != nullptr) { + V8::MoveTracedGlobalReference( + reinterpret_cast<internal::Address**>(&other.val_), + reinterpret_cast<internal::Address**>(&this->val_)); + other.val_ = nullptr; + } +} + +template <class T> +template <class S> +TracedGlobal<T>& TracedGlobal<T>::operator=(TracedGlobal<S>&& rhs) { + TYPE_CHECK(T, S); + if (this != &rhs) { + this->Reset(); + if (rhs.val_ != nullptr) { + this->val_ = rhs.val_; + V8::MoveTracedGlobalReference( + reinterpret_cast<internal::Address**>(&rhs.val_), + reinterpret_cast<internal::Address**>(&this->val_)); + rhs.val_ = nullptr; + } + } + return *this; +} + +template <class T> +void TracedGlobal<T>::SetWrapperClassId(uint16_t class_id) { + typedef internal::Internals I; + if (IsEmpty()) return; + internal::Address* obj = reinterpret_cast<internal::Address*>(this->val_); + uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; + *reinterpret_cast<uint16_t*>(addr) = class_id; +} + +template <class T> +uint16_t TracedGlobal<T>::WrapperClassId() const { + typedef internal::Internals I; + if (IsEmpty()) return 0; + internal::Address* obj = reinterpret_cast<internal::Address*>(this->val_); + uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; + return *reinterpret_cast<uint16_t*>(addr); +} + +template <class T> +void TracedGlobal<T>::SetFinalizationCallback( + void* parameter, typename WeakCallbackInfo<void>::Callback callback) { + V8::SetFinalizationCallbackTraced( + reinterpret_cast<internal::Address*>(this->val_), parameter, callback); +} + +template <typename T> +ReturnValue<T>::ReturnValue(internal::Address* slot) : value_(slot) {} + +template<typename T> +template<typename S> +void ReturnValue<T>::Set(const Persistent<S>& handle) { + TYPE_CHECK(T, S); + if (V8_UNLIKELY(handle.IsEmpty())) { + *value_ = GetDefaultValue(); + } else { + *value_ = *reinterpret_cast<internal::Address*>(*handle); + } +} + +template <typename T> +template <typename S> +void ReturnValue<T>::Set(const Global<S>& handle) { + TYPE_CHECK(T, S); + if (V8_UNLIKELY(handle.IsEmpty())) { + *value_ = GetDefaultValue(); + } else { + *value_ = *reinterpret_cast<internal::Address*>(*handle); + } +} + +template <typename T> +template <typename S> +void ReturnValue<T>::Set(const TracedGlobal<S>& handle) { + TYPE_CHECK(T, S); + if (V8_UNLIKELY(handle.IsEmpty())) { + *value_ = GetDefaultValue(); + } else { + *value_ = *reinterpret_cast<internal::Address*>(*handle); + } +} + +template <typename T> +template <typename S> +void ReturnValue<T>::Set(const Local<S> handle) { + TYPE_CHECK(T, S); + if (V8_UNLIKELY(handle.IsEmpty())) { + *value_ = GetDefaultValue(); + } else { + *value_ = *reinterpret_cast<internal::Address*>(*handle); + } +} + +template<typename T> +void ReturnValue<T>::Set(double i) { + TYPE_CHECK(T, Number); + Set(Number::New(GetIsolate(), i)); +} + +template<typename T> +void ReturnValue<T>::Set(int32_t i) { + TYPE_CHECK(T, Integer); + typedef internal::Internals I; + if (V8_LIKELY(I::IsValidSmi(i))) { + *value_ = I::IntToSmi(i); + return; + } + Set(Integer::New(GetIsolate(), i)); +} + +template<typename T> +void ReturnValue<T>::Set(uint32_t i) { + TYPE_CHECK(T, Integer); + // Can't simply use INT32_MAX here for whatever reason. + bool fits_into_int32_t = (i & (1U << 31)) == 0; + if (V8_LIKELY(fits_into_int32_t)) { + Set(static_cast<int32_t>(i)); + return; + } + Set(Integer::NewFromUnsigned(GetIsolate(), i)); +} + +template<typename T> +void ReturnValue<T>::Set(bool value) { + TYPE_CHECK(T, Boolean); + typedef internal::Internals I; + int root_index; + if (value) { + root_index = I::kTrueValueRootIndex; + } else { + root_index = I::kFalseValueRootIndex; + } + *value_ = *I::GetRoot(GetIsolate(), root_index); +} + +template<typename T> +void ReturnValue<T>::SetNull() { + TYPE_CHECK(T, Primitive); + typedef internal::Internals I; + *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex); +} + +template<typename T> +void ReturnValue<T>::SetUndefined() { + TYPE_CHECK(T, Primitive); + typedef internal::Internals I; + *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); +} + +template<typename T> +void ReturnValue<T>::SetEmptyString() { + TYPE_CHECK(T, String); + typedef internal::Internals I; + *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); +} + +template <typename T> +Isolate* ReturnValue<T>::GetIsolate() const { + // Isolate is always the pointer below the default value on the stack. + return *reinterpret_cast<Isolate**>(&value_[-2]); +} + +template <typename T> +Local<Value> ReturnValue<T>::Get() const { + typedef internal::Internals I; + if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex)) + return Local<Value>(*Undefined(GetIsolate())); + return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_)); +} + +template <typename T> +template <typename S> +void ReturnValue<T>::Set(S* whatever) { + // Uncompilable to prevent inadvertent misuse. + TYPE_CHECK(S*, Primitive); +} + +template <typename T> +internal::Address ReturnValue<T>::GetDefaultValue() { + // Default value is always the pointer below value_ on the stack. + return value_[-1]; +} + +template <typename T> +FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Address* implicit_args, + internal::Address* values, + int length) + : implicit_args_(implicit_args), values_(values), length_(length) {} + +template<typename T> +Local<Value> FunctionCallbackInfo<T>::operator[](int i) const { + if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate())); + return Local<Value>(reinterpret_cast<Value*>(values_ - i)); +} + + +template<typename T> +Local<Object> FunctionCallbackInfo<T>::This() const { + return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); +} + + +template<typename T> +Local<Object> FunctionCallbackInfo<T>::Holder() const { + return Local<Object>(reinterpret_cast<Object*>( + &implicit_args_[kHolderIndex])); +} + +template <typename T> +Local<Value> FunctionCallbackInfo<T>::NewTarget() const { + return Local<Value>( + reinterpret_cast<Value*>(&implicit_args_[kNewTargetIndex])); +} + +template <typename T> +Local<Value> FunctionCallbackInfo<T>::Data() const { + return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); +} + + +template<typename T> +Isolate* FunctionCallbackInfo<T>::GetIsolate() const { + return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); +} + + +template<typename T> +ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const { + return ReturnValue<T>(&implicit_args_[kReturnValueIndex]); +} + + +template<typename T> +bool FunctionCallbackInfo<T>::IsConstructCall() const { + return !NewTarget()->IsUndefined(); +} + + +template<typename T> +int FunctionCallbackInfo<T>::Length() const { + return length_; +} + +ScriptOrigin::ScriptOrigin(Local<Value> resource_name, + Local<Integer> resource_line_offset, + Local<Integer> resource_column_offset, + Local<Boolean> resource_is_shared_cross_origin, + Local<Integer> script_id, + Local<Value> source_map_url, + Local<Boolean> resource_is_opaque, + Local<Boolean> is_wasm, Local<Boolean> is_module, + Local<PrimitiveArray> host_defined_options) + : resource_name_(resource_name), + resource_line_offset_(resource_line_offset), + resource_column_offset_(resource_column_offset), + options_(!resource_is_shared_cross_origin.IsEmpty() && + resource_is_shared_cross_origin->IsTrue(), + !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue(), + !is_wasm.IsEmpty() && is_wasm->IsTrue(), + !is_module.IsEmpty() && is_module->IsTrue()), + script_id_(script_id), + source_map_url_(source_map_url), + host_defined_options_(host_defined_options) {} + +Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; } + +Local<PrimitiveArray> ScriptOrigin::HostDefinedOptions() const { + return host_defined_options_; +} + +Local<Integer> ScriptOrigin::ResourceLineOffset() const { + return resource_line_offset_; +} + + +Local<Integer> ScriptOrigin::ResourceColumnOffset() const { + return resource_column_offset_; +} + + +Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; } + + +Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; } + +ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin, + CachedData* data) + : source_string(string), + resource_name(origin.ResourceName()), + resource_line_offset(origin.ResourceLineOffset()), + resource_column_offset(origin.ResourceColumnOffset()), + resource_options(origin.Options()), + source_map_url(origin.SourceMapUrl()), + host_defined_options(origin.HostDefinedOptions()), + cached_data(data) {} + +ScriptCompiler::Source::Source(Local<String> string, + CachedData* data) + : source_string(string), cached_data(data) {} + + +ScriptCompiler::Source::~Source() { + delete cached_data; +} + + +const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData() + const { + return cached_data; +} + +const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const { + return resource_options; +} + +Local<Boolean> Boolean::New(Isolate* isolate, bool value) { + return value ? True(isolate) : False(isolate); +} + +void Template::Set(Isolate* isolate, const char* name, Local<Data> value) { + Set(String::NewFromUtf8(isolate, name, NewStringType::kInternalized) + .ToLocalChecked(), + value); +} + +FunctionTemplate* FunctionTemplate::Cast(Data* data) { +#ifdef V8_ENABLE_CHECKS + CheckCast(data); +#endif + return reinterpret_cast<FunctionTemplate*>(data); +} + +ObjectTemplate* ObjectTemplate::Cast(Data* data) { +#ifdef V8_ENABLE_CHECKS + CheckCast(data); +#endif + return reinterpret_cast<ObjectTemplate*>(data); +} + +Signature* Signature::Cast(Data* data) { +#ifdef V8_ENABLE_CHECKS + CheckCast(data); +#endif + return reinterpret_cast<Signature*>(data); +} + +AccessorSignature* AccessorSignature::Cast(Data* data) { +#ifdef V8_ENABLE_CHECKS + CheckCast(data); +#endif + return reinterpret_cast<AccessorSignature*>(data); +} + +Local<Value> Object::GetInternalField(int index) { +#ifndef V8_ENABLE_CHECKS + typedef internal::Address A; + typedef internal::Internals I; + A obj = *reinterpret_cast<A*>(this); + // Fast path: If the object is a plain JSObject, which is the common case, we + // know where to find the internal fields and can return the value directly. + auto instance_type = I::GetInstanceType(obj); + if (instance_type == I::kJSObjectType || + instance_type == I::kJSApiObjectType || + instance_type == I::kJSSpecialApiObjectType) { + int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index); + A value = I::ReadRawField<A>(obj, offset); +#ifdef V8_COMPRESS_POINTERS + // We read the full pointer value and then decompress it in order to avoid + // dealing with potential endiannes issues. + value = I::DecompressTaggedAnyField(obj, static_cast<int32_t>(value)); +#endif + internal::Isolate* isolate = + internal::IsolateFromNeverReadOnlySpaceObject(obj); + A* result = HandleScope::CreateHandle(isolate, value); + return Local<Value>(reinterpret_cast<Value*>(result)); + } +#endif + return SlowGetInternalField(index); +} + + +void* Object::GetAlignedPointerFromInternalField(int index) { +#ifndef V8_ENABLE_CHECKS + typedef internal::Address A; + typedef internal::Internals I; + A obj = *reinterpret_cast<A*>(this); + // Fast path: If the object is a plain JSObject, which is the common case, we + // know where to find the internal fields and can return the value directly. + auto instance_type = I::GetInstanceType(obj); + if (V8_LIKELY(instance_type == I::kJSObjectType || + instance_type == I::kJSApiObjectType || + instance_type == I::kJSSpecialApiObjectType)) { + int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index); + return I::ReadRawField<void*>(obj, offset); + } +#endif + return SlowGetAlignedPointerFromInternalField(index); +} + +String* String::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<String*>(value); +} + + +Local<String> String::Empty(Isolate* isolate) { + typedef internal::Address S; + typedef internal::Internals I; + I::CheckInitialized(isolate); + S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); + return Local<String>(reinterpret_cast<String*>(slot)); +} + + +String::ExternalStringResource* String::GetExternalStringResource() const { + typedef internal::Address A; + typedef internal::Internals I; + A obj = *reinterpret_cast<const A*>(this); + + ExternalStringResource* result; + if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { + void* value = I::ReadRawField<void*>(obj, I::kStringResourceOffset); + result = reinterpret_cast<String::ExternalStringResource*>(value); + } else { + result = GetExternalStringResourceSlow(); + } +#ifdef V8_ENABLE_CHECKS + VerifyExternalStringResource(result); +#endif + return result; +} + + +String::ExternalStringResourceBase* String::GetExternalStringResourceBase( + String::Encoding* encoding_out) const { + typedef internal::Address A; + typedef internal::Internals I; + A obj = *reinterpret_cast<const A*>(this); + int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; + *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); + ExternalStringResourceBase* resource; + if (type == I::kExternalOneByteRepresentationTag || + type == I::kExternalTwoByteRepresentationTag) { + void* value = I::ReadRawField<void*>(obj, I::kStringResourceOffset); + resource = static_cast<ExternalStringResourceBase*>(value); + } else { + resource = GetExternalStringResourceBaseSlow(encoding_out); + } +#ifdef V8_ENABLE_CHECKS + VerifyExternalStringResourceBase(resource, *encoding_out); +#endif + return resource; +} + + +bool Value::IsUndefined() const { +#ifdef V8_ENABLE_CHECKS + return FullIsUndefined(); +#else + return QuickIsUndefined(); +#endif +} + +bool Value::QuickIsUndefined() const { + typedef internal::Address A; + typedef internal::Internals I; + A obj = *reinterpret_cast<const A*>(this); + if (!I::HasHeapObjectTag(obj)) return false; + if (I::GetInstanceType(obj) != I::kOddballType) return false; + return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); +} + + +bool Value::IsNull() const { +#ifdef V8_ENABLE_CHECKS + return FullIsNull(); +#else + return QuickIsNull(); +#endif +} + +bool Value::QuickIsNull() const { + typedef internal::Address A; + typedef internal::Internals I; + A obj = *reinterpret_cast<const A*>(this); + if (!I::HasHeapObjectTag(obj)) return false; + if (I::GetInstanceType(obj) != I::kOddballType) return false; + return (I::GetOddballKind(obj) == I::kNullOddballKind); +} + +bool Value::IsNullOrUndefined() const { +#ifdef V8_ENABLE_CHECKS + return FullIsNull() || FullIsUndefined(); +#else + return QuickIsNullOrUndefined(); +#endif +} + +bool Value::QuickIsNullOrUndefined() const { + typedef internal::Address A; + typedef internal::Internals I; + A obj = *reinterpret_cast<const A*>(this); + if (!I::HasHeapObjectTag(obj)) return false; + if (I::GetInstanceType(obj) != I::kOddballType) return false; + int kind = I::GetOddballKind(obj); + return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind; +} + +bool Value::IsString() const { +#ifdef V8_ENABLE_CHECKS + return FullIsString(); +#else + return QuickIsString(); +#endif +} + +bool Value::QuickIsString() const { + typedef internal::Address A; + typedef internal::Internals I; + A obj = *reinterpret_cast<const A*>(this); + if (!I::HasHeapObjectTag(obj)) return false; + return (I::GetInstanceType(obj) < I::kFirstNonstringType); +} + + +template <class T> Value* Value::Cast(T* value) { + return static_cast<Value*>(value); +} + + +Boolean* Boolean::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Boolean*>(value); +} + + +Name* Name::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Name*>(value); +} + + +Symbol* Symbol::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Symbol*>(value); +} + + +Private* Private::Cast(Data* data) { +#ifdef V8_ENABLE_CHECKS + CheckCast(data); +#endif + return reinterpret_cast<Private*>(data); +} + + +Number* Number::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Number*>(value); +} + + +Integer* Integer::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Integer*>(value); +} + + +Int32* Int32::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Int32*>(value); +} + + +Uint32* Uint32::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Uint32*>(value); +} + +BigInt* BigInt::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<BigInt*>(value); +} + +Date* Date::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Date*>(value); +} + + +StringObject* StringObject::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<StringObject*>(value); +} + + +SymbolObject* SymbolObject::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<SymbolObject*>(value); +} + + +NumberObject* NumberObject::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<NumberObject*>(value); +} + +BigIntObject* BigIntObject::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<BigIntObject*>(value); +} + +BooleanObject* BooleanObject::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<BooleanObject*>(value); +} + + +RegExp* RegExp::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<RegExp*>(value); +} + + +Object* Object::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Object*>(value); +} + + +Array* Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Array*>(value); +} + + +Map* Map::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Map*>(value); +} + + +Set* Set::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Set*>(value); +} + + +Promise* Promise::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Promise*>(value); +} + + +Proxy* Proxy::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Proxy*>(value); +} + +WasmModuleObject* WasmModuleObject::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<WasmModuleObject*>(value); +} + +Promise::Resolver* Promise::Resolver::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Promise::Resolver*>(value); +} + + +ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<ArrayBuffer*>(value); +} + + +ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<ArrayBufferView*>(value); +} + + +TypedArray* TypedArray::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<TypedArray*>(value); +} + + +Uint8Array* Uint8Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Uint8Array*>(value); +} + + +Int8Array* Int8Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Int8Array*>(value); +} + + +Uint16Array* Uint16Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Uint16Array*>(value); +} + + +Int16Array* Int16Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Int16Array*>(value); +} + + +Uint32Array* Uint32Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Uint32Array*>(value); +} + + +Int32Array* Int32Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Int32Array*>(value); +} + + +Float32Array* Float32Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Float32Array*>(value); +} + + +Float64Array* Float64Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Float64Array*>(value); +} + +BigInt64Array* BigInt64Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<BigInt64Array*>(value); +} + +BigUint64Array* BigUint64Array::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<BigUint64Array*>(value); +} + +Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Uint8ClampedArray*>(value); +} + + +DataView* DataView::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<DataView*>(value); +} + + +SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<SharedArrayBuffer*>(value); +} + + +Function* Function::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Function*>(value); +} + + +External* External::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<External*>(value); +} + + +template<typename T> +Isolate* PropertyCallbackInfo<T>::GetIsolate() const { + return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]); +} + + +template<typename T> +Local<Value> PropertyCallbackInfo<T>::Data() const { + return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex])); +} + + +template<typename T> +Local<Object> PropertyCallbackInfo<T>::This() const { + return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex])); +} + + +template<typename T> +Local<Object> PropertyCallbackInfo<T>::Holder() const { + return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex])); +} + + +template<typename T> +ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const { + return ReturnValue<T>(&args_[kReturnValueIndex]); +} + +template <typename T> +bool PropertyCallbackInfo<T>::ShouldThrowOnError() const { + typedef internal::Internals I; + if (args_[kShouldThrowOnErrorIndex] != + I::IntToSmi(I::kInferShouldThrowMode)) { + return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(I::kDontThrow); + } + return v8::internal::ShouldThrowOnError( + reinterpret_cast<v8::internal::Isolate*>(GetIsolate())); +} + +Local<Primitive> Undefined(Isolate* isolate) { + typedef internal::Address S; + typedef internal::Internals I; + I::CheckInitialized(isolate); + S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); + return Local<Primitive>(reinterpret_cast<Primitive*>(slot)); +} + + +Local<Primitive> Null(Isolate* isolate) { + typedef internal::Address S; + typedef internal::Internals I; + I::CheckInitialized(isolate); + S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); + return Local<Primitive>(reinterpret_cast<Primitive*>(slot)); +} + + +Local<Boolean> True(Isolate* isolate) { + typedef internal::Address S; + typedef internal::Internals I; + I::CheckInitialized(isolate); + S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); + return Local<Boolean>(reinterpret_cast<Boolean*>(slot)); +} + + +Local<Boolean> False(Isolate* isolate) { + typedef internal::Address S; + typedef internal::Internals I; + I::CheckInitialized(isolate); + S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); + return Local<Boolean>(reinterpret_cast<Boolean*>(slot)); +} + + +void Isolate::SetData(uint32_t slot, void* data) { + typedef internal::Internals I; + I::SetEmbedderData(this, slot, data); +} + + +void* Isolate::GetData(uint32_t slot) { + typedef internal::Internals I; + return I::GetEmbedderData(this, slot); +} + + +uint32_t Isolate::GetNumberOfDataSlots() { + typedef internal::Internals I; + return I::kNumIsolateDataSlots; +} + +template <class T> +MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) { + T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index)); + if (data) internal::PerformCastCheck(data); + return Local<T>(data); +} + +int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( + int64_t change_in_bytes) { + typedef internal::Internals I; + constexpr int64_t kMemoryReducerActivationLimit = 32 * 1024 * 1024; + int64_t* external_memory = reinterpret_cast<int64_t*>( + reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset); + int64_t* external_memory_limit = reinterpret_cast<int64_t*>( + reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset); + int64_t* external_memory_at_last_mc = + reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) + + I::kExternalMemoryAtLastMarkCompactOffset); + + // Embedders are weird: we see both over- and underflows here. Perform the + // addition with unsigned types to avoid undefined behavior. + const int64_t amount = + static_cast<int64_t>(static_cast<uint64_t>(change_in_bytes) + + static_cast<uint64_t>(*external_memory)); + *external_memory = amount; + + int64_t allocation_diff_since_last_mc = + *external_memory - *external_memory_at_last_mc; + // Only check memory pressure and potentially trigger GC if the amount of + // external memory increased. + if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) { + CheckMemoryPressure(); + } + + if (change_in_bytes < 0) { + const int64_t lower_limit = *external_memory_limit + change_in_bytes; + if (lower_limit > I::kExternalAllocationSoftLimit) + *external_memory_limit = lower_limit; + } else if (change_in_bytes > 0 && amount > *external_memory_limit) { + ReportExternalAllocationLimitReached(); + } + return *external_memory; +} + +Local<Value> Context::GetEmbedderData(int index) { +#ifndef V8_ENABLE_CHECKS + typedef internal::Address A; + typedef internal::Internals I; + A ctx = *reinterpret_cast<const A*>(this); + A embedder_data = + I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset); + int value_offset = + I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index); + A value = I::ReadRawField<A>(embedder_data, value_offset); +#ifdef V8_COMPRESS_POINTERS + // We read the full pointer value and then decompress it in order to avoid + // dealing with potential endiannes issues. + value = + I::DecompressTaggedAnyField(embedder_data, static_cast<int32_t>(value)); +#endif + internal::Isolate* isolate = internal::IsolateFromNeverReadOnlySpaceObject( + *reinterpret_cast<A*>(this)); + A* result = HandleScope::CreateHandle(isolate, value); + return Local<Value>(reinterpret_cast<Value*>(result)); +#else + return SlowGetEmbedderData(index); +#endif +} + + +void* Context::GetAlignedPointerFromEmbedderData(int index) { +#ifndef V8_ENABLE_CHECKS + typedef internal::Address A; + typedef internal::Internals I; + A ctx = *reinterpret_cast<const A*>(this); + A embedder_data = + I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset); + int value_offset = + I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index); + return I::ReadRawField<void*>(embedder_data, value_offset); +#else + return SlowGetAlignedPointerFromEmbedderData(index); +#endif +} + +template <class T> +MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) { + T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index)); + if (data) internal::PerformCastCheck(data); + return Local<T>(data); +} + +template <class T> +size_t SnapshotCreator::AddData(Local<Context> context, Local<T> object) { + T* object_ptr = *object; + internal::Address* p = reinterpret_cast<internal::Address*>(object_ptr); + return AddData(context, *p); +} + +template <class T> +size_t SnapshotCreator::AddData(Local<T> object) { + T* object_ptr = *object; + internal::Address* p = reinterpret_cast<internal::Address*>(object_ptr); + return AddData(*p); +} + +/** + * \example shell.cc + * A simple shell that takes a list of expressions on the + * command-line and executes them. + */ + + +/** + * \example process.cc + */ + + +} // namespace v8 + + +#undef TYPE_CHECK + + +#endif // INCLUDE_V8_H_ diff --git a/android/x86/include/v8/v8config.h b/android/x86/include/v8/v8config.h new file mode 100755 index 00000000..5ec0480c --- /dev/null +++ b/android/x86/include/v8/v8config.h @@ -0,0 +1,388 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8CONFIG_H_ +#define V8CONFIG_H_ + +// clang-format off + +// Platform headers for feature detection below. +#if defined(__ANDROID__) +# include <sys/cdefs.h> +#elif defined(__APPLE__) +# include <TargetConditionals.h> +#elif defined(__linux__) +# include <features.h> +#endif + + +// This macro allows to test for the version of the GNU C library (or +// a compatible C library that masquerades as glibc). It evaluates to +// 0 if libc is not GNU libc or compatible. +// Use like: +// #if V8_GLIBC_PREREQ(2, 3) +// ... +// #endif +#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define V8_GLIBC_PREREQ(major, minor) \ + ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor))) +#else +# define V8_GLIBC_PREREQ(major, minor) 0 +#endif + + +// This macro allows to test for the version of the GNU C++ compiler. +// Note that this also applies to compilers that masquerade as GCC, +// for example clang and the Intel C++ compiler for Linux. +// Use like: +// #if V8_GNUC_PREREQ(4, 3, 1) +// ... +// #endif +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define V8_GNUC_PREREQ(major, minor, patchlevel) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ + ((major) * 10000 + (minor) * 100 + (patchlevel))) +#elif defined(__GNUC__) && defined(__GNUC_MINOR__) +# define V8_GNUC_PREREQ(major, minor, patchlevel) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= \ + ((major) * 10000 + (minor) * 100 + (patchlevel))) +#else +# define V8_GNUC_PREREQ(major, minor, patchlevel) 0 +#endif + + + +// ----------------------------------------------------------------------------- +// Operating system detection +// +// V8_OS_ANDROID - Android +// V8_OS_BSD - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD) +// V8_OS_CYGWIN - Cygwin +// V8_OS_DRAGONFLYBSD - DragonFlyBSD +// V8_OS_FREEBSD - FreeBSD +// V8_OS_FUCHSIA - Fuchsia +// V8_OS_LINUX - Linux +// V8_OS_MACOSX - Mac OS X +// V8_OS_IOS - iOS +// V8_OS_NETBSD - NetBSD +// V8_OS_OPENBSD - OpenBSD +// V8_OS_POSIX - POSIX compatible (mostly everything except Windows) +// V8_OS_QNX - QNX Neutrino +// V8_OS_SOLARIS - Sun Solaris and OpenSolaris +// V8_OS_AIX - AIX +// V8_OS_WIN - Microsoft Windows + +#if defined(__ANDROID__) +# define V8_OS_ANDROID 1 +# define V8_OS_LINUX 1 +# define V8_OS_POSIX 1 +#elif defined(__APPLE__) +# define V8_OS_BSD 1 +# define V8_OS_MACOSX 1 +# define V8_OS_POSIX 1 +# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE +# define V8_OS_IOS 1 +# endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE +#elif defined(__CYGWIN__) +# define V8_OS_CYGWIN 1 +# define V8_OS_POSIX 1 +#elif defined(__linux__) +# define V8_OS_LINUX 1 +# define V8_OS_POSIX 1 +#elif defined(__sun) +# define V8_OS_POSIX 1 +# define V8_OS_SOLARIS 1 +#elif defined(_AIX) +#define V8_OS_POSIX 1 +#define V8_OS_AIX 1 +#elif defined(__FreeBSD__) +# define V8_OS_BSD 1 +# define V8_OS_FREEBSD 1 +# define V8_OS_POSIX 1 +#elif defined(__Fuchsia__) +# define V8_OS_FUCHSIA 1 +# define V8_OS_POSIX 1 +#elif defined(__DragonFly__) +# define V8_OS_BSD 1 +# define V8_OS_DRAGONFLYBSD 1 +# define V8_OS_POSIX 1 +#elif defined(__NetBSD__) +# define V8_OS_BSD 1 +# define V8_OS_NETBSD 1 +# define V8_OS_POSIX 1 +#elif defined(__OpenBSD__) +# define V8_OS_BSD 1 +# define V8_OS_OPENBSD 1 +# define V8_OS_POSIX 1 +#elif defined(__QNXNTO__) +# define V8_OS_POSIX 1 +# define V8_OS_QNX 1 +#elif defined(_WIN32) +# define V8_OS_WIN 1 +#endif + + +// ----------------------------------------------------------------------------- +// C library detection +// +// V8_LIBC_MSVCRT - MSVC libc +// V8_LIBC_BIONIC - Bionic libc +// V8_LIBC_BSD - BSD libc derivate +// V8_LIBC_GLIBC - GNU C library +// V8_LIBC_UCLIBC - uClibc +// +// Note that testing for libc must be done using #if not #ifdef. For example, +// to test for the GNU C library, use: +// #if V8_LIBC_GLIBC +// ... +// #endif + +#if defined (_MSC_VER) +# define V8_LIBC_MSVCRT 1 +#elif defined(__BIONIC__) +# define V8_LIBC_BIONIC 1 +# define V8_LIBC_BSD 1 +#elif defined(__UCLIBC__) +// Must test for UCLIBC before GLIBC, as UCLIBC pretends to be GLIBC. +# define V8_LIBC_UCLIBC 1 +#elif defined(__GLIBC__) || defined(__GNU_LIBRARY__) +# define V8_LIBC_GLIBC 1 +#else +# define V8_LIBC_BSD V8_OS_BSD +#endif + + +// ----------------------------------------------------------------------------- +// Compiler detection +// +// V8_CC_GNU - GCC, or clang in gcc mode +// V8_CC_INTEL - Intel C++ +// V8_CC_MINGW - Minimalist GNU for Windows +// V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32) +// V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64) +// V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode +// +// C++11 feature detection +// +// Compiler-specific feature detection +// +// V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) +// supported +// V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported +// V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported +// V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported +// V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported +// V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result)) +// supported +// V8_HAS_BUILTIN_BSWAP16 - __builtin_bswap16() supported +// V8_HAS_BUILTIN_BSWAP32 - __builtin_bswap32() supported +// V8_HAS_BUILTIN_BSWAP64 - __builtin_bswap64() supported +// V8_HAS_BUILTIN_CLZ - __builtin_clz() supported +// V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported +// V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported +// V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported +// V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported +// V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported +// V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported +// V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported +// V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported +// V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported +// V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported +// V8_HAS_DECLSPEC_NORETURN - __declspec(noreturn) supported +// V8_HAS___FORCEINLINE - __forceinline supported +// +// Note that testing for compilers and/or features must be done using #if +// not #ifdef. For example, to test for Intel C++ Compiler, use: +// #if V8_CC_INTEL +// ... +// #endif + +#if defined(__clang__) + +#if defined(__GNUC__) // Clang in gcc mode. +# define V8_CC_GNU 1 +#endif + +# define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) +# define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) +# define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE \ + (__has_extension(attribute_deprecated_with_message)) +# define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline)) +# define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused)) +# define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) +# define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ + (__has_attribute(warn_unused_result)) + +# define V8_HAS_BUILTIN_BSWAP16 (__has_builtin(__builtin_bswap16)) +# define V8_HAS_BUILTIN_BSWAP32 (__has_builtin(__builtin_bswap32)) +# define V8_HAS_BUILTIN_BSWAP64 (__has_builtin(__builtin_bswap64)) +# define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz)) +# define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz)) +# define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) +# define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address)) +# define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount)) +# define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow)) +# define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow)) +# define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow)) + +# if __cplusplus >= 201402L +# define V8_CAN_HAVE_DCHECK_IN_CONSTEXPR 1 +# endif + +#elif defined(__GNUC__) + +# define V8_CC_GNU 1 +# if defined(__INTEL_COMPILER) // Intel C++ also masquerades as GCC 3.2.0 +# define V8_CC_INTEL 1 +# endif +# if defined(__MINGW32__) +# define V8_CC_MINGW32 1 +# endif +# if defined(__MINGW64__) +# define V8_CC_MINGW64 1 +# endif +# define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64) + +// always_inline is available in gcc 4.0 but not very reliable until 4.4. +// Works around "sorry, unimplemented: inlining failed" build errors with +// older compilers. +# define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0)) +# define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) +# define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0)) +# define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0)) +# define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0)) +# define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) +# define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ + (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0)) + +# define V8_HAS_BUILTIN_CLZ (V8_GNUC_PREREQ(3, 4, 0)) +# define V8_HAS_BUILTIN_CTZ (V8_GNUC_PREREQ(3, 4, 0)) +# define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0)) +# define V8_HAS_BUILTIN_FRAME_ADDRESS (V8_GNUC_PREREQ(2, 96, 0)) +# define V8_HAS_BUILTIN_POPCOUNT (V8_GNUC_PREREQ(3, 4, 0)) + +#endif + +#if defined(_MSC_VER) +# define V8_CC_MSVC 1 + +# define V8_HAS_DECLSPEC_DEPRECATED 1 +# define V8_HAS_DECLSPEC_NOINLINE 1 +# define V8_HAS_DECLSPEC_SELECTANY 1 +# define V8_HAS_DECLSPEC_NORETURN 1 + +# define V8_HAS___FORCEINLINE 1 + +#endif + + +// ----------------------------------------------------------------------------- +// Helper macros + +// A macro used to make better inlining. Don't bother for debug builds. +// Use like: +// V8_INLINE int GetZero() { return 0; } +#if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE +# define V8_INLINE inline __attribute__((always_inline)) +#elif !defined(DEBUG) && V8_HAS___FORCEINLINE +# define V8_INLINE __forceinline +#else +# define V8_INLINE inline +#endif + + +// A macro used to tell the compiler to never inline a particular function. +// Don't bother for debug builds. +// Use like: +// V8_NOINLINE int GetMinusOne() { return -1; } +#if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE +# define V8_NOINLINE __attribute__((noinline)) +#elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE +# define V8_NOINLINE __declspec(noinline) +#else +# define V8_NOINLINE /* NOT SUPPORTED */ +#endif + + +// A macro (V8_DEPRECATED) to mark classes or functions as deprecated. +#if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE +#define V8_DEPRECATED(message, declarator) \ + declarator __attribute__((deprecated(message))) +#elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED +#define V8_DEPRECATED(message, declarator) \ + declarator __attribute__((deprecated)) +#elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED +#define V8_DEPRECATED(message, declarator) __declspec(deprecated) declarator +#else +#define V8_DEPRECATED(message, declarator) declarator +#endif + + +// A macro (V8_DEPRECATE_SOON) to make it easier to see what will be deprecated. +#if defined(V8_IMMINENT_DEPRECATION_WARNINGS) && \ + V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE +#define V8_DEPRECATE_SOON(message, declarator) \ + declarator __attribute__((deprecated(message))) +#elif defined(V8_IMMINENT_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED +#define V8_DEPRECATE_SOON(message, declarator) \ + declarator __attribute__((deprecated)) +#elif defined(V8_IMMINENT_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED +#define V8_DEPRECATE_SOON(message, declarator) __declspec(deprecated) declarator +#else +#define V8_DEPRECATE_SOON(message, declarator) declarator +#endif + + +// A macro to provide the compiler with branch prediction information. +#if V8_HAS_BUILTIN_EXPECT +# define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0)) +# define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1)) +#else +# define V8_UNLIKELY(condition) (condition) +# define V8_LIKELY(condition) (condition) +#endif + + +// Annotate a function indicating the caller must examine the return value. +// Use like: +// int foo() V8_WARN_UNUSED_RESULT; +#if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT +#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else +#define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */ +#endif + +#ifdef V8_OS_WIN + +// Setup for Windows DLL export/import. When building the V8 DLL the +// BUILDING_V8_SHARED needs to be defined. When building a program which uses +// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 +// static library or building a program which uses the V8 static library neither +// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. +#ifdef BUILDING_V8_SHARED +# define V8_EXPORT __declspec(dllexport) +#elif USING_V8_SHARED +# define V8_EXPORT __declspec(dllimport) +#else +# define V8_EXPORT +#endif // BUILDING_V8_SHARED + +#else // V8_OS_WIN + +// Setup for Linux shared library export. +#if V8_HAS_ATTRIBUTE_VISIBILITY +# ifdef BUILDING_V8_SHARED +# define V8_EXPORT __attribute__ ((visibility("default"))) +# else +# define V8_EXPORT +# endif +#else +# define V8_EXPORT +#endif + +#endif // V8_OS_WIN + +// clang-format on + +#endif // V8CONFIG_H_ diff --git a/android/x86/include/webp/decode.h b/android/x86/include/webp/decode.h new file mode 100644 index 00000000..143e4fbe --- /dev/null +++ b/android/x86/include/webp/decode.h @@ -0,0 +1,488 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Main decoding functions for WebP images. +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_WEBP_DECODE_H_ +#define WEBP_WEBP_DECODE_H_ + +#include "./types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WEBP_DECODER_ABI_VERSION 0x0208 // MAJOR(8b) + MINOR(8b) + +// Note: forward declaring enumerations is not allowed in (strict) C and C++, +// the types are left here for reference. +// typedef enum VP8StatusCode VP8StatusCode; +// typedef enum WEBP_CSP_MODE WEBP_CSP_MODE; +typedef struct WebPRGBABuffer WebPRGBABuffer; +typedef struct WebPYUVABuffer WebPYUVABuffer; +typedef struct WebPDecBuffer WebPDecBuffer; +typedef struct WebPIDecoder WebPIDecoder; +typedef struct WebPBitstreamFeatures WebPBitstreamFeatures; +typedef struct WebPDecoderOptions WebPDecoderOptions; +typedef struct WebPDecoderConfig WebPDecoderConfig; + +// Return the decoder's version number, packed in hexadecimal using 8bits for +// each of major/minor/revision. E.g: v2.5.7 is 0x020507. +WEBP_EXTERN(int) WebPGetDecoderVersion(void); + +// Retrieve basic header information: width, height. +// This function will also validate the header and return 0 in +// case of formatting error. +// Pointers 'width' and 'height' can be passed NULL if deemed irrelevant. +WEBP_EXTERN(int) WebPGetInfo(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Decodes WebP images pointed to by 'data' and returns RGBA samples, along +// with the dimensions in *width and *height. The ordering of samples in +// memory is R, G, B, A, R, G, B, A... in scan order (endian-independent). +// The returned pointer should be deleted calling WebPFree(). +// Returns NULL in case of error. +WEBP_EXTERN(uint8_t*) WebPDecodeRGBA(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Same as WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B... ordered data. +WEBP_EXTERN(uint8_t*) WebPDecodeARGB(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data. +WEBP_EXTERN(uint8_t*) WebPDecodeBGRA(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Same as WebPDecodeRGBA, but returning R, G, B, R, G, B... ordered data. +// If the bitstream contains transparency, it is ignored. +WEBP_EXTERN(uint8_t*) WebPDecodeRGB(const uint8_t* data, size_t data_size, + int* width, int* height); + +// Same as WebPDecodeRGB, but returning B, G, R, B, G, R... ordered data. +WEBP_EXTERN(uint8_t*) WebPDecodeBGR(const uint8_t* data, size_t data_size, + int* width, int* height); + + +// Decode WebP images pointed to by 'data' to Y'UV format(*). The pointer +// returned is the Y samples buffer. Upon return, *u and *v will point to +// the U and V chroma data. These U and V buffers need NOT be passed to +// WebPFree(), unlike the returned Y luma one. The dimension of the U and V +// planes are both (*width + 1) / 2 and (*height + 1)/ 2. +// Upon return, the Y buffer has a stride returned as '*stride', while U and V +// have a common stride returned as '*uv_stride'. +// Return NULL in case of error. +// (*) Also named Y'CbCr. See: http://en.wikipedia.org/wiki/YCbCr +WEBP_EXTERN(uint8_t*) WebPDecodeYUV(const uint8_t* data, size_t data_size, + int* width, int* height, + uint8_t** u, uint8_t** v, + int* stride, int* uv_stride); + +// Releases memory returned by the WebPDecode*() functions above. +WEBP_EXTERN(void) WebPFree(void* ptr); + +// These five functions are variants of the above ones, that decode the image +// directly into a pre-allocated buffer 'output_buffer'. The maximum storage +// available in this buffer is indicated by 'output_buffer_size'. If this +// storage is not sufficient (or an error occurred), NULL is returned. +// Otherwise, output_buffer is returned, for convenience. +// The parameter 'output_stride' specifies the distance (in bytes) +// between scanlines. Hence, output_buffer_size is expected to be at least +// output_stride x picture-height. +WEBP_EXTERN(uint8_t*) WebPDecodeRGBAInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); +WEBP_EXTERN(uint8_t*) WebPDecodeARGBInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); +WEBP_EXTERN(uint8_t*) WebPDecodeBGRAInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); + +// RGB and BGR variants. Here too the transparency information, if present, +// will be dropped and ignored. +WEBP_EXTERN(uint8_t*) WebPDecodeRGBInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); +WEBP_EXTERN(uint8_t*) WebPDecodeBGRInto( + const uint8_t* data, size_t data_size, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); + +// WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly +// into pre-allocated luma/chroma plane buffers. This function requires the +// strides to be passed: one for the luma plane and one for each of the +// chroma ones. The size of each plane buffer is passed as 'luma_size', +// 'u_size' and 'v_size' respectively. +// Pointer to the luma plane ('*luma') is returned or NULL if an error occurred +// during decoding (or because some buffers were found to be too small). +WEBP_EXTERN(uint8_t*) WebPDecodeYUVInto( + const uint8_t* data, size_t data_size, + uint8_t* luma, size_t luma_size, int luma_stride, + uint8_t* u, size_t u_size, int u_stride, + uint8_t* v, size_t v_size, int v_stride); + +//------------------------------------------------------------------------------ +// Output colorspaces and buffer + +// Colorspaces +// Note: the naming describes the byte-ordering of packed samples in memory. +// For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,... +// Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels. +// RGBA-4444 and RGB-565 colorspaces are represented by following byte-order: +// RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ... +// RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ... +// In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for +// these two modes: +// RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ... +// RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ... + +typedef enum WEBP_CSP_MODE { + MODE_RGB = 0, MODE_RGBA = 1, + MODE_BGR = 2, MODE_BGRA = 3, + MODE_ARGB = 4, MODE_RGBA_4444 = 5, + MODE_RGB_565 = 6, + // RGB-premultiplied transparent modes (alpha value is preserved) + MODE_rgbA = 7, + MODE_bgrA = 8, + MODE_Argb = 9, + MODE_rgbA_4444 = 10, + // YUV modes must come after RGB ones. + MODE_YUV = 11, MODE_YUVA = 12, // yuv 4:2:0 + MODE_LAST = 13 +} WEBP_CSP_MODE; + +// Some useful macros: +static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) { + return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || + mode == MODE_rgbA_4444); +} + +static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) { + return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB || + mode == MODE_RGBA_4444 || mode == MODE_YUVA || + WebPIsPremultipliedMode(mode)); +} + +static WEBP_INLINE int WebPIsRGBMode(WEBP_CSP_MODE mode) { + return (mode < MODE_YUV); +} + +//------------------------------------------------------------------------------ +// WebPDecBuffer: Generic structure for describing the output sample buffer. + +struct WebPRGBABuffer { // view as RGBA + uint8_t* rgba; // pointer to RGBA samples + int stride; // stride in bytes from one scanline to the next. + size_t size; // total size of the *rgba buffer. +}; + +struct WebPYUVABuffer { // view as YUVA + uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples + int y_stride; // luma stride + int u_stride, v_stride; // chroma strides + int a_stride; // alpha stride + size_t y_size; // luma plane size + size_t u_size, v_size; // chroma planes size + size_t a_size; // alpha-plane size +}; + +// Output buffer +struct WebPDecBuffer { + WEBP_CSP_MODE colorspace; // Colorspace. + int width, height; // Dimensions. + int is_external_memory; // If true, 'internal_memory' pointer is not used. + union { + WebPRGBABuffer RGBA; + WebPYUVABuffer YUVA; + } u; // Nameless union of buffer parameters. + uint32_t pad[4]; // padding for later use + + uint8_t* private_memory; // Internally allocated memory (only when + // is_external_memory is false). Should not be used + // externally, but accessed via the buffer union. +}; + +// Internal, version-checked, entry point +WEBP_EXTERN(int) WebPInitDecBufferInternal(WebPDecBuffer*, int); + +// Initialize the structure as empty. Must be called before any other use. +// Returns false in case of version mismatch +static WEBP_INLINE int WebPInitDecBuffer(WebPDecBuffer* buffer) { + return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); +} + +// Free any memory associated with the buffer. Must always be called last. +// Note: doesn't free the 'buffer' structure itself. +WEBP_EXTERN(void) WebPFreeDecBuffer(WebPDecBuffer* buffer); + +//------------------------------------------------------------------------------ +// Enumeration of the status codes + +typedef enum VP8StatusCode { + VP8_STATUS_OK = 0, + VP8_STATUS_OUT_OF_MEMORY, + VP8_STATUS_INVALID_PARAM, + VP8_STATUS_BITSTREAM_ERROR, + VP8_STATUS_UNSUPPORTED_FEATURE, + VP8_STATUS_SUSPENDED, + VP8_STATUS_USER_ABORT, + VP8_STATUS_NOT_ENOUGH_DATA +} VP8StatusCode; + +//------------------------------------------------------------------------------ +// Incremental decoding +// +// This API allows streamlined decoding of partial data. +// Picture can be incrementally decoded as data become available thanks to the +// WebPIDecoder object. This object can be left in a SUSPENDED state if the +// picture is only partially decoded, pending additional input. +// Code example: +// +// WebPInitDecBuffer(&buffer); +// buffer.colorspace = mode; +// ... +// WebPIDecoder* idec = WebPINewDecoder(&buffer); +// while (has_more_data) { +// // ... (get additional data) +// status = WebPIAppend(idec, new_data, new_data_size); +// if (status != VP8_STATUS_SUSPENDED || +// break; +// } +// +// // The above call decodes the current available buffer. +// // Part of the image can now be refreshed by calling to +// // WebPIDecGetRGB()/WebPIDecGetYUVA() etc. +// } +// WebPIDelete(idec); + +// Creates a new incremental decoder with the supplied buffer parameter. +// This output_buffer can be passed NULL, in which case a default output buffer +// is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer' +// is kept, which means that the lifespan of 'output_buffer' must be larger than +// that of the returned WebPIDecoder object. +// The supplied 'output_buffer' content MUST NOT be changed between calls to +// WebPIAppend() or WebPIUpdate() unless 'output_buffer.is_external_memory' is +// set to 1. In such a case, it is allowed to modify the pointers, size and +// stride of output_buffer.u.RGBA or output_buffer.u.YUVA, provided they remain +// within valid bounds. +// All other fields of WebPDecBuffer MUST remain constant between calls. +// Returns NULL if the allocation failed. +WEBP_EXTERN(WebPIDecoder*) WebPINewDecoder(WebPDecBuffer* output_buffer); + +// This function allocates and initializes an incremental-decoder object, which +// will output the RGB/A samples specified by 'csp' into a preallocated +// buffer 'output_buffer'. The size of this buffer is at least +// 'output_buffer_size' and the stride (distance in bytes between two scanlines) +// is specified by 'output_stride'. +// Additionally, output_buffer can be passed NULL in which case the output +// buffer will be allocated automatically when the decoding starts. The +// colorspace 'csp' is taken into account for allocating this buffer. All other +// parameters are ignored. +// Returns NULL if the allocation failed, or if some parameters are invalid. +WEBP_EXTERN(WebPIDecoder*) WebPINewRGB( + WEBP_CSP_MODE csp, + uint8_t* output_buffer, size_t output_buffer_size, int output_stride); + +// This function allocates and initializes an incremental-decoder object, which +// will output the raw luma/chroma samples into a preallocated planes if +// supplied. The luma plane is specified by its pointer 'luma', its size +// 'luma_size' and its stride 'luma_stride'. Similarly, the chroma-u plane +// is specified by the 'u', 'u_size' and 'u_stride' parameters, and the chroma-v +// plane by 'v' and 'v_size'. And same for the alpha-plane. The 'a' pointer +// can be pass NULL in case one is not interested in the transparency plane. +// Conversely, 'luma' can be passed NULL if no preallocated planes are supplied. +// In this case, the output buffer will be automatically allocated (using +// MODE_YUVA) when decoding starts. All parameters are then ignored. +// Returns NULL if the allocation failed or if a parameter is invalid. +WEBP_EXTERN(WebPIDecoder*) WebPINewYUVA( + uint8_t* luma, size_t luma_size, int luma_stride, + uint8_t* u, size_t u_size, int u_stride, + uint8_t* v, size_t v_size, int v_stride, + uint8_t* a, size_t a_size, int a_stride); + +// Deprecated version of the above, without the alpha plane. +// Kept for backward compatibility. +WEBP_EXTERN(WebPIDecoder*) WebPINewYUV( + uint8_t* luma, size_t luma_size, int luma_stride, + uint8_t* u, size_t u_size, int u_stride, + uint8_t* v, size_t v_size, int v_stride); + +// Deletes the WebPIDecoder object and associated memory. Must always be called +// if WebPINewDecoder, WebPINewRGB or WebPINewYUV succeeded. +WEBP_EXTERN(void) WebPIDelete(WebPIDecoder* idec); + +// Copies and decodes the next available data. Returns VP8_STATUS_OK when +// the image is successfully decoded. Returns VP8_STATUS_SUSPENDED when more +// data is expected. Returns error in other cases. +WEBP_EXTERN(VP8StatusCode) WebPIAppend( + WebPIDecoder* idec, const uint8_t* data, size_t data_size); + +// A variant of the above function to be used when data buffer contains +// partial data from the beginning. In this case data buffer is not copied +// to the internal memory. +// Note that the value of the 'data' pointer can change between calls to +// WebPIUpdate, for instance when the data buffer is resized to fit larger data. +WEBP_EXTERN(VP8StatusCode) WebPIUpdate( + WebPIDecoder* idec, const uint8_t* data, size_t data_size); + +// Returns the RGB/A image decoded so far. Returns NULL if output params +// are not initialized yet. The RGB/A output type corresponds to the colorspace +// specified during call to WebPINewDecoder() or WebPINewRGB(). +// *last_y is the index of last decoded row in raster scan order. Some pointers +// (*last_y, *width etc.) can be NULL if corresponding information is not +// needed. +WEBP_EXTERN(uint8_t*) WebPIDecGetRGB( + const WebPIDecoder* idec, int* last_y, + int* width, int* height, int* stride); + +// Same as above function to get a YUVA image. Returns pointer to the luma +// plane or NULL in case of error. If there is no alpha information +// the alpha pointer '*a' will be returned NULL. +WEBP_EXTERN(uint8_t*) WebPIDecGetYUVA( + const WebPIDecoder* idec, int* last_y, + uint8_t** u, uint8_t** v, uint8_t** a, + int* width, int* height, int* stride, int* uv_stride, int* a_stride); + +// Deprecated alpha-less version of WebPIDecGetYUVA(): it will ignore the +// alpha information (if present). Kept for backward compatibility. +static WEBP_INLINE uint8_t* WebPIDecGetYUV( + const WebPIDecoder* idec, int* last_y, uint8_t** u, uint8_t** v, + int* width, int* height, int* stride, int* uv_stride) { + return WebPIDecGetYUVA(idec, last_y, u, v, NULL, width, height, + stride, uv_stride, NULL); +} + +// Generic call to retrieve information about the displayable area. +// If non NULL, the left/right/width/height pointers are filled with the visible +// rectangular area so far. +// Returns NULL in case the incremental decoder object is in an invalid state. +// Otherwise returns the pointer to the internal representation. This structure +// is read-only, tied to WebPIDecoder's lifespan and should not be modified. +WEBP_EXTERN(const WebPDecBuffer*) WebPIDecodedArea( + const WebPIDecoder* idec, int* left, int* top, int* width, int* height); + +//------------------------------------------------------------------------------ +// Advanced decoding parametrization +// +// Code sample for using the advanced decoding API +/* + // A) Init a configuration object + WebPDecoderConfig config; + CHECK(WebPInitDecoderConfig(&config)); + + // B) optional: retrieve the bitstream's features. + CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK); + + // C) Adjust 'config', if needed + config.no_fancy_upsampling = 1; + config.output.colorspace = MODE_BGRA; + // etc. + + // Note that you can also make config.output point to an externally + // supplied memory buffer, provided it's big enough to store the decoded + // picture. Otherwise, config.output will just be used to allocate memory + // and store the decoded picture. + + // D) Decode! + CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK); + + // E) Decoded image is now in config.output (and config.output.u.RGBA) + + // F) Reclaim memory allocated in config's object. It's safe to call + // this function even if the memory is external and wasn't allocated + // by WebPDecode(). + WebPFreeDecBuffer(&config.output); +*/ + +// Features gathered from the bitstream +struct WebPBitstreamFeatures { + int width; // Width in pixels, as read from the bitstream. + int height; // Height in pixels, as read from the bitstream. + int has_alpha; // True if the bitstream contains an alpha channel. + int has_animation; // True if the bitstream is an animation. + int format; // 0 = undefined (/mixed), 1 = lossy, 2 = lossless + + uint32_t pad[5]; // padding for later use +}; + +// Internal, version-checked, entry point +WEBP_EXTERN(VP8StatusCode) WebPGetFeaturesInternal( + const uint8_t*, size_t, WebPBitstreamFeatures*, int); + +// Retrieve features from the bitstream. The *features structure is filled +// with information gathered from the bitstream. +// Returns VP8_STATUS_OK when the features are successfully retrieved. Returns +// VP8_STATUS_NOT_ENOUGH_DATA when more data is needed to retrieve the +// features from headers. Returns error in other cases. +static WEBP_INLINE VP8StatusCode WebPGetFeatures( + const uint8_t* data, size_t data_size, + WebPBitstreamFeatures* features) { + return WebPGetFeaturesInternal(data, data_size, features, + WEBP_DECODER_ABI_VERSION); +} + +// Decoding options +struct WebPDecoderOptions { + int bypass_filtering; // if true, skip the in-loop filtering + int no_fancy_upsampling; // if true, use faster pointwise upsampler + int use_cropping; // if true, cropping is applied _first_ + int crop_left, crop_top; // top-left position for cropping. + // Will be snapped to even values. + int crop_width, crop_height; // dimension of the cropping area + int use_scaling; // if true, scaling is applied _afterward_ + int scaled_width, scaled_height; // final resolution + int use_threads; // if true, use multi-threaded decoding + int dithering_strength; // dithering strength (0=Off, 100=full) + int flip; // flip output vertically + int alpha_dithering_strength; // alpha dithering strength in [0..100] + + uint32_t pad[5]; // padding for later use +}; + +// Main object storing the configuration for advanced decoding. +struct WebPDecoderConfig { + WebPBitstreamFeatures input; // Immutable bitstream features (optional) + WebPDecBuffer output; // Output buffer (can point to external mem) + WebPDecoderOptions options; // Decoding options +}; + +// Internal, version-checked, entry point +WEBP_EXTERN(int) WebPInitDecoderConfigInternal(WebPDecoderConfig*, int); + +// Initialize the configuration as empty. This function must always be +// called first, unless WebPGetFeatures() is to be called. +// Returns false in case of mismatched version. +static WEBP_INLINE int WebPInitDecoderConfig(WebPDecoderConfig* config) { + return WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION); +} + +// Instantiate a new incremental decoder object with the requested +// configuration. The bitstream can be passed using 'data' and 'data_size' +// parameter, in which case the features will be parsed and stored into +// config->input. Otherwise, 'data' can be NULL and no parsing will occur. +// Note that 'config' can be NULL too, in which case a default configuration +// is used. +// The return WebPIDecoder object must always be deleted calling WebPIDelete(). +// Returns NULL in case of error (and config->status will then reflect +// the error condition). +WEBP_EXTERN(WebPIDecoder*) WebPIDecode(const uint8_t* data, size_t data_size, + WebPDecoderConfig* config); + +// Non-incremental version. This version decodes the full data at once, taking +// 'config' into account. Returns decoding status (which should be VP8_STATUS_OK +// if the decoding was successful). +WEBP_EXTERN(VP8StatusCode) WebPDecode(const uint8_t* data, size_t data_size, + WebPDecoderConfig* config); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_WEBP_DECODE_H_ */ diff --git a/android/x86/include/webp/encode.h b/android/x86/include/webp/encode.h new file mode 100644 index 00000000..c382ea76 --- /dev/null +++ b/android/x86/include/webp/encode.h @@ -0,0 +1,527 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// WebP encoder: main interface +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_WEBP_ENCODE_H_ +#define WEBP_WEBP_ENCODE_H_ + +#include "./types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WEBP_ENCODER_ABI_VERSION 0x0209 // MAJOR(8b) + MINOR(8b) + +// Note: forward declaring enumerations is not allowed in (strict) C and C++, +// the types are left here for reference. +// typedef enum WebPImageHint WebPImageHint; +// typedef enum WebPEncCSP WebPEncCSP; +// typedef enum WebPPreset WebPPreset; +// typedef enum WebPEncodingError WebPEncodingError; +typedef struct WebPConfig WebPConfig; +typedef struct WebPPicture WebPPicture; // main structure for I/O +typedef struct WebPAuxStats WebPAuxStats; +typedef struct WebPMemoryWriter WebPMemoryWriter; + +// Return the encoder's version number, packed in hexadecimal using 8bits for +// each of major/minor/revision. E.g: v2.5.7 is 0x020507. +WEBP_EXTERN(int) WebPGetEncoderVersion(void); + +//------------------------------------------------------------------------------ +// One-stop-shop call! No questions asked: + +// Returns the size of the compressed data (pointed to by *output), or 0 if +// an error occurred. The compressed data must be released by the caller +// using the call 'WebPFree(*output)'. +// These functions compress using the lossy format, and the quality_factor +// can go from 0 (smaller output, lower quality) to 100 (best quality, +// larger output). +WEBP_EXTERN(size_t) WebPEncodeRGB(const uint8_t* rgb, + int width, int height, int stride, + float quality_factor, uint8_t** output); +WEBP_EXTERN(size_t) WebPEncodeBGR(const uint8_t* bgr, + int width, int height, int stride, + float quality_factor, uint8_t** output); +WEBP_EXTERN(size_t) WebPEncodeRGBA(const uint8_t* rgba, + int width, int height, int stride, + float quality_factor, uint8_t** output); +WEBP_EXTERN(size_t) WebPEncodeBGRA(const uint8_t* bgra, + int width, int height, int stride, + float quality_factor, uint8_t** output); + +// These functions are the equivalent of the above, but compressing in a +// lossless manner. Files are usually larger than lossy format, but will +// not suffer any compression loss. +WEBP_EXTERN(size_t) WebPEncodeLosslessRGB(const uint8_t* rgb, + int width, int height, int stride, + uint8_t** output); +WEBP_EXTERN(size_t) WebPEncodeLosslessBGR(const uint8_t* bgr, + int width, int height, int stride, + uint8_t** output); +WEBP_EXTERN(size_t) WebPEncodeLosslessRGBA(const uint8_t* rgba, + int width, int height, int stride, + uint8_t** output); +WEBP_EXTERN(size_t) WebPEncodeLosslessBGRA(const uint8_t* bgra, + int width, int height, int stride, + uint8_t** output); + +// Releases memory returned by the WebPEncode*() functions above. +WEBP_EXTERN(void) WebPFree(void* ptr); + +//------------------------------------------------------------------------------ +// Coding parameters + +// Image characteristics hint for the underlying encoder. +typedef enum WebPImageHint { + WEBP_HINT_DEFAULT = 0, // default preset. + WEBP_HINT_PICTURE, // digital picture, like portrait, inner shot + WEBP_HINT_PHOTO, // outdoor photograph, with natural lighting + WEBP_HINT_GRAPH, // Discrete tone image (graph, map-tile etc). + WEBP_HINT_LAST +} WebPImageHint; + +// Compression parameters. +struct WebPConfig { + int lossless; // Lossless encoding (0=lossy(default), 1=lossless). + float quality; // between 0 (smallest file) and 100 (biggest) + int method; // quality/speed trade-off (0=fast, 6=slower-better) + + WebPImageHint image_hint; // Hint for image type (lossless only for now). + + // Parameters related to lossy compression only: + int target_size; // if non-zero, set the desired target size in bytes. + // Takes precedence over the 'compression' parameter. + float target_PSNR; // if non-zero, specifies the minimal distortion to + // try to achieve. Takes precedence over target_size. + int segments; // maximum number of segments to use, in [1..4] + int sns_strength; // Spatial Noise Shaping. 0=off, 100=maximum. + int filter_strength; // range: [0 = off .. 100 = strongest] + int filter_sharpness; // range: [0 = off .. 7 = least sharp] + int filter_type; // filtering type: 0 = simple, 1 = strong (only used + // if filter_strength > 0 or autofilter > 0) + int autofilter; // Auto adjust filter's strength [0 = off, 1 = on] + int alpha_compression; // Algorithm for encoding the alpha plane (0 = none, + // 1 = compressed with WebP lossless). Default is 1. + int alpha_filtering; // Predictive filtering method for alpha plane. + // 0: none, 1: fast, 2: best. Default if 1. + int alpha_quality; // Between 0 (smallest size) and 100 (lossless). + // Default is 100. + int pass; // number of entropy-analysis passes (in [1..10]). + + int show_compressed; // if true, export the compressed picture back. + // In-loop filtering is not applied. + int preprocessing; // preprocessing filter: + // 0=none, 1=segment-smooth, 2=pseudo-random dithering + int partitions; // log2(number of token partitions) in [0..3]. Default + // is set to 0 for easier progressive decoding. + int partition_limit; // quality degradation allowed to fit the 512k limit + // on prediction modes coding (0: no degradation, + // 100: maximum possible degradation). + int emulate_jpeg_size; // If true, compression parameters will be remapped + // to better match the expected output size from + // JPEG compression. Generally, the output size will + // be similar but the degradation will be lower. + int thread_level; // If non-zero, try and use multi-threaded encoding. + int low_memory; // If set, reduce memory usage (but increase CPU use). + + int near_lossless; // Near lossless encoding [0 = off(default) .. 100]. + // This feature is experimental. + int exact; // if non-zero, preserve the exact RGB values under + // transparent area. Otherwise, discard this invisible + // RGB information for better compression. The default + // value is 0. + +#ifdef WEBP_EXPERIMENTAL_FEATURES + int delta_palettization; + uint32_t pad[2]; // padding for later use +#else + uint32_t pad[3]; // padding for later use +#endif // WEBP_EXPERIMENTAL_FEATURES +}; + +// Enumerate some predefined settings for WebPConfig, depending on the type +// of source picture. These presets are used when calling WebPConfigPreset(). +typedef enum WebPPreset { + WEBP_PRESET_DEFAULT = 0, // default preset. + WEBP_PRESET_PICTURE, // digital picture, like portrait, inner shot + WEBP_PRESET_PHOTO, // outdoor photograph, with natural lighting + WEBP_PRESET_DRAWING, // hand or line drawing, with high-contrast details + WEBP_PRESET_ICON, // small-sized colorful images + WEBP_PRESET_TEXT // text-like +} WebPPreset; + +// Internal, version-checked, entry point +WEBP_EXTERN(int) WebPConfigInitInternal(WebPConfig*, WebPPreset, float, int); + +// Should always be called, to initialize a fresh WebPConfig structure before +// modification. Returns false in case of version mismatch. WebPConfigInit() +// must have succeeded before using the 'config' object. +// Note that the default values are lossless=0 and quality=75. +static WEBP_INLINE int WebPConfigInit(WebPConfig* config) { + return WebPConfigInitInternal(config, WEBP_PRESET_DEFAULT, 75.f, + WEBP_ENCODER_ABI_VERSION); +} + +// This function will initialize the configuration according to a predefined +// set of parameters (referred to by 'preset') and a given quality factor. +// This function can be called as a replacement to WebPConfigInit(). Will +// return false in case of error. +static WEBP_INLINE int WebPConfigPreset(WebPConfig* config, + WebPPreset preset, float quality) { + return WebPConfigInitInternal(config, preset, quality, + WEBP_ENCODER_ABI_VERSION); +} + +// Activate the lossless compression mode with the desired efficiency level +// between 0 (fastest, lowest compression) and 9 (slower, best compression). +// A good default level is '6', providing a fair tradeoff between compression +// speed and final compressed size. +// This function will overwrite several fields from config: 'method', 'quality' +// and 'lossless'. Returns false in case of parameter error. +WEBP_EXTERN(int) WebPConfigLosslessPreset(WebPConfig* config, int level); + +// Returns true if 'config' is non-NULL and all configuration parameters are +// within their valid ranges. +WEBP_EXTERN(int) WebPValidateConfig(const WebPConfig* config); + +//------------------------------------------------------------------------------ +// Input / Output +// Structure for storing auxiliary statistics (mostly for lossy encoding). + +struct WebPAuxStats { + int coded_size; // final size + + float PSNR[5]; // peak-signal-to-noise ratio for Y/U/V/All/Alpha + int block_count[3]; // number of intra4/intra16/skipped macroblocks + int header_bytes[2]; // approximate number of bytes spent for header + // and mode-partition #0 + int residual_bytes[3][4]; // approximate number of bytes spent for + // DC/AC/uv coefficients for each (0..3) segments. + int segment_size[4]; // number of macroblocks in each segments + int segment_quant[4]; // quantizer values for each segments + int segment_level[4]; // filtering strength for each segments [0..63] + + int alpha_data_size; // size of the transparency data + int layer_data_size; // size of the enhancement layer data + + // lossless encoder statistics + uint32_t lossless_features; // bit0:predictor bit1:cross-color transform + // bit2:subtract-green bit3:color indexing + int histogram_bits; // number of precision bits of histogram + int transform_bits; // precision bits for transform + int cache_bits; // number of bits for color cache lookup + int palette_size; // number of color in palette, if used + int lossless_size; // final lossless size + int lossless_hdr_size; // lossless header (transform, huffman etc) size + int lossless_data_size; // lossless image data size + + uint32_t pad[2]; // padding for later use +}; + +// Signature for output function. Should return true if writing was successful. +// data/data_size is the segment of data to write, and 'picture' is for +// reference (and so one can make use of picture->custom_ptr). +typedef int (*WebPWriterFunction)(const uint8_t* data, size_t data_size, + const WebPPicture* picture); + +// WebPMemoryWrite: a special WebPWriterFunction that writes to memory using +// the following WebPMemoryWriter object (to be set as a custom_ptr). +struct WebPMemoryWriter { + uint8_t* mem; // final buffer (of size 'max_size', larger than 'size'). + size_t size; // final size + size_t max_size; // total capacity + uint32_t pad[1]; // padding for later use +}; + +// The following must be called first before any use. +WEBP_EXTERN(void) WebPMemoryWriterInit(WebPMemoryWriter* writer); + +// The following must be called to deallocate writer->mem memory. The 'writer' +// object itself is not deallocated. +WEBP_EXTERN(void) WebPMemoryWriterClear(WebPMemoryWriter* writer); +// The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon +// completion, writer.mem and writer.size will hold the coded data. +// writer.mem must be freed by calling WebPMemoryWriterClear. +WEBP_EXTERN(int) WebPMemoryWrite(const uint8_t* data, size_t data_size, + const WebPPicture* picture); + +// Progress hook, called from time to time to report progress. It can return +// false to request an abort of the encoding process, or true otherwise if +// everything is OK. +typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture); + +// Color spaces. +typedef enum WebPEncCSP { + // chroma sampling + WEBP_YUV420 = 0, // 4:2:0 + WEBP_YUV420A = 4, // alpha channel variant + WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors + WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present +} WebPEncCSP; + +// Encoding error conditions. +typedef enum WebPEncodingError { + VP8_ENC_OK = 0, + VP8_ENC_ERROR_OUT_OF_MEMORY, // memory error allocating objects + VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY, // memory error while flushing bits + VP8_ENC_ERROR_NULL_PARAMETER, // a pointer parameter is NULL + VP8_ENC_ERROR_INVALID_CONFIGURATION, // configuration is invalid + VP8_ENC_ERROR_BAD_DIMENSION, // picture has invalid width/height + VP8_ENC_ERROR_PARTITION0_OVERFLOW, // partition is bigger than 512k + VP8_ENC_ERROR_PARTITION_OVERFLOW, // partition is bigger than 16M + VP8_ENC_ERROR_BAD_WRITE, // error while flushing bytes + VP8_ENC_ERROR_FILE_TOO_BIG, // file is bigger than 4G + VP8_ENC_ERROR_USER_ABORT, // abort request by user + VP8_ENC_ERROR_LAST // list terminator. always last. +} WebPEncodingError; + +// maximum width/height allowed (inclusive), in pixels +#define WEBP_MAX_DIMENSION 16383 + +// Main exchange structure (input samples, output bytes, statistics) +struct WebPPicture { + // INPUT + ////////////// + // Main flag for encoder selecting between ARGB or YUV input. + // It is recommended to use ARGB input (*argb, argb_stride) for lossless + // compression, and YUV input (*y, *u, *v, etc.) for lossy compression + // since these are the respective native colorspace for these formats. + int use_argb; + + // YUV input (mostly used for input to lossy compression) + WebPEncCSP colorspace; // colorspace: should be YUV420 for now (=Y'CbCr). + int width, height; // dimensions (less or equal to WEBP_MAX_DIMENSION) + uint8_t *y, *u, *v; // pointers to luma/chroma planes. + int y_stride, uv_stride; // luma/chroma strides. + uint8_t* a; // pointer to the alpha plane + int a_stride; // stride of the alpha plane + uint32_t pad1[2]; // padding for later use + + // ARGB input (mostly used for input to lossless compression) + uint32_t* argb; // Pointer to argb (32 bit) plane. + int argb_stride; // This is stride in pixels units, not bytes. + uint32_t pad2[3]; // padding for later use + + // OUTPUT + /////////////// + // Byte-emission hook, to store compressed bytes as they are ready. + WebPWriterFunction writer; // can be NULL + void* custom_ptr; // can be used by the writer. + + // map for extra information (only for lossy compression mode) + int extra_info_type; // 1: intra type, 2: segment, 3: quant + // 4: intra-16 prediction mode, + // 5: chroma prediction mode, + // 6: bit cost, 7: distortion + uint8_t* extra_info; // if not NULL, points to an array of size + // ((width + 15) / 16) * ((height + 15) / 16) that + // will be filled with a macroblock map, depending + // on extra_info_type. + + // STATS AND REPORTS + /////////////////////////// + // Pointer to side statistics (updated only if not NULL) + WebPAuxStats* stats; + + // Error code for the latest error encountered during encoding + WebPEncodingError error_code; + + // If not NULL, report progress during encoding. + WebPProgressHook progress_hook; + + void* user_data; // this field is free to be set to any value and + // used during callbacks (like progress-report e.g.). + + uint32_t pad3[3]; // padding for later use + + // Unused for now + uint8_t *pad4, *pad5; + uint32_t pad6[8]; // padding for later use + + // PRIVATE FIELDS + //////////////////// + void* memory_; // row chunk of memory for yuva planes + void* memory_argb_; // and for argb too. + void* pad7[2]; // padding for later use +}; + +// Internal, version-checked, entry point +WEBP_EXTERN(int) WebPPictureInitInternal(WebPPicture*, int); + +// Should always be called, to initialize the structure. Returns false in case +// of version mismatch. WebPPictureInit() must have succeeded before using the +// 'picture' object. +// Note that, by default, use_argb is false and colorspace is WEBP_YUV420. +static WEBP_INLINE int WebPPictureInit(WebPPicture* picture) { + return WebPPictureInitInternal(picture, WEBP_ENCODER_ABI_VERSION); +} + +//------------------------------------------------------------------------------ +// WebPPicture utils + +// Convenience allocation / deallocation based on picture->width/height: +// Allocate y/u/v buffers as per colorspace/width/height specification. +// Note! This function will free the previous buffer if needed. +// Returns false in case of memory error. +WEBP_EXTERN(int) WebPPictureAlloc(WebPPicture* picture); + +// Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*(). +// Note that this function does _not_ free the memory used by the 'picture' +// object itself. +// Besides memory (which is reclaimed) all other fields of 'picture' are +// preserved. +WEBP_EXTERN(void) WebPPictureFree(WebPPicture* picture); + +// Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, *dst +// will fully own the copied pixels (this is not a view). The 'dst' picture need +// not be initialized as its content is overwritten. +// Returns false in case of memory allocation error. +WEBP_EXTERN(int) WebPPictureCopy(const WebPPicture* src, WebPPicture* dst); + +// Compute PSNR, SSIM or LSIM distortion metric between two pictures. Results +// are in dB, stored in result[] in the Y/U/V/Alpha/All or B/G/R/A/All order. +// Returns false in case of error (src and ref don't have same dimension, ...) +// Warning: this function is rather CPU-intensive. +WEBP_EXTERN(int) WebPPictureDistortion( + const WebPPicture* src, const WebPPicture* ref, + int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM + float result[5]); + +// self-crops a picture to the rectangle defined by top/left/width/height. +// Returns false in case of memory allocation error, or if the rectangle is +// outside of the source picture. +// The rectangle for the view is defined by the top-left corner pixel +// coordinates (left, top) as well as its width and height. This rectangle +// must be fully be comprised inside the 'src' source picture. If the source +// picture uses the YUV420 colorspace, the top and left coordinates will be +// snapped to even values. +WEBP_EXTERN(int) WebPPictureCrop(WebPPicture* picture, + int left, int top, int width, int height); + +// Extracts a view from 'src' picture into 'dst'. The rectangle for the view +// is defined by the top-left corner pixel coordinates (left, top) as well +// as its width and height. This rectangle must be fully be comprised inside +// the 'src' source picture. If the source picture uses the YUV420 colorspace, +// the top and left coordinates will be snapped to even values. +// Picture 'src' must out-live 'dst' picture. Self-extraction of view is allowed +// ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so, +// the original dimension will be lost). Picture 'dst' need not be initialized +// with WebPPictureInit() if it is different from 'src', since its content will +// be overwritten. +// Returns false in case of memory allocation error or invalid parameters. +WEBP_EXTERN(int) WebPPictureView(const WebPPicture* src, + int left, int top, int width, int height, + WebPPicture* dst); + +// Returns true if the 'picture' is actually a view and therefore does +// not own the memory for pixels. +WEBP_EXTERN(int) WebPPictureIsView(const WebPPicture* picture); + +// Rescale a picture to new dimension width x height. +// If either 'width' or 'height' (but not both) is 0 the corresponding +// dimension will be calculated preserving the aspect ratio. +// No gamma correction is applied. +// Returns false in case of error (invalid parameter or insufficient memory). +WEBP_EXTERN(int) WebPPictureRescale(WebPPicture* pic, int width, int height); + +// Colorspace conversion function to import RGB samples. +// Previous buffer will be free'd, if any. +// *rgb buffer should have a size of at least height * rgb_stride. +// Returns false in case of memory error. +WEBP_EXTERN(int) WebPPictureImportRGB( + WebPPicture* picture, const uint8_t* rgb, int rgb_stride); +// Same, but for RGBA buffer. +WEBP_EXTERN(int) WebPPictureImportRGBA( + WebPPicture* picture, const uint8_t* rgba, int rgba_stride); +// Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format +// input buffer ignoring the alpha channel. Avoids needing to copy the data +// to a temporary 24-bit RGB buffer to import the RGB only. +WEBP_EXTERN(int) WebPPictureImportRGBX( + WebPPicture* picture, const uint8_t* rgbx, int rgbx_stride); + +// Variants of the above, but taking BGR(A|X) input. +WEBP_EXTERN(int) WebPPictureImportBGR( + WebPPicture* picture, const uint8_t* bgr, int bgr_stride); +WEBP_EXTERN(int) WebPPictureImportBGRA( + WebPPicture* picture, const uint8_t* bgra, int bgra_stride); +WEBP_EXTERN(int) WebPPictureImportBGRX( + WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride); + +// Converts picture->argb data to the YUV420A format. The 'colorspace' +// parameter is deprecated and should be equal to WEBP_YUV420. +// Upon return, picture->use_argb is set to false. The presence of real +// non-opaque transparent values is detected, and 'colorspace' will be +// adjusted accordingly. Note that this method is lossy. +// Returns false in case of error. +WEBP_EXTERN(int) WebPPictureARGBToYUVA(WebPPicture* picture, + WebPEncCSP /*colorspace = WEBP_YUV420*/); + +// Same as WebPPictureARGBToYUVA(), but the conversion is done using +// pseudo-random dithering with a strength 'dithering' between +// 0.0 (no dithering) and 1.0 (maximum dithering). This is useful +// for photographic picture. +WEBP_EXTERN(int) WebPPictureARGBToYUVADithered( + WebPPicture* picture, WebPEncCSP colorspace, float dithering); + +// Performs 'smart' RGBA->YUVA420 downsampling and colorspace conversion. +// Downsampling is handled with extra care in case of color clipping. This +// method is roughly 2x slower than WebPPictureARGBToYUVA() but produces better +// YUV representation. +// Returns false in case of error. +WEBP_EXTERN(int) WebPPictureSmartARGBToYUVA(WebPPicture* picture); + +// Converts picture->yuv to picture->argb and sets picture->use_argb to true. +// The input format must be YUV_420 or YUV_420A. +// Note that the use of this method is discouraged if one has access to the +// raw ARGB samples, since using YUV420 is comparatively lossy. Also, the +// conversion from YUV420 to ARGB incurs a small loss too. +// Returns false in case of error. +WEBP_EXTERN(int) WebPPictureYUVAToARGB(WebPPicture* picture); + +// Helper function: given a width x height plane of RGBA or YUV(A) samples +// clean-up the YUV or RGB samples under fully transparent area, to help +// compressibility (no guarantee, though). +WEBP_EXTERN(void) WebPCleanupTransparentArea(WebPPicture* picture); + +// Scan the picture 'picture' for the presence of non fully opaque alpha values. +// Returns true in such case. Otherwise returns false (indicating that the +// alpha plane can be ignored altogether e.g.). +WEBP_EXTERN(int) WebPPictureHasTransparency(const WebPPicture* picture); + +// Remove the transparency information (if present) by blending the color with +// the background color 'background_rgb' (specified as 24bit RGB triplet). +// After this call, all alpha values are reset to 0xff. +WEBP_EXTERN(void) WebPBlendAlpha(WebPPicture* pic, uint32_t background_rgb); + +//------------------------------------------------------------------------------ +// Main call + +// Main encoding call, after config and picture have been initialized. +// 'picture' must be less than 16384x16384 in dimension (cf WEBP_MAX_DIMENSION), +// and the 'config' object must be a valid one. +// Returns false in case of error, true otherwise. +// In case of error, picture->error_code is updated accordingly. +// 'picture' can hold the source samples in both YUV(A) or ARGB input, depending +// on the value of 'picture->use_argb'. It is highly recommended to use +// the former for lossy encoding, and the latter for lossless encoding +// (when config.lossless is true). Automatic conversion from one format to +// another is provided but they both incur some loss. +WEBP_EXTERN(int) WebPEncode(const WebPConfig* config, WebPPicture* picture); + +//------------------------------------------------------------------------------ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* WEBP_WEBP_ENCODE_H_ */ diff --git a/android/x86/include/webp/types.h b/android/x86/include/webp/types.h new file mode 100644 index 00000000..98fff35a --- /dev/null +++ b/android/x86/include/webp/types.h @@ -0,0 +1,52 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// Common types +// +// Author: Skal (pascal.massimino@gmail.com) + +#ifndef WEBP_WEBP_TYPES_H_ +#define WEBP_WEBP_TYPES_H_ + +#include <stddef.h> // for size_t + +#ifndef _MSC_VER +#include <inttypes.h> +#if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) +#define WEBP_INLINE inline +#else +#define WEBP_INLINE +#endif +#else +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; +typedef long long int int64_t; +#define WEBP_INLINE __forceinline +#endif /* _MSC_VER */ + +#ifndef WEBP_EXTERN +// This explicitly marks library functions and allows for changing the +// signature for e.g., Windows DLL builds. +# if defined(__GNUC__) && __GNUC__ >= 4 +# define WEBP_EXTERN(type) extern __attribute__ ((visibility ("default"))) type +# else +# define WEBP_EXTERN(type) extern type +# endif /* __GNUC__ >= 4 */ +#endif /* WEBP_EXTERN */ + +// Macro to check ABI compatibility (same major revision number) +#define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8)) + +#endif /* WEBP_WEBP_TYPES_H_ */ diff --git a/android/x86/include/websockets/libwebsockets.h b/android/x86/include/websockets/libwebsockets.h new file mode 100644 index 00000000..7efeba1f --- /dev/null +++ b/android/x86/include/websockets/libwebsockets.h @@ -0,0 +1,4196 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation: + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +/** @file */ + +#ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C +#define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C + +#ifdef __cplusplus +#include <cstddef> +#include <cstdarg> +#ifdef MBED_OPERATORS +#include "mbed-drivers/mbed.h" +#include "sal-iface-eth/EthernetInterface.h" +#include "sockets/TCPListener.h" +#include "sal-stack-lwip/lwipv4_init.h" + +namespace { +} +using namespace mbed::Sockets::v0; + + +struct sockaddr_in; +struct lws; + +class lws_conn { + public: + lws_conn(): + ts(NULL), + wsi(NULL), + writeable(1), + awaiting_on_writeable(0) + { + } + +public: + void set_wsi(struct lws *_wsi) { wsi = _wsi; } + int actual_onRX(Socket *s); + void onRX(Socket *s); + void onError(Socket *s, socket_error_t err); + void onDisconnect(TCPStream *s); + void onSent(Socket *s, uint16_t len); + void serialized_writeable(struct lws *wsi); + +public: + TCPStream *ts; + +public: + struct lws *wsi; + char writeable; + char awaiting_on_writeable; +}; + +class lws_conn_listener : lws_conn { +public: + lws_conn_listener(): + srv(SOCKET_STACK_LWIP_IPV4) + { + srv.setOnError(TCPStream::ErrorHandler_t(this, + &lws_conn_listener::onError)); + } + + void start(const uint16_t port); /**< start listening */ + +protected: + void onRX(Socket *s); /**< incoming data ready */ + void onError(Socket *s, socket_error_t err); /**< if error occurs */ + void onIncoming(TCPListener *s, void *impl); /**< new connection */ + void onDisconnect(TCPStream *s); /**< disconnection */ + +public: + TCPListener srv; +}; + +#endif + +extern "C" { +#else +#include <stdarg.h> +#endif + +#if defined(MBED_OPERATORS) || defined(LWS_WITH_ESP8266) +struct sockaddr_in; +#define LWS_POSIX 0 +#else +#define LWS_POSIX 1 +#endif + +#include "lws_config.h" + +#if defined(WIN32) || defined(_WIN32) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include <winsock2.h> +#include <ws2tcpip.h> +#include <stddef.h> +#include <basetsd.h> +#ifndef _WIN32_WCE +#include <fcntl.h> +#else +#define _O_RDONLY 0x0000 +#define O_RDONLY _O_RDONLY +#endif + +// Visual studio older than 2015 and WIN_CE has only _stricmp +#if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE) +#define strcasecmp _stricmp +#else +#define strcasecmp stricmp +#endif +#define getdtablesize() 30000 + +#define LWS_INLINE __inline +#define LWS_VISIBLE +#define LWS_WARN_UNUSED_RESULT +#define LWS_WARN_DEPRECATED + +#ifdef LWS_DLL +#ifdef LWS_INTERNAL +#define LWS_EXTERN extern __declspec(dllexport) +#else +#define LWS_EXTERN extern __declspec(dllimport) +#endif +#else +#define LWS_EXTERN +#endif + +#define LWS_INVALID_FILE INVALID_HANDLE_VALUE +#define LWS_O_RDONLY _O_RDONLY + +#if !defined(_MSC_VER) || _MSC_VER < 1900 /* Visual Studio 2015 already defines this in <stdio.h> */ +#define lws_snprintf _snprintf +#endif + +#ifndef __func__ +#define __func__ __FUNCTION__ +#endif + +#else /* NOT WIN32 */ +#include <unistd.h> + +#if defined(__NetBSD__) || defined(__FreeBSD__) +#include <netinet/in.h> +#endif + +#define LWS_INLINE inline +#define LWS_O_RDONLY O_RDONLY + +#if !defined(MBED_OPERATORS) && !defined(LWS_WITH_ESP8266) +#include <poll.h> +#include <netdb.h> +#define LWS_INVALID_FILE -1 +#else +#define getdtablesize() (20) +#define LWS_INVALID_FILE NULL +#endif + +#if defined(__GNUC__) + +/* warn_unused_result attribute only supported by GCC 3.4 or later */ +#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +#define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else +#define LWS_WARN_UNUSED_RESULT +#endif + +#define LWS_VISIBLE __attribute__((visibility("default"))) +#define LWS_WARN_DEPRECATED __attribute__ ((deprecated)) +#else +#define LWS_VISIBLE +#define LWS_WARN_UNUSED_RESULT +#define LWS_WARN_DEPRECATED +#endif + +#if defined(__ANDROID__) +#include <unistd.h> +#define getdtablesize() sysconf(_SC_OPEN_MAX) +#endif + +#endif + +#ifdef LWS_USE_LIBEV +#include <ev.h> +#endif /* LWS_USE_LIBEV */ +#ifdef LWS_USE_LIBUV +#include <uv.h> +#ifdef LWS_HAVE_UV_VERSION_H +#include <uv-version.h> +#endif +#endif /* LWS_USE_LIBUV */ + +#ifndef LWS_EXTERN +#define LWS_EXTERN extern +#endif + +#ifdef _WIN32 +#define random rand +#else +#include <sys/time.h> +#include <unistd.h> +#endif + +#ifdef LWS_OPENSSL_SUPPORT + +#ifdef USE_WOLFSSL +#ifdef USE_OLD_CYASSL +#include <cyassl/openssl/ssl.h> +#include <cyassl/error-ssl.h> +#else +#include <wolfssl/openssl/ssl.h> +#include <wolfssl/error-ssl.h> +#endif /* not USE_OLD_CYASSL */ +#else +#if defined(LWS_USE_POLARSSL) +#include <polarssl/ssl.h> +struct lws_polarssl_context { + x509_crt ca; /**< ca */ + x509_crt certificate; /**< cert */ + rsa_context key; /**< key */ +}; +typedef struct lws_polarssl_context SSL_CTX; +typedef ssl_context SSL; +#else +#if defined(LWS_USE_MBEDTLS) +#include <mbedtls/ssl.h> +#else +#include <openssl/ssl.h> +#include <openssl/err.h> +#endif /* not USE_MBEDTLS */ +#endif /* not USE_POLARSSL */ +#endif /* not USE_WOLFSSL */ +#endif + + +#define CONTEXT_PORT_NO_LISTEN -1 + +/** \defgroup log Logging + * + * ##Logging + * + * Lws provides flexible and filterable logging facilities, which can be + * used inside lws and in user code. + * + * Log categories may be individually filtered bitwise, and directed to built-in + * sinks for syslog-compatible logging, or a user-defined function. + */ +///@{ + +enum lws_log_levels { + LLL_ERR = 1 << 0, + LLL_WARN = 1 << 1, + LLL_NOTICE = 1 << 2, + LLL_INFO = 1 << 3, + LLL_DEBUG = 1 << 4, + LLL_PARSER = 1 << 5, + LLL_HEADER = 1 << 6, + LLL_EXT = 1 << 7, + LLL_CLIENT = 1 << 8, + LLL_LATENCY = 1 << 9, + + LLL_COUNT = 10 /* set to count of valid flags */ +}; + +LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...); +LWS_VISIBLE LWS_EXTERN void _lws_logv(int filter, const char *format, va_list vl); +/** + * lwsl_timestamp: generate logging timestamp string + * + * \param level: logging level + * \param p: char * buffer to take timestamp + * \param len: length of p + * + * returns length written in p + */ +LWS_VISIBLE LWS_EXTERN int +lwsl_timestamp(int level, char *p, int len); + +#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__) + +#if !defined(LWS_WITH_NO_LOGS) +/* notice, warn and log are always compiled in */ +#define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) +#define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) +#endif +/* + * weaker logging can be deselected at configure time using --disable-debug + * that gets rid of the overhead of checking while keeping _warn and _err + * active + */ + +#if defined(LWS_WITH_ESP8266) +#undef _DEBUG +#endif + +#ifdef _DEBUG +#if defined(LWS_WITH_NO_LOGS) +/* notice, warn and log are always compiled in */ +//#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__) +#define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) +#define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) +#endif +#define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__) +#define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__) +#define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__) +#define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__) +#define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__) +#define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__) +#define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__) +/** + * lwsl_hexdump() - helper to hexdump a buffer (DEBUG builds only) + * + * \param buf: buffer start to dump + * \param len: length of buffer to dump + */ +LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len); + +#else /* no debug */ +#if defined(LWS_WITH_NO_LOGS) +//#define lwsl_err(...) do {} while(0) +#define lwsl_warn(...) do {} while(0) +#define lwsl_notice(...) do {} while(0) +#endif +#define lwsl_info(...) do {} while(0) +#define lwsl_debug(...) do {} while(0) +#define lwsl_parser(...) do {} while(0) +#define lwsl_header(...) do {} while(0) +#define lwsl_ext(...) do {} while(0) +#define lwsl_client(...) do {} while(0) +#define lwsl_latency(...) do {} while(0) +#define lwsl_hexdump(a, b) + +#endif + +/** + * lws_set_log_level() - Set the logging bitfield + * \param level: OR together the LLL_ debug contexts you want output from + * \param log_emit_function: NULL to leave it as it is, or a user-supplied + * function to perform log string emission instead of + * the default stderr one. + * + * log level defaults to "err", "warn" and "notice" contexts enabled and + * emission on stderr. + */ +LWS_VISIBLE LWS_EXTERN void +lws_set_log_level(int level, + void (*log_emit_function)(int level, const char *line)); + +/** + * lwsl_emit_syslog() - helper log emit function writes to system log + * + * \param level: one of LLL_ log level indexes + * \param line: log string + * + * You use this by passing the function pointer to lws_set_log_level(), to set + * it as the log emit function, it is not called directly. + */ +LWS_VISIBLE LWS_EXTERN void +lwsl_emit_syslog(int level, const char *line); + +///@} + + +#include <stddef.h> + +#ifndef lws_container_of +#define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M))) +#endif + + +struct lws; +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#endif + +/* api change list for user code to test against */ + +#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG + +/* the struct lws_protocols has the id field present */ +#define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD + +/* you can call lws_get_peer_write_allowance */ +#define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE + +/* extra parameter introduced in 917f43ab821 */ +#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN + +/* File operations stuff exists */ +#define LWS_FEATURE_FOPS + + +#if defined(_WIN32) +typedef SOCKET lws_sockfd_type; +typedef HANDLE lws_filefd_type; +#define lws_sockfd_valid(sfd) (!!sfd) +struct lws_pollfd { + lws_sockfd_type fd; /**< file descriptor */ + SHORT events; /**< which events to respond to */ + SHORT revents; /**< which events happened */ +}; +#define LWS_POLLHUP (FD_CLOSE) +#define LWS_POLLIN (FD_READ | FD_ACCEPT) +#define LWS_POLLOUT (FD_WRITE) +#else + +#if defined(MBED_OPERATORS) +/* it's a class lws_conn * */ +typedef void * lws_sockfd_type; +typedef void * lws_filefd_type; +#define lws_sockfd_valid(sfd) (!!sfd) +struct pollfd { + lws_sockfd_type fd; /**< fd related to */ + short events; /**< which POLL... events to respond to */ + short revents; /**< which POLL... events occurred */ +}; +#define POLLIN 0x0001 +#define POLLPRI 0x0002 +#define POLLOUT 0x0004 +#define POLLERR 0x0008 +#define POLLHUP 0x0010 +#define POLLNVAL 0x0020 + +struct lws; + +void * mbed3_create_tcp_stream_socket(void); +void mbed3_delete_tcp_stream_socket(void *sockfd); +void mbed3_tcp_stream_bind(void *sock, int port, struct lws *); +void mbed3_tcp_stream_accept(void *sock, struct lws *); +#else +#if defined(LWS_WITH_ESP8266) + +#include <user_interface.h> +#include <espconn.h> + +typedef struct espconn * lws_sockfd_type; +typedef void * lws_filefd_type; +#define lws_sockfd_valid(sfd) (!!sfd) +struct pollfd { + lws_sockfd_type fd; /**< fd related to */ + short events; /**< which POLL... events to respond to */ + short revents; /**< which POLL... events occurred */ +}; +#define POLLIN 0x0001 +#define POLLPRI 0x0002 +#define POLLOUT 0x0004 +#define POLLERR 0x0008 +#define POLLHUP 0x0010 +#define POLLNVAL 0x0020 + +struct lws_vhost; + +lws_sockfd_type esp8266_create_tcp_listen_socket(struct lws_vhost *vh); +void esp8266_tcp_stream_accept(lws_sockfd_type fd, struct lws *wsi); + +#include <os_type.h> +#include <osapi.h> +#include "ets_sys.h" + +int ets_snprintf(char *str, size_t size, const char *format, ...); +#define snprintf ets_snprintf + +typedef os_timer_t uv_timer_t; +typedef void uv_cb_t(uv_timer_t *); + +void os_timer_disarm(void *); +void os_timer_setfn(os_timer_t *, os_timer_func_t *, void *); + +void ets_timer_arm_new(os_timer_t *, int, int, int); + +//void os_timer_arm(os_timer_t *, int, int); + +#define UV_VERSION_MAJOR 1 + +#define lws_uv_getloop(a, b) (NULL) + +static inline void uv_timer_init(void *l, uv_timer_t *t) +{ + (void)l; + memset(t, 0, sizeof(*t)); + os_timer_disarm(t); +} + +static inline void uv_timer_start(uv_timer_t *t, uv_cb_t *cb, int first, int rep) +{ + os_timer_setfn(t, (os_timer_func_t *)cb, t); + /* ms, repeat */ + os_timer_arm(t, first, !!rep); +} + +static inline void uv_timer_stop(uv_timer_t *t) +{ + os_timer_disarm(t); +} + +#else +typedef int lws_sockfd_type; +typedef int lws_filefd_type; +#define lws_sockfd_valid(sfd) (sfd >= 0) +#endif +#endif + +#define lws_pollfd pollfd +#define LWS_POLLHUP (POLLHUP|POLLERR) +#define LWS_POLLIN (POLLIN) +#define LWS_POLLOUT (POLLOUT) +#endif + +/** struct lws_pollargs - argument structure for all external poll related calls + * passed in via 'in' */ +struct lws_pollargs { + lws_sockfd_type fd; /**< applicable socket descriptor */ + int events; /**< the new event mask */ + int prev_events; /**< the previous event mask */ +}; + +struct lws_tokens; +struct lws_token_limits; + +/*! \defgroup wsclose Websocket Close + * + * ##Websocket close frame control + * + * When we close a ws connection, we can send a reason code and a short + * UTF-8 description back with the close packet. + */ +///@{ + +/* + * NOTE: These public enums are part of the abi. If you want to add one, + * add it at where specified so existing users are unaffected. + */ +/** enum lws_close_status - RFC6455 close status codes */ +enum lws_close_status { + LWS_CLOSE_STATUS_NOSTATUS = 0, + LWS_CLOSE_STATUS_NORMAL = 1000, + /**< 1000 indicates a normal closure, meaning that the purpose for + which the connection was established has been fulfilled. */ + LWS_CLOSE_STATUS_GOINGAWAY = 1001, + /**< 1001 indicates that an endpoint is "going away", such as a server + going down or a browser having navigated away from a page. */ + LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002, + /**< 1002 indicates that an endpoint is terminating the connection due + to a protocol error. */ + LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003, + /**< 1003 indicates that an endpoint is terminating the connection + because it has received a type of data it cannot accept (e.g., an + endpoint that understands only text data MAY send this if it + receives a binary message). */ + LWS_CLOSE_STATUS_RESERVED = 1004, + /**< Reserved. The specific meaning might be defined in the future. */ + LWS_CLOSE_STATUS_NO_STATUS = 1005, + /**< 1005 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that no status + code was actually present. */ + LWS_CLOSE_STATUS_ABNORMAL_CLOSE = 1006, + /**< 1006 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that the + connection was closed abnormally, e.g., without sending or + receiving a Close control frame. */ + LWS_CLOSE_STATUS_INVALID_PAYLOAD = 1007, + /**< 1007 indicates that an endpoint is terminating the connection + because it has received data within a message that was not + consistent with the type of the message (e.g., non-UTF-8 [RFC3629] + data within a text message). */ + LWS_CLOSE_STATUS_POLICY_VIOLATION = 1008, + /**< 1008 indicates that an endpoint is terminating the connection + because it has received a message that violates its policy. This + is a generic status code that can be returned when there is no + other more suitable status code (e.g., 1003 or 1009) or if there + is a need to hide specific details about the policy. */ + LWS_CLOSE_STATUS_MESSAGE_TOO_LARGE = 1009, + /**< 1009 indicates that an endpoint is terminating the connection + because it has received a message that is too big for it to + process. */ + LWS_CLOSE_STATUS_EXTENSION_REQUIRED = 1010, + /**< 1010 indicates that an endpoint (client) is terminating the + connection because it has expected the server to negotiate one or + more extension, but the server didn't return them in the response + message of the WebSocket handshake. The list of extensions that + are needed SHOULD appear in the /reason/ part of the Close frame. + Note that this status code is not used by the server, because it + can fail the WebSocket handshake instead */ + LWS_CLOSE_STATUS_UNEXPECTED_CONDITION = 1011, + /**< 1011 indicates that a server is terminating the connection because + it encountered an unexpected condition that prevented it from + fulfilling the request. */ + LWS_CLOSE_STATUS_TLS_FAILURE = 1015, + /**< 1015 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that the + connection was closed due to a failure to perform a TLS handshake + (e.g., the server certificate can't be verified). */ + + /****** add new things just above ---^ ******/ + + LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY = 9999, +}; + +/** + * lws_close_reason - Set reason and aux data to send with Close packet + * If you are going to return nonzero from the callback + * requesting the connection to close, you can optionally + * call this to set the reason the peer will be told if + * possible. + * + * \param wsi: The websocket connection to set the close reason on + * \param status: A valid close status from websocket standard + * \param buf: NULL or buffer containing up to 124 bytes of auxiliary data + * \param len: Length of data in \param buf to send + */ +LWS_VISIBLE LWS_EXTERN void +lws_close_reason(struct lws *wsi, enum lws_close_status status, + unsigned char *buf, size_t len); + +///@} + +struct lws; +struct lws_context; +/* needed even with extensions disabled for create context */ +struct lws_extension; + +/*! \defgroup usercb User Callback + * + * ##User protocol callback + * + * The protocol callback is the primary way lws interacts with + * user code. For one of a list of a few dozen reasons the callback gets + * called at some event to be handled. + * + * All of the events can be ignored, returning 0 is taken as "OK" and returning + * nonzero in most cases indicates that the connection should be closed. + */ +///@{ + + +/* + * NOTE: These public enums are part of the abi. If you want to add one, + * add it at where specified so existing users are unaffected. + */ +/** enum lws_callback_reasons - reason you're getting a protocol callback */ +enum lws_callback_reasons { + LWS_CALLBACK_ESTABLISHED = 0, + /**< (VH) after the server completes a handshake with an incoming + * client. If you built the library with ssl support, in is a + * pointer to the ssl struct associated with the connection or NULL.*/ + LWS_CALLBACK_CLIENT_CONNECTION_ERROR = 1, + /**< the request client connection has been unable to complete a + * handshake with the remote server. If in is non-NULL, you can + * find an error string of length len where it points to + * + * Diagnostic strings that may be returned include + * + * "getaddrinfo (ipv6) failed" + * "unknown address family" + * "getaddrinfo (ipv4) failed" + * "set socket opts failed" + * "insert wsi failed" + * "lws_ssl_client_connect1 failed" + * "lws_ssl_client_connect2 failed" + * "Peer hung up" + * "read failed" + * "HS: URI missing" + * "HS: Redirect code but no Location" + * "HS: URI did not parse" + * "HS: Redirect failed" + * "HS: Server did not return 200" + * "HS: OOM" + * "HS: disallowed by client filter" + * "HS: disallowed at ESTABLISHED" + * "HS: ACCEPT missing" + * "HS: ws upgrade response not 101" + * "HS: UPGRADE missing" + * "HS: Upgrade to something other than websocket" + * "HS: CONNECTION missing" + * "HS: UPGRADE malformed" + * "HS: PROTOCOL malformed" + * "HS: Cannot match protocol" + * "HS: EXT: list too big" + * "HS: EXT: failed setting defaults" + * "HS: EXT: failed parsing defaults" + * "HS: EXT: failed parsing options" + * "HS: EXT: Rejects server options" + * "HS: EXT: unknown ext" + * "HS: Accept hash wrong" + * "HS: Rejected by filter cb" + * "HS: OOM" + * "HS: SO_SNDBUF failed" + * "HS: Rejected at CLIENT_ESTABLISHED" + */ + LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH = 2, + /**< this is the last chance for the client user code to examine the + * http headers and decide to reject the connection. If the + * content in the headers is interesting to the + * client (url, etc) it needs to copy it out at + * this point since it will be destroyed before + * the CLIENT_ESTABLISHED call */ + LWS_CALLBACK_CLIENT_ESTABLISHED = 3, + /**< after your client connection completed + * a handshake with the remote server */ + LWS_CALLBACK_CLOSED = 4, + /**< when the websocket session ends */ + LWS_CALLBACK_CLOSED_HTTP = 5, + /**< when a HTTP (non-websocket) session ends */ + LWS_CALLBACK_RECEIVE = 6, + /**< data has appeared for this server endpoint from a + * remote client, it can be found at *in and is + * len bytes long */ + LWS_CALLBACK_RECEIVE_PONG = 7, + /**< servers receive PONG packets with this callback reason */ + LWS_CALLBACK_CLIENT_RECEIVE = 8, + /**< data has appeared from the server for the client connection, it + * can be found at *in and is len bytes long */ + LWS_CALLBACK_CLIENT_RECEIVE_PONG = 9, + /**< clients receive PONG packets with this callback reason */ + LWS_CALLBACK_CLIENT_WRITEABLE = 10, + /**< If you call lws_callback_on_writable() on a connection, you will + * get one of these callbacks coming when the connection socket + * is able to accept another write packet without blocking. + * If it already was able to take another packet without blocking, + * you'll get this callback at the next call to the service loop + * function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE + * and servers get LWS_CALLBACK_SERVER_WRITEABLE. */ + LWS_CALLBACK_SERVER_WRITEABLE = 11, + /**< See LWS_CALLBACK_CLIENT_WRITEABLE */ + LWS_CALLBACK_HTTP = 12, + /**< an http request has come from a client that is not + * asking to upgrade the connection to a websocket + * one. This is a chance to serve http content, + * for example, to send a script to the client + * which will then open the websockets connection. + * in points to the URI path requested and + * lws_serve_http_file() makes it very + * simple to send back a file to the client. + * Normally after sending the file you are done + * with the http connection, since the rest of the + * activity will come by websockets from the script + * that was delivered by http, so you will want to + * return 1; to close and free up the connection. */ + LWS_CALLBACK_HTTP_BODY = 13, + /**< the next len bytes data from the http + * request body HTTP connection is now available in in. */ + LWS_CALLBACK_HTTP_BODY_COMPLETION = 14, + /**< the expected amount of http request body has been delivered */ + LWS_CALLBACK_HTTP_FILE_COMPLETION = 15, + /**< a file requested to be sent down http link has completed. */ + LWS_CALLBACK_HTTP_WRITEABLE = 16, + /**< you can write more down the http protocol link now. */ + LWS_CALLBACK_FILTER_NETWORK_CONNECTION = 17, + /**< called when a client connects to + * the server at network level; the connection is accepted but then + * passed to this callback to decide whether to hang up immediately + * or not, based on the client IP. in contains the connection + * socket's descriptor. Since the client connection information is + * not available yet, wsi still pointing to the main server socket. + * Return non-zero to terminate the connection before sending or + * receiving anything. Because this happens immediately after the + * network connection from the client, there's no websocket protocol + * selected yet so this callback is issued only to protocol 0. */ + LWS_CALLBACK_FILTER_HTTP_CONNECTION = 18, + /**< called when the request has + * been received and parsed from the client, but the response is + * not sent yet. Return non-zero to disallow the connection. + * user is a pointer to the connection user space allocation, + * in is the URI, eg, "/" + * In your handler you can use the public APIs + * lws_hdr_total_length() / lws_hdr_copy() to access all of the + * headers using the header enums lws_token_indexes from + * libwebsockets.h to check for and read the supported header + * presence and content before deciding to allow the http + * connection to proceed or to kill the connection. */ + LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED = 19, + /**< A new client just had + * been connected, accepted, and instantiated into the pool. This + * callback allows setting any relevant property to it. Because this + * happens immediately after the instantiation of a new client, + * there's no websocket protocol selected yet so this callback is + * issued only to protocol 0. Only wsi is defined, pointing to the + * new client, and the return value is ignored. */ + LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION = 20, + /**< called when the handshake has + * been received and parsed from the client, but the response is + * not sent yet. Return non-zero to disallow the connection. + * user is a pointer to the connection user space allocation, + * in is the requested protocol name + * In your handler you can use the public APIs + * lws_hdr_total_length() / lws_hdr_copy() to access all of the + * headers using the header enums lws_token_indexes from + * libwebsockets.h to check for and read the supported header + * presence and content before deciding to allow the handshake + * to proceed or to kill the connection. */ + LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS = 21, + /**< if configured for + * including OpenSSL support, this callback allows your user code + * to perform extra SSL_CTX_load_verify_locations() or similar + * calls to direct OpenSSL where to find certificates the client + * can use to confirm the remote server identity. user is the + * OpenSSL SSL_CTX* */ + LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS = 22, + /**< if configured for + * including OpenSSL support, this callback allows your user code + * to load extra certifcates into the server which allow it to + * verify the validity of certificates returned by clients. user + * is the server's OpenSSL SSL_CTX* */ + LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION = 23, + /**< if the libwebsockets vhost was created with the option + * LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this + * callback is generated during OpenSSL verification of the cert + * sent from the client. It is sent to protocol[0] callback as + * no protocol has been negotiated on the connection yet. + * Notice that the libwebsockets context and wsi are both NULL + * during this callback. See + * http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html + * to understand more detail about the OpenSSL callback that + * generates this libwebsockets callback and the meanings of the + * arguments passed. In this callback, user is the x509_ctx, + * in is the ssl pointer and len is preverify_ok + * Notice that this callback maintains libwebsocket return + * conventions, return 0 to mean the cert is OK or 1 to fail it. + * This also means that if you don't handle this callback then + * the default callback action of returning 0 allows the client + * certificates. */ + LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER = 24, + /**< this callback happens + * when a client handshake is being compiled. user is NULL, + * in is a char **, it's pointing to a char * which holds the + * next location in the header buffer where you can add + * headers, and len is the remaining space in the header buffer, + * which is typically some hundreds of bytes. So, to add a canned + * cookie, your handler code might look similar to: + * + * char **p = (char **)in; + * + * if (len < 100) + * return 1; + * + * *p += sprintf(*p, "Cookie: a=b\x0d\x0a"); + * + * return 0; + * + * Notice if you add anything, you just have to take care about + * the CRLF on the line you added. Obviously this callback is + * optional, if you don't handle it everything is fine. + * + * Notice the callback is coming to protocols[0] all the time, + * because there is no specific protocol negotiated yet. */ + LWS_CALLBACK_CONFIRM_EXTENSION_OKAY = 25, + /**< When the server handshake code + * sees that it does support a requested extension, before + * accepting the extension by additing to the list sent back to + * the client it gives this callback just to check that it's okay + * to use that extension. It calls back to the requested protocol + * and with in being the extension name, len is 0 and user is + * valid. Note though at this time the ESTABLISHED callback hasn't + * happened yet so if you initialize user content there, user + * content during this callback might not be useful for anything. + * Notice this callback comes to protocols[0]. */ + LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED = 26, + /**< When a client + * connection is being prepared to start a handshake to a server, + * each supported extension is checked with protocols[0] callback + * with this reason, giving the user code a chance to suppress the + * claim to support that extension by returning non-zero. If + * unhandled, by default 0 will be returned and the extension + * support included in the header to the server. Notice this + * callback comes to protocols[0]. */ + LWS_CALLBACK_PROTOCOL_INIT = 27, + /**< One-time call per protocol, per-vhost using it, so it can + * do initial setup / allocations etc */ + LWS_CALLBACK_PROTOCOL_DESTROY = 28, + /**< One-time call per protocol, per-vhost using it, indicating + * this protocol won't get used at all after this callback, the + * vhost is getting destroyed. Take the opportunity to + * deallocate everything that was allocated by the protocol. */ + LWS_CALLBACK_WSI_CREATE = 29, + /**< outermost (earliest) wsi create notification to protocols[0] */ + LWS_CALLBACK_WSI_DESTROY = 30, + /**< outermost (latest) wsi destroy notification to protocols[0] */ + LWS_CALLBACK_GET_THREAD_ID = 31, + /**< lws can accept callback when writable requests from other + * threads, if you implement this callback and return an opaque + * current thread ID integer. */ + + /* external poll() management support */ + LWS_CALLBACK_ADD_POLL_FD = 32, + /**< lws normally deals with its poll() or other event loop + * internally, but in the case you are integrating with another + * server you will need to have lws sockets share a + * polling array with the other server. This and the other + * POLL_FD related callbacks let you put your specialized + * poll array interface code in the callback for protocol 0, the + * first protocol you support, usually the HTTP protocol in the + * serving case. + * This callback happens when a socket needs to be + * added to the polling loop: in points to a struct + * lws_pollargs; the fd member of the struct is the file + * descriptor, and events contains the active events + * + * If you are using the internal lws polling / event loop + * you can just ignore these callbacks. */ + LWS_CALLBACK_DEL_POLL_FD = 33, + /**< This callback happens when a socket descriptor + * needs to be removed from an external polling array. in is + * again the struct lws_pollargs containing the fd member + * to be removed. If you are using the internal polling + * loop, you can just ignore it. */ + LWS_CALLBACK_CHANGE_MODE_POLL_FD = 34, + /**< This callback happens when lws wants to modify the events for + * a connection. + * in is the struct lws_pollargs with the fd to change. + * The new event mask is in events member and the old mask is in + * the prev_events member. + * If you are using the internal polling loop, you can just ignore + * it. */ + LWS_CALLBACK_LOCK_POLL = 35, + /**< These allow the external poll changes driven + * by lws to participate in an external thread locking + * scheme around the changes, so the whole thing is threadsafe. + * These are called around three activities in the library, + * - inserting a new wsi in the wsi / fd table (len=1) + * - deleting a wsi from the wsi / fd table (len=1) + * - changing a wsi's POLLIN/OUT state (len=0) + * Locking and unlocking external synchronization objects when + * len == 1 allows external threads to be synchronized against + * wsi lifecycle changes if it acquires the same lock for the + * duration of wsi dereference from the other thread context. */ + LWS_CALLBACK_UNLOCK_POLL = 36, + /**< See LWS_CALLBACK_LOCK_POLL, ignore if using lws internal poll */ + + LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY = 37, + /**< if configured for including OpenSSL support but no private key + * file has been specified (ssl_private_key_filepath is NULL), this is + * called to allow the user to set the private key directly via + * libopenssl and perform further operations if required; this might be + * useful in situations where the private key is not directly accessible + * by the OS, for example if it is stored on a smartcard. + * user is the server's OpenSSL SSL_CTX* */ + LWS_CALLBACK_WS_PEER_INITIATED_CLOSE = 38, + /**< The peer has sent an unsolicited Close WS packet. in and + * len are the optional close code (first 2 bytes, network + * order) and the optional additional information which is not + * defined in the standard, and may be a string or non-human- readable data. + * If you return 0 lws will echo the close and then close the + * connection. If you return nonzero lws will just close the + * connection. */ + + LWS_CALLBACK_WS_EXT_DEFAULTS = 39, + /**< */ + + LWS_CALLBACK_CGI = 40, + /**< */ + LWS_CALLBACK_CGI_TERMINATED = 41, + /**< */ + LWS_CALLBACK_CGI_STDIN_DATA = 42, + /**< */ + LWS_CALLBACK_CGI_STDIN_COMPLETED = 43, + /**< */ + LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP = 44, + /**< */ + LWS_CALLBACK_CLOSED_CLIENT_HTTP = 45, + /**< */ + LWS_CALLBACK_RECEIVE_CLIENT_HTTP = 46, + /**< */ + LWS_CALLBACK_COMPLETED_CLIENT_HTTP = 47, + /**< */ + LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ = 48, + /**< */ + LWS_CALLBACK_HTTP_BIND_PROTOCOL = 49, + /**< */ + LWS_CALLBACK_HTTP_DROP_PROTOCOL = 50, + /**< */ + LWS_CALLBACK_CHECK_ACCESS_RIGHTS = 51, + /**< */ + LWS_CALLBACK_PROCESS_HTML = 52, + /**< */ + LWS_CALLBACK_ADD_HEADERS = 53, + /**< */ + LWS_CALLBACK_SESSION_INFO = 54, + /**< */ + + LWS_CALLBACK_GS_EVENT = 55, + /**< */ + LWS_CALLBACK_HTTP_PMO = 56, + /**< per-mount options for this connection, called before + * the normal LWS_CALLBACK_HTTP when the mount has per-mount + * options + */ + LWS_CALLBACK_CLIENT_HTTP_WRITEABLE = 57, + /**< when doing an HTTP type client connection, you can call + * lws_client_http_body_pending(wsi, 1) from + * LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER to get these callbacks + * sending the HTTP headers. + * + * From this callback, when you have sent everything, you should let + * lws know by calling lws_client_http_body_pending(wsi, 0) + */ + + /****** add new things just above ---^ ******/ + + LWS_CALLBACK_USER = 1000, + /**< user code can use any including / above without fear of clashes */ +}; + + + +/** + * typedef lws_callback_function() - User server actions + * \param wsi: Opaque websocket instance pointer + * \param reason: The reason for the call + * \param user: Pointer to per-session user data allocated by library + * \param in: Pointer used for some callback reasons + * \param len: Length set for some callback reasons + * + * This callback is the way the user controls what is served. All the + * protocol detail is hidden and handled by the library. + * + * For each connection / session there is user data allocated that is + * pointed to by "user". You set the size of this user data area when + * the library is initialized with lws_create_server. + */ +typedef int +lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len); +///@} + +/*! \defgroup extensions + * + * ##Extension releated functions + * + * Ws defines optional extensions, lws provides the ability to implement these + * in user code if so desired. + * + * We provide one extensions permessage-deflate. + */ +///@{ + +/* + * NOTE: These public enums are part of the abi. If you want to add one, + * add it at where specified so existing users are unaffected. + */ +enum lws_extension_callback_reasons { + LWS_EXT_CB_SERVER_CONTEXT_CONSTRUCT = 0, + LWS_EXT_CB_CLIENT_CONTEXT_CONSTRUCT = 1, + LWS_EXT_CB_SERVER_CONTEXT_DESTRUCT = 2, + LWS_EXT_CB_CLIENT_CONTEXT_DESTRUCT = 3, + LWS_EXT_CB_CONSTRUCT = 4, + LWS_EXT_CB_CLIENT_CONSTRUCT = 5, + LWS_EXT_CB_CHECK_OK_TO_REALLY_CLOSE = 6, + LWS_EXT_CB_CHECK_OK_TO_PROPOSE_EXTENSION = 7, + LWS_EXT_CB_DESTROY = 8, + LWS_EXT_CB_DESTROY_ANY_WSI_CLOSING = 9, + LWS_EXT_CB_ANY_WSI_ESTABLISHED = 10, + LWS_EXT_CB_PACKET_RX_PREPARSE = 11, + LWS_EXT_CB_PACKET_TX_PRESEND = 12, + LWS_EXT_CB_PACKET_TX_DO_SEND = 13, + LWS_EXT_CB_HANDSHAKE_REPLY_TX = 14, + LWS_EXT_CB_FLUSH_PENDING_TX = 15, + LWS_EXT_CB_EXTENDED_PAYLOAD_RX = 16, + LWS_EXT_CB_CAN_PROXY_CLIENT_CONNECTION = 17, + LWS_EXT_CB_1HZ = 18, + LWS_EXT_CB_REQUEST_ON_WRITEABLE = 19, + LWS_EXT_CB_IS_WRITEABLE = 20, + LWS_EXT_CB_PAYLOAD_TX = 21, + LWS_EXT_CB_PAYLOAD_RX = 22, + LWS_EXT_CB_OPTION_DEFAULT = 23, + LWS_EXT_CB_OPTION_SET = 24, + LWS_EXT_CB_OPTION_CONFIRM = 25, + LWS_EXT_CB_NAMED_OPTION_SET = 26, + + /****** add new things just above ---^ ******/ +}; + +/** enum lws_ext_options_types */ +enum lws_ext_options_types { + EXTARG_NONE, /**< does not take an argument */ + EXTARG_DEC, /**< requires a decimal argument */ + EXTARG_OPT_DEC /**< may have an optional decimal argument */ + + /* Add new things just above here ---^ + * This is part of the ABI, don't needlessly break compatibility */ +}; + +/** struct lws_ext_options - Option arguments to the extension. These are + * used in the negotiation at ws upgrade time. + * The helper function lws_ext_parse_options() + * uses these to generate callbacks */ +struct lws_ext_options { + const char *name; /**< Option name, eg, "server_no_context_takeover" */ + enum lws_ext_options_types type; /**< What kind of args the option can take */ + + /* Add new things just above here ---^ + * This is part of the ABI, don't needlessly break compatibility */ +}; + +/** struct lws_ext_option_arg */ +struct lws_ext_option_arg { + const char *option_name; /**< may be NULL, option_index used then */ + int option_index; /**< argument ordinal to use if option_name missing */ + const char *start; /**< value */ + int len; /**< length of value */ +}; + +/** + * typedef lws_extension_callback_function() - Hooks to allow extensions to operate + * \param context: Websockets context + * \param ext: This extension + * \param wsi: Opaque websocket instance pointer + * \param reason: The reason for the call + * \param user: Pointer to ptr to per-session user data allocated by library + * \param in: Pointer used for some callback reasons + * \param len: Length set for some callback reasons + * + * Each extension that is active on a particular connection receives + * callbacks during the connection lifetime to allow the extension to + * operate on websocket data and manage itself. + * + * Libwebsockets takes care of allocating and freeing "user" memory for + * each active extension on each connection. That is what is pointed to + * by the user parameter. + * + * LWS_EXT_CB_CONSTRUCT: called when the server has decided to + * select this extension from the list provided by the client, + * just before the server will send back the handshake accepting + * the connection with this extension active. This gives the + * extension a chance to initialize its connection context found + * in user. + * + * LWS_EXT_CB_CLIENT_CONSTRUCT: same as LWS_EXT_CB_CONSTRUCT + * but called when client is instantiating this extension. Some + * extensions will work the same on client and server side and then + * you can just merge handlers for both CONSTRUCTS. + * + * LWS_EXT_CB_DESTROY: called when the connection the extension was + * being used on is about to be closed and deallocated. It's the + * last chance for the extension to deallocate anything it has + * allocated in the user data (pointed to by user) before the + * user data is deleted. This same callback is used whether you + * are in client or server instantiation context. + * + * LWS_EXT_CB_PACKET_RX_PREPARSE: when this extension was active on + * a connection, and a packet of data arrived at the connection, + * it is passed to this callback to give the extension a chance to + * change the data, eg, decompress it. user is pointing to the + * extension's private connection context data, in is pointing + * to an lws_tokens struct, it consists of a char * pointer called + * token, and an int called token_len. At entry, these are + * set to point to the received buffer and set to the content + * length. If the extension will grow the content, it should use + * a new buffer allocated in its private user context data and + * set the pointed-to lws_tokens members to point to its buffer. + * + * LWS_EXT_CB_PACKET_TX_PRESEND: this works the same way as + * LWS_EXT_CB_PACKET_RX_PREPARSE above, except it gives the + * extension a chance to change websocket data just before it will + * be sent out. Using the same lws_token pointer scheme in in, + * the extension can change the buffer and the length to be + * transmitted how it likes. Again if it wants to grow the + * buffer safely, it should copy the data into its own buffer and + * set the lws_tokens token pointer to it. + * + * LWS_EXT_CB_ARGS_VALIDATE: + */ +typedef int +lws_extension_callback_function(struct lws_context *context, + const struct lws_extension *ext, struct lws *wsi, + enum lws_extension_callback_reasons reason, + void *user, void *in, size_t len); + +/** struct lws_extension - An extension we support */ +struct lws_extension { + const char *name; /**< Formal extension name, eg, "permessage-deflate" */ + lws_extension_callback_function *callback; /**< Service callback */ + const char *client_offer; /**< String containing exts and options client offers */ + + /* Add new things just above here ---^ + * This is part of the ABI, don't needlessly break compatibility */ +}; + +/** + * lws_set_extension_option(): set extension option if possible + * + * \param wsi: websocket connection + * \param ext_name: name of ext, like "permessage-deflate" + * \param opt_name: name of option, like "rx_buf_size" + * \param opt_val: value to set option to + */ +LWS_VISIBLE LWS_EXTERN int +lws_set_extension_option(struct lws *wsi, const char *ext_name, + const char *opt_name, const char *opt_val); + +#ifndef LWS_NO_EXTENSIONS +/* lws_get_internal_extensions() - DEPRECATED + * + * \Deprecated There is no longer a set internal extensions table. The table is provided + * by user code along with application-specific settings. See the test + * client and server for how to do. + */ +static LWS_INLINE LWS_WARN_DEPRECATED const struct lws_extension * +lws_get_internal_extensions() { return NULL; } + +/** + * lws_ext_parse_options() - deal with parsing negotiated extension options + * + * \param ext: related extension struct + * \param wsi: websocket connection + * \param ext_user: per-connection extension private data + * \param opts: list of supported options + * \param o: option string to parse + * \param len: length + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, + void *ext_user, const struct lws_ext_options *opts, + const char *o, int len); +#endif + +/** lws_extension_callback_pm_deflate() - extension for RFC7692 + * + * \param context: lws context + * \param ext: related lws_extension struct + * \param wsi: websocket connection + * \param reason: incoming callback reason + * \param user: per-connection extension private data + * \param in: pointer parameter + * \param len: length parameter + * + * Built-in callback implementing RFC7692 permessage-deflate + */ +LWS_EXTERN +int lws_extension_callback_pm_deflate( + struct lws_context *context, const struct lws_extension *ext, + struct lws *wsi, enum lws_extension_callback_reasons reason, + void *user, void *in, size_t len); + +/* + * The internal exts are part of the public abi + * If we add more extensions, publish the callback here ------v + */ +///@} + +/*! \defgroup Protocols-and-Plugins Protocols and Plugins + * \ingroup lwsapi + * + * ##Protocol and protocol plugin -related apis + * + * Protocols bind ws protocol names to a custom callback specific to that + * protocol implementaion. + * + * A list of protocols can be passed in at context creation time, but it is + * also legal to leave that NULL and add the protocols and their callback code + * using plugins. + * + * Plugins are much preferable compared to cut and pasting code into an + * application each time, since they can be used standalone. + */ +///@{ +/** struct lws_protocols - List of protocols and handlers client or server + * supports. */ + +struct lws_protocols { + const char *name; + /**< Protocol name that must match the one given in the client + * Javascript new WebSocket(url, 'protocol') name. */ + lws_callback_function *callback; + /**< The service callback used for this protocol. It allows the + * service action for an entire protocol to be encapsulated in + * the protocol-specific callback */ + size_t per_session_data_size; + /**< Each new connection using this protocol gets + * this much memory allocated on connection establishment and + * freed on connection takedown. A pointer to this per-connection + * allocation is passed into the callback in the 'user' parameter */ + size_t rx_buffer_size; + /**< lws allocates this much space for rx data and informs callback + * when something came. Due to rx flow control, the callback may not + * be able to consume it all without having to return to the event + * loop. That is supported in lws. + * + * This also controls how much may be sent at once at the moment, + * although this is likely to change. + */ + unsigned int id; + /**< ignored by lws, but useful to contain user information bound + * to the selected protocol. For example if this protocol was + * called "myprotocol-v2", you might set id to 2, and the user + * code that acts differently according to the version can do so by + * switch (wsi->protocol->id), user code might use some bits as + * capability flags based on selected protocol version, etc. */ + void *user; /**< ignored by lws, but user code can pass a pointer + here it can later access from the protocol callback */ + + /* Add new things just above here ---^ + * This is part of the ABI, don't needlessly break compatibility */ +}; + +struct lws_vhost; + +/** + * lws_vhost_name_to_protocol() - get vhost's protocol object from its name + * + * \param vh: vhost to search + * \param name: protocol name + * + * Returns NULL or a pointer to the vhost's protocol of the requested name + */ +LWS_VISIBLE LWS_EXTERN const struct lws_protocols * +lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name); + +/** + * lws_get_protocol() - Returns a protocol pointer from a websocket + * connection. + * \param wsi: pointer to struct websocket you want to know the protocol of + * + * + * Some apis can act on all live connections of a given protocol, + * this is how you can get a pointer to the active protocol if needed. + */ +LWS_VISIBLE LWS_EXTERN const struct lws_protocols * +lws_get_protocol(struct lws *wsi); + +/** lws_protocol_get() - deprecated: use lws_get_protocol */ +LWS_VISIBLE LWS_EXTERN const struct lws_protocols * +lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED; + +/** + * lws_protocol_vh_priv_zalloc() - Allocate and zero down a protocol's per-vhost + * storage + * \param vhost: vhost the instance is related to + * \param prot: protocol the instance is related to + * \param size: bytes to allocate + * + * Protocols often find it useful to allocate a per-vhost struct, this is a + * helper to be called in the per-vhost init LWS_CALLBACK_PROTOCOL_INIT + */ +LWS_VISIBLE LWS_EXTERN void * +lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols *prot, + int size); + +/** + * lws_protocol_vh_priv_get() - retreive a protocol's per-vhost storage + * + * \param vhost: vhost the instance is related to + * \param prot: protocol the instance is related to + * + * Recover a pointer to the allocated per-vhost storage for the protocol created + * by lws_protocol_vh_priv_zalloc() earlier + */ +LWS_VISIBLE LWS_EXTERN void * +lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot); + +/** + * lws_finalize_startup() - drop initial process privileges + * + * \param context: lws context + * + * This is called after the end of the vhost protocol initializations, but + * you may choose to call it earlier + */ +LWS_VISIBLE LWS_EXTERN int +lws_finalize_startup(struct lws_context *context); + +#ifdef LWS_WITH_PLUGINS + +/* PLUGINS implies LIBUV */ + +#define LWS_PLUGIN_API_MAGIC 180 + +/** struct lws_plugin_capability - how a plugin introduces itself to lws */ +struct lws_plugin_capability { + unsigned int api_magic; /**< caller fills this in, plugin fills rest */ + const struct lws_protocols *protocols; /**< array of supported protocols provided by plugin */ + int count_protocols; /**< how many protocols */ + const struct lws_extension *extensions; /**< array of extensions provided by plugin */ + int count_extensions; /**< how many extensions */ +}; + +typedef int (*lws_plugin_init_func)(struct lws_context *, + struct lws_plugin_capability *); +typedef int (*lws_plugin_destroy_func)(struct lws_context *); + +/** struct lws_plugin */ +struct lws_plugin { + struct lws_plugin *list; /**< linked list */ +#if (UV_VERSION_MAJOR > 0) + uv_lib_t lib; /**< shared library pointer */ +#else + void *l; /**< so we can compile on ancient libuv */ +#endif + char name[64]; /**< name of the plugin */ + struct lws_plugin_capability caps; /**< plugin capabilities */ +}; + +#endif + +///@} + + +/*! \defgroup generic-sessions plugin: generic-sessions + * \ingroup Protocols-and-Plugins + * + * ##Plugin Generic-sessions related + * + * generic-sessions plugin provides a reusable, generic session and login / + * register / forgot password framework including email verification. + */ +///@{ + +#define LWSGS_EMAIL_CONTENT_SIZE 16384 +/**< Maximum size of email we might send */ + +/* SHA-1 binary and hexified versions */ +/** typedef struct lwsgw_hash_bin */ +typedef struct { unsigned char bin[20]; /**< binary representation of hash */} lwsgw_hash_bin; +/** typedef struct lwsgw_hash */ +typedef struct { char id[41]; /**< ascii hex representation of hash */ } lwsgw_hash; + +/** enum lwsgs_auth_bits */ +enum lwsgs_auth_bits { + LWSGS_AUTH_LOGGED_IN = 1, /**< user is logged in as somebody */ + LWSGS_AUTH_ADMIN = 2, /**< logged in as the admin user */ + LWSGS_AUTH_VERIFIED = 4, /**< user has verified his email */ + LWSGS_AUTH_FORGOT_FLOW = 8, /**< he just completed "forgot password" flow */ +}; + +/** struct lws_session_info - information about user session status */ +struct lws_session_info { + char username[32]; /**< username logged in as, or empty string */ + char email[100]; /**< email address associated with login, or empty string */ + char ip[72]; /**< ip address session was started from */ + unsigned int mask; /**< access rights mask associated with session + * see enum lwsgs_auth_bits */ + char session[42]; /**< session id string, usable as opaque uid when not logged in */ +}; + +/** enum lws_gs_event */ +enum lws_gs_event { + LWSGSE_CREATED, /**< a new user was created */ + LWSGSE_DELETED /**< an existing user was deleted */ +}; + +/** struct lws_gs_event_args */ +struct lws_gs_event_args { + enum lws_gs_event event; /**< which event happened */ + const char *username; /**< which username the event happened to */ + const char *email; /**< the email address of that user */ +}; + +///@} + + +/*! \defgroup context-and-vhost + * \ingroup lwsapi + * + * ##Context and Vhost releated functions + * + * LWS requires that there is one context, in which you may define multiple + * vhosts. Each vhost is a virtual host, with either its own listen port + * or sharing an existing one. Each vhost has its own SSL context that can + * be set up individually or left disabled. + * + * If you don't care about multiple "site" support, you can ignore it and + * lws will create a single default vhost at context creation time. + */ +///@{ + +/* + * NOTE: These public enums are part of the abi. If you want to add one, + * add it at where specified so existing users are unaffected. + */ + +/** enum lws_context_options - context and vhost options */ +enum lws_context_options { + LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = (1 << 1) | + (1 << 12), + /**< (VH) Don't allow the connection unless the client has a + * client cert that we recognize; provides + * LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT */ + LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = (1 << 2), + /**< (CTX) Don't try to get the server's hostname */ + LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT = (1 << 3) | + (1 << 12), + /**< (VH) Allow non-SSL (plaintext) connections on the same + * port as SSL is listening... undermines the security of SSL; + * provides LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT */ + LWS_SERVER_OPTION_LIBEV = (1 << 4), + /**< (CTX) Use libev event loop */ + LWS_SERVER_OPTION_DISABLE_IPV6 = (1 << 5), + /**< (VH) Disable IPV6 support */ + LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS = (1 << 6), + /**< (VH) Don't load OS CA certs, you will need to load your + * own CA cert(s) */ + LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED = (1 << 7), + /**< (VH) Accept connections with no valid Cert (eg, selfsigned) */ + LWS_SERVER_OPTION_VALIDATE_UTF8 = (1 << 8), + /**< (VH) Check UT-8 correctness */ + LWS_SERVER_OPTION_SSL_ECDH = (1 << 9) | + (1 << 12), + /**< (VH) initialize ECDH ciphers */ + LWS_SERVER_OPTION_LIBUV = (1 << 10), + /**< (CTX) Use libuv event loop */ + LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS = (1 << 11) | + (1 << 12), + /**< (VH) Use http redirect to force http to https + * (deprecated: use mount redirection) */ + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT = (1 << 12), + /**< (CTX) Initialize the SSL library at all */ + LWS_SERVER_OPTION_EXPLICIT_VHOSTS = (1 << 13), + /**< (CTX) Only create the context when calling context + * create api, implies user code will create its own vhosts */ + LWS_SERVER_OPTION_UNIX_SOCK = (1 << 14), + /**< (VH) Use Unix socket */ + LWS_SERVER_OPTION_STS = (1 << 15), + /**< (VH) Send Strict Transport Security header, making + * clients subsequently go to https even if user asked for http */ + LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY = (1 << 16), + /**< (VH) Enable LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE to take effect */ + LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE = (1 << 17), + /**< (VH) if set, only ipv6 allowed on the vhost */ + LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN = (1 << 18), + /**< (CTX) Libuv only: Do not spin on SIGSEGV / SIGFPE. A segfault + * normally makes the lib spin so you can attach a debugger to it + * even if it happened without a debugger in place. You can disable + * that by giving this option. + */ + + /****** add new things just above ---^ ******/ +}; + +#define lws_check_opt(c, f) (((c) & (f)) == (f)) + +/** struct lws_context_creation_info - parameters to create context and /or vhost with + * + * This is also used to create vhosts.... if LWS_SERVER_OPTION_EXPLICIT_VHOSTS + * is not given, then for backwards compatibility one vhost is created at + * context-creation time using the info from this struct. + * + * If LWS_SERVER_OPTION_EXPLICIT_VHOSTS is given, then no vhosts are created + * at the same time as the context, they are expected to be created afterwards. + */ +struct lws_context_creation_info { + int port; + /**< VHOST: Port to listen on... you can use CONTEXT_PORT_NO_LISTEN to + * suppress listening on any port, that's what you want if you are + * not running a websocket server at all but just using it as a + * client */ + const char *iface; + /**< VHOST: NULL to bind the listen socket to all interfaces, or the + * interface name, eg, "eth2" + * If options specifies LWS_SERVER_OPTION_UNIX_SOCK, this member is + * the pathname of a UNIX domain socket. you can use the UNIX domain + * sockets in abstract namespace, by prepending an at symbol to the + * socket name. */ + const struct lws_protocols *protocols; + /**< VHOST: Array of structures listing supported protocols and a protocol- + * specific callback for each one. The list is ended with an + * entry that has a NULL callback pointer. */ + const struct lws_extension *extensions; + /**< VHOST: NULL or array of lws_extension structs listing the + * extensions this context supports. */ + const struct lws_token_limits *token_limits; + /**< CONTEXT: NULL or struct lws_token_limits pointer which is initialized + * with a token length limit for each possible WSI_TOKEN_ */ + const char *ssl_private_key_password; + /**< VHOST: NULL or the passphrase needed for the private key */ + const char *ssl_cert_filepath; + /**< VHOST: If libwebsockets was compiled to use ssl, and you want + * to listen using SSL, set to the filepath to fetch the + * server cert from, otherwise NULL for unencrypted */ + const char *ssl_private_key_filepath; + /**< VHOST: filepath to private key if wanting SSL mode; + * if this is set to NULL but sll_cert_filepath is set, the + * OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY callback is called + * to allow setting of the private key directly via openSSL + * library calls */ + const char *ssl_ca_filepath; + /**< VHOST: CA certificate filepath or NULL */ + const char *ssl_cipher_list; + /**< VHOST: List of valid ciphers to use (eg, + * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL" + * or you can leave it as NULL to get "DEFAULT" */ + const char *http_proxy_address; + /**< VHOST: If non-NULL, attempts to proxy via the given address. + * If proxy auth is required, use format "username:password\@server:port" */ + unsigned int http_proxy_port; + /**< VHOST: If http_proxy_address was non-NULL, uses this port */ + int gid; + /**< CONTEXT: group id to change to after setting listen socket, or -1. */ + int uid; + /**< CONTEXT: user id to change to after setting listen socket, or -1. */ + unsigned int options; + /**< VHOST + CONTEXT: 0, or LWS_SERVER_OPTION_... bitfields */ + void *user; + /**< CONTEXT: optional user pointer that can be recovered via the context + * pointer using lws_context_user */ + int ka_time; + /**< CONTEXT: 0 for no TCP keepalive, otherwise apply this keepalive + * timeout to all libwebsocket sockets, client or server */ + int ka_probes; + /**< CONTEXT: if ka_time was nonzero, after the timeout expires how many + * times to try to get a response from the peer before giving up + * and killing the connection */ + int ka_interval; + /**< CONTEXT: if ka_time was nonzero, how long to wait before each ka_probes + * attempt */ +#ifdef LWS_OPENSSL_SUPPORT + SSL_CTX *provided_client_ssl_ctx; + /**< CONTEXT: If non-null, swap out libwebsockets ssl + * implementation for the one provided by provided_ssl_ctx. + * Libwebsockets no longer is responsible for freeing the context + * if this option is selected. */ +#else /* maintain structure layout either way */ + void *provided_client_ssl_ctx; /**< dummy if ssl disabled */ +#endif + + short max_http_header_data; + /**< CONTEXT: The max amount of header payload that can be handled + * in an http request (unrecognized header payload is dropped) */ + short max_http_header_pool; + /**< CONTEXT: The max number of connections with http headers that + * can be processed simultaneously (the corresponding memory is + * allocated for the lifetime of the context). If the pool is + * busy new incoming connections must wait for accept until one + * becomes free. */ + + unsigned int count_threads; + /**< CONTEXT: how many contexts to create in an array, 0 = 1 */ + unsigned int fd_limit_per_thread; + /**< CONTEXT: nonzero means restrict each service thread to this + * many fds, 0 means the default which is divide the process fd + * limit by the number of threads. */ + unsigned int timeout_secs; + /**< VHOST: various processes involving network roundtrips in the + * library are protected from hanging forever by timeouts. If + * nonzero, this member lets you set the timeout used in seconds. + * Otherwise a default timeout is used. */ + const char *ecdh_curve; + /**< VHOST: if NULL, defaults to initializing server with "prime256v1" */ + const char *vhost_name; + /**< VHOST: name of vhost, must match external DNS name used to + * access the site, like "warmcat.com" as it's used to match + * Host: header and / or SNI name for SSL. */ + const char * const *plugin_dirs; + /**< CONTEXT: NULL, or NULL-terminated array of directories to + * scan for lws protocol plugins at context creation time */ + const struct lws_protocol_vhost_options *pvo; + /**< VHOST: pointer to optional linked list of per-vhost + * options made accessible to protocols */ + int keepalive_timeout; + /**< VHOST: (default = 0 = 60s) seconds to allow remote + * client to hold on to an idle HTTP/1.1 connection */ + const char *log_filepath; + /**< VHOST: filepath to append logs to... this is opened before + * any dropping of initial privileges */ + const struct lws_http_mount *mounts; + /**< VHOST: optional linked list of mounts for this vhost */ + const char *server_string; + /**< CONTEXT: string used in HTTP headers to identify server + * software, if NULL, "libwebsockets". */ + unsigned int pt_serv_buf_size; + /**< CONTEXT: 0 = default of 4096. This buffer is used by + * various service related features including file serving, it + * defines the max chunk of file that can be sent at once. + * At the risk of lws having to buffer failed large sends, it + * can be increased to, eg, 128KiB to improve throughput. */ + unsigned int max_http_header_data2; + /**< CONTEXT: if max_http_header_data is 0 and this + * is nonzero, this will be used in place of the default. It's + * like this for compatibility with the original short version, + * this is unsigned int length. */ + long ssl_options_set; + /**< VHOST: Any bits set here will be set as SSL options */ + long ssl_options_clear; + /**< VHOST: Any bits set here will be cleared as SSL options */ + unsigned short ws_ping_pong_interval; + /**< CONTEXT: 0 for none, else interval in seconds between sending + * PINGs on idle websocket connections. When the PING is sent, + * the PONG must come within the normal timeout_secs timeout period + * or the connection will be dropped. + * Any RX or TX traffic on the connection restarts the interval timer, + * so a connection which always sends or receives something at intervals + * less than the interval given here will never send PINGs / expect + * PONGs. Conversely as soon as the ws connection is established, an + * idle connection will do the PING / PONG roundtrip as soon as + * ws_ping_pong_interval seconds has passed without traffic + */ + const struct lws_protocol_vhost_options *headers; + /**< VHOST: pointer to optional linked list of per-vhost + * canned headers that are added to server responses */ + + /* Add new things just above here ---^ + * This is part of the ABI, don't needlessly break compatibility + * + * The below is to ensure later library versions with new + * members added above will see 0 (default) even if the app + * was not built against the newer headers. + */ + + void *_unused[8]; /**< dummy */ +}; + +/** + * lws_create_context() - Create the websocket handler + * \param info: pointer to struct with parameters + * + * This function creates the listening socket (if serving) and takes care + * of all initialization in one step. + * + * If option LWS_SERVER_OPTION_EXPLICIT_VHOSTS is given, no vhost is + * created; you're expected to create your own vhosts afterwards using + * lws_create_vhost(). Otherwise a vhost named "default" is also created + * using the information in the vhost-related members, for compatibility. + * + * After initialization, it returns a struct lws_context * that + * represents this server. After calling, user code needs to take care + * of calling lws_service() with the context pointer to get the + * server's sockets serviced. This must be done in the same process + * context as the initialization call. + * + * The protocol callback functions are called for a handful of events + * including http requests coming in, websocket connections becoming + * established, and data arriving; it's also called periodically to allow + * async transmission. + * + * HTTP requests are sent always to the FIRST protocol in protocol, since + * at that time websocket protocol has not been negotiated. Other + * protocols after the first one never see any HTTP callack activity. + * + * The server created is a simple http server by default; part of the + * websocket standard is upgrading this http connection to a websocket one. + * + * This allows the same server to provide files like scripts and favicon / + * images or whatever over http and dynamic data over websockets all in + * one place; they're all handled in the user callback. + */ +LWS_VISIBLE LWS_EXTERN struct lws_context * +lws_create_context(struct lws_context_creation_info *info); + +/** + * lws_context_destroy() - Destroy the websocket context + * \param context: Websocket context + * + * This function closes any active connections and then frees the + * context. After calling this, any further use of the context is + * undefined. + */ +LWS_VISIBLE LWS_EXTERN void +lws_context_destroy(struct lws_context *context); + +/** + * lws_set_proxy() - Setups proxy to lws_context. + * \param vhost: pointer to struct lws_vhost you want set proxy for + * \param proxy: pointer to c string containing proxy in format address:port + * + * Returns 0 if proxy string was parsed and proxy was setup. + * Returns -1 if proxy is NULL or has incorrect format. + * + * This is only required if your OS does not provide the http_proxy + * environment variable (eg, OSX) + * + * IMPORTANT! You should call this function right after creation of the + * lws_context and before call to connect. If you call this + * function after connect behavior is undefined. + * This function will override proxy settings made on lws_context + * creation with genenv() call. + */ +LWS_VISIBLE LWS_EXTERN int +lws_set_proxy(struct lws_vhost *vhost, const char *proxy); + + +struct lws_vhost; + +/** + * lws_create_vhost() - Create a vhost (virtual server context) + * \param context: pointer to result of lws_create_context() + * \param info: pointer to struct with parameters + * + * This function creates a virtual server (vhost) using the vhost-related + * members of the info struct. You can create many vhosts inside one context + * if you created the context with the option LWS_SERVER_OPTION_EXPLICIT_VHOSTS + */ +LWS_EXTERN LWS_VISIBLE struct lws_vhost * +lws_create_vhost(struct lws_context *context, + struct lws_context_creation_info *info); + +/** + * lwsws_get_config_globals() - Parse a JSON server config file + * \param info: pointer to struct with parameters + * \param d: filepath of the config file + * \param config_strings: storage for the config strings extracted from JSON, + * the pointer is incremented as strings are stored + * \param len: pointer to the remaining length left in config_strings + * the value is decremented as strings are stored + * + * This function prepares a n lws_context_creation_info struct with global + * settings from a file d. + * + * Requires CMake option LWS_WITH_LEJP_CONF to have been enabled + */ +LWS_VISIBLE LWS_EXTERN int +lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d, + char **config_strings, int *len); + +/** + * lwsws_get_config_vhosts() - Create vhosts from a JSON server config file + * \param context: pointer to result of lws_create_context() + * \param info: pointer to struct with parameters + * \param d: filepath of the config file + * \param config_strings: storage for the config strings extracted from JSON, + * the pointer is incremented as strings are stored + * \param len: pointer to the remaining length left in config_strings + * the value is decremented as strings are stored + * + * This function creates vhosts into a context according to the settings in + *JSON files found in directory d. + * + * Requires CMake option LWS_WITH_LEJP_CONF to have been enabled + */ +LWS_VISIBLE LWS_EXTERN int +lwsws_get_config_vhosts(struct lws_context *context, + struct lws_context_creation_info *info, const char *d, + char **config_strings, int *len); + +/** lws_vhost_get() - \deprecated deprecated: use lws_get_vhost() */ +LWS_VISIBLE LWS_EXTERN struct lws_vhost * +lws_vhost_get(struct lws *wsi) LWS_WARN_DEPRECATED; + +/** + * lws_get_vhost() - return the vhost a wsi belongs to + * + * \param wsi: which connection + */ +LWS_VISIBLE LWS_EXTERN struct lws_vhost * +lws_get_vhost(struct lws *wsi); + +/** + * lws_json_dump_vhost() - describe vhost state and stats in JSON + * + * \param vh: the vhost + * \param buf: buffer to fill with JSON + * \param len: max length of buf + */ +LWS_VISIBLE LWS_EXTERN int +lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len); + +/** + * lws_json_dump_context() - describe context state and stats in JSON + * + * \param context: the context + * \param buf: buffer to fill with JSON + * \param len: max length of buf + */ +LWS_VISIBLE LWS_EXTERN int +lws_json_dump_context(const struct lws_context *context, char *buf, int len); + +/** + * lws_context_user() - get the user data associated with the context + * \param context: Websocket context + * + * This returns the optional user allocation that can be attached to + * the context the sockets live in at context_create time. It's a way + * to let all sockets serviced in the same context share data without + * using globals statics in the user code. + */ +LWS_VISIBLE LWS_EXTERN void * +lws_context_user(struct lws_context *context); + +/*! \defgroup vhost-mounts Vhost mounts and options + * \ingroup context-and-vhost-creation + * + * ##Vhost mounts and options + */ +///@{ +/** struct lws_protocol_vhost_options - linked list of per-vhost protocol + * name=value options + * + * This provides a general way to attach a linked-list of name=value pairs, + * which can also have an optional child link-list using the options member. + */ +struct lws_protocol_vhost_options { + const struct lws_protocol_vhost_options *next; /**< linked list */ + const struct lws_protocol_vhost_options *options; /**< child linked-list of more options for this node */ + const char *name; /**< name of name=value pair */ + const char *value; /**< value of name=value pair */ +}; + +/** enum lws_mount_protocols + * This specifies the mount protocol for a mountpoint, whether it is to be + * served from a filesystem, or it is a cgi etc. + */ +enum lws_mount_protocols { + LWSMPRO_HTTP = 0, /**< not supported yet */ + LWSMPRO_HTTPS = 1, /**< not supported yet */ + LWSMPRO_FILE = 2, /**< serve from filesystem directory */ + LWSMPRO_CGI = 3, /**< pass to CGI to handle */ + LWSMPRO_REDIR_HTTP = 4, /**< redirect to http:// url */ + LWSMPRO_REDIR_HTTPS = 5, /**< redirect to https:// url */ + LWSMPRO_CALLBACK = 6, /**< hand by named protocol's callback */ +}; + +/** struct lws_http_mount + * + * arguments for mounting something in a vhost's url namespace + */ +struct lws_http_mount { + const struct lws_http_mount *mount_next; + /**< pointer to next struct lws_http_mount */ + const char *mountpoint; + /**< mountpoint in http pathspace, eg, "/" */ + const char *origin; + /**< path to be mounted, eg, "/var/www/warmcat.com" */ + const char *def; + /**< default target, eg, "index.html" */ + const char *protocol; + /**<"protocol-name" to handle mount */ + + const struct lws_protocol_vhost_options *cgienv; + /**< optional linked-list of cgi options. These are created + * as environment variables for the cgi process + */ + const struct lws_protocol_vhost_options *extra_mimetypes; + /**< optional linked-list of mimetype mappings */ + const struct lws_protocol_vhost_options *interpret; + /**< optional linked-list of files to be interpreted */ + + int cgi_timeout; + /**< seconds cgi is allowed to live, if cgi://mount type */ + int cache_max_age; + /**< max-age for reuse of client cache of files, seconds */ + unsigned int auth_mask; + /**< bits set here must be set for authorized client session */ + + unsigned int cache_reusable:1; /**< set if client cache may reuse this */ + unsigned int cache_revalidate:1; /**< set if client cache should revalidate on use */ + unsigned int cache_intermediaries:1; /**< set if intermediaries are allowed to cache */ + + unsigned char origin_protocol; /**< one of enum lws_mount_protocols */ + unsigned char mountpoint_len; /**< length of mountpoint string */ +}; +///@} +///@} + +/*! \defgroup client + * \ingroup lwsapi + * + * ##Client releated functions + * */ +///@{ + +/** enum lws_client_connect_ssl_connection_flags - flags that may be used + * with struct lws_client_connect_info ssl_connection member to control if + * and how SSL checks apply to the client connection being created + */ + +enum lws_client_connect_ssl_connection_flags { + LCCSCF_USE_SSL = (1 << 0), + LCCSCF_ALLOW_SELFSIGNED = (1 << 1), + LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK = (1 << 2) +}; + +/** struct lws_client_connect_info - parameters to connect with when using + * lws_client_connect_via_info() */ + +struct lws_client_connect_info { + struct lws_context *context; + /**< lws context to create connection in */ + const char *address; + /**< remote address to connect to */ + int port; + /**< remote port to connect to */ + int ssl_connection; + /**< nonzero for ssl */ + const char *path; + /**< uri path */ + const char *host; + /**< content of host header */ + const char *origin; + /**< content of origin header */ + const char *protocol; + /**< list of ws protocols we could accept */ + int ietf_version_or_minus_one; + /**< deprecated: currently leave at 0 or -1 */ + void *userdata; + /**< if non-NULL, use this as wsi user_data instead of malloc it */ + const struct lws_extension *client_exts; + /**< array of extensions that may be used on connection */ + const char *method; + /**< if non-NULL, do this http method instead of ws[s] upgrade. + * use "GET" to be a simple http client connection */ + struct lws *parent_wsi; + /**< if another wsi is responsible for this connection, give it here. + * this is used to make sure if the parent closes so do any + * child connections first. */ + const char *uri_replace_from; + /**< if non-NULL, when this string is found in URIs in + * text/html content-encoding, it's replaced with uri_replace_to */ + const char *uri_replace_to; + /**< see uri_replace_from */ + struct lws_vhost *vhost; + /**< vhost to bind to (used to determine related SSL_CTX) */ + struct lws **pwsi; + /**< if not NULL, store the new wsi here early in the connection + * process. Although we return the new wsi, the call to create the + * client connection does progress the connection somewhat and may + * meet an error that will result in the connection being scrubbed and + * NULL returned. While the wsi exists though, he may process a + * callback like CLIENT_CONNECTION_ERROR with his wsi: this gives the + * user callback a way to identify which wsi it is that faced the error + * even before the new wsi is returned and even if ultimately no wsi + * is returned. + */ + + /* Add new things just above here ---^ + * This is part of the ABI, don't needlessly break compatibility + * + * The below is to ensure later library versions with new + * members added above will see 0 (default) even if the app + * was not built against the newer headers. + */ + + void *_unused[4]; /**< dummy */ +}; + +/** + * lws_client_connect_via_info() - Connect to another websocket server + * \param ccinfo: pointer to lws_client_connect_info struct + * + * This function creates a connection to a remote server using the + * information provided in ccinfo. + */ +LWS_VISIBLE LWS_EXTERN struct lws * +lws_client_connect_via_info(struct lws_client_connect_info * ccinfo); + +/** + * lws_client_connect() - Connect to another websocket server + * \deprecated DEPRECATED use lws_client_connect_via_info + * \param clients: Websocket context + * \param address: Remote server address, eg, "myserver.com" + * \param port: Port to connect to on the remote server, eg, 80 + * \param ssl_connection: 0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self + * signed certs + * \param path: Websocket path on server + * \param host: Hostname on server + * \param origin: Socket origin name + * \param protocol: Comma-separated list of protocols being asked for from + * the server, or just one. The server will pick the one it + * likes best. If you don't want to specify a protocol, which is + * legal, use NULL here. + * \param ietf_version_or_minus_one: -1 to ask to connect using the default, latest + * protocol supported, or the specific protocol ordinal + * + * This function creates a connection to a remote server + */ +/* deprecated, use lws_client_connect_via_info() */ +LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT +lws_client_connect(struct lws_context *clients, const char *address, + int port, int ssl_connection, const char *path, + const char *host, const char *origin, const char *protocol, + int ietf_version_or_minus_one) LWS_WARN_DEPRECATED; +/* deprecated, use lws_client_connect_via_info() */ +/** + * lws_client_connect_extended() - Connect to another websocket server + * \deprecated DEPRECATED use lws_client_connect_via_info + * \param clients: Websocket context + * \param address: Remote server address, eg, "myserver.com" + * \param port: Port to connect to on the remote server, eg, 80 + * \param ssl_connection: 0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self + * signed certs + * \param path: Websocket path on server + * \param host: Hostname on server + * \param origin: Socket origin name + * \param protocol: Comma-separated list of protocols being asked for from + * the server, or just one. The server will pick the one it + * likes best. + * \param ietf_version_or_minus_one: -1 to ask to connect using the default, latest + * protocol supported, or the specific protocol ordinal + * \param userdata: Pre-allocated user data + * + * This function creates a connection to a remote server + */ +LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT +lws_client_connect_extended(struct lws_context *clients, const char *address, + int port, int ssl_connection, const char *path, + const char *host, const char *origin, + const char *protocol, int ietf_version_or_minus_one, + void *userdata) LWS_WARN_DEPRECATED; + +/** + * lws_init_vhost_client_ssl() - also enable client SSL on an existing vhost + * + * \param info: client ssl related info + * \param vhost: which vhost to initialize client ssl operations on + * + * You only need to call this if you plan on using SSL client connections on + * the vhost. For non-SSL client connections, it's not necessary to call this. + * + * The following members of info are used during the call + * + * - options must have LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT set, + * otherwise the call does nothing + * - provided_client_ssl_ctx must be NULL to get a generated client + * ssl context, otherwise you can pass a prepared one in by setting it + * - ssl_cipher_list may be NULL or set to the client valid cipher list + * - ssl_ca_filepath may be NULL or client cert filepath + * - ssl_cert_filepath may be NULL or client cert filepath + * - ssl_private_key_filepath may be NULL or client cert private key + * + * You must create your vhost explicitly if you want to use this, so you have + * a pointer to the vhost. Create the context first with the option flag + * LWS_SERVER_OPTION_EXPLICIT_VHOSTS and then call lws_create_vhost() with + * the same info struct. + */ +LWS_VISIBLE LWS_EXTERN int +lws_init_vhost_client_ssl(const struct lws_context_creation_info *info, + struct lws_vhost *vhost); + +LWS_VISIBLE LWS_EXTERN int +lws_http_client_read(struct lws *wsi, char **buf, int *len); + +LWS_VISIBLE LWS_EXTERN void +lws_client_http_body_pending(struct lws *wsi, int something_left_to_send); + +/** + * lws_client_http_body_pending() - control if client connection neeeds to send body + * + * \param wsi: client connection + * \param something_left_to_send: nonzero if need to send more body, 0 (default) + * if nothing more to send + * + * If you will send payload data with your HTTP client connection, eg, for POST, + * when you set the related http headers in + * LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER callback you should also call + * this API with something_left_to_send nonzero, and call + * lws_callback_on_writable(wsi); + * + * After sending the headers, lws will call your callback with + * LWS_CALLBACK_CLIENT_HTTP_WRITEABLE reason when writable. You can send the + * next part of the http body payload, calling lws_callback_on_writable(wsi); + * if there is more to come, or lws_client_http_body_pending(wsi, 0); to + * let lws know the last part is sent and the connection can move on. + */ + +///@} + +/** \defgroup service Built-in service loop entry + * + * ##Built-in service loop entry + * + * If you're not using libev / libuv, these apis are needed to enter the poll() + * wait in lws and service any connections with pending events. + */ +///@{ + +/** + * lws_service() - Service any pending websocket activity + * \param context: Websocket context + * \param timeout_ms: Timeout for poll; 0 means return immediately if nothing needed + * service otherwise block and service immediately, returning + * after the timeout if nothing needed service. + * + * This function deals with any pending websocket traffic, for three + * kinds of event. It handles these events on both server and client + * types of connection the same. + * + * 1) Accept new connections to our context's server + * + * 2) Call the receive callback for incoming frame data received by + * server or client connections. + * + * You need to call this service function periodically to all the above + * functions to happen; if your application is single-threaded you can + * just call it in your main event loop. + * + * Alternatively you can fork a new process that asynchronously handles + * calling this service in a loop. In that case you are happy if this + * call blocks your thread until it needs to take care of something and + * would call it with a large nonzero timeout. Your loop then takes no + * CPU while there is nothing happening. + * + * If you are calling it in a single-threaded app, you don't want it to + * wait around blocking other things in your loop from happening, so you + * would call it with a timeout_ms of 0, so it returns immediately if + * nothing is pending, or as soon as it services whatever was pending. + */ +LWS_VISIBLE LWS_EXTERN int +lws_service(struct lws_context *context, int timeout_ms); + +/** + * lws_service() - Service any pending websocket activity + * + * \param context: Websocket context + * \param timeout_ms: Timeout for poll; 0 means return immediately if nothing needed + * service otherwise block and service immediately, returning + * after the timeout if nothing needed service. + * + * Same as lws_service(), but for a specific thread service index. Only needed + * if you are spawning multiple service threads. + */ +LWS_VISIBLE LWS_EXTERN int +lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi); + +/** + * lws_cancel_service_pt() - Cancel servicing of pending socket activity + * on one thread + * \param wsi: Cancel service on the thread this wsi is serviced by + * + * This function lets a call to lws_service() waiting for a timeout + * immediately return. + * + * It works by creating a phony event and then swallowing it silently. + * + * The reason it may be needed is when waiting in poll(), changes to + * the event masks are ignored by the OS until poll() is reentered. This + * lets you halt the poll() wait and make the reentry happen immediately + * instead of having the wait out the rest of the poll timeout. + */ +LWS_VISIBLE LWS_EXTERN void +lws_cancel_service_pt(struct lws *wsi); + +/** + * lws_cancel_service() - Cancel wait for new pending socket activity + * \param context: Websocket context + * + * This function let a call to lws_service() waiting for a timeout + * immediately return. + * + * What it basically does is provide a fake event that will be swallowed, + * so the wait in poll() is ended. That's useful because poll() doesn't + * attend to changes in POLLIN/OUT/ERR until it re-enters the wait. + */ +LWS_VISIBLE LWS_EXTERN void +lws_cancel_service(struct lws_context *context); + +/** + * lws_service_fd() - Service polled socket with something waiting + * \param context: Websocket context + * \param pollfd: The pollfd entry describing the socket fd and which events + * happened. + * + * This function takes a pollfd that has POLLIN or POLLOUT activity and + * services it according to the state of the associated + * struct lws. + * + * The one call deals with all "service" that might happen on a socket + * including listen accepts, http files as well as websocket protocol. + * + * If a pollfd says it has something, you can just pass it to + * lws_service_fd() whether it is a socket handled by lws or not. + * If it sees it is a lws socket, the traffic will be handled and + * pollfd->revents will be zeroed now. + * + * If the socket is foreign to lws, it leaves revents alone. So you can + * see if you should service yourself by checking the pollfd revents + * after letting lws try to service it. + */ +LWS_VISIBLE LWS_EXTERN int +lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd); + +/** + * lws_service_fd_tsi() - Service polled socket in specific service thread + * \param context: Websocket context + * \param pollfd: The pollfd entry describing the socket fd and which events + * happened. + * \param tsi: thread service index + * + * Same as lws_service_fd() but used with multiple service threads + */ +LWS_VISIBLE LWS_EXTERN int +lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd, + int tsi); + +/** + * lws_service_adjust_timeout() - Check for any connection needing forced service + * \param context: Websocket context + * \param timeout_ms: The original poll timeout value. You can just set this + * to 1 if you don't really have a poll timeout. + * \param tsi: thread service index + * + * Under some conditions connections may need service even though there is no + * pending network action on them, this is "forced service". For default + * poll() and libuv / libev, the library takes care of calling this and + * dealing with it for you. But for external poll() integration, you need + * access to the apis. + * + * If anybody needs "forced service", returned timeout is zero. In that case, + * you can call lws_plat_service_tsi() with a timeout of -1 to only service + * guys who need forced service. + */ +LWS_VISIBLE LWS_EXTERN int +lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi); + +/** + * lws_plat_service_tsi() - Lowlevel platform-specific service api + * \param context: Websocket context + * \param timeout_ms: The original poll timeout value. You can just set this + * to 1 if you don't really have a poll timeout. + * \param tsi: thread service index + * + * For default poll() and libuv/ev, lws takes care of using this for you. and + * you can ignore it. + * + * But for external poll() integration, you need access to this api to service + * connections that need to be serviced but have no pending network activity. + * + * See lws_service_adjust_timeout() for more info. + */ +LWS_EXTERN LWS_VISIBLE int +lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi); + +///@} + +/*! \defgroup http HTTP + + Modules related to handling HTTP +*/ +//@{ + +/*! \defgroup httpft HTTP File transfer + * \ingroup http + + APIs for sending local files in response to HTTP requests +*/ +//@{ + +/** + * lws_get_mimetype() - Determine mimetype to use from filename + * + * \param file: filename + * \param m: NULL, or mount context + * + * This uses a canned list of known filetypes first, if no match and m is + * non-NULL, then tries a list of per-mount file suffix to mimtype mappings. + * + * Returns either NULL or a pointer to the mimetype matching the file. + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_get_mimetype(const char *file, const struct lws_http_mount *m); + +/** + * lws_serve_http_file() - Send a file back to the client using http + * \param wsi: Websocket instance (available from user callback) + * \param file: The file to issue over http + * \param content_type: The http content type, eg, text/html + * \param other_headers: NULL or pointer to header string + * \param other_headers_len: length of the other headers if non-NULL + * + * This function is intended to be called from the callback in response + * to http requests from the client. It allows the callback to issue + * local files down the http link in a single step. + * + * Returning <0 indicates error and the wsi should be closed. Returning + * >0 indicates the file was completely sent and + * lws_http_transaction_completed() called on the wsi (and close if != 0) + * ==0 indicates the file transfer is started and needs more service later, + * the wsi should be left alone. + */ +LWS_VISIBLE LWS_EXTERN int +lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, + const char *other_headers, int other_headers_len); +LWS_VISIBLE LWS_EXTERN int +lws_serve_http_file_fragment(struct lws *wsi); +//@} + +/*! \defgroup html-chunked-substitution HTML Chunked Substitution + * \ingroup http + * + * ##HTML chunked Substitution + * + * APIs for receiving chunks of text, replacing a set of variable names via + * a callback, and then prepending and appending HTML chunked encoding + * headers. + */ +//@{ + +enum http_status { + HTTP_STATUS_OK = 200, + HTTP_STATUS_NO_CONTENT = 204, + + HTTP_STATUS_MOVED_PERMANENTLY = 301, + HTTP_STATUS_FOUND = 302, + HTTP_STATUS_SEE_OTHER = 303, + + HTTP_STATUS_BAD_REQUEST = 400, + HTTP_STATUS_UNAUTHORIZED, + HTTP_STATUS_PAYMENT_REQUIRED, + HTTP_STATUS_FORBIDDEN, + HTTP_STATUS_NOT_FOUND, + HTTP_STATUS_METHOD_NOT_ALLOWED, + HTTP_STATUS_NOT_ACCEPTABLE, + HTTP_STATUS_PROXY_AUTH_REQUIRED, + HTTP_STATUS_REQUEST_TIMEOUT, + HTTP_STATUS_CONFLICT, + HTTP_STATUS_GONE, + HTTP_STATUS_LENGTH_REQUIRED, + HTTP_STATUS_PRECONDITION_FAILED, + HTTP_STATUS_REQ_ENTITY_TOO_LARGE, + HTTP_STATUS_REQ_URI_TOO_LONG, + HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, + HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE, + HTTP_STATUS_EXPECTATION_FAILED, + + HTTP_STATUS_INTERNAL_SERVER_ERROR = 500, + HTTP_STATUS_NOT_IMPLEMENTED, + HTTP_STATUS_BAD_GATEWAY, + HTTP_STATUS_SERVICE_UNAVAILABLE, + HTTP_STATUS_GATEWAY_TIMEOUT, + HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED, +}; + +struct lws_process_html_args { + char *p; /**< pointer to the buffer containing the data */ + int len; /**< length of the original data at p */ + int max_len; /**< maximum length we can grow the data to */ + int final; /**< set if this is the last chunk of the file */ +}; + +typedef const char *(*lws_process_html_state_cb)(void *data, int index); + +struct lws_process_html_state { + char *start; /**< pointer to start of match */ + char swallow[16]; /**< matched character buffer */ + int pos; /**< position in match */ + void *data; /**< opaque pointer */ + const char * const *vars; /**< list of variable names */ + int count_vars; /**< count of variable names */ + + lws_process_html_state_cb replace; /**< called on match to perform substitution */ +}; + +/*! lws_chunked_html_process() - generic chunked substitution + * \param args: buffer to process using chunked encoding + * \param s: current processing state + */ +LWS_VISIBLE LWS_EXTERN int +lws_chunked_html_process(struct lws_process_html_args *args, + struct lws_process_html_state *s); +//@} + +/** \defgroup HTTP-headers-read HTTP headers: read + * \ingroup http + * + * ##HTTP header releated functions + * + * In lws the client http headers are temporarily stored in a pool, only for the + * duration of the http part of the handshake. It's because in most cases, + * the header content is ignored for the whole rest of the connection lifetime + * and would then just be taking up space needlessly. + * + * During LWS_CALLBACK_HTTP when the URI path is delivered is the last time + * the http headers are still allocated, you can use these apis then to + * look at and copy out interesting header content (cookies, etc) + * + * Notice that the header total length reported does not include a terminating + * '\0', however you must allocate for it when using the _copy apis. So the + * length reported for a header containing "123" is 3, but you must provide + * a buffer of length 4 so that "123\0" may be copied into it, or the copy + * will fail with a nonzero return code. + * + * In the special case of URL arguments, like ?x=1&y=2, the arguments are + * stored in a token named for the method, eg, WSI_TOKEN_GET_URI if it + * was a GET or WSI_TOKEN_POST_URI if POST. You can check the total + * length to confirm the method. + * + * For URL arguments, each argument is stored urldecoded in a "fragment", so + * you can use the fragment-aware api lws_hdr_copy_fragment() to access each + * argument in turn: the fragments contain urldecoded strings like x=1 or y=2. + * + * As a convenience, lws has an api that will find the fragment with a + * given name= part, lws_get_urlarg_by_name(). + */ +///@{ + +/** struct lws_tokens + * you need these to look at headers that have been parsed if using the + * LWS_CALLBACK_FILTER_CONNECTION callback. If a header from the enum + * list below is absent, .token = NULL and token_len = 0. Otherwise .token + * points to .token_len chars containing that header content. + */ +struct lws_tokens { + char *token; /**< pointer to start of the token */ + int token_len; /**< length of the token's value */ +}; + +/* enum lws_token_indexes + * these have to be kept in sync with lextable.h / minilex.c + * + * NOTE: These public enums are part of the abi. If you want to add one, + * add it at where specified so existing users are unaffected. + */ +enum lws_token_indexes { + WSI_TOKEN_GET_URI = 0, + WSI_TOKEN_POST_URI = 1, + WSI_TOKEN_OPTIONS_URI = 2, + WSI_TOKEN_HOST = 3, + WSI_TOKEN_CONNECTION = 4, + WSI_TOKEN_UPGRADE = 5, + WSI_TOKEN_ORIGIN = 6, + WSI_TOKEN_DRAFT = 7, + WSI_TOKEN_CHALLENGE = 8, + WSI_TOKEN_EXTENSIONS = 9, + WSI_TOKEN_KEY1 = 10, + WSI_TOKEN_KEY2 = 11, + WSI_TOKEN_PROTOCOL = 12, + WSI_TOKEN_ACCEPT = 13, + WSI_TOKEN_NONCE = 14, + WSI_TOKEN_HTTP = 15, + WSI_TOKEN_HTTP2_SETTINGS = 16, + WSI_TOKEN_HTTP_ACCEPT = 17, + WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18, + WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19, + WSI_TOKEN_HTTP_IF_NONE_MATCH = 20, + WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21, + WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22, + WSI_TOKEN_HTTP_PRAGMA = 23, + WSI_TOKEN_HTTP_CACHE_CONTROL = 24, + WSI_TOKEN_HTTP_AUTHORIZATION = 25, + WSI_TOKEN_HTTP_COOKIE = 26, + WSI_TOKEN_HTTP_CONTENT_LENGTH = 27, + WSI_TOKEN_HTTP_CONTENT_TYPE = 28, + WSI_TOKEN_HTTP_DATE = 29, + WSI_TOKEN_HTTP_RANGE = 30, + WSI_TOKEN_HTTP_REFERER = 31, + WSI_TOKEN_KEY = 32, + WSI_TOKEN_VERSION = 33, + WSI_TOKEN_SWORIGIN = 34, + + WSI_TOKEN_HTTP_COLON_AUTHORITY = 35, + WSI_TOKEN_HTTP_COLON_METHOD = 36, + WSI_TOKEN_HTTP_COLON_PATH = 37, + WSI_TOKEN_HTTP_COLON_SCHEME = 38, + WSI_TOKEN_HTTP_COLON_STATUS = 39, + + WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40, + WSI_TOKEN_HTTP_ACCEPT_RANGES = 41, + WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42, + WSI_TOKEN_HTTP_AGE = 43, + WSI_TOKEN_HTTP_ALLOW = 44, + WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45, + WSI_TOKEN_HTTP_CONTENT_ENCODING = 46, + WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47, + WSI_TOKEN_HTTP_CONTENT_LOCATION = 48, + WSI_TOKEN_HTTP_CONTENT_RANGE = 49, + WSI_TOKEN_HTTP_ETAG = 50, + WSI_TOKEN_HTTP_EXPECT = 51, + WSI_TOKEN_HTTP_EXPIRES = 52, + WSI_TOKEN_HTTP_FROM = 53, + WSI_TOKEN_HTTP_IF_MATCH = 54, + WSI_TOKEN_HTTP_IF_RANGE = 55, + WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56, + WSI_TOKEN_HTTP_LAST_MODIFIED = 57, + WSI_TOKEN_HTTP_LINK = 58, + WSI_TOKEN_HTTP_LOCATION = 59, + WSI_TOKEN_HTTP_MAX_FORWARDS = 60, + WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61, + WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62, + WSI_TOKEN_HTTP_REFRESH = 63, + WSI_TOKEN_HTTP_RETRY_AFTER = 64, + WSI_TOKEN_HTTP_SERVER = 65, + WSI_TOKEN_HTTP_SET_COOKIE = 66, + WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67, + WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68, + WSI_TOKEN_HTTP_USER_AGENT = 69, + WSI_TOKEN_HTTP_VARY = 70, + WSI_TOKEN_HTTP_VIA = 71, + WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72, + + WSI_TOKEN_PATCH_URI = 73, + WSI_TOKEN_PUT_URI = 74, + WSI_TOKEN_DELETE_URI = 75, + + WSI_TOKEN_HTTP_URI_ARGS = 76, + WSI_TOKEN_PROXY = 77, + WSI_TOKEN_HTTP_X_REAL_IP = 78, + WSI_TOKEN_HTTP1_0 = 79, + + /****** add new things just above ---^ ******/ + + /* use token storage to stash these internally, not for + * user use */ + + _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, + _WSI_TOKEN_CLIENT_PEER_ADDRESS, + _WSI_TOKEN_CLIENT_URI, + _WSI_TOKEN_CLIENT_HOST, + _WSI_TOKEN_CLIENT_ORIGIN, + _WSI_TOKEN_CLIENT_METHOD, + + /* always last real token index*/ + WSI_TOKEN_COUNT, + + /* parser state additions, no storage associated */ + WSI_TOKEN_NAME_PART, + WSI_TOKEN_SKIPPING, + WSI_TOKEN_SKIPPING_SAW_CR, + WSI_PARSING_COMPLETE, + WSI_INIT_TOKEN_MUXURL, +}; + +struct lws_token_limits { + unsigned short token_limit[WSI_TOKEN_COUNT]; /**< max chars for this token */ +}; + +/** + * lws_token_to_string() - returns a textual representation of a hdr token index + * + * \param: token index + */ +LWS_VISIBLE LWS_EXTERN const unsigned char * +lws_token_to_string(enum lws_token_indexes token); + + +/** + * lws_hdr_total_length: report length of all fragments of a header totalled up + * The returned length does not include the space for a + * terminating '\0' + * + * \param wsi: websocket connection + * \param h: which header index we are interested in + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h); + +/** + * lws_hdr_fragment_length: report length of a single fragment of a header + * The returned length does not include the space for a + * terminating '\0' + * + * \param wsi: websocket connection + * \param h: which header index we are interested in + * \param frag_idx: which fragment of h we want to get the length of + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx); + +/** + * lws_hdr_copy() - copy a single fragment of the given header to a buffer + * The buffer length len must include space for an additional + * terminating '\0', or it will fail returning -1. + * + * \param wsi: websocket connection + * \param dest: destination buffer + * \param len: length of destination buffer + * \param h: which header index we are interested in + * + * copies the whole, aggregated header, even if it was delivered in + * several actual headers piece by piece + */ +LWS_VISIBLE LWS_EXTERN int +lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h); + +/** + * lws_hdr_copy_fragment() - copy a single fragment of the given header to a buffer + * The buffer length len must include space for an additional + * terminating '\0', or it will fail returning -1. + * If the requested fragment index is not present, it fails + * returning -1. + * + * \param wsi: websocket connection + * \param dest: destination buffer + * \param len: length of destination buffer + * \param h: which header index we are interested in + * \param frag_idx: which fragment of h we want to copy + * + * Normally this is only useful + * to parse URI arguments like ?x=1&y=2, token index WSI_TOKEN_HTTP_URI_ARGS + * fragment 0 will contain "x=1" and fragment 1 "y=2" + */ +LWS_VISIBLE LWS_EXTERN int +lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len, + enum lws_token_indexes h, int frag_idx); + +/** + * lws_get_urlarg_by_name() - return pointer to arg value if present + * \param wsi: the connection to check + * \param name: the arg name, like "token=" + * \param buf: the buffer to receive the urlarg (including the name= part) + * \param len: the length of the buffer to receive the urlarg + * + * Returns NULL if not found or a pointer inside buf to just after the + * name= part. + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len); +///@} + +/*! \defgroup HTTP-headers-create HTTP headers: create + * + * ## HTTP headers: Create + * + * These apis allow you to create HTTP response headers in a way compatible with + * both HTTP/1.x and HTTP/2. + * + * They each append to a buffer taking care about the buffer end, which is + * passed in as a pointer. When data is written to the buffer, the current + * position p is updated accordingly. + * + * All of these apis are LWS_WARN_UNUSED_RESULT as they can run out of space + * and fail with nonzero return. + */ +///@{ +/** + * lws_add_http_header_status() - add the HTTP response status code + * + * \param wsi: the connection to check + * \param code: an HTTP code like 200, 404 etc (see enum http_status) + * \param p: pointer to current position in buffer pointer + * \param end: pointer to end of buffer + * + * Adds the initial response code, so should be called first + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_add_http_header_status(struct lws *wsi, + unsigned int code, unsigned char **p, + unsigned char *end); +/** + * lws_add_http_header_by_name() - append named header and value + * + * \param wsi: the connection to check + * \param name: the hdr name, like "my-header" + * \param value: the value after the = for this header + * \param length: the length of the value + * \param p: pointer to current position in buffer pointer + * \param end: pointer to end of buffer + * + * Appends name: value to the headers + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name, + const unsigned char *value, int length, + unsigned char **p, unsigned char *end); +/** + * lws_add_http_header_by_token() - append given header and value + * + * \param wsi: the connection to check + * \param token: the token index for the hdr + * \param value: the value after the = for this header + * \param length: the length of the value + * \param p: pointer to current position in buffer pointer + * \param end: pointer to end of buffer + * + * Appends name=value to the headers, but is able to take advantage of better + * HTTP/2 coding mechanisms where possible. + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token, + const unsigned char *value, int length, + unsigned char **p, unsigned char *end); +/** + * lws_add_http_header_by_name() - append content-length helper + * + * \param wsi: the connection to check + * \param content_length: the content length to use + * \param p: pointer to current position in buffer pointer + * \param end: pointer to end of buffer + * + * Appends content-length: content_length to the headers + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_add_http_header_content_length(struct lws *wsi, + unsigned long content_length, + unsigned char **p, unsigned char *end); +/** + * lws_finalize_http_header() - terminate header block + * + * \param wsi: the connection to check + * \param p: pointer to current position in buffer pointer + * \param end: pointer to end of buffer + * + * Indicates no more headers will be added + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_finalize_http_header(struct lws *wsi, unsigned char **p, + unsigned char *end); +///@} + +/** \defgroup form-parsing Form Parsing + * \ingroup http + * ##POSTed form parsing functions + * + * These lws_spa (stateful post arguments) apis let you parse and urldecode + * POSTed form arguments, both using simple urlencoded and multipart transfer + * encoding. + * + * It's capable of handling file uploads as well a named input parsing, + * and the apis are the same for both form upload styles. + * + * You feed it a list of parameter names and it creates pointers to the + * urldecoded arguments: file upload parameters pass the file data in chunks to + * a user-supplied callback as they come. + * + * Since it's stateful, it handles the incoming data needing more than one + * POST_BODY callback and has no limit on uploaded file size. + */ +///@{ + +/** enum lws_spa_fileupload_states */ +enum lws_spa_fileupload_states { + LWS_UFS_CONTENT, + /**< a chunk of file content has arrived */ + LWS_UFS_FINAL_CONTENT, + /**< the last chunk (possibly zero length) of file content has arrived */ + LWS_UFS_OPEN + /**< a new file is starting to arrive */ +}; + +/** + * lws_spa_fileupload_cb() - callback to receive file upload data + * + * \param data: opt_data pointer set in lws_spa_create + * \param name: name of the form field being uploaded + * \param filename: original filename from client + * \param buf: start of data to receive + * \param len: length of data to receive + * \param state: information about how this call relates to file + * + * Notice name and filename shouldn't be trusted, as they are passed from + * HTTP provided by the client. + */ +typedef int (*lws_spa_fileupload_cb)(void *data, const char *name, + const char *filename, char *buf, int len, + enum lws_spa_fileupload_states state); + +/** struct lws_spa - opaque urldecode parser capable of handling multipart + * and file uploads */ +struct lws_spa; + +/** + * lws_spa_create() - create urldecode parser + * + * \param wsi: lws connection (used to find Content Type) + * \param param_names: array of form parameter names, like "username" + * \param count_params: count of param_names + * \param max_storage: total amount of form parameter values we can store + * \param opt_cb: NULL, or callback to receive file upload data. + * \param opt_data: NULL, or user pointer provided to opt_cb. + * + * Creates a urldecode parser and initializes it. + * + * opt_cb can be NULL if you just want normal name=value parsing, however + * if one or more entries in your form are bulk data (file transfer), you + * can provide this callback and filter on the name callback parameter to + * treat that urldecoded data separately. The callback should return -1 + * in case of fatal error, and 0 if OK. + */ +LWS_VISIBLE LWS_EXTERN struct lws_spa * +lws_spa_create(struct lws *wsi, const char * const *param_names, + int count_params, int max_storage, lws_spa_fileupload_cb opt_cb, + void *opt_data); + +/** + * lws_spa_process() - parses a chunk of input data + * + * \param spa: the parser object previously created + * \param in: incoming, urlencoded data + * \param len: count of bytes valid at \param in + */ +LWS_VISIBLE LWS_EXTERN int +lws_spa_process(struct lws_spa *spa, const char *in, int len); + +/** + * lws_spa_finalize() - indicate incoming data completed + * + * \param spa: the parser object previously created + */ +LWS_VISIBLE LWS_EXTERN int +lws_spa_finalize(struct lws_spa *spa); + +/** + * lws_spa_get_length() - return length of parameter value + * + * \param spa: the parser object previously created + * \param n: parameter ordinal to return length of value for + */ +LWS_VISIBLE LWS_EXTERN int +lws_spa_get_length(struct lws_spa *spa, int n); + +/** + * lws_spa_get_string() - return pointer to parameter value + * \param spa: the parser object previously created + * \param n: parameter ordinal to return pointer to value for + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_spa_get_string(struct lws_spa *spa, int n); + +/** + * lws_spa_destroy() - destroy parser object + * + * \param spa: the parser object previously created + */ +LWS_VISIBLE LWS_EXTERN int +lws_spa_destroy(struct lws_spa *spa); +///@} + +/*! \defgroup urlendec Urlencode and Urldecode + * \ingroup http + * + * ##HTML chunked Substitution + * + * APIs for receiving chunks of text, replacing a set of variable names via + * a callback, and then prepending and appending HTML chunked encoding + * headers. + */ +//@{ + +/** + * lws_urlencode() - like strncpy but with urlencoding + * + * \param escaped: output buffer + * \param string: input buffer ('/0' terminated) + * \param len: output buffer max length + * + * Because urlencoding expands the output string, it's not + * possible to do it in-place, ie, with escaped == string + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_urlencode(char *escaped, const char *string, int len); + +/* + * URLDECODE 1 / 2 + * + * This simple urldecode only operates until the first '\0' and requires the + * data to exist all at once + */ +/** + * lws_urldecode() - like strncpy but with urldecoding + * + * \param string: output buffer + * \param escaped: input buffer ('\0' terminated) + * \param len: output buffer max length + * + * This is only useful for '\0' terminated strings + * + * Since urldecoding only shrinks the output string, it is possible to + * do it in-place, ie, string == escaped + */ +LWS_VISIBLE LWS_EXTERN int +lws_urldecode(char *string, const char *escaped, int len); +///@} +/** + * lws_return_http_status() - Return simple http status + * \param wsi: Websocket instance (available from user callback) + * \param code: Status index, eg, 404 + * \param html_body: User-readable HTML description < 1KB, or NULL + * + * Helper to report HTTP errors back to the client cleanly and + * consistently + */ +LWS_VISIBLE LWS_EXTERN int +lws_return_http_status(struct lws *wsi, unsigned int code, + const char *html_body); + +/** + * lws_http_redirect() - write http redirect into buffer + * + * \param wsi: websocket connection + * \param code: HTTP response code (eg, 301) + * \param loc: where to redirect to + * \param len: length of loc + * \param p: pointer current position in buffer (updated as we write) + * \param end: pointer to end of buffer + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len, + unsigned char **p, unsigned char *end); + +/** + * lws_http_transaction_completed() - wait for new http transaction or close + * \param wsi: websocket connection + * + * Returns 1 if the HTTP connection must close now + * Returns 0 and resets connection to wait for new HTTP header / + * transaction if possible + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_http_transaction_completed(struct lws *wsi); +///@} + +/*! \defgroup pur Sanitize / purify SQL and JSON helpers + * + * ##Sanitize / purify SQL and JSON helpers + * + * APIs for escaping untrusted JSON and SQL safely before use + */ +//@{ + +/** + * lws_sql_purify() - like strncpy but with escaping for sql quotes + * + * \param escaped: output buffer + * \param string: input buffer ('/0' terminated) + * \param len: output buffer max length + * + * Because escaping expands the output string, it's not + * possible to do it in-place, ie, with escaped == string + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_sql_purify(char *escaped, const char *string, int len); + +/** + * lws_json_purify() - like strncpy but with escaping for json chars + * + * \param escaped: output buffer + * \param string: input buffer ('/0' terminated) + * \param len: output buffer max length + * + * Because escaping expands the output string, it's not + * possible to do it in-place, ie, with escaped == string + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_json_purify(char *escaped, const char *string, int len); +///@} + +/*! \defgroup ev libev helpers + * + * ##libev helpers + * + * APIs specific to libev event loop itegration + */ +///@{ + +#ifdef LWS_USE_LIBEV +typedef void (lws_ev_signal_cb_t)(EV_P_ struct ev_signal *w, int revents); + +LWS_VISIBLE LWS_EXTERN int +lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint, + lws_ev_signal_cb_t *cb); + +LWS_VISIBLE LWS_EXTERN int +lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi); + +LWS_VISIBLE LWS_EXTERN void +lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents); +#endif /* LWS_USE_LIBEV */ + +///@} + +/*! \defgroup uv libuv helpers + * + * ##libuv helpers + * + * APIs specific to libuv event loop itegration + */ +///@{ +#ifdef LWS_USE_LIBUV +LWS_VISIBLE LWS_EXTERN int +lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint, + uv_signal_cb cb); + +LWS_VISIBLE LWS_EXTERN void +lws_libuv_run(const struct lws_context *context, int tsi); + +LWS_VISIBLE LWS_EXTERN void +lws_libuv_stop(struct lws_context *context); + +LWS_VISIBLE LWS_EXTERN int +lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi); + +LWS_VISIBLE LWS_EXTERN uv_loop_t * +lws_uv_getloop(struct lws_context *context, int tsi); + +LWS_VISIBLE LWS_EXTERN void +lws_uv_sigint_cb(uv_signal_t *watcher, int signum); +#endif /* LWS_USE_LIBUV */ +///@} + +/*! \defgroup timeout Connection timeouts + + APIs related to setting connection timeouts +*/ +//@{ + +/* + * NOTE: These public enums are part of the abi. If you want to add one, + * add it at where specified so existing users are unaffected. + */ +enum pending_timeout { + NO_PENDING_TIMEOUT = 0, + PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1, + PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2, + PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3, + PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4, + PENDING_TIMEOUT_AWAITING_PING = 5, + PENDING_TIMEOUT_CLOSE_ACK = 6, + PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE = 7, + PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8, + PENDING_TIMEOUT_SSL_ACCEPT = 9, + PENDING_TIMEOUT_HTTP_CONTENT = 10, + PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11, + PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12, + PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13, + PENDING_TIMEOUT_CGI = 14, + PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE = 15, + PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING = 16, + PENDING_TIMEOUT_WS_PONG_CHECK_GET_PONG = 17, + PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD = 18, + + /****** add new things just above ---^ ******/ +}; + +/** + * lws_set_timeout() - marks the wsi as subject to a timeout + * + * You will not need this unless you are doing something special + * + * \param wsi: Websocket connection instance + * \param reason: timeout reason + * \param secs: how many seconds + */ +LWS_VISIBLE LWS_EXTERN void +lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs); +///@} + +/*! \defgroup sending-data Sending data + + APIs related to writing data on a connection +*/ +//@{ +#if !defined(LWS_SIZEOFPTR) +#define LWS_SIZEOFPTR (sizeof (void *)) +#endif +#if !defined(u_int64_t) +#define u_int64_t unsigned long long +#endif + +#if defined(__x86_64__) +#define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */ +#else +#define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */ +#endif +#define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \ + ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n)) +#define LWS_PRE _LWS_PAD(4 + 10) +/* used prior to 1.7 and retained for backward compatibility */ +#define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE +#define LWS_SEND_BUFFER_POST_PADDING 0 + +/* + * NOTE: These public enums are part of the abi. If you want to add one, + * add it at where specified so existing users are unaffected. + */ +enum lws_write_protocol { + LWS_WRITE_TEXT = 0, + /**< Send a ws TEXT message,the pointer must have LWS_PRE valid + * memory behind it. The receiver expects only valid utf-8 in the + * payload */ + LWS_WRITE_BINARY = 1, + /**< Send a ws BINARY message, the pointer must have LWS_PRE valid + * memory behind it. Any sequence of bytes is valid */ + LWS_WRITE_CONTINUATION = 2, + /**< Continue a previous ws message, the pointer must have LWS_PRE valid + * memory behind it */ + LWS_WRITE_HTTP = 3, + /**< Send HTTP content */ + + /* LWS_WRITE_CLOSE is handled by lws_close_reason() */ + LWS_WRITE_PING = 5, + LWS_WRITE_PONG = 6, + + /* Same as write_http but we know this write ends the transaction */ + LWS_WRITE_HTTP_FINAL = 7, + + /* HTTP2 */ + + LWS_WRITE_HTTP_HEADERS = 8, + /**< Send http headers (http2 encodes this payload and LWS_WRITE_HTTP + * payload differently, http 1.x links also handle this correctly. so + * to be compatible with both in the future,header response part should + * be sent using this regardless of http version expected) + */ + + /****** add new things just above ---^ ******/ + + /* flags */ + + LWS_WRITE_NO_FIN = 0x40, + /**< This part of the message is not the end of the message */ + + LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80 + /**< client packet payload goes out on wire unmunged + * only useful for security tests since normal servers cannot + * decode the content if used */ +}; + + +/** + * lws_write() - Apply protocol then write data to client + * \param wsi: Websocket instance (available from user callback) + * \param buf: The data to send. For data being sent on a websocket + * connection (ie, not default http), this buffer MUST have + * LWS_PRE bytes valid BEFORE the pointer. + * This is so the protocol header data can be added in-situ. + * \param len: Count of the data bytes in the payload starting from buf + * \param protocol: Use LWS_WRITE_HTTP to reply to an http connection, and one + * of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate + * data on a websockets connection. Remember to allow the extra + * bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT + * are used. + * + * This function provides the way to issue data back to the client + * for both http and websocket protocols. + * + * IMPORTANT NOTICE! + * + * When sending with websocket protocol + * + * LWS_WRITE_TEXT, + * LWS_WRITE_BINARY, + * LWS_WRITE_CONTINUATION, + * LWS_WRITE_PING, + * LWS_WRITE_PONG + * + * the send buffer has to have LWS_PRE bytes valid BEFORE + * the buffer pointer you pass to lws_write(). + * + * This allows us to add protocol info before and after the data, and send as + * one packet on the network without payload copying, for maximum efficiency. + * + * So for example you need this kind of code to use lws_write with a + * 128-byte payload + * + * char buf[LWS_PRE + 128]; + * + * // fill your part of the buffer... for example here it's all zeros + * memset(&buf[LWS_PRE], 0, 128); + * + * lws_write(wsi, &buf[LWS_PRE], 128, LWS_WRITE_TEXT); + * + * When sending HTTP, with + * + * LWS_WRITE_HTTP, + * LWS_WRITE_HTTP_HEADERS + * LWS_WRITE_HTTP_FINAL + * + * there is no protocol data prepended, and don't need to take care about the + * LWS_PRE bytes valid before the buffer pointer. + * + * LWS_PRE is at least the frame nonce + 2 header + 8 length + * LWS_SEND_BUFFER_POST_PADDING is deprecated, it's now 0 and can be left off. + * The example apps no longer use it. + * + * Pad LWS_PRE to the CPU word size, so that word references + * to the address immediately after the padding won't cause an unaligned access + * error. Sometimes for performance reasons the recommended padding is even + * larger than sizeof(void *). + * + * In the case of sending using websocket protocol, be sure to allocate + * valid storage before and after buf as explained above. This scheme + * allows maximum efficiency of sending data and protocol in a single + * packet while not burdening the user code with any protocol knowledge. + * + * Return may be -1 for a fatal error needing connection close, or a + * positive number reflecting the amount of bytes actually sent. This + * can be less than the requested number of bytes due to OS memory + * pressure at any given time. + */ +LWS_VISIBLE LWS_EXTERN int +lws_write(struct lws *wsi, unsigned char *buf, size_t len, + enum lws_write_protocol protocol); + +/* helper for case where buffer may be const */ +#define lws_write_http(wsi, buf, len) \ + lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP) + +///@} + +/** \defgroup callback-when-writeable Callback when writeable + * + * ##Callback When Writeable + * + * lws can only write data on a connection when it is able to accept more + * data without blocking. + * + * So a basic requirement is we should only use the lws_write() apis when the + * connection we want to write on says that he can accept more data. + * + * When lws cannot complete your send at the time, it will buffer the data + * and send it in the background, suppressing any further WRITEABLE callbacks + * on that connection until it completes. So it is important to write new + * things in a new writeable callback. + * + * These apis reflect the various ways we can indicate we would like to be + * called back when one or more connections is writeable. + */ +///@{ + +/** + * lws_callback_on_writable() - Request a callback when this socket + * becomes able to be written to without + * blocking + * + * \param wsi: Websocket connection instance to get callback for + * + * - Which: only this wsi + * - When: when the individual connection becomes writeable + * - What: LWS_CALLBACK_*_WRITEABLE + */ +LWS_VISIBLE LWS_EXTERN int +lws_callback_on_writable(struct lws *wsi); + +/** + * lws_callback_on_writable_all_protocol() - Request a callback for all + * connections on same vhost using the given protocol when it + * becomes possible to write to each socket without + * blocking in turn. + * + * \param context: lws_context + * \param protocol: Protocol whose connections will get callbacks + * + * - Which: connections using this protocol on ANY VHOST + * - When: when the individual connection becomes writeable + * - What: LWS_CALLBACK_*_WRITEABLE + */ +LWS_VISIBLE LWS_EXTERN int +lws_callback_on_writable_all_protocol(const struct lws_context *context, + const struct lws_protocols *protocol); + +/** + * lws_callback_on_writable_all_protocol_vhost() - Request a callback for + * all connections using the given protocol when it + * becomes possible to write to each socket without + * blocking in turn. + * + * \param vhost: Only consider connections on this lws_vhost + * \param protocol: Protocol whose connections will get callbacks + * + * - Which: connections using this protocol on GIVEN VHOST ONLY + * - When: when the individual connection becomes writeable + * - What: LWS_CALLBACK_*_WRITEABLE + */ +LWS_VISIBLE LWS_EXTERN int +lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost, + const struct lws_protocols *protocol); + +/** + * lws_callback_all_protocol() - Callback all connections using + * the given protocol with the given reason + * + * \param context: lws_context + * \param protocol: Protocol whose connections will get callbacks + * \param reason: Callback reason index + * + * - Which: connections using this protocol on ALL VHOSTS + * - When: when the individual connection becomes writeable + * - What: reason + */ +LWS_VISIBLE LWS_EXTERN int +lws_callback_all_protocol(struct lws_context *context, + const struct lws_protocols *protocol, int reason); + +/** + * lws_callback_all_protocol_vhost() - Callback all connections using + * the given protocol with the given reason + * + * \param vh: Vhost whose connections will get callbacks + * \param protocol: Which protocol to match + * \param reason: Callback reason index + * + * - Which: connections using this protocol on GIVEN VHOST ONLY + * - When: now + * - What: reason + */ +LWS_VISIBLE LWS_EXTERN int +lws_callback_all_protocol_vhost(struct lws_vhost *vh, + const struct lws_protocols *protocol, int reason); + +/** + * lws_callback_vhost_protocols() - Callback all protocols enabled on a vhost + * with the given reason + * + * \param wsi: wsi whose vhost will get callbacks + * \param reason: Callback reason index + * \param in: in argument to callback + * \param len: len argument to callback + * + * - Which: connections using this protocol on same VHOST as wsi ONLY + * - When: now + * - What: reason + */ +LWS_VISIBLE LWS_EXTERN int +lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len); + +LWS_VISIBLE LWS_EXTERN int +lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len); + +/** + * lws_get_socket_fd() - returns the socket file descriptor + * + * You will not need this unless you are doing something special + * + * \param wsi: Websocket connection instance + */ +LWS_VISIBLE LWS_EXTERN int +lws_get_socket_fd(struct lws *wsi); + +/** + * lws_get_peer_write_allowance() - get the amount of data writeable to peer + * if known + * + * \param wsi: Websocket connection instance + * + * if the protocol does not have any guidance, returns -1. Currently only + * http2 connections get send window information from this API. But your code + * should use it so it can work properly with any protocol. + * + * If nonzero return is the amount of payload data the peer or intermediary has + * reported it has buffer space for. That has NO relationship with the amount + * of buffer space your OS can accept on this connection for a write action. + * + * This number represents the maximum you could send to the peer or intermediary + * on this connection right now without the protocol complaining. + * + * lws manages accounting for send window updates and payload writes + * automatically, so this number reflects the situation at the peer or + * intermediary dynamically. + */ +LWS_VISIBLE LWS_EXTERN size_t +lws_get_peer_write_allowance(struct lws *wsi); +///@} + +/** + * lws_rx_flow_control() - Enable and disable socket servicing for + * received packets. + * + * If the output side of a server process becomes choked, this allows flow + * control for the input side. + * + * \param wsi: Websocket connection instance to get callback for + * \param enable: 0 = disable read servicing for this connection, 1 = enable + */ +LWS_VISIBLE LWS_EXTERN int +lws_rx_flow_control(struct lws *wsi, int enable); + +/** + * lws_rx_flow_allow_all_protocol() - Allow all connections with this protocol to receive + * + * When the user server code realizes it can accept more input, it can + * call this to have the RX flow restriction removed from all connections using + * the given protocol. + * \param context: lws_context + * \param protocol: all connections using this protocol will be allowed to receive + */ +LWS_VISIBLE LWS_EXTERN void +lws_rx_flow_allow_all_protocol(const struct lws_context *context, + const struct lws_protocols *protocol); + +/** + * lws_remaining_packet_payload() - Bytes to come before "overall" + * rx packet is complete + * \param wsi: Websocket instance (available from user callback) + * + * This function is intended to be called from the callback if the + * user code is interested in "complete packets" from the client. + * libwebsockets just passes through payload as it comes and issues a buffer + * additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE + * callback handler can use this API to find out if the buffer it has just + * been given is the last piece of a "complete packet" from the client -- + * when that is the case lws_remaining_packet_payload() will return + * 0. + * + * Many protocols won't care becuse their packets are always small. + */ +LWS_VISIBLE LWS_EXTERN size_t +lws_remaining_packet_payload(struct lws *wsi); + + +/** \defgroup sock-adopt Socket adoption helpers + * ##Socket adoption helpers + * + * When integrating with an external app with its own event loop, these can + * be used to accept connections from someone else's listening socket. + * + * When using lws own event loop, these are not needed. + */ +///@{ + +/** + * lws_adopt_socket() - adopt foreign socket as if listen socket accepted it + * \param context: lws context + * \param accept_fd: fd of already-accepted socket to adopt + * + * Either returns new wsi bound to accept_fd, or closes accept_fd and + * returns NULL, having cleaned up any new wsi pieces. + * + * LWS adopts the socket in http serving mode, it's ready to accept an upgrade + * to ws or just serve http. + */ +LWS_VISIBLE LWS_EXTERN struct lws * +lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd); +/** + * lws_adopt_socket_readbuf() - adopt foreign socket and first rx as if listen socket accepted it + * \param context: lws context + * \param accept_fd: fd of already-accepted socket to adopt + * \param readbuf: NULL or pointer to data that must be drained before reading from + * accept_fd + * \param len: The length of the data held at \param readbuf + * + * Either returns new wsi bound to accept_fd, or closes accept_fd and + * returns NULL, having cleaned up any new wsi pieces. + * + * LWS adopts the socket in http serving mode, it's ready to accept an upgrade + * to ws or just serve http. + * + * If your external code did not already read from the socket, you can use + * lws_adopt_socket() instead. + * + * This api is guaranteed to use the data at \param readbuf first, before reading from + * the socket. + * + * readbuf is limited to the size of the ah rx buf, currently 2048 bytes. + */ +LWS_VISIBLE LWS_EXTERN struct lws * +lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd, + const char *readbuf, size_t len); +///@} + +/** \defgroup net Network related helper APIs + * ##Network related helper APIs + * + * These wrap miscellaneous useful network-related functions + */ +///@{ + +/** + * lws_canonical_hostname() - returns this host's hostname + * + * This is typically used by client code to fill in the host parameter + * when making a client connection. You can only call it after the context + * has been created. + * + * \param context: Websocket context + */ +LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT +lws_canonical_hostname(struct lws_context *context); + +/** + * lws_get_peer_addresses() - Get client address information + * \param wsi: Local struct lws associated with + * \param fd: Connection socket descriptor + * \param name: Buffer to take client address name + * \param name_len: Length of client address name buffer + * \param rip: Buffer to take client address IP dotted quad + * \param rip_len: Length of client address IP buffer + * + * This function fills in name and rip with the name and IP of + * the client connected with socket descriptor fd. Names may be + * truncated if there is not enough room. If either cannot be + * determined, they will be returned as valid zero-length strings. + */ +LWS_VISIBLE LWS_EXTERN void +lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name, + int name_len, char *rip, int rip_len); + +/** + * lws_get_peer_simple() - Get client address information without RDNS + * + * \param wsi: Local struct lws associated with + * \param name: Buffer to take client address name + * \param namelen: Length of client address name buffer + * + * This provides a 123.123.123.123 type IP address in name from the + * peer that has connected to wsi + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_get_peer_simple(struct lws *wsi, char *name, int namelen); +#ifndef LWS_WITH_ESP8266 +/** + * lws_interface_to_sa() - Convert interface name or IP to sockaddr struct + * + * \param ipv6: Allow IPV6 addresses + * \param ifname: Interface name or IP + * \param addr: struct sockaddr_in * to be written + * \param addrlen: Length of addr + * + * This converts a textual network interface name to a sockaddr usable by + * other network functions + */ +LWS_VISIBLE LWS_EXTERN int +lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, + size_t addrlen); +///@} +#endif + +/** \defgroup misc Miscellaneous APIs +* ##Miscellaneous APIs +* +* Various APIs outside of other categories +*/ +///@{ + +/** + * lws_snprintf(): snprintf that truncates the returned length too + * + * \param str: destination buffer + * \param size: bytes left in destination buffer + * \param format: format string + * \param ...: args for format + * + * This lets you correctly truncate buffers by concatenating lengths, if you + * reach the limit the reported length doesn't exceed the limit. + */ +LWS_VISIBLE LWS_EXTERN int +lws_snprintf(char *str, size_t size, const char *format, ...); + +/** + * lws_get_random(): fill a buffer with platform random data + * + * \param context: the lws context + * \param buf: buffer to fill + * \param len: how much to fill + * + * This is intended to be called from the LWS_CALLBACK_RECEIVE callback if + * it's interested to see if the frame it's dealing with was sent in binary + * mode. + */ +LWS_VISIBLE LWS_EXTERN int +lws_get_random(struct lws_context *context, void *buf, int len); +/** + * lws_daemonize(): fill a buffer with platform random data + * + * \param _lock_path: the filepath to write the lock file + * + * Spawn lws as a background process, taking care of various things + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_daemonize(const char *_lock_path); +/** + * lws_get_library_version(): return string describing the version of lws + * + * On unix, also includes the git describe + */ +LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT +lws_get_library_version(void); + +/** + * lws_wsi_user() - get the user data associated with the connection + * \param wsi: lws connection + * + * Not normally needed since it's passed into the callback + */ +LWS_VISIBLE LWS_EXTERN void * +lws_wsi_user(struct lws *wsi); + +/** + * lws_parse_uri: cut up prot:/ads:port/path into pieces + * Notice it does so by dropping '\0' into input string + * and the leading / on the path is consequently lost + * + * \param p: incoming uri string.. will get written to + * \param prot: result pointer for protocol part (https://) + * \param ads: result pointer for address part + * \param port: result pointer for port part + * \param path: result pointer for path part + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_parse_uri(char *p, const char **prot, const char **ads, int *port, + const char **path); + +/** + * lws_now_secs(): return seconds since 1970-1-1 + */ +LWS_VISIBLE LWS_EXTERN unsigned long +lws_now_secs(void); + +/** + * lws_get_context - Allow geting lws_context from a Websocket connection + * instance + * + * With this function, users can access context in the callback function. + * Otherwise users may have to declare context as a global variable. + * + * \param wsi: Websocket connection instance + */ +LWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT +lws_get_context(const struct lws *wsi); + +/** + * lws_get_count_threads(): how many service threads the context uses + * + * \param context: the lws context + * + * By default this is always 1, if you asked for more than lws can handle it + * will clip the number of threads. So you can use this to find out how many + * threads are actually in use. + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_get_count_threads(struct lws_context *context); + +/** + * lws_get_parent() - get parent wsi or NULL + * \param wsi: lws connection + * + * Specialized wsi like cgi stdin/out/err are associated to a parent wsi, + * this allows you to get their parent. + */ +LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT +lws_get_parent(const struct lws *wsi); + +/** + * lws_get_child() - get child wsi or NULL + * \param wsi: lws connection + * + * Allows you to find a related wsi from the parent wsi. + */ +LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT +lws_get_child(const struct lws *wsi); + + +/* + * \deprecated DEPRECATED Note: this is not normally needed as a user api. + * It's provided in case it is + * useful when integrating with other app poll loop service code. + */ +LWS_VISIBLE LWS_EXTERN int +lws_read(struct lws *wsi, unsigned char *buf, size_t len); + +/** + * lws_set_allocator() - custom allocator support + * + * \param realloc + * + * Allows you to replace the allocator (and deallocator) used by lws + */ +LWS_VISIBLE LWS_EXTERN void +lws_set_allocator(void *(*realloc)(void *ptr, size_t size)); +///@} + +/** \defgroup wsstatus Websocket status APIs + * ##Websocket connection status APIs + * + * These provide information about ws connection or message status + */ +///@{ +/** + * lws_send_pipe_choked() - tests if socket is writable or not + * \param wsi: lws connection + * + * Allows you to check if you can write more on the socket + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_send_pipe_choked(struct lws *wsi); + +/** + * lws_is_final_fragment() - tests if last part of ws message + * \param wsi: lws connection + */ +LWS_VISIBLE LWS_EXTERN int +lws_is_final_fragment(struct lws *wsi); + +/** + * lws_get_reserved_bits() - access reserved bits of ws frame + * \param wsi: lws connection + */ +LWS_VISIBLE LWS_EXTERN unsigned char +lws_get_reserved_bits(struct lws *wsi); + +/** + * lws_partial_buffered() - find out if lws buffered the last write + * \param wsi: websocket connection to check + * + * Returns 1 if you cannot use lws_write because the last + * write on this connection is still buffered, and can't be cleared without + * returning to the service loop and waiting for the connection to be + * writeable again. + * + * If you will try to do >1 lws_write call inside a single + * WRITEABLE callback, you must check this after every write and bail if + * set, ask for a new writeable callback and continue writing from there. + * + * This is never set at the start of a writeable callback, but any write + * may set it. + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_partial_buffered(struct lws *wsi); + +/** + * lws_frame_is_binary(): true if the current frame was sent in binary mode + * + * \param wsi: the connection we are inquiring about + * + * This is intended to be called from the LWS_CALLBACK_RECEIVE callback if + * it's interested to see if the frame it's dealing with was sent in binary + * mode. + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_frame_is_binary(struct lws *wsi); + +/** + * lws_is_ssl() - Find out if connection is using SSL + * \param wsi: websocket connection to check + * + * Returns 0 if the connection is not using SSL, 1 if using SSL and + * using verified cert, and 2 if using SSL but the cert was not + * checked (appears for client wsi told to skip check on connection) + */ +LWS_VISIBLE LWS_EXTERN int +lws_is_ssl(struct lws *wsi); +/** + * lws_is_cgi() - find out if this wsi is running a cgi process + * \param wsi: lws connection + */ +LWS_VISIBLE LWS_EXTERN int +lws_is_cgi(struct lws *wsi); +///@} + + +/** \defgroup sha SHA and B64 helpers + * ##SHA and B64 helpers + * + * These provide SHA-1 and B64 helper apis + */ +///@{ +#ifdef LWS_SHA1_USE_OPENSSL_NAME +#define lws_SHA1 SHA1 +#else +/** + * lws_SHA1(): make a SHA-1 digest of a buffer + * + * \param d: incoming buffer + * \param n: length of incoming buffer + * \param md: buffer for message digest (must be >= 20 bytes) + * + * Reduces any size buffer into a 20-byte SHA-1 hash. + */ +LWS_VISIBLE LWS_EXTERN unsigned char * +lws_SHA1(const unsigned char *d, size_t n, unsigned char *md); +#endif +/** + * lws_b64_encode_string(): encode a string into base 64 + * + * \param in: incoming buffer + * \param in_len: length of incoming buffer + * \param out: result buffer + * \param out_size: length of result buffer + * + * Encodes a string using b64 + */ +LWS_VISIBLE LWS_EXTERN int +lws_b64_encode_string(const char *in, int in_len, char *out, int out_size); +/** + * lws_b64_decode_string(): decode a string from base 64 + * + * \param in: incoming buffer + * \param out: result buffer + * \param out_size: length of result buffer + * + * Decodes a string using b64 + */ +LWS_VISIBLE LWS_EXTERN int +lws_b64_decode_string(const char *in, char *out, int out_size); +///@} + + +/*! \defgroup cgi cgi handling + * + * ##CGI handling + * + * These functions allow low-level control over stdin/out/err of the cgi. + * + * However for most cases, binding the cgi to http in and out, the default + * lws implementation already does the right thing. + */ +#ifdef LWS_WITH_CGI +enum lws_enum_stdinouterr { + LWS_STDIN = 0, + LWS_STDOUT = 1, + LWS_STDERR = 2, +}; + +enum lws_cgi_hdr_state { + LCHS_HEADER, + LCHS_CR1, + LCHS_LF1, + LCHS_CR2, + LCHS_LF2, + LHCS_PAYLOAD, + LCHS_SINGLE_0A, +}; + +struct lws_cgi_args { + struct lws **stdwsi; /**< get fd with lws_get_socket_fd() */ + enum lws_enum_stdinouterr ch; /**< channel index */ + unsigned char *data; /**< for messages with payload */ + enum lws_cgi_hdr_state hdr_state; /**< track where we are in cgi headers */ + int len; /**< length */ +}; + + +/** + * lws_cgi: spawn network-connected cgi process + * + * \param wsi: connection to own the process + * \param exec_array: array of "exec-name" "arg1" ... "argn" NULL + * \param script_uri_path_len: how many chars on the left of the uri are the path to the cgi + * \param timeout_secs: seconds script should be allowed to run + * \param mp_cgienv: pvo list with per-vhost cgi options to put in env + */ +LWS_VISIBLE LWS_EXTERN int +lws_cgi(struct lws *wsi, const char * const *exec_array, + int script_uri_path_len, int timeout_secs, + const struct lws_protocol_vhost_options *mp_cgienv); + +/** + * lws_cgi_write_split_stdout_headers: write cgi output accounting for header part + * + * \param wsi: connection to own the process + */ +LWS_VISIBLE LWS_EXTERN int +lws_cgi_write_split_stdout_headers(struct lws *wsi); + +/** + * lws_cgi_kill: terminate cgi process associated with wsi + * + * \param wsi: connection to own the process + */ +LWS_VISIBLE LWS_EXTERN int +lws_cgi_kill(struct lws *wsi); +#endif +///@} + + +/*! \defgroup fops file operation wrapping + * + * ##File operation wrapping + * + * Use these helper functions if you want to access a file from the perspective + * of a specific wsi, which is usually the case. If you just want contextless + * file access, use the fops callbacks directly with NULL wsi instead of these + * helpers. + * + * If so, then it calls the platform handler or user overrides where present + * (as defined in info->fops) + * + * The advantage from all this is user code can be portable for file operations + * without having to deal with differences between platforms. + */ +//@{ + +/** struct lws_plat_file_ops - Platform-specific file operations + * + * These provide platform-agnostic ways to deal with filesystem access in the + * library and in the user code. + */ +struct lws_plat_file_ops { + lws_filefd_type (*open)(struct lws *wsi, const char *filename, + unsigned long *filelen, int flags); + /**< Open file (always binary access if plat supports it) + * filelen is filled on exit to be the length of the file + * flags should be set to O_RDONLY or O_RDWR */ + int (*close)(struct lws *wsi, lws_filefd_type fd); + /**< close file */ + unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd, + long offset_from_cur_pos); + /**< seek from current position */ + int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount, + unsigned char *buf, unsigned long len); + /**< Read from file, on exit *amount is set to amount actually read */ + int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount, + unsigned char *buf, unsigned long len); + /**< Write to file, on exit *amount is set to amount actually written */ + + /* Add new things just above here ---^ + * This is part of the ABI, don't needlessly break compatibility */ +}; + +/** + * lws_get_fops() - get current file ops + * + * \param context: context + */ +LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT +lws_get_fops(struct lws_context *context); + +/** + * lws_plat_file_open() - file open operations + * + * \param wsi: connection doing the opening + * \param filename: filename to open + * \param filelen: length of file (filled in by call) + * \param flags: open flags + */ +static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT +lws_plat_file_open(struct lws *wsi, const char *filename, + unsigned long *filelen, int flags) +{ + return lws_get_fops(lws_get_context(wsi))->open(wsi, filename, + filelen, flags); +} + +/** + * lws_plat_file_close() - close file + * + * \param wsi: connection opened by + * \param fd: file descriptor + */ +static LWS_INLINE int +lws_plat_file_close(struct lws *wsi, lws_filefd_type fd) +{ + return lws_get_fops(lws_get_context(wsi))->close(wsi, fd); +} + +/** + * lws_plat_file_seek_cur() - close file + * + * \param wsi: connection opened by + * \param fd: file descriptor + * \param offset: position to seek to + */ +static LWS_INLINE unsigned long +lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset) +{ + return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset); +} +/** + * lws_plat_file_read() - read from file + * + * \param wsi: connection opened by + * \param fd: file descriptor + * \param amount: how much to read (rewritten by call) + * \param buf: buffer to write to + * \param len: max length + */ +static LWS_INLINE int LWS_WARN_UNUSED_RESULT +lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount, + unsigned char *buf, unsigned long len) +{ + return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf, + len); +} +/** + * lws_plat_file_write() - write from file + * + * \param wsi: connection opened by + * \param fd: file descriptor + * \param amount: how much to write (rewritten by call) + * \param buf: buffer to read from + * \param len: max length + */ +static LWS_INLINE int LWS_WARN_UNUSED_RESULT +lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount, + unsigned char *buf, unsigned long len) +{ + return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, buf, + len); +} +//@} + +/** \defgroup smtp + * \ingroup lwsapi + * ##SMTP related functions + * + * These apis let you communicate with a local SMTP server to send email from + * lws. It handles all the SMTP sequencing and protocol actions. + * + * Your system should have postfix, sendmail or another MTA listening on port + * 25 and able to send email using the "mail" commandline app. Usually distro + * MTAs are configured for this by default. + * + * It runs via its own libuv events if initialized (which requires giving it + * a libuv loop to attach to). + * + * It operates using three callbacks, on_next() queries if there is a new email + * to send, on_get_body() asks for the body of the email, and on_sent() is + * called after the email is successfully sent. + * + * To use it + * + * - create an lws_email struct + * + * - initialize data, loop, the email_* strings, max_content_size and + * the callbacks + * + * - call lws_email_init() + * + * When you have at least one email to send, call lws_email_check() to + * schedule starting to send it. + */ +//@{ +#ifdef LWS_WITH_SMTP + +/** enum lwsgs_smtp_states - where we are in SMTP protocol sequence */ +enum lwsgs_smtp_states { + LGSSMTP_IDLE, /**< awaiting new email */ + LGSSMTP_CONNECTING, /**< opening tcp connection to MTA */ + LGSSMTP_CONNECTED, /**< tcp connection to MTA is connected */ + LGSSMTP_SENT_HELO, /**< sent the HELO */ + LGSSMTP_SENT_FROM, /**< sent FROM */ + LGSSMTP_SENT_TO, /**< sent TO */ + LGSSMTP_SENT_DATA, /**< sent DATA request */ + LGSSMTP_SENT_BODY, /**< sent the email body */ + LGSSMTP_SENT_QUIT, /**< sent the session quit */ +}; + +/** struct lws_email - abstract context for performing SMTP operations */ +struct lws_email { + void *data; + /**< opaque pointer set by user code and available to the callbacks */ + uv_loop_t *loop; + /**< the libuv loop we will work on */ + + char email_smtp_ip[32]; /**< Fill before init, eg, "127.0.0.1" */ + char email_helo[32]; /**< Fill before init, eg, "myserver.com" */ + char email_from[100]; /**< Fill before init or on_next */ + char email_to[100]; /**< Fill before init or on_next */ + + unsigned int max_content_size; + /**< largest possible email body size */ + + /* Fill all the callbacks before init */ + + int (*on_next)(struct lws_email *email); + /**< (Fill in before calling lws_email_init) + * called when idle, 0 = another email to send, nonzero is idle. + * If you return 0, all of the email_* char arrays must be set + * to something useful. */ + int (*on_sent)(struct lws_email *email); + /**< (Fill in before calling lws_email_init) + * called when transfer of the email to the SMTP server was + * successful, your callback would remove the current email + * from its queue */ + int (*on_get_body)(struct lws_email *email, char *buf, int len); + /**< (Fill in before calling lws_email_init) + * called when the body part of the queued email is about to be + * sent to the SMTP server. */ + + + /* private things */ + uv_timer_t timeout_email; /**< private */ + enum lwsgs_smtp_states estate; /**< private */ + uv_connect_t email_connect_req; /**< private */ + uv_tcp_t email_client; /**< private */ + time_t email_connect_started; /**< private */ + char email_buf[256]; /**< private */ + char *content; /**< private */ +}; + +/** + * lws_email_init() - Initialize a struct lws_email + * + * \param email: struct lws_email to init + * \param loop: libuv loop to use + * \param max_content: max email content size + * + * Prepares a struct lws_email for use ending SMTP + */ +LWS_VISIBLE LWS_EXTERN int +lws_email_init(struct lws_email *email, uv_loop_t *loop, int max_content); + +/** + * lws_email_check() - Request check for new email + * + * \param email: struct lws_email context to check + * + * Schedules a check for new emails in 1s... call this when you have queued an + * email for send. + */ +LWS_VISIBLE LWS_EXTERN void +lws_email_check(struct lws_email *email); +/** + * lws_email_destroy() - stop using the struct lws_email + * + * \param email: the struct lws_email context + * + * Stop sending email using email and free allocations + */ +LWS_VISIBLE LWS_EXTERN void +lws_email_destroy(struct lws_email *email); + +#endif +//@} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/android/x86/include/websockets/lws_config.h b/android/x86/include/websockets/lws_config.h new file mode 100644 index 00000000..bf49e46e --- /dev/null +++ b/android/x86/include/websockets/lws_config.h @@ -0,0 +1,117 @@ +/* lws_config.h Generated from lws_config.h.in */ + +#ifndef NDEBUG + #ifndef _DEBUG + #define _DEBUG + #endif +#endif + +#define LWS_INSTALL_DATADIR "/Users/james/Project/cocos2d-x-3rd-party-libs-src/contrib/install-android/arm/share" + +/* Define to 1 to use wolfSSL/CyaSSL as a replacement for OpenSSL. + * LWS_OPENSSL_SUPPORT needs to be set also for this to work. */ +/* #undef USE_WOLFSSL */ + +/* Also define to 1 (in addition to USE_WOLFSSL) when using the + (older) CyaSSL library */ +/* #undef USE_OLD_CYASSL */ + +/* #undef LWS_USE_MBEDTLS */ +/* #undef LWS_USE_POLARSSL */ +/* #undef LWS_WITH_ESP8266 */ + +/* #undef LWS_WITH_PLUGINS */ +/* #undef LWS_WITH_NO_LOGS */ + +/* The Libwebsocket version */ +#define LWS_LIBRARY_VERSION "2.1.0" + +#define LWS_LIBRARY_VERSION_MAJOR 2 +#define LWS_LIBRARY_VERSION_MINOR 1 +#define LWS_LIBRARY_VERSION_PATCH 0 +/* LWS_LIBRARY_VERSION_NUMBER looks like 1005001 for e.g. version 1.5.1 */ +#define LWS_LIBRARY_VERSION_NUMBER (LWS_LIBRARY_VERSION_MAJOR*1000000)+(LWS_LIBRARY_VERSION_MINOR*1000)+LWS_LIBRARY_VERSION_PATCH + +/* The current git commit hash that we're building from */ +#define LWS_BUILD_HASH "james@James-Chen.local-v3.4-138-g60b1a6f" + +/* Build with OpenSSL support */ +#define LWS_OPENSSL_SUPPORT + +/* The client should load and trust CA root certs it finds in the OS */ +#define LWS_SSL_CLIENT_USE_OS_CA_CERTS + +/* Sets the path where the client certs should be installed. */ +#define LWS_OPENSSL_CLIENT_CERTS "../share" + +/* Turn off websocket extensions */ +/* #undef LWS_NO_EXTENSIONS */ + +/* Enable libev io loop */ +/* #undef LWS_USE_LIBEV */ + +/* Enable libuv io loop */ +/* #undef LWS_USE_LIBUV */ + +/* Build with support for ipv6 */ +#define LWS_USE_IPV6 + +/* Build with support for UNIX domain socket */ +/* #undef LWS_USE_UNIX_SOCK */ + +/* Build with support for HTTP2 */ +/* #undef LWS_USE_HTTP2 */ + +/* Turn on latency measuring code */ +/* #undef LWS_LATENCY */ + +/* Don't build the daemonizeation api */ +#define LWS_NO_DAEMONIZE + +/* Build without server support */ +#define LWS_NO_SERVER + +/* Build without client support */ +/* #undef LWS_NO_CLIENT */ + +/* If we should compile with MinGW support */ +/* #undef LWS_MINGW_SUPPORT */ + +/* Use the BSD getifaddrs that comes with libwebsocket, for uclibc support */ +#define LWS_BUILTIN_GETIFADDRS + +/* use SHA1() not internal libwebsockets_SHA1 */ +/* #undef LWS_SHA1_USE_OPENSSL_NAME */ + +/* SSL server using ECDH certificate */ +/* #undef LWS_SSL_SERVER_WITH_ECDH_CERT */ +#define LWS_HAVE_SSL_CTX_set1_param +#define LWS_HAVE_X509_VERIFY_PARAM_set1_host + +/* #undef LWS_HAVE_UV_VERSION_H */ + +/* CGI apis */ +/* #undef LWS_WITH_CGI */ + +/* whether the Openssl is recent enough, and / or built with, ecdh */ +#define LWS_HAVE_OPENSSL_ECDH_H + +/* HTTP Proxy support */ +/* #undef LWS_WITH_HTTP_PROXY */ + +/* Http access log support */ +/* #undef LWS_WITH_ACCESS_LOG */ +/* #undef LWS_WITH_SERVER_STATUS */ + +/* #undef LWS_WITH_STATEFUL_URLDECODE */ + +/* Maximum supported service threads */ +#define LWS_MAX_SMP 32 + +/* Lightweight JSON Parser */ +/* #undef LWS_WITH_LEJP */ + +/* SMTP */ +/* #undef LWS_WITH_SMTP */ + + diff --git a/android/x86/include/zlib/zconf.h b/android/x86/include/zlib/zconf.h new file mode 100644 index 00000000..996fff29 --- /dev/null +++ b/android/x86/include/zlib/zconf.h @@ -0,0 +1,511 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2013 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_bits z__tr_flush_bits +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# ifdef _WIN32 +# define gzopen_w z_gzopen_w +# endif +# define gzprintf z_gzprintf +# define gzvprintf z_gzvprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateGetDictionary z_inflateGetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# endif +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include <windows.h> + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) +# include <limits.h> +# if (UINT_MAX == 0xffffffffUL) +# define Z_U4 unsigned +# elif (ULONG_MAX == 0xffffffffUL) +# define Z_U4 unsigned long +# elif (USHRT_MAX == 0xffffffffUL) +# define Z_U4 unsigned short +# endif +#endif + +#ifdef Z_U4 + typedef Z_U4 z_crc_t; +#else + typedef unsigned long z_crc_t; +#endif + +#if 1 /* was set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#if 1 /* was set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include <sys/types.h> /* for off_t */ +# endif +#endif + +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +# include <stdarg.h> /* for va_list */ +# endif +#endif + +#ifdef _WIN32 +# ifndef Z_SOLO +# include <stddef.h> /* for wchar_t */ +# endif +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) +# define Z_HAVE_UNISTD_H +#endif +#ifndef Z_SOLO +# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +# ifdef VMS +# include <unixio.h> /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +# endif +#endif + +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 +# define Z_LFS64 +#endif + +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) +# define Z_LARGE64 +#endif + +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) +# define Z_WANT64 +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(_WIN32) && defined(Z_LARGE64) +# define z_off64_t off64_t +#else +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +# endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/android/x86/include/zlib/zlib.h b/android/x86/include/zlib/zlib.h new file mode 100644 index 00000000..3e0c7672 --- /dev/null +++ b/android/x86/include/zlib/zlib.h @@ -0,0 +1,1768 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.8, April 28th, 2013 + + Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 + (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.8" +#define ZLIB_VERNUM 0x1280 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 8 +#define ZLIB_VER_SUBREVISION 0 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + z_const Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total number of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total number of bytes output so far */ + + z_const char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use in the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). Some + output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed code + block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the stream + are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least the + value returned by deflateBound (see below). Then deflate is guaranteed to + return Z_STREAM_END. If not enough output space is provided, deflate will + not return Z_STREAM_END, and it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect the + compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the + exact value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit() does not process any header information -- that is deferred + until inflate() is called. +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing will + resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all of the uncompressed data for the + operation to complete. (The size of the uncompressed data may have been + saved by the compressor for this purpose.) The use of Z_FINISH is not + required to perform an inflation in one step. However it may be used to + inform inflate that a faster approach can be used for the single inflate() + call. Z_FINISH also informs inflate to not maintain a sliding window if the + stream completes, which reduces inflate's memory footprint. If the stream + does not complete, either because not all of the stream is provided or not + enough output space is provided, then a sliding window will be allocated and + inflate() can be called again to continue the operation as if Z_NO_FLUSH had + been used. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the effects of the flush parameter in this implementation are + on the return value of inflate() as noted below, when inflate() returns early + when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of + memory for a sliding window when Z_FINISH is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the Adler-32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the Adler-32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained, so applications that need that information should + instead use raw inflate, see inflateInit2() below, or inflateBack() and + perform their own processing of the gzip header and trailer. When processing + gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output + producted so far. The CRC-32 is checked against the gzip trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. When using the zlib format, this + function must be called immediately after deflateInit, deflateInit2 or + deflateReset, and before any call of deflate. When doing raw deflate, this + function must be called either before any call of deflate, or immediately + after the completion of a deflate block, i.e. after all input has been + consumed and all output has been delivered when using any of the flush + options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The + compressor and decompressor must use exactly the same dictionary (see + inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if not at a block boundary for raw deflate). deflateSetDictionary does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. The + stream will keep the same compression level and any other attributes that + may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression level is changed, the input available so far is + compressed with the old level (and may be flushed); the new level will take + effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to be + compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if + strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). If that first deflate() call is provided the + sourceLen input bytes, an output buffer allocated to the size returned by + deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed + to return Z_STREAM_END. Note that it is possible for the compressed size to + be larger than the value returned by deflateBound() if flush options other + than Z_FINISH or Z_NO_FLUSH are used. +*/ + +ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, + unsigned *pending, + int *bits)); +/* + deflatePending() returns the number of bytes and bits of output that have + been generated, but not yet provided in the available output. The bytes not + provided would be due to the available output space having being consumed. + The number of bits of output not provided are between 0 and 7, where they + await more bits to join them in order to fill out a full byte. If pending + or bits are Z_NULL, then those values are not set. + + deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough + room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called at any + time to set the dictionary. If the provided dictionary is smaller than the + window and there is already data in the window, then the provided dictionary + will amend what's there. The application must insure that the dictionary + that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, + Bytef *dictionary, + uInt *dictLength)); +/* + Returns the sliding dictionary being maintained by inflate. dictLength is + set to the number of bytes in the dictionary, and that many bytes are copied + to dictionary. dictionary must have enough space, where 32768 bytes is + always enough. If inflateGetDictionary() is called with dictionary equal to + Z_NULL, then only the dictionary length is returned, and nothing is copied. + Similary, if dictLength is Z_NULL, then it is not set. + + inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the + stream state is inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a possible full flush point (see above + for the description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync searches for a 00 00 FF FF pattern in the compressed data. + All full flush points have this pattern, but not all occurrences of this + pattern are full flush points. + + inflateSync returns Z_OK if a possible full flush point has been found, + Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point + has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. + In the success case, the application may save the current current value of + total_in which indicates where valid compressed data was found. In the + error case, the application may repeatedly call inflateSync, providing more + input each time, until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above or -1 << 16 if the provided + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the parameters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, + z_const unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is potentially more efficient than + inflate() for file i/o applications, in that it avoids copying between the + output and the sliding window by simply making the window itself the output + buffer. inflate() can be faster on modern CPUs when used with large + buffers. inflateBack() trusts the application to not change the output + buffer passed by the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the normal + behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + +#ifndef Z_SOLO + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In + the case where there is not enough room, uncompress() will fill the output + buffer with the uncompressed data up to that point. +*/ + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) 'T' will + request transparent writing or appending with no compression and not using + the gzip format. + + "a" can be used instead of "w" to request that the gzip stream that will + be written be appended to the file. "+" will result in an error, since + reading and writing to the same gzip file is not supported. The addition of + "x" when writing will create the file exclusively, which fails if the file + already exists. On systems that support it, the addition of "e" when + reading or writing will set the flag to close the file on an execve() call. + + These functions, as well as gzip, will read and decode a sequence of gzip + streams in a file. The append function of gzopen() can be used to create + such a file. (Also see gzflush() for another way to do this.) When + appending, gzopen does not test whether the file begins with a gzip stream, + nor does it look for the end of the gzip streams to begin appending. gzopen + will simply append a gzip stream to the existing file. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. When + reading, this will be detected automatically by looking for the magic two- + byte gzip header. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. If you are using fileno() to get the + file descriptor from a FILE *, then you will have to use dup() to avoid + double-close()ing the file descriptor. Both gzclose() and fclose() will + close the associated file descriptor, so they need to have different file + descriptors. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Two buffers are allocated, either both of the specified size when + writing, or one of the specified size and the other twice that size when + reading. A larger buffer size of, for example, 64K or 128K bytes will + noticeably increase the speed of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file is not in gzip format, gzread copies the given number of + bytes into the buffer directly from the file. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream. Any number of gzip streams may be + concatenated in the input file, and will all be decompressed by gzread(). + If something other than a gzip stream is encountered after a gzip stream, + that remaining trailing garbage is ignored (and no error is returned). + + gzread can be used to read a gzip file that is being concurrently written. + Upon reaching the end of the input, gzread will return with the available + data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then + gzclearerr can be used to clear the end of file indicator in order to permit + gzread to be tried again. Z_OK indicates that a gzip stream was completed + on the last gzread. Z_BUF_ERROR indicates that the input file ended in the + middle of a gzip stream. Note that gzread does not return -1 in the event + of an incomplete gzip stream. This error is deferred until gzclose(), which + will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip + stream. Alternatively, gzerror can be used before gzclose to detect this + case. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. +*/ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or 0 in case of error. The number of + uncompressed bytes written is limited to 8191, or one less than the buffer + size given to gzbuffer(). The caller should assure that this limit is not + exceeded. If it is exceeded, then gzprintf() will return an error (0) with + nothing written. In this case, there may also be a buffer overflow with + unpredictable consequences, which is possible only if zlib was compiled with + the insecure functions sprintf() or vsprintf() because the secure snprintf() + or vsnprintf() functions were not available. This can be determined using + zlibCompileFlags(). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. This is implemented as a macro for speed. + As such, it does not do all of the checking the other functions do. I.e. + it does not check to see if file is NULL, nor whether the structure file + points to has been clobbered or not. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatented gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); + + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). + + When writing, gzdirect() returns true (1) if transparent writing was + requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: + gzdirect() is not needed when writing. Transparent writing must be + explicitly requested, so the application already knows the answer. When + linking statically, using gzdirect() will include all of the zlib code for + gzip file reading and decompression, which may not be desired.) +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the + last read ended in the middle of a gzip stream, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + +#endif /* !Z_SOLO */ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); + + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note + that the z_off_t type (like off_t) is a signed integer. If len2 is + negative, the result has no meaning or utility. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ + (int)sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, (int)sizeof(z_stream)) + +#ifndef Z_SOLO + +/* gzgetc() macro and its supporting function and exposed data structure. Note + * that the real internal state is much larger than the exposed structure. + * This abbreviated structure exposes just enough for the gzgetc() macro. The + * user should not mess with these exposed elements, since their names or + * behavior could change in the future, perhaps even capriciously. They can + * only be used by the gzgetc() macro. You have been warned. + */ +struct gzFile_s { + unsigned have; + unsigned char *next; + z_off64_t pos; +}; +ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +#ifdef Z_PREFIX_SET +# undef z_gzgetc +# define z_gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#else +# define gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#endif + +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if + * both are true, the application gets the *64 functions, and the regular + * functions are changed to 64 bits) -- in case these are set on systems + * without large file support, _LFS64_LARGEFILE must also be true + */ +#ifdef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) +# ifdef Z_PREFIX_SET +# define z_gzopen z_gzopen64 +# define z_gzseek z_gzseek64 +# define z_gztell z_gztell64 +# define z_gzoffset z_gzoffset64 +# define z_adler32_combine z_adler32_combine64 +# define z_crc32_combine z_crc32_combine64 +# else +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# endif +# ifndef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +# endif +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif + +#else /* Z_SOLO */ + + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); + +#endif /* !Z_SOLO */ + +/* hack for buggy compilers */ +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; +#endif + +/* undocumented functions */ +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); +ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); +ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +#if defined(_WIN32) && !defined(Z_SOLO) +ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, + const char *mode)); +#endif +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, + const char *format, + va_list va)); +# endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/android/x86/libcrypto.a b/android/x86/libcrypto.a new file mode 100644 index 00000000..7fc849ca Binary files /dev/null and b/android/x86/libcrypto.a differ diff --git a/android/x86/libfreetype.a b/android/x86/libfreetype.a new file mode 100644 index 00000000..82882760 Binary files /dev/null and b/android/x86/libfreetype.a differ diff --git a/android/x86/libjpeg.a b/android/x86/libjpeg.a new file mode 100644 index 00000000..90297136 Binary files /dev/null and b/android/x86/libjpeg.a differ diff --git a/android/x86/libpng.a b/android/x86/libpng.a new file mode 100644 index 00000000..de997462 Binary files /dev/null and b/android/x86/libpng.a differ diff --git a/android/x86/libssl.a b/android/x86/libssl.a new file mode 100644 index 00000000..bfacd688 Binary files /dev/null and b/android/x86/libssl.a differ diff --git a/android/x86/libtiff.a b/android/x86/libtiff.a new file mode 100644 index 00000000..53a4764a Binary files /dev/null and b/android/x86/libtiff.a differ diff --git a/android/x86/libuv.a b/android/x86/libuv.a new file mode 100644 index 00000000..1531e9fd Binary files /dev/null and b/android/x86/libuv.a differ diff --git a/android/x86/libwebp.a b/android/x86/libwebp.a new file mode 100644 index 00000000..02959c63 Binary files /dev/null and b/android/x86/libwebp.a differ diff --git a/android/x86/libwebsockets.a b/android/x86/libwebsockets.a new file mode 100644 index 00000000..861114ee Binary files /dev/null and b/android/x86/libwebsockets.a differ diff --git a/android/x86/libz.a b/android/x86/libz.a new file mode 100644 index 00000000..c3df6c74 Binary files /dev/null and b/android/x86/libz.a differ diff --git a/android/x86/v8/libc++.a b/android/x86/v8/libc++.a new file mode 100755 index 00000000..2eeff221 Binary files /dev/null and b/android/x86/v8/libc++.a differ diff --git a/android/x86/v8/libc++abi.a b/android/x86/v8/libc++abi.a new file mode 100755 index 00000000..bd87c808 Binary files /dev/null and b/android/x86/v8/libc++abi.a differ diff --git a/android/x86/v8/libinspector.a b/android/x86/v8/libinspector.a new file mode 100755 index 00000000..33a8a45c Binary files /dev/null and b/android/x86/v8/libinspector.a differ diff --git a/android/x86/v8/libv8_base_without_compiler.a b/android/x86/v8/libv8_base_without_compiler.a new file mode 100755 index 00000000..b8593270 Binary files /dev/null and b/android/x86/v8/libv8_base_without_compiler.a differ diff --git a/android/x86/v8/libv8_compiler.a b/android/x86/v8/libv8_compiler.a new file mode 100755 index 00000000..014db079 Binary files /dev/null and b/android/x86/v8/libv8_compiler.a differ diff --git a/android/x86/v8/libv8_libbase.a b/android/x86/v8/libv8_libbase.a new file mode 100755 index 00000000..6ecc9fcc Binary files /dev/null and b/android/x86/v8/libv8_libbase.a differ diff --git a/android/x86/v8/libv8_libplatform.a b/android/x86/v8/libv8_libplatform.a new file mode 100755 index 00000000..b02d3ef1 Binary files /dev/null and b/android/x86/v8/libv8_libplatform.a differ diff --git a/android/x86/v8/libv8_libsampler.a b/android/x86/v8/libv8_libsampler.a new file mode 100755 index 00000000..bcd577ca Binary files /dev/null and b/android/x86/v8/libv8_libsampler.a differ diff --git a/android/x86/v8/libv8_snapshot.a b/android/x86/v8/libv8_snapshot.a new file mode 100755 index 00000000..fe0dcb5d Binary files /dev/null and b/android/x86/v8/libv8_snapshot.a differ